<?php
include 'dbconn.php';
include 'func.php';

if(!empty($_SESSION['LoggedIn'.$session_app]) && !empty($_SESSION['Type']))
{
	$proceed = false;
	$check_member_points = checkExistPoints($_SESSION['Member_ID'], $gameType);
	
	if(count($check_member_points) > 0){
		$proceed = true;
	}else{
		if(createMemberPoints($gameType, $_SESSION['Member_ID'], $defaultPoint, $defaultChance, $defaultScore)){
			$proceed = true;
		}
	}
	
	
	if($proceed){
		$check_member_points = checkExistPoints($_SESSION['Member_ID'], $gameType);
		if(count($check_member_points) > 0){
			$member_point = $check_member_points[0]['member_point'];
			$member_chance = $check_member_points[0]['member_chance'];
			$member_score = $check_member_points[0]['member_score'];

			echo '{"status":true, "member_id":"'.$_SESSION['Member_ID'].'", "member_email":"'.$_SESSION['Email'].'", "member_name":"'.$_SESSION['Name'].'", "member_point":'.$member_point.', "member_chance":'.$member_chance.', "member_score":'.$member_score.', "token":"'.$_SESSION['Token'].'", "game_type":"'.$gameType.'", "message":"'.$lang['user-retrieve-successful'].'"}';
		}else{
			echo '{"status":false, "message":"'.$lang['server-points-not-found'].'"}';	
		}
	}else{
		echo '{"status":false, "message":"'.$lang['server-points-not-found'].'"}';
	}
}else{
	echo '{"status":false, "message":"'.$lang['session-not-found'].'"}';
}

// Close connection
mysqli_close($conn);
?>