def sendError(self): print "Error:", self.errorId, self.errorMsg packer = Packer() packer.pack_int(GProtocol.MSG_ERROR) packer.pack_int(self.errorId) packer.pack_string(self.errorMsg) self.writePacker(packer)
def sendTankRemove(self, id): packer = Packer() print "[->] REMOVE_TANK #%d" % (id, ) packer.pack_int(SC_TANK_REMOVE) packer.pack_int(id) self.writePacker(packer)
def sendTankId(self, id): self.tank_ids.append(id) print "[->] TANK_ID #%d" % (id, ) packer = Packer() packer.pack_int(SC_TANK_ID) packer.pack_int(id) self.writePacker(packer)
def sendPlayerJoin(self, playerName): packer = Packer() packer.pack_int(SC_PLAYER_JOIN) packer.pack_string(playerName) self.writePacker(packer)
def sendPlayerLeave(self, playerName): packer = Packer() packer.pack_int(SC_PLAYER_LEAVE) packer.pack_string(playerName) self.writePacker(packer)
def sendHello(self, name): packer = Packer() packer.pack_int(CS_HELLO) packer.pack_string(name) self.writePacker(packer)
def sendTankId(self): packer = Packer() packer.pack_int(CS_TANK_ID) self.writePacker(packer)
packer = Packer() packer.pack_int(CS_TANK_STATE) packer.pack_int(id) packer.pack_float(rot) packer.pack_int(rot_signum) packer.pack_float(speed) packer.pack_int(driving_signum) packer.pack_float(x) packer.pack_float(y) self.writePacker(packer) def sendTankId(self): packer = Packer() packer.pack_int(CS_TANK_ID) self.writePacker(packer) def sendFire(self, tank_id, rotation, (x, y)): print "[->] REQUEST_FIRE <rotation:%f, location:(%f, %f)>" % (rotation, x, y) packer = Packer() packer.pack_int(CS_REQUEST_FIRE) packer.pack_int(tank_id) packer.pack_float(rotation) packer.pack_float(x) packer.pack_float(y) self.writePacker(packer)
self.writePacker(packer) def connectionLost(self, reason): ServerProtocol.connectionLost(self, reason) for id in self.tank_ids: print "[<-] REMOVE_TANK #%d" % (id, ) self.app.tankRemove(id) def sendTankRemove(self, id): packer = Packer() print "[->] REMOVE_TANK #%d" % (id, ) packer.pack_int(SC_TANK_REMOVE) packer.pack_int(id) self.writePacker(packer) def sendFire(self, bullet_id, rotation, (x, y)): packer = Packer() print "[->] FIRE <rotation:%f, location(%f,%f)>" % (rotation, x, y) packer.pack_int(SC_FIRE) packer.pack_int(bullet_id) packer.pack_float(rotation) packer.pack_float(x) packer.pack_float(y) self.writePacker(packer)