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