]> ruin.nu Git - ndwebbie.git/blobdiff - lib/NDWeb/Controller/Members.pm
Use FindBin and send USR1 to irssi
[ndwebbie.git] / lib / NDWeb / Controller / Members.pm
index 9373b8f58b77b230212cf16d3c9e62704518545d..6dcc1f67e5f3563fd440a23579f09ab9c63fd0f3 100644 (file)
@@ -32,7 +32,7 @@ sub index : Path : Args(0) {
        $c->stash(comma => \&comma_value);
        $c->stash(u => $dbh->selectrow_hashref(q{SELECT planet,defense_points
                        ,attack_points,scan_points,humor_points
-                       , (attack_points+defense_points+scan_points/20) as total_points
+                       , (attack_points+defense_points+scan_points/20)::NUMERIC(5,1) as total_points
                        , sms,rank,hostmask FROM users WHERE uid = ?
                        },undef,$c->user->id)
        );
@@ -145,6 +145,30 @@ sub postsmsupdate : Local {
        $c->res->redirect($c->uri_for(''));
 }
 
+sub postowncoords : Local {
+       my ( $self, $c ) = @_;
+       my $dbh = $c->model;
+
+       if ($c->user->planet){
+               $c->flash(error => 'You already have a planet set.'
+                       .' Contact a HC if they need to be changed');
+       }elsif ($c->req->param('planet') =~ m/(\d+)\D+(\d+)\D+(\d+)/){
+               my $planet = $dbh->selectrow_array(q{SELECT planetid($1,$2,$3,TICK())
+                       },undef,$1,$2,$3);
+
+               if ($planet){
+                       $dbh->do(q{UPDATE users SET planet = ? WHERE uid = ?
+                               },undef, $planet , $c->user->id);
+               }else{
+                       $c->flash(error => "No planet at coords: $1:$2:$3");
+               }
+       }else{
+               $c->flash(error => $c->req->param('planet') . " are not valid coords.");
+       }
+
+       $c->res->redirect($c->uri_for(''));
+}
+
 sub postfleetupdate : Local {
        my ( $self, $c ) = @_;
        my $dbh = $c->model;
@@ -225,12 +249,33 @@ sub postfleetsupdates : Local {
        $c->res->redirect($c->uri_for(''));
 }
 
+sub ircrequest : Local {
+       my ( $self, $c ) = @_;
+       my $dbh = $c->model;
+
+       $c->stash(reply => $c->flash->{reply});
+       $c->stash(channels => ['def','scan','members']);
+}
+
+sub postircrequest : Local {
+       my ( $self, $c ) = @_;
+       my $dbh = $c->model;
+
+       my $query = $dbh->prepare(q{INSERT INTO irc_requests
+               (uid,channel,message) VALUES($1,$2,$3)
+               });
+       $query->execute($c->user->id,$c->req->param('channel'),$c->req->param('message'));
+       system 'killall','-USR1', 'irssi';
+
+       $c->flash(reply => "Msg sent to: ".$c->req->param('channel'));
+       $c->res->redirect($c->uri_for('ircrequest'));
+}
 
 sub points : Local {
        my ( $self, $c, $order ) = @_;
        my $dbh = $c->model;
 
-       if ($order =~ /^((?:defense|attack|total|humor|scan|raid)_points)$/){
+       if ($order && $order =~ /^((?:defense|attack|total|humor|scan|raid)_points)$/){
                $order = "$1 DESC";
        }else{
                $order = 'total_points DESC';
@@ -241,7 +286,7 @@ sub points : Local {
 
        my $query = $dbh->prepare(qq{SELECT username,defense_points,attack_points
                ,scan_points,humor_points
-               ,(attack_points+defense_points+scan_points/20) as total_points
+               ,(attack_points+defense_points+scan_points/20)::NUMERIC(4,0) as total_points
                , count(NULLIF(rc.launched,FALSE)) AS raid_points
                FROM users u LEFT OUTER JOIN raid_claims rc USING (uid)
                WHERE uid IN (SELECT uid FROM groupmembers WHERE gid = 2)
@@ -397,7 +442,7 @@ sub postconfirmation : Local {
                        });
                my @missions;
                $dbh->begin_work;
-               while ($missions =~ m/([^\n]+)\s+(\d+):(\d+):(\d+)\s+(\d+):(\d+):(\d+)
+               while ($missions && $missions =~ m/([^\n]+)\s+(\d+):(\d+):(\d+)\s+(\d+):(\d+):(\d+)
                        \s+\((?:(\d+)\+)?(\d+)\).*?(?:\d+hrs\s+)?\d+mins?\s+
                        (Attack|Defend|Return|Fake\ Attack|Fake\ Defend)
                        (.*?)