class Client(LineReceiver): def __init__(self, players, world): self.evaluator = Eval() self.world = world self.players = players self.character = None def purge_connection(self): if getattr(self, 'character', None): del self.players[self.character.name.lower()] self.character = None def connectionMade(self): self.purge_connection() return self.evaluator.initialize(self) def connectionLost(self, reason): """ XXX This really needs to do magic with the Server use self.server.remove_client() """ self.purge_connection() self.transport.loseConnection() def lineReceived(self, line): if line: #try: return self.evaluator.evaluate(self, line) #except: # self.transport.loseConnection() def send(self, msg, protocol=None): protocol = protocol if protocol else self protocol.sendLine("%s" % msg) def broadcast(self, msg, scope=SCOPES["room"], protocol=None, send2self=True): for name, protocol in self.players.iteritems(): if not send2self and name == self.character.name.lower(): continue if scope(self, protocol): self.send(msg, protocol=protocol)
def __init__(self, players, world): self.evaluator = Eval() self.world = world self.players = players self.character = None