Added GMCP output for room info and added a mudlet mapper script for
automapping.
Showing
8 changed files
with
142 additions
and
18 deletions
... | @@ -6,13 +6,10 @@ def go(id, params, players, mud, tokens, command): | ... | @@ -6,13 +6,10 @@ def go(id, params, players, mud, tokens, command): |
6 | params = params.strip().lower() | 6 | params = params.strip().lower() |
7 | 7 | ||
8 | room_data = utils.load_object_from_file('rooms/' + players[id]["room"] + '.json') | 8 | room_data = utils.load_object_from_file('rooms/' + players[id]["room"] + '.json') |
9 | tmp_exits = room_data['exits'] | 9 | |
10 | # if the specified exit is found in the room's exits list | 10 | # if the specified exit is found in the room's exits list |
11 | exits = {} | 11 | exits = room_data['exits'] |
12 | for exit, value in tmp_exits.items(): | ||
13 | exits[exit.lower()] = value | ||
14 | 12 | ||
15 | print(exits) | ||
16 | if params in exits: | 13 | if params in exits: |
17 | # go through all the players in the game | 14 | # go through all the players in the game |
18 | for pid, pl in players.items(): | 15 | for pid, pl in players.items(): |
... | @@ -31,12 +28,12 @@ def go(id, params, players, mud, tokens, command): | ... | @@ -31,12 +28,12 @@ def go(id, params, players, mud, tokens, command): |
31 | mud.send_message(id, "An invisible force prevents you from going in that direction.") | 28 | mud.send_message(id, "An invisible force prevents you from going in that direction.") |
32 | return None | 29 | return None |
33 | else: | 30 | else: |
34 | new_room = utils.load_object_from_file('rooms/' + exits[params] + '.json') | 31 | new_room = utils.load_object_from_file('rooms/' + exits[params][0] + '.json') |
35 | if not new_room: | 32 | if not new_room: |
36 | mud.send_message(id, "An invisible force prevents you from going in that direction.") | 33 | mud.send_message(id, "An invisible force prevents you from going in that direction.") |
37 | return None | 34 | return None |
38 | else: | 35 | else: |
39 | players[id]["room"] = exits[params] | 36 | players[id]["room"] = exits[params][0] |
40 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) | 37 | utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"])) |
41 | mud.send_message(id, "You arrive at '{}'".format(new_room['title'])) | 38 | mud.send_message(id, "You arrive at '{}'".format(new_room['title'])) |
42 | 39 | ... | ... |
... | @@ -10,7 +10,13 @@ def look(id, mud, players, tokens): | ... | @@ -10,7 +10,13 @@ def look(id, mud, players, tokens): |
10 | del tokens[0] | 10 | del tokens[0] |
11 | container = True | 11 | container = True |
12 | if len(tokens) == 0: | 12 | if len(tokens) == 0: |
13 | mud.send_room(id, room_data.get('title'), room_data.get('description'), 'exits') | 13 | exits = {} |
14 | for exit_name, exit in room_data.get('exits').items(): | ||
15 | exits[exit_name] = exit[1] | ||
16 | print(room_data) | ||
17 | # clid, name, zone, terrain, description, exits, coords | ||
18 | mud.send_room(id, room_data.get('num'), room_data.get('title'), room_data.get('zone'), | ||
19 | 'City', '', exits, room_data.get('coords')) | ||
14 | mud.send_message(id, room_data.get('title'), color=['bold', 'green']) | 20 | mud.send_message(id, room_data.get('title'), color=['bold', 'green']) |
15 | mud.send_message(id, room_data.get('description'), line_ending='\r\n\r\n', color='green') | 21 | mud.send_message(id, room_data.get('description'), line_ending='\r\n\r\n', color='green') |
16 | else: | 22 | else: | ... | ... |
mudletmapper.xml
0 → 100644
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <!DOCTYPE MudletPackage> | ||
3 | <MudletPackage version="1.001"> | ||
4 | <ScriptPackage> | ||
5 | <Script isActive="yes" isFolder="no"> | ||
6 | <name>mapper</name> | ||
7 | <packageName></packageName> | ||
8 | <script>mudlet = mudlet or {}; mudlet.mapper_script = true | ||
9 | |||
10 | exitmap = { | ||
11 | n = 1, | ||
12 | north = 1, | ||
13 | ne = 2, | ||
14 | northeast = 2, | ||
15 | nw = 3, | ||
16 | northwest = 3, | ||
17 | e = 4, | ||
18 | east = 4, | ||
19 | w = 5, | ||
20 | west = 5, | ||
21 | s = 6, | ||
22 | south = 6, | ||
23 | se = 7, | ||
24 | southeast = 7, | ||
25 | sw = 8, | ||
26 | southwest = 8, | ||
27 | u = 9, | ||
28 | up = 9, | ||
29 | d = 10, | ||
30 | down = 10, | ||
31 | ["in"] = 11, | ||
32 | out = 12, | ||
33 | [1] = "north", | ||
34 | [2] = "northeast", | ||
35 | [3] = "northwest", | ||
36 | [4] = "east", | ||
37 | [5] = "west", | ||
38 | [6] = "south", | ||
39 | [7] = "southeast", | ||
40 | [8] = "southwest", | ||
41 | [9] = "up", | ||
42 | [10] = "down", | ||
43 | [11] = "in", | ||
44 | [12] = "out", | ||
45 | } | ||
46 | |||
47 | function doSpeedWalk() | ||
48 | echo("Path we need to take: " .. table.concat(speedWalkDir, ", ") .. "\n") | ||
49 | echo("Rooms we'll pass through: " .. table.concat(speedWalkPath, ", ") .. "\n") | ||
50 | |||
51 | speedwalk(table.concat(speedWalkDir, " ")) | ||
52 | end | ||
53 | |||
54 | function readNewRoom() | ||
55 | local info = gmcp.Room.Info | ||
56 | |||
57 | addAreaName(info.zone) | ||
58 | addRoom(info.num) | ||
59 | setRoomCoordinates(info.num, info.coord.x, info.coord.y, info.coord.z) | ||
60 | setRoomArea(info.num, info.zone) | ||
61 | centerview(info.num) | ||
62 | display(gmcp) | ||
63 | for direction,num in pairs(info.exits) do | ||
64 | print("Creating exit: " .. direction) | ||
65 | if direction == "east" then | ||
66 | setExitStub(info.num, exitmap.e, true) | ||
67 | connectExitStub(info.num, exitmap.e) | ||
68 | elseif direction == "west" then | ||
69 | setExitStub(info.num, exitmap.w, true) | ||
70 | connectExitStub(info.num, exitmap.w) | ||
71 | elseif direction == "north" then | ||
72 | setExitStub(info.num, exitmap.n, true) | ||
73 | connectExitStub(info.num, exitmap.n) | ||
74 | elseif direction == "south" then | ||
75 | setExitStub(info.num, exitmap.s, true) | ||
76 | connectExitStub(info.num, exitmap.s) | ||
77 | end | ||
78 | end | ||
79 | print("Mapper test: " .. info.zone) | ||
80 | end | ||
81 | |||
82 | registerAnonymousEventHandler("gmcp.Room.Info", "readNewRoom")</script> | ||
83 | <eventHandlerList/> | ||
84 | </Script> | ||
85 | </ScriptPackage> | ||
86 | </MudletPackage> |
... | @@ -13,6 +13,7 @@ import select | ... | @@ -13,6 +13,7 @@ import select |
13 | import time | 13 | import time |
14 | import sys | 14 | import sys |
15 | import struct | 15 | import struct |
16 | import json | ||
16 | 17 | ||
17 | from utils import get_color, get_color_list, multiple_replace | 18 | from utils import get_color, get_color_list, multiple_replace |
18 | 19 | ||
... | @@ -67,6 +68,7 @@ class MudServer(object): | ... | @@ -67,6 +68,7 @@ class MudServer(object): |
67 | _MSDP = 69 | 68 | _MSDP = 69 |
68 | _MSSP = 70 | 69 | _MSSP = 70 |
69 | _MXP = 91 | 70 | _MXP = 91 |
71 | _GMCP = 201 | ||
70 | 72 | ||
71 | _MSSP_VAR = 1 | 73 | _MSSP_VAR = 1 |
72 | _MSSP_VAL = 2 | 74 | _MSSP_VAL = 2 |
... | @@ -241,7 +243,11 @@ class MudServer(object): | ... | @@ -241,7 +243,11 @@ class MudServer(object): |
241 | # stop listening for new clients | 243 | # stop listening for new clients |
242 | self._listen_socket.close() | 244 | self._listen_socket.close() |
243 | 245 | ||
244 | def send_room(self, clid, name, description, exits): | 246 | def send_room(self, clid, num, name, zone, terrain, details, exits, coords): |
247 | if self._clients[clid].GMCP_ENABLED: | ||
248 | room = 'Room.Info {"num": %i, "name":"%s","zone":"%s","terrain":"%s","details":"%s","exits":%s,"coord":%s}' % (num, name, zone, terrain, details, json.dumps(exits), json.dumps(coords)) | ||
249 | print(room) | ||
250 | self.gmcp_message(clid, room) | ||
245 | if self._clients[clid].MXP_ENABLED: | 251 | if self._clients[clid].MXP_ENABLED: |
246 | self.mxp_secure(clid, name, 10) | 252 | self.mxp_secure(clid, name, 10) |
247 | 253 | ||
... | @@ -285,6 +291,16 @@ class MudServer(object): | ... | @@ -285,6 +291,16 @@ class MudServer(object): |
285 | else: | 291 | else: |
286 | self.send_message(clid, ', '.join(list_items)) | 292 | self.send_message(clid, ', '.join(list_items)) |
287 | 293 | ||
294 | def gmcp_message(self, clid, message): | ||
295 | byte_data = bytearray([self._TN_IAC, self._TN_SUB_START, self._GMCP]) | ||
296 | byte_data.extend(message.encode()) | ||
297 | byte_data.extend([self._TN_IAC, self._TN_SUB_END]) | ||
298 | |||
299 | print("SENDING GMCP") | ||
300 | print(byte_data) | ||
301 | client_socket = self._clients[clid].socket | ||
302 | client_socket.sendall(byte_data) | ||
303 | |||
288 | def mxp_secure(self, clid, message, mxp_code="1"): | 304 | def mxp_secure(self, clid, message, mxp_code="1"): |
289 | bytes_to_send = bytearray("\x1b[{}z{}\x1b[3z\r\n".format(mxp_code, message), 'utf-8') | 305 | bytes_to_send = bytearray("\x1b[{}z{}\x1b[3z\r\n".format(mxp_code, message), 'utf-8') |
290 | client_socket = self._clients[clid].socket | 306 | client_socket = self._clients[clid].socket |
... | @@ -355,8 +371,8 @@ class MudServer(object): | ... | @@ -355,8 +371,8 @@ class MudServer(object): |
355 | MSSP_REQUEST = bytearray([self._TN_IAC, self._TN_WILL, self._MSSP]) | 371 | MSSP_REQUEST = bytearray([self._TN_IAC, self._TN_WILL, self._MSSP]) |
356 | joined_socket.sendall(MSSP_REQUEST) | 372 | joined_socket.sendall(MSSP_REQUEST) |
357 | 373 | ||
358 | # MSDP_REQUEST = bytearray([self._TN_IAC, self._TN_WILL, self._MSDP]) | 374 | GMCP_REQUEST = bytearray([self._TN_IAC, self._TN_WILL, self._GMCP]) |
359 | # joined_socket.sendall(MSDP_REQUEST) | 375 | joined_socket.sendall(GMCP_REQUEST) |
360 | 376 | ||
361 | MXP_REQUEST = bytearray([self._TN_IAC, self._TN_WILL, self._MXP]) | 377 | MXP_REQUEST = bytearray([self._TN_IAC, self._TN_WILL, self._MXP]) |
362 | joined_socket.sendall(MXP_REQUEST) | 378 | joined_socket.sendall(MXP_REQUEST) |
... | @@ -585,6 +601,18 @@ class MudServer(object): | ... | @@ -585,6 +601,18 @@ class MudServer(object): |
585 | client.MXP_ENABLED = False | 601 | client.MXP_ENABLED = False |
586 | state = self._READ_STATE_NORMAL | 602 | state = self._READ_STATE_NORMAL |
587 | 603 | ||
604 | elif c == self._GMCP: | ||
605 | if option_support == self._TN_DO: | ||
606 | print("GMCP Enabled") | ||
607 | client.GMCP_ENABLED = True | ||
608 | # Enable for mushclient "on command" | ||
609 | byte_data = bytearray([self._TN_IAC, self._TN_SUB_START, self._MXP, self._TN_IAC, self._TN_SUB_END]) | ||
610 | client.socket.sendall(byte_data) | ||
611 | else: | ||
612 | print("GMCP Disabled") | ||
613 | client.GMCP_ENABLED = False | ||
614 | state = self._READ_STATE_NORMAL | ||
615 | |||
588 | elif c == self._MSSP: | 616 | elif c == self._MSSP: |
589 | if option_support == self._TN_DO: | 617 | if option_support == self._TN_DO: |
590 | self._send_mssp(client) | 618 | self._send_mssp(client) | ... | ... |
1 | { | 1 | { |
2 | "num": 1002, | ||
3 | "coords": { "id": 1000, "x": 1, "y": 0, "z": 0 }, | ||
2 | "look_items": { | 4 | "look_items": { |
3 | "wooden,oak,plank": "An old solid oak plank that has a large number of chips and drink marks.", | 5 | "wooden,oak,plank": "An old solid oak plank that has a large number of chips and drink marks.", |
4 | "barrel,barrels": "The old barrels bands are thick with oxidation and stained with the purple of spilled wine.", | 6 | "barrel,barrels": "The old barrels bands are thick with oxidation and stained with the purple of spilled wine.", |
... | @@ -11,8 +13,8 @@ | ... | @@ -11,8 +13,8 @@ |
11 | }] | 13 | }] |
12 | }, | 14 | }, |
13 | "exits": { | 15 | "exits": { |
14 | "tavern": "town/tavern" | 16 | "tavern": ["town/tavern", 1001] |
15 | }, | 17 | }, |
16 | "title": "Behind the bar", | 18 | "title": "Behind the bar", |
17 | "zone": "town", | 19 | "zone": "town" |
18 | } | 20 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | { | 1 | { |
2 | "num": 1001, | ||
3 | "coords": { "id": 1000, "x": 0, "y": 0, "z": 0}, | ||
2 | "look_items": { | 4 | "look_items": { |
3 | "wooden,oak,plank": "An old solid oak plank that has a large number of chips and drink marks.", | 5 | "wooden,oak,plank": "An old solid oak plank that has a large number of chips and drink marks.", |
4 | "barrel,barrels": "The old barrels bands are thick with oxidation and stained with the purple of spilled wine.", | 6 | "barrel,barrels": "The old barrels bands are thick with oxidation and stained with the purple of spilled wine.", |
... | @@ -17,8 +19,8 @@ | ... | @@ -17,8 +19,8 @@ |
17 | }] | 19 | }] |
18 | }, | 20 | }, |
19 | "exits": { | 21 | "exits": { |
20 | "behind": "town/room001", | 22 | "behind": ["town/room001", 1002], |
21 | "west": "wilderness/outside" | 23 | "west": ["wilderness/outside", 2001] |
22 | }, | 24 | }, |
23 | "title": "Tavern", | 25 | "title": "Tavern", |
24 | "zone":"town" | 26 | "zone":"town" | ... | ... |
1 | { | 1 | { |
2 | "num": 2001, | ||
3 | "coords": { "id": 2000, "x": -1, "y": 0, "z": 0 }, | ||
2 | "look_items": { | 4 | "look_items": { |
3 | "tavern": "A roughly constructed building." | 5 | "tavern": "A roughly constructed building." |
4 | }, | 6 | }, |
5 | "description": "You are standing outside of a simple tavern made of pressed clay and shale roof. The door becons you to come in and have a drink.", | 7 | "description": "You are standing outside of a simple tavern made of pressed clay and shale roof. The door becons you to come in and have a drink.", |
6 | "inventory": {}, | 8 | "inventory": {}, |
7 | "exits": { | 9 | "exits": { |
8 | "east": "town/tavern" | 10 | "east": ["town/tavern", 1001] |
9 | }, | 11 | }, |
10 | "title": "Outside the Tavern", | 12 | "title": "Outside the Tavern", |
11 | "zone": "wilderness" | 13 | "zone": "town" |
12 | } | 14 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment