forked from pythonwars/PythonWars-1996
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nanny.py
335 lines (275 loc) · 10.6 KB
/
nanny.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# PythonWars copyright © 2020 by Paul Penner. All rights reserved. In order to
# use this codebase you must comply with all licenses.
#
# Original Diku Mud copyright © 1990, 1991 by Sebastian Hammer,
# Michael Seifert, Hans Henrik Stærfeldt, Tom Madsen, and Katja Nyboe.
#
# Merc Diku Mud improvements copyright © 1992, 1993 by Michael
# Chastain, Michael Quan, and Mitchell Tse.
#
# ROM 2.4 is copyright 1993-1998 Russ Taylor. ROM has been brought to
# you by the ROM consortium: Russ Taylor (rtaylor@hypercube.org),
# Gabrielle Taylor (gtaylor@hypercube.org), and Brian Moore (zump@rom.org).
#
# Ported to Python by Davion of MudBytes.net using Miniboa
# (https://code.google.com/p/miniboa/).
#
# In order to use any part of this Merc Diku Mud, you must comply with
# both the original Diku license in 'license.doc' as well the Merc
# license in 'license.txt'. In particular, you may not remove either of
# these copyright notices.
#
# Much time and thought has gone into this software, and you are
# benefiting. We hope that you share your changes too. What goes
# around, comes around.
import os
import comm
import game_utils
import handler_game
import handler_pc
import handler_room
import instance
import merc
import save
import settings
import sys_utils
class CharDummy:
def __init__(self):
self.name = ""
self.pwd = None
self.desc = None
self.stub = None
def send(self, pstr):
pass
ch_selections = {}
def licheck(c):
return not c.lower() in ["l", "i"]
def check_parse_name(name):
bad_names = ["All", "Auto", "Immortal", "Self", "Someone", "Gaia"]
if name.title() in bad_names:
return False
if len(name) not in merc.irange(3, 12):
return False
if not name.isalpha():
return False
checked = [licheck(c) for c in name]
if True not in checked:
return False
return True
def con_get_name(self):
argument = self.get_command()
name = argument.title()
if not check_parse_name(name):
self.send("Illegal name, try another.\n"
"Name: ")
return
if not self.character:
ch_dummy = CharDummy()
ch_dummy.desc = self
self.character = ch_dummy
ch_dummy.send = self.send
else:
ch_dummy = self.character
ch_dummy.name = name
comm.notify("{} trying to connect".format(name), merc.CONSOLE_INFO)
ch_dummy.stub = handler_pc.Pc.load_stub(name)
if ch_dummy.stub:
found = True
if ch_dummy.stub["is_banned"]:
comm.notify("Denying access to {}@{}".format(ch_dummy.stub["name"], self.addrport()), merc.CONSOLE_INFO)
self.send("You are denied access.\n")
comm.close_socket(self)
return
if settings.WIZLOCK and not ch_dummy.stub["is_immortal"]:
self.send("The game is wizlocked.\n")
comm.close_socket(self)
return
if comm.is_reconnecting(self, name):
found = True
else:
found, ch_dummy = save.legacy_load_char_obj(self, name)
ch_dummy.send = self.send
ch_dummy.desc = self
self.character = ch_dummy
if found:
ch_dummy.send("Please enter password: ")
ch_dummy.desc.password_mode_on()
self.set_connected(con_get_old_password)
return
else:
ch_dummy.send("You want {} engraved on your tombstone (Y/N)? ".format(ch_dummy.name))
self.set_connected(con_confirm_new_name)
def con_confirm_new_name(self):
argument = self.get_command()[:1].upper()
ch_dummy = self.character
if argument == "Y":
ch_dummy.send("New character.\n"
"Give me a password for {}: ".format(ch_dummy.name))
ch_dummy.desc.password_mode_on()
self.set_connected(con_get_new_password)
elif argument == "N":
ch_dummy.send("Ok, what IS it, then? ")
del self.character
self.character = None
self.set_connected(con_get_name)
else:
ch_dummy.send("Please type Yes or No? ")
def con_get_new_password(self):
argument = self.get_command()
ch_dummy = self.character
ch_dummy.send("\n")
if len(argument) < 5:
ch_dummy.send("Password must be at least five characters long.\n"
"Password: ")
return
ch_dummy.pwd = argument
ch_dummy.send("Please retype password: ")
ch_dummy.desc.password_mode_on()
self.set_connected(con_confirm_new_password)
def con_confirm_new_password(self):
argument = self.get_command()
ch_dummy = self.character
ch_dummy.send("\n")
if argument != ch_dummy.pwd:
ch_dummy.send("Passwords don't match.\n"
"Retype password: ")
ch_dummy.desc.password_mode_on()
self.set_connected(con_get_new_password)
return
ch = handler_pc.Pc(ch_dummy.name)
ch.pwd = ch_dummy.pwd
del ch_dummy
ch.desc = self
ch.send = self.send
self.character = ch
ch.desc.password_mode_off()
ch.send("What is your sex (M/F)? ")
self.set_connected(con_get_new_sex)
def con_get_new_sex(self):
argument = self.get_command()[:1].upper()
ch = self.character
if argument == "M":
ch.sex = merc.SEX_MALE
elif argument == "F":
ch.sex = merc.SEX_FEMALE
else:
ch.send("That's not a sex.\n"
"What IS your sex? ")
return
ch.perm_stat = [game_utils.number_range(10, 16) for _ in range(merc.MAX_STATS)]
comm.notify("{}@{} new player.".format(ch.name, self.addrport()), merc.CONSOLE_INFO)
ch.send("\n")
ch.cmd_help("motd")
self.set_connected(con_read_motd)
def con_get_old_password(self):
argument = self.get_command()
ch_dummy = self.character
ch_dummy.send("\n")
ch_dummy.desc.password_mode_off()
pwdcmp = argument
if pwdcmp != ch_dummy.stub["pwd"]:
ch_dummy.send("Wrong password.\n")
comm.close_socket(self)
return
ch_dummy.desc.password_mode_on()
if comm.check_reconnect(self, ch_dummy.name, True):
return
if comm.check_playing(self, ch_dummy.name):
return
ch = handler_pc.Pc.load(ch_dummy.name)
del ch_dummy
ch.send = self.send
ch.desc = self
self.character = ch
comm.notify("{}@{} has connected.".format(ch.name, self.addrport()), merc.CONSOLE_INFO)
# In case we have level 4+ players from another merc mud, or
# players who have somehow got file access and changed their pfiles.
if ch.level > 3 and ch.trust == 0:
ch.level = 3
else:
ch.level = min(ch.level, merc.MAX_LEVEL)
ch.trust = min(ch.trust, merc.MAX_LEVEL)
if ch.is_hero():
ch.cmd_help("imotd")
ch.cmd_help("motd")
self.set_connected(con_read_motd)
def con_read_motd(self):
ch = self.character
ch.send("\nWelcome to God Wars Mud. May thy blade stay ever sharp, thy soul ever dark.\n")
self.set_connected(con_playing)
if ch.position == merc.POS_FIGHTING:
ch.position = merc.POS_STANDING
if ch.is_vampire() and (ch.special.is_set(merc.SPC_PRINCE) or ch.powers[merc.UNI_GEN] < 3 or ch.rank > merc.AGE_CHILDE):
ch_age = ch.years_old()
if ch_age >= 100:
ch.rank = merc.AGE_METHUSELAH
elif ch_age >= 75:
ch.rank = merc.AGE_ELDER
elif ch_age >= 50:
ch.rank = merc.AGE_ANCILLA
else:
ch.rank = merc.AGE_NEONATE
if ch.level == 0:
ch.level = 1
ch.id = game_utils.get_mob_id(npc=False)
ch.hit = ch.max_hit
ch.mana = ch.max_mana
ch.move = ch.max_move
ch.title = "the mortal"
ch.position = merc.POS_STANDING
# TODO: create a player manifest that we can use/check, instead of needing to walk the dir.
player_files = list(sys_utils.flatten([x[2] for x in os.walk(settings.PLAYER_DIR)]))
if len([x for x in player_files if not x.startswith(".")]) < 1:
ch.level = merc.MAX_LEVEL
ch.trust = merc.MAX_LEVEL
ch.send("\n\nCongratulations! As the first player to log into this MUD, you are now\n"
"the IMPLEMENTOR, the sucker in charge, the place where the buck stops.\n"
"Enjoy!\n\n")
ch.send("--------------------------------------------------------------------------------\n"
"If you need help, try talking to the spirit of mud school!\n"
"--------------------------------------------------------------------------------\n")
school_id = instance.instances_by_room[merc.ROOM_VNUM_SCHOOL][0]
school = instance.rooms[school_id]
school.put(ch)
ch.cmd_look("auto")
else:
if ch.obj_vnum != 0:
to_instance_id = instance.instances_by_room[merc.ROOM_VNUM_SCHOOL if not ch._room_vnum else ch._room_vnum][0]
to_instance = instance.rooms[to_instance_id]
to_instance.put(ch)
ch.bind_char()
return
elif ch._room_vnum:
room_id = instance.instances_by_room.get(merc.ROOM_VNUM_TEMPLE if ch._room_vnum == merc.ROOM_VNUM_LIMBO else ch._room_vnum, None)[0]
if room_id:
instance.global_instances[room_id].put(ch)
elif ch.is_immortal():
to_instance_id = instance.instances_by_room[merc.ROOM_VNUM_CHAT][0]
to_instance = instance.rooms[to_instance_id]
to_instance.put(ch)
elif ch._environment in instance.global_instances.keys():
room = instance.global_instances.get(ch._environment, None)
if room and ch._environment == room.instance_id:
room.put(ch)
elif ch._saved_room_vnum:
room_id = instance.instances_by_room.get(ch._saved_room_vnum, None)[0]
if room_id:
instance.global_instances[room_id].put(ch)
else:
to_instance_id = instance.instances_by_room[merc.ROOM_VNUM_TEMPLE][0]
to_instance = instance.rooms[to_instance_id]
to_instance.put(ch)
ch.update_skills()
comm.notify("{} has entered the God Wars.".format(ch.name))
handler_game.act("$n has entered the game.", ch, None, None, merc.TO_ROOM)
ch.cmd_look("auto")
self.send("\n\n" + self.show_terminal_type())
handler_room.room_text(ch, ">ENTER<")
def con_playing(self):
# TODO: Remove the is_immortal() check here, and possibly roll that into a new "nolag" flag or similar.
if self.character and self.character.wait > 0 and not self.character.is_immortal():
return
command = self.get_command()
if not command.strip():
return
handler_game.substitute_alias(self, command)