def init_player(self, data, address, pl_id): #check if name already exists name = data.player.chat i = 1 namegen = chain(self.players.itervalues(), self.specs.itervalues()) while name in [p.name for p in namegen]: name = data.player.chat + '_' + str(i) i += 1 player = Player(True, self.projectiles.add_projectile, pl_id) player.timer = 0 player.address = address player.name = name player.colstring = data.input.name print ' '.join((str(datetime.now()), player.name, str(pl_id), 'joined the server', str(address))) player.time = 0 self.specs[pl_id] = player tosendplayer = proto.Player() tosendplayer.id = pl_id tosendplayer.chat = player.name #send info do newly connected player own = proto.Message() player = proto.Player() own.type = proto.connectResponse player.id = pl_id player.chat = self.specs[pl_id].name inpt = proto.Input() inpt.time = 0 inpt.name = self.map.name own.input.CopyFrom(inpt) own.player.CopyFrom(player) self.ackman.send_rel(own, address) #send other players to player for idx, p in self.players.iteritems(): if idx != pl_id: #other players other = proto.Message() player = self.players_pack[idx] player.chat = p.name other.type = proto.newPlayer other.player.CopyFrom(player) other.gameState = proto.wantsJoin inpt = proto.Input() inpt.name = p.colstring other.input.CopyFrom(inpt) self.ackman.send_rel(other, address) #other.type = proto.playerUpdate new = proto.Message() new.type = proto.newPlayer #player = self.players_pack[pl_id] new.gameState = proto.goesSpec new.player.CopyFrom(tosendplayer) inpt = proto.Input() inpt.name = self.specs[pl_id].colstring new.input.CopyFrom(inpt) self.ackman.send_rel(new, p.address) for idx, p in self.specs.iteritems(): if idx != pl_id: other = proto.Message() player = proto.Player() player.id = idx player.chat = p.name other.type = proto.newPlayer other.player.CopyFrom(player) other.gameState = proto.goesSpec inpt = proto.Input() inpt.name = p.colstring other.input.CopyFrom(inpt) self.ackman.send_rel(other, address) new = proto.Message() new.type = proto.newPlayer #player = self.players_pack[pl_id] new.gameState = proto.goesSpec new.player.CopyFrom(tosendplayer) inpt = proto.Input() inpt.name = self.specs[pl_id].colstring new.input.CopyFrom(inpt) self.ackman.send_rel(new, p.address) #TODO: send map status self.map.items.send_mapstate(self.gamestate.send_mapupdate, address)