def main(): data = "abcdefghijklmnopqrstuvxz" server_address = ('localhost', 6000) socket = CarcaSocket() server = CarcaServer(socket, data) server.listen(server_address) encoded_data = server.receive_data() encoded_data = utils.string_from_segments(encoded_data) encoded_data = utils.parse_from_string(encoded_data) print(encoded_data)
def test_parsing_object_with_non_stock_flag(self): text = """#42 thing~ thing~ A thing is here.~ ~ 5 abcM 8193 0 4 6 6 22 100000 25000 $ """ objs, errors = parse_from_string(text, parse_object, split_on_vnums) thing = objs.pop() self.assertEqual(len(thing['effects']), 4) expected = { 'value': 274877906944, 'note': None } self.assertIn(expected, thing['effects'])
def test_parsing_objects(self): text = """#12020 thunderbolt jupiter~ Jupiter's Thunderbolt~ Jupiter's Thunderbolt has been left here.~ ~ 5 bgkmn 8193 0 4 6 6 22 100000 25000 A 18 3 A 19 3 #15005 telescope scope~ a large telescope~ There is a large telescope here, pointing at the sky.~ ~ 12 0 0 0 0 0 0 0 0 0 E telescope scope~ A small sign says: Made in Siberia. ~ A 18 2 A 19 2 $ """ expected = [ { "weight": 22, "wear": [ { "value": 1, "note": "WEAR_TAKE" }, { "value": 8192, "note": "WEAR_WIELD" } ], "id": 12020, "values": [ 0, 4, 6, 6 ], "type": { "value": 5, "note": "WEAPON" }, "affects": [ { "value": 3, "note": "HITROLL", "location": 18 }, { "value": 3, "note": "DAMROLL", "location": 19 } ], "aliases": [ "thunderbolt", "jupiter" ], "cost": 100000, "extra_descs": [], "effects": [ { "value": 2, "note": "HUM" }, { "value": 64, "note": "MAGIC" }, { "value": 1024, "note": "ANTI_EVIL" }, { "value": 4096, "note": "ANTI_MAGIC_USER" }, { "value": 8192, "note": "ANTI_CLERIC" } ], "long_desc": "Jupiter's Thunderbolt has been left here.", "rent": 25000, "short_desc": "Jupiter's Thunderbolt" }, { "weight": 0, "wear": [], "id": 15005, "values": [ 0, 0, 0, 0 ], "type": { "value": 12, "note": "OTHER" }, "affects": [ { "value": 2, "note": "HITROLL", "location": 18 }, { "value": 2, "note": "DAMROLL", "location": 19 } ], "aliases": [ "telescope", "scope" ], "cost": 0, "extra_descs": [ { "keywords": [ "telescope", "scope" ], "desc": "A small sign says:\n\nMade in Siberia.\n" } ], "effects": [], "long_desc": "There is a large telescope here, pointing at the sky.", "rent": 0, "short_desc": "a large telescope" } ] objs, errors = parse_from_string(text, parse_object, split_on_vnums) self.assertEqual(objs, expected)
def test_parsing_type_e_mob(self): e_type = self.text.replace('ablno d 900 S', 'ablno d 900 E') e_type += '\nBareHandAttack: 4\nInt: 25\nE' mobs, errors = parse_from_string(e_type, parse_mob, split_on_vnums) expected = dict(BareHandAttack=4, Int=25) self.assertDictEqual(mobs[0]['extra_spec'], expected)
def test_parsing_type_s_mob(self): mobs, errors = parse_from_string(self.text, parse_mob, split_on_vnums) mob = mobs.pop() expected = { "xp": 160000, "id": 3000, "thac0": 2, "extra_spec": {}, "detail_desc": "The wizard looks old and senile, and yet he looks like a very powerful\nwizard. He is equipped with fine clothing, and is wearing many fine\nrings and bracelets.", "bare_hand_damage": { "sides": 8, "dice": 2, "bonus": 18 }, "armor_class": 2, "alignment": 900, "aliases": [ "wizard" ], "affects": [ { "value": 8, "note": "DETECT_INVIS" } ], "flags": [ { "value": 1, "note": "SPEC" }, { "value": 2, "note": "SENTINEL" }, { "value": 2048, "note": "MEMORY" }, { "value": 8192, "note": "NOCHARM" }, { "value": 16384, "note": "NOSUMMON" } ], "gender": { "value": 1, "note": "M" }, "gold": 30000, "level": 33, "long_desc": "A wizard walks around behind the counter, talking to himself.", "max_hit_points": { "sides": 1, "dice": 1, "bonus": 30000 }, "mob_type": "S", "position": { "load": { "value": 8, "note": "POSITION_STANDING" }, "default": { "value": 8, "note": "POSITION_STANDING" } }, "short_desc": "the wizard" } self.assertEqual(mob, expected)
def test_parsing_rooms(self): text = """#3028 The Thieves' Bar~ The bar of the thieves. Once upon a time this place was beautifully furnished, but now it seems almost empty. To the south is the yard, and to the west is the entrance hall. (Maybe the furniture has been stolen?!) ~ 30 cdh 0 D2 You see the secret yard. ~ ~ 0 -1 3029 D3 You see the entrance hall to the thieves' guild. ~ ~ 0 -1 3027 E furniture~ As you look at the furniture, the chair you sit on disappears. Also with multiple lines. ~ E other~ A different thing. ~ S #3029 The Secret Yard~ The secret practice yard of thieves and assassins. To the north is the bar. A well leads down into darkness. ~ 30 cd 0 D0 You see the bar. ~ ~ 0 -1 3028 D5 You can't see what is down there, it is too dark. Looks like it would be impossible to climb back up. ~ ~ 0 -1 7043 S """ expected = [ { "zone_number": 30, "id": 3028, "sector_type": { "value": 0, "note": "INSIDE" }, "name": "The Thieves' Bar", "flags": [ { "value": 4, "note": "NOMOB" }, { "value": 8, "note": "INDOORS" }, { "value": 128, "note": "NOMAGIC" } ], "extra_descs": [ { "keywords": [ "furniture" ], "desc": "As you look at the furniture, the chair you sit on disappears.\nAlso with multiple lines." }, { "keywords": [ "other" ], "desc": "A different thing." } ], "exits": [ { "room_linked": 3029, "keywords": [], "key_number": -1, "door_flag": { "value": 0, "note": "NO_DOOR" }, "dir": 2, "desc": "You see the secret yard." }, { "room_linked": 3027, "keywords": [], "key_number": -1, "door_flag": { "value": 0, "note": "NO_DOOR" }, "dir": 3, "desc": "You see the entrance hall to the thieves' guild." } ], "desc": "The bar of the thieves. Once upon a time this place was beautifully\nfurnished, but now it seems almost empty. To the south is the yard, and to\nthe west is the entrance hall.\n (Maybe the furniture has been stolen?!)" }, { "zone_number": 30, "id": 3029, "sector_type": { "value": 0, "note": "INSIDE" }, "name": "The Secret Yard", "flags": [ { "value": 4, "note": "NOMOB" }, { "value": 8, "note": "INDOORS" } ], "extra_descs": [], "exits": [ { "room_linked": 3028, "keywords": [], "key_number": -1, "door_flag": { "value": 0, "note": "NO_DOOR" }, "dir": 0, "desc": "You see the bar." }, { "room_linked": 7043, "keywords": [], "key_number": -1, "door_flag": { "value": 0, "note": "NO_DOOR" }, "dir": 5, "desc": "You can't see what is down there, it is too dark. Looks like it would be\nimpossible to climb back up." } ], "desc": "The secret practice yard of thieves and assassins. To the north is the\nbar. A well leads down into darkness." } ] rooms, errors = parse_from_string(text, parse_room, split_on_vnums) self.assertListEqual(rooms, expected)
def show_data(self): encoded_data = self._byte_list encoded_data = utils.string_from_segments(encoded_data) decoded_data = utils.parse_from_string(encoded_data) print(decoded_data)
def recvfrom(self, buffer): data, sender_address = super(CarcaSocket, self).recvfrom(buffer) return utils.parse_from_string(data), sender_address