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 #**************************************************************************/
19 package NDIRC::Usermgm;
26 our @ISA = qw/Exporter/;
28 our @EXPORT = qw/addPoints setHost setPNick/;
34 if(defined $msg && $msg =~ /^(\S+)(?: (-?(\d+)?(\.\d+)?))?$/){
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.");
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");
50 my $f = $ND::DBH->prepare("SELECT uid,username FROM users WHERE username ILIKE ?");
52 my @row = $f->fetchrow();
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.");
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");
69 $ND::server->command("msg $ND::target More than 1 user matched, please refine the search");
74 $ND::server->command("msg $ND::target You don't have access for that");
79 my ($msg, $command) = @_;
82 if(defined $msg && $msg =~ /^(\S+) (\S+)$/){
86 $ND::server->command("notice $ND::nick syntax: .sethost nick host | % can be used for wildcards \%arro% will match barrow");
90 my $f = $ND::DBH->prepare("SELECT uid,username FROM users WHERE username ILIKE ?");
92 my ($uid,$nick) = $f->fetchrow();
94 my ($username,$hostname) = $ND::DBH->selectrow_array("SELECT username, hostmask FROM users WHERE hostmask ILIKE ? AND NOT (username ILIKE ?)",undef,$host,$nick);
95 if ((not defined $username) && $ND::DBH->do("UPDATE users SET hostmask = ? WHERE uid = ?",undef,$host,$uid) > 0){
96 $ND::server->command("msg $ND::target Updated $ND::B$nick${ND::B}'s host to: $ND::B$host$ND::B");
97 }elsif(defined $username){
98 $ND::server->command("msg $ND::target $ND::B$username$ND::B already exists with host: $ND::B$hostname$ND::B.");
100 $ND::server->command("msg $ND::target Couldn't update $ND::B$username${ND::B}'s host");
102 }elsif ($f->rows == 0){
103 $ND::server->command("msg $ND::target No hit, maybe spelling mistake, or add % as wildcard");
105 $ND::server->command("msg $ND::target More than 1 user matched, please refine the search");
112 my ($msg, $command) = @_;
115 if(defined $msg && $msg =~ /^(\S+) ([^.\s]+)$/){
119 $ND::server->command("notice $ND::nick syntax: .$command nick pnick | % can be used for wildcards \%arro% will match barrow");
123 my $f = $ND::DBH->prepare("SELECT uid,username FROM users WHERE username ILIKE ?");
125 my ($uid,$nick) = $f->fetchrow();
127 my ($username,$p_nick) = $ND::DBH->selectrow_array("SELECT username, pnick FROM users WHERE pnick ILIKE ? AND NOT (username ILIKE ?)",undef,$pnick,$nick);
128 my $hostname = "$pnick.users.netgamers.org";
129 if ((not defined $username) && $ND::DBH->do("UPDATE users SET pnick = ?, hostmask = ? WHERE uid = ?",undef,$pnick,$hostname,$uid) > 0){
130 $ND::server->command("msg $ND::target Updated $ND::B$nick${ND::B}'s pnick to: $ND::B$pnick$ND::B and hostname to $ND::B$hostname$ND::B");
131 }elsif(defined $username){
132 $ND::server->command("msg $ND::target $ND::B$username$ND::B already exists with pnick $ND::B$p_nick$ND::B.");
134 $ND::server->command("msg $ND::target Couldn't update $ND::B$username${ND::B}'s host");
136 }elsif ($f->rows == 0){
137 $ND::server->command("msg $ND::target No hit, maybe spelling mistake, or add % as wildcard");
139 $ND::server->command("msg $ND::target More than 1 user matched, please refine the search");