ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/chat.ext
Revision: 1.21
Committed: Fri Jul 20 16:11:10 2007 UTC (16 years, 10 months ago) by root
Branch: MAIN
Changes since 1.20: +64 -79 lines
Log Message:
preliminary chat channel implementation

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