Source

Selador / brain / clear-wars.php

<?php

/* clear-wars.php - Back-end code for clearing wars after they expire
 *
 * Copyright (C) 2006, 2007, 2008 Kevin Read, Simone Schaefer
 *
 * This file is part of Selador, a browser-based fantasy strategy game
 *
 * This program is distributed under the terms of the GNU Affero General Public License.
 *
 *
 *   Selador is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   any later version.
 *
 *   Selador is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with Selador.  If not, see <http://www.gnu.org/licenses/>.
 **/

// Called by a cron job.

// This should be solved differently.

require_once ("config.inc.php");

// DB-Initialisierung
$dblink=mysql_pconnect ('localhost', DB_USER, DB_PASS);
mysql_select_db (DB_NAME);

$query = 'select distinct B.aid1,B.aid2 from allyactions A, wars B where A.aid1=B.aid1 and A.aid2=B.aid2 and A.type in (20,21,22,23,24,25,26) and B.over>0 and date_add(B.end_of_war, interval ' . WAR_COOLDOWN . ' hour)<now();';

if (!($res = mysql_query ($query)))
  echo "bah: ".$query.", ".mysql_error ();
else
{
  while ($row = mysql_fetch_array ($res))
  {
    $query = 'delete from wars where aid1='.$row['aid1'].' and aid2='.$row['aid2'];

    if (!mysql_query ($query))
      echo "bah: ".$query.", ".mysql_error ();
    else
    {
      $query = 'delete from war_flags where aid1='.$row['aid1'].' and aid2='.$row['aid2'];

      if (!mysql_query ($query))
        echo "bah: ".$query.", ".mysql_error ();
      else
      {
        $query = 'delete from war_stats_tmp where aid1='.$row['aid1'].' and aid2='.$row['aid2'];

        if (!mysql_query ($query))
          echo "bah: ".$query.", ".mysql_error ();
      }
    }
  }
}

?>