forked from PsychoticNinjaRepo/idlerpg-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
idlebot.pl
executable file
·2458 lines (2380 loc) · 99.7 KB
/
idlebot.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
#!/usr/bin/env perl
# irpg bot v3.1.2 by jotun, jotun@idlerpg.net, et al. See http://idlerpg.net/
# v3.1.3 by Bahhumbug, jrd@gerdesas.com
#
# Some code within this file was written by authors other than myself. As such,
# distributing this code or distributing modified versions of this code is
# strictly prohibited without written authorization from the authors. Contact
# jotun@idlerpg.net. Please note that this may change (at any time, no less) if
# authorization for distribution is given by patch submitters.
#
# As a side note, patches submitted for this project are automatically taken to
# be freely distributable and modifiable for any use, public or private, though
# I make no claim to ownership; original copyrights will be retained.. except as
# I've just stated.
#
# Please mail bugs, etc. to me. Patches are welcome to fix bugs or clean up
# the code, but please do not use a radically different coding style. Thanks
# to everyone that's contributed!
#
# NOTE: This code should NOT be run as root. You deserve anything that happens
# to you if you run this code as a superuser. Also, note that giving a
# user admin access to the bot effectively gives them full access to the
# user under which your bot runs, as they can use the PEVAL command to
# execute any command, or possibly even change your password. I sincerely
# suggest that you exercise extreme caution when giving someone admin
# access to your bot, or that you disable the PEVAL command for non-owner
# accounts in your config file, irpg.conf
use strict;
use warnings;
use IO::Socket;
use IO::Select;
use Data::Dumper;
use Getopt::Long;
my %opts;
readconfig();
my $version = "3.1.3";
# command line overrides irpg.conf
GetOptions(\%opts,
"help|h",
"verbose|v",
"debug",
"debugfile=s",
"server|s=s",
"botnick|n=s",
"botuser|u=s",
"botrlnm|r=s",
"botchan|c=s",
"botident|p=s",
"botmodes|m=s",
"botopcmd|o=s",
"localaddr=s",
"botghostcmd|g=s",
"helpurl=s",
"admincommurl=s",
"doban",
"silentmode=i",
"writequestfile",
"questfilename=s",
"voiceonlogin",
"noccodes",
"nononp",
"mapurl=s",
"statuscmd",
"pidfile=s",
"reconnect",
"reconnect_wait=i",
"self_clock=i",
"modsfile=s",
"casematters",
"detectsplits",
"splitwait=i",
"allowuserinfo",
"noscale",
"phonehome",
"owner=s",
"owneraddonly",
"ownerdelonly",
"ownerpevalonly",
"checkupdates",
"senduserlist",
"limitpen=i",
"mapx=i",
"mapy=i",
"modesperline=i",
"okurl|k=s@",
"eventsfile=s",
"rpstep=f",
"rpbase=i",
"rppenstep=f",
"dbfile|irpgdb|db|d=s",
"newuserreports",
"newuserdest=s",
"newuserfromname=s",
"newuserfromaddr=s",
"gametitle=s",
) or debug("Error: Could not parse command line. Try $0 --help\n",1);
$opts{help} and do { help(); exit 0; };
debug("Config: read $_: ".Dumper($opts{$_})) for keys(%opts);
my $outbytes = 0; # sent bytes
my $primnick = $opts{botnick}; # for regain or register checks
my $inbytes = 0; # received bytes
my %onchan; # users on game channel
my %rps; # role-players
my %quest = (
questers => [],
p1 => [], # point 1 for q2
p2 => [], # point 2 for q2
qtime => time() + int(rand(21600)), # first quest starts in <=6 hours
text => "",
type => 1,
stage => 1); # quest info
my $rpreport = 0; # constant for reporting top players
my %prev_online; # user@hosts online on restart, die
my %auto_login; # users to automatically log back on
my @bans; # bans auto-set by the bot, saved to be removed after 1 hour
my $pausemode = 0; # pausemode on/off flag
my $silentmode = 0; # silent mode 0/1/2/3, see head of file
my @queue; # outgoing message queue
my $lastreg = 0; # holds the time of the last reg. cleared every second.
# prevents more than one account being registered / second
my $registrations = 0; # count of registrations this period
my $sel; # IO::Select object
my $lasttime = 1; # last time that rpcheck() was run
my $buffer; # buffer for socket stuff
my $conn_tries = 0; # number of connection tries. gives up after trying each
# server twice
my $sock; # IO::Socket::INET object
my %split; # holds nick!user@hosts for clients that have been netsplit
my $freemessages = 4; # number of "free" privmsgs we can send. 0..$freemessages
sub daemonize(); # prototype to avoid warnings
if (! -e $opts{dbfile}) {
$|=1;
%rps = ();
print "$opts{dbfile} does not appear to exist. I'm guessing this is your ".
"first time using IRPG. Please give an account name that you would ".
"like to have admin access [$opts{owner}]: ";
chomp(my $uname = <STDIN>);
$uname =~ s/\s.*//g;
$uname = length($uname)?$uname:$opts{owner};
print "Enter a character class for this account: ";
chomp(my $uclass = <STDIN>);
$rps{$uname}{class} = substr($uclass,0,30);
print "Enter a password for this account: ";
if ($^O ne "MSWin32") {
system("stty -echo");
}
chomp(my $upass = <STDIN>);
if ($^O ne "MSWin32") {
system("stty echo");
}
$rps{$uname}{pass} = crypt($upass,mksalt());
$rps{$uname}{next} = $opts{rpbase};
$rps{$uname}{nick} = "";
$rps{$uname}{userhost} = "";
$rps{$uname}{level} = 0;
$rps{$uname}{online} = 0;
$rps{$uname}{idled} = 0;
$rps{$uname}{created} = time();
$rps{$uname}{lastlogin} = time();
$rps{$uname}{x} = int(rand($opts{mapx}));
$rps{$uname}{y} = int(rand($opts{mapy}));
$rps{$uname}{alignment}="n";
$rps{$uname}{isadmin} = 1;
for my $item ("ring","amulet","charm","weapon","helm",
"tunic","pair of gloves","shield",
"set of leggings","pair of boots") {
$rps{$uname}{item}{$item} = 0;
}
for my $pen ("pen_mesg","pen_nick","pen_part",
"pen_kick","pen_quit","pen_quest",
"pen_logout","pen_logout") {
$rps{$uname}{$pen} = 0;
}
writedb();
print "OK, wrote you into $opts{dbfile}.\n";
}
# this is almost silly...
if ($opts{checkupdates}) {
print "Checking for updates...\n\n";
my $tempsock = IO::Socket::INET->new(PeerAddr=>"jotun.ultrazone.org:80",
Timeout => 15);
if ($tempsock) {
print $tempsock "GET /g7/version.php?version=$version HTTP/1.1\r\n".
"Host: jotun.ultrazone.org:80\r\n\r\n";
my($line,$newversion);
while ($line=<$tempsock>) {
chomp($line);
next() unless $line;
if ($line =~ /^Current version : (\S+)/) {
if ($version ne $1) {
print "There is an update available! Changes include:\n";
$newversion=1;
}
else {
print "You are running the latest version (v$1).\n";
close($tempsock);
last();
}
}
elsif ($newversion && $line =~ /^( -? .+)/) { print "$1\n"; }
elsif ($newversion && $line =~ /^URL: (.+)/) {
print "\nGet the newest version from $1!\n";
close($tempsock);
last();
}
}
}
else { print debug("Could not connect to update server.")."\n"; }
}
print "\n".debug("Becoming a daemon...")."\n";
daemonize();
$SIG{HUP} = "readconfig"; # sighup = reread config file
$SIG{INT} = "writedb"; # sigint = force write of players database
$SIG{TERM} = "quit"; # sigterm = write db and quit game
CONNECT: # cheese.
loaddb();
while (!$sock && $conn_tries < 2*@{$opts{servers}}) {
debug("Connecting to $opts{servers}->[0]...");
my %sockinfo = (PeerAddr => $opts{servers}->[0],
PeerPort => 6667);
if ($opts{localaddr}) { $sockinfo{LocalAddr} = $opts{localaddr}; }
$sock = IO::Socket::INET->new(%sockinfo) or
debug("Error: failed to connect: $!\n");
++$conn_tries;
if (!$sock) {
# cycle front server to back if connection failed
push(@{$opts{servers}},shift(@{$opts{servers}}));
}
else { debug("Connected."); }
}
if (!$sock) {
debug("Error: Too many connection failures, exhausted server list.\n",1);
}
$conn_tries=0;
$sel = IO::Select->new($sock);
sts("NICK $opts{botnick}");
sts("USER $opts{botuser} 0 0 :$opts{botrlnm}");
while (1) {
my($readable) = IO::Select->select($sel,undef,undef,0.5);
if (defined($readable)) {
my $fh = $readable->[0];
my $buffer2;
$fh->recv($buffer2,512,0);
if (length($buffer2)) {
$buffer .= $buffer2;
while (index($buffer,"\n") != -1) {
my $line = substr($buffer,0,index($buffer,"\n")+1);
$buffer = substr($buffer,length($line));
parse($line);
}
}
else {
# uh oh, we've been disconnected from the server, possibly before
# we've logged in the users in %auto_login. so, we'll set those
# users' online flags to 1, rewrite db, and attempt to reconnect
# (if that's wanted of us)
$rps{$_}{online}=1 for keys(%auto_login);
writedb();
close($fh);
$sel->remove($fh);
if ($opts{reconnect}) {
undef(@queue);
undef($sock);
debug("Socket closed; disconnected. Cleared outgoing message ".
"queue. Waiting $opts{reconnect_wait}s before next ".
"connection attempt...");
sleep($opts{reconnect_wait});
goto CONNECT;
}
else { debug("Socket closed; disconnected.",1); }
}
}
else { select(undef,undef,undef,1); }
if ((time()-$lasttime) >= $opts{self_clock}) { rpcheck(); }
}
sub parse {
my($in) = shift;
$inbytes += length($in); # increase parsed byte count
$in =~ s/[\r\n]//g; # strip all \r and \n
debug("<- $in");
my @arg = split(/\s/,$in); # split into "words"
my $usernick = substr((split(/!/,$arg[0]))[0],1);
# logged in char name of nickname, or undef if nickname is not online
my $username = finduser($usernick);
if (lc($arg[0]) eq 'ping') { sts("PONG $arg[1]",1); }
elsif (lc($arg[0]) eq 'error') {
# uh oh, we've been disconnected from the server, possibly before we've
# logged in the users in %auto_login. so, we'll set those users' online
# flags to 1, rewrite db, and attempt to reconnect (if that's wanted of
# us)
$rps{$_}{online}=1 for keys(%auto_login);
writedb();
return;
}
$arg[1] = lc($arg[1]); # original case no longer matters
if ($arg[1] eq '433' && $opts{botnick} eq $arg[3]) {
$opts{botnick} .= 0;
sts("NICK $opts{botnick}");
}
elsif ($arg[1] eq 'join') {
# %onchan holds time user joined channel. used for the advertisement ban
$onchan{$usernick}=time();
if ($opts{'detectsplits'} && exists($split{substr($arg[0],1)})) {
delete($split{substr($arg[0],1)});
}
elsif ($opts{botnick} eq $usernick) {
sts("WHO $opts{botchan}");
(my $opcmd = $opts{botopcmd}) =~ s/%botnick%/$opts{botnick}/eg;
sts($opcmd);
chanmsg ("*** $opts{gametitle} ver $version has returned ***");
$lasttime = time(); # start rpcheck()
}
}
elsif ($arg[1] eq 'quit') {
# if we see our nick come open, grab it (skipping queue)
if ($usernick eq $primnick) { sts("NICK $primnick",1); }
elsif ($opts{'detectsplits'} &&
"@arg[2..$#arg]" =~ /^:\S+\.\S+ \S+\.\S+$/) {
if (defined($username)) { # user was online
$split{substr($arg[0],1)}{time}=time();
$split{substr($arg[0],1)}{account}=$username;
}
}
else {
penalize($username,"quit");
}
delete($onchan{$usernick});
}
elsif ($arg[1] eq 'nick') {
# if someone (nickserv) changes our nick for us, update $opts{botnick}
if ($usernick eq $opts{botnick}) {
$opts{botnick} = substr($arg[2],1);
}
# if we see our nick come open, grab it (skipping queue), unless it was
# us who just lost it
elsif ($usernick eq $primnick) { sts("NICK $primnick",1); }
else {
penalize($username,"nick",$arg[2]);
$onchan{substr($arg[2],1)} = delete($onchan{$usernick});
}
}
elsif ($arg[1] eq 'part') {
penalize($username,"part");
delete($onchan{$usernick});
}
elsif ($arg[1] eq 'kick') {
$usernick = $arg[3];
penalize(finduser($usernick),"kick");
delete($onchan{$usernick});
}
# don't penalize /notices to the bot
elsif ($arg[1] eq 'notice' && $arg[2] ne $opts{botnick}) {
penalize($username,"notice",length("@arg[3..$#arg]")-1);
}
elsif ($arg[1] eq '001') {
# send our identify command, set our usermode, join channel
sts($opts{botident});
sts("MODE $opts{botnick} :$opts{botmodes}");
sts("JOIN $opts{botchan}");
$opts{botchan} =~ s/ .*//; # strip channel key if present
}
elsif ($arg[1] eq '315') {
# 315 is /WHO end. report who we automagically signed online iff it will
# print < 1k of text
if (keys(%auto_login)) {
# not a true measure of size, but easy
if (length("%auto_login") < 1024 && $opts{senduserlist}) {
chanmsg(scalar(keys(%auto_login))." users matching ".
scalar(keys(%prev_online))." hosts automatically ".
"logged in; accounts: ".join(", ",keys(%auto_login)));
}
else {
chanmsg(scalar(keys(%auto_login))." users matching ".
scalar(keys(%prev_online))." hosts automatically ".
"logged in.");
}
if ($opts{voiceonlogin}) {
my @vnicks = map { $rps{$_}{nick} } keys(%auto_login);
while (@vnicks) {
sts("MODE $opts{botchan} +".
('v' x $opts{modesperline})." ".
join(" ",@vnicks[0..$opts{modesperline}-1]));
splice(@vnicks,0,$opts{modesperline});
}
}
}
else { chanmsg("0 users qualified for auto login."); }
undef(%prev_online);
undef(%auto_login);
loadquestfile();
}
elsif ($arg[1] eq '005') {
if ("@arg" =~ /MODES=(\d+)/) { $opts{modesperline}=$1; }
}
elsif ($arg[1] eq '352') {
my $user;
# 352 is one line of /WHO. check that the nick!user@host exists as a key
# in %prev_online, the list generated in loaddb(). the value is the user
# to login
$onchan{$arg[7]}=time();
if (exists($prev_online{$arg[7]."!".$arg[4]."\@".$arg[5]})) {
$rps{$prev_online{$arg[7]."!".$arg[4]."\@".$arg[5]}}{online} = 1;
$auto_login{$prev_online{$arg[7]."!".$arg[4]."\@".$arg[5]}}=1;
}
}
elsif ($arg[1] eq 'privmsg') {
$arg[0] = substr($arg[0],1); # strip leading : from privmsgs
if (lc($arg[2]) eq lc($opts{botnick})) { # to us, not channel
$arg[3] = lc(substr($arg[3],1)); # lowercase, strip leading :
if ($arg[3] eq "\1version\1") {
notice("\1VERSION $opts{gametitle} bot v$version by jotun/jrd; ".
"http://idlerpg.net/\1",$usernick);
}
elsif ($arg[3] eq "peval") {
if (!ha($username) || ($opts{ownerpevalonly} &&
$opts{owner} ne $username)) {
privmsg("You don't have access to PEVAL.", $usernick);
}
else {
my @peval = eval "@arg[4..$#arg]";
if (@peval >= 4 || length("@peval") > 1024) {
privmsg("Command produced too much output to send ".
"outright; queueing ".length("@peval").
" bytes in ".scalar(@peval)." items. Use ".
"CLEARQ to clear queue if needed.",$usernick,1);
privmsg($_,$usernick) for @peval;
}
else { privmsg($_,$usernick, 1) for @peval; }
privmsg("EVAL ERROR: $@", $usernick, 1) if $@;
}
}
elsif ($arg[3] eq "register") {
if (defined $username) {
privmsg("Sorry, you are already online as $username.",
$usernick);
}
else {
if ($#arg < 6 || $arg[6] eq "") {
privmsg("Try: REGISTER <char name> <password> <class>",
$usernick);
privmsg("IE : REGISTER Poseidon MyPassword God of the ".
"Sea",$usernick);
}
elsif ($pausemode) {
privmsg("Sorry, new accounts may not be registered ".
"while the bot is in pause mode; please wait ".
"a few minutes and try again.",$usernick);
}
elsif (exists $rps{$arg[4]} || ($opts{casematters} &&
scalar(grep { lc($arg[4]) eq lc($_) } keys(%rps)))) {
privmsg("Sorry, that character name is already in use.",
$usernick);
}
elsif (lc($arg[4]) eq lc($opts{botnick}) ||
lc($arg[4]) eq lc($primnick)) {
privmsg("Sorry, that character name cannot be ".
"registered.",$usernick);
}
elsif (!exists($onchan{$usernick})) {
privmsg("Sorry, you're not in $opts{botchan}.",
$usernick);
}
elsif (length($arg[4]) > 16 || length($arg[4]) < 1) {
privmsg("Sorry, character names must be < 17 and > 0 ".
"chars long.", $usernick);
}
elsif ($arg[4] =~ /^#/) {
privmsg("Sorry, character names may not begin with #.",
$usernick);
}
elsif ($arg[4] =~ /\001/) {
privmsg("Sorry, character names may not include ".
"character \\001.",$usernick);
}
elsif ($opts{noccodes} && ($arg[4] =~ /[[:cntrl:]]/ ||
"@arg[6..$#arg]" =~ /[[:cntrl:]]/)) {
privmsg("Sorry, neither character names nor classes ".
"may include control codes.",$usernick);
}
elsif ($opts{nononp} && ($arg[4] =~ /[[:^print:]]/ ||
"@arg[6..$#arg]" =~ /[[:^print:]]/)) {
privmsg("Sorry, neither character names nor classes ".
"may include non-printable chars.",$usernick);
}
elsif (length("@arg[6..$#arg]") > 30) {
privmsg("Sorry, character classes must be < 31 chars ".
"long.",$usernick);
}
elsif (time() == $lastreg) {
privmsg("Wait 1 second and try again.",$usernick);
}
else {
if ($opts{voiceonlogin}) {
sts("MODE $opts{botchan} +v :$usernick");
}
++$registrations;
$lastreg = time();
$rps{$arg[4]}{next} = $opts{rpbase};
$rps{$arg[4]}{class} = "@arg[6..$#arg]";
$rps{$arg[4]}{level} = 0;
$rps{$arg[4]}{online} = 1;
$rps{$arg[4]}{nick} = $usernick;
$rps{$arg[4]}{userhost} = $arg[0];
$rps{$arg[4]}{created} = time();
$rps{$arg[4]}{lastlogin} = time();
$rps{$arg[4]}{pass} = crypt($arg[5],mksalt());
$rps{$arg[4]}{x} = int(rand($opts{mapx}));
$rps{$arg[4]}{y} = int(rand($opts{mapy}));
$rps{$arg[4]}{alignment}="n";
$rps{$arg[4]}{isadmin} = 0;
for my $item ("ring","amulet","charm","weapon","helm",
"tunic","pair of gloves","shield",
"set of leggings","pair of boots") {
$rps{$arg[4]}{item}{$item} = 0;
}
for my $pen ("pen_mesg","pen_nick","pen_part",
"pen_kick","pen_quit","pen_quest",
"pen_logout","pen_logout") {
$rps{$arg[4]}{$pen} = 0;
}
if ($opts{newuserreports}) {
my $char = $arg[4];
my $class = "@arg[6..$#arg]";
my $host = $arg[0];
report_new ($char, $class, $usernick, $host);
}
chanmsg("Welcome $usernick\'s new player $arg[4], the ".
"@arg[6..$#arg]! Next level in ".
duration($opts{rpbase}).".");
privmsg("Success! Account $arg[4] created. You have ".
"$opts{rpbase} seconds idleness until you ".
"reach level 1. ", $usernick);
privmsg("NOTE: The point of the game is to see who ".
"can idle the longest. As such, talking in ".
"the channel, parting, quitting, and changing ".
"nicks all penalize you.",$usernick);
privmsg("WARNING: This is a development version of ".
"the game and as such may be stopped or even ".
"without warning.",$usernick);
if ($opts{phonehome}) {
my $tempsock = IO::Socket::INET->new(PeerAddr=>
"jotun.ultrazone.org:80");
if ($tempsock) {
print $tempsock
"GET /g7/count.php?new=1 HTTP/1.1\r\n".
"Host: jotun.ultrazone.org:80\r\n\r\n";
sleep(1);
close($tempsock);
}
}
}
}
}
elsif ($arg[3] eq "delold") {
if (!ha($username)) {
privmsg("You don't have access to DELOLD.", $usernick);
}
# insure it is a number
elsif ($arg[4] !~ /^[\d\.]+$/) {
privmsg("Try: DELOLD <# of days>", $usernick, 1);
}
else {
my @oldaccounts = grep { (time()-$rps{$_}{lastlogin}) >
($arg[4] * 86400) &&
!$rps{$_}{online} } keys(%rps);
delete(@rps{@oldaccounts});
chanmsg(scalar(@oldaccounts)." accounts not accessed in ".
"the last $arg[4] days removed by $arg[0].");
}
}
elsif ($arg[3] eq "del") {
if (!ha($username)) {
privmsg("You don't have access to DEL.", $usernick);
}
elsif (!defined($arg[4])) {
privmsg("Try: DEL <char name>", $usernick, 1);
}
elsif (!exists($rps{$arg[4]})) {
privmsg("No such account $arg[4].", $usernick, 1);
}
else {
delete($rps{$arg[4]});
chanmsg("Account $arg[4] removed by $arg[0].");
}
}
elsif ($arg[3] eq "mkadmin") {
if (!ha($username) || ($opts{owneraddonly} &&
$opts{owner} ne $username)) {
privmsg("You don't have access to MKADMIN.", $usernick);
}
elsif (!defined($arg[4])) {
privmsg("Try: MKADMIN <char name>", $usernick, 1);
}
elsif (!exists($rps{$arg[4]})) {
privmsg("No such account $arg[4].", $usernick, 1);
}
else {
$rps{$arg[4]}{isadmin}=1;
privmsg("Account $arg[4] is now a bot admin.",$usernick, 1);
}
}
elsif ($arg[3] eq "deladmin") {
if (!ha($username) || ($opts{ownerdelonly} &&
$opts{owner} ne $username)) {
privmsg("You don't have access to DELADMIN.", $usernick);
}
elsif (!defined($arg[4])) {
privmsg("Try: DELADMIN <char name>", $usernick, 1);
}
elsif (!exists($rps{$arg[4]})) {
privmsg("No such account $arg[4].", $usernick, 1);
}
elsif ($arg[4] eq $opts{owner}) {
privmsg("Cannot DELADMIN owner account.", $usernick, 1);
}
else {
$rps{$arg[4]}{isadmin}=0;
privmsg("Account $arg[4] is no longer a bot admin.",
$usernick, 1);
}
}
elsif ($arg[3] eq "hog") {
if (!ha($username)) {
privmsg("You don't have access to HOG.", $usernick);
}
else {
chanmsg("$usernick has summoned the Hand of God.");
hog();
}
}
elsif ($arg[3] eq "rehash") {
if (!ha($username)) {
privmsg("You don't have access to REHASH.", $usernick);
}
else {
readconfig();
privmsg("Reread config file.",$usernick,1);
$opts{botchan} =~ s/ .*//; # strip channel key if present
}
}
elsif ($arg[3] eq "chpass") {
if (!ha($username)) {
privmsg("You don't have access to CHPASS.", $usernick);
}
elsif (!defined($arg[5])) {
privmsg("Try: CHPASS <char name> <new pass>", $usernick, 1);
}
elsif (!exists($rps{$arg[4]})) {
privmsg("No such username $arg[4].", $usernick, 1);
}
else {
$rps{$arg[4]}{pass} = crypt($arg[5],mksalt());
privmsg("Password for $arg[4] changed.", $usernick, 1);
}
}
elsif ($arg[3] eq "chuser") {
if (!ha($username)) {
privmsg("You don't have access to CHUSER.", $usernick);
}
elsif (!defined($arg[5])) {
privmsg("Try: CHUSER <char name> <new char name>",
$usernick, 1);
}
elsif (!exists($rps{$arg[4]})) {
privmsg("No such username $arg[4].", $usernick, 1);
}
elsif (exists($rps{$arg[5]})) {
privmsg("Username $arg[5] is already taken.", $usernick,1);
}
else {
$rps{$arg[5]} = delete($rps{$arg[4]});
privmsg("Username for $arg[4] changed to $arg[5].",
$usernick, 1);
}
}
elsif ($arg[3] eq "chclass") {
if (!ha($username)) {
privmsg("You don't have access to CHCLASS.", $usernick);
}
elsif (!defined($arg[5])) {
privmsg("Try: CHCLASS <char name> <new char class>",
$usernick, 1);
}
elsif (!exists($rps{$arg[4]})) {
privmsg("No such username $arg[4].", $usernick, 1);
}
else {
$rps{$arg[4]}{class} = "@arg[5..$#arg]";
privmsg("Class for $arg[4] changed to @arg[5..$#arg].",
$usernick, 1);
}
}
elsif ($arg[3] eq "push") {
if (!ha($username)) {
privmsg("You don't have access to PUSH.", $usernick);
}
# insure it's a positive or negative, integral number of seconds
elsif ($arg[5] !~ /^\-?\d+$/) {
privmsg("Try: PUSH <char name> <seconds>", $usernick, 1);
}
elsif (!exists($rps{$arg[4]})) {
privmsg("No such username $arg[4].", $usernick, 1);
}
elsif ($arg[5] > $rps{$arg[4]}{next}) {
privmsg("Time to level for $arg[4] ($rps{$arg[4]}{next}s) ".
"is lower than $arg[5]; setting TTL to 0.",
$usernick, 1);
chanmsg("$usernick has pushed $arg[4] $rps{$arg[4]}{next} ".
"seconds toward level ".($rps{$arg[4]}{level}+1));
$rps{$arg[4]}{next}=0;
}
else {
$rps{$arg[4]}{next} -= $arg[5];
chanmsg("$usernick has pushed $arg[4] $arg[5] seconds ".
"toward level ".($rps{$arg[4]}{level}+1).". ".
"$arg[4] reaches next level in ".
duration($rps{$arg[4]}{next}).".");
}
}
elsif ($arg[3] eq "logout") {
if (defined($username)) {
penalize($username,"logout");
}
else {
privmsg("You are not logged in.", $usernick);
}
}
elsif ($arg[3] eq "quest") {
if (!@{$quest{questers}}) {
privmsg("There is no active quest.",$usernick);
}
elsif ($quest{type} == 1) {
privmsg(join(", ",(@{$quest{questers}})[0..2]).", and ".
"$quest{questers}->[3] are on a quest to ".
"$quest{text}. Quest to complete in ".
duration($quest{qtime}-time()).".",$usernick);
}
elsif ($quest{type} == 2) {
privmsg(join(", ",(@{$quest{questers}})[0..2]).", and ".
"$quest{questers}->[3] are on a quest to ".
"$quest{text}. Participants must first reach ".
"[$quest{p1}->[0],$quest{p1}->[1]], then ".
"[$quest{p2}->[0],$quest{p2}->[1]].".
($opts{mapurl}?" See $opts{mapurl} to monitor ".
"their journey's progress.":""),$usernick);
}
}
elsif ($arg[3] eq "status" && $opts{statuscmd}) {
if (!defined($username)) {
privmsg("You are not logged in.", $usernick);
}
# argument is optional
elsif ($arg[4] && !exists($rps{$arg[4]})) {
privmsg("No such user.",$usernick);
}
elsif ($arg[4]) { # optional 'user' argument
privmsg("$arg[4]: Level $rps{$arg[4]}{level} ".
"$rps{$arg[4]}{class}; Status: O".
($rps{$arg[4]}{online}?"n":"ff")."line; ".
"TTL: ".duration($rps{$arg[4]}{next})."; ".
"Idled: ".duration($rps{$arg[4]}{idled}).
"; Item sum: ".itemsum($arg[4]),$usernick);
}
else { # no argument, look up this user
privmsg("$username: Level $rps{$username}{level} ".
"$rps{$username}{class}; Status: O".
($rps{$username}{online}?"n":"ff")."line; ".
"TTL: ".duration($rps{$username}{next})."; ".
"Idled: ".duration($rps{$username}{idled})."; ".
"Item sum: ".itemsum($username),$usernick);
}
}
elsif ($arg[3] eq "whoami") {
if (!defined($username)) {
privmsg("You are not logged in.", $usernick);
}
else {
privmsg("You are $username, the level ".
$rps{$username}{level}." $rps{$username}{class}. ".
"Next level in ".duration($rps{$username}{next}),
$usernick);
}
}
elsif ($arg[3] eq "newpass") {
if (!defined($username)) {
privmsg("You are not logged in.", $usernick)
}
elsif (!defined($arg[4])) {
privmsg("Try: NEWPASS <new password>", $usernick);
}
else {
$rps{$username}{pass} = crypt($arg[4],mksalt());
privmsg("Your password was changed.",$usernick);
}
}
elsif ($arg[3] eq "align") {
if (!defined($username)) {
privmsg("You are not logged in.", $usernick)
}
elsif (!defined($arg[4]) || (lc($arg[4]) ne "good" &&
lc($arg[4]) ne "neutral" && lc($arg[4]) ne "evil")) {
privmsg("Try: ALIGN <good|neutral|evil>", $usernick);
}
else {
$rps{$username}{alignment} = substr(lc($arg[4]),0,1);
chanmsg("$username has changed alignment to: ".lc($arg[4]).
".");
privmsg("Your alignment was changed to ".lc($arg[4]).".",
$usernick);
}
}
elsif ($arg[3] eq "removeme") {
if (!defined($username)) {
privmsg("You are not logged in.", $usernick)
}
else {
privmsg("Account $username removed.",$usernick);
chanmsg("$arg[0] removed their account, $username, the ".
$rps{$username}{class}.".");
delete($rps{$username});
}
}
elsif ($arg[3] eq "help") {
if (!ha($username)) {
privmsg("For information on IRPG bot commands, see ".
$opts{helpurl}, $usernick);
}
else {
privmsg("Help URL is $opts{helpurl}", $usernick, 1);
privmsg("Admin commands URL is $opts{admincommurl}",
$usernick, 1);
}
}
elsif ($arg[3] eq "die") {
if (!ha($username)) {
privmsg("You do not have access to DIE.", $usernick);
}
else {
$opts{reconnect} = 0;
writedb();
chanmsg ("$opts{gametitle} is taking a short break and shall return shortly.");
fq ();
sts("QUIT :DIE from $arg[0]",1);
}
}
elsif ($arg[3] eq "reloaddb") {
if (!ha($username)) {
privmsg("You do not have access to RELOADDB.", $usernick);
}
elsif (!$pausemode) {
privmsg("ERROR: Can only use LOADDB while in PAUSE mode.",
$usernick, 1);
}
else {
loaddb();
privmsg("Reread player database file; ".scalar(keys(%rps)).
" accounts loaded.",$usernick,1);
}
}
elsif ($arg[3] eq "backup") {
if (!ha($username)) {
privmsg("You do not have access to BACKUP.", $usernick);
}
else {
backup();
privmsg("$opts{dbfile} copied to ".
".dbbackup/$opts{dbfile}-".time(),$usernick,1);
}
}
elsif ($arg[3] eq "pause") {
if (!ha($username)) {
privmsg("You do not have access to PAUSE.", $usernick);
}
else {
$pausemode = $pausemode ? 0 : 1;
privmsg("PAUSE_MODE set to $pausemode.",$usernick,1);
}
}
elsif ($arg[3] eq "silent") {
if (!ha($username)) {
privmsg("You do not have access to SILENT.", $usernick);
}
elsif (!defined($arg[4]) || $arg[4] < 0 || $arg[4] > 3) {
privmsg("Try: SILENT <mode>", $usernick,1);
}
else {
$silentmode = $arg[4];
privmsg("SILENT_MODE set to $silentmode.",$usernick,1);
}
}
elsif ($arg[3] eq "jump") {
if (!ha($username)) {
privmsg("You do not have access to JUMP.", $usernick);
}
elsif (!defined($arg[4])) {
privmsg("Try: JUMP <server[:port]>", $usernick, 1);
}
else {
writedb();
sts("QUIT :JUMP to $arg[4] from $arg[0]");
unshift(@{$opts{servers}},$arg[4]);
close($sock);
sleep(3);
goto CONNECT;
}
}
elsif ($arg[3] eq "restart") {
if (!ha($username)) {
privmsg("You do not have access to RESTART.", $usernick);
}
else {
writedb();
chanmsg("*** $opts{gametitle} ver $version is restarting ***");
fq();
sts("QUIT :RESTART from $arg[0]",1);
close($sock);
exec("perl $0");
}
}
elsif ($arg[3] eq "clearq") {
if (!ha($username)) {
privmsg("You do not have access to CLEARQ.", $usernick);
}
else {
undef(@queue);
chanmsg("Outgoing message queue cleared by $arg[0].");
privmsg("Outgoing message queue cleared.",$usernick,1);
}
}
elsif ($arg[3] eq "info") {
my $info;
if (!ha($username) && $opts{allowuserinfo}) {
$info = "IRPG bot v$version by jotun, ".
"http://idlerpg.net/. On via server: ".
$opts{servers}->[0].". Admins online: ".
join(", ", map { $rps{$_}{nick} }
grep { $rps{$_}{isadmin} &&
$rps{$_}{online} } keys(%rps)).".";
privmsg($info, $usernick);
}
elsif (!ha($username) && !$opts{allowuserinfo}) {
privmsg("You do not have access to INFO.", $usernick);
}
else {
my $queuedbytes = 0;
$queuedbytes += (length($_)+2) for @queue; # +2 = \r\n
$info = sprintf(
"%.2fkb sent, %.2fkb received in %s. %d IRPG users ".
"online of %d total users. %d accounts created since ".
"startup. PAUSE_MODE is %d, SILENT_MODE is %d. ".
"Outgoing queue is %d bytes in %d items. On via: %s. ".
"Admins online: %s.",
$outbytes/1024,
$inbytes/1024,
duration(time()-$^T),
scalar(grep { $rps{$_}{online} } keys(%rps)),
scalar(keys(%rps)),
$registrations,
$pausemode,
$silentmode,
$queuedbytes,
scalar(@queue),
$opts{servers}->[0],
join(", ",map { $rps{$_}{nick} }
grep { $rps{$_}{isadmin} && $rps{$_}{online} }
keys(%rps)));
privmsg($info, $usernick, 1);
}
}
elsif ($arg[3] eq "login") {
if (defined($username)) {
notice("Sorry, you are already online as $username.",
$usernick);
}