config.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /**
  17. * 测试号
  18. * @param string $uid
  19. * @return bool
  20. */
  21. function isTester($uid) {
  22. return in_array($uid, $this->testerArr);
  23. }
  24. /**
  25. * 封号
  26. * @param type $uid
  27. */
  28. function isBaned($uid) {
  29. return in_array($uid, $this->banedArr);
  30. }
  31. // 测试号
  32. abstract protected function _InitTester();
  33. // 封号
  34. abstract protected function _InitBaneder();
  35. // 初始化外网paydb的设置
  36. abstract protected function _InitOuterNetPaydb();
  37. // 初始化外网nosql设置
  38. abstract protected function _InitOuterNetNosql();
  39. /**
  40. * 初始化内网paydb的设置
  41. */
  42. private function _InitIntranetPaydb() {
  43. $this->paydb->host = '192.168.10.16';
  44. $this->paydb->port = '3306';
  45. $this->paydb->name = 'ylsj2019_pay';
  46. $this->paydb->user = 'gwang';
  47. $this->paydb->password = 'wanggang1985';
  48. // todo: Ps. 可以设置从库, 主从架构, 主库写入, 从库查询
  49. }
  50. /**
  51. * 初始化paydb
  52. */
  53. private function _InitPaydb() {
  54. $this->paydb = new \stdclass();
  55. $this->paydb->persistant = false; # 持久链接 or not.
  56. $this->paydb->driver = 'mysql'; # Must be MySQL. Don't support other database server yet.
  57. $this->paydb->encoding = 'UTF8'; # Encoding of database.
  58. $this->paydb->strictMode = false; # Turn off the strict mode of MySQL.
  59. // $this->paydb->emulatePrepare = true; # PDO::ATTR_EMULATE_PREPARES
  60. // $this->paydb->bufferQuery = true; # PDO::MYSQL_ATTR_USE_BUFFERED_QUERY
  61. $this->paydb->prefix = ''; # 表前缀
  62. if (GAME_ONLINE) { # 外网版的paydb配置
  63. $this->_InitOuterNetPaydb();
  64. } else { # 内网版的paydb配置
  65. $this->_InitIntranetPaydb();
  66. }
  67. }
  68. private function _InitNosql() {
  69. $this->nosql = new \stdClass();
  70. if (GAME_ONLINE) { # 外网 配置
  71. $this->_InitOuterNetNosql();
  72. } else { # 内网
  73. $this->nosql->host = '192.168.10.16'; # host/ip
  74. $this->nosql->port = 6004; # 端口
  75. $this->nosql->pwd = 'wanggang1985'; # 密钥
  76. }
  77. }
  78. private function _InitStatSettings() {
  79. $stat = new \stdClass(); # 对象初始化
  80. $stat->usernumber = true; # 玩家数量
  81. $stat->cmd = true; # 操作记录
  82. }
  83. /**
  84. * @return config 单例
  85. */
  86. static public function Inst() {
  87. static $config = null;
  88. if (is_null($config)) {
  89. $config = include __DIR__ . '/configs/config_' . PLAT . '.php';
  90. }
  91. return $config;
  92. }
  93. /**
  94. * 构造函数负责初始化配置数据
  95. */
  96. private function __construct() {
  97. $this->_InitTester(); # 测试用户
  98. $this->_InitBaneder(); # 封号用户
  99. $this->_InitPaydb(); # mysql数据库配置
  100. $this->_InitNosql(); # nosql数据库配置
  101. $this->_InitStatSettings(); # 统计配置
  102. }
  103. }