ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/chat.ext
Revision: 1.20
Committed: Thu Jun 28 08:34:42 2007 UTC (16 years, 11 months ago) by elmex
Branch: MAIN
Changes since 1.19: +14 -4 lines
Log Message:
made multiline chats possible

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