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.20 by elmex, Thu Jun 28 08:34:42 2007 UTC

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