ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/chat.ext
Revision: 1.32
Committed: Sun Sep 2 08:43:46 2007 UTC (16 years, 8 months ago) by root
Branch: MAIN
CVS Tags: rel-2_2
Changes since 1.31: +1 -0 lines
Log Message:
prepare cfplus release

File Contents

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