config.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace loyalsoft;
  3. //use \GAME_ONLINE;
  4. /**
  5. * Description of config
  6. * 尝试用这种写法来定义服务器配置
  7. * @author gwang (email: mail@wanggangzero.cn)
  8. * @copyright © 2015-2-3, SJZ LoyalSoft Corporation & gwang. All rights reserved.
  9. */
  10. abstract class config {
  11. protected $testerArr; # 测试号数组
  12. protected $banedArr; # 封号数组
  13. public $paydb; # mysql配置
  14. public $nosql; # nosql配置
  15. public $stat; # 统计配置
  16. public $mongo; # MongoDB配置
  17. /**
  18. * 测试号
  19. * @param string $uid
  20. * @return bool
  21. */
  22. function isTester($uid) {
  23. return in_array($uid, $this->testerArr);
  24. }
  25. /**
  26. * 封号
  27. * @param string $uid
  28. */
  29. function isBaned($uid) {
  30. return in_array($uid, $this->banedArr);
  31. }
  32. // 测试号
  33. abstract protected function _InitTester();
  34. // 封号
  35. abstract protected function _InitBaneder();
  36. // 初始化外网paydb的设置
  37. abstract protected function _InitOuterNetPaydb();
  38. // 初始化外网nosql设置
  39. abstract protected function _InitOuterNetNosql();
  40. // 初始化外网MongoDB设置
  41. abstract protected function _InitOuterMongoDB();
  42. /**
  43. * 初始化内网paydb的设置
  44. */
  45. private function _InitIntranetPaydb() {
  46. $this->paydb->host = '192.168.10.16';
  47. $this->paydb->port = '3306';
  48. $this->paydb->name = 'ylsj2019_pay';
  49. $this->paydb->user = 'gwang';
  50. $this->paydb->password = 'wanggang1985';
  51. // todo: Ps. 可以设置从库, 主从架构, 主库写入, 从库查询
  52. }
  53. /**
  54. * 初始化paydb
  55. */
  56. private function _InitPaydb() {
  57. $this->paydb = new \stdclass();
  58. $this->paydb->persistant = false; # 持久链接 or not.
  59. $this->paydb->driver = 'mysql'; # Must be MySQL. Don't support other database server yet.
  60. $this->paydb->encoding = 'UTF8'; # Encoding of database.
  61. $this->paydb->strictMode = false; # Turn off the strict mode of MySQL.
  62. // $this->paydb->emulatePrepare = true; # PDO::ATTR_EMULATE_PREPARES
  63. // $this->paydb->bufferQuery = true; # PDO::MYSQL_ATTR_USE_BUFFERED_QUERY
  64. $this->paydb->prefix = ''; # 表前缀
  65. if (GAME_ONLINE) { # 外网版的paydb配置
  66. $this->_InitOuterNetPaydb();
  67. } else { # 内网版的paydb配置
  68. $this->_InitIntranetPaydb();
  69. }
  70. }
  71. private function _InitNosql() {
  72. $this->nosql = new \stdClass();
  73. if (GAME_ONLINE) { # 外网 配置
  74. $this->_InitOuterNetNosql();
  75. } else { # 内网
  76. $this->nosql->host = '192.168.10.16'; # host/ip
  77. $this->nosql->port = 6004; # 端口
  78. $this->nosql->pwd = 'wanggang1985'; # 密钥
  79. $this->nosql->db = 0; # db索引
  80. }
  81. }
  82. private function _InitMongoDB() {
  83. $this->mongo = new \stdClass();
  84. if (GAME_ONLINE) {
  85. $this->_InitOuterMongoDB();
  86. } else {
  87. // $this->mongodb = "mongodb://ylsjMTY0LjkyLjE5NC4x:wanggang1985@192.168.10.16:27017/?authSource=ylsj2019";
  88. $this->mongo->db = "ylsj2019_TTT";
  89. $this->mongo->conn = "mongodb://ylsjMTY0LjkyLjE5NC4x:wanggang1985@192.168.10.16:27017/?authSource=ylsj2019";
  90. }
  91. }
  92. private function _InitStatSettings() {
  93. $stat = new \stdClass(); # 对象初始化
  94. $stat->usernumber = true; # 玩家数量
  95. $stat->cmd = true; # 操作记录
  96. }
  97. /**
  98. * @return config 单例
  99. */
  100. static public function Inst() {
  101. static $config = null;
  102. if (is_null($config)) {
  103. $config = include __DIR__ . '/configs/config_' . PLAT . '.php';
  104. }
  105. return $config;
  106. }
  107. /**
  108. * 构造函数负责初始化配置数据
  109. */
  110. private function __construct() {
  111. $this->_InitTester(); # 测试用户
  112. $this->_InitBaneder(); # 封号用户
  113. $this->_InitPaydb(); # mysql数据库配置
  114. $this->_InitNosql(); # nosql数据库配置
  115. $this->_InitStatSettings(); # 统计配置
  116. $this->_InitMongoDB(); # mongodb
  117. }
  118. }