ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/chat.ext
Revision: 1.22
Committed: Sun Jul 22 14:17:57 2007 UTC (16 years, 10 months ago) by root
Branch: MAIN
Changes since 1.21: +16 -14 lines
Log Message:
fix crash problem

File Contents

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