ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/chat.ext
Revision: 1.29
Committed: Sat Jul 28 12:02:58 2007 UTC (16 years, 10 months ago) by root
Branch: MAIN
Changes since 1.28: +105 -120 lines
Log Message:
- remote code was not making copies of strings it modified
- implemented two ew flags: NDI_REPLY and NDI_DEF.
- went over a lot of chat-related code and converted to send_msg,
  NDI_REPLY and NDI_DEF.

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