forked from sbpp/sourcebans-pp
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsb_debug_connection.php
More file actions
541 lines (469 loc) · 20.7 KB
/
sb_debug_connection.php
File metadata and controls
541 lines (469 loc) · 20.7 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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
<?php
// SourceBans++ (c) 2014-2026 SourceBans++ Dev Team
// Licensed under the Elastic License 2.0.
// See LICENSE.txt for the full license text and THIRD-PARTY-NOTICES.txt for attributions.
/**
* SourceBans "Error Connecting()" Debug
* Checks for the ports being forwarded correctly
*/
/**
* Config part
* Change to IP and port of the gameserver you want to test
*/
$serverip = "";
$serverport = "";
$serverrcon = ""; // Leave empty if you're only testing the serverinfo connection
/*******
* Don't change below here
*******/
// Track errors for dynamic troubleshooting
$errors = [];
// Validate server IP and port
if (empty($serverip)) {
$errors[] = "no_server_ip";
}
// Use default port if not specified
if (empty($serverport)) {
$serverport = 27015;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SourceBans++ Connection Debug</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
line-height: 1.6;
color: #333;
background-color: #f0f0f0;
margin: 0;
padding: 20px;
}
.container {
max-width: 800px;
margin: 0 auto;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
padding: 20px;
}
h1 {
color: #2c3e50;
text-align: center;
margin-top: 0;
margin-bottom: 20px;
padding-bottom: 10px;
border-bottom: 1px solid #eee;
}
h2 {
color: #2c3e50;
margin-top: 30px;
margin-bottom: 15px;
padding-bottom: 5px;
border-bottom: 1px solid #eee;
}
.server-info {
background-color: #2c3e50;
color: white;
padding: 15px;
border-radius: 5px;
margin-bottom: 20px;
text-align: center;
font-size: 18px;
font-weight: bold;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.log-container {
background-color: #f5f5f5;
border: 1px solid #ddd;
border-radius: 5px;
padding: 15px;
margin-bottom: 20px;
}
.log-line {
font-family: Consolas, Monaco, 'Courier New', monospace;
margin-bottom: 4px;
line-height: 1.5;
}
.success {
color: #28a745;
}
.error {
color: #dc3545;
font-weight: bold;
}
.warning {
color: #fd7e14;
}
.info {
color: #17a2b8;
}
.troubleshooting {
background-color: #f8f9fa;
padding: 20px;
border-radius: 5px;
margin-top: 20px;
border-left: 4px solid #28a745;
}
.troubleshooting.has-errors {
border-left: 4px solid #dc3545;
}
.troubleshooting h2 {
margin-top: 0;
border-bottom: none;
padding-bottom: 0;
}
.troubleshooting.has-errors h2 {
color: #dc3545;
}
.troubleshooting:not(.has-errors) h2 {
color: #28a745;
}
.troubleshooting ul, .troubleshooting ol {
padding-left: 25px;
margin: 15px 0;
}
.troubleshooting li {
margin-bottom: 10px;
}
.docs-link {
background-color: #2c3e50;
color: white;
border-radius: 5px;
padding: 20px;
margin: 20px 0;
text-align: center;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.docs-link h3 {
color: white;
margin-top: 0;
margin-bottom: 15px;
font-size: 20px;
}
.docs-link p {
margin-bottom: 15px;
font-size: 16px;
}
.doc-button, .discord-button {
display: inline-block;
text-decoration: none;
font-weight: bold;
padding: 10px 20px;
border-radius: 4px;
transition: all 0.2s ease;
margin: 5px;
}
.doc-button {
background-color: white;
color: #2c3e50;
}
.discord-button {
background-color: #7289DA;
color: white;
}
.doc-button:hover, .discord-button:hover {
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.doc-button:hover {
background-color: #f0f0f0;
}
.discord-button:hover {
background-color: #5e78d5;
}
.sdr-warning {
background-color: #fff3cd;
border: 1px solid #ffeeba;
border-left: 4px solid #ffc107;
color: #856404;
padding: 15px;
border-radius: 5px;
margin-bottom: 20px;
}
.sdr-warning h3 {
color: #856404;
margin-top: 0;
margin-bottom: 10px;
}
.sdr-warning ul {
padding-left: 25px;
margin: 10px 0;
}
.sdr-warning li {
margin-bottom: 5px;
}
.sdr-warning p:last-child {
margin-bottom: 0;
}
.footer {
text-align: center;
margin-top: 30px;
padding-top: 10px;
border-top: 1px solid #eee;
color: #777;
font-size: 14px;
}
.config-error {
background-color: #f8d7da;
color: #721c24;
padding: 15px;
border-radius: 5px;
margin-bottom: 20px;
text-align: center;
font-size: 16px;
border: 1px solid #f5c6cb;
}
.config-error code {
background-color: #f5c6cb;
padding: 2px 4px;
border-radius: 3px;
}
</style>
</head>
<body>
<div class="container">
<h1>SourceBans++ Connection Debug</h1>
<?php if (in_array("no_server_ip", $errors)): ?>
<div class="config-error">
<strong>Configuration Error:</strong> No server IP has been specified.<br />Please edit this file and set the <code>$serverip</code> variable at the top of the file.
</div>
<?php else: ?>
<div class="server-info">
Testing connection to server: <?php echo $serverip . ':' . $serverport; ?>
</div>
<h2>System Information</h2>
<div class="log-container">
<div class="log-line">PHP Version: <?php echo phpversion(); ?></div>
<div class="log-line">Operating System: <?php echo PHP_OS; ?></div>
<div class="log-line">Web Server: <?php echo $_SERVER['SERVER_SOFTWARE']; ?></div>
</div>
<?php
// Check if socket functions are available
if (!function_exists('fsockopen')) {
$errors[] = "fsockopen_unavailable";
echo '<h2>Error</h2>';
echo '<div class="log-container">';
echo '<div class="log-line error">fsockopen function is not available. Check PHP configuration.</div>';
echo '</div>';
} else {
?>
<h2>UDP Test</h2>
<div class="log-container">
<?php
$isBanned = false;
echo '<div class="log-line info">[+] Attempting UDP connection to ' . $serverip . ':' . $serverport . '</div>';
// Try to create socket with error handling
$sock = @fsockopen("udp://" . $serverip, $serverport, $errno, $errstr, 2);
if (!$sock) {
$errors[] = "udp_connection_failed";
echo '<div class="log-line error">[-] Connection error #' . $errno . ': ' . $errstr . '</div>';
echo '<div class="log-line warning">Suggestion: Check if outgoing UDP connections are allowed by your firewall.</div>';
} else {
echo '<div class="log-line success">[+] UDP connection successful!</div>';
stream_set_timeout($sock, 1);
echo '<div class="log-line info">[+] Attempting to write to socket</div>';
// Use error suppression and check for errors
$written = @fwrite($sock, "\xFF\xFF\xFF\xFF\x54Source Engine Query\0");
if ($written === false) {
$errors[] = "udp_write_failed";
$error = error_get_last();
echo '<div class="log-line error">[-] Write error: ' . $error['message'] . '</div>';
echo '<div class="log-line warning">Suggestion: This is likely a permission issue. Check if your web server has permission to make outgoing UDP connections.</div>';
} else {
echo '<div class="log-line success">[+] Successfully wrote ' . $written . ' bytes to socket.</div>';
echo '<div class="log-line info">[+] Server info request sent. Reading...</div>';
$packet = fread($sock, 1480);
if (empty($packet)) {
$errors[] = "udp_read_failed";
echo '<div class="log-line error">[-] Unable to read server info. Port might be blocked.</div>';
echo '<div class="log-line warning">Suggestion: The game server might not be responding or might be blocking incoming connections.</div>';
} else {
if (substr($packet, 5, (strpos(substr($packet, 5), "\0") - 1)) == "Banned by server") {
$errors[] = "server_banned";
echo '<div class="log-line error">[-] This web server\'s IP is banned by the game server.</div>';
$isBanned = true;
} else {
$packet = substr($packet, 6);
$hostname = substr($packet, 0, strpos($packet, "\0"));
echo '<div class="log-line success">[+] Response received! Server: ' . htmlspecialchars($hostname) . '</div>';
}
}
}
fclose($sock);
}
?>
</div>
<h2>TCP Test</h2>
<div class="log-container">
<?php
echo '<div class="log-line info">[+] Attempting TCP connection to ' . $serverip . ':' . $serverport . '</div>';
$sock = @fsockopen($serverip, $serverport, $errno, $errstr, 2);
if (!$sock) {
$errors[] = "tcp_connection_failed";
echo '<div class="log-line error">[-] Connection error #' . $errno . ': ' . $errstr . '</div>';
echo '<div class="log-line warning">Suggestion: Check if outgoing TCP connections are allowed by your firewall.</div>';
} else {
echo '<div class="log-line success">[+] TCP connection successful!</div>';
if (empty($serverrcon)) {
echo '<div class="log-line warning">[o] Stopping here since no RCON password was specified.</div>';
} else if ($isBanned) {
echo '<div class="log-line warning">[o] Stopping here since this IP is banned by the game server.</div>';
} else {
stream_set_timeout($sock, 2);
$data = pack("VV", 0, 03) . $serverrcon . chr(0) . '' . chr(0);
$data = pack("V", strlen($data)) . $data;
echo '<div class="log-line info">[+] Attempting RCON authentication via TCP</div>';
$written = @fwrite($sock, $data, strlen($data));
if ($written === false) {
$errors[] = "tcp_write_failed";
$error = error_get_last();
echo '<div class="log-line error">[-] Write error: ' . $error['message'] . '</div>';
echo '<div class="log-line warning">Suggestion: This is likely a permission issue. Check if your web server has permission to make outgoing TCP connections.</div>';
} else {
echo '<div class="log-line info">[+] Authentication request sent. Reading...</div>';
$size = fread($sock, 4);
if (!$size) {
$errors[] = "tcp_read_failed";
echo '<div class="log-line error">[-] Read error.</div>';
} else {
echo '<div class="log-line success">[+] Response received!</div>';
$size = unpack('V1Size', $size);
$packet = fread($sock, $size["Size"]);
$size = fread($sock, 4);
$size = unpack('V1Size', $size);
$packet = fread($sock, $size["Size"]);
$ret = unpack("V1ID/V1Reponse/a*S1/a*S2", $packet);
if (empty($ret) || (isset($ret['ID']) && $ret['ID'] == -1)) {
$errors[] = "rcon_auth_failed";
echo '<div class="log-line error">[-] Incorrect password. Avoid too many attempts to prevent being banned.</div>';
} else {
echo '<div class="log-line success">[+] Password correct!</div>';
}
}
}
}
fclose($sock);
}
?>
</div>
<div class="troubleshooting <?php echo !empty($errors) && !in_array("no_server_ip", $errors) ? 'has-errors' : ''; ?>">
<h2>Troubleshooting Recommendations</h2>
<?php if (empty($errors) || (count($errors) == 1 && in_array("no_server_ip", $errors))): ?>
<p>All tests completed successfully! Your server appears to be properly configured for SourceBans++.</p>
<?php else: ?>
<p>Based on the test results, here are some recommendations to fix the issues:</p>
<ul>
<?php if (in_array("fsockopen_unavailable", $errors)): ?>
<li>The <code>fsockopen</code> function is not available on your server. Contact your hosting provider to enable this PHP function, as it's required for SourceBans++ to connect to game servers.</li>
<?php endif; ?>
<?php if (in_array("udp_connection_failed", $errors)): ?>
<li><strong>UDP Connection Failed:</strong> Your web server cannot establish a UDP connection to the game server. This could be due to:
<ul>
<li>Firewall restrictions on your web server blocking outgoing UDP connections</li>
<li>The game server being offline or unreachable</li>
<li>Incorrect server IP or port</li>
</ul>
<p>From the official documentation:</p>
<ul>
<li>Make sure your host is not blocking UDP Incoming</li>
<li>If hosting locally, make sure you are port forwarding correctly</li>
</ul>
</li>
<?php endif; ?>
<?php if (in_array("tcp_connection_failed", $errors)): ?>
<li><strong>TCP Connection Failed:</strong> Your web server cannot establish a TCP connection to the game server. This could be due to:
<ul>
<li>Firewall restrictions on your web server blocking outgoing TCP connections</li>
<li>The game server being offline or unreachable</li>
<li>Incorrect server IP or port</li>
</ul>
<p>From the official documentation:</p>
<ul>
<li>Make sure your host is not blocking TCP Outgoing</li>
<li>Make sure your server is explicitly IP binded, do so using <code>-ip</code> launch parameter</li>
<li>If you are unable to use RCON through in-game console, append <code>-usercon</code> to launch parameter</li>
</ul>
</li>
<?php endif; ?>
<?php if (in_array("udp_write_failed", $errors) || in_array("tcp_write_failed", $errors)): ?>
<li><strong>"Operation not permitted" error detected:</strong> Your web server cannot send data to the game server. This is typically caused by:
<ul>
<li>Security restrictions on your hosting (common on shared hosting)</li>
<li>SELinux or AppArmor policies blocking outgoing connections</li>
<li>PHP configuration restrictions</li>
</ul>
<p>Possible solutions:</p>
<ul>
<li>Contact your hosting provider to allow outgoing UDP/TCP connections</li>
<li>If you have server access, check and modify firewall rules</li>
<li>Consider moving to a VPS or dedicated server where you have more control</li>
</ul>
</li>
<?php endif; ?>
<?php if (in_array("udp_read_failed", $errors) || in_array("tcp_read_failed", $errors)): ?>
<li><strong>Cannot read response from server:</strong> Connection was established but no response was received. This could be due to:
<ul>
<li>The game server firewall blocking incoming connections from your web server</li>
<li>The game server not running Source engine or being misconfigured</li>
<li>Network issues between your web server and the game server</li>
</ul>
</li>
<?php endif; ?>
<?php if (in_array("server_banned", $errors)): ?>
<li><strong>Your web server IP is banned on the game server:</strong>
<p>From the official documentation:</p>
<ul>
<li>Make sure your game server did not ban your web server's IP using <code>listip</code></li>
<li>If banned: remove it from <code>cfg/banned_ip.cfg</code> and using <code>removeip IP</code> via RCON</li>
</ul>
</li>
<?php endif; ?>
<?php if (in_array("rcon_auth_failed", $errors)): ?>
<li><strong>RCON authentication failed:</strong> The RCON password you provided is incorrect. Double-check the password in your server configuration.</li>
<?php endif; ?>
</ul>
<p><strong>From the official documentation checklist:</strong></p>
<ul>
<li>Your host is not blocking any traffic on your game server port (UDP Incoming & TCP Outgoing)</li>
<li>Your game server is online to people outside of your network w/o any error on binding</li>
<li>You can connect to server in-game</li>
<li>You can use RCON through in-game console</li>
</ul>
<p><strong>General advice:</strong></p>
<ul>
<li>If you're on shared hosting and experiencing "Operation not permitted" errors, these restrictions are often permanent. Consider using a VPS instead.</li>
<li>Make sure both your web server and game server have their firewalls configured to allow the necessary connections.</li>
<li>If possible, host your website and game server on the same network to minimize connectivity issues.</li>
</ul>
<?php endif; ?>
</div>
<div class="docs-link" style="margin-bottom: 20px;">
<h3>Official Documentation</h3>
<p>For more detailed information on debugging connection issues, please refer to the official SourceBans++ documentation:</p>
<a href="https://sbpp.github.io/docs/debugging_connection/" target="_blank" class="doc-button">View Documentation</a>
<h3 style="margin-top: 20px;">Need More Help?</h3>
<p>Join the SourceBans++ Discord community for additional support:</p>
<a href="https://discord.gg/tzqYqmAtF5" target="_blank" class="discord-button">Join Discord</a>
</div>
<div class="sdr-warning">
<h3>Important Note About Steam Datagram Relay (SDR)</h3>
<p>SourceBans++ does <strong>not</strong> support servers using Steam Datagram Relay (SDR) for the following reasons:</p>
<ul>
<li>SDR uses randomized public IP addresses which are not compatible with SourceBans++ connection methods</li>
<li>RCON commands cannot be sent through SDR connections</li>
<li>Using the server's real IP address as a workaround in SourceBans++ would expose this IP in the public web UI, compromising server security</li>
</ul>
<p>If your server uses SDR, you will need to disable it for SourceBans++ integration to work properly.</p>
</div>
<?php } // End of fsockopen check ?>
<?php endif; // End of server IP check ?>
<div class="footer">
SourceBans++ Connection Debug Tool © <?php echo date('Y'); ?>
</div>
</div>
</body>
</html>