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.24 by root, Fri Jul 21 08:24:47 2006 UTC vs.
Revision 1.40 by pippijn, Sun Dec 10 11:36:39 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 => 0, 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
47}; 51};
48 52
49cf::register_command say => 0, sub { 53cf::register_command say => 0, sub {
50 my ($who, $msg) = @_; 54 my ($who, $msg) = @_;
51 55
56 utf8::decode $msg;
57
58 return if $who->contr->invoke (cf::EVENT_PLAYER_SAY, $msg);
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 ) {
70 # if some listener teleported us somewhere else, stop right here 81 # if some listener teleported us somewhere else, stop right here
71 last unless $map->path == $who->map->path; 82 last unless $map->path == $who->map->path;
72 83
73 my $dialog = new NPC_Dialogue ob => $who, npc => $npc; 84 my $dialog = new NPC_Dialogue ob => $who, npc => $npc;
74 my $reply = $dialog->tell ($msg); 85 my ($reply, @kw) = $dialog->tell ($msg);
75 86
76 if (defined $reply) { 87 if (defined $reply) {
77 if ($npc->type == cf::MAGIC_EAR) { 88 if ($npc->type == cf::MAGIC_EAR) {
78 if (length $reply) { 89 if (length $reply) {
79 $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE) 90 $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE)
85 $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE) 96 $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE)
86 for grep $who->on_same_map_as ($_->ob), cf::player::list; 97 for grep $who->on_same_map_as ($_->ob), cf::player::list;
87 } 98 }
88 } 99 }
89 } 100 }
101
102 if (@kw) {
103 $_->ob->message ("[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN | cf::NDI_UNIQUE)
104 for grep $who->on_same_map_as ($_->ob), cf::player::list;
105 }
90 } 106 }
91 107
92 } else { 108 } else {
93 $who->message ("What do you want to say?", cf::NDI_UNIQUE); 109 $who->message ("What do you want to say?", cf::NDI_UNIQUE);
94 } 110 }
95}; 111};
96 112
97cf::register_command chat => 0, sub { 113cf::register_command chat => 0, sub {
98 my ($who, $msg) = @_; 114 my ($who, $msg) = @_;
115
116 utf8::decode $msg;
117
118 return if $who->contr->invoke (cf::EVENT_PLAYER_CHAT, $msg);
99 119
100 if ($msg) { 120 if ($msg) {
101 my $name = $who->name; 121 my $name = $who->name;
102 my $NOW = time; 122 my $NOW = time;
103 123
124 utf8::encode $msg; # ->message not yet utf8-ified
104 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);
105 127
106 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 128 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
107 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;
108 130
109 } else { 131 } else {
111 } 133 }
112}; 134};
113 135
114cf::register_command shout => 0, sub { 136cf::register_command shout => 0, sub {
115 my ($who, $msg) = @_; 137 my ($who, $msg) = @_;
138
139 utf8::decode $msg;
140
141 return if $who->contr->invoke (cf::EVENT_PLAYER_SHOUT, $msg);
116 142
117 if ($msg) { 143 if ($msg) {
118 my $NOW = time; 144 my $NOW = time;
119 my $name = $who->name; 145 my $name = $who->name;
120 146
121 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 "\0034{%s} %s\n", $name, $msg);
122 149
150 utf8::encode $msg; # ->message not yet utf8-ified
123 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 151 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
124 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;
125 153
126 } else { 154 } else {
127 $who->message ("Shout what?", cf::NDI_UNIQUE); 155 $who->message ("Shout what?", cf::NDI_UNIQUE);
131 159
132cf::register_command tell => 0, sub { 160cf::register_command tell => 0, sub {
133 my ($who, $args) = @_; 161 my ($who, $args) = @_;
134 my ($target, $msg) = split /\s+/, $args, 2; 162 my ($target, $msg) = split /\s+/, $args, 2;
135 163
164 utf8::decode $msg;
165
166 return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $target, $msg);
167
136 my $name = $who->name; 168 my $name = $who->name;
137 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);
138 if (my $other = cf::player::find $target) { 174 } elsif (my $other = cf::player::find $target) {
139 175
140 if ($msg) { 176 if ($msg) {
141 if ($target eq $name) { 177 if ($target eq $name) {
142 $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);
143 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { 179 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
144 $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);
145 } else { 181 } else {
182 utf8::encode $msg; # ->message not yet utf8-ified
146 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;
147 184
148 $who->message ("You tell $target: $msg"); 185 $who->message ("You tell $target: $msg");
149 $other->ob->message ("$name tells you: $msg"); 186 $other->ob->message ("$name tells you: $msg");
150 $other->ob->{ext_last_tell} = $name; 187 $other->ob->{ext_last_tell} = $name;
160 197
161cf::register_command reply => 0, sub { 198cf::register_command reply => 0, sub {
162 my ($who, $args) = @_; 199 my ($who, $args) = @_;
163 my $name = $who->name; 200 my $name = $who->name;
164 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);
165 if (my $other = cf::player::find $who->{ext_last_tell}) { 210 } elsif (my $other = cf::player::find $who->{ext_last_tell}) {
211
166 if ($args) { 212 if ($args) {
167
168 $other->ob->{ext_ignore_tell}{$name} >= time 213 $other->ob->{ext_ignore_tell}{$name} >= time
169 or delete $other->ob->{ext_ignore_tell}{$name}; 214 or delete $other->ob->{ext_ignore_tell}{$name};
170 215
171 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
172 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;
173 219
174 $who->message ("You tell " . $other->ob->name . ": $args"); 220 $who->message ("You tell " . $other->ob->name . ": $args");
175 $other->ob->message ("$name tells you: $args"); 221 $other->ob->message ("$name tells you: $args");
176 $who->{ext_last_tell} = $other->ob->name; 222 $who->{ext_last_tell} = $other->ob->name;
180 } else { 226 } else {
181 $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);
182 } 228 }
183 229
184 } else { 230 } else {
185 $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);
186 } 232 }
187}; 233};
188 234
189cf::register_command ignore => 0, sub { 235cf::register_command ignore => 0, sub {
190 my ($who, $args) = @_; 236 my ($who, $args) = @_;
279 $who->message ("$login is right here on this server!", cf::NDI_UNIQUE); 325 $who->message ("$login is right here on this server!", cf::NDI_UNIQUE);
280 } elsif (cf::player::exists $login 326 } elsif (cf::player::exists $login
281 and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) { 327 and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) {
282 my $time = (stat _)[9]; 328 my $time = (stat _)[9];
283 329
284 $who->message ("$login was last seen here on " 330 $who->message ("$login was last seen here "
285 . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time) 331 . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time)
286 . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE); 332 . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE);
287 } else { 333 } else {
288 $who->message ("No player named $login is known to me.", cf::NDI_UNIQUE); 334 $who->message ("No player named $login is known to me.", cf::NDI_UNIQUE);
289 } 335 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines