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.33 by root, Wed Sep 19 21:56:30 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
27cf::attach_to_players 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
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 $Coro::current->{desc} = "emote handler for $name";
713
714 if ($tname eq $name) {
715 my %emote = %{ $emotes->{$emotion}->{self} || {} };
716
717 $emote{other} ||= "You look away from <self>.";
718 $emote{self} ||= "My god! Is that LEGAL?";
719
720 $emote{other} =~ s/<self>/$name/;
721
722 $_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY)
723 for grep { $ob->on_same_map_as ($_->ob) && $_ != $ob} cf::player::list;
724
725 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY);
726 } elsif ($tname) {
727 my $target = cf::player::find $tname
728 or return $pl->send_msg (tell_channel $tname, "$tname is not around.", cf::NDI_DK_ORANGE | cf::NDI_REPLY);
729
730 my %emote = %{ $emotes->{$emotion}->{params} || {} };
731
732 $emote{other} ||= "<self> is eyeing <other> quizzically.";
733 $emote{self} ||= "You are still nuts.";
734 $emote{target} ||= "You get the distinct feeling that <other> is nuts.";
735
736 $emote{self} =~ s/<other>/$tname/;
737 $emote{target} =~ s/<self>/$name/;
738 $emote{other} =~ s/<other>/$tname/;
739 $emote{other} =~ s/<self>/$name/;
740
741 $_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY)
742 for grep { $_ != $pl && $_ != $target && $ob->on_same_map_as ($_->ob) } cf::player::list;
743
744 $target->send_msg (tell_channel $name, $emote{target}, cf::NDI_GREY);
745 $pl->send_msg (tell_channel $tname, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY);
746 } else {
747 my %emote = %{ $emotes->{$emotion}->{noparams} || {} };
748
749 $emote{other} ||= "<self> dances with glee.";
750 $emote{self} ||= "You are a nut.";
751
752 $emote{other} =~ s/<self>/$name/;
753
754 $_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY)
755 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl } cf::player::list;
756
757 $pl->send_msg ($CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY);
758 }
759 };
760 };
761}
762
763cf::register_command me => sub {
764 my ($pl, $msg) = @_;
765
766 my $name = $pl->name;
767
768 $_->send_msg ($SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0))
769 for grep $pl->on_same_map_as ($_->ob), cf::player::list;
770};
771
53cf::register_command say => sub { 772cf::register_command say => sub {
54 my ($who, $msg) = @_; 773 my ($ob, $msg) = @_;
55 774
56 utf8::decode $msg; 775 utf8::decode $msg;
57 776
58 return if $who->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); 777 return if $ob->contr->invoke (cf::EVENT_PLAYER_SAY, $msg);
59 778
60 if ($msg) { 779 if ($msg) {
61 my $name = $who->name; 780 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; 781 my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list;
66 utf8::decode $msg; 782
783 $_->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | ($_ == $ob->contr ? cf::NDI_REPLY : 0))
784 for @plonmap;
67 785
68 # npcs, magic_ears etc. 786 # npcs, magic_ears etc.
69 # first find all objects and theirt-level inventories 787 # first find all objects and their first-level inventories
70 # within a 5x5 square # that have something resembling 788 # within a 5x5 square that have something resembling
71 # dialogue or support on_say. 789 # dialogue or support on_say.
72 my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2); 790 my ($map, $x, $y) = ($ob->map, $ob->x - 2, $ob->y - 2);
73 791
74 for my $npc ( 792 for my $npc (
75 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $who->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, 793 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_,
76 map +($_, $_->inv), 794 map +($_, $_->inv),
77 grep $_, 795 grep $_,
78 map $map->at ($x + $_ % 5, $y + (int $_ / 5)), 796 map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
79 0..24 797 0..24
80 ) { 798 ) {
81 # if some listener teleported us somewhere else, stop right here 799 # if some listener teleported us somewhere else, stop right here
82 last unless $map->path == $who->map->path; 800 last unless $map->path == $ob->map->path;
83 801
84 my $dialog = new NPC_Dialogue ob => $who, npc => $npc; 802 my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc;
85 my ($reply, @kw) = $dialog->tell ($msg); 803 my ($reply, @kw) = $dialog->tell ($msg);
86 804
87 if (defined $reply) { 805 if (defined $reply) {
88 if ($npc->type == cf::MAGIC_EAR) { 806 if ($npc->type == cf::MAGIC_EAR) {
89 if (length $reply) { 807 if (length $reply) {
90 $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE) 808 $_->send_msg ($SAY_CHANNEL => $reply, cf::NDI_BROWN)
91 for grep $who->on_same_map_as ($_->ob), cf::player::list; 809 for @plonmap;
92 } 810 }
93 $npc->use_trigger; 811 $npc->use_trigger;
94 } else { 812 } else {
95 if (length $reply) { 813 if (length $reply) {
96 $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE) 814 $_->send_msg ($SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN)
97 for grep $who->on_same_map_as ($_->ob), cf::player::list; 815 for @plonmap;
98 } 816 }
99 } 817 }
100 } 818 }
101 819
102 if (@kw) { 820 if (@kw) {
103 $_->ob->message ("[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN | cf::NDI_UNIQUE) 821 $_->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
104 for grep $who->on_same_map_as ($_->ob), cf::player::list; 822 for @plonmap;
105 } 823 }
106 } 824 }
107 825
108 } else { 826 } else {
109 $who->message ("What do you want to say?", cf::NDI_UNIQUE); 827 $ob->send_msg ($SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY);
110 } 828 }
111}; 829};
112 830
113cf::register_command chat => sub { 831cf::register_command chat => sub {
114 my ($who, $msg) = @_; 832 my ($ob, $msg) = @_;
115 833
116 utf8::decode $msg; 834 utf8::decode $msg;
117 835
836 my $pl = $ob->contr;
837
118 return if $who->contr->invoke (cf::EVENT_PLAYER_CHAT, $msg); 838 return if $pl->invoke (cf::EVENT_PLAYER_CHAT, $msg);
119 839
120 if ($msg) { 840 if ($msg) {
121 my $name = $who->name; 841 my $name = $ob->name;
122 my $NOW = time; 842 my $NOW = time;
123 843
124 utf8::encode $msg; # ->message not yet utf8-ified
125 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 844 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
126 ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg); 845 send_irc ("[%s] %s", $name, $msg);
127 846
128 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 847 $_->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; 848 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
130 849
131 } else { 850 } else {
132 $who->message ("Chat what?", cf::NDI_UNIQUE); 851 $pl->send_msg ($CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY);
133 } 852 }
134}; 853};
135 854
136cf::register_command shout => sub { 855cf::register_command shout => sub {
137 my ($who, $msg) = @_; 856 my ($ob, $msg) = @_;
138 857
139 utf8::decode $msg; 858 utf8::decode $msg;
140 859
860 my $pl = $ob->contr;
861
141 return if $who->contr->invoke (cf::EVENT_PLAYER_SHOUT, $msg); 862 return if $pl->invoke (cf::EVENT_PLAYER_SHOUT, $msg);
142 863
143 if ($msg) { 864 if ($msg) {
144 my $NOW = time; 865 my $NOW = time;
145 my $name = $who->name; 866 my $name = $ob->name;
146 867
147 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; 868 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); 869 send_irc ("\007\0034{%s} %s\n", $name, $msg);
149 870
150 utf8::encode $msg; # ->message not yet utf8-ified 871 $_->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; 872 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
153 873
154 } else { 874 } else {
155 $who->message ("Shout what?", cf::NDI_UNIQUE); 875 $pl->send_msg ($CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY);
156 } 876 }
157
158}; 877};
159 878
160cf::register_command tell => sub { 879cf::register_command tell => sub {
161 my ($who, $args) = @_; 880 my ($ob, $args) = @_;
162 my ($target, $msg) = split /\s+/, $args, 2; 881 my ($target, $msg) = split /\s+/, $args, 2;
163 882
164 utf8::decode $msg; 883 utf8::decode $msg;
165 884
166 return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $target, $msg); 885 my $pl = $ob->contr;
167 886 my $ns = $pl->ns
887 or return;
168 my $name = $who->name; 888 my $name = $ob->name;
889
890 return if $pl->invoke (cf::EVENT_PLAYER_TELL, $target, $msg);
891
892 my $pl_channel = tell_channel $target;
169 893
170 if ($target =~ /irc\//) { 894 if ($target =~ /irc\//) {
171 my (undef, $nick) = split /\//, $target, 2; 895 my (undef, $nick) = split /\//, $target, 2;
172 $who->message ("You tell $target: $args"); 896 $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); 897 send_irc ("(%s) %s: %s\n", $name, $nick, $msg);
898
174 } elsif (my $other = cf::player::find $target) { 899 } elsif (my $other = cf::player::find_active $target) {
900 my $other_channel = tell_channel $name;
175 901
176 if ($msg) { 902 if ($msg) {
177 if ($target eq $name) { 903 if ($target eq $name) {
178 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); 904 $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) { 905 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
180 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); 906 $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 { 907 } else {
182 utf8::encode $msg; # ->message not yet utf8-ified 908 return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl, $msg);
183 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; 909 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
184 910
185 $who->message ("You tell $target: $msg"); 911 $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"); 912 $other->send_msg ($other_channel => "$name tells you: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF);
187 $other->ob->{ext_last_tell} = $name;
188 } 913 }
189 } else { 914 } else {
190 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE); 915 $ns->send_msg ($pl_channel => "What do you want to tell $target?", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY);
191 } 916 }
192 917
193 } else { 918 } else {
194 $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE); 919 $ns->send_msg ($pl_channel => "No such player. Your message: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY);
195 } 920 }
196}; 921};
197 922
198cf::register_command reply => sub { 923cf::register_command ignore => sub {
199 my ($who, $args) = @_; 924 my ($pl, $args) = @_;
200 my $name = $who->name; 925 my ($target, $type, $timeout) = split /\s+/, $args;
201 926
202 utf8::decode $args; 927 if ($args eq "list") {
928 clean_timeouts $pl;
203 929
204 return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $who->{ext_last_tell}, $args); 930 if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}})
931 + (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) {
932 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY);
933 $pl->message ((join ", ", @ignored_tell), cf::NDI_REPLY);
934 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY);
935 $pl->message ((join ", ", @ignored_shout), cf::NDI_REPLY);
936 $pl->message ("To stop ignoring one, use unignore.", cf::NDI_REPLY);
937 } else {
938 $pl->message ("Not ignoring anyone", cf::NDI_REPLY);
939 }
205 940
206 if ($who->{ext_last_tell} =~ /irc\//) { 941 } 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 942
212 if ($args) { 943 $timeout ne "" or $timeout = 24;
213 $other->ob->{ext_ignore_tell}{$name} >= time 944 my $absolute_timeout = time + $timeout * 3600;
214 or delete $other->ob->{ext_ignore_tell}{$name};
215 945
216 if ($other->ob->{ext_ignore_tell}{$name} < time) { 946 if (cf::player::exists $target) {
217 utf8::encode $args; # ->message not yet utf8-ified 947 if ($type eq "tell") {
218 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; 948 $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_REPLY);
219 949 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
220 $who->message ("You tell " . $other->ob->name . ": $args"); 950 } elsif ($type eq "shout") {
221 $other->ob->message ("$name tells you: $args"); 951 $pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_REPLY);
222 $who->{ext_last_tell} = $other->ob->name; 952 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
953 } elsif ($type eq "all") {
954 $pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_REPLY);
955 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
956 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
223 } else { 957 } else {
224 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); 958 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY);
225 } 959 }
226 } else { 960 } else {
227 $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE); 961 $pl->message ("No such player: $target", cf::NDI_REPLY);
228 } 962 }
229 963
230 } else { 964 } 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" 965 $pl->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
278 . "will ignore a player for <timeout> hours.\n" 966 . "will ignore a player for <timeout> hours.\n"
279 . "Usage: ignore list\n" 967 . "Usage: ignore list\n"
280 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); 968 . "will show you a list of players currently ignored.", cf::NDI_REPLY);
281 } 969 }
282}; 970};
283 971
284cf::register_command unignore => sub { 972cf::register_command unignore => sub {
285 my ($who, $args) = @_; 973 my ($pl, $args) = @_;
286 my ($target, $type) = split /\s+/, $args; 974 my ($target, $type) = split /\s+/, $args;
287 975
288 if ($args eq "") { 976 if ($args eq "") {
289 if ($who->{ext_ignore_tell}) { 977 if ($pl->{ext_ignore_tell}) {
290 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 978 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY);
291 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE); 979 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_REPLY);
292 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 980 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY);
293 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); 981 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_REPLY);
294 } else { 982 } else {
295 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); 983 $pl->message ("Not ignoring anyone", cf::NDI_REPLY);
296 } 984 }
297 } else { 985 } else {
298 if (cf::player::exists $target) { 986 if (cf::player::exists $target) {
299 if ($type eq "tell") { 987 if ($type eq "tell") {
300 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); 988 $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_REPLY);
301 delete $who->{ext_ignore_tell} {$target}; 989 delete $pl->{ext_ignore_tell} {$target};
302 } elsif ($type eq "shout") { 990 } elsif ($type eq "shout") {
303 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); 991 $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_REPLY);
304 delete $who->{ext_ignore_shout}{$target}; 992 delete $pl->{ext_ignore_shout}{$target};
305 } elsif ($type eq "all") { 993 } elsif ($type eq "all") {
306 $who->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE); 994 $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_REPLY);
307 delete $who->{ext_ignore_tell} {$target}; 995 delete $pl->{ext_ignore_tell} {$target};
308 delete $who->{ext_ignore_shout}{$target}; 996 delete $pl->{ext_ignore_shout}{$target};
309 } else { 997 } else {
310 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); 998 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY);
311 } 999 }
312 } else { 1000 } else {
313 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 1001 $pl->message ("No such player or ambiguous name: $target", cf::NDI_REPLY);
314 } 1002 }
315 } 1003 }
316}; 1004};
317 1005
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