123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- define('CONFIG_FILE', __DIR__ . '/config.php');
- define('LOG_NAME', 'tcpserver');
- include __DIR__ . '/lib/functions.php';
- include __DIR__ . '/lib/message.php';
- include __DIR__ . '/lib/server.php';
- include __DIR__ . '/lib/client_base.php';
- include __DIR__ . '/lib/timerman.php';
- include __DIR__ . '/client.php';
- //配置
- $cfg = [];
- load_config();
- //登录后的客户端列表
- $users = [];
- //定时管理器
- $timerman = new TimerMan();
- //Server对象
- $srv = new Server($cfg);
- $srv->start();
- $srv->run();
- /**
- * 取全局Server对象的函数(避免在Client对象中保存Server的对象引用,从而导致循环指向的问题)
- * @return Server
- */
- function GET_SERVER()
- {
- return $GLOBALS['srv'];
- }
- /**
- * 取全局定时器管理对象
- * @return TimerMan
- */
- function GET_TIMER()
- {
- return $GLOBALS['timerman'];
- }
- /**
- * 广播消息
- * @param Message $msg
- */
- function BC($msg)
- {
- foreach ($GLOBALS['users'] as $cli) {
- $cli->response($msg);
- }
- }
|