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