forked from quentinnuk/perlmud-3.0-TH
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmudlib.pl
4434 lines (4185 loc) · 99.7 KB
/
mudlib.pl
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
#IMPORTANT: change these configuration settings to suit your site.
#You may want to be much more careful about what players can do!
#This file can be reloaded in response to the @reload command
#(wizard only of course). Code accordingly: don't assume that
#lists will be empty, etc. in any initialization you do here.
use strict;
use Text::Wrap;
use List::Util qw(shuffle);
#use warnings;
#Port number to listen for tiny line protocol connections on
our $tinypPort = 4096;
#$tinypPort = 4096;
#IP address to listen on. If this is set to 0.0.0.0, then
#PerlMUD will answer on all interfaces. If it is set to a
#specific IP address, PerlMUD will only answer on that
#interface. If you can set up virtual interfaces to give
#your machine several IP addresses, then you can take
#advantage of this to have a PerlMUD server that answers
#HTTP requests on port 80 without interfering
#with your regular WWW server.
#$ipAddress = "206.125.69.87";
our $ipAddress = "0.0.0.0";
#What is the complete ** Internet host name ** of your server?
#This goes out with the instructions that are sent to
#MUD users that get their accounts via email. Examples:
#www.boutell.com, mud.myschool.edu, et cetera. This must
#be a REAL host name for the server -- just putting
#something here won't magically add a new name to your DNS!
#Should users be allowed to create objects and rooms by default?
#Set this to 0 if you prefer not.
my $allowBuild = 1;
#Should users be allowed to @emit things without their
#name prefixed? Set this to zero if you prefer not.
my $allowEmit = 1;
#File locations for the database, the login screen banner,
#the Message of the Day, and the help file.
my $dbFile = "mud.db";
my $welcomeFile = "welcome.txt";
my $motdFile = "motd.txt";
my $helpFile = "help.txt";
my $emailFile = "mail.txt";
my $homePageFile = "home.html";
my $applicationFile = "application.html";
my $acceptedFile = "accepted.html";
my $mailAliasesFile = "aliases.txt";
my $apachePasswordsFile = "apache.passwords.txt";
my $updateMailAliasesCommand = "./updatealiases";
#If you uncomment this, set a password
#my $newsPassword = "";
my $newsPassword = "a8b7";
#Idle timeout. This hangs up on users if they do not
#enter at least one command in the time interval
#(specified in seconds; 3600 is an hour).
my $idleTimeout = 86400;
#Time to wait between (brief) attempts at closing
#sockets we don't need anymore. The longer this is,
#the fewer pauses the mud will experience.
my $fdClosureInterval = 30;
#Interval between automatic backups of the database, in seconds (1 hour).
#Note: stale topics are also sent home during this pass.
my $dumpinterval = 3600;
#Seconds until a topic is considered stale.
my $topicStaleTime = 3000;
#Version of PerlMUD.
my $perlMudVersion = 3.0;
#Max size of output buffer before flushing takes place
my $flushOutput = 32768;
#If the client sends the 'smartclient' command prior to sending the
#connect command, then this prefix is sent in front of each line of
#topic-specific output for the life of the connection. The @emit command
#cannot spoof this.
my $topicPrefix = "[{}]";
#Nothing below here should require changes to set up the mud
our $reloadFlag;
#Protocols
my $tinyp = 0;
#Object types
my $room = 1;
my $player = 2;
my $exit = 3;
my $thing = 4;
my $topic = 5;
my $synonym = 6;
#Special IDs
my $none = -1;
my $home = -2;
my $nowhere = -3;
#Flag values
#Can't be seen; or description only, contents invisible
my $dark = 1;
#Gender
my $male = 2;
my $female = 4;
my $herm = 6;
#Name of location visible in who list
my $public = 8;
#Unused flag
my $unusedFlag = 16;
#OK to link to
my $linkok = 32;
#OK to jump to
my $jumpok = 64;
#OK for anyone to build here
my $buildok = 128;
#Claimable by anyone who passes the lock
#(Not yet implemented)
my $claimok = 256;
#Goes home when dropped
my $sticky = 512;
#Part of a puzzle; a teleport or home command
#from this location drops all objects carried.
my $puzzle = 1024;
#If true, this location can be set home (@link)
#for an object by anyone.
my $abode = 2048;
#If true for a room, this location is "grand central station":
#players can see things, hear people speak, etc., but arrivals and
#departures go unnoticed.
my $grand = 4096;
#If true for an object, any person can "sign" the object,
#appending a string of up to 60 characters to its description.
my $book = 8192;
#This player is a wizard. #1 is always a wizard.
my $wizard = 16384;
#This player hates automatic speech and wants more abbreviations.
my $expert = 32768;
#This player wants to know who @emits things.
#Only an issue if $allowEmit is set.
my $spy = 65536;
#This player is allowed to build things. Set for new
#players if $allowBuild is set. Only a wizard can change
#this flag after that.
my $builder = 131072;
#If the book flag is set, and the once flag is also set, then
#any subsequent signature replaces all previous signatures
#by the same individual.
my $once = 262144;
# there is water here
my $water = 524288;
# there is oil here
my $oil = 1048576;
# if a mortal player enters they die
my $death = 2097152;
# objects dropped here add to score by object value
my $sanctuary = 4194304;
# If a player is in here, they cannot be seen from outside by mortals
my $hideaway = 8388608;
# If an object is in here, it cannot be seen by mortal players.
my $hide = 16777216;
# Only one player or mobile can be in this room at a time.
my $small = 33554432;
# This means that the room cannot be looked into from an adjacent room
my $nolook = 67108864;
# If a wiz is in a silent room, then they receives no status messages
my $silent = 134217728;
# you cannot pick up an object with this flag
my $noget = 268435456;
# you can always see the contents of this object even if not prop 0
my $transparent = 536870912;
# objects can be removed even if not at prop 0
my $opened = 1073741824;
# there will be no indication that this object is a container
my $disguised = 2147483648;
# need a 64bit arch for these flags
# if you carry this object you cannot be summoned
my $nosummon = 4294967296;
# impossible to pick up even for wizards (eg tide or rain)
my $fixed = 8589934592;
# will never be assigned to "it"
my $noit = 17179869184;
#For flag setting
my %flags = (
"dark", $dark,
"male", $male,
"female", $female,
"public", $public,
"linkok", $linkok,
"jumpok", $jumpok,
"buildok", $buildok,
"claimok", $claimok,
"link_ok", $linkok,
"jump_ok", $jumpok,
"build_ok", $buildok,
"claim_ok", $claimok,
"link-ok", $linkok,
"jump-ok", $jumpok,
"build-ok", $buildok,
"claim-ok", $claimok,
"sticky", $sticky,
"puzzle", $puzzle,
"abode", $abode,
"grand", $grand,
"book", $book,
"wizard", $wizard,
"expert", $expert,
"spy", $spy,
"builder", $builder,
"once", $once,
"water", $water,
"oil", $oil,
"death", $death,
"sanctuary", $sanctuary,
"hideaway", $hideaway,
"hide", $hide,
"small", $small,
"no-look", $nolook,
"silent", $silent,
"no-get", $noget,
"transparent", $transparent,
"opened", $opened,
"disguised", $disguised,
"no-summon", $nosummon,
"fixed", $fixed,
"no-it", $noit
);
my %flagsProper = (
"dark", $dark,
"male", $male,
"female", $female,
"public", $public,
"linkok", $linkok,
"jumpok", $jumpok,
"buildok", $buildok,
"claimok", $claimok,
"sticky", $sticky,
"puzzle", $puzzle,
"abode", $abode,
"grand", $grand,
"book", $book,
"wizard", $wizard,
"expert", $expert,
"spy", $spy,
"builder", $builder,
"once", $once,
"water", $water,
"oil", $oil,
"death", $death,
"sanctuary", $sanctuary,
"hideaway", $hideaway,
"hide", $hide,
"small", $small,
"nolook", $nolook,
"silent", $silent,
"noget", $noget,
"transparent", $transparent,
"opened", $opened,
"disguised", $disguised,
"no-summon", $nosummon,
"fixed", $fixed,
"noit", $noit
);
my @flagNames = (
"dark",
"male",
"female",
"unusedFlag",
"public",
"linkok",
"jumpok",
"buildok",
"claimok",
"sticky",
"puzzle",
"abode",
"grand",
"book",
"wizard",
"expert",
"spy",
"builder",
"once",
"water",
"oil",
"death",
"sanctuary",
"hideaway",
"hide",
"small",
"nolook",
"silent",
"noget",
"transparent",
"opened",
"disguised",
"no-summon",
"fixed",
"noit"
);
#Set these up in a particular order so that we can
#say that, for instance, abbreviations of 'whisper'
#should beat abbreviations of 'who'.
my @commandsProperOrder = (
"\@wall", \&wall,
"say", \&say,
"emote", \&emote,
"\@dig", \&dig,
"\@doing", \&doing,
"\@create", \&create,
"\@stats", \&stats,
"\@rooms", \&rooms,
"\@gag", \&gag,
"\@ungag", \&ungag,
"look", \&look,
"read", \&look,
"examine", \&examine,
"inventory", \&inventory,
"drop", \&drop,
"get", \&get,
"take", \&get,
"home", \&home,
"whisper", \&whisper,
"who", \&who,
"sign", \&sign,
"write", \&sign,
"unsign", \&unsign,
"help", \&help,
"motd", \&motd,
"welcome", \&welcome,
"\@set", \&set,
"\@describe", \&setDescription,
"page", \&page,
"\@name", \&name,
"\@chown", \&chown,
"\@pcreate", \&pcreate,
"\@password", \&password,
"\@teleport", \&teleport,
"\@link", \&link,
"\@open", \&open,
"\@fail", \&setFail,
"\@ofail", \&setOfail,
"\@success", \&setSuccess,
"\@osuccess", \&setOsuccess,
"\@odrop", \&setOdrop,
"\@lock", \&setLock,
"\@boot", \&boot,
"\@clean", \&clean,
"\@find", \&find,
"\@rows", \&setRows,
"\@emit", \&emit,
"\@email", \&setEmail,
"\@topic", \&createTopic,
"\@join", \&joinTopic,
"\@leave", \&leaveTopic,
"last", \&last,
"\@tz", \&tz,
"\@24", \&twentyfour,
"\@12", \&twelve
);
my %commandsProper;
my($i);
for ($i = 0; ($i < int(@commandsProperOrder)); $i += 2) {
$commandsProper{$commandsProperOrder[$i]} =
$commandsProperOrder[$i + 1];
}
#Data for base64 decoder
my $base64alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
'abcdefghijklmnopqrstuvwxyz'.
'0123456789+/';
my $base64pad = '=';
my $base64initialized = 0;
#Set the SIGPIPE handler (grrr)
&plumber;
#Set up commands table (now in order of precedence)
#3.0: make sure to empty it again if we're reloading
my %commandsTable = ( );
for ($i = 0; ($i < int(@commandsProperOrder)); $i += 2) {
my($key) = $commandsProperOrder[$i];
my($val) = $commandsProperOrder[$i + 1];
my($j);
for ($j = 1; ($j <= length($key)); $j++) {
my($s) = substr($key, 0, $j);
if ($s eq "@") {
next;
}
if (!exists($commandsTable{$s})) {
$commandsTable{$s} = $val;
}
}
}
our ($lastdump, $lastFdClosure,$now);
our ($initialized);
my (@activeFds, $fdClosureNew, $fdClosureTimedOut, @fdClosureList);
my (@objects, %playerIds, $commandLogging);
#(re)initialization code ends here
sub selectPass
{
my($rfds, $wfds, $i);
$rfds = "";
$wfds = "";
# set bits in rfds and wfds for each fd fileno to indicate if data to read/write
for ($i = 0; ($i <= $#activeFds); $i++) {
if ($activeFds[$i]{"fd"} ne $none) {
if ($activeFds[$i]{"protocol"} == $tinyp) {
my($fd) = $activeFds[$i]{"fd"};
vec($rfds, fileno($fd), 1) = 1;
if (length($activeFds[$i]{"outbuf"})) {
vec($wfds, fileno($fd), 1) = 1;
}
}
}
}
vec($rfds, fileno(TINYP_LISTENER), 1) = 1;
my($timeout);
my($before);
$before = time;
# The longest timeout would be between dump intervals
$timeout = $dumpinterval - ($now - $lastdump);
# Second longest, probably, between fd closure intervals
if ($fdClosureNew) {
# Try it right away
$timeout = 0;
} else {
my($fdTimeout);
$fdTimeout = $lastFdClosure + $fdClosureInterval - $now;
if ($fdTimeout < $timeout) {
$timeout = $fdTimeout;
}
}
if ($timeout < 0) {
# Reasonable timeouts only
$timeout = 0;
}
select($rfds, $wfds, undef, $timeout);
$now = time;
if ($now - $lastdump >= $dumpinterval) {
&dump($none, "", "", "");
}
if ($fdClosureNew || ($now - $lastFdClosure >= $fdClosureInterval))
{
$fdClosureNew = 0;
# Try to close some file descriptors we're
# done with. This can take a while if they have
# not flushed completely yet, so we make three-second
# attempts to close them, every n seconds.
# This is a workaround for the SO_LINGER problem.
$SIG{ALRM} = \&fdClosureTimeout;
$fdClosureTimedOut = 0;
alarm(3);
while (int(@fdClosureList)) {
close($fdClosureList[0]);
if ($fdClosureTimedOut) {
# Try again later
last;
}
# It worked
shift @fdClosureList;
}
# No more need for the alarm timer
alarm(0);
$SIG{ALRM} = undef;
$lastFdClosure = time;
}
for ($i = 0; ($i <= $#activeFds); $i++) {
if ($activeFds[$i]{"fd"} ne $none) { # is there a player on this fd
my($fd) = $activeFds[$i]{"fd"};
# if there is data to be read from fd, readData
if (vec($rfds, fileno($fd), 1)) {
&readData($i, $fd);
}
# Watch out for a close detected on the read
if ($activeFds[$i]{"fd"} ne $none) { # is there still a player on this fd
# if there is data to be written to fd, writeData
if (vec($wfds, fileno($fd), 1)) {
&writeData($i, $fd);
}
}
}
}
# this is the bit that accepts new conections
if (vec($rfds, fileno(TINYP_LISTENER), 1)) {
&acceptTinyp;
}
# Idle Timeouts
for ($i = 0; ($i <= $#activeFds); $i++) {
my $e = $activeFds[$i]{"id"};
if ($e != $none) {
my $idlesecs = $now - $objects[$e]{"last"};
if ($idlesecs > $idleTimeout) {
&closePlayer($e, 1);
}
}
}
}
sub closeActiveFd
{
my($i) = @_;
if ($activeFds[$i]{"id"} != $none) {
$objects[$activeFds[$i]{"id"}]{"activeFd"} = $none;
$activeFds[$i]{"id"} = $none;
}
my($fd);
$fd = $activeFds[$i]{"fd"};
if ($fd ne $none) {
push @fdClosureList, $fd;
$fdClosureNew = 1;
}
# Make sure the next person doesn't get old buffer data!
$activeFds[$i] = { };
$activeFds[$i]{"fd"} = $none;
$activeFds[$i]{"id"} = $none;
$activeFds[$i]{"smartclient"} = 0;
}
sub input
{
my($aindex, $input) = @_;
$input =~ tr/\x00-\x1F//d;
if ($activeFds[$aindex]{"id"} ne $none) {
&command($activeFds[$aindex]{"id"}, $input);
} else {
$input =~ s/\s+/ /g;
$input =~ s/^ //g;
$input =~ s/ $//g;
my($verb, $object, $pwd) = split(/ /, $input);
if ($verb eq "") {
return;
}
if (($verb eq "quit") || ($verb eq "QUIT")) {
closeActiveFd($aindex);
return;
}
if ($verb eq "news") {
if ($newsPassword ne "") {
if ($input =~
/news\s+$newsPassword\s+\#(\d+)\s+(.*)/)
{
my($to, $what) = ($1, $2);
if ($objects[$to]{"type"} eq $player) {
&tellPlayer($to, $what);
} else {
&tellRoom($to, undef, $what, undef);
}
closeActiveFd($aindex);
return;
}
} else {
&tellActiveFd($aindex, "Bad syntax or bad password.");
closeActiveFd($aindex);
return;
}
}
if ($verb eq "connect") {
my($id, $n);
$n = $object;
$n =~ tr/A-Z/a-z/;
if (!exists($playerIds{$n})) {
&tellActiveFd($aindex, "Login Failed");
&tellActiveFd($aindex,
"That player does not exist, or has a different password.");
return;
} else {
$id = $playerIds{$n};
if ($pwd ne $objects[$id]{"password"}) {
&tellActiveFd($aindex, "Login Failed");
&tellActiveFd($aindex,
"That player does not exist, or has a different password.");
return;
}
&tellActiveFd($aindex, "Login Succeeded");
if (($objects[$id]{"activeFd"} != $none))
{
closePlayer($id, 0);
}
$activeFds[$aindex]{"id"} = $id;
&login($id, $aindex);
}
return;
}
if ($verb eq "smartclient") {
$activeFds[$aindex]{"smartclient"} = 1;
return;
}
&tellActiveFd($aindex,
"Try: connect name password (or quit)");
}
}
sub closePlayer
{
my($id, $gohome) = @_;
my($i);
for ($i = 0; ($i <= $#activeFds); $i++) {
if (($activeFds[$i]{"fd"} ne $none) &&
($activeFds[$i]{"id"} == $id))
{
$activeFds[$i]{"id"} = $none;
&closeActiveFd($i);
last;
}
}
$objects[$id]{"activeFd"} = $none;
if (!($objects[$objects[$id]{"location"}]{"flags"} & $grand)) {
&tellRoom($objects[$id]{"location"}, $none, $objects[$id]{"name"} .
" has disconnected.");
}
if ($gohome) {
&sendHome($id);
}
$objects[$id]{"off"} = $now;
}
sub acceptTinyp
{
if (accept(my $fd, TINYP_LISTENER)) {
my($i, $found);
$found = 0;
for ($i = 0; ($i <= $#activeFds); $i++) {
if ($activeFds[$i]{"fd"} eq $none) {
$activeFds[$i]{"protocol"} = $tinyp;
$activeFds[$i]{"fd"} = $fd;
$activeFds[$i]{"id"} = $none;
&sendActiveFdFile($i, $welcomeFile);
$found = 1;
last;
}
}
if (!$found) {
my($aindex) = $#activeFds + 1;
$activeFds[$aindex]{"protocol"} = $tinyp;
$activeFds[$aindex]{"fd"} = $fd;
$activeFds[$aindex]{"id"} = $none;
&sendActiveFdFile($aindex, $welcomeFile);
}
# Stop (ma)lingering behavior
setsockopt($fd, SOL_SOCKET, SO_LINGER, 0);
# Set non-blocking I/O
fcntl($fd, F_SETFL, O_NONBLOCK);
}
}
sub command
{
my($me, $text) = @_;
my($id);
$objects[$me]{"lastPing"} = $now;
$_ = $text;
# Don't let the user embed commands. Could do nasty, nasty things.
s/\x01/\./g;
s/\x02/\./g;
# Clean up whitespace.
s/\s/ /g;
s/^ //g;
s/ $//g;
$text = $_;
if ($text eq "") {
return;
}
if ($text eq "quit") {
&closePlayer($me, 1);
return;
}
$objects[$me]{"last"} = $now;
# we are not going to use PerlMUD logging
# if ($commandLogging) {
# print CLOG $me, ":", $text, "\n";
# &flush(CLOG);
# }
if (substr($text, 0, 1) eq "\"") {
&say($me, substr($text, 1), "", "");
return;
}
if (substr($text, 0, 1) eq ":") {
&emote($me, substr($text, 1), "", "");
return;
}
if (substr($text, 0, 1) eq "'") {
$text =~ s/^\'(\S+)\s*//;
&say($me, $text, "", "", $1);
return;
}
if (substr($text, 0, 2) eq "..") {
&tellPlayer($me, "Sorry, support for .. has been removed. Please use ' instead of .. as this makes the .name whisper shortcut safe to use.");
}
if (substr($text, 0, 1) eq ".") {
$text =~ s/^\.(\S+)\s+//;
&whisper($me, "", $1, $text);
return;
}
if ($text =~ /^,(\S+)\s+(.*)$/) {
&topic($me, "", $1, $2, 0);
return;
}
if ($text =~ /^;(\S+)\s+(.*)$/) {
&topic($me, "", $1, $2, 1);
return;
}
#
# Consider exits from this room.
#
if (substr($text, 0, 1) ne "@") {
$id = &findContents($objects[$me]{"location"}, $text);
if ($id != $none) {
if ($objects[$id]{"type"} != $exit) {
&fail($me, $id, "You can't go that way.", "");
return;
}
if (!&testLock($me, $id)) {
&fail($me, $id, "You can't go that way.", "");
return;
}
if ($objects[$id]{"action"} == $nowhere) {
&success($me, $id, "",
$objects[$me]{"name"} . " has left.");
return;
}
&removeContents($objects[$me]{"location"}, $me);
if (!($objects[$objects[$me]{"location"}]{"flags"} & $grand)) {
&success($me, $id, "",
$objects[$me]{"name"} . " has left.");
}
if ($objects[$id]{"action"} == $home) {
&sendHome($me);
return;
}
my $destid=$objects[$id]{"action"};
if ($destid=~/(.+?)\|.+/) { # multi destination exit
$destid=$1; # pick the first destination the loader randomised
}
if (!($objects[$destid]{"flags"} & $grand)) {
if ($objects[$id]{"odrop"} ne "") {
&tellRoom($destid, $none,
$objects[$me]{"name"} . " " .
&substitute($me,
$objects[$id]{"odrop"}));
} else {
&tellRoom($destid, $none,
$objects[$me]{"name"} . " has arrived.");
}
}
&addContents($destid, $me);
&describe($me, $objects[$me]{"location"}, 0);
return;
}
}
#Split into command and argument.
my($c, $arg) = split(/ /, $text, 2);
$arg = &canonicalizeWord($me, $arg);
# Now commands with an = sign.
# Common parsing
my($arg1, $arg2) = split(/=/, $arg, 2);
$arg1 = &canonicalizeWord($me, $arg1);
$arg2 = &canonicalizeWord($me, $arg2);
# Commands that are not in the normal table
$c =~ tr/A-Z/a-z/;
if ($c eq "\@recycle") {
&recycle($me, $arg, $arg1, $arg2);
return;
}
if ($c eq "\@purge") {
&purge($me, $arg, $arg1, $arg2);
return;
}
if ($c eq "\@toad") {
&toad($me, $arg, $arg1, $arg2);
return;
}
if ($c eq "\@shutdown") {
&shutdown($me, $arg, $arg1, $arg2);
return;
}
if ($c eq "\@reload") {
&reload($me, $arg, $arg1, $arg2);
return;
}
if ($c eq "\@dump") {
&dump($me, $arg, $arg1, $arg2);
return;
}
# If there is an =, then look for an abbreviated command
if (!($objects[$me]{"flags"} & $expert)) {
if ($arg2 ne "") {
if (exists($commandsTable{$c})) {
&{$commandsTable{$c}}($me, $arg, $arg1, $arg2);
return;
}
} else {
# if there is no =, then require an exact command
if (exists($commandsProper{$c})) {
&{$commandsTable{$c}}($me, $arg, $arg1, $arg2);
return;
}
}
# Okay, it is (apparently) not a command, so just say it.
&say($me, $text, "", "");
} else {
if (exists($commandsTable{$c})) {
&{$commandsTable{$c}}($me, $arg, $arg1, $arg2);
return;
}
&tellPlayer($me, "Not a valid command. Try typing help.");
}
}
sub dig
{
my($me, $arg, $arg1, $arg2) = @_;
if (!&builderTest($me)) {
&tellPlayer($me, "Sorry, only an authorized builder can do that.");
return;
}
&addObject($me, $arg, $room);
}
sub doing
{
my($me, $arg, $arg1, $arg2) = @_;
$objects[$me]{"doing"} = $arg;
&tellPlayer($me, "Doing doing doing!");
}
sub twentyfour
{
my($me, $arg, $arg1, $arg2) = @_;
$objects[$me]{"24hour"} = 1;
&tellPlayer($me, "24-hour time display set.");
}
sub twelve
{
my($me, $arg, $arg1, $arg2) = @_;
$objects[$me]{"24hour"} = 0;
&tellPlayer($me, "12-hour time display set.");
}
sub reload
{
my($me, $arg, $arg1, $arg2) = @_;
if ($me != $none) {
if (!&wizardTest($me)) {
&tellPlayer($me, "Sorry, only a wizard can do that.");
return;
}
}
&dump($me, $arg, $arg1, $arg2);
$reloadFlag = 1;
}
sub tz
{
my($me, $arg, $arg1, $arg2) = @_;
if ($arg eq "") {
&tellPlayer($me, "Usage: [-]HH:MM (optional minus sign, " .
"followed by an offset in hours and minutes)");
return;
}
if ($arg =~ /^([-+]?)(\d\d?):(\d\d)$/) {
my($sign, $hours, $mins) = ($1, $2, $3);
my($tz) = $hours * 60 + $mins;
if ($sign eq "-") {
$tz = -$tz;
}
$objects[$me]{"tz"} = $tz;
&tellPlayer($me, "Time zone updated.");
} else {
&tellPlayer($me, "Usage: [-]HH:MM (optional minus sign, " .
"followed by an offset in hours and minutes)");
}
}
sub setEmail
{
my($me, $arg, $arg1, $arg2) = @_;
my($id);
if ($mailAliasesFile eq "") {
&tellPlayer($me, "This system does not " .
"have a mail aliases file.");
return;
}
if ($arg =~ /=/) {
$id = &setField($me, $arg, $arg1, $arg2,
"email", "Email address");
if ($id ne $none) {
if (!&updateMailAliases) {
&tellPlayer($me, "NOTE: there may be " .
"a short delay before your " .
"new alias is valid.");
}
}
} else {
$objects[$me]{"email"} = $arg;
&tellPlayer($me, "Email address set.");
if (!&updateMailAliases) {
&tellPlayer($me, "NOTE: there may be " .
"a short delay before your " .
"new alias is valid.");
}
}
}
sub create
{
my($me, $arg, $arg1, $arg2) = @_;
my($id);
if (!&builderTest($me)) {
&tellPlayer($me, "Sorry, only an authorized builder can do that.");
return;
}
if ($arg =~ /^\s*$/) {
&tellPlayer($me, "Syntax: \@create nameofthing");
return;
}
$id = &addObject($me, $arg, $thing);
&addContents($me, $id);
$objects[$id]{"home"} = $objects[$me]{"home"};
}