ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/chat.ext
Revision: 1.13
Committed: Sun May 7 19:51:50 2006 UTC (18 years ago) by pippijn
Branch: MAIN
Changes since 1.12: +2 -2 lines
Log Message:
Check for listen level in shout and chat.

File Contents

# Content
1 #! perl
2
3 # implement a replacement for the built-in chat/shout/tell/reply commands
4 # adds ignore/unignore functionality
5
6 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 my ($player) = @_;
12 my $NOW = time;
13
14 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
15 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 }
25 }
26
27 sub on_logout {
28 my ($pl, $host) = @_;
29
30 clean_timeouts $pl->ob;
31 }
32
33 cf::register_command chat => 0, sub {
34 my ($who, $msg) = @_;
35
36 if ($msg) {
37 my $name = $who->name;
38 my $NOW = time;
39
40 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
41 for grep { $_->ob->{ext_ignore_shout}{$name} and $_->listening >= 10 } < $NOW, cf::player::list;
42
43 } else {
44 $who->message ("Chat what?", cf::NDI_UNIQUE);
45 }
46 };
47
48 cf::register_command shout => 0, sub {
49 my ($who, $msg) = @_;
50
51 if ($msg) {
52 my $NOW = time;
53 my $name = $who->name;
54
55 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
56 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW and $_->listening >= 2 }, cf::player::list;
57
58 } else {
59 $who->message ("Shout what?", cf::NDI_UNIQUE);
60 }
61
62 };
63
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 if (my $other = cf::player::find $target) {
71
72 if ($msg) {
73 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 $who->message ("You tell $target: $msg");
79 $other->ob->message ("$name tells you: $msg");
80 $other->ob->{ext_last_tell} = $name;
81 }
82 } else {
83 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
84 }
85
86 } else {
87 $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE);
88 }
89 };
90
91 cf::register_command reply => 0, sub {
92 my ($who, $args) = @_;
93 my $name = $who->name;
94
95 if (my $other = cf::player::find $who->{ext_last_tell}) {
96 if ($args) {
97
98 $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 } else {
109 $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE);
110 }
111
112 } else {
113 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE);
114 }
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 clean_timeouts $who;
123
124 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 if (valid_user $target) {
141 if ($type eq "tell") {
142 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE);
143 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
144 } elsif ($type eq "shout") {
145 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE);
146 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
147 } elsif ($type eq "all") {
148 $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 } else {
152 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
153 }
154 } else {
155 $who->message ("No such player: $target", cf::NDI_UNIQUE);
156 }
157
158 } else {
159 $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 }
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 if ($who->{ext_ignore_tell}) {
172 $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 if (valid_user $target) {
182 if ($type eq "tell") {
183 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE);
184 delete $who->{ext_ignore_tell} {$target};
185 } elsif ($type eq "shout") {
186 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE);
187 delete $who->{ext_ignore_shout}{$target};
188 } elsif ($type eq "all") {
189 $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 } 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