From 1305a2fbb95ce9ba58ab7e2f90df92715aa7f28e Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Sat, 16 May 2009 14:53:54 +0200 Subject: [PATCH] Converted the .+user command --- Commands/Usermgm.pm | 56 +++++++++++++++++++++++++++++++++++++++++++++ Usermgm.pm | 32 +------------------------- database/roles.sql | 3 +++ ndawn.pl | 2 +- 4 files changed, 61 insertions(+), 32 deletions(-) create mode 100644 Commands/Usermgm.pm diff --git a/Commands/Usermgm.pm b/Commands/Usermgm.pm new file mode 100644 index 0000000..d7d86b0 --- /dev/null +++ b/Commands/Usermgm.pm @@ -0,0 +1,56 @@ +#************************************************************************** +# Copyright (C) 2009 by Michael Andreen * +# * +# This program is free software; you can redistribute it and/or modify * +# it under the terms of the GNU General Public License as published by * +# the Free Software Foundation; either version 2 of the License, or * +# (at your option) any later version. * +# * +# This program is distributed in the hope that it will be useful, * +# but WITHOUT ANY WARRANTY; without even the implied warranty of * +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# GNU General Public License for more details. * +# * +# You should have received a copy of the GNU General Public License * +# along with this program; if not, write to the * +# Free Software Foundation, Inc., * +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +#**************************************************************************/ + +package NDIRC::Commands::Usermgm; + +use strict; +use warnings; +use feature ':5.10'; + +use Moose; +use MooseX::MethodAttributes; + +sub adduser + : Help(syntax: .+user username [pnick] | username must be alphanum characters, if no pnick is given then it will be set to the same as username) + : Alias(+user) + : ACL(irc_adduser) +{ + my ($self,$c,$msg) = @_; + my ($nick,$pnick) = $msg =~ /^(\w+)(?: ([^.\s]+))?$/ or die 'ARGS'; + $pnick //= $nick; + + my $dbh = $c->model; + + my $host = "$pnick.users.netgamers.org"; + my ($username,$hostname,$p_nick) = $dbh->selectrow_array(q{ +SELECT username, hostmask,pnick +FROM users WHERE username ILIKE ? OR hostmask ILIKE ? OR pnick ILIKE ? + },undef,$nick,$host,$pnick); + + if (defined $username){ + $c->reply("$username ($p_nick) already exists with host: $hostname"); + }else{ + $dbh->do(q{ +INSERT INTO users (username,hostmask,pnick,password) VALUES(?,?,?,'') + },undef,$nick,$host,$pnick); + $c->reply("Added $nick(/$pnick) with host: $host"); + } +} + +1; diff --git a/Usermgm.pm b/Usermgm.pm index 6771d65..d3083f4 100644 --- a/Usermgm.pm +++ b/Usermgm.pm @@ -25,38 +25,8 @@ require Exporter; our @ISA = qw/Exporter/; -our @EXPORT = qw/addUser whois flags flag laston addPoints chattrG setHost setPNick deactivateUser getShips getFleet/; +our @EXPORT = qw/whois flags flag laston addPoints chattrG setHost setPNick deactivateUser getShips getFleet/; -sub addUser { - 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()){ - $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 ($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 ($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 add users"); - } -} sub whois { my ($msg, $command) = @_; diff --git a/database/roles.sql b/database/roles.sql index 1a024f8..6840ee5 100644 --- a/database/roles.sql +++ b/database/roles.sql @@ -9,6 +9,7 @@ INSERT INTO roles VALUES('irc_anonscan'); INSERT INTO roles VALUES('irc_delquote'); INSERT INTO roles VALUES('irc_points_others'); INSERT INTO roles VALUES('irc_sms'); +INSERT INTO roles VALUES('irc_adduser'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_nick'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_intel'); @@ -19,6 +20,7 @@ INSERT INTO group_roles (gid,role) VALUES(1,'irc_anonscan'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_delquote'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_points_others'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_sms'); +INSERT INTO group_roles (gid,role) VALUES(1,'irc_adduser'); INSERT INTO group_roles (gid,role) VALUES(2,'irc_gs'); INSERT INTO group_roles (gid,role) VALUES(2,'irc_scan'); @@ -31,6 +33,7 @@ INSERT INTO group_roles (gid,role) VALUES(3,'irc_anonscan'); INSERT INTO group_roles (gid,role) VALUES(3,'irc_delquote'); INSERT INTO group_roles (gid,role) VALUES(3,'irc_points_others'); INSERT INTO group_roles (gid,role) VALUES(3,'irc_sms'); +INSERT INTO group_roles (gid,role) VALUES(3,'irc_adduser'); INSERT INTO group_roles (gid,role) VALUES(4,'irc_points_others'); diff --git a/ndawn.pl b/ndawn.pl index ca09a20..79165bd 100644 --- a/ndawn.pl +++ b/ndawn.pl @@ -55,7 +55,7 @@ my $TICK = $DBH->selectrow_array('SELECT tick()'); my $disp = new NDIRC::Dispatcher; -$disp->load('Basic','PA','Channel','Scans','Quotes','Members'); +$disp->load('Basic','PA','Channel','Scans','Quotes','Members','Usermgm'); $ND::scanchan = '#testarmer'; $disp->add_channel('#testarlite', ['pub','help','channel']); -- 2.39.2