Advertisement
Guest User

Untitled

a guest
Nov 7th, 2017
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.93 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5. if (!defined('IN_DISCUZ')) {
  6.  
  7. exit('Access Denied');
  8.  
  9. }
  10.  
  11. #require_once 'steamid.php';
  12.  
  13. $psetting = $_G['cache']['plugin']['xnet_steam_credit'];
  14.  
  15. $plang = lang('xnet_steam_credit:scriptlang'); //读取配置语言
  16.  
  17.  
  18.  
  19. if(!$_G['uid']) {
  20.  
  21. showmessage($plang['alert_user_login'], NULL, array(), array('login' => 1));
  22.  
  23. }
  24.  
  25.  
  26.  
  27. //Plugin Global Settings.
  28.  
  29. $ctype = intval($psetting['ctype']);
  30.  
  31. $jifen_title = $_G['setting']['extcredits'][$ctype]['title'];
  32.  
  33. $bbs_scale = intval($psetting['bbs_scale']);
  34.  
  35. $game_scale = intval($psetting['game_scale']);
  36.  
  37. $allowtype = intval($psetting['btype']);
  38.  
  39. $settings_tb = $psetting['bbs_credits_tb'];
  40.  
  41. //SteamAPI
  42.  
  43. $steam_apikey = $psetting['steam_apikey'];
  44.  
  45. $steam_apikey_check_steam = $psetting['steam_apikey_check_steam'];
  46.  
  47. $steam_apicheck_type = $psetting['steam_apicheck_type'];
  48.  
  49. //远程数据库设置
  50.  
  51. $Use_remote_mysql = $psetting['remote_mysql'];
  52.  
  53. $remote_host = $psetting['remote_host'];
  54.  
  55. $remote_user = $psetting['remote_user'];
  56.  
  57. $remote_pass = $psetting['remote_pass'];
  58.  
  59. $remote_database = $psetting['remote_database'];
  60.  
  61. //远程数据库
  62.  
  63. //QQ通知变量
  64.  
  65. $qq_robot_enable = $psetting['qq_robot_enable'];
  66.  
  67. $qq_robot_send_user = $psetting['qq_robot_send_user'];
  68.  
  69. $qq_robot_send_admin = $psetting['qq_robot_send_admin'];
  70.  
  71. $qq_robot_admin_qq = $psetting['qq_robot_admin_qq'];
  72.  
  73. $qq_robot_send_type = $psetting['qq_robot_send_type'];
  74.  
  75. //QQ通知
  76.  
  77.  
  78.  
  79. //URL
  80.  
  81. $notbind_url_goto = $psetting['notbind_url_goto'];
  82.  
  83.  
  84.  
  85. if (!$steamid64 = DB::result_first("select steamID64 from " . DB::table('steam_users') . " where uid='" . $_G['uid'] . "'")) {
  86.  
  87. showmessage($plang['alert_user_nosteamid'], $url_forward = "$notbind_url_goto");
  88.  
  89. }
  90.  
  91. if (!$dzuid = DB::result_first("select uid from " . DB::table('steam_users') . " where uid='" . $_G['uid'] . "'")) {
  92.  
  93. showmessage($plang['alert_user_nosteamid'], $url_forward = "$notbind_url_goto");
  94.  
  95. }
  96.  
  97. $steamid32 = ConvertSteam64To32($steamid64);
  98.  
  99.  
  100.  
  101. if ($steam_apikey_check_steam && $steam_apicheck_type == 3) {
  102.  
  103. $NotInGame = SteamAPI_Fetch_PlayerNotInGame($steamid64);
  104.  
  105. if (!$NotInGame) {
  106.  
  107. $reson = SteamAPI_Fetch_Player_Reson($steamid64);
  108.  
  109. showmessage($reson);
  110.  
  111. }
  112.  
  113. }
  114.  
  115. if ($Use_remote_mysql) {
  116. //后台如果开启远程数据库
  117. //PHP连接其他MYSQL
  118. try {
  119. $connect = new PDO("mysql:host={$remote_host};dbname={$remote_database}", $remote_user, $remote_pass);
  120. } catch (PDOException $e) {
  121. showmessage($plang['alert_couldnot_connect_remote_mysql_server']);
  122. }
  123. }
  124.  
  125.  
  126. if (!empty($_GET['formhash'])) {
  127.  
  128. if ($_GET['formhash'] != FORMHASH) {
  129.  
  130. showmessage('undefined_action');
  131.  
  132. }
  133.  
  134. $duiru = intval($_GET['duiru']);
  135.  
  136. $duicount = intval($_GET['duicount']);
  137.  
  138. //$file = fopen("creditslog.txt", "w+");
  139.  
  140. $fangxiang = ("兑换到游戏");
  141.  
  142. $time = date('Y-m-d H:i:s', time());
  143.  
  144. $CTDF_USERINFO["user"] = $discuz_user;
  145.  
  146. if (empty($duiru) || empty($duicount)) { //检验数据
  147.  
  148. showmessage($plang['alert_user_data_isnull']);
  149.  
  150. }
  151.  
  152. if ($duiru == '1') { //游戏币换论坛积分
  153.  
  154. if ($steam_apikey_check_steam && $steam_apicheck_type == 1) {
  155.  
  156. $NotInGame = SteamAPI_Fetch_PlayerNotInGame($steamid64);
  157.  
  158. if (!$NotInGame) {
  159.  
  160. $reson = SteamAPI_Fetch_Player_Reson($steamid64);
  161.  
  162. showmessage($reson);
  163.  
  164. }
  165.  
  166. }
  167.  
  168. if ($allowtype != 0 && $allowtype != 2) {
  169.  
  170. showmessage($plang['alert_dhfx_disble']);
  171.  
  172. }
  173.  
  174. if (!$Use_remote_mysql) {
  175.  
  176. if (!$gamecredits = DB::fetch_first("select * from `store_players` where authid like '%:{$steamid32}'")) {
  177.  
  178. showmessage($plang['alert_user_nosteamid'], $url_forward = "$notbind_url_goto");
  179.  
  180. }
  181.  
  182. }
  183.  
  184. //远程 查询游戏积分
  185.  
  186. if ($Use_remote_mysql) {
  187.  
  188. $sql_gamecredits = "select * from `store_players` where authid like '%:{$steamid32}'";
  189.  
  190. $sth = $connect->query($sql_gamecredits);
  191.  
  192. if (!$sth) {
  193.  
  194. showmessage($plang['alert_couldnot_connect_remote_mysql_server']);
  195.  
  196. }
  197.  
  198. while ($row = $sth->fetch()) {
  199.  
  200. $gamecredits = $row['credits'];
  201.  
  202. }
  203.  
  204. } else
  205.  
  206. //查询本地积分
  207.  
  208. {
  209.  
  210. $gamecredits = DB::result_first("select credits from `store_players` where authid like '%:{$steamid32}'");
  211.  
  212. }
  213.  
  214. //远程 查询游戏积分
  215.  
  216. $scount = ceil($duicount * $game_scale / $bbs_scale);
  217.  
  218. if (intval($gamecredits) < $scount) { //积分不足
  219.  
  220. showmessage($plang['alert_user_has_nofull']);
  221.  
  222. }
  223.  
  224. if (intval($gamecredits['credits']) == "") { //无帐号
  225.  
  226. showmessage($plang['alert_nogame_credits'], $url_forward = "$notbind_url_goto");
  227.  
  228. }
  229.  
  230. if ($duicount < 1) { //积分不足
  231.  
  232. showmessage($plang['alert_user_has_nofull']);
  233.  
  234. }
  235.  
  236. if (!is_numeric($duiru) || !is_int($duiru)) {
  237.  
  238. showmessage($plang['alert_duicount_wrong']);
  239.  
  240. }
  241.  
  242. //通知论坛积分增加
  243.  
  244. if ($qq_robot_enable && $qq_robot_send_type == 1 || $qq_robot_send_type == 3) {
  245.  
  246. $localtime = date('y-m-d H:i:s', time()); //取现时间
  247.  
  248. //消息定义
  249.  
  250. $qqmessage = " UID : " . $_G['uid'] . " 论坛id :" . $_G['username'] . " {$steamid64} 操作:游戏积分兑换 $jifen_title 数量:$duicount 操作时间:$localtime";
  251.  
  252. if ($qq_robot_send_user && $qq_user = qqlite::getuser($_G['uid'])) { //如果QQ用户发送消息给对应号码
  253.  
  254. $qq_hao = $qq_user['qq'];
  255.  
  256. //$qqusername = $qq_user['username'];
  257.  
  258. qqlite::sendqq($qq_hao, $qqmessage); //发送到对应QQ
  259.  
  260.  
  261.  
  262. }
  263.  
  264. //发送到admin
  265.  
  266. if ($qq_robot_send_admin) {
  267.  
  268. $adminqqs = preg_split('/\r\n/', $qq_robot_admin_qq); //后台 qq逐行读取
  269.  
  270. foreach ($adminqqs as $admin_qq) {
  271.  
  272. $admin_qq = str_replace(' ', '', $admin_qq); //过滤可能的空格
  273.  
  274. qqlite::sendqq($admin_qq, $qqmessage);
  275.  
  276. }
  277.  
  278. }
  279.  
  280. }
  281.  
  282. //扣游戏币,加论坛积分
  283.  
  284. //PDO判断 扣除游戏积分增加论坛积分
  285.  
  286. if (!$Use_remote_mysql) //不使用远程数据库 则
  287.  
  288. {
  289.  
  290. $duicount && updatemembercount($_G['uid'], array(
  291.  
  292. 'extcredits' . $ctype => $duicount
  293.  
  294. ));
  295.  
  296. DB::query("update `store_players` set credits = credits - {$scount} where authid like '%:{$steamid32}'");
  297.  
  298. credit_log($_G['uid'], "dgm", 16, array(
  299.  
  300. 'extcredits2' => $scount
  301.  
  302. ) , $customtitle1, "test"); //LOG
  303.  
  304.  
  305.  
  306. }
  307.  
  308. //PDO
  309.  
  310. if ($Use_remote_mysql) //使用远程数据库 则
  311.  
  312. {
  313.  
  314. $sql_gamecredits = "update `store_players` set credits = credits - {$scount} where authid like '%:{$steamid32}'";
  315.  
  316. $sth = $connect->query($sql_gamecredits);
  317.  
  318. if (!$sth) {
  319.  
  320. showmessage($plang['alert_couldnot_connect_remote_mysql_server']);
  321.  
  322. }
  323.  
  324. $duicount && updatemembercount($_G['uid'], array(
  325.  
  326. 'extcredits' . $ctype => $duicount
  327.  
  328. ));
  329.  
  330. credit_log($_G['uid'], "dgm", 16, array(
  331.  
  332. 'extcredits2' => $scount
  333.  
  334. ) , $customtitle1, "test"); //LOG
  335.  
  336.  
  337.  
  338. } //使用远程数据库 结束
  339.  
  340.  
  341.  
  342. } elseif ($duiru == '2') { //积分换游戏币
  343.  
  344. if ($allowtype != 0 && $allowtype != 1) {
  345.  
  346. showmessage($plang['alert_dhfx_disble']);
  347.  
  348. }
  349.  
  350. if ($steam_apikey_check_steam && $steam_apicheck_type == 2) {
  351.  
  352. $NotInGame = SteamAPI_Fetch_PlayerNotInGame($steamid64);
  353.  
  354. if (!$NotInGame) {
  355.  
  356. $reson = SteamAPI_Fetch_Player_Reson($steamid64);
  357.  
  358. showmessage($reson);
  359.  
  360. }
  361.  
  362. }
  363.  
  364. $bbscredits = C::t('common_member_count')->fetch($_G['uid']);
  365.  
  366. $ccount = intval($bbscredits['extcredits' . $ctype]);
  367.  
  368. $scount = ceil($duicount * $bbs_scale / $game_scale);
  369.  
  370. //远程 查询游戏积分
  371.  
  372. if ($Use_remote_mysql) {
  373.  
  374. $sql_gamecredits = "select * from `store_players` where authid like '%:{$steamid32}'";
  375.  
  376. $sth = $connect->query($sql_gamecredits);
  377.  
  378. if (!$sth) {
  379.  
  380. showmessage($plang['alert_couldnot_connect_remote_mysql_server']);
  381.  
  382. }
  383.  
  384. while ($row = $sth->fetch()) {
  385.  
  386. $gamecredit2 = $row['credits'];
  387.  
  388. }
  389.  
  390. } else
  391.  
  392. //查询本地积分
  393.  
  394. {
  395.  
  396. $gamecredit2 = DB::result_first("select credits from `store_players` where authid like '%:{$steamid32}'");
  397.  
  398. }
  399.  
  400. //远程 查询游戏积分
  401.  
  402. if ($ccount < $scount) { //积分不足
  403.  
  404. showmessage($plang['alert_user_has_nofull']);
  405.  
  406. }
  407.  
  408. if ($duicount < 1) { //积分不足
  409.  
  410. showmessage($plang['alert_user_has_nofull']);
  411.  
  412. }
  413.  
  414. if ($gamecredit2 == "") { //如果游戏积分为空 未读取到
  415.  
  416. showmessage($plang['alert_nogame_credits'], $url_forward = "$notbind_url_goto");
  417.  
  418. }
  419.  
  420. if (!is_numeric($duiru) || !is_int($duiru)) {
  421.  
  422. showmessage($plang['alert_duicount_wrong']);
  423.  
  424. }
  425.  
  426. if ($qq_robot_enable && $qq_robot_send_type == 2 || $qq_robot_send_type == 3) {
  427.  
  428. $localtime = date('y-m-d H:i:s', time()); //取现时间
  429.  
  430. //消息定义
  431.  
  432. $qqmessage = " UID : " . $_G['uid'] . " 论坛id :" . $_G['username'] . " {$steamid64} 操作: $jifen_title 兑换 游戏积分 数量:$duicount 操作时间:$localtime";
  433.  
  434. if ($qq_robot_send_user && $qq_user = qqlite::getuser($_G['uid'])) { //如果QQ用户发送消息给对应号码
  435.  
  436. $qq_hao = $qq_user['qq'];
  437.  
  438. //$qqusername = $qq_user['username'];
  439.  
  440. qqlite::sendqq($qq_hao, $qqmessage); //发送到对应QQ
  441.  
  442.  
  443.  
  444. }
  445.  
  446. //发送到admin
  447.  
  448. if ($qq_robot_send_admin) {
  449.  
  450. $adminqqs = preg_split('/\r\n/', $qq_robot_admin_qq); //后台 qq逐行读取
  451.  
  452. foreach ($adminqqs as $admin_qq) {
  453.  
  454. $admin_qq = str_replace(' ', '', $admin_qq); //过滤可能的空格
  455.  
  456. qqlite::sendqq($admin_qq, $qqmessage);
  457.  
  458. }
  459.  
  460. }
  461.  
  462. }
  463.  
  464. //加游戏币,扣论坛积分
  465.  
  466. if (!$Use_remote_mysql) //不使用远程数据库 则
  467.  
  468. {
  469.  
  470. $scount && updatemembercount($_G['uid'], array(
  471.  
  472. 'extcredits' . $ctype => - $scount
  473.  
  474. ));
  475.  
  476. DB::query("update `store_players` set credits = credits + {$duicount} where authid like '%:{$steamid32}'");
  477.  
  478. credit_log($_G['uid'], "dbb", 16, array(
  479.  
  480. 'extcredits2' => -$scount
  481.  
  482. ) , "test1", "test"); //LOG
  483.  
  484.  
  485.  
  486.  
  487.  
  488. }
  489.  
  490. //PDO
  491.  
  492. if ($Use_remote_mysql) //使用远程数据库 则
  493.  
  494. {
  495.  
  496. $sql_gamecredits = "update `store_players` set credits = credits + {$duicount} where authid like '%:{$steamid32}'";
  497.  
  498. if (!$connect->exec($sql_gamecredits)) {
  499. showmessage($plang['alert_couldnot_connect_remote_mysql_server']);
  500. }
  501.  
  502. $scount && updatemembercount($_G['uid'], array(
  503.  
  504. 'extcredits' . $ctype => - $scount
  505.  
  506. ));
  507.  
  508. credit_log($_G['uid'], "dbb", 16, array(
  509.  
  510. 'extcredits2' => -$scount
  511.  
  512. ) , "test1", "test"); //LOG
  513.  
  514.  
  515.  
  516. } //使用远程数据库 结束
  517.  
  518.  
  519.  
  520. } else {
  521.  
  522. showmessage('undefined_action');
  523.  
  524. }
  525.  
  526. //update credits
  527.  
  528. //远程 查询游戏积分
  529.  
  530. if ($Use_remote_mysql) {
  531.  
  532. $sql_gamecredits = "select * from `store_players` where authid like '%:{$steamid32}'";
  533.  
  534. if (!$connect->exec($sql_gamecredits)) {
  535. showmessage($plang['alert_couldnot_connect_remote_mysql_server']);
  536. }
  537.  
  538. while ($row = $sth->fetch()) {
  539.  
  540. $gamecredit = $row['credits'];
  541.  
  542. }
  543.  
  544. } else
  545.  
  546. //查询本地积分
  547.  
  548. {
  549.  
  550. $gamecredit = DB::result_first("select credits from `store_players` where authid like '%:{$steamid32}'");
  551.  
  552. }
  553.  
  554. //远程 查询游戏积分
  555.  
  556. $search = array(
  557.  
  558. $steamid32full
  559.  
  560. );
  561.  
  562.  
  563.  
  564. if($settings_tb != 3)
  565.  
  566. {
  567.  
  568. DB::query("update " . DB::table('common_member_count') . " set extcredits8 = " . intval($gamecredit) . " where uid='" . $_G['uid'] . "'");
  569.  
  570. showmessage($plang['alert_user_duihuan_suc'], 'home.php?mod=spacecp&ac=plugin&op=credit&id=xnet_steam_credit:steam');
  571.  
  572. }
  573.  
  574. }
  575.  
  576. //远程 查询游戏积分
  577.  
  578. if ($Use_remote_mysql) {
  579.  
  580. $sql_gamecredits = "select * from `store_players` where authid like '%:{$steamid32}'";
  581.  
  582. $sth = $connect->query($sql_gamecredits);
  583.  
  584. if (!$sth) {
  585.  
  586. showmessage($plang['alert_couldnot_connect_remote_mysql_server']);
  587.  
  588. }
  589.  
  590. while ($row = $sth->fetch()) {
  591.  
  592. $gamecount = $row['credits'];
  593.  
  594. }
  595.  
  596. } else
  597.  
  598. //查询本地积分
  599.  
  600. {
  601.  
  602. $gamecount = DB::result_first("select credits from `store_players` where authid like '%:{$steamid32}'");
  603.  
  604. }
  605.  
  606. //远程 查询游戏积分
  607.  
  608. $bbscredits = C::t('common_member_count')->fetch($_G['uid']);
  609.  
  610. $jifencount = $bbscredits['extcredits' . $ctype];
  611.  
  612. function ConvertSteam64To32($oriSteamID64) {
  613.  
  614. if (empty($oriSteamID64)) {
  615.  
  616. return '';
  617.  
  618. }
  619.  
  620. return st64to32($oriSteamID64);
  621.  
  622. }
  623.  
  624. function st64to32($steam_cid) {
  625.  
  626. $id = array(
  627.  
  628. 'STEAM_0'
  629.  
  630. );
  631.  
  632. $id[1] = substr($steam_cid, -1, 1) % 2 == 0 ? 0 : 1;
  633.  
  634. $id[2] = bcsub($steam_cid, '76561197960265728');
  635.  
  636. if (bccomp($id[2], '0') != 1) {
  637.  
  638. return false;
  639.  
  640. }
  641.  
  642. $id[2] = bcsub($id[2], $id[1]);
  643.  
  644. list($id[2],) = explode('.', bcdiv($id[2], 2) , 2);
  645.  
  646. return $id[2];
  647.  
  648. }
  649.  
  650. function SteamAPI_Fetch_PlayerNotInGame($st64) {
  651.  
  652. global $psetting;
  653.  
  654. $content = @file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$psetting[steam_apikey]&steamids=$st64&format=json");
  655.  
  656. if ($content === false) return false;
  657.  
  658. $profile = json_decode($content, true);
  659.  
  660. if (empty($profile['response']['players'][0]['communityvisibilitystate'])) {
  661.  
  662. return false;
  663.  
  664. }
  665.  
  666. $visibilitystateID = $profile['response']['players'][0]['communityvisibilitystate']; //如果资料私人拒绝!
  667.  
  668. $IsClientInGame = $profile['response']['players'][0]['gameid'];
  669.  
  670. $personastate = $profile['response']['players'][0]['personastate']; //在线
  671.  
  672. $personastateflags = $profile['response']['players'][0]['personastateflags']; //在线类型
  673.  
  674. if($personastateflags === ""){
  675.  
  676. return false;
  677.  
  678. }
  679.  
  680. if ($visibilitystateID == 3 && $IsClientInGame == "" && $personastate == 1 && $personastateflags === 0) {
  681.  
  682. return true;
  683.  
  684. }
  685.  
  686. return false;
  687.  
  688. }
  689.  
  690. function SteamAPI_Fetch_Player_Reson($st64) {
  691.  
  692. global $psetting,$plang;
  693.  
  694. $content = @file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$psetting[steam_apikey]&steamids=$st64&format=json");
  695.  
  696. if ($content === false) {
  697.  
  698. $resons = $plang['alert_couldnot_connect_steamapi_server'];
  699.  
  700. return $resons;
  701.  
  702. }
  703.  
  704. $profile = json_decode($content, true);
  705.  
  706. if (empty($profile['response']['players'][0]['communityvisibilitystate'])) {
  707.  
  708. $resons = $plang['alert_couldnot_connect_steamapi_server'];
  709.  
  710. return $resons;
  711.  
  712. }
  713.  
  714. $visibilitystateID = $profile['response']['players'][0]['communityvisibilitystate']; //如果资料私人拒绝!
  715.  
  716. $IsClientInGame = $profile['response']['players'][0]['gameid'];
  717.  
  718. $personastate = $profile['response']['players'][0]['personastate']; //在线
  719.  
  720. $personastateflags = $profile['response']['players'][0]['personastateflags']; //在线类型
  721.  
  722.  
  723.  
  724. if ($visibilitystateID != 3) {
  725.  
  726. $resons = $plang['alert_steam_client_profiles_invisible'];
  727.  
  728. return $resons;
  729.  
  730. }
  731.  
  732. if ($IsClientInGame != "") {
  733.  
  734. $resons = $plang['alert_steam_client_ingame'];
  735.  
  736. return $resons;
  737.  
  738. }
  739.  
  740. if ($personastateflags > 0)
  741.  
  742. {
  743.  
  744. $resons = $plang['alert_steam_client_mobile_online'];
  745.  
  746. return $resons;
  747.  
  748. }
  749.  
  750. if ($personastate != 1) {
  751.  
  752. $resons = $plang['alert_steam_client_offline'];
  753.  
  754. return $resons;
  755.  
  756. }
  757.  
  758. return $resons;
  759.  
  760. }
  761.  
  762. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement