main.php 968 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. define('CONFIG_FILE', __DIR__ . '/config.php');
  3. define('LOG_NAME', 'tcpserver');
  4. include __DIR__ . '/lib/functions.php';
  5. include __DIR__ . '/lib/message.php';
  6. include __DIR__ . '/lib/server.php';
  7. include __DIR__ . '/lib/client_base.php';
  8. include __DIR__ . '/lib/timerman.php';
  9. include __DIR__ . '/client.php';
  10. //配置
  11. $cfg = [];
  12. load_config();
  13. //登录后的客户端列表
  14. $users = [];
  15. //定时管理器
  16. $timerman = new TimerMan();
  17. //Server对象
  18. $srv = new Server($cfg);
  19. $srv->start();
  20. $srv->run();
  21. /**
  22. * 取全局Server对象的函数(避免在Client对象中保存Server的对象引用,从而导致循环指向的问题)
  23. * @return Server
  24. */
  25. function GET_SERVER()
  26. {
  27. return $GLOBALS['srv'];
  28. }
  29. /**
  30. * 取全局定时器管理对象
  31. * @return TimerMan
  32. */
  33. function GET_TIMER()
  34. {
  35. return $GLOBALS['timerman'];
  36. }
  37. /**
  38. * 广播消息
  39. * @param Message $msg
  40. */
  41. function BC($msg)
  42. {
  43. foreach ($GLOBALS['users'] as $cli) {
  44. $cli->response($msg);
  45. }
  46. }