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.9 by pippijn, Sun May 7 10:46:07 2006 UTC vs.
Revision 1.13 by pippijn, Sun May 7 19:51:50 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines