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