-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinc.common.php
More file actions
273 lines (250 loc) · 11 KB
/
inc.common.php
File metadata and controls
273 lines (250 loc) · 11 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php
function writeErrorLog($PageName, $Section, $Message){
$LogDate = date("Ymd");
$MsgDate = date("Y-m-d H:i:s");
$RemoteAddr = "REMOTE_ADDR: ";
if(isset($_SERVER["REMOTE_ADDR"])){
$RemoteAddr .= $_SERVER["REMOTE_ADDR"];
}
$HttpUserAgent = "HTTP_USER_AGENT: ";
if(isset($_SERVER["HTTP_USER_AGENT"])){
$HttpUserAgent .= $_SERVER["HTTP_USER_AGENT"];
}
if(file_exists($GLOBALS["logfileFolder"]) === false){
mkdir($GLOBALS["logfileFolder"], 0600, true);
}
error_log("\"" . $MsgDate . "\";\"" . $Section . "\";\"" . $Message . "\";\"" . $RemoteAddr . "\";\"" . $HttpUserAgent . "\"\r\n", 3, $GLOBALS["logfileFolder"] . "/" . $LogDate . "." . $PageName . ".error.log");
}
function dtmNow(){
return date("l, d. F Y (G:i:s T)");
}
function formatLapTime($LapTime){
if($LapTime > 0){
return sprintf("%d:%06.3F", floor($LapTime / 60), fmod($LapTime, 60));
}else{
return $LapTime;
}
}
function formatTemp($Temperatur){
return number_format($Temperatur, 1, ".", "");
}
function formatLapDist($LapDist){
return number_format($LapDist, 1, ".", "");
}
function formatWetness($Wetness){
return number_format($Wetness * 100, 1, ".", "");
}
function formatStartTime($StartTime){
if($StartTime != 0){
$arrStartTime = explode("-", $StartTime);
return $arrStartTime[2] . "." . $arrStartTime[1] . "." . $arrStartTime[0] . " (" . $arrStartTime[3] . ":" .$arrStartTime[4] . ":" .$arrStartTime[5] . ") " . date("T");
}else{
return "<span class='redbold'>No Session Data</span>";
}
}
function formatUptime($ServerStart, $ServerStatus){
if($ServerStart != "0" && $ServerStatus != "0"){
$arrServerStart = explode("-", $ServerStart);
$ServerUptime = strtotime("now") - strtotime($arrServerStart[2] . "." . $arrServerStart[1] . "." . $arrServerStart[0] . " " . $arrServerStart[3] . ":" .$arrServerStart[4] . ":" .$arrServerStart[5]);
$upD = floor($ServerUptime / 86400);
$upH = floor(($ServerUptime - (86400 * $upD)) / 3600);
$upM = floor(($ServerUptime % 3600) / 60);
$upS = floor($ServerUptime % 60);
return sprintf("%02d:%02d:%02d", $upD, $upH, $upM);
}else{
return "<span class='redbold'>No Session Data</span>";
}
}
function formatInGameTime($InGameTime){
if($InGameTime > 0){
$inH = floor($InGameTime / 60);
$inM = floor($InGameTime % 60);
$inS = floor(((fmod($InGameTime, 60)) - $inM) * 60);
return sprintf("%02d:%02d:%02d", $inH, $inM, $inS);
}else{
return "00:00:00";
}
}
function formatSessionTime($SessionTime){
if($SessionTime > 0){
$stH = floor($SessionTime / 3600);
$stM = floor(($SessionTime % 3600) / 60);
$stS = floor(((fmod($SessionTime, 3600) / 60) - $stM) * 60);
return sprintf("%02d:%02d:%02d", $stH, $stM, $stS);
}else{
return "00:00:00";
}
}
function setSessionName($SessionID, $GameID){
$SessionName = "Unknown";
if($GameID == 1){
switch($SessionID){
case 0: $SessionName = "Test Day"; break;
case 1: $SessionName = "Practice 1"; break;
case 2: $SessionName = "Practice 2"; break;
case 3: $SessionName = "Practice 3"; break;
case 4: $SessionName = "Practice 4"; break;
case 5: $SessionName = "Qualifying"; break;
case 6: $SessionName = "Warmup"; break;
case 7: $SessionName = "Race"; break;
default: $SessionName = "Unknown"; break;
}
}
if($GameID == 2){
switch($SessionID){
case 0: $SessionName = "Test Day"; break;
case 1: $SessionName = "Practice 1"; break;
case 2: $SessionName = "Practice 2"; break;
case 3: $SessionName = "Practice 3"; break;
case 4: $SessionName = "Practice 4"; break;
case 5: $SessionName = "Qualifying 1"; break;
case 6: $SessionName = "Qualifying 2"; break;
case 7: $SessionName = "Qualifying 3"; break;
case 8: $SessionName = "Qualifying 4"; break;
case 9: $SessionName = "Warmup"; break;
case 10: $SessionName = "Race 1"; break;
case 11: $SessionName = "Race 2"; break;
case 12: $SessionName = "Race 3"; break;
case 13: $SessionName = "Race 4"; break;
default: $SessionName = "Unknown"; break;
}
}
return $SessionName;
}
function setSessionState($SessionStateID){
$SessionState = "Unknown";
switch($SessionStateID){
case 0: $SessionState = "Before Session"; break;
case 1: $SessionState = "Recon Lap"; break;
case 2: $SessionState = "Grid walk-through"; break;
case 3: $SessionState = "Formation Lap"; break;
case 4: $SessionState = "Countdown..."; break;
case 5: $SessionState = "Green Flag"; break;
case 6: $SessionState = "Full Course Yellow"; break;
case 7: $SessionState = "Session Stopped"; break;
case 8: $SessionState = "Finished"; break;
default: $SessionState = "Unknown"; break;
}
return $SessionState;
}
function setTrackState($TrackStateID){
$TrackState = "Unknown";
switch($TrackStateID){
case -1: $TrackState = "Invalid"; break;
case 0: $TrackState = "Clear"; break;
case 1: $TrackState = "Pending..."; break;
case 2: $TrackState = "Pits closed"; break;
case 3: $TrackState = "Pit lead lap"; break;
case 4: $TrackState = "Pits open"; break;
case 5: $TrackState = "Last Lap"; break;
case 6: $TrackState = "Resume..."; break;
case 7: $TrackState = "Race halted"; break;
default: $TrackState = "Unknown"; break;
}
return $TrackState;
}
function setVehicleControl($VehicleControlID){
$VehicleControl = "Unknown";
switch($VehicleControlID){
case -1: $VehicleControl = "Nobody"; break;
case 0: $VehicleControl = "Local"; break;
case 1: $VehicleControl = "AI"; break;
case 2: $VehicleControl = "Remote"; break;
case 3: $VehicleControl = "Replay"; break;
default: $VehicleControl = "Unknown"; break;
}
return $VehicleControl;
}
function setFinishStatus($FinishStatusID){
$FinishStatus = "Unknown";
switch($FinishStatusID){
case -1: $FinishStatus = "<span class='finish-status-out'>DIS</span>"; break;
case 0: $FinishStatus = "<span class=''></span>"; break;
case 1: $FinishStatus = "<span class='finish-status-checkeredflag'> </span>"; break;
case 2: $FinishStatus = "<span class='finish-status-out'>DNF</span>"; break;
case 3: $FinishStatus = "<span class='finish-status-out'>DQ</span>"; break;
default: $FinishStatus = "Unk"; break;
}
return $FinishStatus;
}
function validateNameVars($StringSubject){
// -- $StringPattern = "([\"\$\/\*\'\<\>\;])";
$StringPattern = "([\"\$\/\*\<\>\;])";
if($StringSubject != ""){
// -- echo preg_match($StringPattern, trim($StringSubject)); // -- debug only
if(preg_match($StringPattern, trim($StringSubject)) == 1){
return false;
}else{
return true;
}
}else{
return true;
}
}
function sqlGetServerStats($mySQLiConn){
$ServerStats["GameID"] = 0;
$ServerStats["ServerState"] = 0;
$ServerStats["SessionStart"] = 0;
$ServerStats["SessionID"] = 0;
$ServerStats["SessionState"] = 0;
$ServerStats["SessionTime"] = 0;
$ServerStats["SessionEnd"] = 0;
$ServerStats["CurLaps"] = 0;
$ServerStats["MaxLaps"] = 0;
$ServerStats["NumVehicles"] = 0;
$ServerStats["TrackName"] = "No Session";
$ServerStats["AmbientTemp"] = 0;
$ServerStats["TrackTemp"] = 0;
if(!$mySQLiConn->connect_error){
$selectSessionInfos = "SELECT SQL_CACHE * FROM `sessioninfos` LIMIT 1";
if($resultSessionInfos = $mySQLiConn->query($selectSessionInfos)){
if($resultSessionInfos->num_rows == 1){
while($rowSessionInfos = $resultSessionInfos->fetch_assoc()){
$ServerStats["GameID"] = $rowSessionInfos["GameID"];
$ServerStats["ServerState"] = $rowSessionInfos["ServerState"];
$ServerStats["SessionStart"] = $rowSessionInfos["SessionStart"];
$ServerStats["SessionID"] = $rowSessionInfos["SessionID"];
$ServerStats["SessionState"] = $rowSessionInfos["SessionState"];
$ServerStats["SessionTime"] = $rowSessionInfos["SessionTime"];
$ServerStats["SessionEnd"] = $rowSessionInfos["SessionEnd"];
$ServerStats["CurLaps"] = $rowSessionInfos["CurLaps"];
$ServerStats["MaxLaps"] = $rowSessionInfos["MaxLaps"];
$ServerStats["NumVehicles"] = $rowSessionInfos["NumVehicles"];
$ServerStats["TrackName"] = $rowSessionInfos["TrackName"];
$ServerStats["AmbientTemp"] = $rowSessionInfos["AmbientTemp"];
$ServerStats["TrackTemp"] = $rowSessionInfos["TrackTemp"];
}
}
$resultSessionInfos->free();
}else{
writeErrorLog("inc.common.php", "sqlGetServerStats()", "Error: (" . $mySQLiConn->error . ") Query: (" . $selectSessionInfos . ")");
}
}else{
writeErrorLog("inc.common.php", "sqlGetServerStats()", "Error: (" . $mySQLiConn->connect_error . ")");
}
return $ServerStats;
}
function genPassword($length = 8){
// -- $dummy = array_merge(range("0", "9"), range("a", "z"), range("A", "Z"), array("#", "&" , "@", "$", "_", "%", "?", "+", "-"));
$dummy = array_merge(range("0", "9"), range("a", "z"), range("A", "Z"));
// -- shuffle array
mt_srand((double)microtime() * 1000000);
for($i = 1; $i <= (count($dummy) * 2); $i++){
$swap = mt_rand(0, count($dummy) - 1);
$tmp = $dummy[$swap];
$dummy[$swap] = $dummy[0];
$dummy[0] = $tmp;
}
// -- get password
return substr(implode("", $dummy), 0, $length);
}
function mapRotate90($RotationAngle){
if($RotationAngle < -360.0){$RotationAngle = -360.0;}
if($RotationAngle > 360.0){$RotationAngle = 360.0;}
if($RotationAngle < 0.0){$RotationAngle *= -1;}
if($RotationAngle > 90.0 && $RotationAngle <= 180.0){$RotationAngle = 90 - ($RotationAngle - 90);}
if($RotationAngle > 180.0 && $RotationAngle <= 270.0){$RotationAngle = ($RotationAngle - 180);}
if($RotationAngle > 270.0 && $RotationAngle <= 360.0){$RotationAngle = 90 - ($RotationAngle - 270);}
return $RotationAngle;
}
?>