瀏覽代碼

Merge branch 'dev' of http://ylsjtt.game7000.com:3000/YLSJ/jzhj2024server into dev

cyzhao 1 年之前
父節點
當前提交
89eedfa0e7

+ 4 - 0
Gameserver/App/base/Resp.php

@@ -111,6 +111,10 @@ class Resp extends Object_ext {
                 }
             }
         }
+        if (count(CRedisUtil::$caller_counter) > 0) {
+            echoLine("called Number: " . count(CRedisUtil::$caller_counter));
+            echoLine(json_encode(CRedisUtil::$caller_counter));
+        }
     }
 
     // <editor-fold defaultstate="collapsed" desc="附加event带回">

+ 17 - 13
Gameserver/App/process/FightProc.php

@@ -599,13 +599,13 @@ class FightProc {
                 $r = rand(0, $n);                                                  # 投色子
                 $l = 0;
                 foreach ($pool as $item) {
-                    if ($r < ($l + $item->p)) {
-                        $gemId = $item->q * 10000 + rand(1, 6) * 1000;
+                    if ($r < ($l + $item['p'])) {
+                        $gemId = $item['q'] * 100000 + rand(1, 6) * 1000;
                         StoreProc::PutGemInStore($gemId);                       # 发放宝石并退出本次投色子
                         $pickups .= ";$gemId,1";
                         break;
                     }
-                    $l += $item->p;                                             # 累计到下一段
+                    $l += $item['p'];                                             # 累计到下一段
                 }
             }
         }
@@ -984,33 +984,37 @@ class FightProc {
         $ret = array();
         return Resp::ok($ret);
     }
+
     /*
      * 删除排行榜内注销账号的玩家
      */
+
     public static function DeleteRankInvalidUser($uid) {
-        gMem()->zrem(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), $uid);    
-        gMem()->zrem(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), $uid);    
+        gMem()->zrem(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), $uid);
+        gMem()->zrem(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), $uid);
     }
+
     /*
      * 排行玩家头像变动
      */
-    public static function UpdateRankUserHeadImg($uid,$headImg) {
+
+    public static function UpdateRankUserHeadImg($uid, $headImg) {
         $memKey1 = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
         $dic = gMem()->hgetall($memKey1);
         foreach ($dic as $gateId => $ins_rank) {
-            if($ins_rank->uid == $uid){
-                $ins_rank->headImg = $headImg;              
+            if ($ins_rank->uid == $uid) {
+                $ins_rank->headImg = $headImg;
                 gMem()->hset($memKey1, $gateId, $ins_rank);
-            }                     
+            }
         }
-        
+
         $memKey2 = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
         $dic2 = gMem()->hgetall($memKey2);
         foreach ($dic2 as $fightPower => $ins_rank) {
-            if($ins_rank->uid == $uid){
-                $ins_rank->headImg = $headImg; 
+            if ($ins_rank->uid == $uid) {
+                $ins_rank->headImg = $headImg;
                 gMem()->hset($memKey2, $fightPower, $ins_rank);
-            } 
+            }
         }
     }
 

+ 62 - 62
Gameserver/App/process/StoreProc.php

@@ -50,57 +50,57 @@ class StoreProc {
                 Err(ErrCode::cmd_err);
         }
     }
