ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/chat.ext
(Generate patch)

Comparing deliantra/server/ext/chat.ext (file contents):
Revision 1.35 by root, Sat Oct 20 05:16:44 2007 UTC vs.
Revision 1.52 by root, Wed Apr 21 03:34:26 2010 UTC

1#! perl # depends=irc mandatory 1#! perl # depends=irc mandatory
2 2
3# implement a replacement for the built-in say/chat/shout/tell/reply commands 3# implement a replacement for the built-in say/chat/shout/tell commands
4# adds ignore/unignore functionality 4# adds ignore/unignore functionality
5 5
6use NPC_Dialogue; 6use NPC_Dialogue;
7use POSIX (); # for strftime only 7use POSIX (); # for strftime only
8
9our $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
16our $CHAT_CHANNEL = {
17 id => "chat",
18 title => "Chat",
19 reply => "chat ",
20 tooltip => "Player chat and shouts, global to the server.",
21};
22 8
23sub tell_channel($) { 9sub tell_channel($) {
24 my ($target) = @_; 10 my ($target) = @_;
25 11
26 { 12 {
68cf::player->attach ( 54cf::player->attach (
69 prio => -1000, 55 prio => -1000,
70 on_login => sub { 56 on_login => sub {
71 my ($pl) = @_; 57 my ($pl) = @_;
72 58
59 cf::async {
73 clean_timeouts $pl->ob; 60 clean_timeouts $pl->ob;
61 };
74 62
75 $pl->send_msg ($SAY_CHANNEL); 63 $pl->send_msg ($cf::SAY_CHANNEL);
76 $pl->send_msg ($CHAT_CHANNEL); 64 $pl->send_msg ($cf::CHAT_CHANNEL);
77 }, 65 },
78); 66);
79 67
68# TODO: remove once safe
80cf::register_command listen => sub { 69cf::register_command listen => sub {
81 my ($pl, $msg) = @_;
82 my $player = cf::player::find_active $pl->name;
83
84 if ($msg ne "") {
85 $msg = 10 if $msg > 10;
86
87 my $prev_listen = $player->listening;
88 $player->listening ($msg);
89 if ($prev_listen == $player->listening) {
90 $pl->message ("Your verbose level stays at $prev_listen.", cf::NDI_REPLY);
91 } else {
92 $pl->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_REPLY);
93 }
94 } else {
95 $pl->message ("Your verbose level is " . $player->listening . ".", cf::NDI_REPLY);
96 }
97}; 70};
98 71
99cf::register_command cointoss => sub { 72cf::register_command cointoss => sub {
100 my ($ob, $msg) = @_; 73 my ($ob, $msg) = @_;
101 74
102 my $pl = $ob->contr; 75 my $pl = $ob->contr;
103 my $name = $ob->name; 76 my $name = $ob->name;
104 77
105 my $coin = int rand 2 ? "Heads" : "Tails"; 78 my $coin = int rand 2 ? "Heads" : "Tails";
106 79
107 send_msg $_, $SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY, "msg_say" 80 send_msg $_, $cf::SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY, "msg_say"
108 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; 81 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list;
109 82
110 $pl->send_msg ($SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY); 83 $pl->send_msg ($cf::SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY);
111}; 84};
112 85
113cf::register_command orcknuckle => sub { 86cf::register_command orcknuckle => sub {
114 my ($ob, $msg) = @_; 87 my ($ob, $msg) = @_;
115 88
118 91
119 my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc"); 92 my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc");
120 my ($i, $j, $k, $l) = (rand 5, rand 5, rand 5, rand 6); 93 my ($i, $j, $k, $l) = (rand 5, rand 5, rand 5, rand 6);
121 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]"; 94 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]";
122 95
123 send_msg $_, $SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY, "msg_say" 96 send_msg $_, $cf::SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY, "msg_say"
124 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; 97 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list;
125 98
126 $pl->send_msg ($SAY_CHANNEL => "You roll $result!", cf::NDI_GREY | cf::NDI_REPLY); 99 $pl->send_msg ($cf::SAY_CHANNEL => "You roll $result!", cf::NDI_GREY | cf::NDI_REPLY);
127}; 100};
128 101
129my $emotes = { 102my $emotes = {
130 growl => { 103 growl => {
131 noparams => { 104 noparams => {
177 self => { 150 self => {
178 }, 151 },
179 }, 152 },
180 scream => { 153 scream => {
181 noparams => { 154 noparams => {
182 other => "<self> screams at the top of his lungs!", 155 other => "<self> screams at the top of G<his|her> lungs!",
183 self => "ARRRRRRRRRRGH!!!!!", 156 self => "ARRRRRRRRRRGH!!!!!",
184 }, 157 },
185 params => { 158 params => {
186 }, 159 },
187 self => { 160 self => {
196 target => "<self> pukes on your clothes!", 169 target => "<self> pukes on your clothes!",
197 other => "<self> pukes on <other>.", 170 other => "<self> pukes on <other>.",
198 self => "You puke on <other>.", 171 self => "You puke on <other>.",
199 }, 172 },
200 self => { 173 self => {
201 other => "<self> pukes on his clothes.", 174 other => "<self> pukes on G<his|her> clothes.",
202 self => "You puke on yourself.", 175 self => "You puke on yourself.",
203 }, 176 },
204 }, 177 },
205 strut => { 178 strut => {
206 noparams => { 179 noparams => {
245 }, 218 },
246 }, 219 },
247 kiss => { 220 kiss => {
248 noparams => { 221 noparams => {
249 other => "<self> makes a weird facial contortion", 222 other => "<self> makes a weird facial contortion",
250 self => "All the lonely people..", 223 self => "All the lonely people...",
251 }, 224 },
252 params => { 225 params => {
253 target => "<self> kisses you.", 226 target => "<self> kisses you.",
254 other => "<self> kisses <other>.", 227 other => "<self> kisses <other>.",
255 self => "You kiss <other>.", 228 self => "You kiss <other>.",
256 }, 229 },
257 self => { 230 self => {
258 }, 231 },
259 }, 232 },
233 hug => {
234 noparams => {
235 other => "<self> makes weird body movements.",
236 self => "All the lonely people...",
237 },
238 params => {
239 target => "<self> suddenly grabs you and gives you a bear hug.",
240 other => "<self> hugs <other>.",
241 self => "You hug <other>.",
242 },
243 self => {
244 other => "<self> tries to hug G<himself|herself>, but stumbles and now feels stupid.",
245 self => "You try and fail to hug yourself.",
246 },
247 },
248 smother => {
249 noparams => {
250 other => "<self> makes weird facial contortions",
251 self => "All the lonely people...",
252 },
253 params => {
254 target => "<self> smothers you with kisses.",
255 other => "<self> smothers <other> with kisses.",
256 self => "You smother <other> with kisses.",
257 },
258 self => {
259 },
260 },
260 wink => { 261 wink => {
261 noparams => { 262 noparams => {
262 other => "<self> winks suggestively.", 263 other => "<self> winks suggestively.",
263 self => "Have you got something in your eye?", 264 self => "Have you got something in your eye?",
264 }, 265 },
266 target => "<self> winks at you.", 267 target => "<self> winks at you.",
267 other => "<self> winks at <other>.", 268 other => "<self> winks at <other>.",
268 self => "You wink suggestively at <other>.", 269 self => "You wink suggestively at <other>.",
269 }, 270 },
270 self => { 271 self => {
271 other => "<self> winks at himself - something strange is going on...", 272 other => "<self> winks at G<him|her>self - something strange is going on...",
272 self => "You wink at yourself?? What are you up to?", 273 self => "You wink at yourself?? What are you up to?",
273 }, 274 },
274 }, 275 },
275 pout => { 276 pout => {
276 noparams => { 277 noparams => {
282 self => { 283 self => {
283 }, 284 },
284 }, 285 },
285 cackle => { 286 cackle => {
286 noparams => { 287 noparams => {
287 other => "<self> throws back his head and cackles with insane glee!", 288 other => "<self> throws back G<his|her> head and cackles with insane glee!",
288 self => "You cackle gleefully.", 289 self => "You cackle gleefully.",
289 }, 290 },
290 params => { 291 params => {
291 }, 292 },
292 self => { 293 self => {
301 target => "<self> sniffs you.", 302 target => "<self> sniffs you.",
302 other => "<self> sniffs <other>", 303 other => "<self> sniffs <other>",
303 self => "You sniff <other>.", 304 self => "You sniff <other>.",
304 }, 305 },
305 self => { 306 self => {
306 other => "<self> sniffs himself.", 307 other => "<self> sniffs G<him|her>self.",
307 self => "You sniff yourself.", 308 self => "You sniff yourself.",
308 }, 309 },
309 }, 310 },
310 nod => { 311 nod => {
311 noparams => { 312 noparams => {
312 other => "<self> nods solemnly.", 313 other => "<self> nods solemnly.",
313 self => "You nod solemnly.", 314 self => "You nod solemnly.",
314 }, 315 },
315 params => { 316 params => {
316 target => "<self> nods solemnly to you.", 317 target => "<self> nods solemnly at you.",
317 other => "<self> nods solemnly to <other>.", 318 other => "<self> nods solemnly at <other>.",
318 self => "You nod solemnly to <other>.", 319 self => "You nod solemnly at <other>.",
319 }, 320 },
320 self => { 321 self => {
321 }, 322 },
322 }, 323 },
323 frown => { 324 frown => {
329 target => "<self> frowns darkly at you.", 330 target => "<self> frowns darkly at you.",
330 other => "<self> frowns darkly at <other>.", 331 other => "<self> frowns darkly at <other>.",
331 self => "You frown darkly at <other>.", 332 self => "You frown darkly at <other>.",
332 }, 333 },
333 self => { 334 self => {
334 other => "<self> frowns at himself.", 335 other => "<self> frowns at G<him|her>self.",
335 self => "You frown at yourself.", 336 self => "You frown at yourself.",
336 }, 337 },
337 }, 338 },
338 snicker => { 339 snicker => {
339 noparams => { 340 noparams => {
362 noparams => { 363 noparams => {
363 other => "<self> is bleeding all over the carpet - got a spare tourniquet?", 364 other => "<self> is bleeding all over the carpet - got a spare tourniquet?",
364 self => "You bleed all over your nice new armour.", 365 self => "You bleed all over your nice new armour.",
365 }, 366 },
366 params => { 367 params => {
367 target => "<self> slashes his wrist and bleeds all over you.", 368 target => "<self> slashes G<his|her> wrist and bleeds all over you.",
368 other => "<self> slashes his wrist and bleeds all over <other>.", 369 other => "<self> slashes G<his|her> wrist and bleeds all over <other>.",
369 self => "You slash your wrist and bleed all over <other>", 370 self => "You slash your wrist and bleed all over <other>",
370 }, 371 },
371 self => { 372 self => {
372 other => "<self> performs some satanic ritual while wiping his blood on himself.", 373 other => "<self> performs some satanic ritual while wiping G<his|her> blood on G<him|her>self.",
373 self => "Very impressive! You wipe your blood all over yourself.", 374 self => "Very impressive! You wipe your blood all over yourself.",
374 }, 375 },
375 }, 376 },
376 twiddle => { 377 twiddle => {
377 noparams => { 378 noparams => {
378 other => "<self> patiently twiddles his thumbs.", 379 other => "<self> patiently twiddles G<his|her> thumbs.",
379 self => "You patiently twiddle your thumbs.", 380 self => "You patiently twiddle your thumbs.",
380 }, 381 },
381 params => { 382 params => {
382 }, 383 },
383 self => { 384 self => {
384 }, 385 },
385 }, 386 },
386 spit => { 387 spit => {
387 noparams => { 388 noparams => {
388 other => "<self> spits over his left shoulder.", 389 other => "<self> spits over G<his|her> left shoulder.",
389 self => "You spit over your left shoulder.", 390 self => "You spit over your left shoulder.",
390 }, 391 },
391 params => { 392 params => {
392 target => "<self> spits in your face!", 393 target => "<self> spits in your face!",
393 other => "<self> spits in <other>'s face.", 394 other => "<self> spits in <other>'s face.",
394 self => "You spit on <other>.", 395 self => "You spit on <other>.",
395 }, 396 },
396 self => { 397 self => {
397 other => "<self> drools all over himself.", 398 other => "<self> drools all over G<him|her>self.",
398 self => "You drool all over yourself.", 399 self => "You drool all over yourself.",
399 }, 400 },
400 }, 401 },
401 glare => { 402 glare => {
402 noparams => { 403 noparams => {
403 other => "<self> glares around him.", 404 other => "<self> glares around G<him|her>.",
404 self => "You glare at nothing in particular.", 405 self => "You glare at nothing in particular.",
405 }, 406 },
406 params => { 407 params => {
407 target => "<self> glares icily at you, you feel cold to your bones.", 408 target => "<self> glares icily at you, you feel cold to your bones.",
408 other => "<self> glares at <other>.", 409 other => "<self> glares at <other>.",
409 self => "You glare icily at <other>.", 410 self => "You glare icily at <other>.",
410 }, 411 },
411 self => { 412 self => {
412 other => "<self> glares at his feet, what is bothering him?", 413 other => "<self> glares at G<his|her> feet, what is bothering G<him|her>?",
413 self => "You glare icily at your feet, they are suddenly very cold.", 414 self => "You glare icily at your feet, they are suddenly very cold.",
414 }, 415 },
415 }, 416 },
416 bow => { 417 bow => {
417 noparams => { 418 noparams => {
422 target => "<self> bows before you.", 423 target => "<self> bows before you.",
423 other => "<self> bows before <other>.", 424 other => "<self> bows before <other>.",
424 self => "You bow before <other>.", 425 self => "You bow before <other>.",
425 }, 426 },
426 self => { 427 self => {
427 other => "<self> folds up like a jackknife and kisses his own toes.", 428 other => "<self> folds up like a jackknife and kisses G<his|her> own toes.",
428 self => "You kiss your toes.", 429 self => "You kiss your toes.",
429 }, 430 },
430 }, 431 },
431 dance => { 432 dance => {
432 noparams => { 433 noparams => {
433 other => "<self> expresses himself through interpretive dance.", 434 other => "<self> expresses G<him|her>self through interpretive dance.",
434 self => "You dance with glee.", 435 self => "You dance with glee.",
435 }, 436 },
436 params => { 437 params => {
437 target => "<self> grabs you, and begins dancing!", 438 target => "<self> grabs you, and begins dancing!",
438 other => "Yipe! <self> and <other> are doing the Macarena!", 439 other => "Yipe! <self> and <other> are doing the Macarena!",
439 self => "You grab <other> and begin doing the Cha-Cha!", 440 self => "You grab <other> and begin doing the Cha-Cha!",
440 }, 441 },
441 self => { 442 self => {
442 other => "<self> embraces himself and begins to dance!", 443 other => "<self> embraces G<him|her>self and begins to dance!",
443 self => "You skip and dance around by yourself.", 444 self => "You skip and dance around by yourself.",
444 }, 445 },
445 }, 446 },
446 snore => { 447 snore => {
447 noparams => { 448 noparams => {
463 self => { 464 self => {
464 }, 465 },
465 }, 466 },
466 snap => { 467 snap => {
467 noparams => { 468 noparams => {
468 other => "<self> snaps his fingers.", 469 other => "<self> snaps G<his|her> fingers.",
469 self => "PRONTO! you snap your fingers.", 470 self => "PRONTO! you snap your fingers.",
470 }, 471 },
471 params => { 472 params => {
472 }, 473 },
473 self => { 474 self => {
482 target => "<self> waves goodbye to you. Have a good journey.", 483 target => "<self> waves goodbye to you. Have a good journey.",
483 other => "<self> waves goodbye to <other>.", 484 other => "<self> waves goodbye to <other>.",
484 self => "You wave goodbye to <other>.", 485 self => "You wave goodbye to <other>.",
485 }, 486 },
486 self => { 487 self => {
487 other => "<self> waves goodbye to himself.", 488 other => "<self> waves goodbye to G<him|her>self.",
488 self => "Are you going on adventures as well??", 489 self => "Are you going on adventures as well??",
489 }, 490 },
490 }, 491 },
491 smile => { 492 smile => {
492 noparams => { 493 noparams => {
506 other => "<self> sneezes.", 507 other => "<self> sneezes.",
507 self => "Gesundheit!", 508 self => "Gesundheit!",
508 }, 509 },
509 params => { 510 params => {
510 target => "<self> sneezes on you, you feel the snot cover you. EEEEEEW.", 511 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 other => "<self> sneezes on <other> and a film of snot covers G<him|her>.",
512 self => "You sneeze at <other> and a film of snot shoots onto him.", 513 self => "You sneeze at <other> and a film of snot shoots onto G<him|her>.",
513 }, 514 },
514 self => { 515 self => {
515 other => "<self> sneezes, and covers himself in a slimy substance.", 516 other => "<self> sneezes, and covers G<him|her>self in a slimy substance.",
516 self => "You sneeze on yourself, what a mess!", 517 self => "You sneeze on yourself, what a mess!",
517 }, 518 },
518 }, 519 },
519 bounce => { 520 bounce => {
520 noparams => { 521 noparams => {
529 self => { 530 self => {
530 }, 531 },
531 }, 532 },
532 shake => { 533 shake => {
533 noparams => { 534 noparams => {
534 other => "<self> shakes his head.", 535 other => "<self> shakes G<his|her> head.",
535 self => "You shake your head.", 536 self => "You shake your head.",
536 }, 537 },
537 params => { 538 params => {
538 target => "<self> shakes your hand.", 539 target => "<self> shakes your hand.",
539 other => "<self> shakes <other>'s hand.", 540 other => "<self> shakes <other>'s hand.",
544 self => "You are shaken by yourself.", 545 self => "You are shaken by yourself.",
545 }, 546 },
546 }, 547 },
547 lick => { 548 lick => {
548 noparams => { 549 noparams => {
549 other => "<self> licks his mouth and smiles.", 550 other => "<self> licks G<his|her> mouth and smiles.",
550 self => "You lick your mouth and smile.", 551 self => "You lick your mouth and smile.",
551 }, 552 },
552 params => { 553 params => {
553 target => "<self> licks you.", 554 target => "<self> licks you.",
554 other => "<self> licks <other>.", 555 other => "<self> licks <other>.",
555 self => "You lick <other>.", 556 self => "You lick <other>.",
556 }, 557 },
557 self => { 558 self => {
558 other => "<self> licks himself - YUCK.", 559 other => "<self> licks G<him|her>self - YUCK.",
559 self => "You lick yourself.", 560 self => "You lick yourself.",
560 }, 561 },
561 }, 562 },
562 flip => { 563 flip => {
563 noparams => { 564 noparams => {
569 self => { 570 self => {
570 }, 571 },
571 }, 572 },
572 think => { 573 think => {
573 noparams => { 574 noparams => {
574 other => "<self> closes his eyes and thinks really hard.", 575 other => "<self> closes G<his|her> eyes and thinks really hard.",
575 self => "Anything in particular that you'd care to think about?", 576 self => "Anything in particular that you'd care to think about?",
576 }, 577 },
577 params => { 578 params => {
578 }, 579 },
579 self => { 580 self => {
643 target => "<self> cries on your shoulder.", 644 target => "<self> cries on your shoulder.",
644 other => "<self> cries on <other>'s shoulder.", 645 other => "<self> cries on <other>'s shoulder.",
645 self => "You cry on <other>'s shoulder.", 646 self => "You cry on <other>'s shoulder.",
646 }, 647 },
647 self => { 648 self => {
648 other => "<self> sobs quietly to himself.", 649 other => "<self> sobs quietly to G<him|her>self.",
649 self => "You cry to yourself.", 650 self => "You cry to yourself.",
650 }, 651 },
651 }, 652 },
652 sulk => { 653 sulk => {
653 noparams => { 654 noparams => {
667 params => { 668 params => {
668 target => "<self> whistles at <other>.", 669 target => "<self> whistles at <other>.",
669 self => "You whistle at <other>.", 670 self => "You whistle at <other>.",
670 }, 671 },
671 self => { 672 self => {
672 other => "<self> whistles to himself in boredom.", 673 other => "<self> whistles to G<him|her>self in boredom.",
673 self => "You whistle while you work.", 674 self => "You whistle while you work.",
674 }, 675 },
675 }, 676 },
676 groan => { 677 groan => {
677 noparams => { 678 noparams => {
723 724
724 $emote{other} ||= "You look away from <self>."; 725 $emote{other} ||= "You look away from <self>.";
725 $emote{self} ||= "My god! Is that LEGAL?"; 726 $emote{self} ||= "My god! Is that LEGAL?";
726 727
727 $emote{other} =~ s/<self>/$name/; 728 $emote{other} =~ s/<self>/$name/;
729
730 $_ = $pl->expand_cfpod ($_)
731 for values %emote;
728 732
729 send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" 733 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY | cf::NDI_VERBATIM, "msg_chat"
730 for grep { $ob->on_same_map_as ($_->ob) && $_ != $ob} cf::player::list; 734 for grep { $ob->on_same_map_as ($_->ob) && $_ != $ob} cf::player::list;
731 735
732 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY); 736 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY | cf::NDI_VERBATIM);
733 } elsif ($tname) { 737 } elsif ($tname) {
734 my $target = cf::player::find $tname 738 my $target = cf::player::find $tname
735 or return send_msg $pl, tell_channel $tname, "$tname is not around.", cf::NDI_DK_ORANGE | cf::NDI_REPLY, "msg_chat"; 739 or return send_msg $pl, tell_channel $tname, "$tname is not around.", cf::NDI_DK_ORANGE | cf::NDI_REPLY, "msg_chat";
736 740
737 my %emote = %{ $emotes->{$emotion}->{params} || {} }; 741 my %emote = %{ $emotes->{$emotion}->{params} || {} };
738 742
739 $emote{other} ||= "<self> is eyeing <other> quizzically."; 743 $emote{other} ||= "<self> is eyeing <other> quizzically.";
740 $emote{self} ||= "You are still nuts."; 744 $emote{self} ||= "You are still nuts.";
741 $emote{target} ||= "You get the distinct feeling that <other> is nuts."; 745 $emote{target} ||= "You get the distinct feeling that <self> is nuts.";
742 746
743 $emote{self} =~ s/<other>/$tname/; 747 $emote{self} =~ s/<other>/$tname/;
744 $emote{target} =~ s/<self>/$name/; 748 $emote{target} =~ s/<self>/$name/;
745 $emote{other} =~ s/<other>/$tname/; 749 $emote{other} =~ s/<other>/$tname/;
746 $emote{other} =~ s/<self>/$name/; 750 $emote{other} =~ s/<self>/$name/;
747 751
752 $_ = $pl->expand_cfpod ($_)
753 for values %emote;
754
748 send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" 755 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY | cf::NDI_VERBATIM, "msg_chat"
749 for grep { $_ != $pl && $_ != $target && $ob->on_same_map_as ($_->ob) } cf::player::list; 756 for grep { $_ != $pl && $_ != $target && $ob->on_same_map_as ($_->ob) } cf::player::list;
750 757
751 send_msg $target, tell_channel $name, $emote{target}, cf::NDI_GREY, "msg_shout"; 758 send_msg $target, tell_channel $name, $emote{target}, cf::NDI_GREY | cf::NDI_VERBATIM, "msg_shout";
752 $pl->send_msg (tell_channel $tname, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); 759 $pl->send_msg (tell_channel $tname, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY | cf::NDI_VERBATIM);
753 } else { 760 } else {
754 my %emote = %{ $emotes->{$emotion}->{noparams} || {} }; 761 my %emote = %{ $emotes->{$emotion}->{noparams} || {} };
755 762
756 $emote{other} ||= "<self> dances with glee."; 763 $emote{other} ||= "<self> dances with glee.";
757 $emote{self} ||= "You are a nut."; 764 $emote{self} ||= "You are a nut.";
758 765
759 $emote{other} =~ s/<self>/$name/; 766 $emote{other} =~ s/<self>/$name/;
760 767
768 $_ = $pl->expand_cfpod ($_)
769 for values %emote;
770
761 send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" 771 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY | cf::NDI_VERBATIM, "msg_chat"
762 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl } cf::player::list; 772 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl } cf::player::list;
763 773
764 $pl->send_msg ($CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); 774 $pl->send_msg ($cf::CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY | cf::NDI_VERBATIM);
765 } 775 }
766 }; 776 };
767 }; 777 };
768} 778}
769 779
770cf::register_command me => sub {
771 my ($pl, $msg) = @_;
772
773 my $name = $pl->name;
774
775 send_msg $pl, $SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_say"
776 for grep $pl->on_same_map_as ($_->ob), cf::player::list;
777};
778
779cf::register_command say => sub { 780cf::register_command say => sub {
780 my ($ob, $msg) = @_; 781 my ($ob, $msg) = @_;
781 782
782 utf8::decode $msg; 783 utf8::decode $msg;
783 784
785 786
786 if ($msg) { 787 if ($msg) {
787 my $name = $ob->name; 788 my $name = $ob->name;
788 my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list; 789 my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list;
789 790
790 send_msg $_, $SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say" 791 send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say"
791 for grep $_ != $ob->contr, @plonmap; 792 for grep $_ != $ob->contr, @plonmap;
792 $ob->contr->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY); 793 $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY);
794
795 my @npc;
793 796
794 # npcs, magic_ears etc. 797 # npcs, magic_ears etc.
795 # first find all objects and their first-level inventories 798 # first find all objects and their first-level inventories
796 # within a 5x5 square that have something resembling 799 # within a 5x5 square that have something resembling
797 # dialogue or support on_say. 800 # dialogue or support on_say.
801 # we prefer the nearest items NOT in the player, otherwise in player.
798 my ($map, $x, $y) = ($ob->map, $ob->x - 2, $ob->y - 2); 802 my ($map, $x, $y) = ($ob->map, $ob->x, $ob->y);
799 803
800 for my $npc ( 804 for my $dir (0 .. cf::SIZEOFFREE2) {
801 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, 805 @npc = grep $_->should_invoke (cf::EVENT_OBJECT_SAY) || $_->has_dialogue,
802 map +($_, $_->inv), 806 map +($_, $_->inv),
803 grep $_, 807 grep $_ != $ob,
804 map $map->at ($x + $_ % 5, $y + (int $_ / 5)), 808 $map->at ($x, $y, $dir)
805 0..24 809 and last;
806 ) { 810 }
811
812 unless (@npc) {
813 # nothing found, try the player inventory
814 @npc = grep $_->should_invoke (cf::EVENT_OBJECT_SAY) || $_->has_dialogue,
815 $ob->inv;
816 }
817
818 for my $npc (@npc) {
819 return if $npc->invoke (cf::EVENT_OBJECT_SAY);
820
807 # if some listener teleported us somewhere else, stop right here 821 # if some listener teleported us somewhere else, stop right here
808 last unless $map->path == $ob->map->path; 822 last unless $map->path == $ob->map->path;
809 823
824 if ($npc->has_dialogue) {
810 my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc; 825 my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc;
811 my ($reply, @kw) = $dialog->tell ($msg); 826 my ($reply, @kw) = $dialog->tell ($msg);
812 827
813 if (defined $reply) { 828 if (defined $reply) {
814 if ($npc->type == cf::MAGIC_EAR) { 829 if ($npc->type == cf::MAGIC_EAR) {
815 if (length $reply) {
816 send_msg $_, $SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" 830 send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say"
817 for @plonmap; 831 for @plonmap;
818 }
819 $npc->use_trigger;
820 } else { 832 } else {
821 if (length $reply) {
822 send_msg $_, $SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say" 833 send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say"
823 for @plonmap; 834 for @plonmap;
824 } 835 }
825 } 836 }
826 }
827 837
828 if (@kw) { 838 if (@kw) {
829 $_->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) 839 $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
830 for @plonmap; 840 for @plonmap;
841 }
831 } 842 }
832 } 843 }
833 844
834 } else { 845 } else {
835 $ob->send_msg ($SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY); 846 $ob->send_msg ($cf::SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY);
836 } 847 }
837}; 848};
838 849
839cf::register_command chat => sub { 850
851sub _chat {
840 my ($ob, $msg) = @_; 852 my ($ob, $msg) = @_;
841
842 utf8::decode $msg;
843 853
844 my $pl = $ob->contr; 854 my $pl = $ob->contr;
845 855
846 return if $pl->invoke (cf::EVENT_PLAYER_CHAT, $msg); 856 return if $pl->invoke (cf::EVENT_PLAYER_CHAT, $msg);
847 857
848 if ($msg) { 858 if ($msg) {
849 my $name = $ob->name; 859 my $name = $ob->name;
850 my $NOW = time; 860 my $NOW = time;
851 861
852 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 862 cf::LOG cf::llevDebug, sprintf "QBERT %s\n", $msg;
853 send_irc ("[%s] %s", $name, $msg); 863 send_irc ("%s", $msg);
854 864
855 send_msg $_, $CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat" 865 send_msg $_, $cf::CHAT_CHANNEL => $msg, cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat"
856 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; 866 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list;
857 867
858 } else { 868 } else {
859 $pl->send_msg ($CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY); 869 $pl->send_msg ($cf::CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY);
860 } 870 }
871}
872
873cf::register_command chat => sub {
874 my ($ob, $msg) = @_;
875
876 utf8::decode $msg;
877 _chat $ob, $ob->name . " chats: $msg";
878};
879
880cf::register_command me => sub {
881 my ($ob, $msg) = @_;
882
883 utf8::decode $msg;
884 _chat $ob, "* " . $ob->name . " $msg";
861}; 885};
862 886
863cf::register_command shout => sub { 887cf::register_command shout => sub {
864 my ($ob, $msg) = @_; 888 my ($ob, $msg) = @_;
865 889
874 my $name = $ob->name; 898 my $name = $ob->name;
875 899
876 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; 900 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
877 send_irc ("\007\0034{%s} %s\n", $name, $msg); 901 send_irc ("\007\0034{%s} %s\n", $name, $msg);
878 902
879 send_msg $_, $CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_shout" 903 send_msg $_, $cf::CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_shout"
880 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; 904 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list;
881 905
882 } else { 906 } else {
883 $pl->send_msg ($CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY); 907 $pl->send_msg ($cf::CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY);
884 } 908 }
885}; 909};
886 910
887cf::register_command tell => sub { 911cf::register_command tell => sub {
888 my ($ob, $args) = @_; 912 my ($ob, $args) = @_;
930 954
931cf::register_command ignore => sub { 955cf::register_command ignore => sub {
932 my ($pl, $args) = @_; 956 my ($pl, $args) = @_;
933 my ($target, $type, $timeout) = split /\s+/, $args; 957 my ($target, $type, $timeout) = split /\s+/, $args;
934 958
959 cf::async {
935 if ($args eq "list") { 960 if ($args eq "list") {
936 clean_timeouts $pl; 961 clean_timeouts $pl;
937 962
938 if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}}) 963 if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}})
939 + (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) { 964 + (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) {
940 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY); 965 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY);
941 $pl->message ((join ", ", @ignored_tell), cf::NDI_REPLY); 966 $pl->message ((join ", ", @ignored_tell), cf::NDI_REPLY);
942 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY); 967 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY);
943 $pl->message ((join ", ", @ignored_shout), cf::NDI_REPLY); 968 $pl->message ((join ", ", @ignored_shout), cf::NDI_REPLY);
944 $pl->message ("To stop ignoring one, use unignore.", cf::NDI_REPLY); 969 $pl->message ("To stop ignoring one, use unignore.", cf::NDI_REPLY);
970 } else {
971 $pl->message ("Not ignoring anyone", cf::NDI_REPLY);
972 }
973
974 } elsif ($target && $type) {
975 $timeout ne "" or $timeout = 24;
976 my $absolute_timeout = time + $timeout * 3600;
977
978 if (cf::player::exists $target) {
979 if ($type eq "tell") {
980 $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_REPLY);
981 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
982 } elsif ($type eq "shout") {
983 $pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_REPLY);
984 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
985 } elsif ($type eq "all") {
986 $pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_REPLY);
987 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
988 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
989 } else {
990 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY);
991 }
992 } else {
993 $pl->message ("No such player: $target", cf::NDI_REPLY);
994 }
995
945 } else { 996 } else {
946 $pl->message ("Not ignoring anyone", cf::NDI_REPLY); 997 $pl->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
998 . "will ignore a player for <timeout> hours.\n"
999 . "Usage: ignore list\n"
1000 . "will show you a list of players currently ignored.", cf::NDI_REPLY);
947 } 1001 }
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 $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_REPLY);
957 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
958 } elsif ($type eq "shout") {
959 $pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_REPLY);
960 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
961 } elsif ($type eq "all") {
962 $pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_REPLY);
963 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
964 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
965 } else {
966 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY);
967 }
968 } else {
969 $pl->message ("No such player: $target", cf::NDI_REPLY);
970 }
971
972 } else {
973 $pl->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
974 . "will ignore a player for <timeout> hours.\n"
975 . "Usage: ignore list\n"
976 . "will show you a list of players currently ignored.", cf::NDI_REPLY);
977 } 1002 };
978}; 1003};
979 1004
980cf::register_command unignore => sub { 1005cf::register_command unignore => sub {
981 my ($pl, $args) = @_; 1006 my ($pl, $args) = @_;
982 my ($target, $type) = split /\s+/, $args; 1007 my ($target, $type) = split /\s+/, $args;
983 1008
1009 cf::async {
984 if ($args eq "") { 1010 if ($args eq "") {
985 if ($pl->{ext_ignore_tell}) { 1011 if ($pl->{ext_ignore_tell}) {
986 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY); 1012 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY);
987 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_REPLY); 1013 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_REPLY);
988 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY); 1014 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY);
989 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_REPLY); 1015 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_REPLY);
990 } else {
991 $pl->message ("Not ignoring anyone", cf::NDI_REPLY);
992 }
993 } else {
994 if (cf::player::exists $target) {
995 if ($type eq "tell") {
996 $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_REPLY);
997 delete $pl->{ext_ignore_tell} {$target};
998 } elsif ($type eq "shout") {
999 $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_REPLY);
1000 delete $pl->{ext_ignore_shout}{$target};
1001 } elsif ($type eq "all") {
1002 $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_REPLY);
1003 delete $pl->{ext_ignore_tell} {$target};
1004 delete $pl->{ext_ignore_shout}{$target};
1005 } else { 1016 } else {
1006 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY); 1017 $pl->message ("Not ignoring anyone", cf::NDI_REPLY);
1007 } 1018 }
1008 } else { 1019 } else {
1020 if (cf::player::exists $target) {
1021 if ($type eq "tell") {
1022 $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_REPLY);
1023 delete $pl->{ext_ignore_tell} {$target};
1024 } elsif ($type eq "shout") {
1025 $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_REPLY);
1026 delete $pl->{ext_ignore_shout}{$target};
1027 } elsif ($type eq "all") {
1028 $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_REPLY);
1029 delete $pl->{ext_ignore_tell} {$target};
1030 delete $pl->{ext_ignore_shout}{$target};
1031 } else {
1032 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY);
1033 }
1034 } else {
1009 $pl->message ("No such player or ambiguous name: $target", cf::NDI_REPLY); 1035 $pl->message ("No such player or ambiguous name: $target", cf::NDI_REPLY);
1036 }
1010 } 1037 }
1011 } 1038 };
1012}; 1039};
1013 1040

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines