def load(self): ''' DataFrame: id, name, key, population, isSubscriberServer ['1','Demo', 'demo', 0, 0,] relevant data: id, key, population, isSubscriberServer ['1', 'key', 'population', 'isSubscriberServer'] ''' connection = dataSource.Database().get_connection() cursor = connection.cursor() try: cursor.execute('SELECT * FROM servers;') data = cursor.fetchall() for result in data: # only relevant data is saved server = Server(result['id'], result['key'], 0, result['population'], result['isSubscriberServer']) self.Datasource.append(server) except pymysql.Error as Error: self.log.warning('server_data.py - Can\'t load table servers - ') self.log.warning(str(Error)) finally: cursor.close() connection.close()
def load_in_to_class(self): ''' DataFrame: ''' self.dataSource = [] connection = dataSource.Database().get_connection() cursor = connection.cursor(dictionary=True) try: cursor.execute('SELECT * FROM players;') data = cursor.fetchall() for result in data: try: # the attributes are the inGame order stats = [result['vitality'], result['wisdom'], result['strength'], result['intelligence'], result['chance'], result['agility']] if result['color1'] == -1: color1 = 'ffffffff' else: color1 = hex(result['color1']).replace("0x","") if result['color2'] == -1: color2 = 'ffffffff' else: color2 = hex(result['color2']).replace("0x","") if result['color3'] == -1: color3 = 'ffffffff' else: color3 = hex(result['color3']).replace("0x","") player = Player(result['id'], result['name'], result['account'], result['group'], result['sexe'], result['class'], color1, color2, color3, result['kamas'], result['spellboost'], result['capital'], result['energy'], result['level'], result['xp'], result['size'], result['gfx'], result['alignement'], result['honor'], result['deshonor'], result['alvl'], stats, result['seeFriend'], result['seeAlign'], result['seeSeller'], result['channel'], result['map'], result['cell'], result['pdvper'], result['spells'], result['objets'], result['storeObjets'], result['savepos'], result['zaaps'], result['jobs'], result['mountxpgive'], result['title'], result['wife'], result['morphMode'], result['emotes'], result['prison'], result['server'], result['logged'], result['allTitle'], result['parcho'], result['timeDeblo'], result['noall'],) self.dataSource.append(player) except: self.log.warning('player_data.py - player:{} can\'t be loaded'.format(result['id'])) return self.dataSource except Exception as Error: self.log.warning('player_data.py - Can\'t load table player') self.log.warning(str(Error)) finally: cursor.close() connection.close()
def singel_update_data(self, query): connection = dataSource.Database().get_connection() cursor = connection.cursor() try: if not query.endswith(';'): query += ";" self.cursor.execute(query) except pymysql.Error as Error: self.log.warning('DAO.py - update_data - Can\'t update the Database\n{}\n{}'.format(str(Error),query)) cursor.close() connection.close() finally: cursor.close() connection.close()
def get_data(self, query): connection = dataSource.Database().get_connection() cursor = connection.cursor() try: if not query.endswith(';'): query += ";" cursor.execute(query) data = cursor.fetchall() return data except Exception as e: self.log.warning('DAO.py - Can\'t load: \n{}\n{}'.format(query,str(e))) cursor.close() connection.close() finally: cursor.close() connection.close()
def start(self): # ====================================================== # start message def clear(): return os.system('cls') clear() def wel(): welmsg = [ 58 * '─', '| 0.01 |' + 12 * ' ' + 'pyCestra - World Server' + 11 * ' ' + '|', 58 * "─" ] for x in welmsg: print(bcolors.blue + x + bcolors.cend) wel() # ====================================================== # connection test self.log.info('Connection Test...') database = dataSource.Database() if database.get_connection(): self.log.info('Connection Successfully') else: self.log.warning('Connection ERROR') sys.exit(0) # ====================================================== # world class test world = World() world.createWorld() # ====================================================== # exchange client test exchangeTransferList = [] exClient = ExchangeClient() exClient.initialize(self.config.get_exchange_ip(), self.config.get_exchange_port(), exchangeTransferList) self.log.debug('Game Server Start') GameServer().initialize(self.config.get_world_ip(), self.config.get_world_port(), exchangeTransferList, world)
def load(self): ''' DataFrame: ''' connection = dataSource.Database().get_connection() cursor = connection.cursor(dictionary=True) try: cursor.execute('SELECT * FROM accounts;') data = cursor.fetchall() for row in data: self.Datasource.append(row) except Exception as Error: self.log.warning(' account_data.py - Can\'t load table accounts') self.log.warning(str(Error)) finally: cursor.close() connection.close()
def load_in_to_class(self): ''' DataFrame: ''' self.dataSource = {} connection = dataSource.Database().get_connection() cursor = connection.cursor(dictionary=True) try: cursor.execute('SELECT * FROM maps;') data = cursor.fetchall() for result in data: try: mapData = Map( result['id'], result['date'], result['width'], result['heigth'], result['key'], result['places'], result['mapData'], result['cells'], result['monsters'], result['mappos'], result['numgroup'], result['fixSize'], result['minSize'], result['maxSize'], result['cases'], result['forbidden'], ) self.dataSource[result['id']] = mapData except Exception as Error: self.log.warning( 'maps_data.py - maps:{} can\'t be loaded'.format( str(result['id']))) self.log.warning(Error) except Exception as Error: self.log.warning('map_data.py - Can\'t load table accounts') self.log.warning(str(Error)) finally: cursor.close() connection.close()
def __init__(self): self.log = Logging() self.connection = dataSource.Database().get_connection() self.cursor = self.connection.cursor()
def main(): # ====================================================== # start message log = Logging() console = Console() console.clear() def wel(): welmsg = [ 58 * '─', '| 0.01 |' + 12 * ' ' + 'pyCestra - Logon Server' + 12 * ' ' + '|', 58 * "─" ] for x in welmsg: print(bcolors.blue + x + bcolors.cend) wel() # ====================================================== # preload data config = Config() config.initialize() log.info('Connection Test...') database = dataSource.Database() if database.get_connection(): log.info('Connection Successfully') else: log.warning('Connection ERROR') sys.exit(0) hostList = dataSource.ServerData() hostList.load() hostList = hostList.get_server_data() log.info('ServerData were loaded') accountData = dataSource.AccountData() accountData.load() accountDataDic = accountData.get_account_data() log.info('AccountData were loaded') ipbans = dataSource.IpBans().load() log.info('IP Bans were loaded') dataSource.DatabaseUpdateService().start(accountDataDic, config.get_update_time()) # ====================================================== # socket tests print(58 * '-') game_client_dic = {} LoginServer(config.get_login_ip(), config.get_login_port(), game_client_dic, accountDataDic, hostList, ipbans) ExchangeServer().start(config.get_exchange_ip(), config.get_exchange_port(), hostList) while True: time.sleep(15) if game_client_dic: log.warning('---- game_client_dic ----') for x in game_client_dic: log.warning(str(x)) log.warning('-------------------------')