ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/chat.ext
Revision: 1.40
Committed: Thu May 1 06:33:19 2008 UTC (16 years ago) by root
Branch: MAIN
CVS Tags: rel-2_54, rel-2_55, rel-2_56, rel-2_53
Changes since 1.39: +21 -35 lines
Log Message:
send replies to the map channel

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