def validate(pkt, protocol): if not isinstance(pkt.clientversion, unicode): raise NetworkException("Invalid datatype: clientversion") if not pkt.clientversion: raise SoftNetworkException("Invalid client version") if protocol == 0: pkt.clientid = uuid.uuid4().hex if not isinstance(pkt.clientid, str): raise NetworkException("Invalid datatype: clientid") if len(pkt.clientid) != 32: raise SoftNetworkException("Invalid unique player ID") if not isinstance(pkt.playername, unicode): raise NetworkException("Invalid datatype: playername") if not pkt.playername: raise SoftNetworkException("Your player name cannot be empty") if protocol == 0: # hardcoded playercolor pkt.playercolor = 1 else: if not isinstance(pkt.playercolor, int): raise NetworkException("Invalid datatype: playercolor") if pkt.playercolor < 1: raise SoftNetworkException("Your color is invalid") if not isinstance(pkt.name, unicode): raise NetworkException("Invalid datatype: name") if not pkt.name: pkt.name = u"Unnamed Game" if not isinstance(pkt.mapname, unicode): raise NetworkException("Invalid datatype: mapname") if not pkt.mapname: raise SoftNetworkException( "You can't run a game with an empty mapname") if not isinstance(pkt.maxplayers, int): raise NetworkException("Invalid datatype: maxplayers") if protocol == 0: if pkt.load is None: pkt.maphash = "" elif isinstance(pkt.load, str): pkt.maphash = pkt.load if not isinstance(pkt.maphash, str): raise NetworkException("Invalid datatype: maphash") if not isinstance(pkt.password, str): raise NetworkException("Invalid datatype: password")
def oncreategame(self, player, packet): if packet.maxplayers < self.capabilities['minplayers']: raise SoftNetworkException( "You can't run a game with less than %d players" % (self.capabilities['minplayers'])) if packet.maxplayers > self.capabilities['maxplayers']: raise SoftNetworkException( "You can't run a game with more than %d players" % (self.capabilities['maxplayers'])) game = Game(packet, player) logging.debug("[CREATE] [%s] %s created %s" % (game.uuid, player, game)) self.games.append(game) self.send(player.peer, packets.server.data_gamestate(game))
def validate(pkt, protocol): if not isinstance(pkt.uuid, str): raise NetworkException("Invalid datatype: uuid") if len(pkt.uuid) != 32: raise SoftNetworkException("Invalid game UUID") if not isinstance(pkt.clientversion, unicode): raise NetworkException("Invalid datatype: clientversion") if not len(pkt.clientversion): raise SoftNetworkException("Invalid client version") if protocol == 0: pkt.clientid = uuid.uuid4().hex if not isinstance(pkt.clientid, str): raise NetworkException("Invalid datatype: clientid") if len(pkt.clientid) != 32: raise SoftNetworkException("Invalid unique player ID") if not isinstance(pkt.playername, unicode): raise NetworkException("Invalid datatype: playername") if not len(pkt.playername): raise SoftNetworkException("Your player name cannot be empty") if protocol == 0: # assign playercolor in packet handler pkt.playercolor = None else: if not isinstance(pkt.playercolor, int): raise NetworkException("Invalid datatype: playercolor") if pkt.playercolor < 1: raise SoftNetworkException("Your color is invalid") if not isinstance(pkt.password, str): raise NetworkException("Invalid datatype: password") if not isinstance(pkt.fetch, bool): raise NetworkException("Invalid datatype: fetch")
def validate(pkt, protocol): if hasattr(pkt, 'lang'): if not isinstance(pkt.lang, str): raise NetworkException("Invalid datatype: lang") if not len(pkt.lang): raise SoftNetworkException("Invalid language property")
def validate(pkt, protocol): if not isinstance(pkt.kicksid, str): raise NetworkException("Invalid datatype: player sid") if len(pkt.kicksid) != 32: raise SoftNetworkException("Invalid player sid")
def validate(pkt, protocol): if not isinstance(pkt.playercolor, int): raise NetworkException("Invalid datatype: playercolor") if pkt.playercolor < 1: raise SoftNetworkException("Your color is invalid")
def validate(pkt, protocol): if not isinstance(pkt.playername, unicode): raise NetworkException("Invalid datatype: playername") if not len(pkt.playername): raise SoftNetworkException("You must have a non empty name")
def validate(pkt, protocol): if not isinstance(pkt.chatmsg, unicode): raise NetworkException("Invalid datatype: chatmsg") if not len(pkt.chatmsg): raise SoftNetworkException("Chat message cannot be empty")