def connect(host, port, username, password, app): # Attempt to connect to the specified server by creating a client # object. If successful pass the client back to the main application, # otherwise display an error status message and let the user try # again: client = RounderNetworkClient(app) try: client.connect(host, port, username, password) except Exception, e: logger.error("Unable to login to %s as %s" % (host, username))
def __init__(self, host, port, username, password): self.host = host self.port = port self.username = username self.password = password self.client = RounderNetworkClient(self) self.client.connect(self.host, self.port, self.username, self.password)
class RandomBot(Client): """ An extremely stupid bot. Connects to the given server, opens the first table it can, takes an open seat, and proceeds to act completely randomly. """ def __init__(self, host, port, username, password): self.host = host self.port = port self.username = username self.password = password self.client = RounderNetworkClient(self) self.client.connect(self.host, self.port, self.username, self.password) def connect_success(self, perspective): logger.info("Connected to %s as %s." % (self.host, self.username)) tables = self.client.get_table_list() def list_tables_success(self, table_listings): logger.debug("got list of tables:") # Attempt to open the first table: self.client.open_table(table_listings[0].id) def open_table_success(self, table_uplink): logger.debug("Opened table: %s" % table_uplink.table_id) client_table = RandomBotTable(table_uplink) table_uplink.ui = client_table # Find and take the first available seat: for i in range(10): if table_uplink.state.seats[i] == None: table_uplink.sit(i) break