ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/chat.ext
Revision: 1.19
Committed: Tue Jun 19 17:32:56 2007 UTC (16 years, 11 months ago) by root
Branch: MAIN
Changes since 1.18: +1 -1 lines
Log Message:
fix some dialog bugs (by elmex)

File Contents

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