game/social.php

129 lines
5.1 KiB
PHP

<?php
die();
define('GAME',true);
include('_incl_data/__config.php');
include('_incl_data/class/__db_connect.php');
$u = User::start();
//
if(isset($u->info['id'])) {
$mcf = mysql_fetch_array(mysql_query('SELECT * FROM `mini_actions` WHERE `uid` = "'.$u->info['id'].'" AND (`val` = "vkauth" OR `val` = "fbauth" OR `val` = "okauth") LIMIT 1'));
if(isset($mcf['id'])) {
die('Âû óæå ïîäòâåðäèëè îäíó ñòðàíèöó â ñîöèàëüíîé ñåòè.');
}
}
if(!isset($u->info['id'])) {
echo 'Âû íå àâòîðèçîâàëèñü â èãðå.';
}elseif(isset($_GET['vkconnect'])) {
//
require_once('vk/VK.php');
require_once('vk/VKException.php');
//
$vk_config = array(
'app_id' => '5145826',
'api_secret' => 'V90yIzlgSglfgrnHw7Ny',
'callback_url' => 'https://new-combats.com/social.php?vkconnect',
'api_settings' => 'offline,friends,email'
);
$vk = new VK\VK($vk_config['app_id'], $vk_config['api_secret']);
//
echo '<center style="font-size:20px;"><br><br>';
if(isset($_GET['error']) && $_GET['error'] == 'access_denied') {
echo 'Âû îòêàçàëèñü ïðèâÿçûâàòü ñâîé àêêàóíò â ñîöèàëüíîé ñåòè ÂÊîíòàêòå.';
}else{
$access_token = $vk->getAccessToken($_REQUEST['code'], $vk_config['callback_url']);
if( $access_token['user_id'] > 0 ) {
$mcf = mysql_fetch_array(mysql_query('SELECT * FROM `mini_actions` WHERE `val` = "vkauth" AND `ok` = "'.$access_token['user_id'].'" LIMIT 1'));
$ubn = mysql_fetch_array(mysql_query('SELECT `id` FROM `users` WHERE `id` = "'.$mcf['uid'].'" AND `banned` = 0 LIMIT 1'));
if(!isset($ubn['id'])) {
unset($mcf);
}
if(isset($mcf['id'])) {
echo 'Âàø àêêàóíò óæå áûë ïðèâÿçàí ê îäíîìó èç ïåðñîíàæåé!';
}else{
$bank = mysql_fetch_array(mysql_query('SELECT * FROM `bank` WHERE `uid` = "'.$u->info['id'].'" LIMIT 1'));
//
if(!isset($bank['id'])) {
echo 'id èãðîêà: '.$u->info['id'].'<br>Îòêðîéòå èãðîâîé áàíêîâñêèé ñ÷åò è ïîïðîáóéòå ñíîâà.';
}else{
mysql_query('UPDATE `bank` SET `money2` = `money2` + 1, `money1` = `money1` + 150 WHERE `id` = "'.$bank['id'].'" LIMIT 1');
mysql_query('INSERT INTO `mini_actions` (`uid`,`time`,`val`,`var`,`var2`,`ok`) VALUES (
"'.$u->info['id'].'","'.time().'","vkauth","'.mysql_real_escape_string($access_token['email']).'",
"'.mysql_real_escape_string($access_token['access_token']).'","'.mysql_real_escape_string($access_token['user_id']).'"
)');
//
echo 'Âàø àêêàóíò óñïåøíî ïðèâÿçàí! Ñïàñèáî!<br>Íà ñ÷åò ïåðñîíàæà <b>'.$u->info['login'].'</b> çà÷èñëåí 1 åêð. è 150 êð.';
}
}
}else{
echo 'Èíôîðìàöèÿ íå ïîëó÷åíà, ïîïðîáóéòå ñíîâà.';
}
}
echo '<br><br>(×åðåç 5 ñåêóíä îêíî àâòîìàòè÷åñêè çàêðîåòñÿ)';
echo '</center>';
echo '<script>window.opener.location.href=\'main.php?inv=1\';setTimeout("window.close();",5000);</script>';
//
}elseif(isset($_GET['fbconnect'])) {
//
require_once('vk/FB.php');
// Ïðèìåð èñïîëüçîâàíèÿ êëàññà:
session_start();
if (!empty($_GET['error'])) {
// Ïðèø¸ë îòâåò ñ îøèáêîé. Íàïðèìåð, þçåð îòìåíèë àâòîðèçàöèþ.
die($_GET['error']);
} elseif (empty($_GET['code'])) {
// Ñàìûé ïåðâûé çàïðîñ
OAuthFB::goToAuth();
} else {
// Ïðèø¸ë îòâåò áåç îøèáîê ïîñëå çàïðîñà àâòîðèçàöèè
if (!OAuthFB::checkState($_GET['state'])) {
die("The state does not match. You may be a victim of CSRF.");
}
if (!OAuthFB::getToken($_GET['code'])) {
die('Error - no token by code');
}
$user = OAuthFB::getUser();
if(isset($user->id)) {
$mcf = mysql_fetch_array(mysql_query('SELECT * FROM `mini_actions` WHERE `val` = "fbauth" AND `ok` = "'.$user->id.'" LIMIT 1'));
$ubn = mysql_fetch_array(mysql_query('SELECT `id` FROM `users` WHERE `id` = "'.$mcf['uid'].'" AND `banned` = 0 LIMIT 1'));
if(!isset($ubn['id'])) {
unset($mcf);
}
if(isset($mcf['id'])) {
echo 'Âàø àêêàóíò óæå áûë ïðèâÿçàí ê îäíîìó èç ïåðñîíàæåé!';
}else{
$bank = mysql_fetch_array(mysql_query('SELECT * FROM `bank` WHERE `uid` = "'.$u->info['id'].'" LIMIT 1'));
//
if(!isset($bank['id'])) {
echo 'id èãðîêà: '.$u->info['id'].'<br>Îòêðîéòå èãðîâîé áàíêîâñêèé ñ÷åò è ïîïðîáóéòå ñíîâà.';
}else{
mysql_query('UPDATE `bank` SET `money2` = `money2` + 1, `money1` = `money1` + 150 WHERE `id` = "'.$bank['id'].'" LIMIT 1');
mysql_query('INSERT INTO `mini_actions` (`uid`,`time`,`val`,`var`,`var2`,`ok`) VALUES (
"'.$u->info['id'].'","'.time().'","fbauth","'.mysql_real_escape_string($user->id).'",
"","'.mysql_real_escape_string($user->id).'"
)');
//
echo 'Âàø àêêàóíò óñïåøíî ïðèâÿçàí! Ñïàñèáî!<br>Íà ñ÷åò ïåðñîíàæà <b>'.$u->info['login'].'</b> çà÷èñëåí 1 åêð. è 150 êð.';
}
}
echo '<br><br>(×åðåç 5 ñåêóíä îêíî àâòîìàòè÷åñêè çàêðîåòñÿ)';
echo '</center>';
echo '<script>window.opener.location.href=\'main.php?inv=1\';setTimeout("window.close();",5000);</script>';
}else{
die('Íå óäàëîñü ïîëó÷èòü äàííûå âàøåé ñòðàíè÷êè Facebook');
}
/*
* Âîò è âñ¸ - ìû óçíàëè îñíîâíûå äàííûå àâòîðèçîâàííîãî þçåðà.
* $user â ýòîì ïðèìåðå ñîñòîèò èç äâóõ ïîëåé: id, name.
* Äåëàéòå ñ íèìè ÷òî óãîäíî - ðåãèñòðèðóéòå, àâòîðèçóéòå, ðóãàéòå...
*/
}
//
}else{
echo 'Ìû íå ðàáîòàåò ñ ïîäîáíîé ñîöèàëüíîé ñåòüþ.';
}
?>