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'];
- $plang = lang('xnet_steam_credit:scriptlang'); //读取配置语言
- if(!$_G['uid']) {
- showmessage($plang['alert_user_login'], NULL, array(), array('login' => 1));
- }
- //Plugin Global Settings.
- $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']);
- $settings_tb = $psetting['bbs_credits_tb'];
- //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通知
- //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']);
- }
- }
- 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 ($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 like '%:{$steamid32}'")) {
- showmessage($plang['alert_user_nosteamid'], $url_forward = "$notbind_url_goto");
- }
- }
- //远程 查询游戏积分
- if ($Use_remote_mysql) {
- $sql_gamecredits = "select * from `store_players` where authid like '%:{$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 like '%:{$steamid32}'");
- }
- //远程 查询游戏积分
- $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']);
- }
- //通知论坛积分增加
- if ($qq_robot_enable && $qq_robot_send_type == 1 || $qq_robot_send_type == 3) {
- $localtime = date('y-m-d H:i:s', time()); //取现时间
- //消息定义
- $qqmessage = " UID : " . $_G['uid'] . " 论坛id :" . $_G['username'] . " {$steamid64} 操作:游戏积分兑换 $jifen_title 数量:$duicount 操作时间:$localtime";
- 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);
- }
- }
- }
- //扣游戏币,加论坛积分
- //PDO判断 扣除游戏积分增加论坛积分
- if (!$Use_remote_mysql) //不使用远程数据库 则
- {
- $duicount && updatemembercount($_G['uid'], array(
- 'extcredits' . $ctype => $duicount
- ));
- DB::query("update `store_players` set credits = credits - {$scount} where authid like '%:{$steamid32}'");
- credit_log($_G['uid'], "dgm", 16, array(
- 'extcredits2' => $scount
- ) , $customtitle1, "test"); //LOG
- }
- //PDO
- if ($Use_remote_mysql) //使用远程数据库 则
- {
- $sql_gamecredits = "update `store_players` set credits = credits - {$scount} where authid like '%:{$steamid32}'";
- $sth = $connect->query($sql_gamecredits);
- if (!$sth) {
- showmessage($plang['alert_couldnot_connect_remote_mysql_server']);
- }
- $duicount && updatemembercount($_G['uid'], array(
- 'extcredits' . $ctype => $duicount
- ));
- credit_log($_G['uid'], "dgm", 16, array(
- 'extcredits2' => $scount
- ) , $customtitle1, "test"); //LOG
- } //使用远程数据库 结束
- } 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 like '%:{$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 like '%:{$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']);
- }
- if ($qq_robot_enable && $qq_robot_send_type == 2 || $qq_robot_send_type == 3) {
- $localtime = date('y-m-d H:i:s', time()); //取现时间
- //消息定义
- $qqmessage = " UID : " . $_G['uid'] . " 论坛id :" . $_G['username'] . " {$steamid64} 操作: $jifen_title 兑换 游戏积分 数量:$duicount 操作时间:$localtime";
- 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);
- }
- }
- }
- //加游戏币,扣论坛积分
- if (!$Use_remote_mysql) //不使用远程数据库 则
- {
- $scount && updatemembercount($_G['uid'], array(
- 'extcredits' . $ctype => - $scount
- ));
- DB::query("update `store_players` set credits = credits + {$duicount} where authid like '%:{$steamid32}'");
- credit_log($_G['uid'], "dbb", 16, array(
- 'extcredits2' => -$scount
- ) , "test1", "test"); //LOG
- }
- //PDO
- if ($Use_remote_mysql) //使用远程数据库 则
- {
- $sql_gamecredits = "update `store_players` set credits = credits + {$duicount} where authid like '%:{$steamid32}'";
- 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'], "dbb", 16, array(
- 'extcredits2' => -$scount
- ) , "test1", "test"); //LOG
- } //使用远程数据库 结束
- } else {
- showmessage('undefined_action');
- }
- //update credits
- //远程 查询游戏积分
- if ($Use_remote_mysql) {
- $sql_gamecredits = "select * from `store_players` where authid like '%:{$steamid32}'";
- if (!$connect->exec($sql_gamecredits)) {
- 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 like '%:{$steamid32}'");
- }
- //远程 查询游戏积分
- $search = array(
- $steamid32full
- );
- if($settings_tb != 3)
- {
- 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:steam');
- }
- }
- //远程 查询游戏积分
- if ($Use_remote_mysql) {
- $sql_gamecredits = "select * from `store_players` where authid like '%:{$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 like '%:{$steamid32}'");
- }
- //远程 查询游戏积分
- $bbscredits = C::t('common_member_count')->fetch($_G['uid']);
- $jifencount = $bbscredits['extcredits' . $ctype];
- function ConvertSteam64To32($oriSteamID64) {
- 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;
- $content = @file_get_contents("http://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;
- $content = @file_get_contents("http://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;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement