| 
															
																@@ -5,6 +5,9 @@ namespace App\Console\Commands; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 use Illuminate\Console\Command; 
															 | 
															
															 | 
															
																 use Illuminate\Console\Command; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 use GatewayWorker\Lib\Gateway; 
															 | 
															
															 | 
															
																 use GatewayWorker\Lib\Gateway; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 use Illuminate\Support\Facades\Redis; 
															 | 
															
															 | 
															
																 use Illuminate\Support\Facades\Redis; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+use App\Model\User; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+use App\Model\Room; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+use App\Model\RoomUser; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																  
															 | 
															
															 | 
															
																  
															 | 
														
													
												
													
														
															| 
															 | 
															
																 class recylerobots extends Command 
															 | 
															
															 | 
															
																 class recylerobots extends Command 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 { 
															 | 
															
															 | 
															
																 { 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -41,18 +44,24 @@ class recylerobots extends Command 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     { 
															 | 
															
															 | 
															
																     { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         //注册地址 
															 | 
															
															 | 
															
																         //注册地址 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         Gateway::$registerAddress = '127.0.0.1:1238'; 
															 | 
															
															 | 
															
																         Gateway::$registerAddress = '127.0.0.1:1238'; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         while(1){ 
															 | 
															
															 | 
															
																         while(1){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             //获取所有机器人 
															 | 
															
															 | 
															
																             //获取所有机器人 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            $robots = Redis::lrange('online_robot_list', 0, -1); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            $robots = User::where("is_login", 1)->where("is_robot", 1)->get(); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             if($robots){ 
															 | 
															
															 | 
															
																             if($robots){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 foreach ($robots as $robot) { 
															 | 
															
															 | 
															
																                 foreach ($robots as $robot) { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-                    $message['type'] = 'checkrobot'; 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                     //检测是否在线 
															 | 
															
															 | 
															
																                     //检测是否在线 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-                    if(Gateway::isOnline($robot)){ 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-                        Gateway::sendToClient($robot, json_encode($message)); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+                    if(Gateway::isOnline($robot->user_id)){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+                        //检测游戏是否结束 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+                        $has_game = RoomUser::where("user_id", $user_id)->where("state", 1)->count(); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+                        if(!$has_game){ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+                            $message['type'] = "game_end"; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+                            Gateway::sendToUid($robot->user_id, json_encode($message)); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+                        } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                     }else{ 
															 | 
															
															 | 
															
																                     }else{ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-                        Redis::lrem('online_robot_list', 0, $robot); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-                        Redis::srem('robot_list', $robot); 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+                        $update_data["is_login"] = 0; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+                        $update_data["client_id"] = ''; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+                        User::where("user_id", $robot->user_id)->update($update_data); 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                     } 
															 | 
															
															 | 
															
																                     } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 } 
															 | 
															
															 | 
															
																                 } 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             } 
															 | 
															
															 | 
															
																             } 
															 |