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.46 by root, Thu Dec 18 02:49:22 2008 UTC

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