ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/chat.ext
Revision: 1.8
Committed: Sun May 7 09:18:37 2006 UTC (18 years ago) by root
Branch: MAIN
Changes since 1.7: +23 -7 lines
Log Message:
fix the most obvious problems / try to clean timeouts on log-out

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     if (my $other = cf::player::find $target) {
59    
60 root 1.8 if ($target ne $name and $other->ob->{ext_ignore_tell}{$name} < time) {
61 root 1.5 $who->message ("You tell $target: $msg");
62     $other->ob->message ("$name tells you: $msg");
63     $other->ob->{ext_last_tell} = $name;
64     } elsif ($target eq $name) {
65     $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
66     } else {
67     $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
68     }
69    
70     } else {
71     $who->message ("No such player or ambiguous name. Your message: $msg", cf::NDI_UNIQUE);
72     }
73     };
74    
75     cf::register_command reply => 0, sub {
76     my ($who, $args) = @_;
77     my $name = $who->name;
78    
79     if (my $other = cf::player::find $who->{ext_last_tell}) {
80    
81     $other->ob->{ext_ignore_tell}{$name} >= time
82     or delete $other->ob->{ext_ignore_tell}{$name};
83    
84 root 1.8 if ($other->ob->{ext_ignore_tell}{$name} < time) {
85 root 1.5 $who->message ("You tell " . $other->ob->name . ": $args");
86     $other->ob->message ("$name tells you: $args");
87     $who->{ext_last_tell} = $other->ob->name;
88     } else {
89     $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
90     }
91    
92     } else {
93     $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE);
94     }
95     };
96    
97     cf::register_command ignore => 0, sub {
98     my ($who, $args) = @_;
99     my ($target, $type, $timeout) = split /\s+/, $args;
100    
101     if ($args eq "list") {
102 root 1.8 clean_timeouts $who;
103    
104 root 1.5 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}})
105     + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) {
106     $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
107     $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE);
108     $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
109     $who->message ((join ", ", @ignored_shout), cf::NDI_UNIQUE);
110     $who->message ("To stop ignoring one, use unignore.", cf::NDI_UNIQUE);
111     } else {
112     $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
113     }
114    
115     } elsif ($target && $type) {
116    
117     $timeout ne "" or $timeout = 24;
118    
119     my $absolute_timeout = time + $timeout * 3600;
120    
121     if (my $other = cf::player::find $target) {
122     if ($type eq "tell") {
123     $who->message ("Now ignoring private messages from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE);
124     $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout;
125     } elsif ($type eq "shout") {
126     $who->message ("Now ignoring shouts from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE);
127     $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout;
128     } elsif ($type eq "all") {
129     $who->message ("Now ignoring everything from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE);
130     $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout;
131     $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout;
132     } else {
133     $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
134     }
135     } else {
136     $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE);
137     }
138    
139     } else {
140     $who->message ("Usage:", cf::NDI_UNIQUE);
141     $who->message ("ignore <player> <tell | shout | all> <timeout>", cf::NDI_UNIQUE);
142     $who->message ("will ignore a player for <timeout> hours.", cf::NDI_UNIQUE);
143     $who->message ("ignore list", cf::NDI_UNIQUE);
144     $who->message ("will show you a list of players currently ignored.", cf::NDI_UNIQUE);
145     }
146     };
147    
148     cf::register_command unignore => 0, sub {
149     my ($who, $args) = @_;
150     my ($target, $type) = split /\s+/, $args;
151    
152     if ($args eq "") {
153     if ($who->{ ext_ignore_tell }) {
154     $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
155     $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE);
156     $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
157     $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE);
158     } else {
159     $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
160     }
161     } else {
162    
163     if (my $other = cf::player::find $target) {
164     if ($type eq "tell") {
165     $who->message ("Not ignoring private messages from " . $other->ob->name . " anymore.", cf::NDI_UNIQUE);
166     delete $who->{ext_ignore_tell}{$other->ob->name};
167     } elsif ($type eq "shout") {
168     $who->message ("Not ignoring shouts from " . $other->ob->name." anymore . ", cf::NDI_UNIQUE);
169     delete $who->{ext_ignore_shout}{$other->ob->name};
170     } elsif ($type eq "all") {
171     $who->message ("Not ignoring anything from " . $other->ob->name." anymore . ", cf::NDI_UNIQUE);
172     delete $who->{ext_ignore_tell} {$other->ob->name};
173     delete $who->{ext_ignore_shout}{$other->ob->name};
174     } else {
175     $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
176     }
177     } else {
178     $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE);
179     }
180    
181     }
182     };
183