c272edb4 by Barry

Added GMCP output for room info and added a mudlet mapper script for

automapping.
1 parent 755ccb1a
......@@ -17,7 +17,8 @@ global_aliases = {
'social': 'emote',
'equipment': 'equip',
'wear': 'equip',
'eq': 'equip'
'eq': 'equip',
'goto': 'go'
}
......
......@@ -6,13 +6,10 @@ def go(id, params, players, mud, tokens, command):
params = params.strip().lower()
room_data = utils.load_object_from_file('rooms/' + players[id]["room"] + '.json')
tmp_exits = room_data['exits']
# if the specified exit is found in the room's exits list
exits = {}
for exit, value in tmp_exits.items():
exits[exit.lower()] = value
exits = room_data['exits']
print(exits)
if params in exits:
# go through all the players in the game
for pid, pl in players.items():
......@@ -31,12 +28,12 @@ def go(id, params, players, mud, tokens, command):
mud.send_message(id, "An invisible force prevents you from going in that direction.")
return None
else:
new_room = utils.load_object_from_file('rooms/' + exits[params] + '.json')
new_room = utils.load_object_from_file('rooms/' + exits[params][0] + '.json')
if not new_room:
mud.send_message(id, "An invisible force prevents you from going in that direction.")
return None
else:
players[id]["room"] = exits[params]
players[id]["room"] = exits[params][0]
utils.save_object_to_file(players[id], "players/{}.json".format(players[id]["name"]))
mud.send_message(id, "You arrive at '{}'".format(new_room['title']))
......
......@@ -10,7 +10,13 @@ def look(id, mud, players, tokens):
del tokens[0]
container = True
if len(tokens) == 0:
mud.send_room(id, room_data.get('title'), room_data.get('description'), 'exits')
exits = {}
for exit_name, exit in room_data.get('exits').items():
exits[exit_name] = exit[1]
print(room_data)
# clid, name, zone, terrain, description, exits, coords
mud.send_room(id, room_data.get('num'), room_data.get('title'), room_data.get('zone'),
'City', '', exits, room_data.get('coords'))
mud.send_message(id, room_data.get('title'), color=['bold', 'green'])
mud.send_message(id, room_data.get('description'), line_ending='\r\n\r\n', color='green')
else:
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MudletPackage>
<MudletPackage version="1.001">
<ScriptPackage>
<Script isActive="yes" isFolder="no">
<name>mapper</name>
<packageName></packageName>
<script>mudlet = mudlet or {}; mudlet.mapper_script = true
exitmap = {
n = 1,
north = 1,
ne = 2,
northeast = 2,
nw = 3,
northwest = 3,
e = 4,
east = 4,
w = 5,
west = 5,
s = 6,
south = 6,
se = 7,
southeast = 7,
sw = 8,
southwest = 8,
u = 9,
up = 9,
d = 10,
down = 10,
[&quot;in&quot;] = 11,
out = 12,
[1] = &quot;north&quot;,
[2] = &quot;northeast&quot;,
[3] = &quot;northwest&quot;,
[4] = &quot;east&quot;,
[5] = &quot;west&quot;,
[6] = &quot;south&quot;,
[7] = &quot;southeast&quot;,
[8] = &quot;southwest&quot;,
[9] = &quot;up&quot;,
[10] = &quot;down&quot;,
[11] = &quot;in&quot;,
[12] = &quot;out&quot;,
}
function doSpeedWalk()
echo(&quot;Path we need to take: &quot; .. table.concat(speedWalkDir, &quot;, &quot;) .. &quot;\n&quot;)
echo(&quot;Rooms we'll pass through: &quot; .. table.concat(speedWalkPath, &quot;, &quot;) .. &quot;\n&quot;)
speedwalk(table.concat(speedWalkDir, &quot; &quot;))
end
function readNewRoom()
local info = gmcp.Room.Info
addAreaName(info.zone)
addRoom(info.num)
setRoomCoordinates(info.num, info.coord.x, info.coord.y, info.coord.z)
setRoomArea(info.num, info.zone)
centerview(info.num)
display(gmcp)
for direction,num in pairs(info.exits) do
print(&quot;Creating exit: &quot; .. direction)
if direction == &quot;east&quot; then
setExitStub(info.num, exitmap.e, true)
connectExitStub(info.num, exitmap.e)
elseif direction == &quot;west&quot; then
setExitStub(info.num, exitmap.w, true)
connectExitStub(info.num, exitmap.w)
elseif direction == &quot;north&quot; then
setExitStub(info.num, exitmap.n, true)
connectExitStub(info.num, exitmap.n)
elseif direction == &quot;south&quot; then
setExitStub(info.num, exitmap.s, true)
connectExitStub(info.num, exitmap.s)
end
end
print(&quot;Mapper test: &quot; .. info.zone)
end
registerAnonymousEventHandler(&quot;gmcp.Room.Info&quot;, &quot;readNewRoom&quot;)</script>
<eventHandlerList/>
</Script>
</ScriptPackage>
</MudletPackage>
......@@ -13,6 +13,7 @@ import select
import time
import sys
import struct
import json
from utils import get_color, get_color_list, multiple_replace
......@@ -67,6 +68,7 @@ class MudServer(object):
_MSDP = 69
_MSSP = 70
_MXP = 91
_GMCP = 201
_MSSP_VAR = 1
_MSSP_VAL = 2
......@@ -241,7 +243,11 @@ class MudServer(object):
# stop listening for new clients
self._listen_socket.close()
def send_room(self, clid, name, description, exits):
def send_room(self, clid, num, name, zone, terrain, details, exits, coords):
if self._clients[clid].GMCP_ENABLED:
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))
print(room)
self.gmcp_message(clid, room)
if self._clients[clid].MXP_ENABLED:
self.mxp_secure(clid, name, 10)
......@@ -285,6 +291,16 @@ class MudServer(object):
else:
self.send_message(clid, ', '.join(list_items))
def gmcp_message(self, clid, message):
byte_data = bytearray([self._TN_IAC, self._TN_SUB_START, self._GMCP])
byte_data.extend(message.encode())
byte_data.extend([self._TN_IAC, self._TN_SUB_END])
print("SENDING GMCP")
print(byte_data)
client_socket = self._clients[clid].socket
client_socket.sendall(byte_data)
def mxp_secure(self, clid, message, mxp_code="1"):
bytes_to_send = bytearray("\x1b[{}z{}\x1b[3z\r\n".format(mxp_code, message), 'utf-8')
client_socket = self._clients[clid].socket
......@@ -355,8 +371,8 @@ class MudServer(object):
MSSP_REQUEST = bytearray([self._TN_IAC, self._TN_WILL, self._MSSP])
joined_socket.sendall(MSSP_REQUEST)
# MSDP_REQUEST = bytearray([self._TN_IAC, self._TN_WILL, self._MSDP])
# joined_socket.sendall(MSDP_REQUEST)
GMCP_REQUEST = bytearray([self._TN_IAC, self._TN_WILL, self._GMCP])
joined_socket.sendall(GMCP_REQUEST)
MXP_REQUEST = bytearray([self._TN_IAC, self._TN_WILL, self._MXP])
joined_socket.sendall(MXP_REQUEST)
......@@ -585,6 +601,18 @@ class MudServer(object):
client.MXP_ENABLED = False
state = self._READ_STATE_NORMAL
elif c == self._GMCP:
if option_support == self._TN_DO:
print("GMCP Enabled")
client.GMCP_ENABLED = True
# Enable for mushclient "on command"
byte_data = bytearray([self._TN_IAC, self._TN_SUB_START, self._MXP, self._TN_IAC, self._TN_SUB_END])
client.socket.sendall(byte_data)
else:
print("GMCP Disabled")
client.GMCP_ENABLED = False
state = self._READ_STATE_NORMAL
elif c == self._MSSP:
if option_support == self._TN_DO:
self._send_mssp(client)
......
{
"num": 1002,
"coords": { "id": 1000, "x": 1, "y": 0, "z": 0 },
"look_items": {
"wooden,oak,plank": "An old solid oak plank that has a large number of chips and drink marks.",
"barrel,barrels": "The old barrels bands are thick with oxidation and stained with the purple of spilled wine.",
......@@ -11,8 +13,8 @@
}]
},
"exits": {
"tavern": "town/tavern"
"tavern": ["town/tavern", 1001]
},
"title": "Behind the bar",
"zone": "town",
"zone": "town"
}
\ No newline at end of file
......
{
"num": 1001,
"coords": { "id": 1000, "x": 0, "y": 0, "z": 0},
"look_items": {
"wooden,oak,plank": "An old solid oak plank that has a large number of chips and drink marks.",
"barrel,barrels": "The old barrels bands are thick with oxidation and stained with the purple of spilled wine.",
......@@ -6,7 +8,7 @@
"fire": "The fire crackles quietly in the corner providing a small amount of light and heat."
},
"description": "You're in a cozy tavern warmed by an open fire.",
"inventory": {
"inventory": {
"candle": [{
"age": 0
}, {
......@@ -17,8 +19,8 @@
}]
},
"exits": {
"behind": "town/room001",
"west": "wilderness/outside"
"behind": ["town/room001", 1002],
"west": ["wilderness/outside", 2001]
},
"title": "Tavern",
"zone":"town"
......
{
"num": 2001,
"coords": { "id": 2000, "x": -1, "y": 0, "z": 0 },
"look_items": {
"tavern": "A roughly constructed building."
},
"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.",
"inventory": {},
"exits": {
"east": "town/tavern"
"east": ["town/tavern", 1001]
},
"title": "Outside the Tavern",
"zone": "wilderness"
"zone": "town"
}
\ No newline at end of file
......