1 #**************************************************************************
2 # Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
29 my ($tick,$stattick) = DB()->selectrow_array(q{SELECT tick(),max(tick) FROM planet_stats});
30 my $last_announcement = 0;
33 my ($sender, $heap, $who, $where, $msg) = @_[SENDER, HEAP, ARG0 .. ARG2];
34 my ($nick,$username,$address) = ( split /[!@]/, $who );
35 my $channel = $where->[0];
37 my $irc = $sender->get_heap();
39 if ($msg =~ /^(\S+): (.+)$/ && $heap->{disp}->has_command('anon',$channel)){
42 unless ($irc->is_channel_member($channel,$1) || /(Constructing|Researching)/){
43 $msg = ".anon $_ $text";
47 if (parseCommand($msg,$irc,$nick,$address,$channel,$heap->{disp},DB())){
48 #Command parsed and run successfully
54 my ($sender, $heap, $who, $where, $msg) = @_[SENDER, HEAP, ARG0 .. ARG2];
55 my ($nick,$username,$address) = ( split /[!@]/, $who );
56 my $irc = $sender->get_heap();
58 if (parseCommand($msg,$irc,$nick,$address,'pm',$heap->{disp},DB())){
59 #Command parsed and run successfully
61 $irc->yield(privmsg => $ND::defchan, chr(3)."04 $nick >> $msg");
62 parseCommand(".report_incs $msg",$irc,$nick,' BATCH ','pm',$heap->{disp},DB());
67 my ($sender, $heap, $who, $channel) = @_[SENDER, HEAP, ARG0 .. ARG1];
68 my ($nick,$username,$address) = ( split /[!@]/, $who );
69 my $irc = $sender->get_heap();
73 if ($channel =~ /^$ND::memchan$/i){
74 if (time - $last_announcement < 1){
75 $last_announcement = time;
78 my $user = $dbh->selectrow_hashref(q{
79 SELECT uid,pid,hostmask,password
80 ,(SELECT max(time) FROM forum_thread_visits WHERE uid = u.uid) AS last_forum_visit
81 FROM users u WHERE hostmask = ?
84 if ($user->{password} eq ''){
85 $irc->yield(privmsg => $ND::memchan, "$nick: Get a new random password with /msg delling !getpass . If you don't know your username, then you can get it with .points");
87 if ($tick > 36 && not defined $user->{pid}){
88 $irc->yield(privmsg => $ND::memchan, "$nick: go to https://nd.ruin.nu/ and enter your coords.");
91 if (not defined $user->{last_forum_visit}){
92 $irc->yield(privmsg => $ND::memchan, "$nick: Go read the forum! https://nd.ruin.nu/forum");
94 my $unread = $dbh->selectrow_hashref(q{SELECT * FROM unread_posts($1)},undef,$user->{uid});
95 if ($unread && $unread->{new}){
96 $irc->yield(notice => $nick, "$unread->{new} posts since your last forum visit ($unread->{unread} unread posts in total) https://nd.ruin.nu/forum/allUnread");
100 if (time - $last_announcement < 2){
101 $last_announcement = time;
104 $last_announcement = time;
109 my ($kernel,$heap) = @_[KERNEL,HEAP];
110 $kernel->delay( refresh => 60 );
111 print 'Time: ' . time() . ' Lag: ' . $heap->{connector}->lag() . "\n";
113 my $irc = $heap->{irc};
116 my @row = $dbh->selectrow_array(q{SELECT tick(), max(tick) FROM planet_stats});
117 if ($tick != $row[0]){
119 $irc->yield(privmsg => $ND::defchan, "New tick: $tick");
121 if (defined $row[1] && $stattick != $row[1]){
123 $irc->yield(privmsg => $ND::memchan, "New tick: $stattick");
125 my $ircreqs = $dbh->prepare(q{SELECT id,username,message,channel FROM irc_requests NATURAL JOIN users WHERE not sent});
126 my $upircreq = $dbh->prepare(q{UPDATE irc_requests SET sent = TRUE WHERE id = ?});
128 while (my $req = $ircreqs->fetchrow_hashref){
129 if ($req->{channel} eq 'def'){
130 $irc->yield(privmsg => $ND::defchan, chr(3)."04 ## $req->{username} via webbie ## >> $req->{message}");
131 parseCommand(".report_incs $req->{message}",$irc,$req->{username},' BATCH ','pm',$heap->{disp},$dbh);
132 }elsif($req->{channel} eq 'scan'){
133 $irc->yield(privmsg => $ND::scanchan, "<$req->{username} via webbie> $req->{message}");
134 }elsif($req->{channel} eq 'members'){
135 $irc->yield(privmsg => $ND::memchan, "<$req->{username} via webbie> $req->{message}");
137 $upircreq->execute($req->{id});
139 my $defmissions = $dbh->prepare(q{
140 SELECT username,call,tick,dm.fleet,p.value
141 ,100 * SUM(fs.amount * (metal + crystal + eonium) / 100) / p.value AS value
143 JOIN current_planet_stats p USING (pid)
144 JOIN launch_confirmations USING (uid)
145 JOIN fleets f USING (fid)
146 JOIN fleet_ships fs USING (fid)
147 JOIN defense_missions dm ON f.fid = dm.fleet
148 JOIN ship_stats ss ON fs.ship = ss.name
149 WHERE NOT dm.announced
150 GROUP BY username,call,tick,dm.fleet,p.value
152 my $updefmis = $dbh->prepare(q{UPDATE defense_missions SET announced = TRUE WHERE fleet = ?});
153 $defmissions->execute();
154 while (my $mission = $defmissions->fetchrow_hashref){
155 $irc->yield(privmsg => $ND::defchan, chr(3)."06 $mission->{username} sent def to call $mission->{call}, $mission->{value}% of value (tick $mission->{tick}) https://nd.ruin.nu/calls/edit/$mission->{call}");
156 $updefmis->execute($mission->{fleet});