-    
+
     /**
      * 洗练
      * @return Resp
      */
     public static function gemXiLian() {
         list($uid) = req()->paras;
-          
+
         //把 qual pos u一样的宝石开锁关锁
         $gemStore = ctx()->store->gemStore;
         my_Assert(StlUtil::dictHasProperty($gemStore, $uid), ErrCode::user_store_NotExistGem);
-        
+
         $gem = new Ins_Gem($gemStore->$uid);
         my_Assert($gem->mo()->qual >= 5, ErrCode::user_store_GemNotXilian);
-        
-        $arr = explode(';', glc()->XILianGemlNeedXILianStone); 
+
+        $arr = explode(';', glc()->XILianGemlNeedXILianStone);
         $needStone = 0;
         foreach ($arr as $val) {
             $str = explode(':', $val);
-            if($str[0] == $gem->mo()->qual){
+            if ($str[0] == $gem->mo()->qual) {
                 $needStone = $str[1];
                 break;
             }
         }
-        
+
         my_Assert(ctx()->baseInfo->xilianStone >= $needStone, ErrCode::user_store_XilianStoneNoEnough);
- 
+
         $dic = GameConfig::predicate();
         $pList = array();
         foreach ($dic as $id => $pMo) {
-            if($pMo->positions != null && $pMo->qual != null){
-                $list = explode(',',$pMo->positions);
-                if($pMo->id != $gem->predicateId && $pMo->qual == $gem->mo()->qual && in_array($gem->mo()->position, $list)){
+            if ($pMo->positions != null && $pMo->qual != null) {
+                $list = explode(',', $pMo->positions);
+                if ($pMo->id != $gem->predicateId && $pMo->qual == $gem->mo()->qual && in_array($gem->mo()->position, $list)) {
                     $pList[] = $pMo->id;
                 }
-            }                    
+            }
         }
         my_Assert(count($pList) > 0, ErrCode::user_store_NoFindPredicate);
-        $rand = random_int(0, count($pList)-1);
-        $pId = $pList[$rand]; 
-        ctx()->store->gemStore->$uid->predicateId = $pId;     
-        
+        $rand = random_int(0, count($pList) - 1);
+        $pId = $pList[$rand];
+        ctx()->store->gemStore->$uid->predicateId = $pId;
+
         ctx()->baseInfo->xilianStone -= $needStone;
-        
+
         UserProc::updateUserInfo();
         return Resp::ok(array(
                     'xilianStone' => ctx()->baseInfo->xilianStone,
                     'predicateId' => $pId,
         ));
     }
-    
+
     /**
      * 宝石开锁解锁
      * @return Resp
@@ -154,7 +154,7 @@ class StoreProc {
     /**
      * 所有装备的一键升级
      * 规则:等级不同从等级小到大,等级一样按照部位顺序
-     * 
+     *
      * @return Resp
      */
     public static function allEquipUpgrade() {
@@ -199,8 +199,8 @@ class StoreProc {
                     }
                 }
             }
-            
-            //升级,扣除金币和图纸      
+
+            //升级,扣除金币和图纸
             while (true) {
                 $tag = 9999;
                 foreach ($arr as $index => &$equip) {
@@ -211,10 +211,10 @@ class StoreProc {
                     $neeItemId = $ins_equip->mo()->costTuzhiId;
                     if ($user->baseInfo->gold >= $needGold && StlUtil::dictHasProperty($user->store->items, $neeItemId) && $user->store->items->$neeItemId >= $needItemNum) {
                         $id = $ins_equip->typeId;
-                        if(!in_array($id, $upLevelArr)){
+                        if (!in_array($id, $upLevelArr)) {
                             $upLevelArr[] = $id;
                         }
-                        
+
                         $ins_equip->level += 1;
                         $equipDic->$id->level += 1;
                         $user->baseInfo->Consume_Gold($needGold);
@@ -247,11 +247,11 @@ class StoreProc {
         ctx($user);
         UserProc::updateUserInfo();
         return Resp::ok(array(
-                    'upLevelArr'=>$upLevelArr,
+                    'upLevelArr' => $upLevelArr,
                     'gold' => $user->baseInfo->gold,
                     'store' => $user->store,
-                    'task'=>$user->task,
-            ));
+                    'task' => $user->task,
+        ));
     }
 
     /**
@@ -382,7 +382,7 @@ class StoreProc {
 
                         $index += 1;
                         self::RemoveGemInStore($uid);
-                        //$composeArr 有的话删除                    
+                        //$composeArr 有的话删除
                         for ($i = 0; $i < count($composeArr); $i++) {
                             if ($composeArr[$i]->uid == $uid) {
                                 StlUtil::arrayRemoveAt($composeArr, $i);
@@ -394,7 +394,7 @@ class StoreProc {
                             $res += 1;
                             $composeGem = self::initGem($gemConf->typeId);
                             self::PutGemInStore2($composeGem);
-                            $composeArr[] = $composeGem; //临时放这                                             
+                            $composeArr[] = $composeGem; //临时放这
                         }
 
                         if ($res >= $maxGemNum) {
@@ -414,8 +414,8 @@ class StoreProc {
         return Resp::ok(array(
                     'composeGemIds' => $resultArr,
                     'store' => $user->store,
-                    'task'=>$user->task,
-            ));
+                    'task' => $user->task,
+        ));
     }
 
     /**
@@ -476,7 +476,7 @@ class StoreProc {
      * @return type
      */
     public static function gemSet() {
-        list($uid, $type, $replaceUId) = req()->paras; //宝石uid  手动的时候记得校验u            
+        list($uid, $type, $replaceUId) = req()->paras; //宝石uid  手动的时候记得校验u
         $user = ctx();
 
         my_Assert(StlUtil::dictHasProperty($user->store->gemStore, $uid), ErrCode::user_store_NoItem);
@@ -498,7 +498,7 @@ class StoreProc {
         }
 
         switch ($type) {
-            case 1://镶嵌                
+            case 1://镶嵌
                 my_Assert($tag_gem == null, ErrCode::user_store_GemCanotSet);
                 for ($i = 1; $i <= 5; $i++) {
                     if (!StlUtil::dictHasProperty($dic, $i)) {
@@ -527,27 +527,27 @@ class StoreProc {
                 my_Assert(StlUtil::dictHasProperty($user->store->gemStore, $replaceUId), ErrCode::user_store_NoExistGemReplace);
                 $replace_ins_Gem = new Ins_Gem($user->store->gemStore->$replaceUId);
                 //$id = $replace_ins_Gem->uid;
-                if ($tag_gem != null) {//如果有u那                                    
+                if ($tag_gem != null) {//如果有u那
                     my_Assert($replace_ins_Gem->uid == $tag_gem->uid, ErrCode::user_store_SameGemCanotEquip); //点的不是u一样的,则提示同一件装备无法镶嵌多个技能相同的宝石 【错误】
-                    //有U一样的,则点击正好是这个直接替换                  
-                    //$user->store->gemStore->$id = $replace_ins_Gem;                                       
+                    //有U一样的,则点击正好是这个直接替换
+                    //$user->store->gemStore->$id = $replace_ins_Gem;
                     $dic->$tag_index = $ins_gem;
-                } else {                  
+                } else {
                     $go_index = 0;
-                    foreach ($dic as $index => $g) {                      
+                    foreach ($dic as $index => $g) {
                         if ($g->uid == $replaceUId) {
                             $go_index = $index;
                             break;
                         }
                     }
-                  
-                    my_Assert($go_index > 0, ErrCode::user_store_NoExistGemReplace);                   
+
+                    my_Assert($go_index > 0, ErrCode::user_store_NoExistGemReplace);
                     $dic->$go_index = $ins_gem;
                 }
-              
+
                 break;
             case 4://不能
-                //1.小品阶替大品阶  或是  相等的,在不满的时候不允许    2. //满的  相等不允许替                      
+                //1.小品阶替大品阶  或是  相等的,在不满的时候不允许    2. //满的  相等不允许替
                 my_Assert($uid == 0, ErrCode::user_store_SameGemCanotEquip); //点的不是u一样的,则提示同一件装备无法镶嵌多个技能相同的宝石 【错误】
                 break;
             default:
@@ -555,15 +555,15 @@ class StoreProc {
         }
 
         $user->store->gemEquip->$pag->$posId = $dic;
-        
+
         TaskProc::OnSetSpecialQualGem();
         ctx($user);
         UserProc::updateUserInfo();
         return Resp::ok(array(
                     'gold' => 0,
                     'store' => $user->store,
-                    'task'=>$user->task,
-            ));
+                    'task' => $user->task,
+        ));
     }
 
     /**
@@ -625,7 +625,7 @@ class StoreProc {
         ctx()->baseInfo->Consume_Gold($mo->needGold);
 
         $user->store->equip->$posId->level += 1;
-        
+
         TaskProc::OnAnyEquipUpLevel_X();
         TaskProc::OnAllEquipUpLevel_X();
         TaskProc::OnEquipLevelUpNum();
@@ -634,8 +634,8 @@ class StoreProc {
         return Resp::ok(array(
                     'gold' => $user->baseInfo->gold,
                     'store' => $user->store,
-                    'task'=>$user->task,
-                ));
+                    'task' => $user->task,
+        ));
     }
 
     /**
@@ -689,7 +689,7 @@ class StoreProc {
         return Resp::ok(array(
                     'gold' => $user->baseInfo->gold,
                     'store' => $user->store,
-                    'task'=>$user->task,
+                    'task' => $user->task,
         ));
     }
 
@@ -854,7 +854,7 @@ class StoreProc {
      */
     public static function RandomGemPredicateId($id) {
         $mo = GameConfig::gem_getItem($id);
-
+        my_Assert(null != $mo, "找不到宝石{$id}的配置数据");
         if ($mo->isfixed_predicateId == 1) {
             return $mo->predicateId;
         }
@@ -866,17 +866,17 @@ class StoreProc {
         foreach ($predicateMo as $key => $value) {
             if ($value->positions != null) {
                 $list = explode(',', $value->positions);
-                if ($value->qual == $qual && in_array($posId,$list) && $value->attachTarget == "gem") {
+                if ($value->qual == $qual && in_array($posId, $list) && $value->attachTarget == "gem") {
                     $arr[] = $value->id;
                 }
             }
         }
-        
-        if(count($arr) <= 0){
+
+        if (count($arr) <= 0) {
             return 40;
         }
         my_Assert(count($arr) > 0, "宝石没有对应词条信息");
-        $n = mt_rand(0, count($arr)-1);
+        $n = mt_rand(0, count($arr) - 1);
         return $arr[$n];
 
         //return 40;
@@ -903,21 +903,21 @@ class StoreProc {
 //        if(count((array)ctx()->store->gemStore) > 0){
 //            return;
 //        }
-//        
+//
 //        $index = 0;
 //        $gem = GameConfig::gem();
-//             
+//
 //        for ($i = 1; $i <=21; $i++) {
-//            foreach ($gem as $key => $value) {  
+//            foreach ($gem as $key => $value) {
 //                if($value->id == $i){
-//                    self::PutGemInStore($value->typeId);   
+//                    self::PutGemInStore($value->typeId);
 //                }
-//                             
+//
 //            }
 //        }
-//        
-//        
-//        
-//        
+//
+//
+//
+//
 //    }
 }

+ 4 - 2
Gameserver/App/test.php

@@ -28,7 +28,9 @@ use \loyalsoft\pay\OrderNotice;
 $s = '{"uid":"639743559740E0681F7E0EBBFE60B5C8","cmd":6000,"paras":[false],"ts":1716347687,"zoneid":1,"SN":1,"TK":"","CV":"unityEditor"}';
 new Req($s);
 req()->CV = "999.999.999";
-$arr = GameConfig::waves_getItemArray(FightProc::TowerGateId);
-var_dump($arr);
+//$arr = GameConfig::waves_getItemArray(FightProc::TowerGateId);
+//var_dump($arr);
 
 var_dump(explode('-', '1-2'));
+
+var_dump(DebugHelper::get_call_stack(0, 10));

+ 17 - 2
Gameserver/App/util/CRedisUtil.php

@@ -2,7 +2,7 @@
 
 namespace loyalsoft;
 
-//define('Redis_Debug', true); // 调试redis操作
+define('Redis_Debug', true); // 调试redis操作
 //require __DIR__ . '/Predis/Autoloader.php';
 require __DIR__ . '/predis-2.0.0/src/Autoloader.php';                           # 2022.8.16 更新Predis代码到2.0
 
@@ -28,7 +28,21 @@ require __DIR__ . '/predis-2.0.0/src/Autoloader.php';
  *          1.0.0  pguan,基础功能, 方法与memcache看齐. <br/>
  */
 class CRedisUtil {
+
 //    public $keyDic = null;
+// <editor-fold defaultstate="collapsed" desc="性能分析">
+
+
+    static $caller_counter = array();
+
+    /**
+     * 调用统计
+     */
+    public static function AddCallCount() {
+        self::$caller_counter[] = DebugHelper::get_call_stack(3, 2, true);
+    }
+
+    // </editor-fold>
 
     /**
      *
@@ -45,7 +59,8 @@ class CRedisUtil {
 
     private static function debug() {
         if (defined('Redis_Debug') && Redis_Debug) {
-            DebugHelper::debug(DebugHelper::get_call_stack());
+//            DebugHelper::debug(DebugHelper::get_call_stack());
+            self::AddCallCount();
         }
     }
 

+ 8 - 10
Gameserver/App/util/DebugHelper.php

@@ -135,21 +135,19 @@ class DebugHelper {
 
     /**
      * 获得调用堆栈
-     * @param int $levelnum 想要获得的调用层次,default is 3
+     * @param int $nestedLevelNum 调用的嵌套层次,default is 1
      * @return string formated string
      */
-    static public function get_call_stack($levelnum = 3) {
-        $array = debug_backtrace();
+    static public function get_call_stack($nestedLevelNum = 1, $n = 1, $printArg = false) {
         $outHtml = PHP_EOL;
-        array_shift($array);                                                    # 移除get_call_stack函数自身
-        $n = 1;
+        $arr = debug_backtrace();
+        $array = array_slice($arr, $nestedLevelNum, $n);                        # 移除get_call_stack函数自身
         foreach ($array as $row) {
             $outHtml .= "\t" . CommUtil::str2UTF8(self::arr_get($row, 'file'))  # windows下路径(gb2312)转码
-                    . ', row: ' . self::arr_get($row, 'line') . ', method: '    # line
-                    . self::arr_get($row, 'function') . ";<br/>" . PHP_EOL;     # func
-            if ($levelnum <= $n++) {
-                break;
-            }
+                    . ', row: ' . self::arr_get($row, 'line')                   # line
+                    . ', method: ' . self::arr_get($row, 'function') . '()'     # func
+                    . $printArg ? (', args:' . json_encode(self::arr_get($row, 'args'))) : ""      # 参数
+                    . ";<br/>" . PHP_EOL;
         }
         return $outHtml;
     }

+ 2 - 3
Gameserver/App/util/ErrHandler.php

@@ -21,7 +21,7 @@ class ErrHandler {
      */
     static function error_handler($errno, $errstr, $errfile, $errline) {
         $msg = CommUtil::str2UTF8($errstr) . " in " . CommUtil::str2UTF8($errfile) . ":" . $errline;
-        CLog::err($msg . PHP_EOL . DebugHelper::get_call_stack(10), 'Error Handler:');
+        CLog::err($msg . PHP_EOL . DebugHelper::get_call_stack(), 'Error Handler:');
         return TRUE;                                                            # 不再继续错误处理的冒泡过程::则代码得以继续执行
 //        if ($errno == E_USER_ERROR && !(php_sapi_name() === 'cli')) {           # 如果是用户自定义错误,直接返回resp, 这种情况的话,可以刷下数据
 //            CLog::flush();                                                      # 最后再将快速日志刷到文件
@@ -51,7 +51,7 @@ class ErrHandler {
         $msg = CommUtil::str2UTF8($exception->getMessage())
                 . '  in ' . CommUtil::str2UTF8($exception->getFile())
                 . ":" . $exception->getLine();
-        CLog::err($msg . PHP_EOL . DebugHelper::get_call_stack(10), 'Exception Handler:');
+        CLog::err($msg . PHP_EOL . DebugHelper::get_call_stack(), 'Exception Handler:');
         CLog::flush();                                                          # 最后再将快速日志刷到文件,因为后续逻辑执行就中断了
     }
 
@@ -68,7 +68,6 @@ class ErrHandler {
             error_reporting(0);                                                 # 非调试模式关闭所有的错误报告
         }
     }
-
 }
 
 // 越早启用捕获的错误信息也就越全面