config.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 $mongodb; # 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. }
  80. }
  81. private function _InitMongoDB() {
  82. if (GAME_ONLINE) {
  83. $this->_InitOuterMongoDB();
  84. } else {
  85. $this->mongodb = "mongodb://gwang:wanggang1985@192.168.10.16:27017/?authSource=admin";
  86. }
  87. }
  88. private function _InitStatSettings() {
  89. $stat = new \stdClass(); # 对象初始化
  90. $stat->usernumber = true; # 玩家数量
  91. $stat->cmd = true; # 操作记录
  92. }
  93. /**
  94. * @return config 单例
  95. */
  96. static public function Inst() {
  97. static $config = null;
  98. if (is_null($config)) {
  99. $config = include __DIR__ . '/configs/config_' . PLAT . '.php';
  100. }
  101. return $config;
  102. }
  103. /**
  104. * 构造函数负责初始化配置数据
  105. */
  106. private function __construct() {
  107. $this->_InitTester(); # 测试用户
  108. $this->_InitBaneder(); # 封号用户
  109. $this->_InitPaydb(); # mysql数据库配置
  110. $this->_InitNosql(); # nosql数据库配置
  111. $this->_InitStatSettings(); # 统计配置
  112. $this->_InitMongoDB(); # mongodb
  113. }
  114. }