ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/chat.ext
Revision: 1.31
Committed: Mon Aug 20 19:13:10 2007 UTC (16 years, 9 months ago) by root
Branch: MAIN
Changes since 1.30: +1 -1 lines
Log Message:
- hopefully fix say w.r.t. NDI_REPLY
- rework the disease code a bit.
- set_owene rfater inserting whne throwing or diseasing. these
  are the only cases i know where the owner is set when inserting into
  another object. *cough*

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