郑晓宇 лет назад: 6
Родитель
Сommit
ace9325dfc

+ 1 - 0
app/Console/Commands/gamematch.php

@@ -151,6 +151,7 @@ class gamematch extends Command
                 }
 
                 //执行发题
+                sleep(2);
                 Distribute::dispatch($room_id)->onQueue('distribute');
                 
                 //发送题目

+ 3 - 5
app/Console/Commands/recylerobots.php

@@ -44,15 +44,14 @@ class recylerobots extends Command
     {
         //注册地址
         Gateway::$registerAddress = '127.0.0.1:1238';
-        echo Gateway::isOnline("7f0000010b5700000cb6");exit;
-
+        echo Gateway::isUidOnline(3);exit;
         while(1){
             //获取所有机器人
             $robots = User::where("is_login", 1)->where("is_robot", 1)->get();
             if($robots){
                 foreach ($robots as $robot) {
                     //检测是否在线
-                    if(Gateway::isUidOnline($robot->user_id)){
+                    if(Gateway::isOnline($robot->client_id)){
                         //检测游戏是否结束
                         $has_game = RoomUser::where("user_id", $robot->user_id)->where("state", 1)->count();
                         if(!$has_game){
@@ -61,12 +60,11 @@ class recylerobots extends Command
                         }
                     }else{
                         $update_data["is_login"] = 0;
-                        $update_data["client_id"] = '';
                         User::where("user_id", $robot->user_id)->update($update_data);
                     }
                 }
             }
-            sleep(10);
+            sleep(5);
         }
 
     }

+ 10 - 5
app/Console/Commands/robot.php

@@ -60,14 +60,14 @@ class robot extends Command
             echo "未找到机器人";
             die;
         }
+        //定义请求客户端
+        $room_id = ''; //定义当前机器人加入的room_id
+        $client_id = ''; //定义当前机器人client_id
         $worker = new Worker();
-        $worker->onWorkerStart = function($worker) use($user){
+        $worker->onWorkerStart = function($worker) use($user, $room_id, $client_id){
             //定义基本信息
             $http_addr = 'http://183.234.61.252:8090/';
             // $http_addr = 'http://www.dt.com/';
-            //定义请求客户端
-            $room_id = ''; //定义当前机器人加入的room_id
-            $client_id = ''; //定义当前机器人client_id
             $client = new Client([
                 'cookies' => true,
                 'verify' => false,
@@ -177,7 +177,12 @@ class robot extends Command
                     $sig = SIGINT;
                     $master_pid = is_file($worker::$pidFile) ? file_get_contents($worker::$pidFile) : 0;
                     $master_pid && posix_kill($master_pid, $sig);
-                    Log::info("用户ID: {$user->user_id} \n 房间ID: {$room_id}\n 删除不了进程 {$master_pid}\n");
+
+                    $master_is_alive = $master_pid && posix_kill($master_pid, 0);
+                    if ($master_is_alive) {
+                        Log::info("用户ID: {$user->user_id} \n 房间ID: {$room_id}\n 删除不了进程 {$master_pid}\n");
+                    }
+
                 }
             };
             $con->connect();