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.6 by pippijn, Sun May 7 08:24:50 2006 UTC vs.
Revision 1.17 by pippijn, Mon May 22 08:13:37 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 say/chat/shout/tell/reply commands
4# adds ignore/unignore functionality 4# adds ignore/unignore functionality
5
6sub valid_user($) {
7 -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2;
8}
9
10sub 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);
18 delete $hash->{$k};
19 } elsif (!valid_user $k) {
20 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN);
21 delete $hash->{$k};
22 }
23 }
24 }
25}
26
27sub on_logout {
28 my ($pl, $host) = @_;
29
30 clean_timeouts $pl->ob;
31}
32
33cf::register_command listen => 0, sub {
34 my ($who, $msg) = @_;
35 my $player = cf::player::find $who->name;
36
37 if ($msg ne "") {
38 my $prev_listen = $player->listening;
39 $player->listening ($msg);
40 if ($prev_listen == $player->listening) {
41 $who->message ("Your verbose level stayed ".$prev_listen.".", cf::NDI_UNIQUE);
42 } else {
43 $who->message ("Your verbose level is now ".$player->listening.". (previously: ".$prev_listen.")", cf::NDI_UNIQUE);
44 }
45 } else {
46 $who->message ("Your verbose level is ".$player->listening.".", cf::NDI_UNIQUE);
47 }
48};
49
50#cf::register_command say => 0, sub {
51# my ($who, $msg) = @_;
52#
53# if ($msg) {
54# my $name = $who->name;
55# $_->ob->message ("$name says: $msg", cf::NDI_WHITE)
56# for grep $who->on_same_map_as ($_->ob), cf::player::list;
57# } else {
58# $who->message ("What do you want to say?", cf::NDI_UNIQUE);
59# }
60#};
5 61
6cf::register_command chat => 0, sub { 62cf::register_command chat => 0, sub {
7 my ($who, $msg) = @_; 63 my ($who, $msg) = @_;
8 64
9 if ($msg) { 65 if ($msg) {
10 my $name = $who->name; 66 my $name = $who->name;
67 my $NOW = time;
11 68
12 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 69 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
13 for grep !$player->ob->{ext_ignore_shout}, cf::player::list; 70 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
14 71
15 } else { 72 } else {
16 $who->message ("Chat what?", cf::NDI_UNIQUE); 73 $who->message ("Chat what?", cf::NDI_UNIQUE);
17 } 74 }
18}; 75};
19 76
20cf::register_command shout => 0, sub { 77cf::register_command shout => 0, sub {
21 my ($who, $msg) = @_; 78 my ($who, $msg) = @_;
22 79
23 if ($msg) { 80 if ($msg) {
81 my $NOW = time;
24 my $name = $who->name; 82 my $name = $who->name;
25 83
26 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 84 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
27 for grep !$player->ob->{ext_ignore_shout}, cf::player::list; 85 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
28 86
29 } else { 87 } else {
30 $who->message ("Shout what?", cf::NDI_UNIQUE); 88 $who->message ("Shout what?", cf::NDI_UNIQUE);
31 } 89 }
32 90
38 96
39 my $name = $who->name; 97 my $name = $who->name;
40 98
41 if (my $other = cf::player::find $target) { 99 if (my $other = cf::player::find $target) {
42 100
43 $other->ob->{ext_ignore_tell}{$name} >= time 101 if ($msg) {
44 or delete $other->ob->{ext_ignore_tell}{$name};
45
46 if ($target ne $name and !$other->ob->{ext_ignore_tell}{$name}) {
47 $who->message ("You tell $target: $msg");
48 $other->ob->message ("$name tells you: $msg");
49 $other->ob->{ext_last_tell} = $name;
50 } elsif ($target eq $name) { 102 if ($target eq $name) {
51 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); 103 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
104 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
105 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE);
52 } else { 106 } else {
53 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); 107 $who->message ("You tell $target: $msg");
108 $other->ob->message ("$name tells you: $msg");
109 $other->ob->{ext_last_tell} = $name;
54 } 110 }
55
56 } else { 111 } else {
112 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
113 }
114
115 } else {
57 $who->message ("No such player or ambiguous name. Your message: $msg", cf::NDI_UNIQUE); 116 $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE);
58 } 117 }
59}; 118};
60 119
61cf::register_command reply => 0, sub { 120cf::register_command reply => 0, sub {
62 my ($who, $args) = @_; 121 my ($who, $args) = @_;
63 my $name = $who->name; 122 my $name = $who->name;
64 123
65 if (my $other = cf::player::find $who->{ext_last_tell}) { 124 if (my $other = cf::player::find $who->{ext_last_tell}) {
125 if ($args) {
66 126
67 $other->ob->{ext_ignore_tell}{$name} >= time 127 $other->ob->{ext_ignore_tell}{$name} >= time
68 or delete $other->ob->{ext_ignore_tell}{$name}; 128 or delete $other->ob->{ext_ignore_tell}{$name};
69 129
70 if (!$other->ob->{ext_ignore_tell}{$name}) { 130 if ($other->ob->{ext_ignore_tell}{$name} < time) {
71 $who->message ("You tell " . $other->ob->name . ": $args"); 131 $who->message ("You tell " . $other->ob->name . ": $args");
72 $other->ob->message ("$name tells you: $args"); 132 $other->ob->message ("$name tells you: $args");
73 $who->{ext_last_tell} = $other->ob->name; 133 $who->{ext_last_tell} = $other->ob->name;
74 } else { 134 } else {
75 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); 135 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
136 }
137 } else {
138 $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE);
76 } 139 }
77 140
78 } else { 141 } else {
79 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE); 142 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE);
80 } 143 }
83cf::register_command ignore => 0, sub { 146cf::register_command ignore => 0, sub {
84 my ($who, $args) = @_; 147 my ($who, $args) = @_;
85 my ($target, $type, $timeout) = split /\s+/, $args; 148 my ($target, $type, $timeout) = split /\s+/, $args;
86 149
87 if ($args eq "list") { 150 if ($args eq "list") {
151 clean_timeouts $who;
152
88 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}}) 153 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}})
89 + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) { 154 + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) {
90 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 155 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
91 $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE); 156 $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE);
92 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 157 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
97 } 162 }
98 163
99 } elsif ($target && $type) { 164 } elsif ($target && $type) {
100 165
101 $timeout ne "" or $timeout = 24; 166 $timeout ne "" or $timeout = 24;
102
103 my $absolute_timeout = time + $timeout * 3600; 167 my $absolute_timeout = time + $timeout * 3600;
104 168
105 if (my $other = cf::player::find $target) { 169 if (valid_user $target) {
106 if ($type eq "tell") { 170 if ($type eq "tell") {
107 $who->message ("Now ignoring private messages from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); 171 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE);
108 $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; 172 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
109 } elsif ($type eq "shout") { 173 } elsif ($type eq "shout") {
110 $who->message ("Now ignoring shouts from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); 174 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE);
111 $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; 175 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
112 } elsif ($type eq "all") { 176 } elsif ($type eq "all") {
113 $who->message ("Now ignoring everything from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); 177 $who->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE);
114 $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; 178 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
115 $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; 179 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
116 } else { 180 } else {
117 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); 181 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
118 } 182 }
119 } else { 183 } else {
120 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 184 $who->message ("No such player: $target", cf::NDI_UNIQUE);
121 } 185 }
122 186
123 } else { 187 } else {
124 $who->message ("Usage:", cf::NDI_UNIQUE);
125 $who->message ("ignore <player> <tell | shout | all> <timeout>", cf::NDI_UNIQUE); 188 $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n"
126 $who->message ("will ignore a player for <timeout> hours.", cf::NDI_UNIQUE); 189 . "will ignore a player for <timeout> hours.\n"
127 $who->message ("ignore list", cf::NDI_UNIQUE); 190 . "Usage: ignore list\n"
128 $who->message ("will show you a list of players currently ignored.", cf::NDI_UNIQUE); 191 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE);
129 } 192 }
130}; 193};
131 194
132cf::register_command unignore => 0, sub { 195cf::register_command unignore => 0, sub {
133 my ($who, $args) = @_; 196 my ($who, $args) = @_;
134 my ($target, $type) = split /\s+/, $args; 197 my ($target, $type) = split /\s+/, $args;
135 198
136 if ($args eq "") { 199 if ($args eq "") {
137 if ($who->{ ext_ignore_tell }) { 200 if ($who->{ext_ignore_tell}) {
138 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 201 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
139 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE); 202 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE);
140 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 203 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
141 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); 204 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE);
142 } else { 205 } else {
143 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); 206 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
144 } 207 }
145 } else { 208 } else {
146 209
147 if (my $other = cf::player::find $target) { 210 if (valid_user $target) {
148 if ($type eq "tell") { 211 if ($type eq "tell") {
149 $who->message ("Not ignoring private messages from " . $other->ob->name . " anymore.", cf::NDI_UNIQUE); 212 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE);
150 delete $who->{ext_ignore_tell}{$other->ob->name}; 213 delete $who->{ext_ignore_tell} {$target};
151 } elsif ($type eq "shout") { 214 } elsif ($type eq "shout") {
152 $who->message ("Not ignoring shouts from " . $other->ob->name." anymore . ", cf::NDI_UNIQUE); 215 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE);
153 delete $who->{ext_ignore_shout}{$other->ob->name}; 216 delete $who->{ext_ignore_shout}{$target};
154 } elsif ($type eq "all") { 217 } elsif ($type eq "all") {
155 $who->message ("Not ignoring anything from " . $other->ob->name." anymore . ", cf::NDI_UNIQUE); 218 $who->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE);
156 delete $who->{ext_ignore_tell} {$other->ob->name}; 219 delete $who->{ext_ignore_tell} {$target};
157 delete $who->{ext_ignore_shout}{$other->ob->name}; 220 delete $who->{ext_ignore_shout}{$target};
158 } else { 221 } else {
159 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); 222 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
160 } 223 }
161 } else { 224 } else {
162 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 225 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines