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 say/chat/shout/tell/reply commands |
4 | # adds ignore/unignore functionality |
4 | # adds ignore/unignore functionality |
5 | |
5 | |
6 | sub valid_user($) { |
6 | sub valid_user($) { |
|
|
7 | cf::player::find $_[0] |
7 | -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; |
8 | or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; |
8 | } |
9 | } |
9 | |
10 | |
10 | sub clean_timeouts($) { |
11 | sub clean_timeouts($) { |
11 | my ($player) = @_; |
12 | my ($player) = @_; |
12 | my $NOW = time; |
13 | my $NOW = time; |
… | |
… | |
28 | my ($pl, $host) = @_; |
29 | my ($pl, $host) = @_; |
29 | |
30 | |
30 | clean_timeouts $pl->ob; |
31 | clean_timeouts $pl->ob; |
31 | } |
32 | } |
32 | |
33 | |
|
|
34 | cf::register_command listen => 0, sub { |
|
|
35 | my ($who, $msg) = @_; |
|
|
36 | my $player = cf::player::find $who->name; |
|
|
37 | |
|
|
38 | if ($msg ne "") { |
|
|
39 | my $prev_listen = $player->listening; |
|
|
40 | $player->listening ($msg); |
|
|
41 | if ($prev_listen == $player->listening) { |
|
|
42 | $who->message ("Your verbose level stayed ".$prev_listen.".", cf::NDI_UNIQUE); |
|
|
43 | } else { |
|
|
44 | $who->message ("Your verbose level is now ".$player->listening.". (previously: ".$prev_listen.")", cf::NDI_UNIQUE); |
|
|
45 | } |
|
|
46 | } else { |
|
|
47 | $who->message ("Your verbose level is ".$player->listening.".", cf::NDI_UNIQUE); |
|
|
48 | } |
|
|
49 | }; |
|
|
50 | |
|
|
51 | #cf::register_command say => 0, sub { |
|
|
52 | # my ($who, $msg) = @_; |
|
|
53 | # |
|
|
54 | # if ($msg) { |
|
|
55 | # my $name = $who->name; |
|
|
56 | # $_->ob->message ("$name says: $msg", cf::NDI_WHITE) |
|
|
57 | # for grep $who->on_same_map_as ($_->ob), cf::player::list; |
|
|
58 | # } else { |
|
|
59 | # $who->message ("What do you want to say?", cf::NDI_UNIQUE); |
|
|
60 | # } |
|
|
61 | #}; |
|
|
62 | |
33 | cf::register_command chat => 0, sub { |
63 | cf::register_command chat => 0, sub { |
34 | my ($who, $msg) = @_; |
64 | my ($who, $msg) = @_; |
35 | |
65 | |
36 | if ($msg) { |
66 | if ($msg) { |
37 | my $name = $who->name; |
67 | my $name = $who->name; |
38 | my $NOW = time; |
68 | my $NOW = time; |
39 | |
69 | |
|
|
70 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
|
|
71 | |
40 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
72 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
41 | for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list; |
73 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
42 | |
74 | |
43 | } else { |
75 | } else { |
44 | $who->message ("Chat what?", cf::NDI_UNIQUE); |
76 | $who->message ("Chat what?", cf::NDI_UNIQUE); |
45 | } |
77 | } |
46 | }; |
78 | }; |
… | |
… | |
50 | |
82 | |
51 | if ($msg) { |
83 | if ($msg) { |
52 | my $NOW = time; |
84 | my $NOW = time; |
53 | my $name = $who->name; |
85 | my $name = $who->name; |
54 | |
86 | |
|
|
87 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
|
|
88 | |
55 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
89 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
56 | for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list; |
90 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
57 | |
91 | |
58 | } else { |
92 | } else { |
59 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
93 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
60 | } |
94 | } |
61 | |
95 | |
… | |
… | |
73 | if ($target eq $name) { |
107 | if ($target eq $name) { |
74 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
108 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
75 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
109 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
76 | $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
110 | $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
77 | } else { |
111 | } else { |
|
|
112 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
|
|
113 | |
78 | $who->message ("You tell $target: $msg"); |
114 | $who->message ("You tell $target: $msg"); |
79 | $other->ob->message ("$name tells you: $msg"); |
115 | $other->ob->message ("$name tells you: $msg"); |
80 | $other->ob->{ext_last_tell} = $name; |
116 | $other->ob->{ext_last_tell} = $name; |
81 | } |
117 | } |
82 | } else { |
118 | } else { |
… | |
… | |
97 | |
133 | |
98 | $other->ob->{ext_ignore_tell}{$name} >= time |
134 | $other->ob->{ext_ignore_tell}{$name} >= time |
99 | or delete $other->ob->{ext_ignore_tell}{$name}; |
135 | or delete $other->ob->{ext_ignore_tell}{$name}; |
100 | |
136 | |
101 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
137 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
|
|
138 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; |
|
|
139 | |
102 | $who->message ("You tell " . $other->ob->name . ": $args"); |
140 | $who->message ("You tell " . $other->ob->name . ": $args"); |
103 | $other->ob->message ("$name tells you: $args"); |
141 | $other->ob->message ("$name tells you: $args"); |
104 | $who->{ext_last_tell} = $other->ob->name; |
142 | $who->{ext_last_tell} = $other->ob->name; |
105 | } else { |
143 | } else { |
106 | $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
144 | $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |