/war.php
PHP | 455 lines | 381 code | 26 blank | 48 comment | 85 complexity | cb9e662ac26ddf3d73bf7548aeecf89c MD5 | raw file
Possible License(s): AGPL-3.0, LGPL-2.1
- <?php
- /* war.php - Front-end code for the wars page
- *
- * 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/>.
- **/
- $artefact = "Fähnchen"; // werden wir sicherlich noch umbenennen
- require_once("php/base/user.inc.php");
- require_once("php/base.php");
- require_once("php/event.php");
- require_once("headers.php");
- /* $me->event_handler (true, $me->activevillageid, $gui);
- $me->activevillage->do_income (); */
- $me->activevillage->update_stamp ();
- require_once ("styles/php/base_design-".$_SESSION['theme'].".php");
- echo '<div id="contentbox">';
- require_once("blocked.php");
- $perms = $me->get_ally_perms ();
- if (!isset($_REQUEST['f']))
- $f = 0;
- else
- $f = (int)$_REQUEST['f'];
- function add_allies_msg ($aid1, $aid2)
- {
- $query = "update user set allymsgs=allymsgs+1 where aid in (".$aid1.", ".$aid2.")";
- log_debug ("Pimping ally msgs: ".$query);
- if (!mysql_query ($query))
- log_err ("Cannot update ally msg counter. Query: ".$query.", ".mysql_error ());
- else
- {
- if (!mysql_affected_rows ())
- log_err ("After updating ally msg counter no rows where affected. Query: ".$query);
- }
- }
- function save_ally_news ($aid1, $aid2, $type)
- {
- global $me;
- /* type-werte:
- * 20 : aid1 hat abgesagt
- * 21: aid1 hat aufgegeben
- * 22: aid1 hat die fähnchen geklaut
- * 23: zeit ist um
- jeweils gegenseite: + 4
- */
- $query = "insert into allyactions (aid1,aid2,uid1,uid2,stamp,type) values (".$aid1.", ".$aid2.", ".$me->uid.", NULL, now(), ".$type."), (".$aid2.", ".$aid1.", NULL, ".$me->uid.", now(), ".($type+4) .")";
- if (!mysql_query($query))
- {
- log_err("war.php: could not insert allynews when cancelling war: ".$query);
- }
- log_debug ("Cancel war: ". $query);
- }
- ?>
- <form action="war.php" method="POST" name="war">
- <div id="reiter">
- <table width="98%">
- <tr>
- <th><a href="war.php?f=3">Wer gegen wen</a></th>
- <th><a href="war.php?f=0">Aktuelle Kriege</a></th>
- <th><a href="war.php?f=1">Abgeschlossene Kriege</a></th>
- </tr>
- </table>
- </div><br><br>
- <div id="onecolumn">
- <?php
- if ($me->sat_by && $f != 3)
- echo "Als Sitter hast du nicht das Rechte, die Kriege der Allianz zu sehen. ";
- else
- {
- ?>
- <table width="98%">
- <tr>
- <?php if ($f == 0)
- echo '<h3>Aktuelle Kriege der eigenen Allianz</h3>
- ';
- else
- {
- if ($f == 3)
- echo '<h3>Wer gegen wen in '.WORLDTITLE.'</h3>';
- else
- echo '<h3>Abgeschlossene Kriege der eigenen Allianz</h3>
- ';
- }
- ?>
- </tr>
- <?php
- require_once("php/base/Flag.php");
- require_once("php/base/Krieg.php");
- require_once("php/war_functions.php");
- //erst mal alle buttons abfragen, die so gedrueckt worden sein koennten
- //zunaechst: moechte jemand einen krieg absagen?
- if (isset($_POST['cancel_war']) && ($perms & 16))
- {
- $tmp = explode ("_",$_POST['cancel_really']);
- $aid1 = (int)$tmp[0];
- $aid2 = (int)$tmp[1];
- if (count($tmp)== 2)
- {
- if ($perms & 16)
- {
- if ($aid1 == $me->aid)
- {
- $query = "update wars set over=30, causer=".$me->aid.", end_of_war=now() where aid1=".$aid1." and aid2=".$aid2;
- if (!mysql_query($query))
- {
- echo '<span id="bug">Problem beim Zurückziehen der Kriegserklärung..!</span>';
- log_err("war.php: could not cancel war: ".$query);
- }
- else
- {
- // Add ally reload diplomacy event
- $query = "update user set changed=changed,flags=flags|4 where aid in (".$aid1.",".$aid2.")";
- if (!$gamedb->query ($query))
- log_err ("Cannot add ally reload diplomacy flags after war abort. Query: ".$query.", ".$gamedb->error ());
- save_ally_news($aid1, $aid2, 20);
- add_allies_msg ($aid1, $aid2);
- }
- }
- }
- }
- else
- echo '<span id="bug">Du musst das Häkchen setzen, damit etwas passiert!</span>';
- }
- //moechte jemand ein faehnchen setzen?
- if (isset($_POST['place']) && ($perms & 16))
- {
- $to_delete_tmp = $_POST['setFlags'];
- $to_delete = explode("_",$to_delete_tmp);
- if (count($to_delete) == 2)
- {
- $aid1 = $to_delete[0];
- $aid2 = $to_delete[1];
- $player = $_POST['allyMembers'];
- foreach ($_POST['village'] as $village_key => $village)
- {
- if (strlen($village) > 0)
- {
- if (isset ($player[$village_key]))
- {
- $village = mysql_real_escape_string($village);
- $query = "select A.uid, A.villageid, A.outpost_of, A.x, A.y, A.name, B.aid,B.user from village as A, user as B where A.uid=".$player[$village_key]." and A.name='".$village."' AND A.uid=B.uid";
- if (!$res=mysql_query($query))
- echo "<span id=\"bug\">Fehler beim Auslesen der Dorfnamen...</span>";
- else
- {
- $i = 0;
- $all_villages = array();
- while ($row = mysql_fetch_array($res))
- {
- if (($row['aid']) != $me->aid)
- {
- echo "<span id=\"bug\">Dieser Spieler gehört nicht zu deiner Allianz!</span><br>";
- break;
- }
- $all_villages[] = $row;
- $i++;
- }
- if ($i == 0)
- echo "<span id=\"bug\">Kein Dorf mit diesem Namen zu diesem Spieler gefunden! </span><br>";
- if ($i > 1)
- {
- echo "<span id=\"bug\">Es wurden mehrere passende Dörfer gefunden, bitte wähle eines aus der Liste aus.</span><br>";
- echo "<table><tr><td>";
- foreach ($all_villages as $value=>$current_village)
- {
- if ($current_village['outpost_of'] == 0)
- echo "<input type=\"radio\" name=\"place_choice\" value=\"".$current_village['villageid']."_".$aid1."_".$aid2."\"> ".$current_village['user'] .": ".$current_village['name']." (".$current_village['x']." | ".$current_village['y'].")<br>";
- }
- echo "<input type=\"submit\" name=\"placeIt\" value=\"Mach es so\"></td></tr></table>";
- }
- if ($i == 1)
- {
- if ($all_villages[0]['outpost_of'] != 0)
- echo '<span id="bug">Du darfst in Außenposten keine Fähnchen platzieren, nur in Städten.</span>';
- else
- {
- //nun muss noch ueberprueft werden, ob in dieser Stadt schon ein fähnchen steht
- $query = "select A.villageid, B.over from war_flags as A, wars as B where A.aid1=B.aid1 AND A.aid2=B.aid2 AND A.villageid=".(int)$all_villages[0]['villageid']." AND B.over=0 AND A.aid1=".$aid1." AND A.aid2=".$aid2 ; //FIXME: insegsamt nur ein fähnchen pro dorf oder pro krieg? zur zeit:pro krieg
- if(!$res = mysql_query($query))
- echo '<span id="bug">Something strange happened here! </span>'.$query;
- else
- {
- while ($row = mysql_fetch_array($res))
- {
- $in_village = true;
- }
- if ($in_village == true)
- echo '<span id="bug">In diesem Dorf steht schon ein Fähnchen</span>';
- else
- {
- $query = "insert into war_flags (aid1,aid2, villageid,current_villageid) values (".$aid1.",".$aid2.",".(int)$all_villages[0]['villageid'].",".(int)$all_villages[0]['villageid'].")";
- if (!mysql_query($query))
- echo "<span id=\"bug\">Platzieren fehlgeschlagen".$query."</span>";
- else
- echo "<span id=\"plus\">Erfolgreich platziert</span><br>";
- }
- }
- }
- }
- }
- }
- }
- }
- }
- else
- echo '<span id="bug">Du musst das Häkchen setzen, damit etwas passiert!</span>';
- }
- //wurde eben aus einer auswahl an dörfern eines ausgewählt?
- if (isset($_POST['placeIt']) && ($perms & 16))
- {
- $tmp = explode("_", $_POST['place_choice']);
- if (count($tmp)==3)
- {
- $villageid=(int)$tmp[0];
- $aid1=(int)$tmp[1];
- $aid2 = (int)$tmp[2];
- $query = "select A.uid, A.outpost_of, B.aid from village as A, user as B where villageid=".$villageid. " and A.uid=B.uid ";
- if (!$res = mysql_query($query))
- echo "<span id=\"bug\">Fehler beim Überprüfen der Dorfdaten!</span>".$query."<br>";
- else
- {
- while ($row = mysql_fetch_array($res))
- {
- if (($row['aid']) != $me->aid)
- echo "<span id=\"bug\">Diese Stadt gehört nicht zu deiner Ally!</span>";
- else
- {
- $query = "select A.villageid, B.over from war_flags as A, wars as B where A.aid1=B.aid1 AND A.aid2=B.aid2 AND A.villageid=".$villageid." AND B.over=0 AND A.aid1=".$aid1." AND A.aid2=".$aid2 ; //FIXME: insegsamt nur ein fähnchen pro dorf oder pro krieg? Im Moment: pro Krieg
- if(!$res = mysql_query($query))
- echo '<span id="bug">Something strange happened here! </span>'.$query;
- else
- {
- while ($row = mysql_fetch_array($res))
- {
- $in_village = true;
- }
- if ($in_village == true)
- echo '<span id="bug">In diesem Dorf steht schon ein Fähnchen</span>';
- else
- {
- if ($row['outpost_of'] != 0)
- echo '<span id="bug">Du darfst in Außenposten keine Fähnchen platzieren, nur in Städten.</span>';
- else
- {
- $query = "insert into war_flags (aid1, aid2, villageid,current_villageid) values (".$aid1.", ".$aid2.", ". $villageid.", ".$villageid.")";
- if (!mysql_query($query))
- echo "<span id=\"bug\">Versuch fehlgeschlagen!</span><br>";
- else
- echo "<span id=\"plus\">Erfolgreich platziert</span><br>";
- }
- }
- }
- }
- }
- }
- }
- else
- echo 'span id="bug">Du musst das Häkchen setzen, damit etwas passiert!</span>';
- }
- //will eine der Parteien aufgeben?
- if (isset($_POST['assign']) && ($perms & 16))
- {
- $tmp = explode("_",$_POST['assign_what']);
- if (count ($tmp) == 2)
- {
- if ($me->aid == $tmp[0])
- $other_aid = (int)$tmp[1];
- else
- $other_aid = (int)$tmp[0];
- $query = "update wars set over=20, causer='".$me->aid."', end_of_war=now() where aid1=".(int)$tmp[0]." and aid2=".(int)$tmp[1];
- if (!mysql_query($query))
- {
- log_err("war.php: could not assing war: ".$query);
- echo "<span id=\"bug\">Aufgeben fehlgeschlagen!</span><br>";
- }
- else
- {
- $query = "select flag_score1, flag_score2 from wars where aid1=".(int)$tmp[0]." and aid2=".(int)$tmp[1];
- if (!$res = mysql_query($query))
- log_err("war.php. couldnt check worth of flags: ".$query);
- else
- {
- while ($row = mysql_fetch_array($res))
- {
- if ($other_aid == $tmp[0])
- // wenn die andere allianz aid1 ist, interessieren wir uns nur fuer flag score 2,
- //da die eigene allianz beim aufgeben keine punkte bekommt
- {
- $flag_score = $row['flag_score2'];
- $score_string = "score1";
- $not_score_string = "score2";
- }
- else
- //die andere allianz ist aid2. sie bekommt die flaggenpunkte gutgeschrieben.
- //die allianz, die aufgegeben hat, bekommt 0 Punkte - egal, wieviele Punkte sie schon gemacht hatte
- {
- $flag_score = $row['flag_score1'];
- $score_string = "score2";
- $not_score_string = "score1";
- }
- }
- $query = "update war_stats_tmp set ".$score_string."=".$score_string."+(".$flag_score."*3), ".$not_score_string."=0 where aid1=".(int)$tmp[0]." and aid2=".(int)$tmp[1];
- if (!mysql_query($query))
- log_err("war.php: Could not update war_stats: ". $query);
- // Add ally reload diplomacy event
- $query = "update user set changed=changed,flags=flags|4 where aid in (".$me->aid.",".$other_aid.")";
- if (!$gamedb->query ($query))
- log_err ("Cannot add ally reload diplomacy flags after diplomacy addition. Query: ".$query.", ".$gamedb->error ());
- calcStats($tmp[0],$tmp[1]);
- }
- save_ally_news($me->aid, $other_aid, 21);
- add_allies_msg ( $tmp[0], $tmp[1]);
- //abandonStats ($tmp[0], $tmp[1], $other_aid);
- }
- }
- else
- echo '<span id="bug">Du musst das Häkchen setzen, damit etwas passiert!</span>';
- }
- if ($f != 3)
- {
- if ($f == 0)
- $constraint = "=";
- else
- $constraint = ">=";
- //zunächst werden einmal alle aktuelle kriege aus der datenbank geholt
- $query = "select A.*, date_format(A.begin, \"%d.%c.%Y - %H:%i\") as startdate, time_to_sec(timediff(now(), A.begin)) as remainingTime,B.tag as tag1, C.tag as tag2, D.score1,D.score2 from wars A left join allies B on (A.aid1=B.aid) left join allies C on (A.aid2=C.aid) join war_stats_tmp D on (A.aid1=D.aid1 AND A.aid2=D.aid2) where (A.aid1=".$me->aid. " or A.aid2=".$me->aid.") AND over".$constraint.$f;
- if (!$res=mysql_query($query))
- echo "<span id=\"bug\">Datenbankfehler beim Auslesen der aktuellen Kriege!</span>";
- else
- {
- while ($row = mysql_fetch_array($res))
- {
- $aid1 = $row['aid1'];
- $aid2 = $row['aid2'];
- $tag1 = $row['tag1'];
- $tag2 = $row['tag2'];
- $begin = $row['begin'];
- $remainingTime = $row['remainingTime'];
- $over = $row['over'];
- $causer = $row['causer'];
- $flag_score1 = $row['flag_score1'];
- $flag_score2 = $row['flag_score2'];
- $score1 = $row['score1'];
- $score2 = $row['score2'];
- //hat die eigene allianz den krieg angezettelt?
- if (($row['aid1']) == $me->aid)
- $beginner = true;
- else
- $beginner = false;
- $niceRemainingTime = $row['startdate'];
- $all_wars[] = new Krieg($aid1, $aid2, $beginner, $tag1, $tag2, $begin, $remainingTime,$over, $causer, $niceRemainingTime, $flag_score1, $flag_score2, $me->aid, $score1, $score2);
- }
- if (!isset($all_wars))
- {
- if ($f == 0)
- $output = "Deine Allianz befindet sich derzeit nicht im Krieg";
- else
- $output = "Deine Allianz hat in den letzten " . WAR_COOLDOWN . " Tagen keine Kriege beendet";
- echo "<span id=\"bug\">".$output."</span>";
- }
- else
- {
- //jetzt suchen wir uns zu jedem der Kriege die passenden Fähnchen raus
- //wir iterieren über alle Kriegobjekte
- $count = 1;
- foreach ($all_wars as $current_war=>$obj)
- {
- $obj->setLimit();
- $obj->getFlags($me->aid);
- $obj->setTitle();
- $obj->setLine();
- $obj->setBegin();
- $obj->setLine();
- $gui->displayedtimers++;
- $obj->setLimitInfo($perms, $me->aid, $gui->displayedtimers);
- $obj->setLine();
- $obj->setOwnFlagInfo($perms, $me->aid);
- $obj->setLine();
- $obj->setForeignFlagInfo($me->aid);
- $obj->setLine();
- $obj->setScoreForm();
- $obj->setLine();
- $obj->setAssignmentForm($perms,$me->aid);
- $obj->setLine();
- $obj->setWarState();
- echo "</table>";
- $count ++;
- }
- }
- }
- }
- else // alle Kriege dieser Welt anzeigen
- {
- $query = "select A.*, date_format(A.begin, \"%d.%c.%Y - %H:%i\") as startdate, time_to_sec(timediff(now(), A.begin)) as remainingTime,B.tag as tag1, C.tag as tag2, D.score1,D.score2 from wars A join allies B on (A.aid1=B.aid) join allies C on (A.aid2=C.aid) join war_stats_tmp D on (A.aid1=D.aid1 AND A.aid2=D.aid2) AND over = 0";
- if ($res = mysql_query($query))
- {
- while ($row = mysql_fetch_array($res))
- {
- $display = true;
- echo '<img src="gfx/axe2.gif" height="20px">';
- echo '<b><a href="allianz.php?a='.$row['aid1'].'">'.$row['tag1'].'</a> vs
- <a href="allianz.php?a='.$row['aid2'].'">'.$row['tag2'].'</a></b>
- (Zwischenstand: '.$row['score1'].' Punkte / '.$row['score2'].' Punkte)<br><br>';
- }
- }
- if (!$display)
- echo '<span id="bug">Zur Zeit finden in dieser Welt keine Kriege statt.</span>';
- }
- }
- echo '</table>';
- echo '</div></div>';
- require_once("footer.php");
- ?>