<?php 
error_reporting(0);
session_start(); 

require('includes/mysql_connect.php');
require('includes/functions.php');

if(isset($_REQUEST['eid'])){
	$id = intval(clean($_REQUEST['eid']));
	if($id > 0){
		mysql_query("UPDATE `users` SET `clicked_email`=`clicked_email`+1 WHERE `account_id`='$id' LIMIT 1");
	}
}


if(isset($_GET['logout']) && $_GET['logout'] == "yes"){
	$ac_id = $_SESSION['account_id'];

	$_SESSION = array();
	if (isset($_COOKIE[session_name()])) {
		@setcookie( session_name() ,"",time()-3600,"/");
	}
	if (isset($_COOKIE['piratesglory'])) {
		@setcookie( 'piratesglory' ,"",time()-3600,"/");
	}
	

	if($ac_id){
		mysql_query("UPDATE `users` SET `auto_login`='0', `cookie_id`='null' WHERE `account_id`='$ac_id'");
	}
	// Finally, destroy the session.
	@session_destroy();
	unset($_SESSION);
}


if(isset($_SESSION['login'])){
	if($_SESSION['login'] == "pass"){
		if(($_SESSION['account_id'] > 0) && (md5($_SESSION['account_id']) == $_SESSION['secure'])){
			require('redirects/main.php');
			exit();
		}
		else{
			unset($_SESSION['login']);
		}
	}
}



require('includes/cookie.php');
require('includes/langcontrol.php');



//debug
if(LOGGED_IN == 1 && !($account_id)){
	define(LOGGED_IN,0);
}




if(isset($_GET['unsubscribe'])){
	$unsub = clean($_GET['unsubscribe']);
	$cc = mysql_query("SELECT `account_id`,`email`,`noemail` FROM `users` WHERE `unsubscribe`='$unsub'");
	$store = mysql_fetch_array($cc);
	if(isset($store['email'])){
		if($store['noemail'] == 1){
			echo '<center><br>This account is already unsubscribed!<br></center>';
		}
		else{
			if($_GET['store1'] == 1){
				mysql_query("UPDATE `users` SET `noemail`='1' WHERE `unsubscribe`='$unsub'");
				echo '<center><br>Succesfully Unsubscribed!<br></center>';
			}
			else{
			echo '<br><br><center>Do you wish to unsubscribe the account '.$store['email'].' from our newsletter ?<br><br><a href="/index.php?unsubscribe='.$unsub.'&store1=1" class="links_yellow">Yes</a> | <a href="/" class="links_yellow">No</a></center>';
			die();
			}
			}
	}
}


include('includes/m_detect.php');
mdet();


usleep(10000);


?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo $lang['title']; ?></title>
<META NAME="keywords" CONTENT="pirates, pbbg, rpg, online game, mmo, mmorpg, turn-based game, turn-based strategy/rpg, multi player game, online multiplayer game, free online game, online strategy game, game, free, Buccaneer game, online turn-based game, role playing game, role playing games, strategy, pirates rpg, pirates mmorpg, online pirate rpg, browser-based game about pirates, turn based pirate mmo, Pirate Game, Pirate Games">
<META NAME="description" CONTENT="Pirates Glory is a free online browser turn based & real time strategy rpg game for intelligent people. A free mmo pirates mmorpg rts pirate game.">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="css/full.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<script async src="js/full.js" type="text/javascript"></script>
<!--[if lt IE 9]>
<script src="https://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script>
var sw = 1280;
var sh = 1024;
sw=screen.width;
sh=screen.height;
</script>
</head>
<body style="background:url('images/bg_1.jpg') #181818; background-repeat:repeat;">
<?php


