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