ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/chat.ext
Revision: 1.43
Committed: Fri Aug 29 06:48:45 2008 UTC (15 years, 8 months ago) by root
Branch: MAIN
CVS Tags: rel-2_7
Changes since 1.42: +2 -2 lines
Log Message:
*** empty log message ***

File Contents

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