mysql_select_db('pirates_s2');
function top_countries(){


$sql = mysql_query("SELECT SUM(fame) as tfame,country,country_iso FROM `characters` group by `country` ORDER BY `tfame` DESC limit 10");

$num = mysql_num_rows($sql);

				$i = 0;
				$k = $a + 1;
				echo '<table class="table1" style="background-color:#0b0c06;border:solid;border-width:2px;border-color:#000000;margin-top:0;margin-left:auto;margin-right:auto;"><tr><td style="text-align:center;" colspan="2" class="pfooter">Most Powerful Nations</td></tr><tr><td style="text-align:left;width:15px;">#</td><td style="text-align:left;">Country</td></tr>';
				while($i < $num){
					
					$j = $i % 2;
					if($j == 1){
						$trcolor = "#0b0c06";
					}
					else{
						$trcolor = "#080603";
					}
					
					$tfame = mysql_result($sql,$i,"tfame");
					$nationality = mysql_result($sql,$i,"country");
								if($nationality =="United States of America"){
									$nationality ="USA";
								}
					
				
						echo '<tr style="background-color:'.$trcolor.';"><td style="text-align:left;">'.$k.'</td><td style="text-align:left;"><IMG src="s2/images/countries/'.mysql_result($sql,$i,"country_iso").'.gif" alt="'.$nationality.'" title="'.$nationality.'"> <a href="#">'.$nationality.'</a></td></tr>';
					
					$k++;
					$i++;
				}
				echo '</table>';
			

}

if(isset($_POST['loginbutton_x'])){

$email = $_POST['email'];
$password = $_POST['password'];
}

if(isset($_GET['try'])){
	if($_GET['try'] == "fail"){
	echo '<SCRIPT>alert("'.$lang["errmsg1"].'");</SCRIPT>';
	}
	else if($_GET['try'] == "fail2"){
	echo '<SCRIPT>alert("'.$lang["errmsg2"].'");</SCRIPT>';
	}
		echo '<div style="top:0px;background:#181818;width:100%; height:40px; position:fixed;z-index:8; text-align:center;"><div style="position:relative;margin-top:10px;">
    	<a href="lspwd.php" class="sgoldli" style="font-size:18px;">Click here to get a new password!</a></div>
</div>';
}
else{
	echo '<div style="top:0px;background:#181818;width:100%; height:20px; position:fixed;z-index:8; text-align:center;">
    	<a href="https://www.piratesglory.com/"  class="sgoldli">PIRATES STRATEGY RPG ONLINE GAME</a>
</div>';
}


?>

    

<div id="Main" style="background-repeat:no-repeat; background-position:top left; padding:0px; margin-left:0px; margin-right:0px; margin-top:20px;position:relative;width:100%;">

   <div id="LeftSticker" style="width:817px; margin-left:-2px; padding:1px; top:10px; left:75px; float: left; position:relative; z-index:15;">
    	<table>
        	<tr>
            	<td style="text-align:center;width:259px;"><IMG src="images/logo.png" alt="Pirates Glory" title="Pirates Glory"></td>
                <td style="text-align:center;width:299px;" class="big">Play from your browser<br>No downloads are needed!<br><br>In Pirates Glory you will enroll in a fantasy world set in the age of Gunpowder!<br><br>How far can you go?</td>
                <td style="text-align:center;width:259px;">
                        <?php
						
						//Control logged in player
						if(LOGGED_IN != 1){
						
							?>
                            <table style="margin-left:auto;margin-right:auto;">
							<tr>
								<td style="text-align:center;"><a href="<?php
                                
								if(getTld() == 'com'){
									echo 'https://www.piratesglory.com/';
								}
														
								 
								
								?>login_d.php" onMouseOver="login_o.src='images/welcome/l_login_o.png';" onMouseOut="login_o.src='images/welcome/l_login.png';"><img name="login_o" src="images/welcome/l_login.png" title="Click here to Login" alt="Login" ></a></td>
                                </tr>
                                <tr>
								<td style="text-align:center;"><a href="https://www.piratesglory.com/signup.php" onMouseOver="register_o.src='images/welcome/register_o.png';" onMouseOut="register_o.src='images/welcome/register.png';"><img name="register_o" src="images/welcome/register.png" title="Create your character" alt="Register" ></a></td>
							</tr></table><?php
						
						}
						?>
                    </td>
            </tr>
        </table>
    </div>  
    <?php
	
	if(isset($_GET['try']) && $_GET['try'] == 'canceled'){
		$error = 'You have canceled your authentication.\nYour account is now only accessible with your email.';
	}else if(isset($_GET['try']) && $_GET['try'] == 'autherror'){
		$error = 'Authentication error. Try to login again.';
	}
	else if(isset($_GET['try']) && $_GET['try'] == 'exists'){
		if($_GET['mail']){
			$which_mail = 'the email '.urldecode($_GET['mail']);
		}
		else{
			$which_mail = 'this email';
		}
		$error = 'An account with '.$which_mail.' ALREADY exists!<br>Log in with your email and password to link your account.';
	}
	else if(isset($_GET['try']) && $_GET['mode'] == 'forum'){
		$error = 'You need to be logged in your game account in order to login into forums.';
	}
	
	if($error){
		echo '<div id="myAccount" style="width:300px; left:10px; margin-left:auto; margin-right:auto; top:25%; z-index:18; position:relative; text-align:center;"><table class="stylish"><tr><td class="title">ERROR!</td></tr><tr><td style="text-align:center;">'.$error.'</td></tr></table></div>';	
	}
	
	
	//Get Version
	/*
	$sql = mysql_query("SELECT `value` FROM `config` WHERE `option`='version'");
	$res = mysql_fetch_array($sql);
	$version = $res['value'];
	*/
	?>
    
