]> ruin.nu Git - NDIRC.git/blob - Usermgm.pm
dc798110bbb366ac795747d6338a27664fb4a4b3
[NDIRC.git] / Usermgm.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::Usermgm;
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/addPoints/;
29
30 sub addPoints {
31         my ($msg, $t) = @_;
32
33         my ($nick, $points);
34         if(defined $msg && $msg =~ /^(\S+)(?: (-?(\d+)?(\.\d+)?))?$/){
35                 $nick = $1;
36                 $points = $2;
37         }else{
38                 $ND::server->command("notice $ND::nick syntax: .$t nick [points] | % can be used for wildcards \%arro\% will match barrow, if the number of points isn't specified, then 1 will be assumed.");
39                 return;
40         }
41         if (   ($t eq "d" && dc())
42                 || ($t eq "a" && bc())
43                 || ($t eq "h" && officer())
44                 || ($t eq "s" && scanner())){
45                 $points = 1 unless $points;
46                 if ($points*$points > 400){
47                         $ND::server->command("msg $ND::target Values between -20 and 20 please");
48                         return;
49                 }
50                 my $f = $ND::DBH->prepare("SELECT uid,username FROM users WHERE username ILIKE ?");
51                 $f->execute($nick);
52                 my @row = $f->fetchrow();
53                 if ($f->rows == 1){
54                         my $type = "defense";
55                         $type = "attack" if $t eq "a";
56                         $type = "humor" if $t eq "h";
57                         $type = "scan" if $t eq "s";
58                         my ($fleets) = $ND::DBH->selectrow_array('SELECT count(*) FROM raids r JOIN raid_targets rt ON r.id = rt.raid JOIN raid_claims rc ON rt.id = rc.target WHERE not launched AND uid = ? AND tick + 24 > tick();',undef,$row[0]);
59                         if ($t eq 'a' && $fleets > 0 && $points > 0){
60                                 $ND::server->command("msg $ND::target $row[1] has $fleets claimed waves the last 24 ticks that aren't marked as launched, so no points.");
61                                 return;
62                         }
63                         $type .= "_points";
64                         $ND::DBH->do("UPDATE users SET $type = $type + ? WHERE uid = ?",undef,$points,$row[0]);
65                         $ND::server->command("msg $ND::target $row[1] has been given $points $type");
66                 }elsif ($f->rows == 0){
67                         $ND::server->command("msg $ND::target No hit, maybe spelling mistake, or add % as wildcard");
68                 }else{
69                         $ND::server->command("msg $ND::target More than 1 user matched, please refine the search");
70                 }
71                 $f->finish;
72
73         }else{
74                 $ND::server->command("msg $ND::target You don't have access for that");
75         }
76 }
77
78 1;