Skip to content

Commit

Permalink
Fix #303 SQL error when joining a guild when your already in another …
Browse files Browse the repository at this point in the history
…guild
  • Loading branch information
Znote committed Mar 17, 2019
1 parent 32bbecd commit 44839d9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
12 changes: 10 additions & 2 deletions engine/function/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ function guild_player_join($cid, $gid) {
// Add to guild if rank id was found:
if ($rid != false) {
// Remove the invite:
guild_remove_invitation($cid, $gid);
//guild_remove_invitation($cid, $gid);
guild_remove_all_invitations($cid);
// Add to guild:
mysql_update("UPDATE `players` SET `rank_id`='$rid' WHERE `id`=$cid");
$status = true;
Expand All @@ -383,7 +384,8 @@ function guild_player_join($cid, $gid) {
if ($guildrank !== false) {
$rid = $guildrank['id'];
// Remove invite
guild_remove_invitation($cid, $gid);
//guild_remove_invitation($cid, $gid);
guild_remove_all_invitations($cid);
// Add to guild
mysql_insert("INSERT INTO `guild_membership` (`player_id`, `guild_id`, `rank_id`, `nick`) VALUES ('$cid', '$gid', '$rid', '');");
// Return success
Expand All @@ -400,6 +402,12 @@ function guild_remove_invitation($cid, $gid) {
mysql_delete("DELETE FROM `guild_invites` WHERE `player_id`='$cid' AND `guild_id`='$gid';");
}

// Remove ALL invitations
function guild_remove_all_invitations($cid) {
$cid = (int)$cid;
mysql_delete("DELETE FROM `guild_invites` WHERE `player_id`='$cid';");
}

// Invite character to guild
function guild_invite_player($cid, $gid) {
$cid = (int)$cid;
Expand Down
26 changes: 17 additions & 9 deletions guilds.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function guild_list($TFSVersion) {
<?php
} else { // GUILD OVERVIEW
$guild = get_guild_data($_GET['name']);
$gid = $guild['id'];
$gid = (int)$guild['id'];
if ($gid === false) {
header('Location: guilds.php');
exit();
Expand Down Expand Up @@ -358,16 +358,24 @@ function guild_list($TFSVersion) {
exit();
}
if (!empty($_POST['joinguild'])) {
//
$joining_player_id = (int)$_POST['joinguild'];
// Join a guild
foreach ($inv_data as $inv) {
if ($inv['player_id'] == $_POST['joinguild']) {
if ($config['ServerEngine'] !== 'TFS_10') $chardata = user_character_data($_POST['joinguild'], 'online');
else $chardata['online'] = (user_is_online_10($_POST['joinguild'])) ? 1 : 0;
if ((int)$inv['player_id'] == $joining_player_id) {
if ($config['ServerEngine'] !== 'TFS_10') $chardata = user_character_data($joining_player_id, 'online');
else $chardata['online'] = (user_is_online_10($joining_player_id)) ? 1 : 0;
if ($chardata['online'] == 0) {
if (guild_player_join($_POST['joinguild'], $gid)) {
header('Location: guilds.php?name='. $_GET['name']);
exit();
} else echo '<font color="red" size="4">Failed to find guild position representing member.</font>';
// Ensure player is not already a member of another guild
if (get_character_guild_rank($joining_player_id) === false) {
if (guild_player_join($joining_player_id, (int)$gid)) {
header('Location: guilds.php?name='. $_GET['name']);
exit();
} else echo '<font color="red" size="4">Failed to find guild position representing member.</font>';
} else {
$already_guild = get_player_guild_data($joining_player_id);
$already_guild_name = get_guild_name($already_guild['guild_id']);
echo "<font color='red' size='4'>You are already <strong>{$already_guild['rank_name']}</strong> of another guild: <strong><a href='guilds.php?name={$already_guild_name}'>{$already_guild_name}</a></strong>.<br>You need to leave that guild first before you can join another one.</font>";
}
} else echo '<font color="red" size="4">Character must be offline before joining guild.</font>';
}
}
Expand Down

0 comments on commit 44839d9

Please sign in to comment.