]> ruin.nu Git - NDIRC.git/blob - Members.pm
ba62c1dd506adb417bba9c6ccaf602892871b3df
[NDIRC.git] / Members.pm
1 #**************************************************************************
2 #   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
3 #                                                                         *
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.                                   *
8 #                                                                         *
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.                          *
13 #                                                                         *
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 #**************************************************************************/
19 package NDIRC::Members;
20 use strict;
21 use warnings;
22 use NDIRC::Access;
23 use ND::DB;
24 require Exporter;
25
26 our @ISA = qw/Exporter/;
27
28 our @EXPORT = qw/currentCalls showraids checkPoints findSMS/;
29
30 sub currentCalls {
31         my ($msg, $command) = @_;
32         if (1){ #TODO: add check for member
33                 my $f = $ND::DBH->prepare(<<SQL
34         SELECT (c.landing_tick - tick()) AS eta, concat(i.shiptype||'/') AS shiptype, dc.username,p.x
35         FROM calls c 
36                 JOIN incomings i ON i.call = c.id
37                 LEFT OUTER JOIN users dc ON dc.uid = c.dc
38                 JOIN users u ON u.uid = c.member
39                 JOIN current_planet_stats p ON u.planet = p.id
40         WHERE open AND (c.landing_tick - tick()) >= 7
41         GROUP BY c.id,c.landing_tick,dc.username,p.x
42         ORDER BY c.landing_tick;
43 SQL
44 );
45                 $f->execute();
46                 my $calls = "";
47                 while (my @row = $f->fetchrow()){
48                         chop($row[1]);
49                         my $dc = defined $row[2] ? $row[2] : '';
50                         $calls .= " (Anti $row[1] ETA: $row[0] Cluster: $row[3] DC: $dc) |"
51                 }
52                 chop($calls);
53                 if (defined $command || length $calls > 0){
54                         $ND::server->command("msg $ND::target Current calls: $calls");
55                 }
56         }
57 }
58
59 sub showraids {
60         DB();
61         if (1){ #TODO: add check for member
62                 my $f = $ND::DBH->prepare(<<SQL
63         SELECT id FROM raids 
64         WHERE open AND not removed AND tick + waves - 7 > tick()
65         AND id IN (SELECT raid FROM raid_access WHERE gid = 2)
66 SQL
67 );
68                 $f->execute();
69                 my $calls = "";
70                 while (my ($raid) = $f->fetchrow()){
71                         $calls .= " https://nd.ruin.nu/raids?raid=$raid |"
72                 }
73                 $calls = "No open future raids" if ($f->rows == 0);
74                 chop($calls);
75                 $ND::server->command("msg $ND::target $calls");
76         }
77 }
78
79 sub checkPoints {
80         my ($nick,$command) = @_;
81         my $f;
82         if ($nick){
83                 if (officer() || dc() || bc()){
84                         $f = $ND::DBH->prepare("SELECT username, attack_points, defense_points, scan_points, humor_points FROM users WHERE username ILIKE ?");
85                 }else{
86                         $ND::server->command("msg $ND::target Only officers are allowed to check for others");
87                 }
88         } else{
89                 $f = $ND::DBH->prepare("SELECT username, attack_points, defense_points, scan_points, humor_points FROM users WHERE hostmask ILIKE ?");
90                 $nick = $ND::address;
91         }
92         if ($f){
93                 $f->execute($nick);
94                 while (my @row = $f->fetchrow()){
95                         $ND::server->command("msg $ND::target $row[0] has $row[1] Attack, $row[2] Defense, $row[3] Scan, $row[4] Humor points");
96                 }
97         }
98 }
99
100 sub findSMS {
101         my ($nick,$command) = @_;
102         unless (defined $nick){
103                 $ND::server->command("notice $ND::nick syntax: .$command nick | % can be used for wildcards \%arro\% will match barrow");
104                 return;
105         }
106         if (officer() || dc()){
107                 my $f = $ND::DBH->prepare("SELECT username,COALESCE(sms,'nothing added') FROM users WHERE username ILIKE ?");
108                 if (my ($username,$sms) = $ND::DBH->selectrow_array($f,undef,$nick)){
109                         $ND::server->command("notice $ND::nick $ND::B$username$ND::B has sms $ND::B$sms$ND::B");
110                 }else{
111                         $ND::server->command("notice $ND::nick No hit, maybe spelling mistake, or add % as wildcard");
112                 }
113         }
114 }
115
116 1;