mirror of
https://github.com/Znote/ZnoteAAC.git
synced 2025-05-04 13:19:20 +02:00
guilds.php cleanup
This commit is contained in:
parent
1701d48629
commit
2ec9cfbff4
@ -1,6 +1,14 @@
|
||||
ZnoteAAC
|
||||
========
|
||||
[](https://www.codefactor.io/repository/github/znote/znoteaac)
|
||||
### Branch: v2
|
||||
The purpose of this branch is to server as code cleanup, and strip distro compatibility for anything below TFS 1.4.
|
||||
I want to refactor some code, try to get Znote AAC a bit more lightweight. Remove single-use functions from globally included function files etc.
|
||||
|
||||
New features and bugfixes might arrive here first, and then backported to 1.5/6 (master branch).
|
||||
|
||||
---
|
||||
|
||||
### What is Znote AAC?
|
||||
|
||||
Znote AAC is a full-fledged website used together with an Open Tibia(OT) server.
|
||||
|
@ -422,10 +422,8 @@ function output_errors($errors) {
|
||||
return '<ul><li>'. implode('</li><li>', $errors) .'</li></ul>';
|
||||
}
|
||||
|
||||
// Resize images
|
||||
|
||||
// Resize images and create image
|
||||
function resize_imagex($file, $width, $height) {
|
||||
|
||||
list($w, $h) = getimagesize($file['tmp']);
|
||||
|
||||
$ratio = max($width/$w, $height/$h);
|
||||
@ -443,7 +441,8 @@ function resize_imagex($file, $width, $height) {
|
||||
0, 0,
|
||||
$x, 0,
|
||||
$width, $height,
|
||||
$w, $h);
|
||||
$w, $h
|
||||
);
|
||||
|
||||
imagegif($tmp, $path);
|
||||
imagedestroy($image);
|
||||
@ -452,71 +451,43 @@ function resize_imagex($file, $width, $height) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Guild logo upload security
|
||||
// Validate guild logo
|
||||
function check_image($image) {
|
||||
$image_data = array(
|
||||
'new_name' => $_GET['name'].'.gif',
|
||||
'name' => $image['name'],
|
||||
'tmp' => $image['tmp_name'],
|
||||
'error' => $image['error'],
|
||||
'size' => $image['size'],
|
||||
'type' => $image['type']
|
||||
);
|
||||
|
||||
$image_data = array('new_name' => $_GET['name'].'.gif', 'name' => $image['name'], 'tmp' => $image['tmp_name'], 'error' => $image['error'], 'size' => $image['size'], 'type' => $image['type']);
|
||||
if ($image_data['type'] !== 'image/gif') {
|
||||
header('Location: guilds.php?error=Only gif images are accepted, you uploaded:['.$image_data['type'].'].&name='. $_GET['name']);
|
||||
exit();
|
||||
}
|
||||
|
||||
// First security check, quite useless but still do its job
|
||||
if ($image_data['type'] === 'image/gif') {
|
||||
|
||||
// Second security check, lets go
|
||||
$check = getimagesize($image_data['tmp']);
|
||||
|
||||
if ($check) {
|
||||
|
||||
// Third
|
||||
if ($check['mime'] === 'image/gif') {
|
||||
|
||||
$path_info = pathinfo($image_data['name']);
|
||||
|
||||
// Last one
|
||||
if ($path_info['extension'] === 'gif') {
|
||||
|
||||
// Resize image
|
||||
$img = resize_imagex($image_data, 100, 100);
|
||||
|
||||
if ($img) {
|
||||
|
||||
header('Location: guilds.php?name='. $_GET['name']);
|
||||
exit();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
header('Location: guilds.php?error=Only gif images accepted, you uploaded:['.$path_info['extension'].'].&name='. $_GET['name']);
|
||||
exit();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
header('Location: guilds.php?error=Only gif images accepted, you uploaded:['.$check['mime'].'].&name='. $_GET['name']);
|
||||
exit();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (!$check) {
|
||||
header('Location: guilds.php?error=Uploaded image is invalid.&name='. $_GET['name']);
|
||||
exit();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
header('Location: guilds.php?error=Only gif images are accepted, you uploaded:['.$image_data['type'].'].&name='. $_GET['name']);
|
||||
if ($check['mime'] !== 'image/gif') {
|
||||
header('Location: guilds.php?error=Only gif images accepted, you uploaded:['.$check['mime'].'].&name='. $_GET['name']);
|
||||
exit();
|
||||
}
|
||||
|
||||
$path_info = pathinfo($image_data['name']);
|
||||
if ($path_info['extension'] !== 'gif') {
|
||||
header('Location: guilds.php?error=Only gif images accepted, you uploaded:['.$path_info['extension'].'].&name='. $_GET['name']);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Check guild logo
|
||||
function logo_exists($guild) {
|
||||
$guild = sanitize($guild);
|
||||
if (file_exists('engine/guildimg/'.$guild.'.gif')) {
|
||||
|
||||
echo'engine/guildimg/'.$guild.'.gif';
|
||||
|
||||
} else {
|
||||
|
||||
echo'engine/guildimg/default@logo.gif';
|
||||
// Resize image
|
||||
if (resize_imagex($image_data, 100, 100)) {
|
||||
header('Location: guilds.php?name='. $_GET['name']);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -250,62 +250,6 @@ function guild_remove_member_10($cid) {
|
||||
mysql_update("DELETE FROM `guild_membership` WHERE `player_id`='$cid' LIMIT 1;");
|
||||
}
|
||||
|
||||
// Change guild rank name.
|
||||
function guild_change_rank($rid, $name) {
|
||||
$rid = (int)$rid;
|
||||
$name = sanitize($name);
|
||||
|
||||
mysql_update("UPDATE `guild_ranks` SET `name`='$name' WHERE `id`=$rid");
|
||||
}
|
||||
|
||||
// Change guild leader (parameters: cid, new and old leader).
|
||||
function guild_change_leader($nCid, $oCid) {
|
||||
$nCid = (int)$nCid;
|
||||
$oCid = (int)$oCid;
|
||||
$gid = guild_leader_gid($oCid);
|
||||
$ranks = get_guild_rank_data($gid);
|
||||
$leader_rid = 0;
|
||||
$vice_rid = 0;
|
||||
|
||||
|
||||
// Get rank id for leader and vice leader.
|
||||
foreach ($ranks as $rank) {
|
||||
if ($rank['level'] == 3) $leader_rid = $rank['id'];
|
||||
if ($rank['level'] == 2) $vice_rid = $rank['id'];
|
||||
}
|
||||
|
||||
$status = false;
|
||||
if ($leader_rid > 0 && $vice_rid > 0) $status = true;
|
||||
|
||||
// Verify that we found the rank ids for vice leader and leader.
|
||||
if ($status) {
|
||||
|
||||
// Update players and set their new rank id
|
||||
if (config('ServerEngine') !== 'TFS_10') {
|
||||
mysql_update("UPDATE `players` SET `rank_id`='$leader_rid' WHERE `id`=$nCid LIMIT 1;");
|
||||
mysql_update("UPDATE `players` SET `rank_id`='$vice_rid' WHERE `id`=$oCid LIMIT 1;");
|
||||
} else {
|
||||
mysql_update("UPDATE `guild_membership` SET `rank_id`='$leader_rid' WHERE `player_id`=$nCid LIMIT 1;");
|
||||
mysql_update("UPDATE `guild_membership` SET `rank_id`='$vice_rid' WHERE `player_id`=$oCid LIMIT 1;");
|
||||
}
|
||||
|
||||
// Update guilds set new ownerid
|
||||
guild_new_leader($nCid, $gid);
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
// Changes leadership of aguild to player_id
|
||||
function guild_new_leader($new_leader, $gid) {
|
||||
$new_leader = (int)$new_leader;
|
||||
$gid = (int)$gid;
|
||||
if (config('ServerEngine') !== 'OTHIRE')
|
||||
mysql_update("UPDATE `guilds` SET `ownerid`='$new_leader' WHERE `id`=$gid");
|
||||
else
|
||||
mysql_update("UPDATE `guilds` SET `owner_id`='$new_leader' WHERE `id`=$gid");
|
||||
}
|
||||
|
||||
// Returns $gid of a guild leader($cid).
|
||||
function guild_leader_gid($leader) {
|
||||
$leader = (int)$leader;
|
||||
@ -326,158 +270,12 @@ function guild_leader($gid) {
|
||||
return ($data !== false) ? $data['ownerid'] : false;
|
||||
}
|
||||
|
||||
// Disband guild
|
||||
function guild_remove_invites($gid) {
|
||||
$gid = (int)$gid;
|
||||
mysql_delete("DELETE FROM `guild_invites` WHERE `guild_id`='$gid';");
|
||||
}
|
||||
|
||||
// Remove guild invites
|
||||
function guild_delete($gid) {
|
||||
$gid = (int)$gid;
|
||||
mysql_delete("DELETE FROM `guilds` WHERE `id`='$gid';");
|
||||
}
|
||||
|
||||
// Player leave guild
|
||||
function guild_player_leave($cid) {
|
||||
$cid = (int)$cid;
|
||||
mysql_update("UPDATE `players` SET `rank_id`='0', `guildnick`= NULL WHERE `id`=$cid LIMIT 1;");
|
||||
}
|
||||
function guild_player_leave_10($cid) {
|
||||
$cid = (int)$cid;
|
||||
mysql_delete("DELETE FROM `guild_membership` WHERE `player_id`='$cid' LIMIT 1;");
|
||||
}
|
||||
|
||||
// Player join guild
|
||||
function guild_player_join($cid, $gid) {
|
||||
$cid = (int)$cid;
|
||||
$gid = (int)$gid;
|
||||
// Create a status we can return depending on results.
|
||||
$status = false;
|
||||
|
||||
if (config('ServerEngine') !== 'TFS_10') {
|
||||
// Get rank data
|
||||
$ranks = get_guild_rank_data($gid);
|
||||
// Locate rank id for regular member position in this guild
|
||||
$rid = false;
|
||||
foreach ($ranks as $rank) {
|
||||
if ($rank['level'] == 1) $rid = $rank['id'];
|
||||
}
|
||||
// Add to guild if rank id was found:
|
||||
if ($rid != false) {
|
||||
// Remove the invite:
|
||||
//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;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Find rank id for regular member in this guild
|
||||
$guildrank = mysql_select_single("SELECT `id` FROM `guild_ranks` WHERE `guild_id`='$gid' AND `level`='1' LIMIT 1;");
|
||||
if ($guildrank !== false) {
|
||||
$rid = $guildrank['id'];
|
||||
// Remove invite
|
||||
//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
|
||||
return true;
|
||||
} return false;
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
// Remove cid invitation from guild (gid)
|
||||
function guild_remove_invitation($cid, $gid) {
|
||||
$cid = (int)$cid;
|
||||
$gid = (int)$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;
|
||||
$gid = (int)$gid;
|
||||
mysql_insert("INSERT INTO `guild_invites` (`player_id`, `guild_id`) VALUES ('$cid', '$gid')");
|
||||
}
|
||||
|
||||
// Gets a list of invited players to a particular guild.
|
||||
function guild_invite_list($gid) {
|
||||
$gid = (int)$gid;
|
||||
return mysql_select_multi("SELECT `gi`.`player_id`, `gi`.`guild_id`, `p`.`name` FROM `guild_invites` AS `gi` INNER JOIN `players` AS `p` ON `gi`.`player_id`=`p`.`id` WHERE `gi`.`guild_id`='$gid';");
|
||||
}
|
||||
|
||||
// Update player's guild position
|
||||
function update_player_guild_position($cid, $rid) {
|
||||
$cid = (int)$cid;
|
||||
$rid = (int)$rid;
|
||||
mysql_update("UPDATE `players` SET `rank_id`='$rid' WHERE `id`=$cid");
|
||||
}
|
||||
function update_player_guild_position_10($cid, $rid) {
|
||||
$cid = (int)$cid;
|
||||
$rid = (int)$rid;
|
||||
mysql_update("UPDATE `guild_membership` SET `rank_id`='$rid' WHERE `player_id`=$cid");
|
||||
}
|
||||
|
||||
// Update player's guild nick
|
||||
function update_player_guildnick($cid, $nick) {
|
||||
$cid = (int)$cid;
|
||||
$nick = sanitize($nick);
|
||||
if (!empty($nick)) {
|
||||
mysql_update("UPDATE `players` SET `guildnick`='$nick' WHERE `id`=$cid");
|
||||
} else {
|
||||
mysql_update("UPDATE `players` SET `guildnick`='' WHERE `id`=$cid");
|
||||
}
|
||||
}
|
||||
function update_player_guildnick_10($cid, $nick) {
|
||||
$cid = (int)$cid;
|
||||
$nick = sanitize($nick);
|
||||
if (!empty($nick)) {
|
||||
mysql_update("UPDATE `guild_membership` SET `nick`='$nick' WHERE `player_id`=$cid");
|
||||
} else {
|
||||
mysql_update("UPDATE `guild_membership` SET `nick`='' WHERE `player_id`=$cid");
|
||||
}
|
||||
}
|
||||
|
||||
// Get guild data, using guild id.
|
||||
function get_guild_rank_data($gid) {
|
||||
$gid = (int)$gid;
|
||||
return mysql_select_multi("SELECT `id`, `guild_id`, `name`, `level` FROM `guild_ranks` WHERE `guild_id`='$gid' ORDER BY `id` DESC LIMIT 0, 30");
|
||||
}
|
||||
|
||||
// Creates a guild, where cid is the owner of the guild, and name is the name of guild.
|
||||
function create_guild($cid, $name) {
|
||||
$cid = (int)$cid;
|
||||
$name = sanitize($name);
|
||||
$time = time();
|
||||
|
||||
// Create the guild
|
||||
if (config('ServerEngine') !== 'OTHIRE')
|
||||
mysql_insert("INSERT INTO `guilds` (`name`, `ownerid`, `creationdata`, `motd`) VALUES ('$name', '$cid', '$time', '');");
|
||||
else
|
||||
mysql_insert("INSERT INTO `guilds` (`name`, `owner_id`, `creationdate`) VALUES ('$name', '$cid', '$time');");
|
||||
|
||||
// Get guild id
|
||||
$gid = get_guild_id($name);
|
||||
|
||||
// Get rank id for guild leader
|
||||
$data = mysql_select_single("SELECT `id` FROM `guild_ranks` WHERE `guild_id`='$gid' AND `level`='3' LIMIT 1;");
|
||||
$rid = ($data !== false) ? $data['id'] : false;
|
||||
|
||||
// Give player rank id for leader of his guild
|
||||
if (config('ServerEngine') !== 'TFS_10') mysql_update("UPDATE `players` SET `rank_id`='$rid' WHERE `id`='$cid' LIMIT 1;");
|
||||
else mysql_insert("INSERT INTO `guild_membership` (`player_id`, `guild_id`, `rank_id`, `nick`) VALUES ('$cid', '$gid', '$rid', '');");
|
||||
}
|
||||
|
||||
// Search player table on cid for his rank_id, returns rank_id
|
||||
function get_character_guild_rank($cid) {
|
||||
$cid = (int)$cid;
|
||||
@ -497,13 +295,6 @@ function get_player_guild_rank($rank_id) {
|
||||
return ($data !== false) ? $data['name'] : false;
|
||||
}
|
||||
|
||||
// Get a player guild position ID, using his rank_id
|
||||
function get_guild_position($rid) {
|
||||
$rid = (int)$rid;
|
||||
$data = mysql_select_single("SELECT `level` FROM `guild_ranks` WHERE `id`=$rid;");
|
||||
return ($data !== false) ? $data['level'] : false;
|
||||
}
|
||||
|
||||
// Get a players rank_id, guild_id, rank_level(ID), rank_name(string), using cid(player id)
|
||||
function get_player_guild_data($cid) {
|
||||
$cid = (int)$cid;
|
||||
@ -522,7 +313,7 @@ function get_player_guild_data($cid) {
|
||||
// Returns guild name of guild id
|
||||
function get_guild_name($gid) {
|
||||
$gid = (int)$gid;
|
||||
$guild = mysql_select_single("SELECT `name` FROM `guilds` WHERE `id`=$gid LIMIT 1;");
|
||||
$guild = mysql_select_single("SELECT `name` FROM `guilds` WHERE `id`={$gid} LIMIT 1;");
|
||||
if ($guild !== false) return $guild['name'];
|
||||
else return false;
|
||||
}
|
||||
@ -530,7 +321,7 @@ function get_guild_name($gid) {
|
||||
// Returns guild id from name
|
||||
function get_guild_id($name) {
|
||||
$name = sanitize($name);
|
||||
$data = mysql_select_single("SELECT `id` FROM `guilds` WHERE `name`='$name';");
|
||||
$data = mysql_select_single("SELECT `id` FROM `guilds` WHERE `name`='{$name}';");
|
||||
return ($data !== false) ? $data['id'] : false;
|
||||
}
|
||||
|
||||
@ -573,18 +364,6 @@ function get_guild_level_data($gid) {
|
||||
} else return false;
|
||||
}
|
||||
|
||||
// Returns total members in a guild (integer)
|
||||
function count_guild_members($gid) {
|
||||
$gid = (int)$gid;
|
||||
if (config('ServerEngine') !== 'TFS_10') {
|
||||
$data = mysql_select_single("SELECT COUNT(p.id) AS total FROM players AS p LEFT JOIN guild_ranks AS gr ON gr.id = p.rank_id WHERE gr.guild_id =$gid");
|
||||
return ($data !== false) ? $data['total'] : false;
|
||||
} else {
|
||||
$data = mysql_select_single("SELECT COUNT('guild_id') AS `total` FROM `guild_membership` WHERE `guild_id`='$gid';");
|
||||
return ($data !== false) ? $data['total'] : false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// GUILD WAR
|
||||
//
|
||||
@ -1736,33 +1515,4 @@ function user_logged_in() {
|
||||
return (getSession('user_id') !== false) ? true : false;
|
||||
}
|
||||
|
||||
function guild_war_invitation($cid, $gid) {
|
||||
$cid = (int)$cid;
|
||||
$gid = (int)$gid;
|
||||
$gname = get_guild_name($cid);
|
||||
$ename = get_guild_name($gid);
|
||||
$time = time();
|
||||
mysql_insert("INSERT INTO `guild_wars` (`guild1`, `guild2`, `name1`, `name2`, `status`, `started`, `ended`) VALUES ('$cid', '$gid', '$gname', '$ename', '0', '$time', '0');");
|
||||
}
|
||||
|
||||
function accept_war_invitation($cid, $gid) {
|
||||
$cid = (int)$cid;
|
||||
$gid = (int)$gid;
|
||||
mysql_update("UPDATE `guild_wars` SET `status` = 1 WHERE `guild1` = '$cid' AND `guild2` = '$gid' AND `status` = 0;");
|
||||
}
|
||||
|
||||
function reject_war_invitation($cid, $gid) {
|
||||
$cid = (int)$cid;
|
||||
$gid = (int)$gid;
|
||||
$time = time();
|
||||
mysql_update("UPDATE `guild_wars` SET `status` = 2, `ended` = '$time' WHERE `guild1` = '$cid' AND `guild2` = '$gid';");
|
||||
}
|
||||
|
||||
function cancel_war_invitation($cid, $gid) {
|
||||
$cid = (int)$cid;
|
||||
$gid = (int)$gid;
|
||||
$time = time();
|
||||
mysql_update("UPDATE `guild_wars` SET `status` = 3, `ended` = '$time' WHERE `guild2` = '$cid' AND `guild1` = '$gid';");
|
||||
}
|
||||
|
||||
?>
|
||||
|
544
guilds.php
544
guilds.php
@ -1,17 +1,24 @@
|
||||
<?php require_once 'engine/init.php';
|
||||
if ($config['require_login']['guilds']) protect_page();
|
||||
$isOtx = ($config['CustomVersion'] == 'OTX') ? true : false;
|
||||
|
||||
// These functions are page-specific and only used in this file.
|
||||
function guild_list($TFSVersion) {
|
||||
$cache = new Cache('engine/cache/guildlist');
|
||||
if ($cache->hasExpired()) {
|
||||
if ($TFSVersion != 'TFS_10')
|
||||
if ($TFSVersion === 'OTHIRE')
|
||||
$guilds = mysql_select_multi("SELECT `t`.`id`, `t`.`name`, `t`.`creationdate`, (SELECT count(p.rank_id) FROM players AS p LEFT JOIN guild_ranks AS gr ON gr.id = p.rank_id WHERE gr.guild_id =`t`.`id`) AS `total` FROM `guilds` as `t` ORDER BY `t`.`name`;");
|
||||
else
|
||||
$guilds = mysql_select_multi("SELECT `t`.`id`, `t`.`name`, `t`.`creationdata`, `motd`, (SELECT count(p.rank_id) FROM players AS p LEFT JOIN guild_ranks AS gr ON gr.id = p.rank_id WHERE gr.guild_id =`t`.`id`) AS `total` FROM `guilds` as `t` ORDER BY `t`.`name`;");
|
||||
else
|
||||
$guilds = mysql_select_multi("SELECT `id`, `name`, `creationdata`, `motd`, (SELECT COUNT('guild_id') FROM `guild_membership` WHERE `guild_id`=`id`) AS `total` FROM `guilds` ORDER BY `name`;");
|
||||
$guilds = mysql_select_multi("
|
||||
SELECT
|
||||
`id`,
|
||||
`name`,
|
||||
`creationdata`,
|
||||
`motd`,
|
||||
( SELECT
|
||||
COUNT('guild_id')
|
||||
FROM `guild_membership`
|
||||
WHERE `guild_id`=`id`
|
||||
) AS `total`
|
||||
FROM `guilds`
|
||||
ORDER BY `name`;
|
||||
");
|
||||
|
||||
// Add level data info to guilds
|
||||
if ($guilds !== false)
|
||||
@ -26,10 +33,195 @@ function guild_list($TFSVersion) {
|
||||
return $guilds;
|
||||
}
|
||||
|
||||
function get_guild_position($rid) {
|
||||
$rid = (int)$rid;
|
||||
$data = mysql_select_single("SELECT `level` FROM `guild_ranks` WHERE `id`={$rid};");
|
||||
return ($data !== false) ? $data['level'] : false;
|
||||
}
|
||||
|
||||
// Check guild logo
|
||||
function logo_exists($guild) {
|
||||
$guild = sanitize($guild);
|
||||
echo (file_exists('engine/guildimg/'.$guild.'.gif')) ? 'engine/guildimg/'.$guild.'.gif' : 'engine/guildimg/default@logo.gif';
|
||||
}
|
||||
|
||||
// Remove cid invitation from guild (gid)
|
||||
function guild_remove_invitation($cid, $gid) {
|
||||
$cid = (int)$cid;
|
||||
$gid = (int)$gid;
|
||||
mysql_delete("
|
||||
DELETE FROM `guild_invites`
|
||||
WHERE `player_id`='{$cid}'
|
||||
AND `guild_id`='{$gid}'
|
||||
;");
|
||||
}
|
||||
|
||||
function update_player_guildnick_10($cid, $nick) {
|
||||
$cid = (int)$cid;
|
||||
$nick = sanitize($nick);
|
||||
mysql_update("UPDATE `guild_membership` SET `nick`='{$nick}' WHERE `player_id`={$cid}");
|
||||
}
|
||||
|
||||
function guild_player_join($cid, $gid) {
|
||||
$cid = (int)$cid;
|
||||
$gid = (int)$gid;
|
||||
|
||||
// Find rank id for regular member in this guild
|
||||
$guildrank = mysql_select_single("
|
||||
SELECT `id`
|
||||
FROM `guild_ranks`
|
||||
WHERE `guild_id`='{$gid}'
|
||||
AND `level`='1' LIMIT 1;
|
||||
");
|
||||
|
||||
if ($guildrank !== false) {
|
||||
$rid = $guildrank['id'];
|
||||
// Remove invite
|
||||
mysql_delete("DELETE FROM `guild_invites` WHERE `player_id`='{$cid}';");
|
||||
// Add to guild
|
||||
mysql_insert("
|
||||
INSERT INTO `guild_membership` (`player_id`, `guild_id`, `rank_id`, `nick`)
|
||||
VALUES ('{$cid}', '{$gid}', '{$rid}', '')
|
||||
;");
|
||||
// Return success
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function guild_player_leave_10($cid) {
|
||||
$cid = (int)$cid;
|
||||
mysql_delete("DELETE FROM `guild_membership` WHERE `player_id`='{$cid}' LIMIT 1;");
|
||||
}
|
||||
|
||||
function update_player_guild_position_10($cid, $rid) {
|
||||
$cid = (int)$cid;
|
||||
$rid = (int)$rid;
|
||||
mysql_update("UPDATE `guild_membership` SET `rank_id`='{$rid}' WHERE `player_id`={$cid}");
|
||||
}
|
||||
|
||||
function guild_invite_player($cid, $gid) {
|
||||
$cid = (int)$cid;
|
||||
$gid = (int)$gid;
|
||||
mysql_insert("INSERT INTO `guild_invites` (`player_id`, `guild_id`) VALUES ('{$cid}', '{$gid}')");
|
||||
}
|
||||
|
||||
function guild_remove_invites($gid) {
|
||||
$gid = (int)$gid;
|
||||
mysql_delete("DELETE FROM `guild_invites` WHERE `guild_id`='{$gid}';");
|
||||
}
|
||||
|
||||
function guild_delete($gid) {
|
||||
$gid = (int)$gid;
|
||||
mysql_delete("DELETE FROM `guilds` WHERE `id`='{$gid}';");
|
||||
}
|
||||
|
||||
// Get guild data, using guild id.
|
||||
function get_guild_rank_data($gid) {
|
||||
$gid = (int)$gid;
|
||||
return mysql_select_multi("SELECT `id`, `guild_id`, `name`, `level` FROM `guild_ranks` WHERE `guild_id`='{$gid}' ORDER BY `id` DESC LIMIT 0, 30");
|
||||
}
|
||||
|
||||
// Changes leadership of a guild to player_id
|
||||
function guild_new_leader($new_leader, $gid) {
|
||||
$new_leader = (int)$new_leader;
|
||||
$gid = (int)$gid;
|
||||
mysql_update("UPDATE `guilds` SET `ownerid`='{$new_leader}' WHERE `id`={$gid}");
|
||||
}
|
||||
|
||||
// Change guild leader (parameters: cid, new and old leader).
|
||||
function guild_change_leader($nCid, $oCid) {
|
||||
$nCid = (int)$nCid;
|
||||
$oCid = (int)$oCid;
|
||||
$gid = guild_leader_gid($oCid);
|
||||
$ranks = get_guild_rank_data($gid);
|
||||
$leader_rid = 0;
|
||||
$vice_rid = 0;
|
||||
|
||||
// Get rank id for leader and vice leader.
|
||||
foreach ($ranks as $rank) {
|
||||
if ($rank['level'] == 3) $leader_rid = $rank['id'];
|
||||
if ($rank['level'] == 2) $vice_rid = $rank['id'];
|
||||
}
|
||||
|
||||
$status = ($leader_rid > 0 && $vice_rid > 0) ? true : false;
|
||||
|
||||
if ($status) {
|
||||
// Update players and set their new rank id
|
||||
mysql_update("UPDATE `guild_membership` SET `rank_id`='{$leader_rid}' WHERE `player_id`={$nCid} LIMIT 1;");
|
||||
mysql_update("UPDATE `guild_membership` SET `rank_id`='{$vice_rid}' WHERE `player_id`={$oCid} LIMIT 1;");
|
||||
|
||||
// Update guilds set new ownerid
|
||||
guild_new_leader($nCid, $gid);
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
// Creates a guild, where cid is the owner of the guild, and name is the name of guild.
|
||||
function create_guild($cid, $name) {
|
||||
$cid = (int)$cid;
|
||||
$name = sanitize($name);
|
||||
$time = time();
|
||||
|
||||
// Create the guild
|
||||
mysql_insert("INSERT INTO `guilds` (`name`, `ownerid`, `creationdata`, `motd`) VALUES ('{$name}', '{$cid}', '{$time}', '');");
|
||||
|
||||
// Get guild id
|
||||
$gid = get_guild_id($name);
|
||||
|
||||
// Get rank id for guild leader
|
||||
$data = mysql_select_single("SELECT `id` FROM `guild_ranks` WHERE `guild_id`='{$gid}' AND `level`='3' LIMIT 1;");
|
||||
$rid = ($data !== false) ? $data['id'] : false;
|
||||
|
||||
// Give player rank id for leader of his guild
|
||||
mysql_insert("INSERT INTO `guild_membership` (`player_id`, `guild_id`, `rank_id`, `nick`) VALUES ('{$cid}', '{$gid}', '{$rid}', '');");
|
||||
}
|
||||
|
||||
// Returns total members in a guild (integer)
|
||||
function count_guild_members($gid) {
|
||||
$gid = (int)$gid;
|
||||
$data = mysql_select_single("SELECT COUNT('guild_id') AS `total` FROM `guild_membership` WHERE `guild_id`='{$gid}';");
|
||||
return ($data !== false) ? $data['total'] : false;
|
||||
}
|
||||
|
||||
// Guildwar functions
|
||||
function guild_war_invitation($cid, $gid) {
|
||||
$cid = (int)$cid;
|
||||
$gid = (int)$gid;
|
||||
$gname = get_guild_name($cid);
|
||||
$ename = get_guild_name($gid);
|
||||
$time = time();
|
||||
mysql_insert("
|
||||
INSERT INTO `guild_wars` (`guild1`, `guild2`, `name1`, `name2`, `status`, `started`, `ended`)
|
||||
VALUES ('{$cid}', '{$gid}', '{$gname}', '{$ename}', '0', '{$time}', '0')
|
||||
;");
|
||||
}
|
||||
|
||||
function accept_war_invitation($cid, $gid) {
|
||||
$cid = (int)$cid;
|
||||
$gid = (int)$gid;
|
||||
mysql_update("UPDATE `guild_wars` SET `status` = 1 WHERE `guild1` = '{$cid}' AND `guild2` = '{$gid}' AND `status` = 0;");
|
||||
}
|
||||
|
||||
function reject_war_invitation($cid, $gid) {
|
||||
$cid = (int)$cid;
|
||||
$gid = (int)$gid;
|
||||
$time = time();
|
||||
mysql_update("UPDATE `guild_wars` SET `status` = 2, `ended` = '{$time}' WHERE `guild1` = '{$cid}' AND `guild2` = '{$gid}';");
|
||||
}
|
||||
|
||||
function cancel_war_invitation($cid, $gid) {
|
||||
$cid = (int)$cid;
|
||||
$gid = (int)$gid;
|
||||
$time = time();
|
||||
mysql_update("UPDATE `guild_wars` SET `status` = 3, `ended` = '{$time}' WHERE `guild2` = '{$cid}' AND `guild1` = '{$gid}';");
|
||||
}
|
||||
|
||||
include 'layout/overall/header.php';
|
||||
|
||||
if (user_logged_in() === true) {
|
||||
|
||||
// fetch data
|
||||
$char_count = user_character_list_count($session_user_id);
|
||||
$char_array = user_character_list($user_data['id']);
|
||||
@ -47,22 +239,24 @@ if (user_logged_in() === true) {
|
||||
$char_count = 0;
|
||||
}
|
||||
|
||||
if (empty($_GET['name'])) {
|
||||
// Display the guild list
|
||||
|
||||
if (empty($_GET['name'])) {
|
||||
//data_dump($guild, false, "guild data");
|
||||
|
||||
$guilds = guild_list($config['ServerEngine']);
|
||||
|
||||
if (isset($guilds) && !empty($guilds) && $guilds !== false) {
|
||||
//data_dump($guilds, false, "Guilds");
|
||||
?>
|
||||
<style type="text/css">
|
||||
#guildsTable tr {
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
<table id="guildsTable" class="table table-striped table-hover">
|
||||
<tr class="yellow">
|
||||
<th>Logo</th>
|
||||
<th>Description</th>
|
||||
<th>Guild data</th>
|
||||
<!-- <th>Founded:</th> -->
|
||||
</tr>
|
||||
<?php
|
||||
foreach ($guilds as $guild) {
|
||||
@ -71,7 +265,8 @@ if (isset($guilds) && !empty($guilds) && $guilds !== false) {
|
||||
?>
|
||||
<tr class="special" onclick="javascript:window.location.href='<?php echo $url; ?>'">
|
||||
<td style="width: 100px;">
|
||||
<img style="max-height: 100px; margin: auto; display: block;" src="<?php logo_exists($guild['name']); ?>">
|
||||
<img style="max-height: 100px; margin: auto; display: block;"
|
||||
src="<?php logo_exists($guild['name']); ?>">
|
||||
</td>
|
||||
<td>
|
||||
<b><?php echo $guild['name']; ?></b>
|
||||
@ -89,22 +284,24 @@ if (isset($guilds) && !empty($guilds) && $guilds !== false) {
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<?php } else echo '<p>Guild list is empty.</p>';?>
|
||||
<!-- user stuff -->
|
||||
<?php
|
||||
} else echo '<p>Guild list is empty.</p>';?>
|
||||
|
||||
<!-- POST action: create guild -->
|
||||
<?php
|
||||
if (user_logged_in() === true) {
|
||||
// post verifications
|
||||
// CREATE GUILD
|
||||
if (!empty($_POST['selected_char']) && !empty($_POST['guild_name'])) {
|
||||
if (user_character_account_id($_POST['selected_char']) === $session_user_id) {
|
||||
data_dump($_POST, false, "debug");
|
||||
if ((int)user_character_account_id($_POST['selected_char']) === $session_user_id) {
|
||||
data_dump($_POST, false, "debug2");
|
||||
//code here
|
||||
$name = sanitize($_POST['selected_char']);
|
||||
$user_id = user_character_id($name);
|
||||
if ($config['ServerEngine'] !== 'TFS_10') $char_data = user_character_data($user_id, 'level', 'online');
|
||||
else {
|
||||
|
||||
$char_data = user_character_data($user_id, 'level');
|
||||
$char_data['online'] = (user_is_online_10($user_id)) ? 1 : 0;
|
||||
}
|
||||
|
||||
// If character level is high enough
|
||||
if ($char_data['level'] >= $config['create_guild_level']) {
|
||||
@ -156,7 +353,6 @@ if (user_logged_in() === true) {
|
||||
?>
|
||||
</select>
|
||||
<input type="text" name="guild_name">
|
||||
|
||||
<input type="submit" value="Create Guild">
|
||||
</li>
|
||||
</ul>
|
||||
@ -203,6 +399,7 @@ if (user_logged_in() === true) {
|
||||
$playerRank = $charactersRank[$i];
|
||||
|
||||
if ($playerRank == $rid) {
|
||||
// Get a player guild position ID, using his rank_id
|
||||
$access = get_guild_position($playerRank);
|
||||
if ($access == 2 || $access == 3) { //If player got access level vice leader or leader
|
||||
if ($access > $highest_access) $highest_access = $access;
|
||||
@ -215,18 +412,25 @@ if (user_logged_in() === true) {
|
||||
// Display the specific guild page
|
||||
?>
|
||||
|
||||
<!-- Guild information above table -->
|
||||
<div id="guildTitleDiv">
|
||||
<?php echo (isset($_GET['error'])) ? "<font size='5' color='red'>".sanitize($_GET['error'])."</font><br><br>" : ""; ?>
|
||||
<?php if ($config['use_guild_logos']): ?>
|
||||
<?php
|
||||
if (isset($_GET['error']))
|
||||
echo "<font size='5' color='red'>".sanitize($_GET['error'])."</font><br><br>";
|
||||
|
||||
if ($config['use_guild_logos']): ?>
|
||||
<div id="guildImageDiv" style="float: left; margin-right: 10px;">
|
||||
<img style="max-width: 100px; max-height: 100px;" src="<?php logo_exists(sanitize($_GET['name'])); ?>">
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
endif; ?>
|
||||
<div id="guildDescription">
|
||||
<h1>Guild: <?php echo sanitize($_GET['name']); ?></h1>
|
||||
<p><?php echo $guild['motd']; ?></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Guild information -->
|
||||
<table id="guildViewTable" class="table table-striped">
|
||||
<tr class="yellow">
|
||||
<th>Rank:</th>
|
||||
@ -236,24 +440,24 @@ if (user_logged_in() === true) {
|
||||
<th>Status:</th>
|
||||
</tr>
|
||||
<?php
|
||||
if ($config['ServerEngine'] == 'TFS_10') {
|
||||
$onlinelist = array();
|
||||
$gplayers = array();
|
||||
foreach ($players as $player) {
|
||||
$gplayers[] = $player['id'];
|
||||
}
|
||||
$gplayers = join(',',$gplayers);
|
||||
$onlinequery = mysql_select_multi("SELECT `player_id` FROM `players_online` WHERE `player_id` IN ($gplayers);");
|
||||
$onlinequery = mysql_select_multi("
|
||||
SELECT `player_id`
|
||||
FROM `players_online`
|
||||
WHERE `player_id` IN({$gplayers});
|
||||
");
|
||||
if ($onlinequery !== false) foreach ($onlinequery as $online) {
|
||||
$onlinelist[] = $online['player_id'];
|
||||
}
|
||||
}
|
||||
//data_dump($players, false, "Data");
|
||||
$rankName = '';
|
||||
foreach ($players as $player) {
|
||||
if ($config['ServerEngine'] !== 'TFS_10') {
|
||||
$chardata['online'] = $player['online'];
|
||||
} else $chardata['online'] = (in_array($player['id'], $onlinelist)) ? 1 : 0;
|
||||
$chardata['online'] = (in_array($player['id'], $onlinelist)) ? 1 : 0;
|
||||
echo '<tr>';
|
||||
echo '<td>' . ($rankName !== $player['rank_name'] ? $player['rank_name'] : '') . '</td>';
|
||||
$rankName = $player['rank_name'];
|
||||
@ -271,7 +475,8 @@ if (user_logged_in() === true) {
|
||||
?>
|
||||
</table>
|
||||
|
||||
<?php if ($inv_count > 0) { ?>
|
||||
<?php // Invited characters
|
||||
if ($inv_count > 0): ?>
|
||||
<h3>Invited characters</h3>
|
||||
<table>
|
||||
<tr class="yellow">
|
||||
@ -343,78 +548,83 @@ if (user_logged_in() === true) {
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<?php } ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Leader stuff -->
|
||||
<?php
|
||||
// Only guild leaders
|
||||
if (user_logged_in() === true) {
|
||||
|
||||
// Uninvite and joinguild is also used for visitors who reject their invitation.
|
||||
if (!empty($_POST['uninvite'])) {
|
||||
//
|
||||
guild_remove_invitation($_POST['uninvite'], $gid);
|
||||
header('Location: guilds.php?name='. $_GET['name']);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Join guild
|
||||
if (!empty($_POST['joinguild'])) {
|
||||
$joining_player_id = (int)$_POST['joinguild'];
|
||||
// Join a guild
|
||||
if ($inv_data !== false) foreach ($inv_data as $inv) {
|
||||
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;
|
||||
$chardata['online'] = (user_is_online_10($joining_player_id)) ? 1 : 0;
|
||||
if ($chardata['online'] == 0) {
|
||||
|
||||
// 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>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// leave guild
|
||||
if (!empty($_POST['leave_guild'])) {
|
||||
$name = sanitize($_POST['leave_guild']);
|
||||
$cidd = user_character_id($name);
|
||||
// If character is offline
|
||||
if ($config['ServerEngine'] !== 'TFS_10') $chardata = user_character_data($cidd, 'online');
|
||||
else $chardata['online'] = (user_is_online_10($cidd)) ? 1 : 0;
|
||||
$chardata['online'] = (user_is_online_10($cidd)) ? 1 : 0;
|
||||
if ($chardata['online'] == 0) {
|
||||
if ($config['ServerEngine'] !== 'TFS_10') guild_player_leave($cidd);
|
||||
else guild_player_leave_10($cidd);
|
||||
guild_player_leave_10($cidd);
|
||||
header('Location: guilds.php?name='. $_GET['name']);
|
||||
exit();
|
||||
} else echo '<font color="red" size="4">Character must be offline first!</font>';
|
||||
}
|
||||
|
||||
// vice leader (and guild leader) actions
|
||||
if ($highest_access >= 2) {
|
||||
// Guild leader stuff
|
||||
|
||||
// Vice-leaders and leaders
|
||||
// Change Guild Nick
|
||||
if (!empty($_POST['player_guildnick'])) {
|
||||
if ($config['guild_allow_nicknames']) {
|
||||
$p_cid = user_character_id($_POST['player_guildnick']);
|
||||
$p_guild = get_player_guild_data($p_cid);
|
||||
|
||||
if (preg_match("/^[a-zA-Z_ ]+$/", $_POST['guildnick']) || empty($_POST['guildnick'])) {
|
||||
// Only allow normal symbols as guild nick
|
||||
$p_nick = sanitize($_POST['guildnick']);
|
||||
|
||||
if ($p_guild['guild_id'] == $gid) {
|
||||
if ($config['ServerEngine'] !== 'TFS_10') $chardata = user_character_data($p_cid, 'online');
|
||||
else $chardata['online'] = (user_is_online_10($p_cid)) ? 1 : 0;
|
||||
$chardata['online'] = (user_is_online_10($p_cid)) ? 1 : 0;
|
||||
|
||||
if ($chardata['online'] == 0) {
|
||||
if ($config['ServerEngine'] !== 'TFS_10') update_player_guildnick($p_cid, $p_nick);
|
||||
else update_player_guildnick_10($p_cid, $p_nick);
|
||||
update_player_guildnick_10($p_cid, $p_nick);
|
||||
header('Location: guilds.php?name='. $_GET['name']);
|
||||
exit();
|
||||
} else echo '<font color="red" size="4">Character not offline.</font>';
|
||||
}
|
||||
|
||||
} else echo '<font color="red" size="4">Character guild nick may only contain a-z, A-Z and spaces.</font>';
|
||||
} else echo '<font color="red" size="4">Change guild nickname feature has been disabled.</font>';
|
||||
}
|
||||
@ -427,33 +637,22 @@ if ($highest_access >= 2) {
|
||||
$p_guild = get_player_guild_data($p_cid);
|
||||
|
||||
if ($p_guild['guild_id'] == $gid) {
|
||||
// Do the magic.
|
||||
if ($config['ServerEngine'] !== 'TFS_10') $chardata = user_character_data($p_cid, 'online');
|
||||
else $chardata['online'] = (user_is_online_10($p_cid)) ? 1 : 0;
|
||||
$chardata['online'] = (user_is_online_10($p_cid)) ? 1 : 0;
|
||||
if ($chardata['online'] == 0) {
|
||||
if ($config['ServerEngine'] !== 'TFS_10') update_player_guild_position($p_cid, $p_rid);
|
||||
else update_player_guild_position_10($p_cid, $p_rid);
|
||||
update_player_guild_position_10($p_cid, $p_rid);
|
||||
header('Location: guilds.php?name='. $_GET['name']);
|
||||
exit();
|
||||
} else echo '<font color="red" size="4">Character not offline.</font>';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// Invite character to guild
|
||||
if (!empty($_POST['invite'])) {
|
||||
if (user_character_exist($_POST['invite'])) {
|
||||
// Make sure they are not in another guild
|
||||
|
||||
if ($config['ServerEngine'] != 'TFS_10') {
|
||||
$charname = sanitize($_POST['invite']);
|
||||
$playerdata = mysql_select_single("SELECT `id`, `rank_id` FROM `players` WHERE `name`='$charname' LIMIT 1;");
|
||||
$charid = $playerdata['id'];
|
||||
$membership = ($playerdata['rank_id'] > 0) ? true : false;
|
||||
} else {
|
||||
$charid = user_character_id($_POST['invite']);
|
||||
$membership = mysql_select_single("SELECT `rank_id` FROM `guild_membership` WHERE `player_id`='$charid' LIMIT 1;");
|
||||
}
|
||||
$membership = mysql_select_single("SELECT `rank_id` FROM `guild_membership` WHERE `player_id`='{$charid}' LIMIT 1;");
|
||||
if (!$membership) {
|
||||
//
|
||||
$status = false;
|
||||
if ($inv_data !== false) {
|
||||
foreach ($inv_data as $inv) {
|
||||
@ -473,24 +672,24 @@ if ($highest_access >= 2) {
|
||||
|
||||
} else echo '<font color="red" size="4">That character name does not exist.</font>';
|
||||
}
|
||||
|
||||
// Guild Message (motd)
|
||||
if (!empty($_POST['motd'])) {
|
||||
$motd = sanitize($_POST['motd']);
|
||||
mysql_update("UPDATE `guilds` SET `motd`='$motd' WHERE `id`='$gid' LIMIT 1;");
|
||||
mysql_update("UPDATE `guilds` SET `motd`='{$motd}' WHERE `id`='{$gid}' LIMIT 1;");
|
||||
header('Location: guilds.php?name='. $_GET['name']);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Disband guild
|
||||
if (!empty($_POST['disband'])) {
|
||||
//
|
||||
$gidd = (int)$_POST['disband'];
|
||||
$members = get_guild_players($gidd);
|
||||
$online = false;
|
||||
|
||||
// First figure out if anyone are online.
|
||||
foreach ($members as $member) {
|
||||
if ($config['ServerEngine'] !== 'TFS_10') $chardata = user_character_data(user_character_id($member['name']), 'online');
|
||||
else $chardata['online'] = (user_is_online_10(user_character_id($member['name']))) ? 1 : 0;
|
||||
$chardata['online'] = (user_is_online_10(user_character_id($member['name']))) ? 1 : 0;
|
||||
if ($chardata['online'] == 1) {
|
||||
$online = true;
|
||||
}
|
||||
@ -498,11 +697,12 @@ if ($highest_access >= 2) {
|
||||
|
||||
if (!$online) {
|
||||
// Then remove guild rank from every player.
|
||||
if ($config['ServerEngine'] !== 'TFS_10') foreach ($members as $member) guild_player_leave(user_character_id($member['name']));
|
||||
else foreach ($members as $member) guild_player_leave_10(user_character_id($member['name']));
|
||||
foreach ($members as $member)
|
||||
guild_player_leave_10(user_character_id($member['name']));
|
||||
|
||||
// Remove all guild invitations to this guild
|
||||
if ($inv_count > 0) guild_remove_invites($gidd);
|
||||
if ($inv_count > 0)
|
||||
guild_remove_invites($gidd);
|
||||
|
||||
// Then remove the guild itself.
|
||||
guild_delete($gidd);
|
||||
@ -511,18 +711,15 @@ if ($highest_access >= 2) {
|
||||
} else echo '<font color="red" size="4">All members must be offline to disband the guild.</font>';
|
||||
}
|
||||
|
||||
// Change guild leader
|
||||
if (!empty($_POST['new_leader'])) {
|
||||
$new_leader = (int)$_POST['new_leader'];
|
||||
$old_leader = guild_leader($gid);
|
||||
|
||||
$online = false;
|
||||
if ($config['ServerEngine'] !== 'TFS_10') {
|
||||
$newData = user_character_data($new_leader, 'online');
|
||||
$oldData = user_character_data($old_leader, 'online');
|
||||
} else {
|
||||
$newData['online'] = (user_is_online_10($new_leader)) ? 1 : 0;
|
||||
$oldData['online'] = (user_is_online_10($old_leader)) ? 1 : 0;
|
||||
}
|
||||
|
||||
if ($newData['online'] == 1 || $oldData['online'] == 1) $online = true;
|
||||
|
||||
if ($online == false) {
|
||||
@ -533,6 +730,7 @@ if ($highest_access >= 2) {
|
||||
} else echo '<font color="red" size="4">The new and old leader must be offline to change leadership.</font>';
|
||||
}
|
||||
|
||||
// Change guild ranks
|
||||
if (!empty($_POST['change_ranks'])) {
|
||||
$c_gid = (int)$_POST['change_ranks'];
|
||||
$c_ranks = get_guild_rank_data($c_gid);
|
||||
@ -548,35 +746,39 @@ if ($highest_access >= 2) {
|
||||
}
|
||||
}
|
||||
|
||||
// Change guild rank name.
|
||||
foreach ($rank_data as $level => $name) {
|
||||
guild_change_rank($rank_ids[$level], $name);
|
||||
$rid = (int)$rank_ids[$level];
|
||||
$name = sanitize($name);
|
||||
mysql_update("UPDATE `guild_ranks` SET `name`='{$name}' WHERE `id`={$rid}");
|
||||
}
|
||||
|
||||
header('Location: guilds.php?name='. $_GET['name']);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Remove guild member
|
||||
if (!empty($_POST['remove_member'])) {
|
||||
$name = sanitize($_POST['remove_member']);
|
||||
$cid = user_character_id($name);
|
||||
|
||||
if ($config['ServerEngine'] !== 'TFS_10') guild_remove_member($cid);
|
||||
else guild_remove_member_10($cid);
|
||||
guild_remove_member_10($cid);
|
||||
header('Location: guilds.php?name='. $_GET['name']);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Create forum guild board
|
||||
if (!empty($_POST['forumGuildId'])) {
|
||||
|
||||
if ($config['forum']['guildboard'] === true) {
|
||||
$forumExist = mysql_select_single("SELECT `id` FROM `znote_forum` WHERE `guild_id`='$gid' LIMIT 1;");
|
||||
$forumExist = mysql_select_single("SELECT `id` FROM `znote_forum` WHERE `guild_id`='{$gid}' LIMIT 1;");
|
||||
|
||||
if ($forumExist === false) {
|
||||
// Insert data
|
||||
mysql_insert("INSERT INTO `znote_forum` (`name`, `access`, `closed`, `hidden`, `guild_id`)
|
||||
VALUES ('Guild',
|
||||
'1',
|
||||
'0',
|
||||
'0',
|
||||
'$gid');");
|
||||
mysql_insert("
|
||||
INSERT INTO `znote_forum`
|
||||
(`name`, `access`, `closed`, `hidden`, `guild_id`)
|
||||
VALUES ('Guild','1','0','0','{$gid}')
|
||||
;");
|
||||
echo '<h1>Guild board has been created.</h1>';
|
||||
} else echo '<h1>Guild board already exist.</h1>';
|
||||
|
||||
@ -585,11 +787,15 @@ if ($highest_access >= 2) {
|
||||
}
|
||||
}
|
||||
|
||||
if ($config['ServerEngine'] == 'TFS_02' || $config['ServerEngine'] == 'OTHIRE' || $config['ServerEngine'] == 'TFS_10' && $config['guildwar_enabled'] === true) {
|
||||
// Guildwar actions
|
||||
if ($config['guildwar_enabled'] === true) {
|
||||
|
||||
// Invite another guild to war
|
||||
if (!empty($_POST['warinvite'])) {
|
||||
$targetGuild = get_guild_id($_POST['warinvite']);
|
||||
if ($targetGuild) {
|
||||
$status = false;
|
||||
|
||||
$war_invite = mysql_select_single("SELECT `id` FROM `guilds` WHERE `id` = '$gid';");
|
||||
if ($war_invite !== false) {
|
||||
foreach ($war_invite as $inv) {
|
||||
@ -604,7 +810,15 @@ if ($highest_access >= 2) {
|
||||
|
||||
if ((int)$gid === (int)$targetGuild) $status = true;
|
||||
|
||||
$wars = mysql_select_multi("SELECT `id`, `guild1`, `guild2`, `status` FROM `guild_wars` WHERE (`guild1` = '$gid' OR `guild1` = '$targetGuild') AND (`guild2` = '$gid' OR `guild2` = '$targetGuild') AND `status` IN (0, 1);");
|
||||
$wars = mysql_select_multi("
|
||||
SELECT
|
||||
`id`, `guild1`, `guild2`, `status`
|
||||
FROM `guild_wars`
|
||||
WHERE (`guild1` = '$gid' OR `guild1` = '$targetGuild')
|
||||
AND (`guild2` = '$gid' OR `guild2` = '$targetGuild')
|
||||
AND `status` IN (0, 1)
|
||||
;");
|
||||
|
||||
if ($status == false && $wars == false) {
|
||||
guild_war_invitation($gid, $targetGuild);
|
||||
$limit = (empty($_POST['limit'])) ? 100 : (int)$_POST['limit'];
|
||||
@ -612,6 +826,7 @@ if ($highest_access >= 2) {
|
||||
header('Location: guilds.php?name='. $_GET['name']);
|
||||
exit();
|
||||
} else echo '<font color="red" size="4">This guild has already been invited to war(or you\'re trying to invite your own).</FONT>';
|
||||
|
||||
} else echo '<font color="red" size="4">That guild name does not exist.</font>';
|
||||
}
|
||||
|
||||
@ -636,9 +851,8 @@ if ($highest_access >= 2) {
|
||||
|
||||
$members = count_guild_members($gid);
|
||||
$ranks = get_guild_rank_data($gid);
|
||||
?>
|
||||
<!-- Form to create guild -->
|
||||
<?php
|
||||
|
||||
// Form to create guild board
|
||||
if ($config['forum']['guildboard'] === true && $config['forum']['enabled'] === true) {
|
||||
$forumExist = mysql_select_single("SELECT `id` FROM `znote_forum` WHERE `guild_id`='$gid' LIMIT 1;");
|
||||
if ($forumExist === false) {
|
||||
@ -654,11 +868,9 @@ if ($highest_access >= 2) {
|
||||
}
|
||||
}
|
||||
|
||||
// Form to upload guild logo
|
||||
if ($config['use_guild_logos']) {
|
||||
|
||||
?>
|
||||
|
||||
<!-- form to upload guild logo -->
|
||||
<form action="" method="post" enctype="multipart/form-data">
|
||||
<ul>
|
||||
<li>Upload guild logo [.gif images only, 100x100px size]:<br>
|
||||
@ -667,17 +879,14 @@ if ($highest_access >= 2) {
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
|
||||
if (!empty($_FILES['file'])) {
|
||||
|
||||
check_image($_FILES['file']);
|
||||
|
||||
echo '<br><br>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
} ?>
|
||||
<!-- forms to invite character -->
|
||||
<form action="" method="post">
|
||||
<ul>
|
||||
@ -687,6 +896,7 @@ if ($highest_access >= 2) {
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
|
||||
<!-- Guild message of the day motd -->
|
||||
<form action="" method="post">
|
||||
<ul>
|
||||
@ -697,6 +907,7 @@ if ($highest_access >= 2) {
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
|
||||
<?php if ($config['guild_allow_nicknames']): ?>
|
||||
<!-- FORMS TO CHANGE GUILD NICK -->
|
||||
<form action="" method="post">
|
||||
@ -707,7 +918,6 @@ if ($highest_access >= 2) {
|
||||
<?php
|
||||
//$gid = get_guild_id($_GET['name']);
|
||||
//$players = get_guild_players($gid);
|
||||
|
||||
foreach ($players as $player) {
|
||||
if ($player['rank_level'] != 3) {
|
||||
echo '<option value="'. $player['name'] .'">'. $player['name'] .'</option>';
|
||||
@ -725,8 +935,8 @@ if ($highest_access >= 2) {
|
||||
</ul>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<!-- END FORMS TO CHANGE GUILD NICK -->
|
||||
<?php if ($members > 1) { ?>
|
||||
|
||||
<?php if ($members > 1): ?>
|
||||
<!-- FORMS TO PROMOTE CHARACTER-->
|
||||
<form action="" method="post">
|
||||
<ul>
|
||||
@ -762,6 +972,7 @@ if ($highest_access >= 2) {
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
|
||||
<!-- Remove member from guild -->
|
||||
<form action="" method="post">
|
||||
<ul>
|
||||
@ -775,7 +986,11 @@ if ($highest_access >= 2) {
|
||||
if ($player['rank_level'] != 3) {
|
||||
if ($player['rank_level'] != 2) {
|
||||
echo '<option value="'. $player['name'] .'">'. $player['name'] .'</option>';
|
||||
} else if ($highest_access == 3) echo '<option value="'. $player['name'] .'">'. $player['name'] .'</option>';
|
||||
} else {
|
||||
if ($highest_access == 3) {
|
||||
echo '<option value="'. $player['name'] .'">'. $player['name'] .'</option>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -784,9 +999,14 @@ if ($highest_access >= 2) {
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
<?php } ?>
|
||||
<?php endif; ?>
|
||||
<br><br>
|
||||
<?php if ($highest_access == 3) { ?>
|
||||
<?php
|
||||
} // end vice leader+
|
||||
|
||||
if ($highest_access == 3) { ?>
|
||||
<!-- guild leaders only -->
|
||||
|
||||
<!-- forms to change rank titles -->
|
||||
<form action="" method="post">
|
||||
<ul>
|
||||
@ -802,6 +1022,7 @@ if ($highest_access >= 2) {
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
|
||||
<!-- forms to disband guild -->
|
||||
<form action="" method="post">
|
||||
<ul>
|
||||
@ -811,8 +1032,9 @@ if ($highest_access >= 2) {
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
|
||||
<!-- forms to change leadership-->
|
||||
<?php if ($members > 1) { ?>
|
||||
<?php if ($members > 1): ?>
|
||||
<form action="" method="post">
|
||||
<ul>
|
||||
<li><b>Change Leadership with:</b><br>
|
||||
@ -831,8 +1053,10 @@ if ($highest_access >= 2) {
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
<?php } ?>
|
||||
<?php if ($config['ServerEngine'] == 'TFS_02' || $config['ServerEngine'] == 'OTHIRE' || $config['ServerEngine'] == 'TFS_10' && $config['guildwar_enabled'] === true) { ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Guild war management -->
|
||||
<?php if ($config['guildwar_enabled'] === true) { ?>
|
||||
<h2>Guild War Management:</h2>
|
||||
<form action="" method="post">
|
||||
<ul>
|
||||
@ -843,49 +1067,87 @@ if ($highest_access >= 2) {
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
|
||||
<style type="text/css">
|
||||
form {display: inline;}
|
||||
#btnspace{margin-left:100px;}
|
||||
</style>
|
||||
<table id="guildsTable" class="table table-striped table-hover"><tr class="yellow"><th>Aggressor</th><th>Information</th><th>Enemy</th></tr>
|
||||
|
||||
<table id="guildsTable" class="table table-striped table-hover">
|
||||
<tr class="yellow">
|
||||
<th>Aggressor</th>
|
||||
<th>Information</th>
|
||||
<th>Enemy</th>
|
||||
</tr>
|
||||
<?php
|
||||
$i = 0;
|
||||
$wars = mysql_select_multi("SELECT `guild1`, `guild2`, `name1`, `name2`, `started`, (SELECT `limit` FROM `znote_guild_wars` WHERE `znote_guild_wars`.`id` = `guild_wars`.`id`) AS `limit` FROM `guild_wars` WHERE (`guild1` = '$gid' OR `guild2` = '$gid') AND `status` = 0 ORDER BY `started` DESC");
|
||||
$wars = mysql_select_multi("
|
||||
SELECT
|
||||
`guild1`, `guild2`, `name1`, `name2`, `started`,
|
||||
( SELECT `limit`
|
||||
FROM `znote_guild_wars`
|
||||
WHERE `znote_guild_wars`.`id` = `guild_wars`.`id`
|
||||
) AS `limit`
|
||||
FROM `guild_wars`
|
||||
WHERE (`guild1` = '$gid' OR `guild2` = '$gid')
|
||||
AND `status` = 0
|
||||
ORDER BY `started` DESC
|
||||
");
|
||||
if (!empty($wars) || $wars !== false) {
|
||||
foreach($wars as $war) {
|
||||
foreach($wars as $war):
|
||||
$i++;
|
||||
echo '<tr><td><a href="guilds.php?name='.$war['name1'].'">'.$war['name1'].'</a></td><td>';
|
||||
echo '<center><b>Pending invitation</b><br />Invited on ' . getClock($war['started'], true) . '.<br />The frag limit is set to ' . $war['limit'] . ' frags.<br />';
|
||||
$row = "<tr>";
|
||||
$row .= "<td><a href='guilds.php?name={$war['name1']}'>{$war['name1']}</a></td>";
|
||||
|
||||
$row .= '<td><center>';
|
||||
|
||||
$row .= '<b>Pending invitation</b>';
|
||||
$row .= '<br />Invited on '. getClock($war['started'], true) .'.';
|
||||
$row .= "<br />The frag limit is set to {$war['limit']} frags.<br />";
|
||||
|
||||
if ($war['guild1'] == $gid) {
|
||||
echo '<br /><form action="" method="post"><input type="hidden" name="cancel_war_invite" value="'.$war['guild2'].'" /><input type="submit" value="Cancel Invitation"></form>';
|
||||
$row .= '<br><form action="" method="post">';
|
||||
$row .= "<input type='hidden' name='cancel_war_invite' value='{$war['guild2']}' />";
|
||||
$row .= '<input type="submit" value="Cancel Invitation">';
|
||||
$row .= '</form>';
|
||||
} else if ($war['guild2'] == $gid) {
|
||||
echo '<br><form action="" method="post"><input type="hidden" name="accept_war_invite" value="'.$war['guild1'].'" /><input type="submit" value="Accept Invitation"></form>';
|
||||
echo '<form action="" method="post"><input type="hidden" name="reject_war_invite" value="'.$war['guild1'].'" /><input type="submit" ID="btnspace" value="Reject Invitation"></form>';
|
||||
}
|
||||
echo '</center></td><td><a href="guilds.php?name='.$war['name2'].'">'.$war['name2'].'</a></td></tr>';
|
||||
$row .= '<br><form action="" method="post">';
|
||||
$row .= "<input type='hidden' name='accept_war_invite' value='{$war['guild1']}' />";
|
||||
$row .= '<input type="submit" value="Accept Invitation">';
|
||||
$row .= '</form>';
|
||||
|
||||
$row .= '<form action="" method="post">';
|
||||
$row .= "<input type='hidden' name='reject_war_invite' value='{$war['guild1']}' />";
|
||||
$row .= '<input type="submit" ID="btnspace" value="Reject Invitation">';
|
||||
$row .= '</form>';
|
||||
}
|
||||
$row .= '</center></td>';
|
||||
$row .= "<td><a href='guilds.php?name={$war['name2']}'>{$war['name2']}</a></td>";
|
||||
$row .= '</tr>';
|
||||
echo $row;
|
||||
endforeach;
|
||||
}
|
||||
|
||||
if ($i == 0)
|
||||
echo '<tr><td colspan="3"><center>Currently there are no pending invitations.</center></td></tr>';
|
||||
echo '</table>';
|
||||
} } ?>
|
||||
if ($i == 0) echo '<tr><td colspan="3"><center>Currently there are no pending invitations.</center></td></tr>';
|
||||
?>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
} // end leader+
|
||||
} // end user_logged_in() === true
|
||||
?>
|
||||
<!-- end leader-->
|
||||
<!-- end leader and vice leader -->
|
||||
|
||||
<?php
|
||||
if ($config['guildwar_enabled'] === true) {
|
||||
if ($config['ServerEngine'] == 'TFS_02' || $config['ServerEngine'] == 'OTHIRE' || $config['ServerEngine'] == 'TFS_10') $wardata = get_guild_wars();
|
||||
else if ($config['ServerEngine'] == 'TFS_03') $wardata = get_guild_wars03();
|
||||
else die("Can't recognize TFS version. It has to be either TFS_02 or TFS_03. Correct this in config.php");
|
||||
$wardata = get_guild_wars();
|
||||
$war_exist = false;
|
||||
if ($wardata !== false) {
|
||||
foreach ($wardata as $wars) {
|
||||
if ($wars['guild1'] == $gid || $wars['guild2'] == $gid) $war_exist = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($war_exist) {
|
||||
?>
|
||||
<h2>War overview:</h2>
|
||||
@ -897,23 +1159,26 @@ if ($config['guildwar_enabled'] === true) {
|
||||
<td>started:</td>
|
||||
</tr>
|
||||
<?php
|
||||
foreach ($wardata as $wars) {
|
||||
if ($wars['guild1'] == $gid || $wars['guild2'] == $gid) {
|
||||
foreach ($wardata as $wars):
|
||||
if ($wars['guild1'] == $gid || $wars['guild2'] == $gid):
|
||||
$url = url("guildwar.php?warid=". $wars['id']);
|
||||
echo '<tr class="special" onclick="javascript:window.location.href=\'' . $url . '\'">';
|
||||
echo '<td>'. $wars['name1'] .'</td>';
|
||||
echo '<td>'. $wars['name2'] .'</td>';
|
||||
echo '<td>'. $config['war_status'][$wars['status']] .'</td>';
|
||||
echo '<td>'. getClock($wars['started'], true) .'</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<tr class="special" onclick="javascript:window.location.href='<?php echo $url; ?>'">
|
||||
<td><?php echo $wars['name1']; ?></td>
|
||||
<td><?php echo $wars['name2']; ?></td>
|
||||
<td><?php echo $config['war_status'][$wars['status']]; ?></td>
|
||||
<td><?php echo getClock($wars['started'], true); ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
endif;
|
||||
endforeach;
|
||||
?>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!-- leave guild with character -->
|
||||
<?php
|
||||
$bool = false;
|
||||
@ -924,12 +1189,11 @@ if (user_logged_in() === true) {
|
||||
}
|
||||
}
|
||||
if ($bool) {
|
||||
$forumExist = mysql_select_single("SELECT `id` FROM `znote_forum` WHERE `guild_id`='$gid' LIMIT 1;");
|
||||
$forumExist = mysql_select_single("SELECT `id` FROM `znote_forum` WHERE `guild_id`='{$gid}' LIMIT 1;");
|
||||
if ($forumExist !== false) {
|
||||
?> - <font size="4"><a href="forum.php?cat=<?php echo $forumExist['id']; ?>">Visit Guild Board</a></font><br><br><br><?php
|
||||
}
|
||||
?>
|
||||
|
||||
<form action="" method="post">
|
||||
<ul>
|
||||
<li>
|
||||
@ -955,5 +1219,5 @@ if ($forumExist !== false) {
|
||||
<?php
|
||||
} // display form if user has a character in guild
|
||||
} // user logged in
|
||||
} // if warname as $_GET
|
||||
} // end view specific guild
|
||||
include 'layout/overall/footer.php'; ?>
|
Loading…
x
Reference in New Issue
Block a user