Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!defined('IN_DISCUZ')) {
- exit('Access Denied');
- }
- require_once 'steamid.php';
- $psetting = $_G['cache']['plugin']['xnet_steam_credit_gf'];
- $plang = lang('xnet_steam_credit_gf:scriptlang');
- //读取配置语言
- if (!$_G['uid']) {
- showmessage($plang['alert_user_login'], NULL, array(), array('login' => 1));
- }
- $ctype = intval($psetting['ctype']);
- $jifen_title = $_G['setting']['extcredits'][$ctype]['title'];
- $bbs_scale = intval($psetting['bbs_scale']);
- $game_scale = intval($psetting['game_scale']);
- $allowtype = intval($psetting['btype']);
- //SteamAPI
- $steam_apikey = $psetting['steam_apikey'];
- $steam_apikey_check_steam = $psetting['steam_apikey_check_steam'];
- $steam_apicheck_type = $psetting['steam_apicheck_type'];
- //远程数据库设置
- $Use_remote_mysql = $psetting['remote_mysql'];
- $remote_host = $psetting['remote_host'];
- $remote_user = $psetting['remote_user'];
- $remote_pass = $psetting['remote_pass'];
- $remote_database = $psetting['remote_database'];
- //远程数据库
- //QQ通知变量
- $qq_robot_enable = $psetting['qq_robot_enable'];
- $qq_robot_send_user = $psetting['qq_robot_send_user'];
- $qq_robot_send_admin = $psetting['qq_robot_send_admin'];
- $qq_robot_admin_qq = $psetting['qq_robot_admin_qq'];
- $qq_robot_send_type = $psetting['qq_robot_send_type'];
- //QQ通知
- if ($TradeCoolDown <= 20) {
- $TradeCoolDown = 20;
- }
- //URL
- $notbind_url_goto = $psetting['notbind_url_goto'];
- if (!($steamid64 = DB::result_first("select steamID64 from " . DB::table('steam_users') . " where uid='" . $_G['uid'] . "'"))) {
- showmessage($plang['alert_user_nosteamid'], $url_forward = "{$notbind_url_goto}");
- }
- if (!($dzuid = DB::result_first("select uid from " . DB::table('steam_users') . " where uid='" . $_G['uid'] . "'"))) {
- showmessage($plang['alert_user_nosteamid'], $url_forward = "{$notbind_url_goto}");
- }
- $steamid32 = ConvertSteam64To32($steamid64);
- if ($steam_apikey_check_steam && $steam_apicheck_type == 3) {
- $NotInGame = SteamAPI_Fetch_PlayerNotInGame($steamid64);
- if (!$NotInGame) {
- $reson = SteamAPI_Fetch_Player_Reson($steamid64);
- showmessage($reson);
- }
- }
- if ($Use_remote_mysql) {
- //后台如果开启远程数据库
- //PHP连接其他MYSQL
- try {
- $connect = new PDO("mysql:host={$remote_host};dbname={$remote_database}", $remote_user, $remote_pass);
- } catch (PDOException $e) {
- showmessage($plang['alert_couldnot_connect_remote_mysql_server']);
- }
- }
- //不开启整段无视.
- //Remove SQL?
- if (!empty($_GET['formhash'])) {
- if ($_GET['formhash'] != FORMHASH) {
- showmessage('undefined_action');
- }
- $duiru = intval($_GET['duiru']);
- $duicount = intval($_GET['duicount']);
- //$file = fopen("creditslog.txt", "w+");
- $fangxiang = "兑换到游戏";
- $time = date('Y-m-d H:i:s', time());
- $CTDF_USERINFO["user"] = $discuz_user;
- if (empty($duiru) || empty($duicount)) {
- //检验数据
- showmessage($plang['alert_user_data_isnull']);
- }
- if (!$_G['uid']) {
- showmessage("请先登录!");
- }
- // if ($_G['uid'] != 480) showmessage("尚未开放!");
- if (!($steamid64 = DB::result_first("select steamID64 from " . DB::table('steam_users') . " where uid='" . $_G['uid'] . "'"))) {
- showmessage("没有绑定SteamID");
- }
- $OLDBBSCredits = C::t('common_member_count')->fetch($_G['uid']);
- $OLDBBSCreditsNumber = $OLDBBSCredits['extcredits' . $ctype];
- $OLDGameCredits = DB::result_first("select credits from `store_players` where authid = '{$steamid32}'");
- if ($duiru == '1') {
- //游戏币换论坛积分
- if ($steam_apikey_check_steam && $steam_apicheck_type == 1) {
- $NotInGame = SteamAPI_Fetch_PlayerNotInGame($steamid64);
- if (!$NotInGame) {
- $reson = SteamAPI_Fetch_Player_Reson($steamid64);
- showmessage($reson);
- }
- }
- if ($allowtype != 0 && $allowtype != 2) {
- showmessage($plang['alert_dhfx_disble']);
- }
- if (!$Use_remote_mysql) {
- if (!($gamecredits = DB::fetch_first("select * from `store_players` where authid = '{$steamid32}'"))) {
- showmessage($plang['alert_user_nosteamid'], $url_forward = "{$notbind_url_goto}");
- }
- }
- //远程 查询游戏积分
- if ($Use_remote_mysql) {
- $sql_gamecredits = "select * from `store_players` where authid = '{$steamid32}'";
- $sth = $connect->query($sql_gamecredits);
- if (!$sth) {
- showmessage($plang['alert_couldnot_connect_remote_mysql_server']);
- }
- while ($row = $sth->fetch()) {
- $gamecredits = $row['credits'];
- }
- } else {
- //查询本地积分
- $gamecredits = DB::result_first("select credits from `store_players` where authid = '{$steamid32}'");
- }
- $dayu500 = $gamecredits - $duicount;
- if ($allowtype != 2 && $dayu500 < 500) {
- showmessage("必须留 500 游戏积分!");
- }
- //远程 查询游戏积分
- $scount = ceil($duicount * $game_scale / $bbs_scale);
- if (intval($gamecredits) < $scount) {
- //积分不足
- showmessage($plang['alert_user_has_nofull']);
- }
- if (intval($gamecredits['credits']) == "") {
- //无帐号
- showmessage($plang['alert_nogame_credits'], $url_forward = "{$notbind_url_goto}");
- }
- if ($duicount < 1) {
- //积分不足
- showmessage($plang['alert_user_has_nofull']);
- }
- if (!is_numeric($duiru) || !is_int($duiru)) {
- showmessage($plang['alert_duicount_wrong']);
- }
- // Lengque
- if (!($timestamp = DB::result_first("select timestamp from " . DB::table('plugin_cooldown') . " where uid='" . $_G['uid'] . "'"))) {
- ##如果没有则写入
- $arr = array('uid' => $_G['uid'], 'timestamp' => TIMESTAMP);
- DB::query("insert into " . DB::table('plugin_cooldown') . "(`uid`, `timestamp`) VALUES ('{$arr['uid']}', '{$arr['timestamp']}')");
- } else {
- if ($timestamp = DB::result_first("select timestamp from " . DB::table('plugin_cooldown') . " where uid='" . $_G['uid'] . "'")) {
- if ($timestamp >= TIMESTAMP - $TradeCoolDown) {
- $countdown = $timestamp - (TIMESTAMP - $TradeCoolDown);
- showmessage("上一次操作是成功的! 请间隔 {$countdown} 秒后再操作!");
- } else {
- $Nowtimestamp = TIMESTAMP;
- DB::query("update " . DB::table('plugin_cooldown') . " set timestamp = '{$Nowtimestamp}' where uid='" . $_G['uid'] . "'");
- }
- }
- }
- // Lengque
- //扣游戏币,加论坛积分
- //PDO判断 扣除游戏积分增加论坛积分
- if (!$Use_remote_mysql) {
- //不使用远程数据库 则
- $duicount && updatemembercount($_G['uid'], array('extcredits' . $ctype => $duicount));
- DB::query("update `store_players` set credits = credits - {$scount} where authid = '{$steamid32}'");
- credit_log($_G['uid'], "dbb", 16, array('extcredits2' => $duicount), $customtitle1, "test");
- //LOG
- }
- //PDO
- if ($Use_remote_mysql) {
- //使用远程数据库 则
- $sql_gamecredits = "update `store_players` set credits = credits - {$scount} where authid = '{$steamid32}'";
- // $sth = $connect->query($sql_gamecredits);
- if (!$connect->exec($sql_gamecredits)) {
- showmessage($plang['alert_couldnot_connect_remote_mysql_server']);
- }
- $duicount && updatemembercount($_G['uid'], array('extcredits' . $ctype => $duicount));
- credit_log($_G['uid'], "dbb", 16, array('extcredits2' => $duicount), $customtitle1, "test");
- //LOG
- }
- //使用远程数据库 结束
- if ($duiru == '1') {
- // $OLDBBSCreditsNumber Credits:$OLDGameCredits
- $bbs_bypass = $OLDBBSCreditsNumber + $duicount;
- $game_bypass = $OLDGameCredits - $duicount;
- $NowBBSCredits = C::t('common_member_count')->fetch($_G['uid']);
- $NowBBSCreditsNumber = $NowBBSCredits['extcredits' . $ctype];
- $NowGameCredits = DB::result_first("select credits from `store_players` where authid = '{$steamid32}'");
- if ($Use_remote_mysql) {
- $sql_gamecredits = "select * from `store_players` where authid = '{$steamid32}'";
- $sth = $connect->query($sql_gamecredits);
- if (!$sth) {
- showmessage($plang['alert_couldnot_connect_remote_mysql_server']);
- }
- while ($row = $sth->fetch()) {
- $NowGameCredits = $row['credits'];
- }
- }
- if ($bbs_bypass == $NowBBSCreditsNumber) {
- $bbs_bypass = "验证积分PASS!";
- } else {
- $repuid = $_G['uid'];
- $bbs_bypass = "积分验证失败!!!";
- }
- if ($game_bypass == $NowGameCredits) {
- $game_bypass = "验证积分PASS!";
- } else {
- $repuid = $_G['uid'];
- $game_bypass = "积分验证失败!!!";
- //qqlite::sendqun(148942041, "UID$repuid $game_bypass");
- }
- //通知论坛积分增加
- if ($qq_robot_enable && $qq_robot_send_type == 1 || $qq_robot_send_type == 3) {
- $localtime = date('y-m-d H:i:s', time());
- //取现时间
- //消息定义
- $qqmessage = "[CSGO-CN] UID : " . $_G['uid'] . " 论坛id :" . $_G['username'] . " {$steamid64} 操作:游戏积分兑换 {$jifen_title} 数量:{$duicount} 操作时间:{$localtime} \n 原有信息:\n叶子:{$OLDBBSCreditsNumber} Credits:{$OLDGameCredits} \n现有信息:\n叶子:{$NowBBSCreditsNumber} [{$bbs_bypass}] Credits:{$NowGameCredits} [{$game_bypass}]";
- if ($qq_robot_send_user && ($qq_user = qqlite::getuser($_G['uid']))) {
- //如果QQ用户发送消息给对应号码
- $qq_hao = $qq_user['qq'];
- //$qqusername = $qq_user['username'];
- qqlite::sendqq($qq_hao, $qqmessage);
- //发送到对应QQ
- }
- //发送到admin
- if ($qq_robot_send_admin) {
- $adminqqs = preg_split('/\\r\\n/', $qq_robot_admin_qq);
- //后台 qq逐行读取
- foreach ($adminqqs as $admin_qq) {
- $admin_qq = str_replace(' ', '', $admin_qq);
- //过滤可能的空格
- qqlite::sendqq($admin_qq, $qqmessage);
- }
- }
- }
- //通知论坛积分增加
- }
- } elseif ($duiru == '2') {
- //积分换游戏币
- if ($allowtype != 0 && $allowtype != 1) {
- showmessage($plang['alert_dhfx_disble']);
- }
- if ($steam_apikey_check_steam && $steam_apicheck_type == 2) {
- $NotInGame = SteamAPI_Fetch_PlayerNotInGame($steamid64);
- if (!$NotInGame) {
- $reson = SteamAPI_Fetch_Player_Reson($steamid64);
- showmessage($reson);
- }
- }
- $bbscredits = C::t('common_member_count')->fetch($_G['uid']);
- $ccount = intval($bbscredits['extcredits' . $ctype]);
- $scount = ceil($duicount * $bbs_scale / $game_scale);
- //远程 查询游戏积分
- if ($Use_remote_mysql) {
- $sql_gamecredits = "select * from `store_players` where authid = '{$steamid32}'";
- $sth = $connect->query($sql_gamecredits);
- if (!$sth) {
- showmessage($plang['alert_couldnot_connect_remote_mysql_server']);
- }
- while ($row = $sth->fetch()) {
- $gamecredit2 = $row['credits'];
- }
- } else {
- //查询本地积分
- $gamecredit2 = DB::result_first("select credits from `store_players` where authid = '{$steamid32}'");
- }
- //远程 查询游戏积分
- if ($ccount < $scount) {
- //积分不足
- showmessage($plang['alert_user_has_nofull']);
- }
- if ($duicount < 1) {
- //积分不足
- showmessage($plang['alert_user_has_nofull']);
- }
- if ($gamecredit2 == "") {
- //如果游戏积分为空 未读取到
- showmessage($plang['alert_nogame_credits'], $url_forward = "{$notbind_url_goto}");
- }
- if (!is_numeric($duiru) || !is_int($duiru)) {
- showmessage($plang['alert_duicount_wrong']);
- }
- // Lengque
- if (!($timestamp = DB::result_first("select timestamp from " . DB::table('plugin_cooldown') . " where uid='" . $_G['uid'] . "'"))) {
- ##如果没有则写入
- $arr = array('uid' => $_G['uid'], 'timestamp' => TIMESTAMP);
- DB::query("insert into " . DB::table('plugin_cooldown') . "(`uid`, `timestamp`) VALUES ('{$arr['uid']}', '{$arr['timestamp']}')");
- } else {
- if ($timestamp = DB::result_first("select timestamp from " . DB::table('plugin_cooldown') . " where uid='" . $_G['uid'] . "'")) {
- if ($timestamp >= TIMESTAMP - $TradeCoolDown) {
- $countdown = $timestamp - (TIMESTAMP - $TradeCoolDown);
- showmessage("上一次操作是成功的! 请间隔 {$countdown} 秒后再操作!");
- } else {
- $Nowtimestamp = TIMESTAMP;
- DB::query("update " . DB::table('plugin_cooldown') . " set timestamp = '{$Nowtimestamp}' where uid='" . $_G['uid'] . "'");
- }
- }
- }
- // Lengque
- //验证积分
- //$zhengquejifen = $OLDBBSCreditsNumber-$duicount;
- // if()
- // $OLDBBSCreditsNumber = $bbscredits['extcredits' . $ctype];
- // $OLDGameCredits = DB::fetch_first("select * from `store_players` where authid = '$steamid32'");
- //
- //加游戏币,扣论坛积分
- if (!$Use_remote_mysql) {
- //不使用远程数据库 则
- $scount && updatemembercount($_G['uid'], array('extcredits' . $ctype => -$scount));
- DB::query("update `store_players` set credits = credits + {$duicount} where authid = '{$steamid32}'");
- credit_log($_G['uid'], "dgm", 16, array('extcredits2' => -$duicount), "test1", "test");
- //LOG
- }
- //PDO
- if ($Use_remote_mysql) {
- //使用远程数据库 则
- $sql_gamecredits = "update `store_players` set credits = credits + {$duicount} where authid = '{$steamid32}'";
- // $sth = $connect->query($sql_gamecredits);
- if (!$connect->exec($sql_gamecredits)) {
- showmessage($plang['alert_couldnot_connect_remote_mysql_server']);
- }
- $scount && updatemembercount($_G['uid'], array('extcredits' . $ctype => -$scount));
- credit_log($_G['uid'], "dgm", 16, array('extcredits2' => -$duicount), "test1", "test");
- //LOG
- }
- //使用远程数据库 结束
- } else {
- showmessage('undefined_action');
- }
- if ($duiru == '2') {
- // $OLDBBSCreditsNumber Credits:$OLDGameCredits
- $bbs_bypass = $OLDBBSCreditsNumber - $duicount;
- $game_bypass = $OLDGameCredits + $duicount;
- $NowBBSCredits = C::t('common_member_count')->fetch($_G['uid']);
- $NowBBSCreditsNumber = $NowBBSCredits['extcredits' . $ctype];
- $NowGameCredits = DB::result_first("select credits from `store_players` where authid = '{$steamid32}'");
- if ($Use_remote_mysql) {
- $sql_gamecredits = "select * from `store_players` where authid = '{$steamid32}'";
- $sth = $connect->query($sql_gamecredits);
- if (!$sth) {
- showmessage($plang['alert_couldnot_connect_remote_mysql_server']);
- }
- while ($row = $sth->fetch()) {
- $NowGameCredits = $row['credits'];
- }
- }
- if ($bbs_bypass == $NowBBSCreditsNumber) {
- $bbs_bypass = "验证积分PASS!";
- } else {
- $repuid = $_G['uid'];
- $bbs_bypass = "积分验证失败!!!";
- //qqlite::sendqun(148942041, "UID:$repuid $bbs_bypass");
- }
- if ($game_bypass == $NowGameCredits) {
- $game_bypass = "验证积分PASS!";
- } else {
- $repuid = $_G['uid'];
- $game_bypass = "积分验证失败!!!";
- // qqlite::sendqun(148942041, "UID$repuid $game_bypass");
- }
- if ($qq_robot_enable && $qq_robot_send_type == 2 || $qq_robot_send_type == 3) {
- $localtime = date('y-m-d H:i:s', time());
- //取现时间
- //消息定义
- $qqmessage = "[CSGO-CN] UID : " . $_G['uid'] . " 论坛id :" . $_G['username'] . " {$steamid64} 操作: {$jifen_title} 兑换 游戏积分 数量:{$duicount} 操作时间:{$localtime} \n 原有信息:\n叶子:{$OLDBBSCreditsNumber} Credits:{$OLDGameCredits} \n现有信息:\n叶子:{$NowBBSCreditsNumber} [{$bbs_bypass}] Credits:{$NowGameCredits} [{$game_bypass}]";
- if ($qq_robot_send_user && ($qq_user = qqlite::getuser($_G['uid']))) {
- //如果QQ用户发送消息给对应号码
- $qq_hao = $qq_user['qq'];
- //$qqusername = $qq_user['username'];
- qqlite::sendqq($qq_hao, $qqmessage);
- //发送到对应QQ
- }
- //发送到admin
- if ($qq_robot_send_admin) {
- $adminqqs = preg_split('/\\r\\n/', $qq_robot_admin_qq);
- //后台 qq逐行读取
- foreach ($adminqqs as $admin_qq) {
- $admin_qq = str_replace(' ', '', $admin_qq);
- //过滤可能的空格
- qqlite::sendqq($admin_qq, $qqmessage);
- }
- }
- }
- }
- //update credits
- //远程 查询游戏积分
- if ($Use_remote_mysql) {
- $sql_gamecredits = "select * from `store_players` where authid = '{$steamid32}'";
- $sth = $connect->query($sql_gamecredits);
- if (!$sth) {
- showmessage($plang['alert_couldnot_connect_remote_mysql_server']);
- }
- while ($row = $sth->fetch()) {
- $gamecredit = $row['credits'];
- }
- } else {
- //查询本地积分
- $gamecredit = DB::result_first("select credits from `store_players` where authid = '{$steamid32}'");
- }
- //远程 查询游戏积分
- $search = array($steamid32full);
- DB::query("update " . DB::table('common_member_count') . " set extcredits8 = " . intval($gamecredit) . " where uid='" . $_G['uid'] . "'");
- showmessage($plang['alert_user_duihuan_suc'], 'home.php?mod=spacecp&ac=plugin&op=credit&id=xnet_steam_credit_gf:steam');
- }
- //远程 查询游戏积分
- if ($Use_remote_mysql) {
- $sql_gamecredits = "select * from `store_players` where authid = '{$steamid32}'";
- $sth = $connect->query($sql_gamecredits);
- if (!$sth) {
- showmessage($plang['alert_couldnot_connect_remote_mysql_server']);
- }
- while ($row = $sth->fetch()) {
- $gamecount = $row['credits'];
- }
- } else {
- //查询本地积分
- $gamecount = DB::result_first("select credits from `store_players` where authid = '{$steamid32}'");
- }
- //远程 查询游戏积分
- $bbscredits = C::t('common_member_count')->fetch($_G['uid']);
- $jifencount = $bbscredits['extcredits' . $ctype];
- function ConvertSteam64To32($oriSteamID64)
- {
- $steamidcha = SteamID::Parse($oriSteamID64, SteamID::FORMAT_STEAMID64);
- $steamid32 = $steamidcha->Format(SteamID::FORMAT_STEAMID32);
- $steamid32 = str_replace("STEAM_1:", "", $steamid32);
- $steamid32 = str_replace("STEAM_0:", "", $steamid32);
- return $steamid32;
- /*
- if (empty($oriSteamID64)) {
- return '';
- }
- return st64to32($oriSteamID64);
- */
- }
- function st64to32($steam_cid)
- {
- $id = array('STEAM_0');
- $id[1] = substr($steam_cid, -1, 1) % 2 == 0 ? 0 : 1;
- $id[2] = bcsub($steam_cid, '76561197960265728');
- if (bccomp($id[2], '0') != 1) {
- return false;
- }
- $id[2] = bcsub($id[2], $id[1]);
- list($id[2], ) = explode('.', bcdiv($id[2], 2), 2);
- return $id[2];
- }
- function SteamAPI_Fetch_PlayerNotInGame($st64)
- {
- global $psetting;
- $daili = stream_context_create(array('http' => array('timeout' => 15, 'proxy' => 'tcp://127.0.0.1:1080', 'request_fulluri' => True)));
- $content = @file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={$psetting['steam_apikey']}&steamids={$st64}&format=json", false, $daili);
- //$content = @file_get_contents("https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$psetting[steam_apikey]&steamids=$st64&format=json");
- if ($content === false) {
- return false;
- }
- $profile = json_decode($content, true);
- if (empty($profile['response']['players'][0]['communityvisibilitystate'])) {
- return false;
- }
- $visibilitystateID = $profile['response']['players'][0]['communityvisibilitystate'];
- //如果资料私人拒绝!
- $IsClientInGame = $profile['response']['players'][0]['gameid'];
- $personastate = $profile['response']['players'][0]['personastate'];
- //在线
- $personastateflags = $profile['response']['players'][0]['personastateflags'];
- //在线类型
- if ($personastateflags === "") {
- return false;
- }
- if ($visibilitystateID == 3 && $IsClientInGame == "" && $personastate == 1 && $personastateflags === 0) {
- return true;
- }
- return false;
- }
- function SteamAPI_Fetch_Player_Reson($st64)
- {
- global $psetting, $plang;
- $daili = stream_context_create(array('http' => array('timeout' => 15, 'proxy' => 'tcp://127.0.0.1:1080', 'request_fulluri' => True)));
- $content = @file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={$psetting['steam_apikey']}&steamids={$st64}&format=json", false, $daili);
- // $content = @file_get_contents("https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$psetting[steam_apikey]&steamids=$st64&format=json");
- if ($content === false) {
- $resons = $plang['alert_couldnot_connect_steamapi_server'];
- return $resons;
- }
- $profile = json_decode($content, true);
- if (empty($profile['response']['players'][0]['communityvisibilitystate'])) {
- $resons = $plang['alert_couldnot_connect_steamapi_server'];
- return $resons;
- }
- $visibilitystateID = $profile['response']['players'][0]['communityvisibilitystate'];
- //如果资料私人拒绝!
- $IsClientInGame = $profile['response']['players'][0]['gameid'];
- $personastate = $profile['response']['players'][0]['personastate'];
- //在线
- $personastateflags = $profile['response']['players'][0]['personastateflags'];
- //在线类型
- if ($visibilitystateID != 3) {
- $resons = $plang['alert_steam_client_profiles_invisible'];
- return $resons;
- }
- if ($IsClientInGame != "") {
- $resons = $plang['alert_steam_client_ingame'];
- return $resons;
- }
- if ($personastateflags > 0) {
- $resons = $plang['alert_steam_client_mobile_online'];
- return $resons;
- }
- if ($personastate != 1) {
- $resons = $plang['alert_steam_client_offline'];
- return $resons;
- }
- return $resons;
- }
- <?php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement