forked from ragnos/eBot-CSGO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap_server.php
115 lines (98 loc) · 4.66 KB
/
bootstrap_server.php
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
<?php
/**
* eBot - A bot for match management for CS:GO
* @license http://creativecommons.org/licenses/by/3.0/ Creative Commons 3.0
* @author Julien Pardons <[email protected]>
* @version 3.0
* @date 21/10/2012
*/
$check["php"] = (function_exists('version_compare') && version_compare(phpversion(), '5.3.1', '>='));
$check["php5.4"] = (function_exists('version_compare') && version_compare(phpversion(), '5.4', '>='));
$check["mysql"] = extension_loaded('mysql');
$check["spl"] = extension_loaded('spl');
$check["sockets"] = extension_loaded("sockets");
define('EBOT_DIRECTORY', __DIR__);
define('APP_ROOT', __DIR__ . DIRECTORY_SEPARATOR);
require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
require_once 'steam-condenser.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'websocket' . DIRECTORY_SEPARATOR . 'websocket.client.php';
echo "
____ _
| _ \ | |
___| |_) | ___ | |_
/ _ \ _ < / _ \| __|
| __/ |_) | (_) | |_
\___|____/ \___/ \__|
" . PHP_EOL;
echo "PHP Compatibility Test" . PHP_EOL;
echo "-----------------------------------------------------" . PHP_EOL;
echo "| PHP 5.3.1 or newer -> required -> " . ($check["php"] ? ("[\033[0;32m Yes \033[0m]" . phpversion()) : "[\033[0;31m No \033[0m]") . PHP_EOL;
echo "| Standard PHP Library -> required -> " . ($check["spl"] ? "[\033[0;32m Yes \033[0m]" : "[\033[0;31m No \033[0m]") . PHP_EOL;
echo "| MySQL -> required -> " . ($check["mysql"] ? "[\033[0;32m Yes \033[0m]" : "[\033[0;31m No \033[0m]") . PHP_EOL;
echo "| Sockets -> required -> " . ($check["sockets"] ? "[\033[0;32m Yes \033[0m]" : "[\033[0;31m No \033[0m]") . PHP_EOL;
echo "-----------------------------------------------------" . PHP_EOL;
if (!$check["php5.4"]) {
echo "| We recommand to use PHP5.4 to get better performance !" . PHP_EOL;
echo '-----------------------------------------------------' . PHP_EOL;
}
unset($check["php5.4"]);
if (in_array(false, $check)) {
echo "| Your php configuration missed, please make sure that you have all feature !" . PHP_EOL;
echo '-----------------------------------------------------' . PHP_EOL;
exit();
}
// better checking if timezone is set
if (!ini_get('date.timezone')) {
$timezone = @date_default_timezone_get();
echo '| Timezone is not set in php.ini. Please edit it and change/set "date.timezone" appropriately. '
. 'Setting to default: \'' . $timezone . '\'' . PHP_EOL;
echo '-----------------------------------------------------' . PHP_EOL;
date_default_timezone_set($timezone);
}
// enable error reporting
ini_set('display_errors', 1);
error_reporting(E_ALL);
gc_enable();
function handleShutdown() {
global $webSocketProcess;
if (PHP_OS == "Linux") {
proc_terminate($webSocketProcess,9);
foreach (\eBot\Application\ApplicationServer::getInstance()->instance as $proc) {
proc_terminate($proc,9);
}
}
$error = error_get_last();
if (!empty($error)) {
$info = "[SHUTDOWN] date: " . date("d.m.y H:m", time()) . " file: " . $error['file'] . " | ln: " . $error['line'] . " | msg: " . $error['message'] . PHP_EOL;
file_put_contents(APP_ROOT . 'logs' . DIRECTORY_SEPARATOR . 'error.log', $info, FILE_APPEND);
}
}
echo "| Registerung Shutdown function !" . PHP_EOL;
register_shutdown_function('handleShutdown');
// Starting ebot Websocket Server
if (PHP_OS == "Linux") {
echo "| Starting eBot Websocket-Server !" . PHP_EOL;
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("file", "websocket.log", "a"),
2 => array("file", "websocket.error", "a")
);
$webSocketProcess = proc_open('node ' . __DIR__ . '/websocket_server.js ' . \eBot\Config\Config::getInstance()->getBot_ip() . ' ' . \eBot\Config\Config::getInstance()->getBot_port(), $descriptorspec, $pipes);
if (is_resource($webSocketProcess)) {
fclose($pipes[0]);
usleep(400000);
$status = proc_get_status($webSocketProcess);
if (!$status['running']) {
echo '| WebSocket server crashed' . PHP_EOL;
echo '-----------------------------------------------------' . PHP_EOL;
die();
}
echo "| WebSocket has been started" . PHP_EOL;
}
} else {
echo "| You are under windows, please run websocket_server.bat before starting ebot" . PHP_EOL;
sleep(5);
}
echo '-----------------------------------------------------' . PHP_EOL;
error_reporting(E_ALL);
\eBot\Application\ApplicationServer::getInstance()->run();