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

Comparing deliantra/maps/perl/chat.ext (file contents):
Revision 1.5 by root, Sun May 7 08:10:23 2006 UTC vs.
Revision 1.9 by pippijn, Sun May 7 10:46:07 2006 UTC

1#! perl 1#! perl
2 2
3# implement a replacement for the built-in chat/shout/tell/reply commands 3# implement a replacement for the built-in chat/shout/tell/reply commands
4# adds ignore/unignore functionality 4# adds ignore/unignore functionality
5 5
6sub clean_timeouts {
7 my ($player) = @_;
8 my $NOW = time;
9
10 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
11 delete $hash->{$_} for grep $hash->{$_} < $NOW, keys %$hash;
12 }
13}
14
15sub on_logout {
16 my ($pl, $host) = @_;
17
18 clean_timeouts $pl->ob;
19}
20
6cf::register_command chat => 0, sub 21cf::register_command chat => 0, sub {
7{
8 my ($who, $msg) = @_; 22 my ($who, $msg) = @_;
9 23
10 if ($msg) { 24 if ($msg) {
11 my $name = $who->name; 25 my $name = $who->name;
26 my $NOW = time;
12 27
13 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 28 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
14 for grep !$player->ob->{ext_ignore_shout}, cf::player::list; 29 for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list;
15 30
16 } else { 31 } else {
17 $who->message ("Chat what?", cf::NDI_UNIQUE); 32 $who->message ("Chat what?", cf::NDI_UNIQUE);
18 } 33 }
19}; 34};
20 35
21cf::register_command shout => 0, sub 36cf::register_command shout => 0, sub {
22{
23 my ($who, $msg) = @_; 37 my ($who, $msg) = @_;
24 38
25 if ($msg) { 39 if ($msg) {
40 my $NOW = time;
26 my $name = $who->name; 41 my $name = $who->name;
27 42
28 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 43 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
29 for grep !$player->ob->{ext_ignore_shout}, cf::player::list; 44 for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list;
30 45
31 } else { 46 } else {
32 $who->message ("Shout what?", cf::NDI_UNIQUE); 47 $who->message ("Shout what?", cf::NDI_UNIQUE);
33 } 48 }
34 49
38 my ($who, $args) = @_; 53 my ($who, $args) = @_;
39 my ($target, $msg) = split /\s+/, $args, 2; 54 my ($target, $msg) = split /\s+/, $args, 2;
40 55
41 my $name = $who->name; 56 my $name = $who->name;
42 57
58 if ($msg) {
43 if (my $other = cf::player::find $target) { 59 if (my $other = cf::player::find $target) {
44 60
45 $other->ob->{ext_ignore_tell}{$name} >= time 61 if ($target ne $name and $other->ob->{ext_ignore_tell}{$name} < time) {
62 $who->message ("You tell $target: $msg");
63 $other->ob->message ("$name tells you: $msg");
46 or delete $other->ob->{ext_ignore_tell}{$name}; 64 $other->ob->{ext_last_tell} = $name;
65 } elsif ($target eq $name) {
66 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
67 } else {
68 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
69 }
47 70
48 if ($target ne $name and !$other->ob->{ext_ignore_tell}{$name}) {
49 $who->message ("You tell $target: $msg");
50 $other->ob->message ("$name tells you: $msg");
51 $other->ob->{ext_last_tell} = $name;
52 } elsif ($target eq $name) {
53 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
54 } else { 71 } else {
55 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); 72 $who->message ("No such player or ambiguous name. Your message: $msg", cf::NDI_UNIQUE);
56 } 73 }
57
58 } else { 74 } else {
59 $who->message ("No such player or ambiguous name. Your message: $msg", cf::NDI_UNIQUE); 75 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
60 } 76 }
61}; 77};
62 78
63cf::register_command reply => 0, sub { 79cf::register_command reply => 0, sub {
64 my ($who, $args) = @_; 80 my ($who, $args) = @_;
65 my $name = $who->name; 81 my $name = $who->name;
66 82
83 if ($args) {
67 if (my $other = cf::player::find $who->{ext_last_tell}) { 84 if (my $other = cf::player::find $who->{ext_last_tell}) {
68 85
69 $other->ob->{ext_ignore_tell}{$name} >= time 86 $other->ob->{ext_ignore_tell}{$name} >= time
70 or delete $other->ob->{ext_ignore_tell}{$name}; 87 or delete $other->ob->{ext_ignore_tell}{$name};
71 88
72 if (!$other->ob->{ext_ignore_tell}{$name}) { 89 if ($other->ob->{ext_ignore_tell}{$name} < time) {
73 $who->message ("You tell " . $other->ob->name . ": $args"); 90 $who->message ("You tell " . $other->ob->name . ": $args");
74 $other->ob->message ("$name tells you: $args"); 91 $other->ob->message ("$name tells you: $args");
75 $who->{ext_last_tell} = $other->ob->name; 92 $who->{ext_last_tell} = $other->ob->name;
93 } else {
94 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
95 }
96
76 } else { 97 } else {
77 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); 98 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE);
78 } 99 }
79
80 } else { 100 } else {
81 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE); 101 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
82 } 102 }
83}; 103};
84 104
85cf::register_command ignore => 0, sub { 105cf::register_command ignore => 0, sub {
86 my ($who, $args) = @_; 106 my ($who, $args) = @_;
87 my ($target, $type, $timeout) = split /\s+/, $args; 107 my ($target, $type, $timeout) = split /\s+/, $args;
88 108
89 if ($args eq "list") { 109 if ($args eq "list") {
110 clean_timeouts $who;
111
90 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}}) 112 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}})
91 + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) { 113 + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) {
92 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 114 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
93 $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE); 115 $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE);
94 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 116 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines