def test_base_85(self): mmdb_parser = MMDBParser("./text.mdb") n = 11 num_str = mmdb_parser.write_base_85(n) self.assertEqual(b"!!!!,", num_str) new_n = mmdb_parser.read_base_85(num_str) self.assertEqual(n, new_n) print(mmdb_parser.read_base_85(b"!!!!\""))
def test_system_message_ext_msg_handling(self): # tests SystemMessage with an ExtendedMessage containing a reference param mmdb_parser = MMDBParser("../../text.mdb") bot = Tyrbot() bot.mmdb_parser = mmdb_parser packet = SystemMessage.from_bytes(b'\x00\x05\xc0\xbe\x00\x00\x00\x00\x03@\xe2E\x00\x05l\x0f\xcf\xcaw') packet = bot.system_message_ext_msg_handling(packet) self.assertEqual("Could not send message to offline player: the message is too big to fit in the inbox", packet.extended_message.get_message())
def test_public_channel_message_ext_msg_handling(self): # tests PublicChannelMessage with an ExtendedMessage containing a tower attack mmdb_parser = MMDBParser("../../text.mdb") bot = Tyrbot() bot.mmdb_parser = mmdb_parser packet = PublicChannelMessage.from_bytes(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x53~&!!!&r!5b/RR!!!8S!!!!#s\x09TestOrg1s\x09TestCharR!!!8S!!!!"s\x09TestOrg2s\x05Morti!!!Dui!!!Eu~\x00\x04Test') packet = bot.public_channel_message_ext_msg_handling(packet) self.assertEqual("The omni organization TestOrg1 just entered a state of war! TestChar attacked the clan organization TestOrg2's tower in Mort at location (3059,3144).", packet.extended_message.get_message())
# configure database db = Registry.get_instance("db") if config.database.type == "sqlite": db.connect_sqlite("./data/" + config.database.name) elif config.database.type == "mysql": db.connect_mysql(config.database.host, config.database.username, config.database.password, config.database.name) else: raise Exception("Unknown database type '%s'" % config.database.type) # run db upgrade scripts import upgrade # finish initializing bot and modules, and then connect bot = Registry.get_instance("bot") bot.init(config, Registry, paths, MMDBParser("text.mdb")) bot.connect(config.server.host, config.server.port) if not bot.login(config.username, config.password, config.character): bot.disconnect() time.sleep(5) exit(3) else: status = bot.run() bot.disconnect() exit(status.value) except KeyboardInterrupt: exit(0) except Exception as e: logger = Logger("bootstrap") logger.error("", e)
print( 'You can manually create a config by editing the template /conf/config.template.json and rename it to config.json' ) exit(0) logger.debug("Reading config file '%s'" % config_file) with open(config_file) as cfg: config = json.load(cfg) logger.debug("Loading instances") Registry.load_instances([ "core", os.path.join("modules", "core"), os.path.join("modules", "addons") ]) Registry.add_instance("mmdb_parser", MMDBParser("text.mdb")) Registry.inject_all() bot = Registry.get_instance("mangopie") db = Registry.get_instance("db") db.connect(config["db_host"], config["db_name"]) bot.init(config, Registry) if int(config["dimension"]) == 1: bot.connect("chat.d1.funcom.com", 7105) elif int(config["dimension"]) == 2: bot.connect("chat.dt.funcom.com", 7109) elif int(config["dimension"]) == 3: bot.connect("localhost", 9993) else: print('Invalid server!')
def test_parse_params(self): # param type S mmdb_parser = MMDBParser("../../../text.mdb") params = mmdb_parser.parse_params(b'S\x00\x08TestOrg1') self.assertEqual(["TestOrg1"], params) # param type s mmdb_parser = MMDBParser("../../../text.mdb") params = mmdb_parser.parse_params(b's\x09TestOrg1') self.assertEqual(["TestOrg1"], params) # param type I mmdb_parser = MMDBParser("../../../text.mdb") params = mmdb_parser.parse_params(b'I\x01\x02\x03\x04') self.assertEqual([16909060], params) # param type i, u params = mmdb_parser.parse_params(b'i\x21\x21\x21\x21\x31') self.assertEqual([16], params) # param type R params = mmdb_parser.parse_params(b'R!!!8S!!!!#') self.assertEqual(["omni"], params) # param type l params = mmdb_parser.parse_params(b'l\x0f\xcf\xcaw') self.assertEqual(["the message is too big to fit in the inbox"], params) # multiple params = mmdb_parser.parse_params(b'R!!!8S!!!!#s\x09TestOrg1s\x09TestCharR!!!8S!!!!"s\x09TestOrg2s\x05Testi!!!Dui!!!Eu') self.assertEqual(['omni', 'TestOrg1', 'TestChar', 'clan', 'TestOrg2', 'Test', 3059, 3144], params)
def test_write_param(self): mmdb_parser = MMDBParser("./text.mdb") self.assertEqual(b's\x08Tyrence', mmdb_parser.write_param("s", "Tyrence"))