Bladeren bron

代码整理,1. 去除mysqli引擎, 只保留dao访问MySQL的接口 2. 根据错误日志修复一批bug,暂时清空了错误日志. 3. 精简了通讯协议中请求/返回对象的字段.

gwang 4 jaren geleden
bovenliggende
commit
04d4a287ce

+ 6 - 6
Gameserver/Amfphp/Services/AppServer.php

@@ -32,10 +32,11 @@ class AppServer {
      * 预处理逻辑
      */
     private static function BeforeProc($req) {
+        if (!GAME_ONLINE) {
+            return ErrCode::ok;                                                 # 直接返回 0:成功
+        }
         my_Assert(!config::Inst()->isBaned($req->uid), ErrCode::err_server_updating); # 检查封号 
-        # 检查是否处于更新阶段,暂停对玩家请求的响应。
-        if (GAME_ONLINE                                                         # 外网
-                && self::isUpdating()                                           # 更新
+        if (self::isUpdating()                                                  # 检查是否处于更新阶段,暂停对玩家请求的响应。
                 && !config::Inst()->isTester($req->uid)) {                      # 排除测试号
             return ErrCode::err_server_updating;
         }
@@ -43,13 +44,12 @@ class AppServer {
         if (now() > $ssd->startts && now() < $ssd->endts) {                     # 在维护期间 
             Err(ErrCode::err_server_maintaining, $ssd->reason);
         }
-        // todo: 检查clientVersion 判断是否应该强制升级
-
+        // todo: 检查clientVersion 判断是否应该强制升级 
 
         if (now() - $req->ts > OFFSET_MSGTIME) {                                # 如果服务端客户端时间戳超过规定误差,则消息非法
             return ErrCode::err_outtime;
         }
-        return ErrCode::ok;                                                     # 返回操作结果,0:成功,其余为错误码
+        return ErrCode::ok;                                                     # 所有检查通过
     }
 
     /**

+ 20 - 5
Gameserver/Amfphp/base/Req.php

@@ -50,6 +50,12 @@ class Req extends Object_ext {
      * @var str
      */
     public $clientVer;
+
+    /**
+     * 标签[扩展用,保留]
+     * @var type
+     */
+    public $tag;
 // -----------------------------------------------------------
 //    服务端为了便于操作使用到的变量直接挂载到req上
     /**
@@ -70,12 +76,8 @@ class Req extends Object_ext {
      * @var bool userInfo是否需要回写
      */
     public $userInfoChanged = false;
+
 // -------------------------------------------------------------
-    /**
-     * 标签[扩展用,保留]
-     * @var type
-     */
-    public $tag;
 
     /**
      *
@@ -110,6 +112,19 @@ class Req extends Object_ext {
         self::$_req = $this; // ---赋值---
     }
 
+    /**
+     * 把Req对象序列化到字符串
+     * @return type
+     */
+    public function __toString() {
+        $clone = clone $this;
+        unset($clone->mem);                                                     # 删除不必要的字段
+        unset($clone->userInfo);                                                # 删除不必要的字段
+        unset($clone->userInfoChanged);                                         # 删除不必要的字段 
+        $str = JsonUtil::encode($clone);                                        # json
+        return $str;
+    }
+
     // <editor-fold defaultstate="collapsed" desc="单例:想着以后不在通过函数透传此对象了">
 
     /**

+ 0 - 18
Gameserver/Amfphp/main.php

@@ -42,24 +42,6 @@ require_once ROOTDIR . '/AutoLoad.php';
 DebugHelper::checkkPHPVersion();                                                # 检查PHP版本
 DebugHelper::checkModules();                                                    # 检查PHP模块
 
-/**
- * ★★★初始化支付数据工具★★★
- * @return \CDbUtil
- * @deprecated since version 0
- */
-function CPayInit() {
-    $cpay = new CDbUtil();
-    global $zoneid;
-
-    $paydb = config::Inst()->paydb;
-    $dbname = $paydb->name;
-    if ($zoneid != null && $zoneid == 999) {                                    // 999区作为测试分区,充值等数据都是虚拟的,单独设置,其他区直接默认值
-        $dbname = "dhd_pay"; // "dhd_pay_test";
-    }
-    $cpay->dbconn($paydb->host, $paydb->port, $paydb->user, $paydb->password, $dbname);
-    return $cpay;
-}
-
 /**
  * get dao instance,
  * @version 2019年12月23日 经过梦幻星工场2一年多的使用, 未发现特别明显的bug. 决定侧重使用. -- 王刚

+ 2 - 2
Gameserver/Amfphp/model/User/UserGameModel.php

@@ -61,7 +61,7 @@ class UserGameModel extends HashSaver {
     public $pvp;
 
     /**
-     * 战斗队伍配置信息
+     * 战斗队伍配置信息(使用时必须先json_decode)
      * @var dictionary
      */
     public $heroTeamConfig;
@@ -117,7 +117,7 @@ class UserGameModel extends HashSaver {
             $this->gates = new UserGateDifficulty();                            # 初始化关卡默认数据
 //            $this->heroManual = new HeroManualModel();                          # 初始化图鉴数据结构
             $this->NewbieGuide = ObjectInit();                                  # 初始化新手引导结构
-            $this->pvp = new UserPVPModel();                                    # 初始化pvp模块
+//            $this->pvp = new UserPVPModel();                                    # 初始化pvp模块
             $this->userSecretshop = new userSecretshopModel();                  # 神秘商店
             $this->task = new UserTaskInfo();                                   # 任务数据
         } else {                                                                # 实参

+ 5 - 2
Gameserver/Amfphp/model/User/UserPVPModel.php

@@ -137,8 +137,11 @@ class UserPVPModel extends Object_ext {
         if ($this->defTeam[0] <= 0) {
             $one = 1;
             if (isset(req()->userInfo)) {
-                $teams = req()->userInfo->game->heroTeamConfig->teamDic;
-                $this->defTeam = array_slice($teams->$one->heros, 0, 3);
+                $teamCfg = JsonUtil::decode(req()->userInfo->game->heroTeamConfig);
+                $teams = $teamCfg->teamDic;
+                if (isset($teams->$one->heros)) {
+                    $this->defTeam = array_slice($teams->$one->heros, 0, 3);
+                }
             }
         }
     }

+ 2 - 2
Gameserver/Amfphp/process/HeroProc.php

@@ -1014,8 +1014,8 @@ class HeroProc {
 
         //  取可用武器中第一个初始化 -- 策划要求初始英雄要带有武器 -- 王刚 2020年1月
         $wp = null;
-        $arr = GameConfig::item_weapon();
-        krsort($arr);       // todo: 排序不正常
+        $arr = (array) GameConfig::item_weapon();
+        krsort($arr);                                                            // todo: 排序不正常
         foreach ($arr as $id => $mo) {
 //            isEditor() and $mo = new \sm_item_weapon();
             if ($mo->hero_id == $hero->typeId) {

+ 1 - 1
Gameserver/Amfphp/process/ShopProc.php

@@ -136,7 +136,7 @@ class ShopProc {
      * @param req $req
      */
     static function DailyCheck($req) {
-        CLog::err("每日检查");
+        CLog::info("shop-每日检查-清除每日/周限量礼包购买记录");
         $zoneid = $req->zoneid;
         $uid = $req->uid;
         $shopdata = new UserShopInfoModel($req->userInfo->game->shopdata);

+ 1 - 1
Gameserver/Amfphp/process/StoreProc.php

@@ -539,7 +539,7 @@ class StoreProc {
             Err(ErrCode::store_itemno_err);
         }
         $yanlingVo = $user->store->yanling->$yanling_uid;                       # 取言灵对象
-        if ($yanlingVo->herouid > 0 && $yanlingVo->herouid != $herouid) {       # 检测该言灵是否装备到其他英雄身上 
+        if (isset($yanlingVo->herouid) && $yanlingVo->herouid != $herouid) {    # 检测该言灵是否装备到其他英雄身上 
             Err(ErrCode::store_equipWeared_err);
         }
         $collectHeros = $user->heros->collectHeros;                             # 英雄集合

+ 4 - 5
Gameserver/Amfphp/process/TaskProc.php

@@ -152,7 +152,7 @@ class TaskProc {
      * @param TaskParams $taskParam Description
      */
     static function CheckTaskConditions($taskParam) {
-        var_dump($taskParam);
+//        var_dump($taskParam);
         $bUpdate = false;
         foreach (req()->userInfo->game->task->taskListPlot as $tid => $task) {
             $taskCfg = GameConfig::task_getItem($tid);
@@ -195,7 +195,7 @@ class TaskProc {
         }
         if ($bUpdate) {
             Resp::addTag("isTaskUpdated", true);                                # 附加tag信息, 任务有更新
-            CornerSignEventProc::OnTask_Plot_new($req);
+            CornerSignEventProc::OnTask_Plot_new(req());
         }
     }
 
@@ -205,8 +205,7 @@ class TaskProc {
      */
     static function CheckDailyTaskConditions($taskParam) {
         $bUpdate = false;
-        $req = req();
-        $daily = $req->userInfo->game->task->taskListDaily;
+        $daily = req()->userInfo->game->task->taskListDaily;
         foreach ($daily as $tid => &$task) {
             $taskCfg = GameConfig::task_daily_getItem($tid);
             my_Assert($taskCfg != null, ErrCode::err_const_no);                 # 获取任务配置数据    
@@ -232,7 +231,7 @@ class TaskProc {
 
         if ($bUpdate) {
             Resp::addTag("isTaskUpdated", true);                                # 附加tag信息, 任务有更新
-            CornerSignEventProc::OnTask_Daily_new($req);
+            CornerSignEventProc::OnTask_Daily_new(req());
         }
     }
 

+ 23 - 21
Gameserver/Amfphp/process/UserProc.php

@@ -216,8 +216,11 @@ class UserProc {
         list($rolename, $gender, $profile_img) = $req->paras;                   # 参数: 昵称,性别,头像
         if (self::checkRoleNameNotExist($rolename)) {                           # 记录玩家
             $userinfo = self::createUser($req, $rolename, $gender, $profile_img);
-            self::regRole($req->zoneid, $userID, $rolename, $gender, $profile_img, $userinfo->getPlatStr());
-            $resp = Resp::ok($userinfo);
+            if (1 == self::regRole($req->zoneid, $userID, $rolename, $gender, $profile_img, $userinfo->getPlatStr())) {
+                $resp = Resp::ok($userinfo);
+            } else {
+                $resp = Resp::err(ErrCode::err_db);
+            }
 //            StatProc::UserGuidStep($userinfo->user->firstLogOn, $req->zoneid, -2, 1);
         } else {                                                                # 昵称已存在
             $resp = Resp::ok(array('ret' => '用户已存在.'));
@@ -417,13 +420,15 @@ class UserProc {
      * @param string $plat
      */
     static function regRole($zoneid, $userID, $nickname, $gender, $profile_img, $plat) {
-        $paydb = CPayInit();
-        $sqlFormat = "INSERT INTO `tab_rolename` ( zoneid,userID,roleName,gender, profile,plat) "
-                . "VALUES ('%s','%s','%s','%s','%s','%s')";
-        $sql = sprintf($sqlFormat, $zoneid, $userID, #
-                $paydb->escape_string($nickname), $gender, $profile_img, $plat);
-        $paydb->query($sql);
-        $paydb->close();
+        return daoInst()->insert('tab_rolename')
+                        ->data(array(
+                            'zoneid' => $zoneid,
+                            'userID' => $userID,
+                            'roleName' => $nickname,
+                            'gender' => $gender,
+                            'profile' => $profile_img,
+                            'plat' => $plat
+                        ))->exec();
     }
 
     /**
@@ -648,8 +653,7 @@ class RegNewUser {
     /**
      * 查找已有用户
      */
-    const SQL_SelectUser = "Select tid, pwd from `tab_register` where `userName` = '%s' order by tid limit 1;
-";
+    const SQL_SelectUser = "Select tid, pwd from `tab_register` where `userName` = '%s' order by tid limit 1;";
 
     /**
      * 插入新用户, Ps 常量字符串只能这么写了
@@ -667,18 +671,18 @@ sql;
      * @return array
      */
     public static function Write2MysqlUserInfo($userName, $pwd, $email = "", $phoneNumber = "") {
-        $paydb = CPayInit();
         $sql_sel = sprintf(self::SQL_SelectUser, $userName);
-        $data = $paydb->fetch_result($sql_sel);
-        if (count($data) > 0) {                                                 # 已经有用户了,那么注册失败.
+        $n = daoInst()->query($sql_sel)->rowCount();
+        if ($n > 0) {                                                           # 已经有用户了,那么注册失败.
             return array('ret' => -1, 'msg' => "这个账号已经注册过了.");
         }                                                                       # 尚未注册, 继续执行
         $sql_insert = sprintf(self::SQL_InsertNewUser, $userName, $pwd, $email, $phoneNumber);
-        if (false === $paydb->query($sql_insert)) {                             # 插入用户信息
+
+        if (daoInst()->query($sql_insert)->exec() <= 0) {                       # 插入用户信息
             return array('ret' => -1, 'msg' => "数据插入失败, 请重试.");
         }
         $ret = array('ret' => 0, 'msg' => "注册成功.");                          # 插入成功, 返回
-        $paydb->close();
+
         return $ret;
     }
 
@@ -688,18 +692,16 @@ sql;
      * @param type $pwd
      */
     public static function VerifyUserPwd($userName, $pwd) {
-        $paydb = CPayInit();
         $sql_sel = sprintf(self::SQL_SelectUser, $userName);
-        $data = $paydb->fetch_result($sql_sel);
-        $paydb->close();
+        $data = daoInst()->query($sql_sel)->fetchAll();
         if (count($data) > 0) {
-            if ($data[0]["pwd"] == $pwd) {                                      # 验证成功
+            $info = obj2arr($data[0]);
+            if ($info["pwd"] == $pwd) {                                         # 验证成功
                 return array('ret' => 0, 'msg' => "通过.");
             } else {
                 return array('ret' => -1, 'msg' => "密码错误.");
             }
         }
-        return array('ret' => -1, 'msg' => "账号不存在.");
     }
 
 }

+ 10 - 13
Gameserver/Amfphp/service_call/InquireApi/VerifyReturnCode.php

@@ -17,8 +17,7 @@ require_once ROOTDIR . '/Util/OpenSSLVerify.php'; #Ps. 这个文件和类名没
  * @copyright © 2015-6-8, SJZ LoyalSoft Corporation & gwang. All rights reserved.
  */
 
-class VerifyReturnCode
-{
+class VerifyReturnCode {
 
     //put your code here
     const SQL_SelectReturnCode = "Select * from `tab_returncode` where oid='%s' and returncode='%s';";
@@ -29,21 +28,19 @@ class VerifyReturnCode
      * @param string $returncode  曾经留下的回归密码
      * @return int 0 不通过, 1 通过
      */
-    public static function Verify($oid, $returncode)
-    {
-        $paydb = CPayInit();
+    public static function Verify($oid, $returncode) {
         $sql = sprintf(self::SQL_SelectReturnCode, $oid, $returncode);
-        $data = $paydb->fetch_result($sql);
-        $paydb->close();
+        $data = daoInst()->query($sql)->fetchAll();
         if (count($data) > 0) {
+            $info = $data[0];
             $ret = array(
                 'ret' => 1,
-                'msg' => json_encode(array(
-                    'name' => $data[0]['name'],
-                    'lvl' => $data[0]['lvl'],
-                    'cash' => $data[0]['cash'],
-                    'charge_amt' => $data[0]['charge_amt']
-                ))
+                'msg' => array(
+                    'name' => $info->name,
+                    'lvl' => $info->lvl,
+                    'cash' => $info->cash,
+                    'charge_amt' => $info->charge_amt
+                )
             );
         } else {
             $ret = array(

+ 4 - 10
Gameserver/Amfphp/service_call/mergemem/decodeCMemDump_v2.2.php

@@ -31,8 +31,7 @@ set_time_limit(0);  # cli 不限定执行时间
 
 if (!function_exists('hex2bin')) {  // first include in php 5.4
 
-    function hex2bin($str)
-    {
+    function hex2bin($str) {
         return pack('H*', $str);
         // safer方法:2个字节一转换,确保最大限度完成转换.
         $sbin = "";
@@ -52,8 +51,7 @@ if (!function_exists('hex2bin')) {  // first include in php 5.4
  * @staticvar CRedisUtil $gRedis
  * @return \CRedisUtil
  */
-function gRedis()
-{
+function gRedis() {
     static $gRedis;
     if ($gRedis == null) {
         $gRedis = new CRedisUtil();
@@ -65,8 +63,7 @@ function gRedis()
     return $gRedis;
 }
 
-function output($key, $value)
-{
+function output($key, $value) {
     if (strpos($key, '-info') !== FALSE) { // userinfo
         $userinfo = JsonUtil::decode($value);
         if (property_exists($userinfo, 'user') //
@@ -78,10 +75,7 @@ function output($key, $value)
             $tsday = day($userinfo->user->ts);
             $info = base64_encode(gzcompress($value));
             $SQL = sprintf("call mgodpay.insertUserInfo('%s',%d,%d,'%s');", $uid, $zoneid, $tsday, $info);
-            $paydb = CPayInit();
-            $paydb->query($SQL);
-            // echo $SQL. "\r\n";
-//            $paydb->close();
+            daoInst()->query($SQL)->exec();
             echo $key . "\r\n";
             return;
         }

+ 4 - 9
Gameserver/Amfphp/service_call/mergemem/decodeCMemDump_v2.php

@@ -28,8 +28,7 @@ set_time_limit(0);  # cli 不限定执行时间
 
 if (!function_exists('hex2bin')) {  // first include in php 5.4
 
-    function hex2bin($str)
-    {
+    function hex2bin($str) {
         $sbin = "";
         $len = strlen($str);
         for ($i = 0; $i < $len; $i += 2) {
@@ -47,8 +46,7 @@ if (!function_exists('hex2bin')) {  // first include in php 5.4
  * @staticvar CRedisUtil $gRedis
  * @return \CRedisUtil
  */
-function gRedis()
-{
+function gRedis() {
     static $gRedis;
     if ($gRedis == null) {
         $gRedis = new CRedisUtil();
@@ -60,8 +58,7 @@ function gRedis()
     return $gRedis;
 }
 
-function output($key, $value)
-{
+function output($key, $value) {
     if (strpos($key, '-info') !== FALSE) { // userinfo
         $userinfo = JsonUtil::decode($value);
         if (property_exists($userinfo, 'user') //
@@ -73,9 +70,7 @@ function output($key, $value)
             $tsday = day($userinfo->user->ts);
             $info = bin2hex(gzdeflate($value));
             $SQL = sprintf("call mgodpay.insertUserInfo('%s',%d,%d,'%s');", $uid, $zoneid, $tsday, $info);
-            $paydb = CPayInit();
-            $paydb->query($SQL);
-//            $paydb->close();
+            daoInst()->query($SQL)->exec();
             echo $key . "\r\n";
             return;
         }

+ 2 - 0
Gameserver/Amfphp/test.php

@@ -11,3 +11,5 @@ include __DIR__ . '/main.php';
 
 
 var_dump("Hello world!");
+
+var_dump(GameConfig::item_weapon());

+ 212 - 212
Gameserver/Amfphp/util/CDbUtil.php

@@ -1,214 +1,214 @@
 <?php
 
-namespace loyalsoft;
-
-/**
- * CDB工具类[APHP三大操作单元之一]
- * @version 2.0.1 gwang 修补了部分mysqli方法 2020.3.25
- *           2.0   gwang 升级到mysqli,以便能在PHP7.0以后的环境下继续运行. 约 2017
- *           1.0   jgao  created 约 2013
- * @author jgao,gwang
- */
-class CDbUtil {
-
-    public $conn = 0;
-
-    public function dbconn($dbhost, $dbport, $dbuser, $dbpw, $dbname) {
-//        CLogUtil::output("数据库初始化: $dbhost,$dbport,$dbuser,$dbpw,$dbname");
-//        DebugHelper::log2file($dbhost, $dbport, $dbname, $dbuser, $dbpw);
-        $this->conn = mysqli_connect($dbhost, $dbuser, $dbpw, $dbname, $dbport, true);
-        !$this->conn && $this->halt("Connect to MySQL failed");
-        $serverinfo = mysqli_get_server_info($this->conn);
-        if ($serverinfo > '4.1' && $GLOBALS['charset']) {
-            mysqli_query($this->conn, "SET character_set_connection=" . $GLOBALS['charset'] . ",character_set_results=" . $GLOBALS['charset'] . ",character_set_client=binary");
-        }
-        if ($serverinfo > '5.0') {
-            mysqli_query($this->conn, "SET sql_mode=''");
-        }
-        if ($dbname && !mysqli_select_db($this->conn, $dbname)) {
-            $this->halt('Cannot use database');
-        }
-    }
-
-    /**
-     * 切换db
-     * @param type $dbname
-     */
-    public function select_db($dbname) {
-        if (!mysqli_select_db($this->conn, $dbname)) {
-            $this->halt('Cannot use database');
-        }
-    }
-
-    /**
-     * 调取服务器信息
-     * @return type
-     */
-    public function server_info() {
-        return mysqli_get_server_info($this->conn);
-    }
-
-    /**
-     * 最后一次执行insert时插入的第一行记录Id,(如果一次插入3条记录,则得到第一条的记录)
-     * 所以,这个如何用要慎重(gwang)
-     * @return type
-     */
-    public function insert_id() {
-        $arr = $this->fetch_array('SELECT LAST_INSERT_ID() as id');
-        return $arr["id"];
-    }
-
-    /**
-     * 直接取查询结果的某行某列的数值
-     * @param type $SQL
-     * @param type $offset
-     * @param type $field
-     * @return boolean
-     */
-    public function get_value($SQL, $offset = 0, $field = 0) {
-        $rt = $this->fetch_result($SQL);
-        if (isset($rt[$offset][$field])) {
-            return $rt[$offset][$field];
-        }
-        return false;
-    }
-
-    /**
-     * 执行查询
-     * @param type $SQL
-     * @param type $method
-     * @param type $error
-     * @return mixed
-     */
-    public function query($SQL, $method = null, $error = true) {
-        $query = mysqli_query($this->conn, $SQL);
-        !$query && $error && $this->halt('Query Error: ' . $SQL);
-        return $query;
-    }
-
-    /**
-     * 执行更新的时候加上事物逻辑
-     * @param type $SQL
-     * @return int errno
-     */
-    public function safeQuery($SQL) {
-        mysqli_query($this->conn, 'start transaction');
-        mysqli_query($this->conn, 'SET autocommit=0');
-        $query = mysqli_query($this->conn, $SQL);
-        $err = mysqli_errno($this->conn);
-        if ($err && !$query) {
-            mysqli_query($this->conn, 'rollback');
-        } else {
-            mysqli_query($this->conn, 'commit');
-        }
-        mysqli_query($this->conn, 'SET autocommit=1');
-        return $err;
-    }
-
-    /**
-     * 将查询结果作为索引数组返回
-     * @param string $SQL
-     * @return array
-     */
-    public function fetch_row($SQL) {
-        return $this->fetch_result($SQL, MYSQLI_NUM);
-    }
-
-    /**
-     * 将查询结果作为关联数组返回
-     * @param string $SQL
-     * @return array
-     */
-    public function fetch_array($SQL) {
-        return $this->fetch_result($SQL, MYSQLI_ASSOC);
-    }
-
-    /**
-     * 从结果中取一行作为结果返回
-     * @param string $SQL
-     * @param int $result_type 1. 关联数组, 2. 索引数组, 3 both
-     * @return type
-     */
-    public function fetch_result($SQL, $result_type = MYSQLI_BOTH) {
-        $arr = array();
-        $query = $this->query($SQL);
-        $data = mysqli_fetch_array($query, $result_type);
-        while ($data) {
-            $arr[] = $data;
-            $data = mysqli_fetch_array($query, $result_type);
-        }
-        $this->free_result();
-        return $arr;
-    }
-
-    /**
-     * 调取查询影响的行数
-     * @return type
-     */
-    public function affected_rows() {
-        return mysqli_affected_rows($this->conn);
-    }
-
-    /**
-     * 调取结果集中行的数目
-     * @param type $SQL
-     * @return int
-     */
-    public function num_rows($SQL) {
-        $query = $this->query($SQL);
-        if (!is_bool($query)) {
-            return mysqli_num_rows($query);
-        }
-        return 0;
-    }
-
-    /**
-     * 调取结果集中字段数量
-     * @param type $SQL
-     * @return type
-     */
-    public function num_fields($SQL) {
-        $query = $this->query($SQL);
-        return mysqli_num_fields($query);
-    }
-
-    /**
-     * 封装SQL字符串中特殊字符,以免SQL语句执行失败.
-     * @param type $str 带有风险字符的SQL语句或者字符串
-     * @return type 处理后的字符串
-     */
-    public function escape_string($str) {
-        return mysqli_real_escape_string($this->conn, $str);
-    }
-
-    /**
-     * 释放SQL查询结果
-     */
-    public function free_result() {
-        $void = func_get_args();
-        foreach ($void as $query) {
-            if (is_resource($query) && get_resource_type($query) === 'mysql result') {
-                mysqli_free_result($query);
-            }
-        }
-        unset($void);
-    }
-
-    /**
-     * 关闭当前实例的连接
-     * @return type
-     */
-    public function close() {
-        $this->free_result();
-        return mysqli_close($this->conn);
-    }
-
-    /**
-     * 直接报错退出
-     * @param type $msg
-     */
-    public function halt($msg = null) {
-        exit($msg . '<br /><br />' . mysqli_error($this->conn));
-    }
-
-}
+// 淘汰掉这个, 保留单一的MySQL操作入口: daoInst(). --gwang 2020年11月9日13:58:03
+//
+//namespace loyalsoft;
+//
+///**
+// * CDB工具类[APHP三大操作单元之一]
+// * @version 2.0.1 gwang 修补了部分mysqli方法 2020.3.25
+// *           2.0   gwang 升级到mysqli,以便能在PHP7.0以后的环境下继续运行. 约 2017
+// *           1.0   jgao  created 约 2013
+// * @author jgao,gwang
+// */
+//class CDbUtil {
+//
+//    public $conn = 0;
+//
+//    public function dbconn($dbhost, $dbport, $dbuser, $dbpw, $dbname) {
+//        $this->conn = mysqli_connect($dbhost, $dbuser, $dbpw, $dbname, $dbport, true);
+//        !$this->conn && $this->halt("Connect to MySQL failed");
+//        $serverinfo = mysqli_get_server_info($this->conn);
+//        if ($serverinfo > '4.1' && $GLOBALS['charset']) {
+//            mysqli_query($this->conn, "SET character_set_connection=" . $GLOBALS['charset'] . ",character_set_results=" . $GLOBALS['charset'] . ",character_set_client=binary");
+//        }
+//        if ($serverinfo > '5.0') {
+//            mysqli_query($this->conn, "SET sql_mode=''");
+//        }
+//        if ($dbname && !mysqli_select_db($this->conn, $dbname)) {
+//            $this->halt('Cannot use database');
+//        }
+//    }
+//
+//    /**
+//     * 切换db
+//     * @param type $dbname
+//     */
+//    public function select_db($dbname) {
+//        if (!mysqli_select_db($this->conn, $dbname)) {
+//            $this->halt('Cannot use database');
+//        }
+//    }
+//
+//    /**
+//     * 调取服务器信息
+//     * @return type
+//     */
+//    public function server_info() {
+//        return mysqli_get_server_info($this->conn);
+//    }
+//
+//    /**
+//     * 最后一次执行insert时插入的第一行记录Id,(如果一次插入3条记录,则得到第一条的记录)
+//     * 所以,这个如何用要慎重(gwang)
+//     * @return type
+//     */
+//    public function insert_id() {
+//        $arr = $this->fetch_array('SELECT LAST_INSERT_ID() as id');
+//        return $arr["id"];
+//    }
+//
+//    /**
+//     * 直接取查询结果的某行某列的数值
+//     * @param type $SQL
+//     * @param type $offset
+//     * @param type $field
+//     * @return boolean
+//     */
+//    public function get_value($SQL, $offset = 0, $field = 0) {
+//        $rt = $this->fetch_result($SQL);
+//        if (isset($rt[$offset][$field])) {
+//            return $rt[$offset][$field];
+//        }
+//        return false;
+//    }
+//
+//    /**
+//     * 执行查询
+//     * @param type $SQL
+//     * @param type $method
+//     * @param type $error
+//     * @return mixed
+//     */
+//    public function query($SQL, $method = null, $error = true) {
+//        $query = mysqli_query($this->conn, $SQL);
+//        !$query && $error && $this->halt('Query Error: ' . $SQL);
+//        return $query;
+//    }
+//
+//    /**
+//     * 执行更新的时候加上事物逻辑
+//     * @param type $SQL
+//     * @return int errno
+//     */
+//    public function safeQuery($SQL) {
+//        mysqli_query($this->conn, 'start transaction');
+//        mysqli_query($this->conn, 'SET autocommit=0');
+//        $query = mysqli_query($this->conn, $SQL);
+//        $err = mysqli_errno($this->conn);
+//        if ($err && !$query) {
+//            mysqli_query($this->conn, 'rollback');
+//        } else {
+//            mysqli_query($this->conn, 'commit');
+//        }
+//        mysqli_query($this->conn, 'SET autocommit=1');
+//        return $err;
+//    }
+//
+//    /**
+//     * 将查询结果作为索引数组返回
+//     * @param string $SQL
+//     * @return array
+//     */
+//    public function fetch_row($SQL) {
+//        return $this->fetch_result($SQL, MYSQLI_NUM);
+//    }
+//
+//    /**
+//     * 将查询结果作为关联数组返回
+//     * @param string $SQL
+//     * @return array
+//     */
+//    public function fetch_array($SQL) {
+//        return $this->fetch_result($SQL, MYSQLI_ASSOC);
+//    }
+//
+//    /**
+//     * 从结果中取一行作为结果返回
+//     * @param string $SQL
+//     * @param int $result_type 1. 关联数组, 2. 索引数组, 3 both
+//     * @return type
+//     */
+//    public function fetch_result($SQL, $result_type = MYSQLI_BOTH) {
+//        $arr = array();
+//        $query = $this->query($SQL);
+//        $data = mysqli_fetch_array($query, $result_type);
+//        while ($data) {
+//            $arr[] = $data;
+//            $data = mysqli_fetch_array($query, $result_type);
+//        }
+//        $this->free_result();
+//        return $arr;
+//    }
+//
+//    /**
+//     * 调取查询影响的行数
+//     * @return type
+//     */
+//    public function affected_rows() {
+//        return mysqli_affected_rows($this->conn);
+//    }
+//
+//    /**
+//     * 调取结果集中行的数目
+//     * @param type $SQL
+//     * @return int
+//     */
+//    public function num_rows($SQL) {
+//        $query = $this->query($SQL);
+//        if (!is_bool($query)) {
+//            return mysqli_num_rows($query);
+//        }
+//        return 0;
+//    }
+//
+//    /**
+//     * 调取结果集中字段数量
+//     * @param type $SQL
+//     * @return type
+//     */
+//    public function num_fields($SQL) {
+//        $query = $this->query($SQL);
+//        return mysqli_num_fields($query);
+//    }
+//
+//    /**
+//     * 封装SQL字符串中特殊字符,以免SQL语句执行失败.
+//     * @param type $str 带有风险字符的SQL语句或者字符串
+//     * @return type 处理后的字符串
+//     */
+//    public function escape_string($str) {
+//        return mysqli_real_escape_string($this->conn, $str);
+//    }
+//
+//    /**
+//     * 释放SQL查询结果
+//     */
+//    public function free_result() {
+//        $void = func_get_args();
+//        foreach ($void as $query) {
+//            if (is_resource($query) && get_resource_type($query) === 'mysql result') {
+//                mysqli_free_result($query);
+//            }
+//        }
+//        unset($void);
+//    }
+//
+//    /**
+//     * 关闭当前实例的连接
+//     * @return type
+//     */
+//    public function close() {
+//        $this->free_result();
+//        return mysqli_close($this->conn);
+//    }
+//
+//    /**
+//     * 直接报错退出
+//     * @param type $msg
+//     */
+//    public function halt($msg = null) {
+//        exit($msg . '<br /><br />' . mysqli_error($this->conn));
+//    }
+//
+//}

+ 2 - 1
Gameserver/Amfphp/util/CLog.php

@@ -175,6 +175,7 @@ class CLog {
         $key = "log-" . $typename;
         $arr = self::$$typename;                                                # 取对应类型的数组
         if (count($arr) > 0) {
+            $arr[] = JsonUtil::encode(req()->__toString());
             gMem()->lpush($key, $arr);
             if (gMem()->llen($key) > self::redis_log_trim_max + self::redis_log_trim_once) {# 达到清理条件
                 gMem()->ltrim($key, 0, -self::redis_log_trim_once);             # 缩减记录
@@ -200,7 +201,7 @@ class CLog {
             $data = array();
             array_map(function($v) use(&$data) {
                 $s = daoInst()->quote($v);
-                var_dump($s);
+//                var_dump($s);
                 $data[] = "(" . $s . ")";
             }, $arr);
             $sql_insert = "insert into `$key` (`msg`) values " . implode(',', $data) . " ;";

+ 15 - 11
Gameserver/nbproject/private/private.xml

@@ -12,20 +12,24 @@
     </editor-bookmarks>
     <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
         <group>
-            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/process/RankProc.php</file>
-            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/util/CV3Util.php</file>
+            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/util/CLog.php</file>
             <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/index.php</file>
-            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/process/StoreProc.php</file>
-            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/process/TaskProc.php</file>
-            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/util/OpenAPI/OpenApiV3.php</file>
-            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/process/StatProc.php</file>
-            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/Services/AppServer.php</file>
+            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/base/ErrCode.php</file>
+            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/process/FightProc/PVPProc.php</file>
+            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/util/ErrHandler.php</file>
+            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/util/CDbUtil.php</file>
+            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/base/Req.php</file>
+            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/util/StlUtil.php</file>
+            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/util/UtilInclude.php</file>
+            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/model/User/UserGameModel.php</file>
+            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/process/UserProc.php</file>
+            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/main.php</file>
+            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/util/CommUtil.php</file>
+            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/test.php</file>
+            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/base/Object_ext.php</file>
             <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/model/User/UserPVPModel.php</file>
-            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/util/OpenAPI/Test_UploadFile.php</file>
-            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/util/OpenAPI/Test_OpenApiV3.php</file>
             <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/process/SystemProc.php</file>
-            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/process/ShopProc.php</file>
-            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/util/OpenAPI/Cpay_for_CEE_V2.php</file>
+            <file>file:/D:/local_svn/0_ylsj2019/ylsj2019Server/Gameserver/Amfphp/util/dao.php</file>
         </group>
     </open-files>
 </project-private>