1
0

functions.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2018 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. function toCommunityID($id){
  25. if(preg_match('/^STEAM_/', $id)){
  26. $parts = explode(':', $id);
  27. return bcadd(bcadd(bcmul($parts[2], '2'), '76561197960265728'), $parts[1]);
  28. }elseif(is_numeric($id) && strlen($id) < 16){
  29. return bcadd($id, '76561197960265728');
  30. }else{
  31. return $id;
  32. }
  33. }
  34. function toSteamID($id){
  35. if(is_numeric($id) && strlen($id) >= 16){
  36. $z = bcdiv(bcsub($id, '76561197960265728'), '2');
  37. }elseif(is_numeric($id)){
  38. $z = bcdiv($id, '2');
  39. }else{
  40. return $id;
  41. }
  42. $y = bcmod($id, '2');
  43. return 'STEAM_0:'.$y.':'.floor($z);
  44. }
  45. function toUserID($id){
  46. if(preg_match('/^STEAM_/', $id)){
  47. $split = explode(':', $id);
  48. return $split[2] * 2 + $split[1];
  49. }elseif(preg_match('/^765/', $id) && strlen($id) > 15){
  50. return bcsub($id, '76561197960265728');
  51. }else{
  52. return $id;
  53. }
  54. }
  55. function getSteamId($input){
  56. $xml = simplexml_load_file('http://steamcommunity.com/id/'.$input.'?xml=1');
  57. $steamId64 = $xml->steamID64;
  58. if(preg_match('/^765/', $steamId64) === 0){
  59. return false;
  60. }else{
  61. return (string)$steamId64; // Cast it to a string, otherwise an SimpleXMLElement Object will be returned.
  62. }
  63. }
  64. function convert($id){
  65. if(preg_match('/^\[U:1:[0-9]+\]/', $id)){
  66. $id = substr($id, 5, -1);
  67. }
  68. // Check if the input is in legacyId, communityId, or SteamId3 format.
  69. // If it's not, assume it's a custom Id and attempt to get the communityId from what the user entered.
  70. if(preg_match('/^STEAM_[01]:[01]:\d+$/', $id) === 0 && preg_match('/^[0-9]/', $id) === 0 && preg_match('/^765/', $id) === 0){
  71. if(($steamId = getSteamId($id)) === false){
  72. return json_encode(array());
  73. }
  74. $id = $steamId;
  75. }
  76. echo json_encode(array(
  77. 'communityId' => toCommunityID($id),
  78. 'steamId' => toSteamID($id),
  79. 'steamId3' => '[U:1:'.toUserID($id).']',
  80. 'steamProfile' => '<a href="http://steamcommunity.com/profiles/'.toCommunityID($id).'">Steam Profile</a>',
  81. ));
  82. }
  83. // Get gameservers belonging to each user with matching permissions if they're not an admin.
  84. function getUserServers($servers, $flags, $supportedGames){
  85. global $db;
  86. $info = array();
  87. $userInfo = $db->getUserById($_SESSION['user_id']);
  88. $userRole = $userInfo['users_role'];
  89. if(!empty($servers)){
  90. foreach($servers as $server){
  91. $gamehome = $db->getUserGameHome($_SESSION['user_id'], $server['home_id']);
  92. if(in_array($gamehome['game_name'], $supportedGames) === true){
  93. if($userRole !== 'admin'){
  94. if(strpbrk($gamehome['access_rights'], $flags) !== false){
  95. $info[] = $server;
  96. }
  97. }else{
  98. $info[] = $server;
  99. }
  100. }
  101. }
  102. }
  103. return $info;
  104. }
  105. ?>