def setObjectZone(self, owner, object, zoneId): if object.zoneId == zoneId: # No change. return oldZoneId = object.zoneId self.objectsByZoneId[object.zoneId].remove(object) if not self.objectsByZoneId[object.zoneId]: del self.objectsByZoneId[object.zoneId] owner.objectsByZoneId[object.zoneId].remove(object) if not owner.objectsByZoneId[object.zoneId]: del owner.objectsByZoneId[object.zoneId] object.zoneId = zoneId self.objectsByZoneId.setdefault(zoneId, set()).add(object) owner.objectsByZoneId.setdefault(zoneId, set()).add(object) self.updateClientInterestZones(owner) # Any clients that are listening to oldZoneId but not zoneId # should receive a disable message: this object has just gone # out of scope for you. datagram = PyDatagram() datagram.addUint16(OBJECT_DISABLE_CMU) datagram.addUint32(object.doId) for client in self.zonesToClients[oldZoneId]: if client != owner: if zoneId not in client.currentInterestZoneIds: self.cw.send(datagram, client.connection) self.needsFlush.add(client)
def updatePlayers(self,serverClass,data,type): if (type == "positions"): #keep players updated on their position self.elapsed = globalClock.getDt() self.timeSinceLastUpdate += self.elapsed if (self.timeSinceLastUpdate > 0.1): if (self.active): self.datagram = PyDatagram() self.datagram.addString("update") #add the number of players self.datagram.addFloat64(self.active) #add every players current position for k in range(self.active): self.datagram.addFloat64(self.PlayerList[k].currentPos['x']) self.datagram.addFloat64(self.PlayerList[k].currentPos['y']) self.datagram.addFloat64(self.PlayerList[k].currentPos['z']) self.datagram.addFloat64(self.PlayerList[k].currentPos['h']) self.datagram.addFloat64(self.PlayerList[k].currentPos['p']) self.datagram.addFloat64(self.PlayerList[k].currentPos['r']) for k in self.PlayerList: self.conn = k.connectionID serverClass.cWriter.send(self.datagram,self.conn) self.timeSinceLastUpdate = 0 return Task.cont if(type == "chat"): #Keep players up to date with all the chat thats goin on self.iterator = data self.datagram = PyDatagram() self.datagram.addString("chat") self.text = self.iterator.getString() self.datagram.addString(self.text) print self.text,' ',str(serverClass) for k in self.PlayerList: serverClass.cWriter.send(self.datagram,k.connectionID)
def init_file(self): with open(self.filepath, 'wb') as file: data = PyDatagram() data.add_uint8(0) file.write(PyDatagramIterator(data).get_remaining_bytes())
def makeNetString(self): dg = PyDatagram() for part in self.dna: part.makeNetString(dg=dg) return dg.getMessage()
def resendPlayToken(self): cr = self.cr datagram = PyDatagram() datagram.addUint16(CLIENT_SET_SECURITY) self._LoginTTAccount__addPlayToken(datagram) self._LoginTTAccount__addTokenType(datagram) cr.send(datagram)
def WAIT(self, charid, direction): myPyDatagram = PyDatagram() myPyDatagram.addString('WAIT') myPyDatagram.addString(charid) # seem direction became str myPyDatagram.addUint8(int(direction)) self.cWriter.send(myPyDatagram, self.myConnection)
def sendMove(mx, my): move = PyDatagram() move.addUint16(PACKET_MOVE) sgn = (mode == MODE_2P or MY_POSITION>1) and -1 or 1 move.addFloat64(sgn*mx) move.addFloat64(sgn*my) cWriter.send(move, serverConnection)
def resendLoginCookie(self): cr = self.cr datagram = PyDatagram() datagram.addUint16(CLIENT_SET_SECURITY) self.__addLoginCookie(datagram) self.__addTokenType(datagram) cr.send(datagram)
def syncSmiley(self, task): print "SYNCING SMILEYS!" sync = PyDatagram() sync.addFloat32(self.smiley.vel) sync.addFloat32(self.smiley.pos.getZ()) self.broadcast(sync) return task.again
def update_winner(self,task): closest=0 closestDist = 999999 for i in range(1,len(self.Server.players)): x=self.Server.players[i].getX() y=self.Server.players[i].getY() z=self.Server.players[i].getZ() mx=self.Server.players[0].getX() my=self.Server.players[0].getY() mz=self.Server.players[0].getZ() dist=math.sqrt((x-mx)**2+(y-my)**2+(z-mz)**2) #print i, dist if dist <closestDist: closest = i closestDist=dist #print closest, " is the closest" self.poloScores[closest]+=100.0/24.0/10000.0 update = PyDatagram() update.addUint8(101) for score in self.poloScores: update.addFloat32(score) self.broadcast(update) return task.cont
def updateListener(self, task): if self.listener.newConnectionAvailable(): connection = PointerToConnection() if self.listener.getNewConnection(connection): connection = connection.p() connection.setNoDelay(True) self.connections.append(connection) self.reader.addConnection(connection) print "Server: New connection established." self.tempClientID = -1 for client in range(0,len(direction)): if direction[client] == -1: direction[client] = 0 #print "Client ID ",client self.tempClientID = client break if self.tempClientID == -1: print "Server is full, keeping connection but giving fake ID!" reply = PyDatagram() reply.addUint8(42) reply.addInt8(self.tempClientID) self.writer.send(reply,connection) print "Giving new client ID: ",self.tempClientID return task.cont
def makeNamedMovementDone(self): datagram = PyDatagram() datagram.addUint32(self.packetNumber) self.packetNumber = self.packetNumber + 1 datagram.addUint8(CLUSTER_NAMED_MOVEMENT_DONE) return datagram
def updateGardenData(self): gardenData = PyDatagram() gardenData.addUint8(len(self.plots)) for plot in self.plots: plot.pack(gardenData) self.house.b_setGardenData(gardenData.getMessage())
def pingTask(task): if (task.frame % 1000) > 0: #determine network delay every now and then (every 1000 frames) return Task.cont ping = PyDatagram() ping.addUint16(PACKET_PING) ping.addFloat64(time.time()) toAll(ping, activeConnections) return Task.cont
def informBan(self, banner, username, time): msg = "%s banned %s for %s hours" self.notify.info(msg) dg = PyDatagram() dg.addString(msg) dgi = PyDatagramIterator(dg) self.cr.handleSystemMessage(dgi)
def makeNetString(self): dataList = self.experience datagram = PyDatagram() for track in range(0, len(Tracks)): datagram.addUint16(dataList[track]) dgi = PyDatagramIterator(datagram) return dgi.getRemainingBytes()
def __makeBlob(self, store): dg = PyDatagram() if self.__list: dg.addUint8(CatalogItem.CatalogItemVersion) for item in self.__list: CatalogItem.encodeCatalogItem(dg, item, store) return dg.getMessage()
def sendStartGame(self, players): datagram = PyDatagram() datagram.addUint8(protocols.ClientMsgId.gameStarted) #nicks = [p.nick for p in players] datagram.addString(players[0].nick) datagram.addString(players[1].nick) self.server.broadcast(datagram)
def sendMove(self, fr, to): dg = PyDatagram() dg.addUint8(fr[0]) dg.addUint8(fr[1]) dg.addUint8(to[0]) dg.addUint8(to[1]) print "Sent move (%d, %d) -> (%d, %d)" % (fr[0], fr[1], to[0], to[1]) self.cWriter.send(dg, self.oppConnection)
def makeNetString(self): dataList = self.inventory datagram = PyDatagram() for track in range(0, len(Tracks)): for level in range(0, len(Levels[track])): datagram.addUint8(dataList[track][level]) dgi = PyDatagramIterator(datagram) return dgi.getRemainingBytes()
def checkReset(): global lastResetPress lastResetPress = time.time() reset = PyDatagram() #send a reset request to partner reset.addUint16(PACKET_RESET) if role==ROLE_CLIENT: cWriter.send(reset, serverConnection) elif role == ROLE_SERVER and not isResetConfirmed(): toAll(reset, activeConnections)
def handleAuth(self, opcode, data, client): """ Handle auth and player login. NOTE: THIS IS REALLY SIMPLE FOR NOW Add something to check if the user is already logged in """ # Get the data the client sent. clientUser = data.getString() clientPass = data.getString() # Flag to be send back after serverside auth flag = None userpass = False loginTries = 0 # Not thought out now, will return to it later... # Get the data from DB try: # Here we can add the player to the PLAYERS{} by using a player # ID or something details = [] details = Database.getAccountData(clientUser, clientPass) except: print "Can't connected to ACCOUNT DATABASE" # Will make some other checks later... this is just good for now.. if details == None: flag = 2 print "Player: ", clientUser, " Doesn't exist! or Incorrect!" loginTries += 1 # Check if the password/username match elif clientPass == details[2] and clientUser == details[1]: print details userpass = True self.network.base.PLAYERS[details[0]] = Player(self, details[0], details[1]) print "Player: ", details[1], " Logged in, ID: ", details[0] flag = 1 else: userpass = False print "Player: ", clientUser, " login incorrect" loginTries += 1 flag = 2 # Create buffer pkg = PyDatagram() # Add response pkg.addUint16(SMSG_AUTH_RESPONSE) # Add the flag pkg.addUint16(flag) # Send the packet self.network.tcpWriter.send(pkg, client)
def getCollisionDatagrams(self): myDatagrams = [] for data in self.collisionData: newDatagram = PyDatagram() newDatagram.addUint8(COLLIDED_MESSAGE) newDatagram.addUint8(data[0]) newDatagram.addUint8(data[1]) myDatagrams.append(newDatagram) return myDatagrams
def subscribe(self, avId, access): self.subscribed[avId] = access self.notify.info('Subscribed avatar %s with access %s' % (avId, access)) dgcleanup = self.dclass.aiFormatUpdate("unsubscribe", self.doId, self.air.ourChannel, self.air.ourChannel, [avId]) dg = PyDatagram() dg.addServerHeader(self.GetAccountConnectionChannel(self.avId), self.air.ourChannel, CLIENTAGENT_ADD_POST_REMOVE) dg.addString(dgcleanup.getMessage()) self.air.send(dg)
def send(self, args=[]): try: pkg = PyDatagram() pkg.addUint16(Constants.CMSG_TIME) self.cWriter.send(pkg, self.connection) except: self.log("Bad [" + str(Constants.CMSG_TIME) + "] Time Request")
def send(self, args = []): try: pkg = PyDatagram() pkg.addUint16(Constants.CMSG_REQ_TEST) self.cWriter.send(pkg, self.connection) except: self.log('Bad [' + str(Constants.CMSG_REQ_TEST) + '] Test Request')
def send(self): try: pkg = PyDatagram() pkg.addUint16(Constants.CMSG_DEAD) self.cWriter.send(pkg, self.connection) except: self.log('Bad [' + str(Constants.CMSG_DEAD) + '] Dead Request')
def update_players(self, task): for ip, player in self.players.items(): if player.do_move(): datagram = PyDatagram() datagram.addInt8(player.pid) datagram.addFloat32(player.node.getX()) datagram.addFloat32(player.node.getY()) for conn in self.connections: self.writer.send(datagram, conn) return task.cont
def send(self, args=None): try: pkg = PyDatagram() pkg.addUint16(Constants.REQ_HEARTBEAT) self.cWriter.send(pkg, self.connection) # self.log('Sent [' + str(Constants.RAND_STRING) + '] Int Request') except: self.log("Bad [" + str(Constants.RAND_STRING) + "] Int Request")
def msgChat(self, msgID, data, senderClient): message = data.getString() self.screenText.appendText("Message: ") self.screenText.appendText(message) self.screenText.appendText("\n") pkg = PyDatagram() pkg.addUint16(SV_MSG_CHAT) pkg.addString(message) for receiverClient in CLIENTS: self.cWriter.send(pkg, receiverClient)
def send(self, gameId): try: pkg = PyDatagram() pkg.addUint16(Constants.CMSG_RESULTS) pkg.addInt32(gameId) # GameId self.cWriter.send(pkg, self.connection) except: self.log('Bad [' + str(Constants.CMSG_RESULTS) + '] Results Request')
def send(self, kwargs): try: pkg = PyDatagram() pkg.addUint16(Constants.CMSG_DEAD) pkg.addInt32(kwargs['gameId']) self.cWriter.send(pkg, self.connection) self.log('Sent [' + str(Constants.CMSG_DEAD) + '] RequestDead') except: self.log('Bad [' + str(Constants.CMSG_DEAD) + '] RequestDead') print_exc()
def constructToonStatuary(self, plotIndex, typeIndex, dnaCode): dg = PyDatagram() dg.addUint8(plotIndex) dg.addUint8(typeIndex) dg.addUint16(dnaCode) gardenData = PyDatagramIterator(dg) plot = occupier2Class[GardenGlobals.ToonStatuaryPlot](self.air, self, self.house.housePos) plot.construct(gardenData) self.plots[plotIndex] = plot self.updateGardenData()
def send(self, powerId): try: pkg = PyDatagram() pkg.addUint16(Constants.CMSG_POWER_UP_PICK_UP) pkg.addInt32(powerId) self.cWriter.send(pkg, self.connection) except: self.log('Bad [' + str(Constants.CMSG_POWER_UP_PICK_UP) + '] Power Pick Up Request')
def sendMagicWord(self, word, targetId): invokerId = self.air.getAvatarIdFromSender() invoker = self.air.doId2do.get(invokerId) if not isinstance(self.air.doId2do.get(targetId), DistributedToonAI): self.sendUpdateToAvatarId(invokerId, 'sendMagicWordResponse', ['Target is not a toon object!']) return if not invoker: self.sendUpdateToAvatarId(invokerId, 'sendMagicWordResponse', ['missing invoker']) return now = time.strftime("%c") if invoker.getAdminAccess() < MINIMUM_MAGICWORD_ACCESS: self.air.writeServerEvent( 'suspicious', invokerId, 'Attempted to issue magic word: %s' % word) dg = PyDatagram() dg.addServerHeader(self.GetPuppetConnectionChannel(invokerId), self.air.ourChannel, CLIENTAGENT_EJECT) dg.addUint16(126) dg.addString('Magic Words are reserved for administrators only!') self.air.send(dg) return target = self.air.doId2do.get(targetId) if not target: self.sendUpdateToAvatarId(invokerId, 'sendMagicWordResponse', ['missing target']) return response = spellbook.process(invoker, target, word) if response: self.sendUpdateToAvatarId(invokerId, 'sendMagicWordResponse', [response]) self.air.writeServerEvent('magic-word', invokerId, invoker.getAdminAccess(), targetId, target.getAdminAccess(), word, response) with open("logs/mw/magic-words.txt", "a") as textFile: textFile.write("%s | %s : %s\n" % (now, invokerId, word)) print("%s | %s : %s\n" % (now, invokerId, word))
def reload(self, do, dclass, fields): """reload(self, DistributedObjectAI do, DCClass dclass) Re-reads all of the data from the DistributedObject and stores it in the values table. """ self.doId = do.doId self.values = {} for fieldName in fields: field = dclass.getFieldByName(fieldName) if field == None: self.notify.warning("No definition for %s" % (fieldName)) else: dg = PyDatagram() packOk = dclass.packRequiredField(dg, do, field) assert (packOk) self.values[fieldName] = dg
def send(self, args=None): try: pkg = PyDatagram() pkg.addUint16(Constants.RAND_SHORT) pkg.addUint16(args) self.cWriter.send(pkg, self.connection) #self.log('Sent [' + str(Constants.RAND_SHORT) + '] Short Request') except: self.log('Bad [' + str(Constants.RAND_SHORT) + '] Short Request') print_exc()
def requestDelete(self, do): """ Request the deletion of an object that already exists on the State Server. You should use do.requestDelete() instead. This is not meant to be called directly unless you really know what you are doing. """ dg = PyDatagram() dg.addServerHeader(do.doId, self.ourChannel, STATESERVER_OBJECT_DELETE_RAM) dg.addUint32(do.doId) self.send(dg)
def send(self, message): try: pkg = PyDatagram() pkg.addUint16(Constants.CMSG_CHAT) pkg.addString(message) self.cWriter.send(pkg, self.connection) #self.log('Sent [' + str(Constants.RAND_STRING) + '] Int Request') except: self.log('Bad [' + str(Constants.CMSG_CHAT) + '] Int Request') print_exc()
def send(self, args = None): try: pkg = PyDatagram() pkg.addUint16(Constants.REQ_HEARTBEAT) pkg.addString("adrien") self.cWriter.send(pkg, self.connection) except: self.log('Bad [' + str(Constants.REQ_HEARTBEAT) + '] Heartbeat Request')
def dg_remove_player(local_id): """ Tells the players that a player has Left. This should only be called while the game is in the lobby as it'll delete the player's data from clients :param local_id: the local ID of the ex-player :type local_id: int :return: the datagram to send :rtype: pydatagram """ dg = PyDatagram() dg.addUint8(REMOVE_PLAYER) dg.addUint8(local_id) return dg
def clearPostRemove(self): """ Clear all datagrams registered with addPostRemove. This is useful if the Panda3D process is performing a clean exit. It may clear the "emergency clean-up" post-remove messages and perform a normal exit-time clean-up instead, depending on the specific design of the game. """ dg = PyDatagram() dg.addServerControlHeader(CONTROL_CLEAR_POST_REMOVE) dg.addUint64(self.ourChannel) self.send(dg)
def send(self, args=None): try: pkg = PyDatagram() pkg.addUint16(Constants.CMSG_NPCDEATH) pkg.addUint32(args[0]) self.cWriter.send(pkg, self.connection) #self.log('Sent [' + str(Constants.RAND_INT) + '] Int Request') except: self.log('Bad [' + str(Constants.RAND_INT) + '] Int Request') print_exc()
def send(self, args=None): try: pkg = PyDatagram() pkg.addUint16(Constants.REQ_HEARTBEAT) pkg.addString(args) self.cWriter.send(pkg, self.connection) #self.log('Sent [' + str(Constants.RAND_STRING) + '] Int Request') except: self.log('Bad [' + str(Constants.REQ_HEARTBEAT) + '] Int Request') print_exc()
def sendMagicWord(self, word, targetId): invokerId = self.air.getAvatarIdFromSender() invoker = self.air.doId2do.get(invokerId) # Broken... # NF #if not 'DistributedToonAI' in str(self.air.doId2do.get(targetId)): # self.sendUpdateToAvatarId(invokerId, 'sendMagicWordResponse', ['Target is not a toon object!']) # return if not invoker: self.sendUpdateToAvatarId(invokerId, 'sendMagicWordResponse', ['missing invoker']) return if invoker.getAdminAccess() < MINIMUM_MAGICWORD_ACCESS: self.air.writeServerEvent( 'suspicious', invokerId, 'Attempted to issue magic word: %s' % word) dg = PyDatagram() dg.addServerHeader(self.GetPuppetConnectionChannel(invokerId), self.air.ourChannel, CLIENTAGENT_EJECT) dg.addUint16(126) dg.addString('Magic Words are reserved for administrators only!') self.air.send(dg) return target = self.air.doId2do.get(targetId) if not target: self.sendUpdateToAvatarId(invokerId, 'sendMagicWordResponse', ['missing target']) return response = spellbook.process(invoker, target, word) if response: self.sendUpdateToAvatarId(invokerId, 'sendMagicWordResponse', [response]) self.air.writeServerEvent('magic-word', invokerId, invoker.getAdminAccess(), targetId, target.getAdminAccess(), word, response)
def submitSecret(self, requesterId, secret): """ Submits a "secret" back to the database server for validation. This attempts to match the indicated string, entered by the user, to a string returned by a previous call to requestSecret(). When the response comes back from the server, a "submitSecretReply" message will be thrown with four parameters: the result code (0 or 1, indicating failure or success), the secret again, the requesterId again, and the number associated with the original secret (that is, the original requesterId). """ datagram = PyDatagram() datagram.addServerHeader( DBSERVER_ID, self.ourChannel, DBSERVER_SUBMIT_SECRET) # Pass in our identifying number, and the string. datagram.addUint32(requesterId) datagram.addString(secret) self.send(datagram)
def send(self, message = None): try: print "username: "******"; password: "******", "+ list(message)[1] + '] Login Request') print_exc()
def setInterestZones(self, interestZoneIds): """ Changes the set of zones that this particular client is interested in hearing about. """ datagram = PyDatagram() # Add message type datagram.addUint16(CLIENT_SET_INTEREST_CMU) for zoneId in interestZoneIds: datagram.addUint32(zoneId) # send the message self.send(datagram) self.interestZones = interestZoneIds[:]
def send(self, username = None, password = None): try: pkg = PyDatagram() pkg.addUint16(Constants.CMSG_AUTH) pkg.addString(username) pkg.addString(password) self.cWriter.send(pkg, self.connection) #self.log('Sent [' + str(Constants.RAND_STRING) + '] Int Request') except: self.log('Bad [' + str(Constants.RAND_STRING) + '] Int Request') print_exc()
def sendRequest108(self, task): if (self.received): print "->Client request:" # Send a request to the server myPyDatagram108 = PyDatagram() prot = 108 change_Health = raw_input('Change in health (-100 to 100):') myPyDatagram108.addUint16(prot) myPyDatagram108.addUint32(change_Health) self.cWriter.send(myPyDatagram108, self.connection) self.received = 0 taskMgr.add(self.receiveResponse108, "healthresponse")
def send(self, args): try: pkg = PyDatagram() pkg.addUint16(Constants.CMSG_ENTER_GAME_NAME) pkg.addString(args) #room name self.cWriter.send(pkg, self.connection) print "RequestEnterGameLobby sent" except: self.log('Bad [' + str(Constants.CMSG_ENTER_GAME_NAME) + '] Login Request') print_exc()
def unregisterForChannel(self, channel): """ Unregister a channel subscription on the Message Director. The Message Director will cease to relay messages to this AIR sent on the channel. """ if channel not in self._registeredChannels: return self._registeredChannels.remove(channel) dg = PyDatagram() dg.addServerControlHeader(CONTROL_REMOVE_CHANNEL) dg.addChannel(channel) self.send(dg)
def sendRequest105(self): if (self.received): print "->Client request:" # Send a request to the server myPyDatagram105 = PyDatagram() prot = 105 chat = raw_input('Insert Chat Message :') myPyDatagram105.addUint16(prot) myPyDatagram105.addString(chat) self.cWriter.send(myPyDatagram105, self.connection) print " sent" self.received = 0
def __handleServerTick(self, dgi): self.serverTickCount = dgi.getUint32() # Let the C++ repository unpack and apply the snapshot onto our objects self.unpackServerSnapshot(dgi) self.notify.debug("Got tick %i and snapshot from server" % self.serverTickCount) # Inform server we got the tick dg = PyDatagram() dg.addUint16(NetMessages.CL_Tick) dg.addUint32(self.serverTickCount) self.sendDatagram(dg)
def send(self, args=[]): try: pkg = PyDatagram() pkg.addUint16(Constants.CMSG_LOGIN) print args pkg.addString(args[0]) pkg.addString(args[1]) self.cWriter.send(pkg, self.connection) except: self.log('Bad [' + str(Constants.CMSG_LOGIN) + '] Login Request') print_exc()
def send(self, kwargs): try: pkg = PyDatagram() pkg.addUint16(Constants.CMSG_POWER_PICKUP) pkg.addInt32(kwargs['powerId']) self.cWriter.send(pkg, self.connection) self.log('Sent [' + str(Constants.CMSG_POWER_PICKUP) + '] RequestPowerUpPickUp') except: self.log('Bad [' + str(Constants.CMSG_POWER_PICKUP) + '] RequestPowerUpPickUp') print_exc()
def sendUpdateToChannel(self, distObj, channelId, fieldName, args): """ Sends a targeted update of a single field to a particular client. The top 32 bits of channelId is ignored; the lower 32 bits should be the client Id of the recipient (i.e. the client's doIdbase). The field update will be sent to the indicated client only. The field must be marked clsend or p2p, and may not be marked broadcast. """ datagram = distObj.dclass.clientFormatUpdate(fieldName, distObj.doId, args) dgi = PyDatagramIterator(datagram) # Reformat the packed datagram to change the message type and # add the target id. dgi.getUint16() dg = PyDatagram() dg.addUint16(CLIENT_OBJECT_UPDATE_FIELD_TARGETED_CMU) dg.addUint32(channelId & 0xffffffff) dg.appendData(dgi.getRemainingBytes()) self.send(dg)
def fromNetString(self, netString): self.tracks.clear() dg = PyDatagram(netString) dgi = PyDatagramIterator(dg) avDoId = dgi.getUint32() favGagId = dgi.getUint8() self.avatar = base.cr.doId2do.get(avDoId, None) self.avatarName = None if not self.avatar else self.avatar.getName() self.favoriteGag = base.cr.attackMgr.getAttackName(favGagId) while dgi.getRemainingSize() > 0: track = GagGlobals.TrackNameById.get(dgi.getUint8()) exp = dgi.getInt16() maxExp = dgi.getInt16() increment = dgi.getInt16() self.tracks[track] = Track(track, exp, maxExp, increment) return avDoId
def getFieldsResponse(self, di): objId = di.getUint32() if objId != self.doId: self.notify.warning('Unexpected doId %d' % objId) return count = di.getUint16() fields = [] for i in range(count): name = di.getString() fields.append(name) retCode = di.getUint8() if retCode != 0: self.notify.warning( 'Failed to retrieve data for object %d' % self.doId) else: values = [] for i in range(count): value = di.getString() values.append(value) for i in range(count): found = di.getUint8() if not found: self.notify.info('field %s is not found' % fields[i]) try: del self.values[fields[i]] except: pass else: self.values[fields[i]] = PyDatagram(values[i]) self.notify.info('got data for %d' % self.doId) if self.gotDataHandler is not None: self.gotDataHandler(self.do, self.dclass) self.gotDataHandler = None if self.doneEvent is not None: messenger.send(self.doneEvent, [self, retCode]) return
def sendRequest107(self, task): if (self.received): print "->Client request:" # Send a request to the server myPyDatagram107 = PyDatagram() prot = 107 attackId = raw_input('Attack Id (0 or 1):') myPyDatagram107.addUint16(prot) myPyDatagram107.addUint32(attackId) self.cWriter.send(myPyDatagram107, self.connection) #print " sent" self.received = 0 taskMgr.add(self.receiveResponse108, "attackresponse")