Skip to content

Commit

Permalink
more alliance fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and unknown committed Jun 26, 2012
1 parent 6c3502f commit 1f4b475
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 116 deletions.
125 changes: 75 additions & 50 deletions GameEngine/Alliance.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,43 +107,30 @@ public function procAlliForm($post) {
*****************************************/
public function sendInvite($post) {
global $form, $database, $session;
// ¿El campo posee informacion?
if(!isset($post['a_name']) || $post['a_name'] == "") {
$form->addError("name1", NAME_EMPTY);
}
// ¿Existe el usuario?
if(!$database->checkExist($post['a_name'], 0)) {
$form->addError("name2", NAME_NO_EXIST);
}
// ¿La invitacion es a si mismo?
if($post['a_name'] == ($session->username)) {
$form->addError("name3", SAME_NAME);
}
// ¿Esta ya invitado a la alianza?
$UserData = $database->getUserArray($post['a_name'], 0);
if($database->getInvitation($UserData['id'])) {
$form->addError("name4", OLRADY_INVITED);
}
// ¿Esta ya en la alianza?
if($session->access != BANNED){
$UserData = $database->getUserArray($post['a_name'], 0);
if($UserData['alliance'] == $session->alliance) {
$form->addError("name5", OLRADY_IN_ALLY);
}
// ¿La invitación la envia un autorizado?
if($this->userPermArray['opt4'] == 0) {
$form->addError("perm", NO_PERMISSION);
}
if($form->returnErrors() != 0) {
$_SESSION['errorarray'] = $form->getErrors();
$_SESSION['valuearray'] = $post;
print_r($form->getErrors());
} else {
}elseif(!isset($post['a_name']) || $post['a_name'] == "") {
$form->addError("name1", NAME_EMPTY);
}elseif(!$database->checkExist($post['a_name'], 0)) {
$form->addError("name2", NAME_NO_EXIST.$post['a_name']);
}elseif($post['a_name'] == (addslashes($session->username))) {
$form->addError("name3", SAME_NAME);
}elseif($database->getInvitation2($UserData['id'],$session->alliance)) {
$form->addError("name4", $post['a_name'].ALREADY_INVITED);
}elseif($UserData['alliance'] == $session->alliance) {
$form->addError("name5", $post['a_name'].ALREADY_IN_ALLY);
}else{
// Obtenemos la informacion necesaria
$aid = $session->alliance;
// Insertamos invitacion
$database->sendInvitation($UserData['id'], $aid, $session->uid);
// Log the notice
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid=' . $session->uid . '">' . $session->username . '</a> has invited <a href="spieler.php?uid=' . $UserData['id'] . '">' . $UserData['username'] . '</a> into the alliance.');
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid=' . $session->uid . '">' . addslashes($session->username) . '</a> has invited <a href="spieler.php?uid=' . $UserData['id'] . '">' . $UserData['username'] . '</a> into the alliance.');
}
}else{
header("Location: banned.php");
}
}

Expand All @@ -152,63 +139,79 @@ public function sendInvite($post) {
*****************************************/
private function rejectInvite($get) {
global $database, $session;
if($session->access != BANNED){
foreach($this->inviteArray as $invite) {
if($invite['id'] == $get['d']) {
$database->removeInvitation($get['d']);
$database->insertAlliNotice($invite['alliance'], '<a href="spieler.php?uid=' . $session->uid . '">' . $session->username . '</a> has rejected the invitation.');
$database->insertAlliNotice($invite['alliance'], '<a href="spieler.php?uid=' . $session->uid . '">' . addslashes($session->username) . '</a> has rejected the invitation.');
}
}
header("Location: build.php?id=".$get['id']);
}else{
header("Location: banned.php");
}
}

/*****************************************
Function to del an invitation
*****************************************/
private function delInvite($get) {
global $database, $session;
if($session->access != BANNED){
$inviteArray = $database->getAliInvitations($session->alliance);
foreach($inviteArray as $invite) {
if($invite['id'] == $get['d']) {
$invitename = $database->getUserArray($invite['uid'], 1);
$database->removeInvitation($get['d']);
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid=' . $session->uid . '">' . $session->username . '</a> has deleted the invitation for <a href="spieler.php?uid=' . $invitename['id'] . '">' . $invitename['username'] . '</a>.');
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid=' . $session->uid . '">' . addslashes($session->username) . '</a> has deleted the invitation for <a href="spieler.php?uid=' . $invitename['id'] . '">' . $invitename['username'] . '</a>.');
}
}
header("Location: allianz.php?delinvite");
}else{
header("Location: banned.php");
}
}

/*****************************************
Function to accept an invitation
*****************************************/
private function acceptInvite($get) {
global $form, $database, $session;
if($session->access != BANNED){
foreach($this->inviteArray as $invite) {
if($invite['id'] == $get['d']) {
if($session->alliance == 0){
if($invite['id'] == $get['d'] && $invite['uid'] == $session->uid) {
$memberlist = $database->getAllMember($invite['alliance']);
$alliance_info = $database->getAlliance($invite['alliance']);
if(count($memberlist) < $alliance_info['max']){
$database->removeInvitation($database->RemoveXSS($get['d']));
$database->updateUserField($database->RemoveXSS($invite['uid']), "alliance", $database->RemoveXSS($invite['alliance']), 1);
$database->createAlliPermissions($database->RemoveXSS($invite['uid']), $database->RemoveXSS($invite['alliance']), '', '0', '0', '0', '0', '0', '0', '0', '0');
// Log the notice
$database->insertAlliNotice($invite['alliance'], '<a href="spieler.php?uid=' . $session->uid . '">' . $session->username . '</a> has joined the alliance.');
$database->insertAlliNotice($invite['alliance'], '<a href="spieler.php?uid=' . $session->uid . '">' . addslashes($session->username) . '</a> has joined the alliance.');
}else{
$accept_error = 1;
$max = $alliance_info['max'];
}
}
}
}
if($accept_error == 1){
$form->addError("ally_accept", "The alliance can contain only ".$max." peoples right now.");
}else{
header("Location: build.php?id=" . $get['id']);
}
}else{
header("Location: banned.php");
}
}

/*****************************************
Function to create an alliance
*****************************************/
private function createAlliance($post) {
global $form, $database, $session, $bid18, $village;
if($session->access != BANNED){
if(!isset($post['ally1']) || $post['ally1'] == "") {
$form->addError("ally1", ATAG_EMPTY);
}
Expand All @@ -233,17 +236,20 @@ private function createAlliance($post) {
// Asign Permissions
$database->createAlliPermissions($database->RemoveXSS($session->uid), $database->RemoveXSS($aid), 'Alliance founder', '1', '1', '1', '1', '1', '1', '1', '1');
// log the notice
$database->insertAlliNotice($aid, 'The alliance has been founded by <a href="spieler.php?uid=' . $session->uid . '">' . $session->username . '</a>.');
$database->insertAlliNotice($aid, 'The alliance has been founded by <a href="spieler.php?uid=' . $session->uid . '">' . addslashes($session->username) . '</a>.');
header("Location: build.php?id=" . $post['id']);
}
}else{
header("Location: banned.php");
}
}

/*****************************************
Function to change the alliance name
*****************************************/
private function changeAliName($get) {
global $form, $database, $session;

if($session->access != BANNED){
if(!isset($get['ally1']) || $get['ally1'] == "") {
$form->addError("ally1", ATAG_EMPTY);
}
Expand All @@ -266,7 +272,10 @@ private function changeAliName($get) {
} else {
$database->setAlliName($database->RemoveXSS($session->alliance), $database->RemoveXSS($get['ally2']), $database->RemoveXSS($get['ally1']));
// log the notice
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid=' . $session->uid . '">' . $session->username . '</a> has changed the alliance name.');
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid=' . $session->uid . '">' . addslashes($session->username) . '</a> has changed the alliance name.');
}
}else{
header("Location: banned.php");
}
}

Expand All @@ -275,6 +284,7 @@ private function changeAliName($get) {
*****************************************/
private function updateAlliProfile($post) {
global $database, $session, $form;
if($session->access != BANNED){
if($this->userPermArray['opt3'] == 0) {
$form->addError("perm", NO_PERMISSION);
}
Expand All @@ -285,7 +295,10 @@ private function updateAlliProfile($post) {
} else {
$database->submitAlliProfile($database->RemoveXSS($session->alliance), $database->RemoveXSS($post['be2']), $database->RemoveXSS($post['be1']));
// log the notice
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid=' . $session->uid . '">' . $session->username . '</a> has changed the alliance description.');
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid=' . $session->uid . '">' . addslashes($session->username) . '</a> has changed the alliance description.');
}
}else{
header("Location: banned.php");
}
}

Expand All @@ -294,6 +307,7 @@ private function updateAlliProfile($post) {
*****************************************/
private function changeUserPermissions($post) {
global $database, $session, $form;
if($session->access != BANNED){
if($this->userPermArray['opt1'] == 0) {
$form->addError("perm", NO_PERMISSION);
}
Expand All @@ -304,47 +318,52 @@ private function changeUserPermissions($post) {
} else {
$database->updateAlliPermissions($post['a_user'], $session->alliance, $post['a_titel'], $post['e1'], $post['e2'], $post['e3'], $post['e4'], $post['e5'], $post['e6'], $post['e7']);
// log the notice
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid=' . $session->uid . '">' . $session->username . '</a> has changed permissions.');
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid=' . $session->uid . '">' . addslashes($session->username) . '</a> has changed permissions.');
}
}else{
header("Location: banned.php");
}

}
/*****************************************
Function to kick a user from alliance
*****************************************/
private function kickAlliUser($post) {
global $database, $session, $form;

if($session->access != BANNED){
$UserData = $database->getUserArray($post['a_user'], 0);
if($this->userPermArray['opt2'] == 0) {
$form->addError("perm", NO_PERMISSION);
}
if($form->returnErrors() != 0) {
$_SESSION['errorarray'] = $form->getErrors();
$_SESSION['valuearray'] = $post;
//header("Location: build.php?id=".$post['id']);
} else {
} else if($UserData['id'] != $session->uid){
$database->updateUserField($post['a_user'], 'alliance', 0, 1);
$database->deleteAlliPermissions($post['a_user']);
$database->deleteAlliance($session->alliance);
// log the notice
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid=' . $session->uid . '">' . $session->username . '</a> kicked <a href="spieler.php?uid=' . $post['a_user'] . '">' . $UserData['username'] . '</a>.');
//header("Location: build.php?id=".$post['id']);
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid=' . $UserData['id'] . '">' . $post['a_user'] . '</a> has quit the alliance.');
}
}else{
header("Location: banned.php");
}
}
/*****************************************
Function to set forum link
*****************************************/
public function setForumLink($post) {
global $database, $session;
if($session->access != BANNED){
if(isset($post['f_link'])){
$database->setAlliForumLink($session->alliance, $post['f_link']);
header("Location: allianz.php?s=5");
}else{
header("Location: banned.php");
}
}
}
/*****************************************
Function to quit from alliance
*****************************************/
private function quitally($post) {
global $database, $session, $form;
if($session->access != BANNED){
if(!isset($post['pw']) || $post['pw'] == "") {
$form->addError("pw1", PW_EMPTY);
} elseif(md5($post['pw']) !== $session->userinfo['password']) {
Expand All @@ -354,14 +373,17 @@ private function quitally($post) {
$database->deleteAlliPermissions($session->uid);
// log the notice
$database->deleteAlliance($session->alliance);
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid=' . $session->uid . '">' . $session->username . '</a> has quit the alliance.');
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid=' . $session->uid . '">' . addslashes($session->username) . '</a> has quit the alliance.');
header("Location: spieler.php?uid=".$session->uid);
}
}else{
header("Location: banned.php");
}
}

private function changediplomacy($post) {
global $database, $session, $form;

if($session->access != BANNED){
$aName = $database->RemoveXSS($_POST['a_name']);
$aType = (int)intval($_POST['dipl']);
if($database->aExist($aName, "tag")) {
Expand Down Expand Up @@ -391,6 +413,9 @@ private function changediplomacy($post) {
} else {
$form->addError("name", "Alliance does not exist");
}
}else{
header("Location: banned.php");
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions GameEngine/Database/db_MYSQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,12 @@ function getInvitation($uid) {
$result = mysql_query($q, $this->connection);
return $this->mysql_fetch_all($result);
}

function getInvitation2($uid, $aid) {
$q = "SELECT * FROM " . TB_PREFIX . "ali_invite where uid = $uid and alliance = $aid";
$result = mysql_query($q, $this->connection);
return $this->mysql_fetch_all($result);
}

function getAliInvitations($aid) {
$q = "SELECT * FROM " . TB_PREFIX . "ali_invite where alliance = $aid && accept = 0";
Expand Down
5 changes: 5 additions & 0 deletions GameEngine/Lang/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
define("ANAME_EXIST","Name taken");
define("NOT_OPENED_YET","Server not started yet.");
define("REGISTER_CLOSED","The register is closed. You can't register to this server.");
define("NAME_EMPTY","Please insert name");
define("NAME_NO_EXIST","There is no user with the name ");
define("SAME_NAME","You can't invite yourself");
define("ALREADY_INVITED"," already invited");
define("ALREADY_IN_ALLY"," already in this alliance");

//COPYRIGHT
define("TRAVIAN_COPYRIGHT","TravianZ 100% Open Source Travian Clone.");
Expand Down
10 changes: 2 additions & 8 deletions Templates/Alliance/allidesc.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ foreach($memberlist as $member) {
}

echo "<h1>".$allianceinfo['tag']." - ".$allianceinfo['name']."</h1>";
include("alli_menu.tpl");
if($session->access!=BANNED){
include("alli_menu.tpl");
?>
<table cellpadding="1" cellspacing="1" id="edit"><thead>
<form method="post" action="allianz.php">
Expand Down Expand Up @@ -134,9 +133,4 @@ INDELING CATEGORIEEN:
</table></p>
</table>

<p class="btn"><input tabindex="3" type="image" value="" name="s1" id="btn_save" class="dynamic_img" src="img/x.gif" alt="save" /></p></form>
<?php
}else{
header("Location: banned.php");
}
?>
<p class="btn"><input tabindex="3" type="image" value="" name="s1" id="btn_save" class="dynamic_img" src="img/x.gif" alt="save" /></p></form>
8 changes: 1 addition & 7 deletions Templates/Alliance/changename.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ $aid = $session->alliance;
$allianceinfo = $database->getAlliance($aid);
echo "<h1>".$allianceinfo['tag']." - ".$allianceinfo['name']."</h1>";
include("alli_menu.tpl");
if($session->access!=BANNED){
?>
<table cellpadding="1" cellspacing="1" cellpadding="1" cellspacing="1" id="name" class="small_option"><thead>
<form method="post" action="allianz.php">
Expand Down Expand Up @@ -36,9 +35,4 @@ if($session->access!=BANNED){
<p class="error3"><?php echo $form->getError("ally2"); ?></p>
<p class="error3"><?php echo $form->getError("owner"); ?></p>
<p class="error3"><?php echo $form->getError("tag"); ?></p>
<p class="error3"><?php echo $form->getError("name"); ?></p>
<?php
}else{
header("Location: banned.php");
}
?>
<p class="error3"><?php echo $form->getError("name"); ?></p>
8 changes: 1 addition & 7 deletions Templates/Alliance/chgdiplo.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
$allianceinfo = $database->getAlliance($aid);
echo "<h1>".$allianceinfo['tag']." - ".$allianceinfo['name']."</h1>";
include("alli_menu.tpl");
if($session->access!=BANNED){
?>
<form method="post" action="allianz.php">
<input type="hidden" name="a" value="6"> <input type="hidden" name="o" value="6"> <input type="hidden" name="s" value="5">
Expand Down Expand Up @@ -200,9 +199,4 @@

?>
</tbody>
</table>
<?php
}else{
header("Location: banned.php");
}
?>
</table>
Loading

0 comments on commit 1f4b475

Please sign in to comment.