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.33 by root, Fri Aug 25 15:07:43 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
52 if ($msg) { 58 if ($msg) {
53 my $name = $who->name; 59 my $name = $who->name;
54 60
61 utf8::encode $msg; # ->message not yet utf8-ified
55 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) 62 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
56 for grep $who->on_same_map_as ($_->ob), cf::player::list; 63 for grep $who->on_same_map_as ($_->ob), cf::player::list;
64 utf8::decode $msg;
57 65
58 # npcs, magic_ears etc. 66 # npcs, magic_ears etc.
59 # first find all objects and their inventories within a 5x5 square 67 # first find all objects and their inventories within a 5x5 square
60 # that have something resembling dialogue 68 # that have something resembling dialogue
61 my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2); 69 my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2);
69 ) { 77 ) {
70 # if some listener teleported us somewhere else, stop right here 78 # if some listener teleported us somewhere else, stop right here
71 last unless $map->path == $who->map->path; 79 last unless $map->path == $who->map->path;
72 80
73 my $dialog = new NPC_Dialogue ob => $who, npc => $npc; 81 my $dialog = new NPC_Dialogue ob => $who, npc => $npc;
74 my $reply = $dialog->tell ($msg); 82 my ($reply, @kw) = $dialog->tell ($msg);
75 83
76 if (defined $reply) { 84 if (defined $reply) {
77 if ($npc->type == cf::MAGIC_EAR) { 85 if ($npc->type == cf::MAGIC_EAR) {
78 if (length $reply) { 86 if (length $reply) {
79 $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE) 87 $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE)
85 $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE) 93 $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE)
86 for grep $who->on_same_map_as ($_->ob), cf::player::list; 94 for grep $who->on_same_map_as ($_->ob), cf::player::list;
87 } 95 }
88 } 96 }
89 } 97 }
98
99 if (@kw) {
100 $_->ob->message ("[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN | cf::NDI_UNIQUE)
101 for grep $who->on_same_map_as ($_->ob), cf::player::list;
102 }
90 } 103 }
91 104
92 } else { 105 } else {
93 $who->message ("What do you want to say?", cf::NDI_UNIQUE); 106 $who->message ("What do you want to say?", cf::NDI_UNIQUE);
94 } 107 }
95}; 108};
96 109
97cf::register_command chat => 0, sub { 110cf::register_command chat => 0, sub {
98 my ($who, $msg) = @_; 111 my ($who, $msg) = @_;
112
113 utf8::decode $msg;
99 114
100 if ($msg) { 115 if ($msg) {
101 my $name = $who->name; 116 my $name = $who->name;
102 my $NOW = time; 117 my $NOW = time;
103 118
119 utf8::encode $msg; # ->message not yet utf8-ified
104 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 120# cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
121 cf::ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg);
105 122
106 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 123 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
107 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; 124 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
108 125
109 } else { 126 } else {
111 } 128 }
112}; 129};
113 130
114cf::register_command shout => 0, sub { 131cf::register_command shout => 0, sub {
115 my ($who, $msg) = @_; 132 my ($who, $msg) = @_;
133
134 utf8::decode $msg;
116 135
117 if ($msg) { 136 if ($msg) {
118 my $NOW = time; 137 my $NOW = time;
119 my $name = $who->name; 138 my $name = $who->name;
120 139
121 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; 140# cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
141 cf::ext::schmorp_irc::do_notice (sprintf "{%s} %s\n", $name, $msg);
122 142
143 utf8::encode $msg; # ->message not yet utf8-ified
123 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 144 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
124 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; 145 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
125 146
126 } else { 147 } else {
127 $who->message ("Shout what?", cf::NDI_UNIQUE); 148 $who->message ("Shout what?", cf::NDI_UNIQUE);
130}; 151};
131 152
132cf::register_command tell => 0, sub { 153cf::register_command tell => 0, sub {
133 my ($who, $args) = @_; 154 my ($who, $args) = @_;
134 my ($target, $msg) = split /\s+/, $args, 2; 155 my ($target, $msg) = split /\s+/, $args, 2;
156
157 utf8::decode $msg;
135 158
136 my $name = $who->name; 159 my $name = $who->name;
137 160
138 if (my $other = cf::player::find $target) { 161 if (my $other = cf::player::find $target) {
139 162
141 if ($target eq $name) { 164 if ($target eq $name) {
142 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); 165 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
143 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { 166 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
144 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); 167 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE);
145 } else { 168 } else {
169 utf8::encode $msg; # ->message not yet utf8-ified
146 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; 170 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
147 171
148 $who->message ("You tell $target: $msg"); 172 $who->message ("You tell $target: $msg");
149 $other->ob->message ("$name tells you: $msg"); 173 $other->ob->message ("$name tells you: $msg");
150 $other->ob->{ext_last_tell} = $name; 174 $other->ob->{ext_last_tell} = $name;
160 184
161cf::register_command reply => 0, sub { 185cf::register_command reply => 0, sub {
162 my ($who, $args) = @_; 186 my ($who, $args) = @_;
163 my $name = $who->name; 187 my $name = $who->name;
164 188
189 utf8::decode $args;
190
165 if (my $other = cf::player::find $who->{ext_last_tell}) { 191 if (my $other = cf::player::find $who->{ext_last_tell}) {
166 if ($args) { 192 if ($args) {
167 193
168 $other->ob->{ext_ignore_tell}{$name} >= time 194 $other->ob->{ext_ignore_tell}{$name} >= time
169 or delete $other->ob->{ext_ignore_tell}{$name}; 195 or delete $other->ob->{ext_ignore_tell}{$name};
170 196
171 if ($other->ob->{ext_ignore_tell}{$name} < time) { 197 if ($other->ob->{ext_ignore_tell}{$name} < time) {
198 utf8::encode $args; # ->message not yet utf8-ified
172 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; 199 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args;
173 200
174 $who->message ("You tell " . $other->ob->name . ": $args"); 201 $who->message ("You tell " . $other->ob->name . ": $args");
175 $other->ob->message ("$name tells you: $args"); 202 $other->ob->message ("$name tells you: $args");
176 $who->{ext_last_tell} = $other->ob->name; 203 $who->{ext_last_tell} = $other->ob->name;
279 $who->message ("$login is right here on this server!", cf::NDI_UNIQUE); 306 $who->message ("$login is right here on this server!", cf::NDI_UNIQUE);
280 } elsif (cf::player::exists $login 307 } elsif (cf::player::exists $login
281 and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) { 308 and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) {
282 my $time = (stat _)[9]; 309 my $time = (stat _)[9];
283 310
284 $who->message ("$login was last seen here on " 311 $who->message ("$login was last seen here "
285 . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time) 312 . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time)
286 . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE); 313 . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE);
287 } else { 314 } else {
288 $who->message ("No player named $login is known to me.", cf::NDI_UNIQUE); 315 $who->message ("No player named $login is known to me.", cf::NDI_UNIQUE);
289 } 316 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines