郑晓宇 6 years ago
parent
commit
f30e541cba
1 changed files with 9 additions and 4 deletions
  1. 9 4
      app/Console/Commands/robot.php

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

@@ -71,7 +71,7 @@ class robot extends Command
             $con = new AsyncTcpConnection('ws://183.234.61.252:8282');
             $con->onConnect = function($con) use($client) {
             };
-            $con->onMessage = function($con, $data) use($client, $room_id, $client_id){
+            $con->onMessage = function($con, $data) use($client, &$room_id, &$client_id){
                 //注册地址
                 Gateway::$registerAddress = '127.0.0.1:1238';
                 //格式化参数
@@ -129,9 +129,14 @@ class robot extends Command
                 }
                 //获得题目
                 if($json_data->type == 'checkrobot'){
-                    echo "{$client_id} 成功重回队列\n";
-                    //重新加入机器人队列
-                    Redis::sadd('robot_list', $json_data->client_id);
+                    if($room_id && $client_id){
+                        $clients = Gateway::getClientIdListByGroup($room_id);
+                        if(count($clients) < 2){
+                            echo "{$client_id} 成功重回队列\n";
+                            //重新加入机器人队列
+                            Redis::sadd('robot_list', $json_data->client_id);
+                        }
+                    }
                 }
             };
             $con->connect();