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.21 by root, Wed Jul 19 22:20: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 say/chat/shout/tell/reply commands
4# adds ignore/unignore functionality 4# adds ignore/unignore functionality
5 5
6use NPC_Dialogue;
7
8sub clean_timeouts($) {
9 my ($player) = @_;
10 my $NOW = time;
11
12 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
13 while (my ($k, $v) = each %$hash) {
14 if ($v < $NOW) {
15 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE);
16 delete $hash->{$k};
17 } elsif (!valid_user $k) {
18 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE);
19 delete $hash->{$k};
20 }
21 }
22 }
23}
24
25sub on_logout {
26 my ($pl, $host) = @_;
27
28 clean_timeouts $pl->ob;
29}
30
31cf::register_command listen => 0, sub {
32 my ($who, $msg) = @_;
33 my $player = cf::player::find $who->name;
34
35 if ($msg ne "") {
36 my $prev_listen = $player->listening;
37 $player->listening ($msg);
38 if ($prev_listen == $player->listening) {
39 $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE);
40 } else {
41 $who->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE);
42 }
43 } else {
44 $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE);
45 }
46};
47
6cf::register_command chat => 0, sub { 48cf::register_command say => 0, sub {
7 my ($who, $msg) = @_; 49 my ($who, $msg) = @_;
8 50
9 if ($msg) { 51 if ($msg) {
10 my $name = $who->name; 52 my $name = $who->name;
11 53
12 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 54 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
13 for grep !$player->ob->{ext_ignore_shout}, cf::player::list; 55 for grep $who->on_same_map_as ($_->ob), cf::player::list;
14 56
57 # npcs, magic_ears etc.
58 # first find all objects and their inventories within a 5x5 square
59 # that have something resembling dialogue
60 my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2);
61
62 for my $npc (
63 grep NPC_Dialogue::has_dialogue $_,
64 map +($_, $_->inv),
65 grep $_,
66 map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
67 0..24
68 ) {
69 # if some listener teleported us somewhere else, stop right here
70 last unless $map->path == $who->map->path;
71
72 my $dialog = new NPC_Dialogue ob => $who, npc => $npc;
73 my $reply = $dialog->tell ($msg);
74
75 if (defined $reply) {
76 if ($npc->type == cf::MAGIC_EAR) {
77 if (length $reply) {
78 $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE)
79 for grep $who->on_same_map_as ($_->ob), cf::player::list;
80 }
81 $npc->use_trigger;
82 } else {
83 if (length $reply) {
84 $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE)
85 for grep $who->on_same_map_as ($_->ob), cf::player::list;
86 }
87 }
88 }
89 }
90
15 } else { 91 } else {
16 $who->message ("Chat what?", cf::NDI_UNIQUE); 92 $who->message ("What do you want to say?", cf::NDI_UNIQUE);
17 } 93 }
18}; 94};
19 95
20cf::register_command shout => 0, sub { 96cf::register_command chat => 0, sub {
21 my ($who, $msg) = @_; 97 my ($who, $msg) = @_;
22 98
23 if ($msg) { 99 if ($msg) {
24 my $name = $who->name; 100 my $name = $who->name;
101 my $NOW = time;
102
103 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
104
105 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
106 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
107
108 } else {
109 $who->message ("Chat what?", cf::NDI_UNIQUE);
110 }
111};
112
113cf::register_command shout => 0, sub {
114 my ($who, $msg) = @_;
115
116 if ($msg) {
117 my $NOW = time;
118 my $name = $who->name;
119
120 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
25 121
26 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 122 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
27 for grep !$player->ob->{ext_ignore_shout}, cf::player::list; 123 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
28 124
29 } else { 125 } else {
30 $who->message ("Shout what?", cf::NDI_UNIQUE); 126 $who->message ("Shout what?", cf::NDI_UNIQUE);
31 } 127 }
32 128
38 134
39 my $name = $who->name; 135 my $name = $who->name;
40 136
41 if (my $other = cf::player::find $target) { 137 if (my $other = cf::player::find $target) {
42 138
43 $other->ob->{ext_ignore_tell}{$name} >= time 139 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) { 140 if ($target eq $name) {
51 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); 141 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
142 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
143 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE);
52 } else { 144 } else {
53 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); 145 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
146
147 $who->message ("You tell $target: $msg");
148 $other->ob->message ("$name tells you: $msg");
149 $other->ob->{ext_last_tell} = $name;
54 } 150 }
55
56 } else { 151 } else {
152 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
153 }
154
155 } else {
57 $who->message ("No such player or ambiguous name. Your message: $msg", cf::NDI_UNIQUE); 156 $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE);
58 } 157 }
59}; 158};
60 159
61cf::register_command reply => 0, sub { 160cf::register_command reply => 0, sub {
62 my ($who, $args) = @_; 161 my ($who, $args) = @_;
63 my $name = $who->name; 162 my $name = $who->name;
64 163
65 if (my $other = cf::player::find $who->{ext_last_tell}) { 164 if (my $other = cf::player::find $who->{ext_last_tell}) {
165 if ($args) {
66 166
67 $other->ob->{ext_ignore_tell}{$name} >= time 167 $other->ob->{ext_ignore_tell}{$name} >= time
68 or delete $other->ob->{ext_ignore_tell}{$name}; 168 or delete $other->ob->{ext_ignore_tell}{$name};
69 169
70 if (!$other->ob->{ext_ignore_tell}{$name}) { 170 if ($other->ob->{ext_ignore_tell}{$name} < time) {
171 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args;
172
71 $who->message ("You tell " . $other->ob->name . ": $args"); 173 $who->message ("You tell " . $other->ob->name . ": $args");
72 $other->ob->message ("$name tells you: $args"); 174 $other->ob->message ("$name tells you: $args");
73 $who->{ext_last_tell} = $other->ob->name; 175 $who->{ext_last_tell} = $other->ob->name;
74 } else { 176 } else {
75 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); 177 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
178 }
179 } else {
180 $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE);
76 } 181 }
77 182
78 } else { 183 } else {
79 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE); 184 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE);
80 } 185 }
83cf::register_command ignore => 0, sub { 188cf::register_command ignore => 0, sub {
84 my ($who, $args) = @_; 189 my ($who, $args) = @_;
85 my ($target, $type, $timeout) = split /\s+/, $args; 190 my ($target, $type, $timeout) = split /\s+/, $args;
86 191
87 if ($args eq "list") { 192 if ($args eq "list") {
193 clean_timeouts $who;
194
88 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}}) 195 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}})
89 + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) { 196 + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) {
90 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 197 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
91 $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE); 198 $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE);
92 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 199 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
97 } 204 }
98 205
99 } elsif ($target && $type) { 206 } elsif ($target && $type) {
100 207
101 $timeout ne "" or $timeout = 24; 208 $timeout ne "" or $timeout = 24;
102
103 my $absolute_timeout = time + $timeout * 3600; 209 my $absolute_timeout = time + $timeout * 3600;
104 210
105 if (my $other = cf::player::find $target) { 211 if (valid_user $target) {
106 if ($type eq "tell") { 212 if ($type eq "tell") {
107 $who->message ("Now ignoring private messages from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); 213 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE);
108 $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; 214 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
109 } elsif ($type eq "shout") { 215 } elsif ($type eq "shout") {
110 $who->message ("Now ignoring shouts from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); 216 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE);
111 $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; 217 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
112 } elsif ($type eq "all") { 218 } elsif ($type eq "all") {
113 $who->message ("Now ignoring everything from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); 219 $who->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE);
114 $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; 220 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
115 $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; 221 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
116 } else { 222 } else {
117 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); 223 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
118 } 224 }
119 } else { 225 } else {
120 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 226 $who->message ("No such player: $target", cf::NDI_UNIQUE);
121 } 227 }
122 228
123 } else { 229 } else {
124 $who->message ("Usage:", cf::NDI_UNIQUE);
125 $who->message ("ignore <player> <tell | shout | all> <timeout>", cf::NDI_UNIQUE); 230 $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n"
126 $who->message ("will ignore a player for <timeout> hours.", cf::NDI_UNIQUE); 231 . "will ignore a player for <timeout> hours.\n"
127 $who->message ("ignore list", cf::NDI_UNIQUE); 232 . "Usage: ignore list\n"
128 $who->message ("will show you a list of players currently ignored.", cf::NDI_UNIQUE); 233 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE);
129 } 234 }
130}; 235};
131 236
132cf::register_command unignore => 0, sub { 237cf::register_command unignore => 0, sub {
133 my ($who, $args) = @_; 238 my ($who, $args) = @_;
134 my ($target, $type) = split /\s+/, $args; 239 my ($target, $type) = split /\s+/, $args;
135 240
136 if ($args eq "") { 241 if ($args eq "") {
137 if ($who->{ ext_ignore_tell }) { 242 if ($who->{ext_ignore_tell}) {
138 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 243 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
139 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE); 244 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE);
140 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 245 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
141 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); 246 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE);
142 } else { 247 } else {
143 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); 248 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
144 } 249 }
145 } else { 250 } else {
146 251
147 if (my $other = cf::player::find $target) { 252 if (valid_user $target) {
148 if ($type eq "tell") { 253 if ($type eq "tell") {
149 $who->message ("Not ignoring private messages from " . $other->ob->name . " anymore.", cf::NDI_UNIQUE); 254 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE);
150 delete $who->{ext_ignore_tell}{$other->ob->name}; 255 delete $who->{ext_ignore_tell} {$target};
151 } elsif ($type eq "shout") { 256 } elsif ($type eq "shout") {
152 $who->message ("Not ignoring shouts from " . $other->ob->name." anymore . ", cf::NDI_UNIQUE); 257 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE);
153 delete $who->{ext_ignore_shout}{$other->ob->name}; 258 delete $who->{ext_ignore_shout}{$target};
154 } elsif ($type eq "all") { 259 } elsif ($type eq "all") {
155 $who->message ("Not ignoring anything from " . $other->ob->name." anymore . ", cf::NDI_UNIQUE); 260 $who->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE);
156 delete $who->{ext_ignore_tell} {$other->ob->name}; 261 delete $who->{ext_ignore_tell} {$target};
157 delete $who->{ext_ignore_shout}{$other->ob->name}; 262 delete $who->{ext_ignore_shout}{$target};
158 } else { 263 } else {
159 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); 264 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
160 } 265 }
161 } else { 266 } else {
162 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 267 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines