X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Commands%2FDef.pm;h=89ceeee3f7ce30b34ec41e6d2e8df654e2a09466;hb=5e02deb33fbdb994d72da23e8de85e633ec6654c;hp=74d0aa8dd85de111414620e2510cbb2d2483e983;hpb=d40ac61049a226782476938747ce50f2da3d2d89;p=NDIRC.git diff --git a/Commands/Def.pm b/Commands/Def.pm index 74d0aa8..89ceeee 100644 --- a/Commands/Def.pm +++ b/Commands/Def.pm @@ -23,6 +23,8 @@ use strict; use warnings; use feature ':5.10'; +use CGI; + use Moose; use MooseX::MethodAttributes; @@ -79,5 +81,111 @@ ORDER BY c.landing_tick; .$c->nick." TO RESPOND"); } +sub settype + : Help(Usage: .settype incId type | or: .settyp callId X:Y:Z type | or: .settypeall callId type) + : Type(def) + : ACL(irc_settype) + : Alias(settypeall) +{ + my ($self,$c,$msg) = @_; + my $dbh = $c->model; + + my $query = q{ +SELECT i.id,call,shiptype, coords(x,y,z),c.landing_tick - tick() AS eta +FROM incomings i + JOIN current_planet_stats p ON i.sender = p.id + JOIN calls c ON i.call = c.id + }; + my $fleets; + my $type; + my $call; + + if ($self->name eq 'settypeall'){ + ($call,$type) = $msg =~ /^(\d+) (.*)$/ or die 'ARGS'; + + $fleets = $dbh->prepare($query . q{ +WHERE i.call = ? + }); + $fleets->execute($call); + }else{ + my ($id,$x,$y,$z,$t) = $msg =~ /^(\d+) (\d+):(\d+):(\d+) (.*)$/; + if (defined $id){ + $fleets = $dbh->prepare($query . q{ +WHERE i.call = ? AND p.id = planetid(?,?,?,tick()) + }); + $fleets->execute($id,$x,$y,$z); + }else{ + ($id,$t) = $msg =~ /^(\d+) (.*)$/ or die 'ARGS'; + $fleets = $dbh->prepare($query . q{ +WHERE i.id = ? + }); + $fleets->execute($id); + } + $type = $t; + } + + $type = CGI::escapeHTML($type); + $dbh->begin_work; + my $deflog = ''; + my $settype = $dbh->prepare(q{UPDATE incomings SET shiptype = ? WHERE id = ?}); + while (my $inc = $fleets->fetchrow_hashref){ + $call //= $inc->{call}; + if ($inc->{eta} < 0){ + $c->reply("This call is old. Did you use the call id instead of inc id by" + ." accident? You can use .settypeall callid to set the type on all incs" + ." in a call. Or use webbie if you really want to update this old call."); + $dbh->rollback; + return; + } + $settype->execute($type,$inc->{id}); + $deflog .= "Set fleet: [B]$inc->{id} [/B] to: [B]$type [/B]\n"; + $c->reply("Set fleet $inc->{id} from $inc->{coords} on call $call to $type (previously $inc->{shiptype})"); + } + if ($fleets->rows == 0){ + $c->reply("No matching fleets"); + $dbh->rollback; + }else{ + $c->def_log($call,$deflog); + $dbh->commit; + } +} + +sub calltake + : Help(Usage: .calltake callid | sets the dc. also markes as covered/ignored with .callcov and .callignore) + : Type(def) + : ACL(irc_calltake) + : Alias(qw/callcov callignore/) +{ + my ($self,$c,$msg) = @_; + my ($id) = $msg =~ /^(\d+)$/ or die 'ARGS'; + my $dbh = $c->model; + + my $extra = ''; + + given ($self->{name}){ + when('callignore'){ + $extra = ',covered = FALSE, open = FALSE' + } + when('callcov'){ + $extra = ',covered = TRUE, open = FALSE' + } + } + + $dbh->begin_work; + my $rows = $dbh->do(q{ +UPDATE calls SET dc = (SELECT uid FROM users WHERE hostmask ILIKE $1) + }. $extra .q{ +WHERE id = $2 + },undef,$c->host,$id); + if ($rows == 1){ + $c->reply("Marked call $id with ".$self->name); + $c->def_log($id , "Used: [B]".$self->name."[/B]"); + $dbh->commit; + }else{ + $c->reply("$id is not a valid call"); + $dbh->rollback; + } +} + 1;