ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/chat.ext
Revision: 1.21
Committed: Fri Jul 20 16:11:10 2007 UTC (16 years, 10 months ago) by root
Branch: MAIN
Changes since 1.20: +64 -79 lines
Log Message:
preliminary chat channel implementation

File Contents

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