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.2 by root, Sun May 7 07:57:04 2006 UTC vs.
Revision 1.9 by pippijn, Sun May 7 10:46:07 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines