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.29 by root, Sat Jul 28 12:02:58 2007 UTC vs.
Revision 1.55 by root, Fri Apr 23 17:56:45 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 {
27 id => "tell-$target", 13 id => "tell-$target",
28 title => "$target", 14 title => "$target",
29 reply => "tell $target ", 15 reply => "tell $target ",
30 tooltip => "Private messages from/to $target", 16 tooltip => "Private messages from/to $target",
31 } 17 }
18}
19
20sub send_msg($$$$$) {
21 my ($pl, $channel, $msg, $flags, $sound) = @_;
22 $pl->play_sound (cf::sound::find $sound) if defined $sound;
23 $pl->send_msg ($channel, $msg, $flags);
24 ()
32} 25}
33 26
34sub clean_timeouts($) { 27sub clean_timeouts($) {
35 my ($player) = @_; 28 my ($player) = @_;
36 my $NOW = time; 29 my $NOW = time;
61cf::player->attach ( 54cf::player->attach (
62 prio => -1000, 55 prio => -1000,
63 on_login => sub { 56 on_login => sub {
64 my ($pl) = @_; 57 my ($pl) = @_;
65 58
59 cf::async {
66 clean_timeouts $pl->ob; 60 clean_timeouts $pl->ob;
61 };
62
67 $pl->ns->send_msg ($SAY_CHANNEL); 63 $pl->send_msg ($cf::SAY_CHANNEL);
68 $pl->ns->send_msg ($CHAT_CHANNEL); 64 $pl->send_msg ($cf::CHAT_CHANNEL);
69 }, 65 },
70); 66);
71 67
68# TODO: remove once safe
72cf::register_command listen => sub { 69cf::register_command listen => sub {
73 my ($pl, $msg) = @_;
74 my $player = cf::player::find_active $pl->name;
75
76 if ($msg ne "") {
77 $msg = 10 if $msg > 10;
78
79 my $prev_listen = $player->listening;
80 $player->listening ($msg);
81 if ($prev_listen == $player->listening) {
82 $pl->message ("Your verbose level stays at $prev_listen.", cf::NDI_REPLY);
83 } else {
84 $pl->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_REPLY);
85 }
86 } else {
87 $pl->message ("Your verbose level is " . $player->listening . ".", cf::NDI_REPLY);
88 }
89}; 70};
90 71
91cf::register_command cointoss => sub { 72cf::register_command cointoss => sub {
92 my ($ob, $msg) = @_; 73 my ($ob, $msg) = @_;
93 74
94 my $pl = $ob->contr; 75 my $pl = $ob->contr;
95 my $name = $ob->name; 76 my $name = $ob->name;
96 77
97 my $coin = int rand 2 ? "Heads" : "Tails"; 78 my $coin = (cf::rndm 2) ? "Heads" : "Tails";
98 79
99 $_->ns->send_msg ($SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY) 80 send_msg $_, $cf::SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY, "msg_say"
100 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;
101 82
102 $pl->ns->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);
103}; 84};
104 85
105cf::register_command orcknuckle => sub { 86cf::register_command orcknuckle => sub {
106 my ($ob, $msg) = @_; 87 my ($ob, $msg) = @_;
107 88
108 my $pl = $ob->contr; 89 my $pl = $ob->contr;
109 my $name = $ob->name; 90 my $name = $ob->name;
110 91
111 my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc"); 92 my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc");
112 my ($i, $j, $k, $l) = (rand 5, rand 5, rand 5, rand 6); 93 my ($i, $j, $k, $l) = map +(cf::rndm $_), 5, 5, 5, 6;
113 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]"; 94 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]";
114 95
115 $_->ns->send_msg ($SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY) 96 send_msg $_, $cf::SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY, "msg_say"
116 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;
117 98
118 $pl->ns->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);
119}; 100};
120 101
121my $emotes = { 102my $emotes = {
122 growl => { 103 growl => {
123 noparams => { 104 noparams => {
169 self => { 150 self => {
170 }, 151 },
171 }, 152 },
172 scream => { 153 scream => {
173 noparams => { 154 noparams => {
174 other => "<self> screams at the top of his lungs!", 155 other => "<self> screams at the top of G<his|her> lungs!",
175 self => "ARRRRRRRRRRGH!!!!!", 156 self => "ARRRRRRRRRRGH!!!!!",
176 }, 157 },
177 params => { 158 params => {
178 }, 159 },
179 self => { 160 self => {
188 target => "<self> pukes on your clothes!", 169 target => "<self> pukes on your clothes!",
189 other => "<self> pukes on <other>.", 170 other => "<self> pukes on <other>.",
190 self => "You puke on <other>.", 171 self => "You puke on <other>.",
191 }, 172 },
192 self => { 173 self => {
193 other => "<self> pukes on his clothes.", 174 other => "<self> pukes on G<his|her> clothes.",
194 self => "You puke on yourself.", 175 self => "You puke on yourself.",
195 }, 176 },
196 }, 177 },
197 strut => { 178 strut => {
198 noparams => { 179 noparams => {
237 }, 218 },
238 }, 219 },
239 kiss => { 220 kiss => {
240 noparams => { 221 noparams => {
241 other => "<self> makes a weird facial contortion", 222 other => "<self> makes a weird facial contortion",
242 self => "All the lonely people..", 223 self => "All the lonely people...",
243 }, 224 },
244 params => { 225 params => {
245 target => "<self> kisses you.", 226 target => "<self> kisses you.",
246 other => "<self> kisses <other>.", 227 other => "<self> kisses <other>.",
247 self => "You kiss <other>.", 228 self => "You kiss <other>.",
248 }, 229 },
249 self => { 230 self => {
250 }, 231 },
251 }, 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 },
252 wink => { 261 wink => {
253 noparams => { 262 noparams => {
254 other => "<self> winks suggestively.", 263 other => "<self> winks suggestively.",
255 self => "Have you got something in your eye?", 264 self => "Have you got something in your eye?",
256 }, 265 },
258 target => "<self> winks at you.", 267 target => "<self> winks at you.",
259 other => "<self> winks at <other>.", 268 other => "<self> winks at <other>.",
260 self => "You wink suggestively at <other>.", 269 self => "You wink suggestively at <other>.",
261 }, 270 },
262 self => { 271 self => {
263 other => "<self> winks at himself - something strange is going on...", 272 other => "<self> winks at G<him|her>self - something strange is going on...",
264 self => "You wink at yourself?? What are you up to?", 273 self => "You wink at yourself?? What are you up to?",
265 }, 274 },
266 }, 275 },
267 pout => { 276 pout => {
268 noparams => { 277 noparams => {
274 self => { 283 self => {
275 }, 284 },
276 }, 285 },
277 cackle => { 286 cackle => {
278 noparams => { 287 noparams => {
279 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!",
280 self => "You cackle gleefully.", 289 self => "You cackle gleefully.",
281 }, 290 },
282 params => { 291 params => {
283 }, 292 },
284 self => { 293 self => {
293 target => "<self> sniffs you.", 302 target => "<self> sniffs you.",
294 other => "<self> sniffs <other>", 303 other => "<self> sniffs <other>",
295 self => "You sniff <other>.", 304 self => "You sniff <other>.",
296 }, 305 },
297 self => { 306 self => {
298 other => "<self> sniffs himself.", 307 other => "<self> sniffs G<him|her>self.",
299 self => "You sniff yourself.", 308 self => "You sniff yourself.",
300 }, 309 },
301 }, 310 },
302 nod => { 311 nod => {
303 noparams => { 312 noparams => {
304 other => "<self> nods solemnly.", 313 other => "<self> nods solemnly.",
305 self => "You nod solemnly.", 314 self => "You nod solemnly.",
306 }, 315 },
307 params => { 316 params => {
308 target => "<self> nods solemnly to you.", 317 target => "<self> nods solemnly at you.",
309 other => "<self> nods solemnly to <other>.", 318 other => "<self> nods solemnly at <other>.",
310 self => "You nod solemnly to <other>.", 319 self => "You nod solemnly at <other>.",
311 }, 320 },
312 self => { 321 self => {
313 }, 322 },
314 }, 323 },
315 frown => { 324 frown => {
321 target => "<self> frowns darkly at you.", 330 target => "<self> frowns darkly at you.",
322 other => "<self> frowns darkly at <other>.", 331 other => "<self> frowns darkly at <other>.",
323 self => "You frown darkly at <other>.", 332 self => "You frown darkly at <other>.",
324 }, 333 },
325 self => { 334 self => {
326 other => "<self> frowns at himself.", 335 other => "<self> frowns at G<him|her>self.",
327 self => "You frown at yourself.", 336 self => "You frown at yourself.",
328 }, 337 },
329 }, 338 },
330 snicker => { 339 snicker => {
331 noparams => { 340 noparams => {
354 noparams => { 363 noparams => {
355 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?",
356 self => "You bleed all over your nice new armour.", 365 self => "You bleed all over your nice new armour.",
357 }, 366 },
358 params => { 367 params => {
359 target => "<self> slashes his wrist and bleeds all over you.", 368 target => "<self> slashes G<his|her> wrist and bleeds all over you.",
360 other => "<self> slashes his wrist and bleeds all over <other>.", 369 other => "<self> slashes G<his|her> wrist and bleeds all over <other>.",
361 self => "You slash your wrist and bleed all over <other>", 370 self => "You slash your wrist and bleed all over <other>",
362 }, 371 },
363 self => { 372 self => {
364 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.",
365 self => "Very impressive! You wipe your blood all over yourself.", 374 self => "Very impressive! You wipe your blood all over yourself.",
366 }, 375 },
367 }, 376 },
368 twiddle => { 377 twiddle => {
369 noparams => { 378 noparams => {
370 other => "<self> patiently twiddles his thumbs.", 379 other => "<self> patiently twiddles G<his|her> thumbs.",
371 self => "You patiently twiddle your thumbs.", 380 self => "You patiently twiddle your thumbs.",
372 }, 381 },
373 params => { 382 params => {
374 }, 383 },
375 self => { 384 self => {
376 }, 385 },
377 }, 386 },
378 spit => { 387 spit => {
379 noparams => { 388 noparams => {
380 other => "<self> spits over his left shoulder.", 389 other => "<self> spits over G<his|her> left shoulder.",
381 self => "You spit over your left shoulder.", 390 self => "You spit over your left shoulder.",
382 }, 391 },
383 params => { 392 params => {
384 target => "<self> spits in your face!", 393 target => "<self> spits in your face!",
385 other => "<self> spits in <other>'s face.", 394 other => "<self> spits in <other>'s face.",
386 self => "You spit on <other>.", 395 self => "You spit on <other>.",
387 }, 396 },
388 self => { 397 self => {
389 other => "<self> drools all over himself.", 398 other => "<self> drools all over G<him|her>self.",
390 self => "You drool all over yourself.", 399 self => "You drool all over yourself.",
391 }, 400 },
392 }, 401 },
393 glare => { 402 glare => {
394 noparams => { 403 noparams => {
395 other => "<self> glares around him.", 404 other => "<self> glares around G<him|her>.",
396 self => "You glare at nothing in particular.", 405 self => "You glare at nothing in particular.",
397 }, 406 },
398 params => { 407 params => {
399 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.",
400 other => "<self> glares at <other>.", 409 other => "<self> glares at <other>.",
401 self => "You glare icily at <other>.", 410 self => "You glare icily at <other>.",
402 }, 411 },
403 self => { 412 self => {
404 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>?",
405 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.",
406 }, 415 },
407 }, 416 },
408 bow => { 417 bow => {
409 noparams => { 418 noparams => {
414 target => "<self> bows before you.", 423 target => "<self> bows before you.",
415 other => "<self> bows before <other>.", 424 other => "<self> bows before <other>.",
416 self => "You bow before <other>.", 425 self => "You bow before <other>.",
417 }, 426 },
418 self => { 427 self => {
419 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.",
420 self => "You kiss your toes.", 429 self => "You kiss your toes.",
421 }, 430 },
422 }, 431 },
423 dance => { 432 dance => {
424 noparams => { 433 noparams => {
425 other => "<self> expresses himself through interpretive dance.", 434 other => "<self> expresses G<him|her>self through interpretive dance.",
426 self => "You dance with glee.", 435 self => "You dance with glee.",
427 }, 436 },
428 params => { 437 params => {
429 target => "<self> grabs you, and begins dancing!", 438 target => "<self> grabs you, and begins dancing!",
430 other => "Yipe! <self> and <other> are doing the Macarena!", 439 other => "Yipe! <self> and <other> are doing the Macarena!",
431 self => "You grab <other> and begin doing the Cha-Cha!", 440 self => "You grab <other> and begin doing the Cha-Cha!",
432 }, 441 },
433 self => { 442 self => {
434 other => "<self> embraces himself and begins to dance!", 443 other => "<self> embraces G<him|her>self and begins to dance!",
435 self => "You skip and dance around by yourself.", 444 self => "You skip and dance around by yourself.",
436 }, 445 },
437 }, 446 },
438 snore => { 447 snore => {
439 noparams => { 448 noparams => {
455 self => { 464 self => {
456 }, 465 },
457 }, 466 },
458 snap => { 467 snap => {
459 noparams => { 468 noparams => {
460 other => "<self> snaps his fingers.", 469 other => "<self> snaps G<his|her> fingers.",
461 self => "PRONTO! you snap your fingers.", 470 self => "PRONTO! you snap your fingers.",
462 }, 471 },
463 params => { 472 params => {
464 }, 473 },
465 self => { 474 self => {
474 target => "<self> waves goodbye to you. Have a good journey.", 483 target => "<self> waves goodbye to you. Have a good journey.",
475 other => "<self> waves goodbye to <other>.", 484 other => "<self> waves goodbye to <other>.",
476 self => "You wave goodbye to <other>.", 485 self => "You wave goodbye to <other>.",
477 }, 486 },
478 self => { 487 self => {
479 other => "<self> waves goodbye to himself.", 488 other => "<self> waves goodbye to G<him|her>self.",
480 self => "Are you going on adventures as well??", 489 self => "Are you going on adventures as well??",
481 }, 490 },
482 }, 491 },
483 smile => { 492 smile => {
484 noparams => { 493 noparams => {
498 other => "<self> sneezes.", 507 other => "<self> sneezes.",
499 self => "Gesundheit!", 508 self => "Gesundheit!",
500 }, 509 },
501 params => { 510 params => {
502 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.",
503 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>.",
504 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>.",
505 }, 514 },
506 self => { 515 self => {
507 other => "<self> sneezes, and covers himself in a slimy substance.", 516 other => "<self> sneezes, and covers G<him|her>self in a slimy substance.",
508 self => "You sneeze on yourself, what a mess!", 517 self => "You sneeze on yourself, what a mess!",
509 }, 518 },
510 }, 519 },
511 bounce => { 520 bounce => {
512 noparams => { 521 noparams => {
521 self => { 530 self => {
522 }, 531 },
523 }, 532 },
524 shake => { 533 shake => {
525 noparams => { 534 noparams => {
526 other => "<self> shakes his head.", 535 other => "<self> shakes G<his|her> head.",
527 self => "You shake your head.", 536 self => "You shake your head.",
528 }, 537 },
529 params => { 538 params => {
530 target => "<self> shakes your hand.", 539 target => "<self> shakes your hand.",
531 other => "<self> shakes <other>'s hand.", 540 other => "<self> shakes <other>'s hand.",
536 self => "You are shaken by yourself.", 545 self => "You are shaken by yourself.",
537 }, 546 },
538 }, 547 },
539 lick => { 548 lick => {
540 noparams => { 549 noparams => {
541 other => "<self> licks his mouth and smiles.", 550 other => "<self> licks G<his|her> mouth and smiles.",
542 self => "You lick your mouth and smile.", 551 self => "You lick your mouth and smile.",
543 }, 552 },
544 params => { 553 params => {
545 target => "<self> licks you.", 554 target => "<self> licks you.",
546 other => "<self> licks <other>.", 555 other => "<self> licks <other>.",
547 self => "You lick <other>.", 556 self => "You lick <other>.",
548 }, 557 },
549 self => { 558 self => {
550 other => "<self> licks himself - YUCK.", 559 other => "<self> licks G<him|her>self - YUCK.",
551 self => "You lick yourself.", 560 self => "You lick yourself.",
552 }, 561 },
553 }, 562 },
554 flip => { 563 flip => {
555 noparams => { 564 noparams => {
561 self => { 570 self => {
562 }, 571 },
563 }, 572 },
564 think => { 573 think => {
565 noparams => { 574 noparams => {
566 other => "<self> closes his eyes and thinks really hard.", 575 other => "<self> closes G<his|her> eyes and thinks really hard.",
567 self => "Anything in particular that you'd care to think about?", 576 self => "Anything in particular that you'd care to think about?",
568 }, 577 },
569 params => { 578 params => {
570 }, 579 },
571 self => { 580 self => {
635 target => "<self> cries on your shoulder.", 644 target => "<self> cries on your shoulder.",
636 other => "<self> cries on <other>'s shoulder.", 645 other => "<self> cries on <other>'s shoulder.",
637 self => "You cry on <other>'s shoulder.", 646 self => "You cry on <other>'s shoulder.",
638 }, 647 },
639 self => { 648 self => {
640 other => "<self> sobs quietly to himself.", 649 other => "<self> sobs quietly to G<him|her>self.",
641 self => "You cry to yourself.", 650 self => "You cry to yourself.",
642 }, 651 },
643 }, 652 },
644 sulk => { 653 sulk => {
645 noparams => { 654 noparams => {
659 params => { 668 params => {
660 target => "<self> whistles at <other>.", 669 target => "<self> whistles at <other>.",
661 self => "You whistle at <other>.", 670 self => "You whistle at <other>.",
662 }, 671 },
663 self => { 672 self => {
664 other => "<self> whistles to himself in boredom.", 673 other => "<self> whistles to G<him|her>self in boredom.",
665 self => "You whistle while you work.", 674 self => "You whistle while you work.",
666 }, 675 },
667 }, 676 },
668 groan => { 677 groan => {
669 noparams => { 678 noparams => {
706 715
707 my $pl = $ob->contr; 716 my $pl = $ob->contr;
708 717
709 cf::async { 718 cf::async {
710 my $name = $ob->name; 719 my $name = $ob->name;
720 $Coro::current->{desc} = "emote handler for $name";
711 721
712 if ($tname eq $name) { 722 if ($tname eq $name) {
713 my %emote = %{ $emotes->{$emotion}->{self} || {} }; 723 my %emote = %{ $emotes->{$emotion}->{self} || {} };
714 724
715 $emote{other} ||= "You look away from <self>."; 725 $emote{other} ||= "You look away from <self>.";
716 $emote{self} ||= "My god! Is that LEGAL?"; 726 $emote{self} ||= "My god! Is that LEGAL?";
717 727
718 $emote{other} =~ s/<self>/$name/; 728 $emote{other} =~ s/<self>/$name/;
729
730 $_ = $pl->expand_cfpod ($_)
731 for values %emote;
719 732
720 $_->ns->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) 733 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY | cf::NDI_VERBATIM, "msg_chat"
721 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;
722 735
723 $pl->ns->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);
724 } elsif ($tname) { 737 } elsif ($tname) {
725 my $target = cf::player::find $tname 738 my $target = cf::player::find $tname
726 or return $pl->ns->send_msg (tell_channel $tname, "$tname is not around.", cf::NDI_DK_ORANGE | cf::NDI_REPLY); 739 or return send_msg $pl, tell_channel $tname, "$tname is not around.", cf::NDI_DK_ORANGE | cf::NDI_REPLY, "msg_chat";
727 740
728 my %emote = %{ $emotes->{$emotion}->{params} || {} }; 741 my %emote = %{ $emotes->{$emotion}->{params} || {} };
729 742
730 $emote{other} ||= "<self> is eyeing <other> quizzically."; 743 $emote{other} ||= "<self> is eyeing <other> quizzically.";
731 $emote{self} ||= "You are still nuts."; 744 $emote{self} ||= "You are still nuts.";
732 $emote{target} ||= "You get the distinct feeling that <other> is nuts."; 745 $emote{target} ||= "You get the distinct feeling that <self> is nuts.";
733 746
734 $emote{self} =~ s/<other>/$tname/; 747 $emote{self} =~ s/<other>/$tname/;
735 $emote{target} =~ s/<self>/$name/; 748 $emote{target} =~ s/<self>/$name/;
736 $emote{other} =~ s/<other>/$tname/; 749 $emote{other} =~ s/<other>/$tname/;
737 $emote{other} =~ s/<self>/$name/; 750 $emote{other} =~ s/<self>/$name/;
738 751
739 $_->ns->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) 752 $_ = $pl->expand_cfpod ($_)
753 for values %emote;
754
755 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY | cf::NDI_VERBATIM, "msg_chat"
740 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;
741 757
742 $target->ns->send_msg (tell_channel $name, $emote{target}, cf::NDI_GREY); 758 send_msg $target, tell_channel $name, $emote{target}, cf::NDI_GREY | cf::NDI_VERBATIM, "msg_shout";
743 $pl->ns->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);
744 } else { 760 } else {
745 my %emote = %{ $emotes->{$emotion}->{noparams} || {} }; 761 my %emote = %{ $emotes->{$emotion}->{noparams} || {} };
746 762
747 $emote{other} ||= "<self> dances with glee."; 763 $emote{other} ||= "<self> dances with glee.";
748 $emote{self} ||= "You are a nut."; 764 $emote{self} ||= "You are a nut.";
749 765
750 $emote{other} =~ s/<self>/$name/; 766 $emote{other} =~ s/<self>/$name/;
751 767
752 $_->ns->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) 768 $_ = $pl->expand_cfpod ($_)
769 for values %emote;
770
771 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY | cf::NDI_VERBATIM, "msg_chat"
753 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;
754 773
755 $pl->ns->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);
756 } 775 }
757 }; 776 };
758 }; 777 };
759} 778}
760 779
761cf::register_command me => sub {
762 my ($pl, $msg) = @_;
763
764 my $name = $pl->name;
765
766 $_->ns->send_msg ($SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0))
767 for grep $pl->on_same_map_as ($_->ob), cf::player::list;
768};
769
770cf::register_command say => sub { 780cf::register_command say => sub {
771 my ($ob, $msg) = @_; 781 my ($ob, $msg) = @_;
772 782
773 utf8::decode $msg; 783 utf8::decode $msg;
774 784
776 786
777 if ($msg) { 787 if ($msg) {
778 my $name = $ob->name; 788 my $name = $ob->name;
779 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;
780 790
791 send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say"
792 for grep $_ != $ob->contr, @plonmap;
781 $_->ns->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | ($_ == $ob ? cf::NDI_REPLY : 0)) 793 $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY);
782 for @plonmap; 794
795 my @npc;
783 796
784 # npcs, magic_ears etc. 797 # npcs, magic_ears etc.
785 # first find all objects and their first-level inventories 798 # first find all objects and their first-level inventories
786 # within a 5x5 square that have something resembling 799 # within a 5x5 square that have something resembling
787 # dialogue or support on_say. 800 # dialogue or support on_say.
801 # we prefer the nearest items NOT in the player, otherwise in player.
788 my ($map, $x, $y) = ($ob->map, $ob->x - 2, $ob->y - 2); 802 my ($map, $x, $y) = ($ob->map, $ob->x, $ob->y);
789 803
790 for my $npc ( 804 for my $dir (
791 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, 805 0,
792 map +($_, $_->inv), 806 1, 3, 5, 7,
793 grep $_, 807 2, 4, 6, 8,
794 map $map->at ($x + $_ % 5, $y + (int $_ / 5)), 808 9 .. cf::SIZEOFFREE2
795 0..24
796 ) { 809 ) {
810 @npc = grep $_->should_invoke (cf::EVENT_OBJECT_SAY) || $_->has_dialogue,
811 map +($_, $_->inv),
812 grep $_ != $ob,
813 $map->at ($x, $y, $dir)
814 and last;
815 }
816
817 unless (@npc) {
818 # nothing found, try the player inventory
819 @npc = grep $_->should_invoke (cf::EVENT_OBJECT_SAY) || $_->has_dialogue,
820 $ob->inv;
821 }
822
823 for my $npc (@npc) {
824 return if $npc->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg);
825
797 # if some listener teleported us somewhere else, stop right here 826 # if some listener teleported us somewhere else, stop right here
798 last unless $map->path == $ob->map->path; 827 last unless $map->path == $ob->map->path;
799 828
829 if ($npc->has_dialogue) {
800 my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc; 830 my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc;
801 my ($reply, @kw) = $dialog->tell ($msg); 831 my ($reply, @kw) = $dialog->tell ($msg);
802 832
803 if (defined $reply) { 833 if (defined $reply) {
804 if ($npc->type == cf::MAGIC_EAR) { 834 if ($npc->type == cf::MAGIC_EAR) {
805 if (length $reply) {
806 $_->ns->send_msg ($SAY_CHANNEL => $reply, cf::NDI_BROWN) 835 send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say"
807 for @plonmap; 836 for @plonmap;
808 }
809 $npc->use_trigger;
810 } else { 837 } else {
811 if (length $reply) {
812 $_->ns->send_msg ($SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN) 838 send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say"
813 for @plonmap; 839 for @plonmap;
814 } 840 }
815 } 841 }
816 }
817 842
818 if (@kw) { 843 if (@kw) {
819 $_->ns->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) 844 $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
820 for @plonmap; 845 for @plonmap;
846 }
821 } 847 }
822 } 848 }
823 849
824 } else { 850 } else {
825 $ob->contr->ns->send_msg ($SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY); 851 $ob->send_msg ($cf::SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY);
826 } 852 }
827}; 853};
828 854
829cf::register_command chat => sub { 855
856sub _chat {
830 my ($ob, $msg) = @_; 857 my ($ob, $msg) = @_;
831
832 utf8::decode $msg;
833 858
834 my $pl = $ob->contr; 859 my $pl = $ob->contr;
835 860
836 return if $pl->invoke (cf::EVENT_PLAYER_CHAT, $msg); 861 return if $pl->invoke (cf::EVENT_PLAYER_CHAT, $msg);
837 862
838 if ($msg) { 863 if ($msg) {
839 my $name = $ob->name; 864 my $name = $ob->name;
840 my $NOW = time; 865 my $NOW = time;
841 866
842 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 867 cf::LOG cf::llevDebug, sprintf "QBERT %s\n", $msg;
843 send_irc ("[%s] %s", $name, $msg); 868 send_irc ("%s", $msg);
844 869
845 $_->ns->send_msg ($CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0)) 870 send_msg $_, $cf::CHAT_CHANNEL => $msg, cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat"
846 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; 871 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list;
847 872
848 } else { 873 } else {
849 $pl->ns->send_msg ($CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY); 874 $pl->send_msg ($cf::CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY);
850 } 875 }
876}
877
878cf::register_command chat => sub {
879 my ($ob, $msg) = @_;
880
881 utf8::decode $msg;
882 _chat $ob, $ob->name . " chats: $msg";
883};
884
885cf::register_command me => sub {
886 my ($ob, $msg) = @_;
887
888 utf8::decode $msg;
889 _chat $ob, "* " . $ob->name . " $msg";
851}; 890};
852 891
853cf::register_command shout => sub { 892cf::register_command shout => sub {
854 my ($ob, $msg) = @_; 893 my ($ob, $msg) = @_;
855 894
864 my $name = $ob->name; 903 my $name = $ob->name;
865 904
866 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; 905 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
867 send_irc ("\007\0034{%s} %s\n", $name, $msg); 906 send_irc ("\007\0034{%s} %s\n", $name, $msg);
868 907
869 $_->ns->send_msg ($CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0)) 908 send_msg $_, $cf::CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_shout"
870 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; 909 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list;
871 910
872 } else { 911 } else {
873 $pl->ns->send_msg ($CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY); 912 $pl->send_msg ($cf::CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY);
874 } 913 }
875}; 914};
876 915
877cf::register_command tell => sub { 916cf::register_command tell => sub {
878 my ($ob, $args) = @_; 917 my ($ob, $args) = @_;
905 } else { 944 } else {
906 return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl, $msg); 945 return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl, $msg);
907 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; 946 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
908 947
909 $ns->send_msg ($pl_channel => "You tell $target: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); 948 $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); 949 send_msg $other, $other_channel => "$name tells you: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF, "msg_tell";
911 } 950 }
912 } else { 951 } else {
913 $ns->send_msg ($pl_channel => "What do you want to tell $target?", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); 952 $ns->send_msg ($pl_channel => "What do you want to tell $target?", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY);
914 } 953 }
915 954
920 959
921cf::register_command ignore => sub { 960cf::register_command ignore => sub {
922 my ($pl, $args) = @_; 961 my ($pl, $args) = @_;
923 my ($target, $type, $timeout) = split /\s+/, $args; 962 my ($target, $type, $timeout) = split /\s+/, $args;
924 963
964 cf::async {
925 if ($args eq "list") { 965 if ($args eq "list") {
926 clean_timeouts $pl; 966 clean_timeouts $pl;
927 967
928 if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}}) 968 if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}})
929 + (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) { 969 + (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) {
930 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY); 970 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY);
931 $pl->message ((join ", ", @ignored_tell), cf::NDI_REPLY); 971 $pl->message ((join ", ", @ignored_tell), cf::NDI_REPLY);
932 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY); 972 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY);
933 $pl->message ((join ", ", @ignored_shout), cf::NDI_REPLY); 973 $pl->message ((join ", ", @ignored_shout), cf::NDI_REPLY);
934 $pl->message ("To stop ignoring one, use unignore.", cf::NDI_REPLY); 974 $pl->message ("To stop ignoring one, use unignore.", cf::NDI_REPLY);
975 } else {
976 $pl->message ("Not ignoring anyone", cf::NDI_REPLY);
977 }
978
979 } elsif ($target && $type) {
980 $timeout ne "" or $timeout = 24;
981 my $absolute_timeout = time + $timeout * 3600;
982
983 if (cf::player::exists $target) {
984 if ($type eq "tell") {
985 $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_REPLY);
986 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
987 } elsif ($type eq "shout") {
988 $pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_REPLY);
989 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
990 } elsif ($type eq "all") {
991 $pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_REPLY);
992 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
993 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
994 } else {
995 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY);
996 }
997 } else {
998 $pl->message ("No such player: $target", cf::NDI_REPLY);
999 }
1000
935 } else { 1001 } else {
936 $pl->message ("Not ignoring anyone", cf::NDI_REPLY); 1002 $pl->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
1003 . "will ignore a player for <timeout> hours.\n"
1004 . "Usage: ignore list\n"
1005 . "will show you a list of players currently ignored.", cf::NDI_REPLY);
937 } 1006 }
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 $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_REPLY);
947 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
948 } elsif ($type eq "shout") {
949 $pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_REPLY);
950 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
951 } elsif ($type eq "all") {
952 $pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_REPLY);
953 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
954 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
955 } else {
956 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY);
957 }
958 } else {
959 $pl->message ("No such player: $target", cf::NDI_REPLY);
960 }
961
962 } else {
963 $pl->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
964 . "will ignore a player for <timeout> hours.\n"
965 . "Usage: ignore list\n"
966 . "will show you a list of players currently ignored.", cf::NDI_REPLY);
967 } 1007 };
968}; 1008};
969 1009
970cf::register_command unignore => sub { 1010cf::register_command unignore => sub {
971 my ($pl, $args) = @_; 1011 my ($pl, $args) = @_;
972 my ($target, $type) = split /\s+/, $args; 1012 my ($target, $type) = split /\s+/, $args;
973 1013
1014 cf::async {
974 if ($args eq "") { 1015 if ($args eq "") {
975 if ($pl->{ext_ignore_tell}) { 1016 if ($pl->{ext_ignore_tell}) {
976 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY); 1017 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY);
977 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_REPLY); 1018 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_REPLY);
978 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY); 1019 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY);
979 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_REPLY); 1020 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_REPLY);
980 } else {
981 $pl->message ("Not ignoring anyone", cf::NDI_REPLY);
982 }
983 } else {
984 if (cf::player::exists $target) {
985 if ($type eq "tell") {
986 $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_REPLY);
987 delete $pl->{ext_ignore_tell} {$target};
988 } elsif ($type eq "shout") {
989 $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_REPLY);
990 delete $pl->{ext_ignore_shout}{$target};
991 } elsif ($type eq "all") {
992 $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_REPLY);
993 delete $pl->{ext_ignore_tell} {$target};
994 delete $pl->{ext_ignore_shout}{$target};
995 } else { 1021 } else {
996 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY); 1022 $pl->message ("Not ignoring anyone", cf::NDI_REPLY);
997 } 1023 }
998 } else { 1024 } else {
1025 if (cf::player::exists $target) {
1026 if ($type eq "tell") {
1027 $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_REPLY);
1028 delete $pl->{ext_ignore_tell} {$target};
1029 } elsif ($type eq "shout") {
1030 $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_REPLY);
1031 delete $pl->{ext_ignore_shout}{$target};
1032 } elsif ($type eq "all") {
1033 $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_REPLY);
1034 delete $pl->{ext_ignore_tell} {$target};
1035 delete $pl->{ext_ignore_shout}{$target};
1036 } else {
1037 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY);
1038 }
1039 } else {
999 $pl->message ("No such player or ambiguous name: $target", cf::NDI_REPLY); 1040 $pl->message ("No such player or ambiguous name: $target", cf::NDI_REPLY);
1041 }
1000 } 1042 }
1001 } 1043 };
1002}; 1044};
1003 1045

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines