Przeglądaj źródła

更新机器人启动逻辑

郑晓宇 6 lat temu
rodzic
commit
adac0cca06
1 zmienionych plików z 9 dodań i 3 usunięć
  1. 9 3
      app/Console/Commands/robot.php

+ 9 - 3
app/Console/Commands/robot.php

@@ -48,6 +48,10 @@ class robot extends Command
      */
     public function handle()
     {
+        global $argv;
+        $argv[0] = 'wk';
+        $argv[1] = "start";
+        $argv[2] = '';
         //获取机器人信息
         $user_id = $this->argument('user_id');
         if(!$user_id){
@@ -100,9 +104,10 @@ class robot extends Command
                     if($response->getStatusCode() != 200){
                         echo "机器人绑定 socket失败, 结束进程\n";
                         //结束进程
-                        $sig = SIGINT;
+                        $sig = SIGTERM;
                         $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 绑定Socket失败退出进程\n");
                         return 0;
                     }
                     $update_data = [
@@ -114,9 +119,10 @@ class robot extends Command
                     $result = json_decode($response->getBody()->getContents());
                     if($result->code == 400 || ($result->code == 0 && $result->info->in_game == 1)){
                         //结束进程
-                        $sig = SIGINT;
+                        $sig = SIGTERM;
                         $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 正在游戏或者登录失败退出进程\n");
                         return 0;
                     }
                     echo "client: {$client_id} 成功绑定socket\n";
@@ -173,7 +179,7 @@ class robot extends Command
                     User::where("user_id", $user->user_id)->update($update_data);
                     echo "已结算,机器人离开房间";
                     //结束进程
-                    $sig = SIGINT;
+                    $sig = SIGTERM;
                     $master_pid = is_file($worker::$pidFile) ? file_get_contents($worker::$pidFile) : 0;
                     $master_pid && posix_kill($master_pid, $sig);