fb785eda by Barry

Huge update and added more protocol handling to the mudserver.py

1 parent 51c565a0
......@@ -7,7 +7,7 @@ def look(id, mud, players, tokens):
del tokens[0]
if len(tokens) == 0:
mud.send_message(id, room_data.get('title'), color=['bold', 'green'])
mud.send_message(id, room_data.get('description'), color='green')
mud.send_message(id, room_data.get('description'), line_ending='\r\n\r\n', color='green')
else:
subject = tokens[0]
items = room_data.get('look_items')
......@@ -46,12 +46,13 @@ def look(id, mud, players, tokens):
if len(playershere) > 0:
mud.send_message(id, "%boldPlayers here:%reset {}".format(", ".join(playershere)))
# send player a message containing the list of exits from this room
mud.send_message(id, "%boldObvious Exits:%reset {}".format(", ".join(room_data.get('exits'))))
mud.send_message(id, "%boldObvious Exits:%reset ", line_ending='')
mud.send_list(id, room_data.get('exits'), "go")
# send player a message containing the list of exits from this room
if len(room_data.get('inventory')) > 0:
mud.send_message(id, "%boldItems here:%reset {}".format(", ".join(room_data.get('inventory').keys())))
mud.send_message(id, "%boldItems here:%reset ", line_ending='')
mud.send_list(id, room_data.get('inventory').keys(), "look")
# send player a message containing the list of players in the room
for mon_name, monster in room_monsters.items():
......
def score(id, players, mud):
from math import floor
mud.send_message(id, " %green+----------------------------=Score=---------------------------+", nowrap=True)
hp = str("%d/%d" % (floor(players[id]['hp']), floor(players[id]['maxhp']))).center(12, ' ')
mp = str("%d/%d" % (floor(players[id]['mp']), floor(players[id]['maxmp']))).center(12, ' ')
sta = str("%d/%d" % (floor(players[id]['sta']), floor(players[id]['maxsta']))).center(12, ' ')
mud.send_message(id, " %%green|%%reset%%bold%%white%s%%reset%%green|" % (players[id]["name"].center(62),), nowrap=True)
mud.send_message(id, " %green+--------------------------------------------------------------+", nowrap=True)
mud.send_message(id, " %%green|%%reset %%cyanHP:%%reset %%white[%s]%%reset %%green|%%reset %%cyanMP:%%reset %%white[%s]%%reset %%green|%%reset %%cyanST:%%reset %%white[%s]%%reset %%green|%%reset" % (hp, mp, sta), nowrap=True)
# output = """
# --------------------------------------------
# HP: {hp} Max HP: {maxhp}
# MP: {mp} Max MP: {maxmp}
# Sta: {sta} Max Sta: {maxsta}
# Experience: {exp}
# Skills:""".format(hp=floor(players[id]['hp']),
# mp=floor(players[id]['mp']),
# maxhp=floor(players[id]['maxhp']),
# maxmp=floor(players[id]['maxmp']),
# sta=floor(players[id]['sta']),
# maxsta=floor(players[id]['maxsta']),
# exp=0)
# mud.send_message(id, output)
mud.send_message(id, " %green+---------------------------=Skills=---------------------------+", nowrap=True)
skills = ["skillasdfasdfasdfasdf", "skill 2 sdfg sdfg", "Skill 3 asdf ewrewwr"]
for skill in skills:
mud.send_message(id, " %%green|%%reset %s%%green|%%reset" % (skill.ljust(61),), nowrap=True)
mud.send_message(id, " %green+--------------------------------------------------------------+", nowrap=True)
score(id, players, mud)
del score
\ No newline at end of file
......@@ -2,6 +2,8 @@ def who(id, players, mud):
mud.send_message(id, "")
mud.send_message(id, "-------- {} Players Currently Online --------".format(len(players)))
for pid, player in players.items():
if player["name"] is None:
continue
mud.send_message(id, " " + player["name"])
mud.send_message(id, "---------------------------------------------".format(len(players)))
mud.send_message(id, "")
......
{
"name": null,
"password": null,
"room": null,
"inventory": {},
"prompt": "hp %hp mp %mp> ",
......
......@@ -11,6 +11,7 @@ from math import floor
from sys import platform
from mudserver import MudServer
from commandhandler import CommandHandler
from utils import load_object_from_file, save_object_to_file
if 'esp' in platform:
......@@ -47,6 +48,8 @@ def show_prompt(pid):
tick = 0.0
spawn = 0.0
cmd_handler = CommandHandler()
# main game loop. We loop forever (i.e. until the program is terminated)
while True:
if 'esp' in platform:
......@@ -104,6 +107,8 @@ while True:
for line in f:
mud.send_message(id, line, "\r")
# send the new player a prompt for their name
#bytes_to_send = bytearray([mud._TN_INTERPRET_AS_COMMAND, mud._TN_WONT, mud._ECHO])
#mud.raw_send(id, bytes_to_send)
mud.send_message(id, "What is your name?")
# go through any recently disconnected players
......@@ -148,9 +153,21 @@ while True:
already_logged_in = True
if already_logged_in:
continue
loaded_player = load_object_from_file("players/{}.json".format(command))
players[id]["name"] = command
mud.remote_echo(id, False)
mud.send_message(id, "Enter Password: ")
elif players[id]["password"] is None:
if command.strip() == '' or command is None:
mud.send_message(id, "Invalid Password")
continue
# TODO: Write password shadow file
loaded_player = load_object_from_file("players/{}.json".format(players[pid]["name"]))
if loaded_player is None:
players[id]["name"] = command
players[id]["password"] = True
players[id]["room"] = "Tavern"
else:
players[id] = loaded_player
......@@ -160,22 +177,21 @@ while True:
# send each player a message to tell them about the new player
mud.send_message(pid, "{} entered the game".format(players[id]["name"]))
mud.remote_echo(id, True)
# send the new player a welcome message
mud.send_message(id, "\r\n\r\nWelcome to the game, {}. ".format(players[id]["name"]) +
"\r\nType 'help' for a list of commands. Have fun!\r\n\r\n")
# send the new player the description of their current room
mud.send_message(id, load_object_from_file('rooms/' + players[id]["room"] + '.json')['description'])
cmd_handler.parse(id, 'look', '', mud, players)
show_prompt(id)
else:
from commandhandler import CommandHandler
if 'esp' in platform:
collect()
cmd_handler = CommandHandler()
handler_results = cmd_handler.parse(id, command, params, mud, players)
show_prompt(id)
cmd_handler.parse(id, command, params, mud, players)
show_prompt(id)
# Start WIFI Setup
if 'esp' in platform:
......
......@@ -3,7 +3,7 @@ def run_mobs(players, mud):
from utils import load_object_from_file, save_object_to_file, calc_att, get_att
for pid, player in players.items():
if not player['name']:
if not player['password']:
continue
if player['mp'] < player['maxmp']:
players[pid]['mp'] += player['mpr']
......
{"name": "test", "room": "Room001", "inventory": {"candle": 1}, "prompt": "h %hp m %mp s %st> ", "aliases": {}, "hp": 74, "mp": 5.0, "sta": 1.2000000000000361, "aa": "1d2", "mpr": 0.25, "star": 0.4, "maxhp": 953, "maxmp": 10, "maxsta": 10, "weapon": "sword", "sp": {"fireball": {"cost": 5, "dmg": "2d4", "desc": "A fireball blasts from your fingertips striking the target"}}, "at": {"kick": {"cost": 5, "dmg": "2d4", "desc": "You unleash a powerful kick"}}}
\ No newline at end of file
{"name": "test", "password": true, "room": "Tavern", "inventory": {"candle": 1}, "prompt": "h %hp m %mp s %st> ", "aliases": {}, "hp": 74, "mp": 10.0, "sta": 10.00000000000004, "aa": "1d2", "mpr": 0.25, "star": 0.4, "maxhp": 953, "maxmp": 10, "maxsta": 10, "weapon": "sword", "sp": {"fireball": {"cost": 5, "dmg": "2d4", "desc": "A fireball blasts from your fingertips striking the target"}}, "at": {"kick": {"cost": 5, "dmg": "2d4", "desc": "You unleash a powerful kick"}}}
\ No newline at end of file
......