ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/chat.ext
Revision: 1.16
Committed: Mon May 8 17:27:42 2006 UTC (18 years ago) by pippijn
Branch: MAIN
Changes since 1.15: +11 -11 lines
Log Message:
Removed say for the moment (it breaks all NPCs, they first have to be
perl-ised)

File Contents

# User Rev Content
1 pippijn 1.1 #! perl
2 root 1.5
3 pippijn 1.15 # implement a replacement for the built-in say/chat/shout/tell/reply commands
4 root 1.5 # adds ignore/unignore functionality
5    
6 root 1.12 sub valid_user($) {
7     -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2;
8     }
9    
10     sub clean_timeouts($) {
11 root 1.8 my ($player) = @_;
12     my $NOW = time;
13    
14     for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
15 root 1.12 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 root 1.8 }
25     }
26    
27     sub on_logout {
28     my ($pl, $host) = @_;
29    
30     clean_timeouts $pl->ob;
31     }
32    
33 pippijn 1.15 cf::register_command listen => 0, sub {
34     my ($who, $msg) = @_;
35     my $player = cf::player::find $who->name;
36    
37     if ($msg) {
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 pippijn 1.16 #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     #};
61 pippijn 1.15
62 pippijn 1.6 cf::register_command chat => 0, sub {
63 pippijn 1.1 my ($who, $msg) = @_;
64    
65     if ($msg) {
66     my $name = $who->name;
67 root 1.8 my $NOW = time;
68 pippijn 1.1
69 root 1.4 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
70 pippijn 1.15 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
71 root 1.4
72 pippijn 1.1 } else {
73     $who->message ("Chat what?", cf::NDI_UNIQUE);
74     }
75     };
76    
77 pippijn 1.6 cf::register_command shout => 0, sub {
78 pippijn 1.1 my ($who, $msg) = @_;
79    
80     if ($msg) {
81 root 1.8 my $NOW = time;
82 pippijn 1.1 my $name = $who->name;
83    
84 root 1.4 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
85 pippijn 1.15 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
86 root 1.4
87 pippijn 1.1 } else {
88     $who->message ("Shout what?", cf::NDI_UNIQUE);
89     }
90    
91     };
92 root 1.5
93     cf::register_command tell => 0, sub {
94     my ($who, $args) = @_;
95     my ($target, $msg) = split /\s+/, $args, 2;
96    
97     my $name = $who->name;
98    
99 pippijn 1.11 if (my $other = cf::player::find $target) {
100 root 1.12
101 pippijn 1.11 if ($msg) {
102 root 1.12 if ($target eq $name) {
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);
106     } else {
107 pippijn 1.9 $who->message ("You tell $target: $msg");
108     $other->ob->message ("$name tells you: $msg");
109     $other->ob->{ext_last_tell} = $name;
110     }
111 root 1.5 } else {
112 pippijn 1.11 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
113 root 1.5 }
114 root 1.12
115 root 1.5 } else {
116 root 1.12 $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE);
117 root 1.5 }
118     };
119    
120     cf::register_command reply => 0, sub {
121     my ($who, $args) = @_;
122     my $name = $who->name;
123    
124 pippijn 1.11 if (my $other = cf::player::find $who->{ext_last_tell}) {
125     if ($args) {
126 root 1.5
127 pippijn 1.9 $other->ob->{ext_ignore_tell}{$name} >= time
128     or delete $other->ob->{ext_ignore_tell}{$name};
129    
130     if ($other->ob->{ext_ignore_tell}{$name} < time) {
131     $who->message ("You tell " . $other->ob->name . ": $args");
132     $other->ob->message ("$name tells you: $args");
133     $who->{ext_last_tell} = $other->ob->name;
134     } else {
135     $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
136     }
137 root 1.5 } else {
138 pippijn 1.11 $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE);
139 root 1.5 }
140 pippijn 1.11
141 root 1.5 } else {
142 pippijn 1.11 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE);
143 root 1.5 }
144     };
145    
146     cf::register_command ignore => 0, sub {
147     my ($who, $args) = @_;
148     my ($target, $type, $timeout) = split /\s+/, $args;
149    
150     if ($args eq "list") {
151 root 1.8 clean_timeouts $who;
152    
153 root 1.5 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}})
154     + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) {
155     $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
156     $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE);
157     $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
158     $who->message ((join ", ", @ignored_shout), cf::NDI_UNIQUE);
159     $who->message ("To stop ignoring one, use unignore.", cf::NDI_UNIQUE);
160     } else {
161     $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
162     }
163    
164     } elsif ($target && $type) {
165    
166     $timeout ne "" or $timeout = 24;
167     my $absolute_timeout = time + $timeout * 3600;
168    
169 root 1.12 if (valid_user $target) {
170 root 1.5 if ($type eq "tell") {
171 root 1.12 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE);
172     $who->{ext_ignore_tell}{$target} = $absolute_timeout;
173 root 1.5 } elsif ($type eq "shout") {
174 root 1.12 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE);
175     $who->{ext_ignore_shout}{$target} = $absolute_timeout;
176 root 1.5 } elsif ($type eq "all") {
177 root 1.12 $who->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE);
178     $who->{ext_ignore_tell}{$target} = $absolute_timeout;
179     $who->{ext_ignore_shout}{$target} = $absolute_timeout;
180 root 1.5 } else {
181     $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
182     }
183     } else {
184 root 1.12 $who->message ("No such player: $target", cf::NDI_UNIQUE);
185 root 1.5 }
186    
187     } else {
188 root 1.12 $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n"
189     . "will ignore a player for <timeout> hours.\n"
190     . "Usage: ignore list\n"
191     . "will show you a list of players currently ignored.", cf::NDI_UNIQUE);
192 root 1.5 }
193     };
194    
195     cf::register_command unignore => 0, sub {
196     my ($who, $args) = @_;
197     my ($target, $type) = split /\s+/, $args;
198    
199     if ($args eq "") {
200 root 1.12 if ($who->{ext_ignore_tell}) {
201 root 1.5 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
202     $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE);
203     $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
204     $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE);
205     } else {
206     $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
207     }
208     } else {
209    
210 root 1.12 if (valid_user $target) {
211 root 1.5 if ($type eq "tell") {
212 root 1.12 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE);
213     delete $who->{ext_ignore_tell} {$target};
214 root 1.5 } elsif ($type eq "shout") {
215 root 1.12 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE);
216     delete $who->{ext_ignore_shout}{$target};
217 root 1.5 } elsif ($type eq "all") {
218 root 1.12 $who->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE);
219     delete $who->{ext_ignore_tell} {$target};
220     delete $who->{ext_ignore_shout}{$target};
221 root 1.5 } else {
222     $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
223     }
224     } else {
225     $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE);
226     }
227    
228     }
229     };
230