ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/chat.ext
Revision: 1.9
Committed: Sun May 7 10:46:07 2006 UTC (18 years ago) by pippijn
Branch: MAIN
Changes since 1.8: +28 -20 lines
Log Message:
Fixed bug where one could tell people empty messages.

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.8 sub 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    
15     sub on_logout {
16     my ($pl, $host) = @_;
17    
18     clean_timeouts $pl->ob;
19     }
20    
21 pippijn 1.6 cf::register_command chat => 0, sub {
22 pippijn 1.1 my ($who, $msg) = @_;
23    
24     if ($msg) {
25     my $name = $who->name;
26 root 1.8 my $NOW = time;
27 pippijn 1.1
28 root 1.4 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
29 root 1.8 for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list;
30 root 1.4
31 pippijn 1.1 } else {
32     $who->message ("Chat what?", cf::NDI_UNIQUE);
33     }
34     };
35    
36 pippijn 1.6 cf::register_command shout => 0, sub {
37 pippijn 1.1 my ($who, $msg) = @_;
38    
39     if ($msg) {
40 root 1.8 my $NOW = time;
41 pippijn 1.1 my $name = $who->name;
42    
43 root 1.4 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
44 root 1.8 for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list;
45 root 1.4
46 pippijn 1.1 } else {
47     $who->message ("Shout what?", cf::NDI_UNIQUE);
48     }
49    
50     };
51 root 1.5
52     cf::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 pippijn 1.9 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 root 1.5
71     } else {
72 pippijn 1.9 $who->message ("No such player or ambiguous name. Your message: $msg", cf::NDI_UNIQUE);
73 root 1.5 }
74     } else {
75 pippijn 1.9 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
76 root 1.5 }
77     };
78    
79     cf::register_command reply => 0, sub {
80     my ($who, $args) = @_;
81     my $name = $who->name;
82    
83 pippijn 1.9 if ($args) {
84     if (my $other = cf::player::find $who->{ext_last_tell}) {
85 root 1.5
86 pippijn 1.9 $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 root 1.5
97     } else {
98 pippijn 1.9 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE);
99 root 1.5 }
100     } else {
101 pippijn 1.9 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
102 root 1.5 }
103     };
104    
105     cf::register_command ignore => 0, sub {
106     my ($who, $args) = @_;
107     my ($target, $type, $timeout) = split /\s+/, $args;
108    
109     if ($args eq "list") {
110 root 1.8 clean_timeouts $who;
111    
112 root 1.5 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    
156     cf::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