ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/chat.ext
(Generate patch)

Comparing deliantra/server/ext/chat.ext (file contents):
Revision 1.1 by root, Fri Dec 15 19:29:18 2006 UTC vs.
Revision 1.21 by root, Fri Jul 20 16:11:10 2007 UTC

1#! perl 1#! perl # depends=irc
2#CONVERSION: PARTIAL 2#CONVERSION: PARTIAL
3 3
4# implement a replacement for the built-in say/chat/shout/tell/reply commands 4# implement a replacement for the built-in say/chat/shout/tell/reply commands
5# adds ignore/unignore functionality 5# adds ignore/unignore functionality
6 6
22 } 22 }
23 } 23 }
24 } 24 }
25} 25}
26 26
27cf::attach_to_players 27# send_irc ($format, @args, $msg)
28# make sure the last argument is the message!
29sub 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
37cf::player->attach (
28 prio => -1000, 38 prio => -1000,
29 on_login => sub { 39 on_login => sub {
30 my ($pl) = @_; 40 my ($pl) = @_;
31 41
32 clean_timeouts $pl->ob; 42 clean_timeouts $pl->ob;
33 }, 43 },
34; 44);
35 45
36cf::register_command listen => sub { 46cf::register_command listen => sub {
37 my ($who, $msg) = @_; 47 my ($pl, $msg) = @_;
38 my $player = cf::player::find $who->name; 48 my $player = cf::player::find_active $pl->name;
39 49
40 if ($msg ne "") { 50 if ($msg ne "") {
51 $msg = 10 if $msg > 10;
52
41 my $prev_listen = $player->listening; 53 my $prev_listen = $player->listening;
42 $player->listening ($msg); 54 $player->listening ($msg);
43 if ($prev_listen == $player->listening) { 55 if ($prev_listen == $player->listening) {
44 $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE); 56 $pl->message ("Your verbose level stays at $prev_listen.", cf::NDI_UNIQUE);
45 } else { 57 } else {
46 $who->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE); 58 $pl->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE);
47 } 59 }
48 } else { 60 } else {
49 $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); 61 $pl->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE);
50 } 62 }
51}; 63};
52 64
65cf::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
80cf::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
98my $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
680for 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
751our $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
758cf::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
53cf::register_command say => sub { 767cf::register_command say => sub {
54 my ($who, $msg) = @_; 768 my ($pl, $msg) = @_;
55 769
56 utf8::decode $msg; 770 utf8::decode $msg;
57 771
58 return if $who->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); 772 return if $pl->contr->invoke (cf::EVENT_PLAYER_SAY, $msg);
59 773
60 if ($msg) { 774 if ($msg) {
61 my $name = $who->name; 775 my $name = $pl->name;
62
63 utf8::encode $msg; # ->message not yet utf8-ified
64 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
65 for grep $who->on_same_map_as ($_->ob), cf::player::list; 776 my @plonmap = grep $pl->on_same_map_as ($_->ob), cf::player::list;
66 utf8::decode $msg; 777
778 $_->ns->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, $_ == $pl ? (reply => 1) : ())
779 for @plonmap;
67 780
68 # npcs, magic_ears etc. 781 # npcs, magic_ears etc.
69 # first find all objects and theirt-level inventories 782 # first find all objects and their first-level inventories
70 # within a 5x5 square # that have something resembling 783 # within a 5x5 square that have something resembling
71 # dialogue or support on_say. 784 # dialogue or support on_say.
72 my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2); 785 my ($map, $x, $y) = ($pl->map, $pl->x - 2, $pl->y - 2);
73 786
74 for my $npc ( 787 for my $npc (
75 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $who->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, 788 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $pl->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_,
76 map +($_, $_->inv), 789 map +($_, $_->inv),
77 grep $_, 790 grep $_,
78 map $map->at ($x + $_ % 5, $y + (int $_ / 5)), 791 map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
79 0..24 792 0..24
80 ) { 793 ) {
81 # if some listener teleported us somewhere else, stop right here 794 # if some listener teleported us somewhere else, stop right here
82 last unless $map->path == $who->map->path; 795 last unless $map->path == $pl->map->path;
83 796
84 my $dialog = new NPC_Dialogue ob => $who, npc => $npc; 797 my $dialog = new NPC_Dialogue pl => $pl->contr, npc => $npc;
85 my ($reply, @kw) = $dialog->tell ($msg); 798 my ($reply, @kw) = $dialog->tell ($msg);
86 799
87 if (defined $reply) { 800 if (defined $reply) {
88 if ($npc->type == cf::MAGIC_EAR) { 801 if ($npc->type == cf::MAGIC_EAR) {
89 if (length $reply) { 802 if (length $reply) {
90 $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE) 803 $_->contr->send_msg ($SAY_CHANNEL => $reply, cf::NDI_BROWN)
91 for grep $who->on_same_map_as ($_->ob), cf::player::list; 804 for @plonmap;
92 } 805 }
93 $npc->use_trigger; 806 $npc->use_trigger;
94 } else { 807 } else {
95 if (length $reply) { 808 if (length $reply) {
96 $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE) 809 $_->contr->send_msg ($SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN)
97 for grep $who->on_same_map_as ($_->ob), cf::player::list; 810 for @plonmap;
98 } 811 }
99 } 812 }
100 } 813 }
101 814
102 if (@kw) { 815 if (@kw) {
103 $_->ob->message ("[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN | cf::NDI_UNIQUE) 816 $_->contr->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
104 for grep $who->on_same_map_as ($_->ob), cf::player::list; 817 for @plonmap;
105 } 818 }
106 } 819 }
107 820
108 } else { 821 } else {
109 $who->message ("What do you want to say?", cf::NDI_UNIQUE); 822 $pl->contr->send_msg ($SAY_CHANNEL => "What do you want to say?", 0, reply => 1);
110 } 823 }
111}; 824};
112 825
826our $CHAT_CHANNEL = {
827 id => "chat",
828 title => "Chat",
829 reply => "chat ",
830 tooltip => "Player chat and shouts, global to the server.",
831};
832
113cf::register_command chat => sub { 833cf::register_command chat => sub {
114 my ($who, $msg) = @_; 834 my ($pl, $msg) = @_;
115 835
116 utf8::decode $msg; 836 utf8::decode $msg;
117 837
118 return if $who->contr->invoke (cf::EVENT_PLAYER_CHAT, $msg); 838 return if $pl->contr->invoke (cf::EVENT_PLAYER_CHAT, $msg);
119 839
120 if ($msg) { 840 if ($msg) {
121 my $name = $who->name; 841 my $name = $pl->name;
122 my $NOW = time; 842 my $NOW = time;
123 843
124 utf8::encode $msg; # ->message not yet utf8-ified
125 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 844 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
126 ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg); 845 send_irc ("[%s] %s", $name, $msg);
127 846
128 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 847 $_->ns->send_msg ($CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE, $_ == $pl ? (reply => 1) : ())
129 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; 848 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
130 849
131 } else { 850 } else {
132 $who->message ("Chat what?", cf::NDI_UNIQUE); 851 $pl->ns->send_msg ($CHAT_CHANNEL => "Chat what?");
133 } 852 }
134}; 853};
135 854
136cf::register_command shout => sub { 855cf::register_command shout => sub {
137 my ($who, $msg) = @_; 856 my ($pl, $msg) = @_;
138 857
139 utf8::decode $msg; 858 utf8::decode $msg;
140 859
141 return if $who->contr->invoke (cf::EVENT_PLAYER_SHOUT, $msg); 860 return if $pl->contr->invoke (cf::EVENT_PLAYER_SHOUT, $msg);
142 861
143 if ($msg) { 862 if ($msg) {
144 my $NOW = time; 863 my $NOW = time;
145 my $name = $who->name; 864 my $name = $pl->name;
146 865
147 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; 866 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
148 ext::schmorp_irc::do_notice (sprintf "\007\0034{%s} %s\n", $name, $msg); 867 send_irc ("\007\0034{%s} %s\n", $name, $msg);
149 868
150 utf8::encode $msg; # ->message not yet utf8-ified 869 $_->ns->send_msg ($CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_BLUE, $_ == $pl ? (reply => 1) : ())
151 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
152 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; 870 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
153 871
154 } else { 872 } else {
155 $who->message ("Shout what?", cf::NDI_UNIQUE); 873 $pl->ns->send_msg ($CHAT_CHANNEL => "Shout what?");
156 } 874 }
157
158}; 875};
159 876
160cf::register_command tell => sub { 877cf::register_command tell => sub {
161 my ($who, $args) = @_; 878 my ($ob, $args) = @_;
162 my ($target, $msg) = split /\s+/, $args, 2; 879 my ($target, $msg) = split /\s+/, $args, 2;
163 880
164 utf8::decode $msg; 881 utf8::decode $msg;
165 882
166 return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $target, $msg); 883 my $pl = $ob->contr;
167 884 my $ns = $pl->ns
885 or return;
168 my $name = $who->name; 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 };
169 896
170 if ($target =~ /irc\//) { 897 if ($target =~ /irc\//) {
171 my (undef, $nick) = split /\//, $target, 2; 898 my (undef, $nick) = split /\//, $target, 2;
172 $who->message ("You tell $target: $args"); 899 $ns->send_msg ($pl_channel => "You tell $target: $args", reply => 1);
173 ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $msg); 900 send_irc ("(%s) %s: %s\n", $name, $nick, $msg);
174 } elsif (my $other = cf::player::find $target) { 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 };
175 908
176 if ($msg) { 909 if ($msg) {
177 if ($target eq $name) { 910 if ($target eq $name) {
178 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); 911 $ns->send_msg ($pl_channel => "You are talking to yourself, you freak!", reply => 1);
179 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { 912 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
180 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); 913 $ns->send_msg ($pl_channel => "$target ignores what you say. Give up on it.", reply => 1);
181 } else { 914 } else {
182 utf8::encode $msg; # ->message not yet utf8-ified 915 return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl->contr, $msg);
183 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; 916 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
184 917
185 $who->message ("You tell $target: $msg"); 918 $ns->send_msg ($pl_channel => "You tell $target: $msg", reply => 1);
186 $other->ob->message ("$name tells you: $msg"); 919 $other->ns->send_msg ($other_channel => "$name tells you: $msg");
187 $other->ob->{ext_last_tell} = $name;
188 } 920 }
189 } else { 921 } else {
190 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE); 922 $ns->send_msg ($pl_channel => "What do you want to tell $target?");
191 } 923 }
192 924
193 } else { 925 } else {
194 $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE); 926 $ns->send_msg ($pl_channel => "No such player. Your message: $msg");
195 } 927 }
196}; 928};
197 929
198cf::register_command reply => sub { 930cf::register_command ignore => sub {
199 my ($who, $args) = @_; 931 my ($pl, $args) = @_;
200 my $name = $who->name; 932 my ($target, $type, $timeout) = split /\s+/, $args;
201 933
202 utf8::decode $args; 934 if ($args eq "list") {
935 clean_timeouts $pl;
203 936
204 return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $who->{ext_last_tell}, $args); 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 }
205 947
206 if ($who->{ext_last_tell} =~ /irc\//) { 948 } elsif ($target && $type) {
207 my (undef, $nick) = split /\//, $who->{ext_last_tell}, 2;
208 $who->message ("You tell " . $who->{ext_last_tell} . ": $args");
209 ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $args);
210 } elsif (my $other = cf::player::find $who->{ext_last_tell}) {
211 949
212 if ($args) { 950 $timeout ne "" or $timeout = 24;
213 $other->ob->{ext_ignore_tell}{$name} >= time 951 my $absolute_timeout = time + $timeout * 3600;
214 or delete $other->ob->{ext_ignore_tell}{$name};
215 952
216 if ($other->ob->{ext_ignore_tell}{$name} < time) { 953 if (cf::player::exists $target) {
217 utf8::encode $args; # ->message not yet utf8-ified 954 if ($type eq "tell") {
218 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; 955 $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE);
219 956 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
220 $who->message ("You tell " . $other->ob->name . ": $args"); 957 } elsif ($type eq "shout") {
221 $other->ob->message ("$name tells you: $args"); 958 $pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE);
222 $who->{ext_last_tell} = $other->ob->name; 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;
223 } else { 964 } else {
224 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); 965 $pl->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
225 } 966 }
226 } else { 967 } else {
227 $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE); 968 $pl->message ("No such player: $target", cf::NDI_UNIQUE);
228 } 969 }
229 970
230 } else { 971 } else {
231 $who->message ("Can't reply, player left. Your message: $args".$who->{ext_last_tell}, cf::NDI_UNIQUE);
232 }
233};
234
235cf::register_command ignore => sub {
236 my ($who, $args) = @_;
237 my ($target, $type, $timeout) = split /\s+/, $args;
238
239 if ($args eq "list") {
240 clean_timeouts $who;
241
242 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}})
243 + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) {
244 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
245 $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE);
246 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
247 $who->message ((join ", ", @ignored_shout), cf::NDI_UNIQUE);
248 $who->message ("To stop ignoring one, use unignore.", cf::NDI_UNIQUE);
249 } else {
250 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
251 }
252
253 } elsif ($target && $type) {
254
255 $timeout ne "" or $timeout = 24;
256 my $absolute_timeout = time + $timeout * 3600;
257
258 if (cf::player::exists $target) {
259 if ($type eq "tell") {
260 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE);
261 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
262 } elsif ($type eq "shout") {
263 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE);
264 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
265 } elsif ($type eq "all") {
266 $who->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE);
267 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
268 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
269 } else {
270 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
271 }
272 } else {
273 $who->message ("No such player: $target", cf::NDI_UNIQUE);
274 }
275
276 } else {
277 $who->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n" 972 $pl->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
278 . "will ignore a player for <timeout> hours.\n" 973 . "will ignore a player for <timeout> hours.\n"
279 . "Usage: ignore list\n" 974 . "Usage: ignore list\n"
280 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); 975 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE);
281 } 976 }
282}; 977};
283 978
284cf::register_command unignore => sub { 979cf::register_command unignore => sub {
285 my ($who, $args) = @_; 980 my ($pl, $args) = @_;
286 my ($target, $type) = split /\s+/, $args; 981 my ($target, $type) = split /\s+/, $args;
287 982
288 if ($args eq "") { 983 if ($args eq "") {
289 if ($who->{ext_ignore_tell}) { 984 if ($pl->{ext_ignore_tell}) {
290 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 985 $pl->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
291 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE); 986 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_UNIQUE);
292 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 987 $pl->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
293 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); 988 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_UNIQUE);
294 } else { 989 } else {
295 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); 990 $pl->message ("Not ignoring anyone", cf::NDI_UNIQUE);
296 } 991 }
297 } else { 992 } else {
298 if (cf::player::exists $target) { 993 if (cf::player::exists $target) {
299 if ($type eq "tell") { 994 if ($type eq "tell") {
300 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); 995 $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE);
301 delete $who->{ext_ignore_tell} {$target}; 996 delete $pl->{ext_ignore_tell} {$target};
302 } elsif ($type eq "shout") { 997 } elsif ($type eq "shout") {
303 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); 998 $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE);
304 delete $who->{ext_ignore_shout}{$target}; 999 delete $pl->{ext_ignore_shout}{$target};
305 } elsif ($type eq "all") { 1000 } elsif ($type eq "all") {
306 $who->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE); 1001 $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE);
307 delete $who->{ext_ignore_tell} {$target}; 1002 delete $pl->{ext_ignore_tell} {$target};
308 delete $who->{ext_ignore_shout}{$target}; 1003 delete $pl->{ext_ignore_shout}{$target};
309 } else { 1004 } else {
310 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); 1005 $pl->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
311 } 1006 }
312 } else { 1007 } else {
313 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 1008 $pl->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE);
314 } 1009 }
315 } 1010 }
316}; 1011};
317 1012
318cf::register_command seen => sub {
319 my ($who, $args) = @_;
320
321 if (my ($login) = $args =~ /(\S+)/) {
322 if ($login eq $who->name) {
323 $who->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE);
324 } elsif (cf::player::find $login) {
325 $who->message ("$login is right here on this server!", cf::NDI_UNIQUE);
326 } elsif (cf::player::exists $login
327 and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) {
328 my $time = (stat _)[9];
329
330 $who->message ("$login was last seen here "
331 . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time)
332 . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE);
333 } else {
334 $who->message ("No player named $login is known to me.", cf::NDI_UNIQUE);
335 }
336 } else {
337 $who->message ("Usage: seen <player>", cf::NDI_UNIQUE);
338 }
339};
340

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines