ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/chat.ext
Revision: 1.41
Committed: Mon Jul 14 23:57:45 2008 UTC (15 years, 10 months ago) by root
Branch: MAIN
CVS Tags: rel-2_6, rel-2_61
Changes since 1.40: +1 -1 lines
Log Message:
introduce and use object::has_dialogue ()

File Contents

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