# Free Software Foundation, Inc., *
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
#**************************************************************************/
-package ND::IRC::Usermgm;
+package NDIRC::Usermgm;
use strict;
use warnings;
use ND::DB;
-use ND::IRC::Access;
+use NDIRC::Access;
require Exporter;
our @ISA = qw/Exporter/;
-our @EXPORT = qw/addUser whois flags flag laston addPoints chattrG setHost deactivateUser/;
+our @EXPORT = qw/addUser whois flags flag laston addPoints chattrG setHost setPNick deactivateUser getShips/;
sub addUser {
- my ($nick,$host) = @_;
- DB();
+ my ($msg, $command) = @_;
+
+ my ($nick,$pnick);
+ if(defined $msg && $msg =~ /^(\w+)(?: ([^.\s]+))?$/){
+ $nick = $1;
+ $pnick = $2;
+ }else{
+ $ND::server->command("notice $ND::nick syntax: .$command nick [pnick] | nick must be alphanum characters, if no pnick is given then it will be set to nick");
+ return;
+ }
if (hc()){
- unless (defined $host){
- my @nicks = $ND::server->nicks_get_same($nick);
- if (@nicks){
- $nicks[1]->{host} =~ /.*@(.*)/;
- $host = $1;
- }else{
- $host = "$nick.users.netgamers.org";
- }
- }
- my ($username,$hostname) = $ND::DBH->selectrow_array("SELECT username, hostmask FROM users WHERE username ILIKE ? OR hostmask ILIKE ?",undef,$nick,$host);
- if ((not defined $username) && $ND::DBH->do("INSERT INTO users (username,hostmask,password) VALUES(?,?,'')"
- ,undef,$nick,$host)){
- $ND::server->command("msg $ND::target Added $ND::B$nick$ND::B with host: $ND::B$host$ND::B");
+ $pnick = $nick unless $pnick;
+ my $host = "$pnick.users.netgamers.org";
+ my ($username,$hostname,$p_nick) = $ND::DBH->selectrow_array(q{SELECT username, hostmask,pnick
+ FROM users WHERE username ILIKE ? OR hostmask ILIKE ? OR pnick ILIKE ?}
+ ,undef,$nick,$host,$pnick);
+ if ((not defined $username) && $ND::DBH->do("INSERT INTO users (username,hostmask,pnick,password) VALUES(?,?,?,'')"
+ ,undef,$nick,$host,$pnick)){
+ $ND::server->command("msg $ND::target Added $ND::B$nick(/$pnick)$ND::B with host: $ND::B$host$ND::B");
}elsif(defined $username){
- $ND::server->command("msg $ND::target $ND::B$username$ND::B already exists with host: $ND::B$hostname$ND::B.");
+ $ND::server->command("msg $ND::target $ND::B$username ($p_nick)$ND::B already exists with host: $ND::B$hostname$ND::B.");
}else{
- $ND::server->command("msg $ND::target Something went wrong when trying to add $ND::B$nick$ND::B with host: $ND::B$host$ND::B, most likely duplicate user name");
+ $ND::server->command("msg $ND::target Something went wrong when trying to add $ND::B$nick ($pnick)$ND::B with host: $ND::B$host$ND::B, ".$ND::DBH->errstr);
}
}else{
- $ND::server->command("msg $ND::target Only HCs are allowed to check that");
+ $ND::server->command("msg $ND::target Only HCs are allowed to add users");
}
}
sub whois {
}
}
+
+sub getShips {
+ my ($ship) = @_;
+
+ if (officer() || dc()){
+ my $f = $ND::DBH->prepare(qq{SELECT username,amount
+ FROM users u JOIN fleets f USING (uid) JOIN fleet_ships fs ON f.id = fs.fleet WHERE f.fleet = 0 AND ship ILIKE ? ORDER BY amount DESC
+ });
+ $f->execute($ship);
+ my $text;
+ my $i = 0;
+ my $total = 0;
+ while (my $user = $f->fetchrow_hashref){
+ $user->{last} = '?' unless defined $user->{last};
+ $text .= "$user->{username}: $user->{amount} ";
+ $i++;
+ $total += $user->{amount};
+ }
+ if ($text){
+ $ND::server->command("notice $ND::nick $ND::B$i$ND::B Users with $ND::B$total $ship$ND::B: $text");
+ }else{
+ $ND::server->command("msg $ND::target $ND::B$i$ND::B Couldn't find any user with $ND::B$ship$ND::B:");
+ }
+ }
+}
+
sub addPoints {
my ($t,$nick,$p) = @_;
DB();
}
sub chattrG {
- my ($nick, $flags) = @_;
- DB();
- if (hc() || ($flags =~ /^(\+|-)?x$/ && $ND::address eq 'Assassin.users.netgamers.org')){
+ my ($msg, $command) = @_;
+
+ my ($nick, $flags);
+ if(defined $msg && $msg =~ /^(\S+) ((\+|-)?\w+)$/){
+ $nick = $1;
+ $flags = $2;
+ }else{
+ $ND::server->command("notice $ND::nick syntax: .chattr nick [-]flags | % can be used for wildcards \%arro% will match barrow, if a - is given then flags will be removed, otherwise added");
+ return;
+ }
+ if (hc()){# || ($flags =~ /^(\+|-)?x$/ && $ND::address eq 'Assassin.users.netgamers.org')){
my $f = $ND::DBH->prepare("SELECT uid,username FROM users WHERE username ILIKE ?");
$f->execute($nick);
my @user = $f->fetchrow();
}
sub setHost {
- my ($nick, $host) = @_;
- DB();
+ my ($msg, $command) = @_;
+
+ my ($nick, $host);
+ if(defined $msg && $msg =~ /^(\S+) (\S+)$/){
+ $nick = $1;
+ $host = $2;
+ }else{
+ $ND::server->command("notice $ND::nick syntax: .sethost nick host | % can be used for wildcards \%arro% will match barrow");
+ return;
+ }
if (hc()){
my $f = $ND::DBH->prepare("SELECT uid,username FROM users WHERE username ILIKE ?");
$f->execute($nick);
}
}
+sub setPNick {
+ my ($msg, $command) = @_;
+
+ my ($nick, $pnick);
+ if(defined $msg && $msg =~ /^(\S+) ([^.\s]+)$/){
+ $nick = $1;
+ $pnick = $2;
+ }else{
+ $ND::server->command("notice $ND::nick syntax: .$command nick pnick | % can be used for wildcards \%arro% will match barrow");
+ return;
+ }
+ if (hc()){
+ my $f = $ND::DBH->prepare("SELECT uid,username FROM users WHERE username ILIKE ?");
+ $f->execute($nick);
+ my ($uid,$nick) = $f->fetchrow();
+ if ($f->rows == 1){
+ my ($username,$p_nick) = $ND::DBH->selectrow_array("SELECT username, pnick FROM users WHERE pnick ILIKE ? AND NOT (username ILIKE ?)",undef,$pnick,$nick);
+ my $hostname = "$pnick.users.netgamers.org";
+ if ((not defined $username) && $ND::DBH->do("UPDATE users SET pnick = ?, hostmask = ? WHERE uid = ?",undef,$pnick,$hostname,$uid) > 0){
+ $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");
+ }elsif(defined $username){
+ $ND::server->command("msg $ND::target $ND::B$username$ND::B already exists with pnick $ND::B$p_nick$ND::B.");
+ }else{
+ $ND::server->command("msg $ND::target Couldn't update $ND::B$username${ND::B}'s host");
+ }
+ }elsif ($f->rows == 0){
+ $ND::server->command("msg $ND::target No hit, maybe spelling mistake, or add % as wildcard");
+ }else{
+ $ND::server->command("msg $ND::target More than 1 user matched, please refine the search");
+ }
+ $f->finish;
+ }
+}
+
sub deactivateUser {
- my ($nick) = @_;
- DB();
+ my ($msg, $command) = @_;
+
+ my $nick;
+ if(defined $msg && $msg =~ /^(\S+)$/){
+ $nick = $1;
+ }else{
+ $ND::server->command("notice $ND::nick syntax: .$command user");
+ return;
+ }
if (hc()){
my $f = $ND::DBH->prepare("SELECT uid,username FROM users WHERE username ILIKE ?");
$f->execute($nick);