当前位置: 首页>>代码示例>>Python>>正文


Python PyDatagram.addString32方法代码示例

本文整理汇总了Python中direct.distributed.PyDatagram.addString32方法的典型用法代码示例。如果您正苦于以下问题:Python PyDatagram.addString32方法的具体用法?Python PyDatagram.addString32怎么用?Python PyDatagram.addString32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在direct.distributed.PyDatagram的用法示例。


在下文中一共展示了PyDatagram.addString32方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: updateAllPartyLists

# 需要导入模块: from direct.distributed import PyDatagram [as 别名]
# 或者: from direct.distributed.PyDatagram import addString32 [as 别名]
    def updateAllPartyLists(self):
        parties = deepcopy(self.parties)
        for party in parties.values():
            del party['map']['tiles']

        for player in self.playersinlobby:
            myPyDatagram = PyDatagram()
            myPyDatagram.addUint8(UPDATE_PARTY_LIST)
            myPyDatagram.addString32(json.dumps(parties))
            self.cWriter.send(myPyDatagram, player)
开发者ID:Ultimoore,项目名称:tethical,代码行数:12,代码来源:main.py

示例2: processData

# 需要导入模块: from direct.distributed import PyDatagram [as 别名]
# 或者: from direct.distributed.PyDatagram import addString32 [as 别名]
    def processData(self, datagram):
        iterator = PyDatagramIterator(datagram)
        source = datagram.getConnection()
        msgID = iterator.getUint8()
        
        if msgID == LOGIN_MESSAGE:

            login = iterator.getString()
            password = iterator.getString()

            if login != password:
                myPyDatagram = PyDatagram()
                myPyDatagram.addUint8(LOGIN_FAIL)
                myPyDatagram.addString('Wrong credentials.')
                self.cWriter.send(myPyDatagram, source)
            elif self.sessions.has_key(source):
                myPyDatagram = PyDatagram()
                myPyDatagram.addUint8(LOGIN_FAIL)
                myPyDatagram.addString('Already logged in.')
                self.cWriter.send(myPyDatagram, source)
            elif login in self.players.keys():
                myPyDatagram = PyDatagram()
                myPyDatagram.addUint8(LOGIN_FAIL)
                myPyDatagram.addString('Username already in use.')
                self.cWriter.send(myPyDatagram, source)
            else:
                self.players[login] = source
                self.sessions[source] = {}
                self.sessions[source]['login'] = login
                print login, 'logged in.'
                myPyDatagram = PyDatagram()
                myPyDatagram.addUint8(LOGIN_SUCCESS)
                self.cWriter.send(myPyDatagram, source)
        
        elif msgID == CREATE_PARTY:

            name = iterator.getString()
            mapname = iterator.getString()
            
            party = {
                'name': name,
                'mapname': mapname,
                'map' : Map.load(mapname),
                'chars': {},
                'log': {},
                'creator': self.sessions[source]['login'],
                'players': [],
            }
            party['players'].append(self.sessions[source]['login'])

            self.parties[name] = party
            self.sessions[source]['party'] = name
            self.sessions[source]['player'] = len(party['players'])-1
            
            self.updateAllPartyLists()
            
            print self.sessions[source]['login'], "created the party", name, "using the map", mapname
            myPyDatagram = PyDatagram()
            myPyDatagram.addUint8(PARTY_CREATED)
            myPyDatagram.addString32(json.dumps(party))
            self.cWriter.send(myPyDatagram, source)

        elif msgID == GET_MAPS:
            self.playersinlobby.remove(source)

            mapnames = map( lambda m: m.split('.')[0], os.listdir(GAME+'/maps'))

            maps = []
            for mapname in mapnames:
                mp = Map.load(mapname)
                del mp['tiles']
                maps.append(mp)

            myPyDatagram = PyDatagram()
            myPyDatagram.addUint8(MAP_LIST)
            myPyDatagram.addString(json.dumps(maps))
            self.cWriter.send(myPyDatagram, source)
        
        elif msgID == GET_PARTIES:
            self.playersinlobby.append(source)

            parties = deepcopy(self.parties)
            for party in parties.values():
                del party['map']['tiles']

            myPyDatagram = PyDatagram()
            myPyDatagram.addUint8(PARTY_LIST)
            myPyDatagram.addString32(json.dumps(parties))
            self.cWriter.send(myPyDatagram, source)
        
        elif msgID == JOIN_PARTY:
        
            name = iterator.getString()
            party = self.parties[name]
            
            if len(party['players']) >= len(party['map']['chartiles']):
                parties = deepcopy(self.parties)
                for party in parties.values():
                    del party['map']['tiles']
                myPyDatagram = PyDatagram()
#.........这里部分代码省略.........
开发者ID:Ultimoore,项目名称:tethical,代码行数:103,代码来源:main.py


注:本文中的direct.distributed.PyDatagram.addString32方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。