12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use GatewayWorker\Lib\Gateway;
- use Illuminate\Support\Facades\Redis;
- use App\Model\User;
- use App\Model\Room;
- use App\Model\RoomUser;
- class recylerobots extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'game:recylerobots';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '机器人资源回收';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- //注册地址
- Gateway::$registerAddress = '127.0.0.1:1238';
- 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)){
- //检测游戏是否结束
- $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{
- $update_data["is_login"] = 0;
- $update_data["client_id"] = '';
- User::where("user_id", $robot->user_id)->update($update_data);
- }
- }
- }
- sleep(10);
- }
- }
- }
|