ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/chat.ext
Revision: 1.7
Committed: Wed Feb 28 19:32:56 2007 UTC (17 years, 2 months ago) by pippijn
Branch: MAIN
Changes since 1.6: +20 -0 lines
Log Message:
added defaults

File Contents

# Content
1 #! perl
2 #CONVERSION: PARTIAL
3
4 # implement a replacement for the built-in say/chat/shout/tell/reply commands
5 # adds ignore/unignore functionality
6
7 use NPC_Dialogue;
8 use POSIX (); # for strftime only
9
10 sub clean_timeouts($) {
11 my ($player) = @_;
12 my $NOW = time;
13
14 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
15 while (my ($k, $v) = each %$hash) {
16 if ($v < $NOW) {
17 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE);
18 delete $hash->{$k};
19 } elsif (!cf::player::exists $k) {
20 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE);
21 delete $hash->{$k};
22 }
23 }
24 }
25 }
26
27 cf::player->attach (
28 prio => -1000,
29 on_login => sub {
30 my ($pl) = @_;
31
32 clean_timeouts $pl->ob;
33 },
34
35 1
36 );
37
38 cf::register_command listen => sub {
39 my ($who, $msg) = @_;
40 my $player = cf::player::find_active $who->name;
41
42 if ($msg ne "") {
43 my $prev_listen = $player->listening;
44 $player->listening ($msg);
45 if ($prev_listen == $player->listening) {
46 $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE);
47 } else {
48 $who->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE);
49 }
50 } else {
51 $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE);
52 }
53
54 1
55 };
56
57 my $emotes = {
58 growl => {
59 noparams => {
60 other => "<self> growls.",
61 self => "Grrrrrrrrr....",
62 },
63 params => {
64 },
65 self => {
66 },
67 },
68 giggle => {
69 noparams => {
70 other => "<self> giggles.",
71 self => "You giggle.",
72 },
73 params => {
74 },
75 self => {
76 },
77 },
78 shiver => {
79 noparams => {
80 other => "<self> shivers uncomfortably.",
81 self => "Brrrrrrrrr.",
82 },
83 params => {
84 },
85 self => {
86 },
87 },
88 chuckle => {
89 noparams => {
90 other => "<self> chuckles politely.",
91 self => "You chuckle politely",
92 },
93 params => {
94 },
95 self => {
96 },
97 },
98 sigh => {
99 noparams => {
100 other => "<self> sighs loudly.",
101 self => "You sigh.",
102 },
103 params => {
104 },
105 self => {
106 },
107 },
108 scream => {
109 noparams => {
110 other => "<self> screams at the top of his lungs!",
111 self => "ARRRRRRRRRRGH!!!!!",
112 },
113 params => {
114 },
115 self => {
116 },
117 },
118 puke => {
119 noparams => {
120 other => "<self> pukes.",
121 self => "Bleaaaaaghhhhhhh!",
122 },
123 params => {
124 target => "<self> pukes on your clothes!",
125 other => "<self> pukes on <other>.",
126 self => "You puke on <other>.",
127 },
128 self => {
129 other => "<self> pukes on his clothes.",
130 self => "You puke on yourself.",
131 },
132 },
133 strut => {
134 noparams => {
135 other => "<self> struts proudly.",
136 self => "Strut your stuff.",
137 },
138 params => {
139 },
140 self => {
141 },
142 },
143 cringe => {
144 noparams => {
145 other => "<self> cringes in terror!",
146 self => "You cringe in terror.",
147 },
148 params => {
149 target => "<self> cringes away from <other> in mortal terror.",
150 self => "You cringe away from <other>.",
151 },
152 self => {
153 },
154 },
155 hiccup => {
156 noparams => {
157 other => "<self> hiccups.",
158 self => "*HIC*",
159 },
160 params => {
161 },
162 self => {
163 },
164 },
165 clap => {
166 noparams => {
167 other => "<self> gives a round of applause.",
168 self => "Clap, clap, clap.",
169 },
170 params => {
171 },
172 self => {
173 },
174 },
175 kiss => {
176 noparams => {
177 other => "<self> makes a weird facial contortion",
178 self => "All the lonely people..",
179 },
180 params => {
181 target => "<self> kisses you.",
182 other => "<self> kisses <other>.",
183 self => "You kiss <other>.",
184 },
185 self => {
186 },
187 },
188 wink => {
189 noparams => {
190 other => "<self> winks suggestively.",
191 self => "Have you got something in your eye?",
192 },
193 params => {
194 target => "<self> winks at <other>.",
195 self => "You wink suggestively at <other>.",
196 },
197 self => {
198 other => "<self> winks at himself - something strange is going on...",
199 self => "You wink at yourself?? What are you up to?",
200 },
201 },
202 pout => {
203 noparams => {
204 other => "<self> pouts.",
205 self => "Aww, don't take it so hard.",
206 },
207 params => {
208 },
209 self => {
210 },
211 },
212 cackle => {
213 noparams => {
214 other => "<self> throws back his head and cackles with insane glee!",
215 self => "You cackle gleefully.",
216 },
217 params => {
218 },
219 self => {
220 },
221 },
222 sniff => {
223 noparams => {
224 other => "<self> sniffs sadly.",
225 self => "You sniff sadly. *SNIFF*",
226 },
227 params => {
228 target => "<self> sniffs you.",
229 other => "<self> sniffs <other>",
230 self => "You sniff <other>.",
231 },
232 self => {
233 other => "<self> sniffs himself.",
234 self => "You sniff yourself.",
235 },
236 },
237 nod => {
238 noparams => {
239 other => "<self> nods solemnly.",
240 self => "You nod solemnly.",
241 },
242 params => {
243 target => "<self> nods solemnly to you.",
244 other => "<self> nods solemnly to <other>.",
245 self => "You nod solemnly to <other>.",
246 },
247 self => {
248 },
249 },
250 frown => {
251 noparams => {
252 other => "<self> frowns.",
253 self => "What's bothering you?",
254 },
255 params => {
256 target => "<self> frowns darkly at you.",
257 other => "<self> frowns darkly at <other>.",
258 self => "You frown darkly at <other>.",
259 },
260 self => {
261 other => "<self> frowns at himself.",
262 self => "You frown at yourself.",
263 },
264 },
265 snicker => {
266 noparams => {
267 other => "<self> snickers softly.",
268 self => "You snicker softly.",
269 },
270 params => {
271 },
272 self => {
273 },
274 },
275 shrug => {
276 noparams => {
277 other => "<self> shrugs helplessly.",
278 self => "You shrug.",
279 },
280 params => {
281 target => "<self> shrugs at you.",
282 other => "<self> shrugs at <other>.",
283 self => "You shrug at <other>.",
284 },
285 self => {
286 },
287 },
288 bleed => {
289 noparams => {
290 other => "<self> is bleeding all over the carpet - got a spare tourniquet?",
291 self => "You bleed all over your nice new armour.",
292 },
293 params => {
294 target => "<self> slashes his wrist and bleeds all over <other>.",
295 self => "You slash your wrist and bleed all over <other>",
296 },
297 self => {
298 other => "<self> performs some satanic ritual while wiping his blood on himself.",
299 self => "Very impressive! You wipe your blood all over yourself.",
300 },
301 },
302 twiddle => {
303 noparams => {
304 other => "<self> patiently twiddles his thumbs.",
305 self => "You patiently twiddle your thumbs.",
306 },
307 params => {
308 },
309 self => {
310 },
311 },
312 spit => {
313 noparams => {
314 other => "<self> spits over his left shoulder.",
315 self => "You spit over your left shoulder.",
316 },
317 params => {
318 target => "<self> spits in your face!",
319 other => "<self> spits in <other>'s face.",
320 self => "You spit on <other>.",
321 },
322 self => {
323 other => "<self> drools all over himself.",
324 self => "You drool all over yourself.",
325 },
326 },
327 glare => {
328 noparams => {
329 other => "<self> glares around him.",
330 self => "You glare at nothing in particular.",
331 },
332 params => {
333 target => "<self> glares icily at you, you feel cold to your bones.",
334 other => "<self> glares at <other>.",
335 self => "You glare icily at <other>.",
336 },
337 self => {
338 other => "<self> glares at his feet, what is bothering him?",
339 self => "You glare icily at your feet, they are suddenly very cold.",
340 },
341 },
342 bow => {
343 noparams => {
344 other => "<self> bows deeply.",
345 self => "You bow deeply.",
346 },
347 params => {
348 target => "<self> bows before you.",
349 other => "<self> bows before <other>.",
350 self => "You bow before <other>.",
351 },
352 self => {
353 other => "<self> folds up like a jackknife and kisses his own toes.",
354 self => "You kiss your toes.",
355 },
356 },
357 dance => {
358 noparams => {
359 other => "<self> expresses himself through interpretive dance.",
360 self => "You dance with glee.",
361 },
362 params => {
363 target => "<self> grabs you, and begins dancing!",
364 other => "Yipe! <self> and <other> are doing the Macarena!",
365 self => "You grab <other> and begin doing the Cha-Cha!",
366 },
367 self => {
368 other => "<self> embraces himself and begins to dance!",
369 self => "You skip and dance around by yourself.",
370 },
371 },
372 snore => {
373 noparams => {
374 other => "<self> snores loudly.",
375 self => "Zzzzzzzzzzzzzzz.",
376 },
377 params => {
378 },
379 self => {
380 },
381 },
382 blush => {
383 noparams => {
384 other => "<self> blushes.",
385 self => "Your cheeks are burning.",
386 },
387 params => {
388 },
389 self => {
390 },
391 },
392 snap => {
393 noparams => {
394 other => "<self> snaps his fingers.",
395 self => "PRONTO! you snap your fingers.",
396 },
397 params => {
398 },
399 self => {
400 },
401 },
402 wave => {
403 noparams => {
404 other => "<self> waves happily.",
405 self => "You wave.",
406 },
407 params => {
408 target => "<self> waves goodbye to you. Have a good journey.",
409 other => "<self> waves goodbye to <other>.",
410 self => "You wave goodbye to <other>.",
411 },
412 self => {
413 other => "<self> waves goodbye to himself.",
414 self => "Are you going on adventures as well??",
415 },
416 },
417 smile => {
418 noparams => {
419 other => "<self> smiles happily.",
420 self => "You smile happily.",
421 },
422 params => {
423 target => "<self> smiles at you.",
424 other => "<self> beams a smile at <other>.",
425 self => "You smile at <other>.",
426 },
427 self => {
428 },
429 },
430 sneeze => {
431 noparams => {
432 other => "<self> sneezes.",
433 self => "Gesundheit!",
434 },
435 params => {
436 target => "<self> sneezes on you, you feel the snot cover you. EEEEEEW.",
437 other => "<self> sneezes on <other> and a film of snot covers him.",
438 self => "You sneeze at <other> and a film of snot shoots onto him.",
439 },
440 self => {
441 other => "<self> sneezes, and covers himself in a slimy substance.",
442 self => "You sneeze on yourself, what a mess!",
443 },
444 },
445 bounce => {
446 noparams => {
447 other => "<self> bounces around.",
448 self => "BOIINNNNNNGG!",
449 },
450 params => {
451 target => "<self> bounces around the room with you.",
452 other => "<self> bounces around the room with <other>.",
453 self => "You bounce around the room with <other>.",
454 },
455 self => {
456 },
457 },
458 shake => {
459 noparams => {
460 other => "<self> shakes his head.",
461 self => "You shake your head.",
462 },
463 params => {
464 target => "<self> shakes your hand.",
465 other => "<self> shakes <other>'s hand.",
466 self => "You shake <other>'s hand.",
467 },
468 self => {
469 other => "<self> shakes and quivers like a bowlful of jelly.",
470 self => "You are shaken by yourself.",
471 },
472 },
473 lick => {
474 noparams => {
475 other => "<self> licks his mouth and smiles.",
476 self => "You lick your mouth and smile.",
477 },
478 params => {
479 target => "<self> licks you.",
480 other => "<self> licks <other>.",
481 self => "You lick <other>.",
482 },
483 self => {
484 other => "<self> licks himself - YUCK.",
485 self => "You lick yourself.",
486 },
487 },
488 flip => {
489 noparams => {
490 other => "<self> flips head over heels.",
491 self => "You flip head over heels.",
492 },
493 params => {
494 },
495 self => {
496 },
497 },
498 think => {
499 noparams => {
500 other => "<self> closes his eyes and thinks really hard.",
501 self => "Anything in particular that you'd care to think about?",
502 },
503 params => {
504 },
505 self => {
506 },
507 },
508 yawn => {
509 noparams => {
510 other => "<self> yawns sleepily.",
511 self => "You open up your yap and let out a big breeze of stale air.",
512 },
513 params => {
514 },
515 self => {
516 },
517 },
518 laugh => {
519 noparams => {
520 other => "<self> falls down laughing.",
521 self => "You fall down laughing.",
522 },
523 params => {
524 target => "<self> looks at you and falls down on the ground laughing.",
525 other => "<self> looks at <other> and falls down on the ground laughing.",
526 self => "You take one look at <other> and fall down laughing.",
527 },
528 self => {
529 other => "<self> is laughing at something.",
530 self => "Laugh at yourself all you want, the others won't understand.",
531 },
532 },
533 burp => {
534 noparams => {
535 other => "<self> burps loudly.",
536 self => "You burp loudly.",
537 },
538 params => {
539 },
540 self => {
541 },
542 },
543 gasp => {
544 noparams => {
545 other => "<self> gasps in astonishment.",
546 self => "You gasp in astonishment.",
547 },
548 params => {
549 },
550 self => {
551 },
552 },
553 smirk => {
554 noparams => {
555 other => "<self> smirks.",
556 self => "You smirk.",
557 },
558 params => {
559 },
560 self => {
561 },
562 },
563 cry => {
564 noparams => {
565 other => "<self> bursts into tears.",
566 self => "Waaaaaaahhh..",
567 },
568 params => {
569 target => "<self> cries on your shoulder.",
570 other => "<self> cries on <other>'s shoulder.",
571 self => "You cry on <other>'s shoulder.",
572 },
573 self => {
574 other => "<self> sobs quietly to himself.",
575 self => "You cry to yourself.",
576 },
577 },
578 sulk => {
579 noparams => {
580 other => "<self> sulks in the corner.",
581 self => "You sulk.",
582 },
583 params => {
584 },
585 self => {
586 },
587 },
588 whistle => {
589 noparams => {
590 other => "<self> whistles appreciatively.",
591 self => "You whistle appreciatively.",
592 },
593 params => {
594 target => "<self> whistles at <other>.",
595 self => "You whistle at <other>.",
596 },
597 self => {
598 other => "<self> whistles to himself in boredom.",
599 self => "You whistle while you work.",
600 },
601 },
602 groan => {
603 noparams => {
604 other => "<self> groans loudly.",
605 self => "You groan loudly.",
606 },
607 params => {
608 },
609 self => {
610 },
611 },
612 cough => {
613 noparams => {
614 other => "<self> coughs loudly.",
615 self => "Yuck, try to cover your mouth next time!",
616 },
617 params => {
618 },
619 self => {
620 },
621 },
622 grin => {
623 noparams => {
624 other => "<self> grins evilly.",
625 self => "You grin evilly.",
626 },
627 params => {
628 target => "<self> grins evilly at you.",
629 other => "<self> grins evilly at <other>.",
630 self => "You grin at <other>.",
631 },
632 self => {
633 },
634 },
635 };
636
637 for my $emotion (keys %$emotes) {
638 cf::register_command $emotion => sub {
639 my ($ob, $tname) = @_;
640
641 cf::async {
642 my $name = $ob->name;
643
644 if ($tname eq $name) {
645 my $emote = $emotes->{$emotion}->{self};
646
647 $emote->{other} = "You look away from <self>."
648 if !$emote->{other};
649 $emote->{self} = "My god! Is that LEGAL?"
650 if !$emote->{self};
651
652 $emote->{other} =~ s/<self>/$name/;
653
654 for my $other ( grep { $ob->on_same_map_as ($_->ob) } cf::player::list ) {
655 next
656 if $other->ob == $ob;
657 $other->ob->message ($emote->{other}, cf::NDI_GREY | cf::NDI_UNIQUE);
658 }
659
660 $ob->message ($emote->{self}, cf::NDI_GREY | cf::NDI_UNIQUE);
661 } elsif ($tname) {
662 my $target = cf::player::find $tname
663 or return $ob->reply (undef, "$tname is not around.");
664
665 my $emote = $emotes->{$emotion}->{params};
666
667 $emote->{other} = "<self> is eyeing <other> quizzically."
668 if !$emote->{other};
669 $emote->{self} = "You are still nuts."
670 if !$emote->{self};
671 $emote->{target} = "You get the distinct feeling that <other> is nuts."
672 if !$emote->{target};
673
674 $emote->{self} =~ s/<other>/$tname/;
675 $emote->{target} =~ s/<self>/$name/;
676 $emote->{other} =~ s/<other>/$tname/;
677 $emote->{other} =~ s/<self>/$name/;
678
679 for my $other ( grep { $ob->on_same_map_as ($_->ob) } cf::player::list ) {
680 next
681 if $other->ob == $ob or $other == $target;
682 $other->ob->message ($emote->{other}, cf::NDI_GREY | cf::NDI_UNIQUE);
683 }
684
685 $target->ob->message ($emote->{target}, cf::NDI_GREY | cf::NDI_UNIQUE);
686 $ob->message ($emote->{self}, cf::NDI_GREY | cf::NDI_UNIQUE);
687 } else {
688 my $emote = $emotes->{$emotion}->{noparams};
689 $emote->{other} =~ s/<self>/$name/;
690
691 $emote->{other} = "<self> dances with glee."
692 if !$emote->{other};
693 $emote->{self} = "You are a nut."
694 if !$emote->{self};
695
696 for my $other ( grep { $ob->on_same_map_as ($_->ob) } cf::player::list ) {
697 next
698 if $other->ob == $ob;
699 $other->ob->message ($emote->{other}, cf::NDI_GREY | cf::NDI_UNIQUE);
700 }
701
702 $ob->message ($emote->{self}, cf::NDI_GREY | cf::NDI_UNIQUE);
703 }
704 };
705 };
706 }
707
708 cf::register_command say => sub {
709 my ($who, $msg) = @_;
710
711 utf8::decode $msg;
712
713 return if $who->contr->invoke (cf::EVENT_PLAYER_SAY, $msg);
714
715 if ($msg) {
716 my $name = $who->name;
717
718 utf8::encode $msg; # ->message not yet utf8-ified
719 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
720 for grep $who->on_same_map_as ($_->ob), cf::player::list;
721 utf8::decode $msg;
722
723 # npcs, magic_ears etc.
724 # first find all objects and theirt-level inventories
725 # within a 5x5 square # that have something resembling
726 # dialogue or support on_say.
727 my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2);
728
729 for my $npc (
730 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $who->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_,
731 map +($_, $_->inv),
732 grep $_,
733 map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
734 0..24
735 ) {
736 # if some listener teleported us somewhere else, stop right here
737 last unless $map->path == $who->map->path;
738
739 my $dialog = new NPC_Dialogue ob => $who, npc => $npc;
740 my ($reply, @kw) = $dialog->tell ($msg);
741
742 if (defined $reply) {
743 if ($npc->type == cf::MAGIC_EAR) {
744 if (length $reply) {
745 $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE)
746 for grep $who->on_same_map_as ($_->ob), cf::player::list;
747 }
748 $npc->use_trigger;
749 } else {
750 if (length $reply) {
751 $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE)
752 for grep $who->on_same_map_as ($_->ob), cf::player::list;
753 }
754 }
755 }
756
757 if (@kw) {
758 $_->ob->message ("[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN | cf::NDI_UNIQUE)
759 for grep $who->on_same_map_as ($_->ob), cf::player::list;
760 }
761 }
762
763 } else {
764 $who->message ("What do you want to say?", cf::NDI_UNIQUE);
765 }
766
767 1
768 };
769
770 cf::register_command chat => sub {
771 my ($who, $msg) = @_;
772
773 utf8::decode $msg;
774
775 return if $who->contr->invoke (cf::EVENT_PLAYER_CHAT, $msg);
776
777 if ($msg) {
778 my $name = $who->name;
779 my $NOW = time;
780
781 utf8::encode $msg; # ->message not yet utf8-ified
782 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
783 ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg);
784
785 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
786 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
787
788 } else {
789 $who->message ("Chat what?", cf::NDI_UNIQUE);
790 }
791
792 1
793 };
794
795 cf::register_command shout => sub {
796 my ($who, $msg) = @_;
797
798 utf8::decode $msg;
799
800 return if $who->contr->invoke (cf::EVENT_PLAYER_SHOUT, $msg);
801
802 if ($msg) {
803 my $NOW = time;
804 my $name = $who->name;
805
806 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
807 ext::schmorp_irc::do_notice (sprintf "\007\0034{%s} %s\n", $name, $msg);
808
809 utf8::encode $msg; # ->message not yet utf8-ified
810 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
811 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
812
813 } else {
814 $who->message ("Shout what?", cf::NDI_UNIQUE);
815 }
816
817 1
818 };
819
820 cf::register_command tell => sub {
821 my ($who, $args) = @_;
822 my ($target, $msg) = split /\s+/, $args, 2;
823
824 utf8::decode $msg;
825
826 return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $target, $msg);
827
828 my $name = $who->name;
829
830 if ($target =~ /irc\//) {
831 my (undef, $nick) = split /\//, $target, 2;
832 $who->message ("You tell $target: $args");
833 ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $msg);
834 } elsif (my $other = cf::player::find_active $target) {
835
836 if ($msg) {
837 if ($target eq $name) {
838 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
839 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
840 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE);
841 } else {
842 utf8::encode $msg; # ->message not yet utf8-ified
843 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
844
845 $who->message ("You tell $target: $msg");
846 $other->ob->message ("$name tells you: $msg");
847 $other->ob->{ext_last_tell} = $name;
848 }
849 } else {
850 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
851 }
852
853 } else {
854 $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE);
855 }
856
857 1
858 };
859
860 cf::register_command reply => sub {
861 my ($who, $args) = @_;
862 my $name = $who->name;
863
864 utf8::decode $args;
865
866 return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $who->{ext_last_tell}, $args);
867
868 if ($who->{ext_last_tell} =~ /irc\//) {
869 my (undef, $nick) = split /\//, $who->{ext_last_tell}, 2;
870 $who->message ("You tell " . $who->{ext_last_tell} . ": $args");
871 ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $args);
872 } elsif (my $other = cf::player::find_active $who->{ext_last_tell}) {
873
874 if ($args) {
875 $other->ob->{ext_ignore_tell}{$name} >= time
876 or delete $other->ob->{ext_ignore_tell}{$name};
877
878 if ($other->ob->{ext_ignore_tell}{$name} < time) {
879 utf8::encode $args; # ->message not yet utf8-ified
880 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args;
881
882 $who->message ("You tell " . $other->ob->name . ": $args");
883 $other->ob->message ("$name tells you: $args");
884 $who->{ext_last_tell} = $other->ob->name;
885 } else {
886 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
887 }
888 } else {
889 $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE);
890 }
891
892 } else {
893 $who->message ("Can't reply, player left. Your message: $args".$who->{ext_last_tell}, cf::NDI_UNIQUE);
894 }
895
896 1
897 };
898
899 cf::register_command ignore => sub {
900 my ($who, $args) = @_;
901 my ($target, $type, $timeout) = split /\s+/, $args;
902
903 if ($args eq "list") {
904 clean_timeouts $who;
905
906 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}})
907 + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) {
908 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
909 $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE);
910 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
911 $who->message ((join ", ", @ignored_shout), cf::NDI_UNIQUE);
912 $who->message ("To stop ignoring one, use unignore.", cf::NDI_UNIQUE);
913 } else {
914 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
915 }
916
917 } elsif ($target && $type) {
918
919 $timeout ne "" or $timeout = 24;
920 my $absolute_timeout = time + $timeout * 3600;
921
922 if (cf::player::exists $target) {
923 if ($type eq "tell") {
924 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE);
925 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
926 } elsif ($type eq "shout") {
927 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE);
928 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
929 } elsif ($type eq "all") {
930 $who->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE);
931 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
932 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
933 } else {
934 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
935 }
936 } else {
937 $who->message ("No such player: $target", cf::NDI_UNIQUE);
938 }
939
940 } else {
941 $who->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
942 . "will ignore a player for <timeout> hours.\n"
943 . "Usage: ignore list\n"
944 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE);
945 }
946
947 1
948 };
949
950 cf::register_command unignore => sub {
951 my ($who, $args) = @_;
952 my ($target, $type) = split /\s+/, $args;
953
954 if ($args eq "") {
955 if ($who->{ext_ignore_tell}) {
956 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
957 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE);
958 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
959 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE);
960 } else {
961 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
962 }
963 } else {
964 if (cf::player::exists $target) {
965 if ($type eq "tell") {
966 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE);
967 delete $who->{ext_ignore_tell} {$target};
968 } elsif ($type eq "shout") {
969 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE);
970 delete $who->{ext_ignore_shout}{$target};
971 } elsif ($type eq "all") {
972 $who->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE);
973 delete $who->{ext_ignore_tell} {$target};
974 delete $who->{ext_ignore_shout}{$target};
975 } else {
976 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
977 }
978 } else {
979 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE);
980 }
981 }
982
983 1
984 };
985
986 cf::register_command seen => sub {
987 my ($who, $args) = @_;
988
989 if (my ($login) = $args =~ /(\S+)/) {
990 if ($login eq $who->name) {
991 $who->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE);
992 } elsif (cf::player::find_active $login) {
993 $who->message ("$login is right here on this server!", cf::NDI_UNIQUE);
994 } elsif (cf::player::exists $login
995 and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) {
996 my $time = (stat _)[9];
997
998 $who->message ("$login was last seen here "
999 . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time)
1000 . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE);
1001 } else {
1002 $who->message ("No player named $login is known to me.", cf::NDI_UNIQUE);
1003 }
1004 } else {
1005 $who->message ("Usage: seen <player>", cf::NDI_UNIQUE);
1006 }
1007
1008 1
1009 };
1010