-
Notifications
You must be signed in to change notification settings - Fork 1
/
commands.py
8248 lines (7475 loc) · 336 KB
/
commands.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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
__filename__ = "commands.py"
__author__ = "Bob Mottram"
__credits__ = ["Bartek Radwanski"]
__license__ = "AGPL3+"
__version__ = "1.0.0"
__maintainer__ = "Bob Mottram"
__email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Command Interface"
import os
import re
import sys
# from copy import deepcopy
from functions import deepcopy
import time
import datetime
import os.path
import random
from random import randint
from functions import parse_cost
from functions import player_is_prone
from functions import set_player_prone
from functions import WEAR_LOCATION
from functions import is_wearing
from functions import player_is_visible
from functions import message_to_room_players
from functions import time_string_to_sec
from functions import add_to_scheduler
from functions import get_free_key
from functions import get_free_room_key
from functions import hash_password
from functions import log
from functions import save_state
from functions import player_inventory_weight
from functions import save_blocklist
from functions import save_universe
from functions import update_player_attributes
from functions import size_from_description
from functions import stow_hands
from functions import random_desc
from functions import increase_affinity_between_players
from functions import decrease_affinity_between_players
from functions import get_sentiment
from functions import get_guild_sentiment
from environment import moon_phase
from environment import moon_illumination
from environment import holding_fly_fishing_rod
from environment import holding_fishing_rod
from environment import is_fishing_site
from environment import get_room_culture
from environment import run_tide
from environment import get_rain_at_coords
from history import assign_item_history
from traps import player_is_trapped
from traps import describe_trapped_player
from traps import trap_activation
from traps import teleport_from_trap
from traps import escape_from_trap
from combat import remove_prepared_spell
from combat import health_of_player
from combat import is_attacking
from combat import stop_attack
from combat import get_attacking_target
from combat import player_begins_attack
from combat import is_player_fighting
from combat import holding_throwable
from chess import show_chess_board
from chess import initial_chess_board
from chess import move_chess_piece
from cards import deal_to_players
from cards import hand_of_cards_show
from cards import swap_card
from cards import shuffle_cards
from cards import call_cards
from morris import show_morris_board
from morris import morris_move
from morris import reset_morris_board
from morris import take_morris_counter
from morris import get_morris_board_name
from proficiencies import thieves_cant
from npcs import npc_conversation
from npcs import get_solar
from markets import buy_item
from markets import market_buys_item_types
from markets import get_market_type
from markets import money_purchase
from familiar import get_familiar_name
def _get_max_weight(id: int, players: {}) -> int:
"""Returns the maximum weight which can be carried
"""
strength = int(players[id]['str'])
return strength * 15
def _pose_prone(params, mud, players_db: {}, players: {}, rooms: {},
npcs_db: {}, npcs: {}, items_db: {}, items: {},
env_db: {}, env: {}, event_db: {}, event_schedule,
id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}):
if players[id]['frozenStart'] != 0:
mud.send_message(
id, random_desc(
players[id]['frozenDescription']) + '\n\n')
return
if player_is_trapped(id, players, rooms):
describe_trapped_player(mud, id, players, rooms)
return
if 'isFishing' in players[id]:
del players[id]['isFishing']
if not player_is_prone(id, players):
msg_str = 'You lie down<r>\n\n'
mud.send_message(id, random_desc(msg_str))
set_player_prone(id, players, True)
else:
msg_str = 'You are already lying down<r>\n\n'
mud.send_message(id, random_desc(msg_str))
def _stand(params, mud, players_db: {}, players: {}, rooms: {},
npcs_db: {}, npcs: {}, items_db: {}, items: {},
env_db: {}, env: {}, event_db: {}, event_schedule,
id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}):
if players[id]['frozenStart'] != 0:
mud.send_message(
id, random_desc(
players[id]['frozenDescription']) + '\n\n')
return
if player_is_trapped(id, players, rooms):
describe_trapped_player(mud, id, players, rooms)
return
if player_is_prone(id, players):
msg_str = 'You stand up<r>\n\n'
mud.send_message(id, random_desc(msg_str))
set_player_prone(id, players, True)
else:
msg_str = 'You are already standing up<r>\n\n'
mud.send_message(id, random_desc(msg_str))
def _shove(params, mud, players_db: {}, players: {}, rooms: {},
npcs_db: {}, npcs: {}, items_db: {}, items: {},
env_db: {}, env: {}, event_db: {}, event_schedule,
id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}):
if players[id]['frozenStart'] != 0:
mud.send_message(
id, random_desc(
players[id]['frozenDescription']) + '\n\n')
return
if player_is_trapped(id, players, rooms):
describe_trapped_player(mud, id, players, rooms)
return
if player_is_prone(id, players):
mud.send_message(id, random_desc('You stand up<r>\n\n'))
set_player_prone(id, players, False)
return
if not is_player_fighting(id, players, fights):
mud.send_message(
id,
random_desc('You try to shove, but to your surprise ' +
'discover that you are not in combat ' +
'with anyone.') +
'\n\n')
return
if players[id]['canGo'] != 1:
mud.send_message(
id, random_desc(
"You try to shove, but don't seem to be able to move") +
'\n\n')
return
mud.send_message(
id, random_desc(
"You get ready to shove...") +
'\n')
players[id]['shove'] = 1
def _trip(params, mud, players_db: {}, players: {}, rooms: {},
npcs_db: {}, npcs: {}, items_db: {}, items: {},
env_db: {}, env: {}, event_db: {}, event_schedule,
id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}):
if players[id]['frozenStart'] != 0:
mud.send_message(
id, random_desc(
players[id]['frozenDescription']) + '\n\n')
return
if player_is_trapped(id, players, rooms):
describe_trapped_player(mud, id, players, rooms)
return
if player_is_prone(id, players):
mud.send_message(id, random_desc('You stand up<r>\n\n'))
set_player_prone(id, players, False)
return
if not is_player_fighting(id, players, fights):
mud.send_message(
id,
random_desc('You try to trip your opponent, ' +
'but to your surprise ' +
'discover that you are not in combat ' +
'with anyone.') +
'\n\n')
return
if players[id]['canGo'] != 1:
mud.send_message(
id, random_desc(
"You try to trip your opponent, " +
"but don't seem to be able to move") +
'\n\n')
return
mud.send_message(
id, random_desc(
"You get ready to trip your opponent...") +
'\n')
players[id]['shove'] = 1
def _dodge(params, mud, players_db: {}, players: {}, rooms: {},
npcs_db: {}, npcs: {}, items_db: {}, items: {},
env_db: {}, env: {}, event_db: {}, event_schedule,
id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}):
if players[id]['frozenStart'] != 0:
mud.send_message(
id, random_desc(
players[id]['frozenDescription']) + '\n\n')
return
if player_is_trapped(id, players, rooms):
describe_trapped_player(mud, id, players, rooms)
return
if player_is_prone(id, players):
mud.send_message(id, random_desc('You stand up<r>\n\n'))
set_player_prone(id, players, False)
return
if not is_player_fighting(id, players, fights):
mud.send_message(
id, random_desc(
"You try dodging, but then realize that you're not actually " +
"fighting|You practice dodging an imaginary attacker") +
'\n\n')
return
if players[id]['canGo'] != 1:
mud.send_message(
id, random_desc(
"You try to dodge, but don't seem to be able to move") +
'\n\n')
return
mud.send_message(
id, random_desc(
"Ok|Ok, here goes...") +
'\n\n')
players[id]['dodge'] = 1
def _remove_item_from_clothing(players: {}, pid: int, item_id: int) -> None:
"""If worn an item is removed
"""
for cstr in WEAR_LOCATION:
if int(players[pid]['clo_' + cstr]) == item_id:
players[pid]['clo_' + cstr] = 0
def _send_command_error(params, mud, players_db: {}, players: {}, rooms: {},
npcs_db: {}, npcs: {}, items_db: {}, items: {},
env_db: {}, env, event_db: {}, event_schedule, id: int,
fights: {}, corpses, blocklist, map_area: [],
character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {},
races_db: {}, item_history: {}, markets: {},
cultures_db: {}) -> None:
mud.send_message(id, "Unknown command " + str(params) + "!\n")
def _is_witch(id: int, players: {}) -> bool:
"""Have we found a witch?
"""
name = players[id]['name']
if not os.path.isfile("witches"):
return False
witches_filename = "witches"
try:
with open(witches_filename, "r", encoding='utf-8') as witchesfile:
for line in witchesfile:
witch_name = line.strip()
if witch_name == name:
return True
except OSError:
print('EX: _is_witch ' + witches_filename)
return False
def _disable_registrations(mud, id: int, players: {}) -> None:
"""Turns off new registrations
"""
if not _is_witch(id, players):
mud.send_message(id, "You don't have enough powers.\n\n")
return
if os.path.isfile(".disableRegistrations"):
mud.send_message(id, "New registrations are already closed.\n\n")
return
filename = ".disableRegistrations"
try:
with open(filename, 'w', encoding='utf-8') as fp_dis:
fp_dis.write('')
except OSError:
print('EX: _disable_registrations ' + filename)
mud.send_message(id, "New player registrations are now closed.\n\n")
def _enable_registrations(mud, id: int, players: {}) -> None:
"""Turns on new registrations
"""
if not _is_witch(id, players):
mud.send_message(id, "You don't have enough powers.\n\n")
return
if not os.path.isfile(".disableRegistrations"):
mud.send_message(id, "New registrations are already allowed.\n\n")
return
os.remove(".disableRegistrations")
mud.send_message(id, "New player registrations are now permitted.\n\n")
def _teleport(params, mud, players_db: {}, players: {}, rooms: {}, npcs_db: {},
npcs: {}, items_db: {}, items: {}, env_db: {}, env, event_db: {},
event_schedule, id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}) -> None:
if players[id]['permissionLevel'] != 0:
mud.send_message(id, "You don't have enough powers for that.\n\n")
return
if _is_witch(id, players):
if player_is_trapped(id, players, rooms):
teleport_from_trap(mud, id, players, rooms)
target_location = params[0:].strip().lower().replace('to ', '', 1)
if len(target_location) != 0:
curr_room = players[id]['room']
if rooms[curr_room]['name'].strip().lower() == target_location:
mud.send_message(
id, "You are already in " +
rooms[curr_room]['name'] +
"\n\n")
return
for room_id, room in rooms.items():
if room['name'].strip().lower() != target_location:
continue
if is_attacking(players, id, fights):
stop_attack(players, id, npcs, fights)
mud.send_message(
id, "You teleport to " + room['name'] + "\n\n")
pname = players[id]['name']
desc = '<f32>{}<r> suddenly vanishes.'.format(pname)
message_to_room_players(mud, players, id, desc + "\n\n")
players[id]['room'] = room_id
desc = '<f32>{}<r> suddenly appears.'.format(pname)
message_to_room_players(mud, players, id, desc + "\n\n")
_look('', mud, players_db, players, rooms, npcs_db, npcs,
items_db, items, env_db, env, event_db,
event_schedule,
id, fights, corpses, blocklist, map_area,
character_class_db, spells_db, sentiment_db,
guilds_db, clouds, races_db, item_history, markets,
cultures_db)
return
# try adding or removing "the"
if target_location.startswith('the '):
target_location = target_location.replace('the ', '')
else:
target_location = 'the ' + target_location
pname = players[id]['name']
desc1 = '<f32>{}<r> suddenly vanishes.'.format(pname)
desc2 = '<f32>{}<r> suddenly appears.'.format(pname)
for room_id, room in rooms.items():
if room['name'].strip().lower() == target_location:
mud.send_message(
id, "You teleport to " + room['name'] + "\n\n")
message_to_room_players(mud, players, id,
desc1 + "\n\n")
players[id]['room'] = room_id
message_to_room_players(mud, players, id,
desc2 + "\n\n")
_look('', mud, players_db, players, rooms, npcs_db, npcs,
items_db, items, env_db, env, event_db,
event_schedule,
id, fights, corpses, blocklist, map_area,
character_class_db, spells_db, sentiment_db,
guilds_db, clouds, races_db, item_history, markets,
cultures_db)
return
mud.send_message(
id, target_location +
" isn't a place you can teleport to.\n\n")
else:
mud.send_message(id, "That's not a place.\n\n")
else:
mud.send_message(id, "You don't have enough powers to teleport.\n\n")
def _summon(params, mud, players_db: {}, players: {}, rooms: {}, npcs_db: {},
npcs: {}, items_db: {}, items: {}, env_db: {}, env, event_db: {},
event_schedule, id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}) -> None:
if players[id]['permissionLevel'] != 0:
return
if _is_witch(id, players):
target_player = params[0:].strip().lower()
if len(target_player) != 0:
for plyr_id, plyr in players.items():
if plyr['name'].strip().lower() != target_player:
continue
if plyr['room'] != players[id]['room']:
pnam = plyr['name']
desc = '<f32>{}<r> suddenly vanishes.'.format(pnam)
message_to_room_players(mud, players, plyr_id,
desc + "\n")
plyr['room'] = players[id]['room']
rmid = plyr['room']
mud.send_message(id, "You summon " +
plyr['name'] + "\n\n")
mud.send_message(plyr_id,
"A mist surrounds you. When it " +
"clears you find that you " +
"are now in " +
rooms[rmid]['name'] + "\n\n")
else:
mud.send_message(
id, plyr['name'] +
" is already here.\n\n")
return
else:
mud.send_message(id, "You don't have enough powers for that.\n\n")
def _mute(params, mud, players_db: {}, players: {}, rooms: {}, npcs_db: {},
npcs: {}, items_db: {}, items: {}, env_db: {}, env, event_db: {},
event_schedule, id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}) -> None:
if players[id]['permissionLevel'] != 0:
mud.send_message(
id, "You aren't capable of doing that.\n\n")
return
if not _is_witch(id, players):
mud.send_message(
id, "You aren't capable of doing that.\n\n")
return
target = params.partition(' ')[0]
if len(target) == 0:
return
for plyr_id, plyr in players.items():
if plyr['name'] != target:
continue
if not _is_witch(plyr_id, players):
plyr['canSay'] = 0
plyr['canAttack'] = 0
plyr['canDirectMessage'] = 0
mud.send_message(id, "You have muted " + target + "\n\n")
else:
mud.send_message(
id, "You try to mute " + target +
" but their power is too strong.\n\n")
return
def _unmute(params, mud, players_db: {}, players: {}, rooms: {}, npcs_db: {},
npcs: {}, items_db: {}, items: {}, env_db: {}, env, event_db: {},
event_schedule, id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}) -> None:
if players[id]['permissionLevel'] != 0:
mud.send_message(
id, "You aren't capable of doing that.\n\n")
return
if not _is_witch(id, players):
mud.send_message(
id, "You aren't capable of doing that.\n\n")
return
target = params.partition(' ')[0]
if len(target) == 0:
return
if target.lower() != 'guest':
for plyr_id, plyr in players.items():
if plyr['name'] != target:
continue
if not _is_witch(plyr_id, players):
plyr['canSay'] = 1
plyr['canAttack'] = 1
plyr['canDirectMessage'] = 1
mud.send_message(
id, "You have unmuted " + target + "\n\n")
return
def _freeze(params, mud, players_db: {}, players: {}, rooms: {}, npcs_db: {},
npcs: {}, items_db: {}, items: {}, env_db: {}, env, event_db: {},
event_schedule, id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}):
"""witch can freeze a player
"""
if players[id]['permissionLevel'] != 0:
return
if not _is_witch(id, players):
return
target = params.partition(' ')[0]
if len(target) == 0:
return
# freeze players
for plyr_id, plyr in players.items():
if plyr['whenDied']:
mud.send_message(
id, "Freezing a player while dead is pointless\n\n")
continue
if plyr['frozenStart'] > 0:
mud.send_message(id, "They are already frozen\n\n")
continue
if target in plyr['name']:
if not _is_witch(plyr_id, players):
# remove from any fights
for fight, _ in fights.items():
if plyr in (fights[fight]['s1id'], fights[fight]['s2id']):
del fights[fight]
plyr['isInCombat'] = 0
plyr['canGo'] = 0
plyr['canAttack'] = 0
mud.send_message(id, "You have frozen " + target + "\n\n")
else:
mud.send_message(
id, "You try to freeze " + target +
" but their power is too strong.\n\n")
return
# freeze npcs
for plyr_id, plyr in npcs.items:
if plyr['whenDied']:
mud.send_message(id, "Freezing while dead is pointless\n\n")
continue
if plyr['frozenStart'] > 0:
mud.send_message(id, "They are already frozen\n\n")
continue
if target not in plyr['name']:
continue
if not _is_witch(plyr_id, npcs):
# remove from any fights
for fight, _ in fights.items():
if plyr in (fights[fight]['s1id'], fights[fight]['s2id']):
del fights[fight]
plyr['isInCombat'] = 0
plyr['canGo'] = 0
plyr['canAttack'] = 0
mud.send_message(id, "You have frozen " + target + "\n\n")
else:
mud.send_message(
id, "You try to freeze " + target +
" but their power is too strong.\n\n")
return
def _unfreeze(params, mud, players_db: {}, players: {}, rooms: {},
npcs_db: {}, npcs: {}, items_db: {}, items: {},
env_db: {}, env: {}, event_db: {}, event_schedule,
id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}) -> None:
"""witch unfreezes a frozen player
"""
if players[id]['permissionLevel'] != 0:
return
if not _is_witch(id, players):
return
target = params.partition(' ')[0]
if len(target) == 0:
return
# unfreeze players
for plyr_id, plyr in players.items():
if target in plyr['name']:
if not _is_witch(plyr_id, players):
plyr['canGo'] = 1
plyr['canAttack'] = 1
plyr['frozenStart'] = 0
mud.send_message(id, "You have unfrozen " + target + "\n\n")
return
# unfreeze npcs
for plyr_id, plyr in npcs.items():
if target not in plyr['name']:
continue
if not _is_witch(plyr_id, npcs):
plyr['canGo'] = 1
plyr['canAttack'] = 1
plyr['frozenStart'] = 0
mud.send_message(id, "You have unfrozen " + target + "\n\n")
return
def _show_blocklist(params, mud, players_db: {}, players: {}, rooms: {},
npcs_db: {}, npcs: {}, items_db: {}, items: {},
env_db: {}, env: {}, event_db: {}, event_schedule,
id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}):
"""show the blocklist
"""
if not _is_witch(id, players):
mud.send_message(id, "You don't have sufficient powers to do that.\n")
return
blocklist.sort()
block_str = ''
for blockedstr in blocklist:
block_str = block_str + blockedstr + '\n'
mud.send_message(id, "Blocked strings are:\n\n" + block_str + '\n')
def _block(params, mud, players_db: {}, players: {}, rooms: {},
npcs_db: {}, npcs: {}, items_db: {}, items: {}, env_db: {},
env: {}, event_db: {}, event_schedule,
id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}):
"""witch blocks a player
"""
if not _is_witch(id, players):
mud.send_message(id, "You don't have sufficient powers to do that.\n")
return
if len(params) == 0:
_show_blocklist(params, mud, players_db, players, rooms, npcs_db, npcs,
items_db, items, env_db, env, event_db, event_schedule,
id, fights, corpses, blocklist, map_area,
character_class_db, spells_db, sentiment_db, guilds_db,
clouds, races_db, item_history, markets, cultures_db)
return
blockedstr = params.lower().strip().replace('"', '')
if blockedstr.startswith('the word '):
blockedstr = blockedstr.replace('the word ', '')
if blockedstr.startswith('word '):
blockedstr = blockedstr.replace('word ', '')
if blockedstr.startswith('the phrase '):
blockedstr = blockedstr.replace('the phrase ', '')
if blockedstr.startswith('phrase '):
blockedstr = blockedstr.replace('phrase ', '')
if blockedstr not in blocklist:
blocklist.append(blockedstr)
save_blocklist("blocked.txt", blocklist)
mud.send_message(id, "Blocklist updated.\n\n")
else:
mud.send_message(id, "That's already in the blocklist.\n")
def _unblock(params, mud, players_db: {}, players: {}, rooms: {}, npcs_db: {},
npcs: {}, items_db: {}, items: {}, env_db: {}, env: {},
event_db: {}, event_schedule,
id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}):
"""witch removes a block on a player
"""
if not _is_witch(id, players):
mud.send_message(id, "You don't have sufficient powers to do that.\n")
return
if len(params) == 0:
_show_blocklist(params, mud, players_db, players, rooms, npcs_db,
npcs, items_db, items, env_db, env, event_db,
event_schedule,
id, fights, corpses, blocklist, map_area,
character_class_db, spells_db, sentiment_db, guilds_db,
clouds, races_db, item_history, markets, cultures_db)
return
unblockedstr = params.lower().strip().replace('"', '')
if unblockedstr.startswith('the word '):
unblockedstr = unblockedstr.replace('the word ', '')
if unblockedstr.startswith('word '):
unblockedstr = unblockedstr.replace('word ', '')
if unblockedstr.startswith('the phrase '):
unblockedstr = unblockedstr.replace('the phrase ', '')
if unblockedstr.startswith('phrase '):
unblockedstr = unblockedstr.replace('phrase ', '')
if unblockedstr in blocklist:
blocklist.remove(unblockedstr)
save_blocklist("blocked.txt", blocklist)
mud.send_message(id, "Blocklist updated.\n\n")
else:
mud.send_message(id, "That's not in the blocklist.\n")
def _kick_out(params, mud, players_db: {}, players: {}, rooms: {},
npcs_db: {}, npcs: {}, items_db: {}, items: {},
env_db: {}, env: {}, event_db: {}, event_schedule,
id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}):
"""witch removes a player
"""
if not _is_witch(id, players):
mud.send_message(id, "You don't have enough powers.\n\n")
return
player_name = params
if len(player_name) == 0:
mud.send_message(id, "Who?\n\n")
return
for pid, plyr in players.items():
if plyr['name'] == player_name:
remove_str = "Removing player " + player_name + "\n\n"
mud.send_message(id, remove_str)
print(remove_str)
mud.handle_disconnect(pid)
return
mud.send_message(id, "There are no players with that name.\n\n")
def _kick(params, mud, players_db: {}, players: {}, rooms: {},
npcs_db: {}, npcs: {}, items_db: {}, items: {},
env_db: {}, env: {}, event_db: {}, event_schedule,
id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}):
"""witch removes a player
"""
kickout = False
if ' out ' in params:
params = params.replace(' out ', ' ')
kickout = True
if ' off ' in params:
params = params.replace(' off ', ' ')
kickout = True
if params.endswidth(' out'):
params = params.replace(' out', '')
kickout = True
if params.endswidth(' off'):
params = params.replace(' off', '')
kickout = True
# kick as in remove from the server
if kickout:
_kick_out(params, mud, players_db, players, rooms,
npcs_db, npcs, items_db, items,
env_db, env, event_db, event_schedule,
id, fights, corpses, blocklist,
map_area, character_class_db, spells_db,
sentiment_db, guilds_db, clouds, races_db,
item_history, markets, cultures_db)
return
# kick as in stick the boot in (unarmed attack)
_punch(params, mud, players_db, players, rooms,
npcs_db, npcs, items_db, items,
env_db, env, event_db, event_schedule,
id, fights, corpses, blocklist,
map_area, character_class_db, spells_db,
sentiment_db, guilds_db, clouds, races_db,
item_history, markets, cultures_db)
def _shutdown(params, mud, players_db: {}, players: {}, rooms: {},
npcs_db: {}, npcs: {}, items_db: {}, items: {},
env_db: {}, env: {}, event_db: {}, event_schedule,
id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}):
"""witch shuts down the server
"""
if not _is_witch(id, players):
mud.send_message(id, "You don't have enough power to do that.\n\n")
return
mud.send_message(id, "\n\nShutdown commenced.\n\n")
save_universe(rooms, npcs_db, npcs, items_db, items,
env_db, env, guilds_db)
mud.send_message(id, "\n\nUniverse saved.\n\n")
log("Universe saved", "info")
for pid, _ in players.items():
shutdown_str = "Game server shutting down...\n\n"
mud.send_message(pid, shutdown_str)
print(shutdown_str)
mud.handle_disconnect(pid)
log("Shutting down", "info")
sys.exit()
def _reset_universe(params, mud, players_db: {}, players: {}, rooms: {},
npcs_db: {}, npcs: {}, items_db: {}, items: {},
env_db: {}, env: {}, event_db: {}, event_schedule,
id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db,
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}):
if not _is_witch(id, players):
mud.send_message(id, "You don't have enough power to do that.\n\n")
return
os.system('rm universe*.json')
log('Universe reset', 'info')
for pid, _ in players.items():
reset_str = "Game server shutting down...\n\n"
mud.send_message(pid, reset_str)
print(reset_str)
mud.handle_disconnect(pid)
log("Shutting down", "info")
sys.exit()
def _quit(params, mud, players_db: {}, players: {}, rooms: {},
npcs_db: {}, npcs: {}, items_db: {}, items: {},
env_db: {}, env: {}, event_db: {}, event_schedule,
id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}):
"""player disconnects
"""
print('quit command from ' + str(id))
mud.handle_disconnect(id)
def _who(params, mud, players_db: {}, players: {}, rooms: {},
npcs_db: {}, npcs: {}, items_db: {}, items: {},
env_db: {}, env: {}, event_db: {}, event_schedule,
id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db,
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}):
"""witch lists players on the system
"""
counter = 1
if players[id]['permissionLevel'] == 0:
is_witch = _is_witch(id, players)
for plyr_id, plyr in players.items():
if plyr['name'] is None:
continue
if not is_witch:
name = plyr['name']
else:
if not _is_witch(plyr_id, players):
if plyr['canSay'] == 1:
name = plyr['name']
else:
name = plyr['name'] + " (muted)"
else:
name = "<f32>" + plyr['name'] + "<r>"
if plyr['room'] is None:
room = "None"
else:
rmid = rooms[plyr['room']]
room = "<f230>" + rmid['name']
mud.send_message(id, str(counter) + ". " + name + " is in " + room)
counter += 1
mud.send_message(id, "\n")
else:
mud.send_message(id, "You do not have permission to do this.\n")
def _tell(params, mud, players_db: {}, players: {}, rooms: {},
npcs_db: {}, npcs: {}, items_db: {}, items: {},
env_db: {}, env: {}, event_db: {}, event_schedule,
id: int, fights: {}, corpses: {}, blocklist,
map_area: [], character_class_db: {}, spells_db: {},
sentiment_db: {}, guilds_db: {}, clouds: {}, races_db: {},
item_history: {}, markets: {}, cultures_db: {}):
"""say something to a player or npc
"""
told = False
target = params.partition(' ')[0]
# replace "familiar" with their NPC name
# as in: "ask familiar to follow"
if target.lower() == 'familiar':
new_target = get_familiar_name(players, id, npcs)
if len(new_target) > 0:
target = new_target
message = params.replace(target, "")[1:]
if len(target) != 0 and len(message) != 0:
cant_str = thieves_cant(message)
for plyr_id, plyr in players.items():
if plyr['authenticated'] is not None and \
plyr['name'].lower() == target.lower():
# print("sending a tell")
if players[id]['name'].lower() == target.lower():
mud.send_message(
id, "It'd be pointless to send a tell " +
"message to yourself\n")
told = True
break
else:
# don't tell if the string contains a blocked string
self_only = False
msglower = message.lower()
for blockedstr in blocklist:
if blockedstr in msglower:
self_only = True
break
if not self_only:
lang_list = plyr['language']
if players[id]['speakLanguage'] in lang_list:
add_to_scheduler(
"0|msg|<f90>From " +
players[id]['name'] +
": " + message +
'\n', plyr_id, event_schedule,
event_db)
sentiment_score = \
get_sentiment(message, sentiment_db) + \
get_guild_sentiment(players, id, players,
plyr_id, guilds_db)
if sentiment_score >= 0:
increase_affinity_between_players(
players, id, players, plyr_id, guilds_db)
else:
decrease_affinity_between_players(
players, id, players, plyr_id, guilds_db)
else:
if players[id]['speakLanguage'] != 'cant':
add_to_scheduler(
"0|msg|<f90>From " +
players[id]['name'] +
": something in " +
players[id]['speakLanguage'] +
'\n', plyr_id, event_schedule,
event_db)
else:
add_to_scheduler(
"0|msg|<f90>From " +
players[id]['name'] +
": " + cant_str +
'\n', plyr_id, event_schedule,
event_db)
mud.send_message(