-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.");
- }
- }
- }
- }
-}