</div>

   <div id="TopCountries" style="margin-right:0px; text-align:center; top:5%; right:1%; float: right; z-index:10; position:fixed;">
    	<?php top_countries(); ?><br><br><a href="https://www.piratesglory.com/images/screenshots/index.php" target="_blank"><IMG src="images/screenshots.png" alt="Pirates Screenshots" title="Click here to see Pirates Glory Screenshots"></a><br><Br><a href="https://www.piratesglory.com/images/concept_art/index.php" target="_blank"><IMG src="images/concept_art.png" alt="Pirates Concept Art" title="Click here to see Pirates Glory Concept Art"></a>
    </div>

<div style="bottom:0px;background:#181818;width:100%;height:40px;position:fixed;" class="pbfooter"><div style="position:relative; width:100%; text-align:center; top:12px;">
	<a href="https://www.piratesglory.com/" class="pbfooter">Pirates Glory Strategy RPG mmo game</a> &copy;<?php echo date("Y"); ?> - All Rights Reserved - <a href="terms.php" target="_blank" class="pbfooter">Terms of Service (ToS)</a> - <a href="https://www.evdaimon.com/?a=pg" class="pbfooter">About</a> - <a href="https://www.piratesglory.com/press.php" target="_self" class="pbfooter">Press</a></div>
</div>
<script type="text/javascript">// <![CDATA[
"number"==typeof window.innerWidth?(sw=window.innerWidth,sh=window.innerHeight):document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)?(sw=document.documentElement.clientWidth,sh=document.documentElement.clientHeight):document.body&&(document.body.clientWidth||document.body.clientHeight)&&(sw=document.body.clientWidth,sh=document.body.clientHeight),sh-=40,sw<1025?document.getElementById("Main").style.backgroundImage="url('images/welcome/1024x768_new.jpg')":sw<1442?document.getElementById("Main").style.backgroundImage="url('images/welcome/1440x900.jpg')":document.getElementById("Main").style.backgroundImage="url('images/welcome/1920x1080.jpg')",sw<1100&&(document.getElementById("TopCountries").style.display="none"),login_o=new Image,login_o.src="images/welcome/l_login_o.png",register_o=new Image,register_o.src="images/welcome/register_o.png",document.getElementById("Main").style.height=sh+"px";

// ]]></script>
<?php 


mysql_close($dbh); 


if($_SERVER['HTTP_REFERER']){
	$url = base64_encode($_SERVER['HTTP_REFERER']);
	echo '<IMG src="referral/ref.php?uref='.$url.'" width="0" height="0">';
}

include('includes/google_analytics.php');
?>
</body>
</html>