+};
+
+command getfleet => {
+ help => q(Usage: .getfleet username | % can be used as wildcard, e.g. barr%),
+ acl => q(irc_getfleet)
+}, class extends NDIRC::Command {
+ method execute ($c,$msg) {
+ my ($nick) = $msg =~ /^(\S+)$/ or die 'ARGS';
+ my $dbh = $c->model;
+
+ my $f = $dbh->prepare(q{
+SELECT fs.ship, fs.amount, username
+FROM fleet_ships fs
+ JOIN (SELECT fid,username
+ FROM fleets f
+ JOIN users u USING (pid)
+ WHERE mission = 'Full fleet' AND name <> 'Unit'
+ AND username ILIKE $1
+ ORDER BY pid,tick DESC,fid DESC
+ LIMIT 1
+ ) f USING (fid)
+ORDER BY num
+ });
+ $f->execute($nick);
+ my $text;
+ my $username;
+ while (my $ship = $f->fetchrow_hashref){
+ unless (defined $username) {
+ $username = $ship->{username};
+ $text = "<b>$username</b> has: "
+ }
+ $text .= "$ship->{ship} $ship->{amount} ";
+ }
+ if ($text){
+ $c->reply($text);
+ }else{
+ $c->reply("Couldn't find any fleet for $nick");
+ }
+ }
+};
+
+command sethost => {
+ help => q(Usage: .sethost username [host] | if host isn't given then it resets to netgamers host),
+ acl => q(irc_sethost)
+}, class extends NDIRC::Command {
+ method execute ($c,$msg) {
+ my ($nick,$host) = $msg =~ /^(\S+)(?: (\S+))?$/ or die 'ARGS';
+ my $dbh = $c->model;
+
+ my $f = $dbh->prepare(q{
+SELECT uid,username,pnick,hostmask FROM users WHERE username ILIKE ?
+ });
+ $f->execute($nick);
+ my $user = $f->fetchrow_hashref;
+ if ($f->rows == 1){
+ $host //= "$user->{pnick}.users.netgamers.org";
+ eval{
+ $dbh->do(q{UPDATE users SET hostmask = ? WHERE uid = ?}
+ ,undef,$host,$user->{uid});
+ $c->reply("Updated <b>$user->{username}</b>'s host to: <b>$host</b>");
+ };
+ if($@){
+ if ($@ =~ /duplicate key value violates unique constraint/){
+ my ($username, $hostname) = $dbh->selectrow_array(q{
+SELECT username,hostmask FROM users WHERE hostmask = $1
+ },undef,$host);
+ $c->reply("<c04>Problem</c>, <b>$username</b> already uses host <b>$hostname</b>.");
+ }else{
+ die $@;
+ }
+ }
+ }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;