Commit 8f0d857d authored by m!nus's avatar m!nus

removed obsolete list types

changed __repr__ to __str__
parent b49acfe7
import re
import logging
logging.basicConfig(format="[%(asctime)s] %(levelname)s: %(funcName)s: %(message)s", level=logging.DEBUG)
L = logging.getLogger(__name__)
from .server import Server
from .player import Player
class ServerList(object):
def __init__(self):
self.servers = []
def add(self, server):
if not isinstance(server, Server):
raise Exception('Trying to add non-Server object')
self.servers.append(server)
def find(self, **kwargs):
output = ServerList()
for server in self.servers:
if server.match(**kwargs):
output.add(server)
return output
def sort(self, cmp=None, key=None, reverse=False):
self.servers.sort(cmp, key, reverse)
def reverse(self):
self.players.reverse()
def __iter__(self):
return iter(self.servers)
def __repr__(self):
return str(self.servers)
class PlayerList(object):
def __init__(self):
self.players = []
def add(self, player):
if not isinstance(player, Player):
raise Exception('Trying to add non-Player-object')
self.players.append(player)
def find(self, name=None, clan=None, country=None, playing=None, server=None):
output = PlayerList()
if name: name = re.compile(name, re.IGNORECASE)
if clan: clan = re.compile(clan, re.IGNORECASE)
for player in self.players:
if (name == None or name.search(player.name)) and \
(clan == None or clan.search(player.clan)) and \
(country == None or player.country == country) and \
(server == None or player.server == server) and \
(playing == None or player.playing == playing):
output.add(player)
return output
def sort(self, cmp=None, key=None, reverse=False):
self.players.sort( cmp, key, reverse)
def reverse(self):
self.players.reverse()
def __iter__(self):
return iter(self.players)
def __repr__(self):
return str(self.players)
\ No newline at end of file
......@@ -92,7 +92,7 @@ class MasterServer(object):
self.on_count_receive(self.count)
L.debug("Count: {}".format(self.count))
def __repr__(self):
def __str__(self):
return "<MasterServer name='{name}' address='{address}' servers='{server_count}'>".format(name=self.name, address=self.address, server_count=len(self.serverlist))
"""
......
......@@ -11,5 +11,5 @@ class Player(object):
self.server = None
self.playing = None
def __repr__(self):
def __str__(self):
return "<Player name='{name}'>".format(name=self.name)
......@@ -101,7 +101,7 @@ class Server(object):
raise
self.on_info_receive(self)
def __repr__(self):
def __str__(self):
return "<Server name='{name}' address='{address}' master='{master}'>".format(**self.__dict__)
"""
......
......@@ -26,9 +26,9 @@ from .base import get_address
from .master import MasterServer
def create_masters(eventsocket):
def create_masters(eventsocket, hostnames=["master{}.teeworlds.com".format(i+1) for i in range(4)]):
masterlist = []
for mastername in ["master{}.teeworlds.com".format(i+1) for i in range(4)]:
for mastername in hostnames:
# resolves host and picks the first address
master_addr = get_address(mastername, port=8300)
if master_addr:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment