]> ruin.nu Git - NDIRC.git/blob - Scans.pm
Converted sendScan and called it anon for scanners too
[NDIRC.git] / Scans.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::Scans;
20 use strict;
21 use warnings;
22 use ND::DB;
23 use NDIRC::Access;
24 require Exporter;
25
26 our @ISA = qw/Exporter/;
27
28 our @EXPORT = qw/addScan addScanGroup/;
29
30 sub addScan {
31         my ($id,$verbose) = @_;
32         if (1){
33                 unless ($ND::DBH->selectrow_array(q{SELECT scan_id FROM scans WHERE NOT groupscan AND scan_id = LOWER(?) AND tick >= tick() - 168},undef,$id)){
34                         my @user = $ND::DBH->selectrow_array(q{SELECT uid,username, scan_points, tick() 
35                                 FROM users WHERE hostmask ILIKE ? },undef,$ND::address);
36                         if ($ND::DBH->do(q{INSERT INTO scans (scan_id,tick,uid) VALUES (LOWER(?),tick(),COALESCE(?,-1))},
37                                         undef,$id,$user[0]) == 1){
38                                 if (@user){
39                                         $ND::DBH->do('UPDATE users SET scan_points = scan_points + 1 WHERE uid = ? ',undef,$user[0]);
40                                         $user[2] += 1;
41                                         $ND::server->command("notice $ND::nick Added scan, points now $user[2]");
42                                 }elsif ($verbose){
43                                         $ND::server->command("msg $ND::target Added scan, but unknown user, no points");
44                                 }
45                         }
46                 }elsif ($verbose){
47                         $ND::server->command("msg $ND::target a scan with that id has already been added within the last 48 ticks");
48                 }
49         }
50 }
51 sub addScanGroup {
52         my ($id,$verbose) = @_;
53         if (1){
54                 unless ($ND::DBH->selectrow_array(q{SELECT scan_id FROM scans WHERE groupscan AND  scan_id = LOWER(?) AND tick >= tick() - 168},undef,$id)){
55                         my @user = $ND::DBH->selectrow_array(q{SELECT uid,username, scan_points, tick() 
56                                 FROM users WHERE hostmask ILIKE ? },undef,$ND::address);
57                         if ($ND::DBH->do(q{INSERT INTO scans (scan_id,tick,groupscan,uid) VALUES (LOWER(?),tick(),true,COALESCE(?,-1))},
58                                         undef,$id,$user[0]) == 1){
59                                 if (@user){
60                                         $ND::server->command("notice $ND::nick Added scan group. Points will be added after parsing.");
61                                 }elsif ($verbose){
62                                         $ND::server->command("msg $ND::target Added scan, but unknown user, no points");
63                                 }
64                         }
65                 }elsif ($verbose){
66                         $ND::server->command("msg $ND::target a scan with that id has already been added within the last 48 ticks");
67                 }
68         }
69 }
70
71
72
73
74 1;