ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/chat.ext
Revision: 1.12
Committed: Sun May 7 11:23:43 2006 UTC (18 years ago) by root
Branch: MAIN
Changes since 1.11: +44 -34 lines
Log Message:
allow all users to be ignored, not just the logged-in ones

File Contents

# User Rev Content
1 pippijn 1.1 #! perl
2 root 1.5
3     # implement a replacement for the built-in chat/shout/tell/reply commands
4     # 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.6 cf::register_command chat => 0, sub {
34 pippijn 1.1 my ($who, $msg) = @_;
35    
36     if ($msg) {
37     my $name = $who->name;
38 root 1.8 my $NOW = time;
39 pippijn 1.1
40 root 1.4 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
41 root 1.8 for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list;
42 root 1.4
43 pippijn 1.1 } else {
44     $who->message ("Chat what?", cf::NDI_UNIQUE);
45     }
46     };
47    
48 pippijn 1.6 cf::register_command shout => 0, sub {
49 pippijn 1.1 my ($who, $msg) = @_;
50    
51     if ($msg) {
52 root 1.8 my $NOW = time;
53 pippijn 1.1 my $name = $who->name;
54    
55 root 1.4 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
56 root 1.8 for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list;
57 root 1.4
58 pippijn 1.1 } else {
59     $who->message ("Shout what?", cf::NDI_UNIQUE);
60     }
61    
62     };
63 root 1.5
64     cf::register_command tell => 0, sub {
65     my ($who, $args) = @_;
66     my ($target, $msg) = split /\s+/, $args, 2;
67    
68     my $name = $who->name;
69    
70 pippijn 1.11 if (my $other = cf::player::find $target) {
71 root 1.12
72 pippijn 1.11 if ($msg) {
73 root 1.12 if ($target eq $name) {
74     $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
75     } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
76     $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE);
77     } else {
78 pippijn 1.9 $who->message ("You tell $target: $msg");
79     $other->ob->message ("$name tells you: $msg");
80     $other->ob->{ext_last_tell} = $name;
81     }
82 root 1.5 } else {
83 pippijn 1.11 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
84 root 1.5 }
85 root 1.12
86 root 1.5 } else {
87 root 1.12 $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE);
88 root 1.5 }
89     };
90    
91     cf::register_command reply => 0, sub {
92     my ($who, $args) = @_;
93     my $name = $who->name;
94    
95 pippijn 1.11 if (my $other = cf::player::find $who->{ext_last_tell}) {
96     if ($args) {
97 root 1.5
98 pippijn 1.9 $other->ob->{ext_ignore_tell}{$name} >= time
99     or delete $other->ob->{ext_ignore_tell}{$name};
100    
101     if ($other->ob->{ext_ignore_tell}{$name} < time) {
102     $who->message ("You tell " . $other->ob->name . ": $args");
103     $other->ob->message ("$name tells you: $args");
104     $who->{ext_last_tell} = $other->ob->name;
105     } else {
106     $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
107     }
108 root 1.5 } else {
109 pippijn 1.11 $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE);
110 root 1.5 }
111 pippijn 1.11
112 root 1.5 } else {
113 pippijn 1.11 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE);
114 root 1.5 }
115     };
116    
117     cf::register_command ignore => 0, sub {
118     my ($who, $args) = @_;
119     my ($target, $type, $timeout) = split /\s+/, $args;
120    
121     if ($args eq "list") {
122 root 1.8 clean_timeouts $who;
123    
124 root 1.5 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}})
125     + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) {
126     $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
127     $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE);
128     $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
129     $who->message ((join ", ", @ignored_shout), cf::NDI_UNIQUE);
130     $who->message ("To stop ignoring one, use unignore.", cf::NDI_UNIQUE);
131     } else {
132     $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
133     }
134    
135     } elsif ($target && $type) {
136    
137     $timeout ne "" or $timeout = 24;
138     my $absolute_timeout = time + $timeout * 3600;
139    
140 root 1.12 if (valid_user $target) {
141 root 1.5 if ($type eq "tell") {
142 root 1.12 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE);
143     $who->{ext_ignore_tell}{$target} = $absolute_timeout;
144 root 1.5 } elsif ($type eq "shout") {
145 root 1.12 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE);
146     $who->{ext_ignore_shout}{$target} = $absolute_timeout;
147 root 1.5 } elsif ($type eq "all") {
148 root 1.12 $who->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE);
149     $who->{ext_ignore_tell}{$target} = $absolute_timeout;
150     $who->{ext_ignore_shout}{$target} = $absolute_timeout;
151 root 1.5 } else {
152     $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
153     }
154     } else {
155 root 1.12 $who->message ("No such player: $target", cf::NDI_UNIQUE);
156 root 1.5 }
157    
158     } else {
159 root 1.12 $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n"
160     . "will ignore a player for <timeout> hours.\n"
161     . "Usage: ignore list\n"
162     . "will show you a list of players currently ignored.", cf::NDI_UNIQUE);
163 root 1.5 }
164     };
165    
166     cf::register_command unignore => 0, sub {
167     my ($who, $args) = @_;
168     my ($target, $type) = split /\s+/, $args;
169    
170     if ($args eq "") {
171 root 1.12 if ($who->{ext_ignore_tell}) {
172 root 1.5 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
173     $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE);
174     $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
175     $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE);
176     } else {
177     $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
178     }
179     } else {
180    
181 root 1.12 if (valid_user $target) {
182 root 1.5 if ($type eq "tell") {
183 root 1.12 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE);
184     delete $who->{ext_ignore_tell} {$target};
185 root 1.5 } elsif ($type eq "shout") {
186 root 1.12 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE);
187     delete $who->{ext_ignore_shout}{$target};
188 root 1.5 } elsif ($type eq "all") {
189 root 1.12 $who->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE);
190     delete $who->{ext_ignore_tell} {$target};
191     delete $who->{ext_ignore_shout}{$target};
192 root 1.5 } else {
193     $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
194     }
195     } else {
196     $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE);
197     }
198    
199     }
200     };
201