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