Huge update and added more protocol handling to the mudserver.py
Showing
8 changed files
with
73 additions
and
14 deletions
... | @@ -7,7 +7,7 @@ def look(id, mud, players, tokens): | ... | @@ -7,7 +7,7 @@ def look(id, mud, players, tokens): |
7 | del tokens[0] | 7 | del tokens[0] |
8 | if len(tokens) == 0: | 8 | if len(tokens) == 0: |
9 | mud.send_message(id, room_data.get('title'), color=['bold', 'green']) | 9 | mud.send_message(id, room_data.get('title'), color=['bold', 'green']) |
10 | mud.send_message(id, room_data.get('description'), color='green') | 10 | mud.send_message(id, room_data.get('description'), line_ending='\r\n\r\n', color='green') |
11 | else: | 11 | else: |
12 | subject = tokens[0] | 12 | subject = tokens[0] |
13 | items = room_data.get('look_items') | 13 | items = room_data.get('look_items') |
... | @@ -46,12 +46,13 @@ def look(id, mud, players, tokens): | ... | @@ -46,12 +46,13 @@ def look(id, mud, players, tokens): |
46 | if len(playershere) > 0: | 46 | if len(playershere) > 0: |
47 | mud.send_message(id, "%boldPlayers here:%reset {}".format(", ".join(playershere))) | 47 | mud.send_message(id, "%boldPlayers here:%reset {}".format(", ".join(playershere))) |
48 | 48 | ||
49 | # send player a message containing the list of exits from this room | 49 | mud.send_message(id, "%boldObvious Exits:%reset ", line_ending='') |
50 | mud.send_message(id, "%boldObvious Exits:%reset {}".format(", ".join(room_data.get('exits')))) | 50 | mud.send_list(id, room_data.get('exits'), "go") |
51 | 51 | ||
52 | # send player a message containing the list of exits from this room | 52 | # send player a message containing the list of exits from this room |
53 | if len(room_data.get('inventory')) > 0: | 53 | if len(room_data.get('inventory')) > 0: |
54 | mud.send_message(id, "%boldItems here:%reset {}".format(", ".join(room_data.get('inventory').keys()))) | 54 | mud.send_message(id, "%boldItems here:%reset ", line_ending='') |
55 | mud.send_list(id, room_data.get('inventory').keys(), "look") | ||
55 | 56 | ||
56 | # send player a message containing the list of players in the room | 57 | # send player a message containing the list of players in the room |
57 | for mon_name, monster in room_monsters.items(): | 58 | for mon_name, monster in room_monsters.items(): | ... | ... |
commands/score.txt
0 → 100644
1 | def score(id, players, mud): | ||
2 | from math import floor | ||
3 | |||
4 | mud.send_message(id, " %green+----------------------------=Score=---------------------------+", nowrap=True) | ||
5 | hp = str("%d/%d" % (floor(players[id]['hp']), floor(players[id]['maxhp']))).center(12, ' ') | ||
6 | mp = str("%d/%d" % (floor(players[id]['mp']), floor(players[id]['maxmp']))).center(12, ' ') | ||
7 | sta = str("%d/%d" % (floor(players[id]['sta']), floor(players[id]['maxsta']))).center(12, ' ') | ||
8 | |||
9 | mud.send_message(id, " %%green|%%reset%%bold%%white%s%%reset%%green|" % (players[id]["name"].center(62),), nowrap=True) | ||
10 | mud.send_message(id, " %green+--------------------------------------------------------------+", nowrap=True) | ||
11 | 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) | ||
12 | |||
13 | |||
14 | # output = """ | ||
15 | # -------------------------------------------- | ||
16 | # HP: {hp} Max HP: {maxhp} | ||
17 | # MP: {mp} Max MP: {maxmp} | ||
18 | # Sta: {sta} Max Sta: {maxsta} | ||
19 | # Experience: {exp} | ||
20 | # Skills:""".format(hp=floor(players[id]['hp']), | ||
21 | # mp=floor(players[id]['mp']), | ||
22 | # maxhp=floor(players[id]['maxhp']), | ||
23 | # maxmp=floor(players[id]['maxmp']), | ||
24 | # sta=floor(players[id]['sta']), | ||
25 | # maxsta=floor(players[id]['maxsta']), | ||
26 | # exp=0) | ||
27 | # mud.send_message(id, output) | ||
28 | |||
29 | mud.send_message(id, " %green+---------------------------=Skills=---------------------------+", nowrap=True) | ||
30 | skills = ["skillasdfasdfasdfasdf", "skill 2 sdfg sdfg", "Skill 3 asdf ewrewwr"] | ||
31 | for skill in skills: | ||
32 | mud.send_message(id, " %%green|%%reset %s%%green|%%reset" % (skill.ljust(61),), nowrap=True) | ||
33 | |||
34 | mud.send_message(id, " %green+--------------------------------------------------------------+", nowrap=True) | ||
35 | |||
36 | |||
37 | |||
38 | score(id, players, mud) | ||
39 | del score | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -2,6 +2,8 @@ def who(id, players, mud): | ... | @@ -2,6 +2,8 @@ def who(id, players, mud): |
2 | mud.send_message(id, "") | 2 | mud.send_message(id, "") |
3 | mud.send_message(id, "-------- {} Players Currently Online --------".format(len(players))) | 3 | mud.send_message(id, "-------- {} Players Currently Online --------".format(len(players))) |
4 | for pid, player in players.items(): | 4 | for pid, player in players.items(): |
5 | if player["name"] is None: | ||
6 | continue | ||
5 | mud.send_message(id, " " + player["name"]) | 7 | mud.send_message(id, " " + player["name"]) |
6 | mud.send_message(id, "---------------------------------------------".format(len(players))) | 8 | mud.send_message(id, "---------------------------------------------".format(len(players))) |
7 | mud.send_message(id, "") | 9 | mud.send_message(id, "") | ... | ... |
... | @@ -11,6 +11,7 @@ from math import floor | ... | @@ -11,6 +11,7 @@ from math import floor |
11 | from sys import platform | 11 | from sys import platform |
12 | 12 | ||
13 | from mudserver import MudServer | 13 | from mudserver import MudServer |
14 | from commandhandler import CommandHandler | ||
14 | from utils import load_object_from_file, save_object_to_file | 15 | from utils import load_object_from_file, save_object_to_file |
15 | 16 | ||
16 | if 'esp' in platform: | 17 | if 'esp' in platform: |
... | @@ -47,6 +48,8 @@ def show_prompt(pid): | ... | @@ -47,6 +48,8 @@ def show_prompt(pid): |
47 | 48 | ||
48 | tick = 0.0 | 49 | tick = 0.0 |
49 | spawn = 0.0 | 50 | spawn = 0.0 |
51 | cmd_handler = CommandHandler() | ||
52 | |||
50 | # main game loop. We loop forever (i.e. until the program is terminated) | 53 | # main game loop. We loop forever (i.e. until the program is terminated) |
51 | while True: | 54 | while True: |
52 | if 'esp' in platform: | 55 | if 'esp' in platform: |
... | @@ -104,6 +107,8 @@ while True: | ... | @@ -104,6 +107,8 @@ while True: |
104 | for line in f: | 107 | for line in f: |
105 | mud.send_message(id, line, "\r") | 108 | mud.send_message(id, line, "\r") |
106 | # send the new player a prompt for their name | 109 | # send the new player a prompt for their name |
110 | #bytes_to_send = bytearray([mud._TN_INTERPRET_AS_COMMAND, mud._TN_WONT, mud._ECHO]) | ||
111 | #mud.raw_send(id, bytes_to_send) | ||
107 | mud.send_message(id, "What is your name?") | 112 | mud.send_message(id, "What is your name?") |
108 | 113 | ||
109 | # go through any recently disconnected players | 114 | # go through any recently disconnected players |
... | @@ -148,9 +153,21 @@ while True: | ... | @@ -148,9 +153,21 @@ while True: |
148 | already_logged_in = True | 153 | already_logged_in = True |
149 | if already_logged_in: | 154 | if already_logged_in: |
150 | continue | 155 | continue |
151 | loaded_player = load_object_from_file("players/{}.json".format(command)) | 156 | players[id]["name"] = command |
157 | |||
158 | mud.remote_echo(id, False) | ||
159 | mud.send_message(id, "Enter Password: ") | ||
160 | |||
161 | elif players[id]["password"] is None: | ||
162 | if command.strip() == '' or command is None: | ||
163 | mud.send_message(id, "Invalid Password") | ||
164 | continue | ||
165 | |||
166 | # TODO: Write password shadow file | ||
167 | |||
168 | loaded_player = load_object_from_file("players/{}.json".format(players[pid]["name"])) | ||
152 | if loaded_player is None: | 169 | if loaded_player is None: |
153 | players[id]["name"] = command | 170 | players[id]["password"] = True |
154 | players[id]["room"] = "Tavern" | 171 | players[id]["room"] = "Tavern" |
155 | else: | 172 | else: |
156 | players[id] = loaded_player | 173 | players[id] = loaded_player |
... | @@ -160,22 +177,21 @@ while True: | ... | @@ -160,22 +177,21 @@ while True: |
160 | # send each player a message to tell them about the new player | 177 | # send each player a message to tell them about the new player |
161 | mud.send_message(pid, "{} entered the game".format(players[id]["name"])) | 178 | mud.send_message(pid, "{} entered the game".format(players[id]["name"])) |
162 | 179 | ||
180 | mud.remote_echo(id, True) | ||
163 | # send the new player a welcome message | 181 | # send the new player a welcome message |
164 | mud.send_message(id, "\r\n\r\nWelcome to the game, {}. ".format(players[id]["name"]) + | 182 | mud.send_message(id, "\r\n\r\nWelcome to the game, {}. ".format(players[id]["name"]) + |
165 | "\r\nType 'help' for a list of commands. Have fun!\r\n\r\n") | 183 | "\r\nType 'help' for a list of commands. Have fun!\r\n\r\n") |
166 | 184 | ||
167 | # send the new player the description of their current room | 185 | # send the new player the description of their current room |
168 | 186 | ||
169 | mud.send_message(id, load_object_from_file('rooms/' + players[id]["room"] + '.json')['description']) | 187 | cmd_handler.parse(id, 'look', '', mud, players) |
170 | 188 | show_prompt(id) | |
171 | else: | 189 | else: |
172 | from commandhandler import CommandHandler | ||
173 | if 'esp' in platform: | 190 | if 'esp' in platform: |
174 | collect() | 191 | collect() |
175 | cmd_handler = CommandHandler() | ||
176 | 192 | ||
177 | handler_results = cmd_handler.parse(id, command, params, mud, players) | 193 | cmd_handler.parse(id, command, params, mud, players) |
178 | show_prompt(id) | 194 | show_prompt(id) |
179 | 195 | ||
180 | # Start WIFI Setup | 196 | # Start WIFI Setup |
181 | if 'esp' in platform: | 197 | if 'esp' in platform: | ... | ... |
... | @@ -3,7 +3,7 @@ def run_mobs(players, mud): | ... | @@ -3,7 +3,7 @@ def run_mobs(players, mud): |
3 | 3 | ||
4 | from utils import load_object_from_file, save_object_to_file, calc_att, get_att | 4 | from utils import load_object_from_file, save_object_to_file, calc_att, get_att |
5 | for pid, player in players.items(): | 5 | for pid, player in players.items(): |
6 | if not player['name']: | 6 | if not player['password']: |
7 | continue | 7 | continue |
8 | if player['mp'] < player['maxmp']: | 8 | if player['mp'] < player['maxmp']: |
9 | players[pid]['mp'] += player['mpr'] | 9 | players[pid]['mp'] += player['mpr'] | ... | ... |
This diff is collapsed.
Click to expand it.
1 | {"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 | ... | \ No newline at end of file |
1 | {"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 | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment