ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/chat.ext
Revision: 1.9
Committed: Thu Mar 1 13:01:37 2007 UTC (17 years, 2 months ago) by pippijn
Branch: MAIN
Changes since 1.8: +127 -123 lines
Log Message:
cointoss in perl

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