Exemple #1
0
 def handle_call_vote(self, data):
     """Recive vote log line and parse it"""
     # TODO: use regex here to avoid false positives
     if data.find("' voted option '") != -1:
         if self.settings.get("debug"):
             say("[VOTES] skip force on option vote")
         return
     if self.settings.get("votes_force") != 0:
         if self.settings.get("votes_blocked_reasons") is None:
             rcon_exec("vote no")
         else:
             match = re.match(
                 r'.*server\]: \'.+\' voted (spectate|kick) \'.+\' '
                 r'reason=\'(.+)\' cmd=\'.*', data)
             if match:
                 reason = match.group(2)
                 if self.is_blocked_reason(reason):
                     rcon_exec("vote no")
                     say("[ANTI-FUNVOTE] please provide a better reason.")
             else:
                 say("[WARNING] Vote parsing error. Please contact a admin.")
     if self.settings.get("votes_discord") != 0:
         self.chat_controller.admin_contact_msg()
     if self.settings.get("votes_discord") == 2:
         send_discord("vote called " + str(self.settings.get("mod_discord"))
             + "!\n" + str(data[:data.find(" cmd='ban")]))
 def handle_player_team(self, data):
     """Parse 'team_join' message"""
     global CONNECTED_PLAYERS
     id_start = data.find("'") + 1
     id_end = base.generic.cfind(data, ":", 2)
     id_str = data[id_start:id_end]
     player = self.get_player_by_id(id_str)
     if player is None:
         if self.settings.get("hotplug") == 1:
             return
         say("[ERROR] teamchange failed id=" + str(id_str) + " data=" +
             str(data))
         self.debug_player_list()
         sys.exit(1)
     team = "invalid"
     data_end = data[-5:]
     change = data_end.rfind(">")
     if change != -1:
         team = data_end[change + 1:]
     else:
         team = str(data[data.rfind("=") + 1:])
     if team == "0":
         player.team = "red"
     elif team == "1":
         player.team = "blue"
     elif team == "-1":
         player.team = "spectator"
     else:
         say("[ERROR] invalid team=" + str(team))
         sys.exit(1)
     name_start = base.generic.cfind(data, ":", 2) + 1
     name_end = data.rfind("'")
     name = data[name_start:name_end]
     if player.name is None:
         # player just joined and still has to be loaded
         self.delete_player(player.cid)  # delete invalid tmp player
         self.create_player(name, player.cid, player.ip_addr, player.team)
         locked = locked_names.get_instance()
         if not locked.check(name, player.ip_addr):
             rcon_exec("kick " + str(player.cid) + " please change name")
     elif player.name != name:
         # https://github.com/chillavanilla/TeeworldsEconMod/issues/49
         # it is very rare but possible that one joins without name
         # the during join the placeholder (connecting) is shown in the logs
         # but later the actual name is used
         if player.name == "(connecting)":
             say("[WARNING] untracked namechange from '" + player.name +
                 "' to '" + name + "'")
             player.name = name
         else:
             say("[ERROR] untracked namechange from '" + player.name +
                 "' to '" + name + "'")
             say('[ERROR] data=' + data)
             sys.exit(1)
 def handle_name_change(self, data):
     """Parse 'changed name to' chat message"""
     old_start = data.find("'") + 1
     old_end = data.find("' changed name to '")
     old = data[old_start:old_end]
     new_start = old_end + len("' changed name to '")
     new_end = data.rfind("'")
     new = data[new_start:new_end]
     team = ""
     player = self.get_player_by_name(old)
     if not player:
         if self.settings.get("hotplug") == 1:
             return
         say("[ERROR] name_change player not found name=" + str(old))
         sys.exit(1)
     team = player.team
     self.save_and_delete_player_by_name(old)
     self.create_player(new, player.cid, player.ip_addr, team=team)
     locked = locked_names.get_instance()
     if not locked.check(new, player.ip_addr):
         rcon_exec("kick " + str(player.cid) + " please change name")