From ca8f6135c9709112a5d6605ac34064f5946d9570 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Sat, 16 May 2009 22:18:22 +0200 Subject: [PATCH] Converted .a, .d, .s and .h --- Commands/Usermgm.pm | 81 +++++++++++++++++++++++++++++++++++++++++++++ Usermgm.pm | 78 ------------------------------------------- database/roles.sql | 15 +++++++++ ndawn.pl | 2 +- 4 files changed, 97 insertions(+), 79 deletions(-) delete mode 100644 Usermgm.pm diff --git a/Commands/Usermgm.pm b/Commands/Usermgm.pm index a8683c8..deae5a2 100644 --- a/Commands/Usermgm.pm +++ b/Commands/Usermgm.pm @@ -403,4 +403,85 @@ SELECT username,hostmask,pnick FROM users WHERE hostmask ILIKE $1 OR pnick ILIKE $f->finish; } +sub a + : Help(Usage: .a username [points] | % can be used for wildcards \%arro\% will match barrow, if the number of points isn't specified, then 1 will be assumed.) + : ACL(irc_a) +{ + my ($self,$c,$msg) = @_; + my ($nick,$points) = $msg =~ /^(\S+)(?: (-?(\d+)?(\.\d+)?))?$/ or die 'ARGS'; + $points //= 1; + + my ($fleets) = $c->model->selectrow_array(q{ +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 tick + 24 > tick() + AND uid = (SELECT uid FROM users WHERE username ILIKE $1); + },undef,$nick); + + if ($fleets > 0 && $points > 0){ + $c->reply("$nick has $fleets claimed waves the last 24 ticks that aren't marked as launched, so no points."); + return; + } + addPoints($c, 'attack', $nick, $points); +} + +sub d + : Help(Usage: .d username [points] | % can be used for wildcards \%arro\% will match barrow, if the number of points isn't specified, then 1 will be assumed.) + : ACL(irc_d) + : Type(def) +{ + my ($self,$c,$msg) = @_; + my ($nick,$points) = $msg =~ /^(\S+)(?: (-?(\d+)?(\.\d+)?))?$/ or die 'ARGS'; + + addPoints($c, 'defense', $nick, $points); +} + +sub s + : Help(Usage: .s username [points] | % can be used for wildcards \%arro\% will match barrow, if the number of points isn't specified, then 1 will be assumed.) + : ACL(irc_s) +{ + my ($self,$c,$msg) = @_; + my ($nick,$points) = $msg =~ /^(\S+)(?: (-?(\d+)?(\.\d+)?))?$/ or die 'ARGS'; + + addPoints($c, 'scan', $nick, $points); +} + +sub h + : Help(Usage: .h username [points] | % can be used for wildcards \%arro\% will match barrow, if the number of points isn't specified, then 1 will be assumed.) + : ACL(irc_h) +{ + my ($self,$c,$msg) = @_; + my ($nick,$points) = $msg =~ /^(\S+)(?: (-?(\d+)?(\.\d+)?))?$/ or die 'ARGS'; + + addPoints($c, 'humor', $nick, $points); +} + +sub addPoints { + my ($c,$type, $nick, $points) = @_; + $points //= 1; + + my $dbh = $c->model; + + if ($points*$points > 400){ + $c->reply("Values between -20 and 20 please"); + return; + } + + my $f = $dbh->prepare(q{SELECT uid,username FROM users WHERE username ILIKE ?}); + $f->execute($nick); + my $user = $f->fetchrow_hashref; + if ($f->rows == 1){ + $type .= "_points"; + $dbh->do(qq{UPDATE users SET $type = $type + ? WHERE uid = ?} + ,undef,$points,$user->{uid}); + $c->reply("$user->{username} has been given $points $type"); + }elsif ($f->rows == 0){ + $c->reply("No hit, maybe spelling mistake, or add % as wildcard"); + }else{ + $c->reply("More than 1 user matched, please refine the search"); + } + $f->finish; +} + 1; diff --git a/Usermgm.pm b/Usermgm.pm deleted file mode 100644 index dc79811..0000000 --- a/Usermgm.pm +++ /dev/null @@ -1,78 +0,0 @@ -#************************************************************************** -# Copyright (C) 2006 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::Usermgm; -use strict; -use warnings; -use ND::DB; -use NDIRC::Access; -require Exporter; - -our @ISA = qw/Exporter/; - -our @EXPORT = qw/addPoints/; - -sub addPoints { - my ($msg, $t) = @_; - - my ($nick, $points); - if(defined $msg && $msg =~ /^(\S+)(?: (-?(\d+)?(\.\d+)?))?$/){ - $nick = $1; - $points = $2; - }else{ - $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."); - return; - } - if ( ($t eq "d" && dc()) - || ($t eq "a" && bc()) - || ($t eq "h" && officer()) - || ($t eq "s" && scanner())){ - $points = 1 unless $points; - if ($points*$points > 400){ - $ND::server->command("msg $ND::target Values between -20 and 20 please"); - return; - } - my $f = $ND::DBH->prepare("SELECT uid,username FROM users WHERE username ILIKE ?"); - $f->execute($nick); - my @row = $f->fetchrow(); - if ($f->rows == 1){ - my $type = "defense"; - $type = "attack" if $t eq "a"; - $type = "humor" if $t eq "h"; - $type = "scan" if $t eq "s"; - 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]); - if ($t eq 'a' && $fleets > 0 && $points > 0){ - $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."); - return; - } - $type .= "_points"; - $ND::DBH->do("UPDATE users SET $type = $type + ? WHERE uid = ?",undef,$points,$row[0]); - $ND::server->command("msg $ND::target $row[1] has been given $points $type"); - }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; - - }else{ - $ND::server->command("msg $ND::target You don't have access for that"); - } -} - -1; diff --git a/database/roles.sql b/database/roles.sql index 465d0ae..d98dce6 100644 --- a/database/roles.sql +++ b/database/roles.sql @@ -20,6 +20,10 @@ INSERT INTO roles VALUES('irc_getships'); INSERT INTO roles VALUES('irc_getfleet'); INSERT INTO roles VALUES('irc_sethost'); INSERT INTO roles VALUES('irc_setpnick'); +INSERT INTO roles VALUES('irc_a'); +INSERT INTO roles VALUES('irc_d'); +INSERT INTO roles VALUES('irc_s'); +INSERT INTO roles VALUES('irc_h'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_nick'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_intel'); @@ -41,6 +45,10 @@ INSERT INTO group_roles (gid,role) VALUES(1,'irc_getships'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_getfleet'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_sethost'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_setpnick'); +INSERT INTO group_roles (gid,role) VALUES(1,'irc_a'); +INSERT INTO group_roles (gid,role) VALUES(1,'irc_d'); +INSERT INTO group_roles (gid,role) VALUES(1,'irc_s'); +INSERT INTO group_roles (gid,role) VALUES(1,'irc_h'); INSERT INTO group_roles (gid,role) VALUES(2,'irc_gs'); INSERT INTO group_roles (gid,role) VALUES(2,'irc_scan'); @@ -64,8 +72,13 @@ INSERT INTO group_roles (gid,role) VALUES(3,'irc_getships'); INSERT INTO group_roles (gid,role) VALUES(3,'irc_getfleet'); INSERT INTO group_roles (gid,role) VALUES(3,'irc_sethost'); INSERT INTO group_roles (gid,role) VALUES(3,'irc_setpnick'); +INSERT INTO group_roles (gid,role) VALUES(3,'irc_a'); +INSERT INTO group_roles (gid,role) VALUES(3,'irc_d'); +INSERT INTO group_roles (gid,role) VALUES(3,'irc_s'); +INSERT INTO group_roles (gid,role) VALUES(3,'irc_h'); INSERT INTO group_roles (gid,role) VALUES(4,'irc_points_others'); +INSERT INTO group_roles (gid,role) VALUES(4,'irc_a'); INSERT INTO group_roles (gid,role) VALUES(5,'irc_p_nick'); INSERT INTO group_roles (gid,role) VALUES(5,'irc_p_intel'); @@ -75,6 +88,7 @@ INSERT INTO group_roles (gid,role) VALUES(6,'irc_points_others'); INSERT INTO group_roles (gid,role) VALUES(6,'irc_sms'); INSERT INTO group_roles (gid,role) VALUES(6,'irc_getships'); INSERT INTO group_roles (gid,role) VALUES(6,'irc_getfleet'); +INSERT INTO group_roles (gid,role) VALUES(6,'irc_d'); INSERT INTO group_roles (gid,role) VALUES(8,'irc_scanreqs'); INSERT INTO group_roles (gid,role) VALUES(8,'irc_anonscan'); @@ -88,3 +102,4 @@ INSERT INTO group_roles (gid,role) VALUES(18,'irc_laston'); INSERT INTO group_roles (gid,role) VALUES(18,'irc_lastseen'); INSERT INTO group_roles (gid,role) VALUES(19,'irc_p_intel'); +INSERT INTO group_roles (gid,role) VALUES(19,'irc_h'); diff --git a/ndawn.pl b/ndawn.pl index 79165bd..594477e 100644 --- a/ndawn.pl +++ b/ndawn.pl @@ -58,7 +58,7 @@ my $disp = new NDIRC::Dispatcher; $disp->load('Basic','PA','Channel','Scans','Quotes','Members','Usermgm'); $ND::scanchan = '#testarmer'; -$disp->add_channel('#testarlite', ['pub','help','channel']); +$disp->add_channel('#testarlite', ['pub','help','channel','def']); $disp->add_channel($ND::scanchan, ['pub','help','channel','scan','member']); $disp->add_channel('pm', ['pub','help','pm']); -- 2.39.2