-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprmod.php
More file actions
137 lines (129 loc) · 4.15 KB
/
prmod.php
File metadata and controls
137 lines (129 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
* This class is used to get data from PR Spy
* @author Illution <support@illution.dk>
* @license https://illution.dk/copyright Copyrights Illution © 2012, All rights reserved
* @package Project Reality Mod
* @category Project Reality Mod
* @subpackage PR Spy
* @link http://www.realitymod.com/prspy/ Project Reality BF 2 Spy
* @link http://www.realitymod.com/pra2spy/ Project Reality ARMA 2 Spy
* @version 1.0
* @author Illution <support@illution.dk>
*/
class PRMod{
/**
* The url to the document containing the current PR BF 2 servers, with players
* @var string
* @access private
* @static
* @since 1.0
*/
private $PR_BF2_SERVERS = "http://www.realitymod.com/prspy/currentservers.jsonp";
/**
* The url to the document containing the list of online PR BF 2 players online
* @var string
* @access private
* @static
* @since 1.0
*/
private $PR_BF2_PLAYERS = "http://www.realitymod.com/prspy/currentplayers.jsonp";
/**
* The url to the PR ARMA 2 document containing, the current servers, with players online
* @var string
* @access private
* @static
* @since 1.0
*/
private $PR_ARMA2_SERVERS = "http://www.realitymod.com/pra2spy/currentserversarma2.jsonp";
/**
* The url to the document containing the current PR ARMA 2 online players
* @var string
* @access private
* @since 1.0
* @static
*/
private $PR_ARMA2_PLAYERS = "http://www.realitymod.com/pra2spy/currentplayersarma2.jsonp";
/**
* The class constructor
* @since 1.0
* @access public
*/
public function __construct(){}
/**
* This function gets the current servers which has players on, depending on which game is selected
* @param string $Game The PR game to get the current servers for values are "BF2" or "ARMA2"
* @param boolean $Assoc If assoc is true the data is converted to an associative array
* @return array|object|boolean FALSE is returned if the operation fails else is an object returned if Assoc is false,
* and an array is returned if Assoc is true
* @access public
* @since 1.0
*/
public function GetCurrentServers($Game = "BF2",$Assoc = false){
if($Game == "BF2"){
$Raw = file_get_contents($this->PR_BF2_SERVERS);
} elseif($Game == "ARMA2"){
$Raw = file_get_contents($this->PR_ARMA2_SERVERS);
}
$Data = self::jsonp_decode($Raw,$Assoc,true);
if($Data !== false && $Data != ""){
return $Data;
} else {
return false;
}
}
/**
* This function gets the current players online, depending on which game is selected
* @param string $Game The PR game to get the current players for values are "BF2" or "ARMA2"
* @param boolean $Assoc If assoc is true the data is converted to an associative array
* @return array|object|boolean FALSE is returned if the operation fails else is an object returned if Assoc is false,
* and an array is returned if Assoc is true
* @access public
* @since 1.0
*/
public function GetCurrentPlayers($Game = "BF2",$Assoc = false){
if($Game == "BF2"){
$Raw = file_get_contents($this->PR_BF2_PLAYERS);
} elseif($Game == "ARMA2"){
$Raw = file_get_contents($this->PR_ARMA2_PLAYERS);
}
$Data = self::jsonp_decode($Raw,$Assoc,true);
if($Data !== false && $Data != ""){
return $Data;
} else {
return false;
}
}
/**
* This function converts a JSONP string to a std object
* @param string $Jsonp The JSONP string to decode
* @param boolean $Assoc If this flag is set to true, then the data will be converted to an array
* @param boolean $Strict If this parameter is true, then some known errors is corrected
* @return array||object|boolean
* @since 1.0
* @access private
* @link http://codepad.org/eJXeaXIO The JSONP decode function
*/
private function jsonp_decode($Jsonp = NULL, $Assoc = false,$Strict = false) {
if(!is_null($Jsonp)){
if ($Jsonp[0] !== '[' && $Jsonp[0] !== '{') {
$Jsonp = substr($Jsonp, strpos($Jsonp, '('));
}
$Data = trim($Jsonp,'();');
if($Strict){
$Data = str_replace('],
],
"', ']],"', $Data);
$Data = str_replace('",
},', '"},', $Data);
$Data = str_replace('",
}
}', '"}}', $Data);
}
return json_decode($Data, $Assoc);
} else {
return false;
}
}
}
?>