… | |
… | |
52 | sub notify_players { |
52 | sub notify_players { |
53 | my (%sent_targets) = @_; |
53 | my (%sent_targets) = @_; |
54 | |
54 | |
55 | # lets message player ingame: this is a NEW feature from the perl IPO :-) |
55 | # lets message player ingame: this is a NEW feature from the perl IPO :-) |
56 | for (keys %sent_targets) { |
56 | for (keys %sent_targets) { |
57 | if (my $player = cf::player::find $_) { |
57 | if (my $player = cf::player::find_active $_) { |
58 | my $cnt = $sent_targets{$_}; |
58 | my $cnt = $sent_targets{$_}; |
59 | |
59 | |
60 | if ($cnt == 1) { |
60 | if ($cnt == 1) { |
61 | $player->ob->message ("You've got new mail."); |
61 | $player->ob->message ("You've got new mail."); |
62 | } else { |
62 | } else { |
… | |
… | |
72 | my $r = $cb->($o, @a); |
72 | my $r = $cb->($o, @a); |
73 | $map->insert_object ($o, $x, $y); |
73 | $map->insert_object ($o, $x, $y); |
74 | $r |
74 | $r |
75 | } |
75 | } |
76 | |
76 | |
77 | # this handler handles to notice the player that he has got mail |
77 | # this handler notifies the player of new mail |
78 | cf::attach_to_players |
78 | cf::player->attach ( |
79 | on_login => sub { |
79 | on_login => sub { |
80 | my ($pl) = @_; |
80 | my ($pl) = @_; |
81 | |
81 | |
82 | my $mails = CFMail::get_mail ($pl->ob->name); |
82 | my $mails = CFMail::get_mail ($pl->ob->name); |
83 | |
83 | |
… | |
… | |
89 | $pl->ob->message ("You got $cnt mails."); |
89 | $pl->ob->message ("You got $cnt mails."); |
90 | } else { |
90 | } else { |
91 | $pl->ob->message ("You haven't got any mail."); |
91 | $pl->ob->message ("You haven't got any mail."); |
92 | } |
92 | } |
93 | }, |
93 | }, |
94 | ; |
94 | ); |
95 | |
95 | |
96 | # this event handler handles receiving of mails |
96 | # this event handler handles receiving of mails |
97 | cf::register_attachment ipo_mailbox => |
97 | cf::object::attachment ipo_mailbox => |
98 | on_apply => sub { |
98 | on_apply => sub { |
99 | my ($box, $pl) = @_; |
99 | my ($box, $pl) = @_; |
100 | |
100 | |
101 | my $cnt; |
101 | my $cnt; |
102 | my $mails = CFMail::get_mail ($pl->name) || []; |
102 | my $mails = CFMail::get_mail ($pl->name) || []; |
… | |
… | |
167 | cf::register_script_function "ipo::command" => sub { |
167 | cf::register_script_function "ipo::command" => sub { |
168 | my ($who, $msg, $npc) = @_; |
168 | my ($who, $msg, $npc) = @_; |
169 | my ($cmd, $arguments) = split /\s+/, $msg, 2; |
169 | my ($cmd, $arguments) = split /\s+/, $msg, 2; |
170 | $cmd = lc $cmd; |
170 | $cmd = lc $cmd; |
171 | |
171 | |
172 | my $pl = cf::player::find $who->name; |
172 | my $pl = cf::player::find_active $who->name; |
173 | my ($x, $y) = ($pl->ob->x, $pl->ob->y); |
173 | my ($x, $y) = ($pl->ob->x, $pl->ob->y); |
174 | |
174 | |
175 | if (my $pr = $prices{$cmd}) { |
175 | if (my $pr = $prices{$cmd}) { |
176 | if ($cmd eq 'mailwarning' and !$who->flag (cf::FLAG_WIZ)) { |
176 | if ($cmd eq 'mailwarning' and !$who->flag (cf::FLAG_WIZ)) { |
177 | return 1; |
177 | return 1; |
… | |
… | |
258 | package CFMail; |
258 | package CFMail; |
259 | |
259 | |
260 | use POSIX qw/strftime/; |
260 | use POSIX qw/strftime/; |
261 | use CFDB; |
261 | use CFDB; |
262 | |
262 | |
263 | my $MAILDB = CFDB->new (db_file => cf::localdir . "/crossfiremail.perl"); |
263 | my $MAILDB = CFDB->new (db_file => cf::localdir . "/crossfiremail"); |
264 | |
264 | |
265 | sub get_mail { |
265 | sub get_mail { |
266 | my ($toname) = @_; |
266 | my ($toname) = @_; |
267 | $MAILDB->get ($toname); |
267 | $MAILDB->get ($toname); |
268 | } |
268 | } |