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.6 by pippijn, Sun May 7 08:24:50 2006 UTC vs.
Revision 1.9 by pippijn, Sun May 7 10:46:07 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
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}
5 20
6cf::register_command chat => 0, sub { 21cf::register_command chat => 0, sub {
7 my ($who, $msg) = @_; 22 my ($who, $msg) = @_;
8 23
9 if ($msg) { 24 if ($msg) {
10 my $name = $who->name; 25 my $name = $who->name;
26 my $NOW = time;
11 27
12 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 28 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
13 for grep !$player->ob->{ext_ignore_shout}, cf::player::list; 29 for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list;
14 30
15 } else { 31 } else {
16 $who->message ("Chat what?", cf::NDI_UNIQUE); 32 $who->message ("Chat what?", cf::NDI_UNIQUE);
17 } 33 }
18}; 34};
19 35
20cf::register_command shout => 0, sub { 36cf::register_command shout => 0, sub {
21 my ($who, $msg) = @_; 37 my ($who, $msg) = @_;
22 38
23 if ($msg) { 39 if ($msg) {
40 my $NOW = time;
24 my $name = $who->name; 41 my $name = $who->name;
25 42
26 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 43 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
27 for grep !$player->ob->{ext_ignore_shout}, cf::player::list; 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
36 my ($who, $args) = @_; 53 my ($who, $args) = @_;
37 my ($target, $msg) = split /\s+/, $args, 2; 54 my ($target, $msg) = split /\s+/, $args, 2;
38 55
39 my $name = $who->name; 56 my $name = $who->name;
40 57
58 if ($msg) {
41 if (my $other = cf::player::find $target) { 59 if (my $other = cf::player::find $target) {
42 60
43 $other->ob->{ext_ignore_tell}{$name} >= time 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");
44 or delete $other->ob->{ext_ignore_tell}{$name}; 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 }
45 70
46 if ($target ne $name and !$other->ob->{ext_ignore_tell}{$name}) {
47 $who->message ("You tell $target: $msg");
48 $other->ob->message ("$name tells you: $msg");
49 $other->ob->{ext_last_tell} = $name;
50 } elsif ($target eq $name) {
51 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
52 } else { 71 } else {
53 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); 72 $who->message ("No such player or ambiguous name. Your message: $msg", cf::NDI_UNIQUE);
54 } 73 }
55
56 } else { 74 } else {
57 $who->message ("No such player or ambiguous name. Your message: $msg", cf::NDI_UNIQUE); 75 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
58 } 76 }
59}; 77};
60 78
61cf::register_command reply => 0, sub { 79cf::register_command reply => 0, sub {
62 my ($who, $args) = @_; 80 my ($who, $args) = @_;
63 my $name = $who->name; 81 my $name = $who->name;
64 82
83 if ($args) {
65 if (my $other = cf::player::find $who->{ext_last_tell}) { 84 if (my $other = cf::player::find $who->{ext_last_tell}) {
66 85
67 $other->ob->{ext_ignore_tell}{$name} >= time 86 $other->ob->{ext_ignore_tell}{$name} >= time
68 or delete $other->ob->{ext_ignore_tell}{$name}; 87 or delete $other->ob->{ext_ignore_tell}{$name};
69 88
70 if (!$other->ob->{ext_ignore_tell}{$name}) { 89 if ($other->ob->{ext_ignore_tell}{$name} < time) {
71 $who->message ("You tell " . $other->ob->name . ": $args"); 90 $who->message ("You tell " . $other->ob->name . ": $args");
72 $other->ob->message ("$name tells you: $args"); 91 $other->ob->message ("$name tells you: $args");
73 $who->{ext_last_tell} = $other->ob->name; 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
74 } else { 97 } else {
75 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); 98 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE);
76 } 99 }
77
78 } else { 100 } else {
79 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE); 101 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
80 } 102 }
81}; 103};
82 104
83cf::register_command ignore => 0, sub { 105cf::register_command ignore => 0, sub {
84 my ($who, $args) = @_; 106 my ($who, $args) = @_;
85 my ($target, $type, $timeout) = split /\s+/, $args; 107 my ($target, $type, $timeout) = split /\s+/, $args;
86 108
87 if ($args eq "list") { 109 if ($args eq "list") {
110 clean_timeouts $who;
111
88 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}}) 112 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}})
89 + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) { 113 + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) {
90 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 114 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
91 $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE); 115 $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE);
92 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 116 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines