use warnings;
use feature ':5.10';
+use CGI;
+
use Moose;
use MooseX::MethodAttributes;
.$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;
+ }
+}
+
1;
$log->execute($c->host,$message,$planet);
}
+sub def_log {
+ my ($c,$call, $message) = @_;
+ my $log = $c->model->prepare(q{
+INSERT INTO forum_posts (ftid,uid,message) VALUES(
+ (SELECT ftid FROM calls WHERE id = $3)
+ ,(SELECT uid FROM users WHERE hostmask ILIKE $1),$2)
+ });
+ $log->execute($c->host,$message,$call);
+}
+
sub _build_roles {
my ($self) = @_;
our @ISA = qw/Exporter/;
-our @EXPORT = qw/showCall setType takeCall covCall ignoreCall
+our @EXPORT = qw/showCall takeCall covCall ignoreCall
setDefPrio setCalc getCalc/;
sub showCall {
}
}
-sub setType {
- my ($msg,$command) = @_;
- my ($type,$id,$x,$y,$z) = @_;
- if ($command eq 'settypeall'){
- if (defined $msg && $msg =~ /^(\d+) (.*)$/){
- $type = $2;
- $id = $1
- }else{
- $ND::server->command("notice $ND::nick Usage: $command callId type");
- return;
- }
- }else{
- if (defined $msg && $msg =~ /^(\d+) (\d+):(\d+):(\d+) (.*)$/){
- $type = $5;
- $id = $1;
- $x = $2;
- $y = $3;
- $z = $4;
- }elsif (defined $msg && $msg =~ /^(\d+) (.*)$/){
- $id = $1;
- $type = $2;
- }else{
- $ND::server->command("notice $ND::nick Usage: $command incId type | or: $command callId X:Y:Z type");
- return;
- }
- }
- if (my $user = dc()){
- my $fleet;
- my $query = qq{
- SELECT i.id,call,shiptype, coords(x,y,z),c.landing_tick - tick() FROM incomings i
- JOIN current_planet_stats p ON i.sender = p.id
- JOIN calls c ON i.call = c.id
- };
- if ($command eq 'settypeall'){
- $fleet = $ND::DBH->prepare(qq{
- $query
- WHERE i.call = ?
- });
- $fleet->execute($id);
- }elsif (defined $x){
- $fleet = $ND::DBH->prepare(qq{
- $query
- WHERE i.call = ? AND p.id = planetid(?,?,?,tick())
- });
- $fleet->execute($id,$x,$y,$z);
- }else{
- $fleet = $ND::DBH->prepare(qq{
- $query
- WHERE i.id = ?
- });
- $fleet->execute($id);
- }
- $type = escapeHTML($type);
- while (my ($id,$call,$oldtype,$coords,$tick) = $fleet->fetchrow()){
- if($ND::DBH->do(q{UPDATE incomings SET shiptype = ? WHERE id = ?},undef,$type,$id) == 1){
- def_log $user->{uid}, $call , "Set fleet: [B] $id [/B] to: [B] $type [/B]";
- $ND::server->command("msg $ND::target Set fleet from $coords on call $call to $type (previously $oldtype)");
- if ($tick < 0 && not (defined $x && $x eq 'call')){
- $ND::server->command("msg $ND::target 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.");
- }
- }
- }
- }
-}
sub takeCall {
my ($msg,$command) = @_;
my ($id);
INSERT INTO roles VALUES('irc_setchannel');
INSERT INTO roles VALUES('irc_anondef');
INSERT INTO roles VALUES('irc_defcall');
+INSERT INTO roles VALUES('irc_settype');
INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_nick');
INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_intel');
INSERT INTO group_roles (gid,role) VALUES(1,'irc_setchannel');
INSERT INTO group_roles (gid,role) VALUES(1,'irc_anondef');
INSERT INTO group_roles (gid,role) VALUES(1,'irc_defcall');
+INSERT INTO group_roles (gid,role) VALUES(1,'irc_settype');
INSERT INTO group_roles (gid,role) VALUES(2,'irc_gs');
INSERT INTO group_roles (gid,role) VALUES(2,'irc_scan');
INSERT INTO group_roles (gid,role) VALUES(3,'irc_setchannel');
INSERT INTO group_roles (gid,role) VALUES(3,'irc_anondef');
INSERT INTO group_roles (gid,role) VALUES(3,'irc_defcall');
+INSERT INTO group_roles (gid,role) VALUES(3,'irc_settype');
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(6,'irc_sethostile');
INSERT INTO group_roles (gid,role) VALUES(6,'irc_anondef');
INSERT INTO group_roles (gid,role) VALUES(6,'irc_defcall');
+INSERT INTO group_roles (gid,role) VALUES(6,'irc_settype');
INSERT INTO group_roles (gid,role) VALUES(8,'irc_scanreqs');
INSERT INTO group_roles (gid,role) VALUES(8,'irc_anonscan');