本文整理汇总了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)
示例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()
#.........这里部分代码省略.........