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.26 by root, Fri Jul 21 08:33:52 2006 UTC vs.
Revision 1.42 by root, Tue Dec 12 16:59:34 2006 UTC

1#! perl 1#! perl
2#CONVERSION: PARTIAL
2 3
3# implement a replacement for the built-in say/chat/shout/tell/reply commands 4# implement a replacement for the built-in say/chat/shout/tell/reply commands
4# adds ignore/unignore functionality 5# adds ignore/unignore functionality
5 6
6use NPC_Dialogue; 7use NPC_Dialogue;
21 } 22 }
22 } 23 }
23 } 24 }
24} 25}
25 26
26sub on_logout { 27cf::attach_to_players
28 prio => -1000,
29 on_login => sub {
27 my ($pl, $host) = @_; 30 my ($pl) = @_;
28 31
29 clean_timeouts $pl->ob; 32 clean_timeouts $pl->ob;
30} 33 },
34;
31 35
32cf::register_command listen => 0, sub { 36cf::register_command listen => sub {
33 my ($who, $msg) = @_; 37 my ($who, $msg) = @_;
34 my $player = cf::player::find $who->name; 38 my $player = cf::player::find $who->name;
35 39
36 if ($msg ne "") { 40 if ($msg ne "") {
37 my $prev_listen = $player->listening; 41 my $prev_listen = $player->listening;
44 } else { 48 } else {
45 $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); 49 $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE);
46 } 50 }
47}; 51};
48 52
49cf::register_command say => 0, sub { 53cf::register_command say => sub {
50 my ($who, $msg) = @_; 54 my ($who, $msg) = @_;
55
56 utf8::decode $msg;
57
58 return if $who->contr->invoke (cf::EVENT_PLAYER_SAY, $msg);
51 59
52 if ($msg) { 60 if ($msg) {
53 my $name = $who->name; 61 my $name = $who->name;
54 62
63 utf8::encode $msg; # ->message not yet utf8-ified
55 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) 64 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
56 for grep $who->on_same_map_as ($_->ob), cf::player::list; 65 for grep $who->on_same_map_as ($_->ob), cf::player::list;
66 utf8::decode $msg;
57 67
58 # npcs, magic_ears etc. 68 # npcs, magic_ears etc.
59 # first find all objects and their inventories within a 5x5 square 69 # first find all objects and theirt-level inventories
60 # that have something resembling dialogue 70 # within a 5x5 square # that have something resembling
71 # dialogue or support on_say.
61 my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2); 72 my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2);
62 73
63 for my $npc ( 74 for my $npc (
64 grep NPC_Dialogue::has_dialogue $_, 75 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $who->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_,
65 map +($_, $_->inv), 76 map +($_, $_->inv),
66 grep $_, 77 grep $_,
67 map $map->at ($x + $_ % 5, $y + (int $_ / 5)), 78 map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
68 0..24 79 0..24
69 ) { 80 ) {
97 } else { 108 } else {
98 $who->message ("What do you want to say?", cf::NDI_UNIQUE); 109 $who->message ("What do you want to say?", cf::NDI_UNIQUE);
99 } 110 }
100}; 111};
101 112
102cf::register_command chat => 0, sub { 113cf::register_command chat => sub {
103 my ($who, $msg) = @_; 114 my ($who, $msg) = @_;
115
116 utf8::decode $msg;
117
118 return if $who->contr->invoke (cf::EVENT_PLAYER_CHAT, $msg);
104 119
105 if ($msg) { 120 if ($msg) {
106 my $name = $who->name; 121 my $name = $who->name;
107 my $NOW = time; 122 my $NOW = time;
108 123
124 utf8::encode $msg; # ->message not yet utf8-ified
109 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 125 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
126 ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg);
110 127
111 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 128 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
112 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; 129 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
113 130
114 } else { 131 } else {
115 $who->message ("Chat what?", cf::NDI_UNIQUE); 132 $who->message ("Chat what?", cf::NDI_UNIQUE);
116 } 133 }
117}; 134};
118 135
119cf::register_command shout => 0, sub { 136cf::register_command shout => sub {
120 my ($who, $msg) = @_; 137 my ($who, $msg) = @_;
138
139 utf8::decode $msg;
140
141 return if $who->contr->invoke (cf::EVENT_PLAYER_SHOUT, $msg);
121 142
122 if ($msg) { 143 if ($msg) {
123 my $NOW = time; 144 my $NOW = time;
124 my $name = $who->name; 145 my $name = $who->name;
125 146
126 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; 147 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
148 ext::schmorp_irc::do_notice (sprintf "\007\0034{%s} %s\n", $name, $msg);
127 149
150 utf8::encode $msg; # ->message not yet utf8-ified
128 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 151 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
129 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; 152 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
130 153
131 } else { 154 } else {
132 $who->message ("Shout what?", cf::NDI_UNIQUE); 155 $who->message ("Shout what?", cf::NDI_UNIQUE);
133 } 156 }
134 157
135}; 158};
136 159
137cf::register_command tell => 0, sub { 160cf::register_command tell => sub {
138 my ($who, $args) = @_; 161 my ($who, $args) = @_;
139 my ($target, $msg) = split /\s+/, $args, 2; 162 my ($target, $msg) = split /\s+/, $args, 2;
140 163
164 utf8::decode $msg;
165
166 return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $target, $msg);
167
141 my $name = $who->name; 168 my $name = $who->name;
142 169
170 if ($target =~ /irc\//) {
171 my (undef, $nick) = split /\//, $target, 2;
172 $who->message ("You tell $target: $args");
173 ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $msg);
143 if (my $other = cf::player::find $target) { 174 } elsif (my $other = cf::player::find $target) {
144 175
145 if ($msg) { 176 if ($msg) {
146 if ($target eq $name) { 177 if ($target eq $name) {
147 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); 178 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
148 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { 179 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
149 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); 180 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE);
150 } else { 181 } else {
182 utf8::encode $msg; # ->message not yet utf8-ified
151 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; 183 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
152 184
153 $who->message ("You tell $target: $msg"); 185 $who->message ("You tell $target: $msg");
154 $other->ob->message ("$name tells you: $msg"); 186 $other->ob->message ("$name tells you: $msg");
155 $other->ob->{ext_last_tell} = $name; 187 $other->ob->{ext_last_tell} = $name;
161 } else { 193 } else {
162 $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE); 194 $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE);
163 } 195 }
164}; 196};
165 197
166cf::register_command reply => 0, sub { 198cf::register_command reply => sub {
167 my ($who, $args) = @_; 199 my ($who, $args) = @_;
168 my $name = $who->name; 200 my $name = $who->name;
169 201
202 utf8::decode $args;
203
204 return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $who->{ext_last_tell}, $args);
205
206 if ($who->{ext_last_tell} =~ /irc\//) {
207 my (undef, $nick) = split /\//, $who->{ext_last_tell}, 2;
208 $who->message ("You tell " . $who->{ext_last_tell} . ": $args");
209 ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $args);
170 if (my $other = cf::player::find $who->{ext_last_tell}) { 210 } elsif (my $other = cf::player::find $who->{ext_last_tell}) {
211
171 if ($args) { 212 if ($args) {
172
173 $other->ob->{ext_ignore_tell}{$name} >= time 213 $other->ob->{ext_ignore_tell}{$name} >= time
174 or delete $other->ob->{ext_ignore_tell}{$name}; 214 or delete $other->ob->{ext_ignore_tell}{$name};
175 215
176 if ($other->ob->{ext_ignore_tell}{$name} < time) { 216 if ($other->ob->{ext_ignore_tell}{$name} < time) {
217 utf8::encode $args; # ->message not yet utf8-ified
177 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; 218 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args;
178 219
179 $who->message ("You tell " . $other->ob->name . ": $args"); 220 $who->message ("You tell " . $other->ob->name . ": $args");
180 $other->ob->message ("$name tells you: $args"); 221 $other->ob->message ("$name tells you: $args");
181 $who->{ext_last_tell} = $other->ob->name; 222 $who->{ext_last_tell} = $other->ob->name;
185 } else { 226 } else {
186 $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE); 227 $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE);
187 } 228 }
188 229
189 } else { 230 } else {
190 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE); 231 $who->message ("Can't reply, player left. Your message: $args".$who->{ext_last_tell}, cf::NDI_UNIQUE);
191 } 232 }
192}; 233};
193 234
194cf::register_command ignore => 0, sub { 235cf::register_command ignore => sub {
195 my ($who, $args) = @_; 236 my ($who, $args) = @_;
196 my ($target, $type, $timeout) = split /\s+/, $args; 237 my ($target, $type, $timeout) = split /\s+/, $args;
197 238
198 if ($args eq "list") { 239 if ($args eq "list") {
199 clean_timeouts $who; 240 clean_timeouts $who;
238 . "Usage: ignore list\n" 279 . "Usage: ignore list\n"
239 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); 280 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE);
240 } 281 }
241}; 282};
242 283
243cf::register_command unignore => 0, sub { 284cf::register_command unignore => sub {
244 my ($who, $args) = @_; 285 my ($who, $args) = @_;
245 my ($target, $type) = split /\s+/, $args; 286 my ($target, $type) = split /\s+/, $args;
246 287
247 if ($args eq "") { 288 if ($args eq "") {
248 if ($who->{ext_ignore_tell}) { 289 if ($who->{ext_ignore_tell}) {
272 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 313 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE);
273 } 314 }
274 } 315 }
275}; 316};
276 317
277cf::register_command seen => 0, sub { 318cf::register_command seen => sub {
278 my ($who, $args) = @_; 319 my ($who, $args) = @_;
279 320
280 if (my ($login) = $args =~ /(\S+)/) { 321 if (my ($login) = $args =~ /(\S+)/) {
281 if ($login eq $who->name) { 322 if ($login eq $who->name) {
282 $who->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE); 323 $who->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines