Example #1
0
    def onjoingame(self, peer, packet):
        logging.debug("[JOIN] name=%s, uuid=%s" %
                      (packet.playername, packet.uuid))
        game = None
        for _game in self.games:
            for _player in _game.players:
                if _player.address == peer.address:
                    game = _game
                    break
        if game is not None:
            self.send(
                peer,
                packets.cmd_error(
                    "You can't join a game while in another game"))
            return

        game = None
        for _game in self.games:
            if (packet.clientversion != _game.clientversion):
                continue
            if (packet.uuid != _game.uuid):
                continue
            game = _game
            break
        if game is None:
            self.send(peer, packets.cmd_error("Unknown game"))
            return
        if game.gamestarts:
            self.send(
                peer,
                packets.cmd_error("Game has already started. No more joining"))
            return
        elif game.maxplayers == len(game.players):
            self.send(peer, packets.cmd_error("Game is full"))
            return

        playerunique = True
        for _player in game.players:
            if _player.name == packet.playername:
                playerunique = False
                break
            elif _player.address == peer.address:
                playerunique = False
                break
        if not playerunique:
            self.send(
                peer,
                packets.cmd_error(
                    "Your name or address is already known to this game"))
            return

        game.addplayer(Player(packet.playername, peer))
        game.playercnt += 1
        for _player in game.players:
            self.send(_player.peer, packets.server.data_gamestate(game))

        # if game is full ... lets start the game
        if game.playercnt == game.maxplayers:
            game.gamestarts = True
            self.call_callbacks("holepunching", game)
Example #2
0
	def onjoingame(self, peer, packet):
		logging.debug("[JOIN] name=%s, uuid=%s" % (packet.playername, packet.uuid))
		game = None
		for _game in self.games:
			for _player in _game.players:
				if _player.address == peer.address:
					game = _game
					break
		if game is not None:
			self.send(peer, packets.cmd_error("You can't join a game while in another game"))
			return

		game = None
		for _game in self.games:
			if (packet.clientversion != _game.clientversion):
				continue
			if (packet.uuid != _game.uuid):
				continue
			game = _game
			break
		if game is None:
			self.send(peer, packets.cmd_error("Unknown game"))
			return
		if game.gamestarts:
			self.send(peer, packets.cmd_error("Game has already started. No more joining"))
			return
		elif game.maxplayers == len(game.players):
			self.send(peer, packets.cmd_error("Game is full"))
			return

		playerunique = True
		for _player in game.players:
			if _player.name == packet.playername:
				playerunique = False
				break
			elif _player.address == peer.address:
				playerunique = False
				break
		if not playerunique:
			self.send(peer, packets.cmd_error("Your name or address is already known to this game"))
			return

		game.addplayer(Player(packet.playername, peer))
		game.playercnt += 1
		for _player in game.players:
			self.send(_player.peer, packets.server.data_gamestate(game))

		# if game is full ... lets start the game
		if game.playercnt == game.maxplayers:
			game.gamestarts = True
			self.call_callbacks("holepunching", game)
Example #3
0
	def onpktleavegame(self, peer, packet):
		game = player = None
		for _game in self.games:
			for _player in _game.players:
				if _player.address == peer.address:
					game = _game
					player = _player
					break
		if game is None or player is None:
			self.send(peer, packets.cmd_error("You are an unknown player"))
			return
		self.call_callbacks("leavegame", game, player)
		self.send(peer, packets.cmd_ok())
Example #4
0
	def onchat(self, peer, packet):
		game = player = None
		for _game in self.games:
			for _player in _game.players:
				if _player.address == peer.address:
					game = _game
					player = _player
					break
		if game is None or player is None:
			self.send(peer, packets.cmd_error("You are an unknown player"))
			self.disconnect(peer, True)
			return
		logging.debug("[CHAT] [%s] %s: %s" % (game.uuid, player.name, packet.chatmsg))
		# don't send packets to already started games
		if game.gamestarts:
			return
		for _player in game.players:
			self.send(_player.peer, packets.server.cmd_chatmsg(player.name, packet.chatmsg))
Example #5
0
	def oncreategame(self, peer, packet):
		game = None
		for _game in self.games:
			for _player in _game.players:
				if _player.address == peer.address:
					game = _game
					break
		if game is not None:
			self.send(peer, packets.cmd_error("You can't create a game while in another game"))
			return
		game = Game(packet, peer)
		logging.debug("[CREATE] uuid=%s, maxplayers=%d" % (game.uuid, game.maxplayers))
		self.games.append(game)
		self.send(peer, packets.server.data_gamestate(game))

		if game.playercnt == game.maxplayers:
			game.gamestarts = True
			self.call_callbacks("holepunching", game)
 def _error(self, peer, message, _type=ErrorType.NotSet):
     self.send(peer, packets.cmd_error(message, _type))
Example #7
0
	def _error(self, peer, message, _type=ErrorType.NotSet):
		self.send(peer, packets.cmd_error(message, _type))
	def error(self, peer, message):
		self.send(peer, packets.cmd_error(message))
Example #9
0
	def _error(self, peer: 'enet.Peer', message: Text, _type=ErrorType.NotSet):
		"""
		Send an error message to a client.
		"""
		self.send(peer, packets.cmd_error(message, _type))
	def _error(self, peer: 'enet.Peer', message: Text, _type=ErrorType.NotSet):
		"""
		Send an error message to a client.
		"""
		self.send(peer, packets.cmd_error(message, _type))