ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/chat.ext
Revision: 1.12
Committed: Fri Mar 2 00:29:08 2007 UTC (17 years, 2 months ago) by pippijn
Branch: MAIN
CVS Tags: rel-2_0
Changes since 1.11: +1 -0 lines
Log Message:
added told and started some kind of chat/tell logging attachment (say works)

File Contents

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