|
@@ -78,10 +78,9 @@ class robot extends Command
|
|
|
]
|
|
|
]);
|
|
|
// $robot = $response->getBody()->getContents();
|
|
|
-
|
|
|
$con = new AsyncTcpConnection('ws://183.234.61.252:8282');
|
|
|
// $con = new AsyncTcpConnection('ws://127.0.0.1:8282');
|
|
|
- $con->onConnect = function($con) use($client) {
|
|
|
+ $con->onConnect = function($con) use($client, $worker) {
|
|
|
};
|
|
|
$con->onMessage = function($con, $data) use($client, &$room_id, &$client_id, $user, $http_addr, $worker){
|
|
|
//注册地址
|
|
@@ -96,25 +95,32 @@ class robot extends Command
|
|
|
'client_id' => $client_id,
|
|
|
]
|
|
|
]);
|
|
|
- $result = json_decode($response->getBody()->getContents());
|
|
|
- if($result->code == 400 || ($result->code == 0 && $result->info->in_game == 1)){
|
|
|
- echo "断线重连中 ...";
|
|
|
+ if($response->getStatusCode() != 200){
|
|
|
+ echo "机器人绑定 socket失败, 结束进程\n";
|
|
|
+ //结束进程
|
|
|
+ $master_pid = is_file($worker::$pidFile) ? file_get_contents($worker::$pidFile) : 0;
|
|
|
+ $master_pid && posix_kill($master_pid, $sig);
|
|
|
return 0;
|
|
|
}
|
|
|
- echo "client: {$client_id} 成功绑定socket\n";
|
|
|
$update_data = [
|
|
|
"is_login" => 1,
|
|
|
"client_id" => $client_id,
|
|
|
];
|
|
|
//更新机器人登陆状态
|
|
|
User::where("user_id", $user->user_id)->update($update_data);
|
|
|
+ $result = json_decode($response->getBody()->getContents());
|
|
|
+ if($result->code == 400 || ($result->code == 0 && $result->info->in_game == 1)){
|
|
|
+ echo "断线重连中 ...";
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ echo "client: {$client_id} 成功绑定socket\n";
|
|
|
//启动匹配
|
|
|
- // $response = $client->request('GET', $http_addr . 'Home/Game/Join',[
|
|
|
- // 'form_params' => [
|
|
|
- // 'client_id' => $client_id,
|
|
|
- // ]
|
|
|
- // ]);
|
|
|
- // echo "{$client_id} 成功加入匹配\n";
|
|
|
+ $response = $client->request('GET', $http_addr . 'Home/Game/Join',[
|
|
|
+ 'form_params' => [
|
|
|
+ 'client_id' => $client_id,
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+ echo "{$client_id} 成功加入匹配\n";
|
|
|
}
|
|
|
//唤起匹配
|
|
|
if($json_data->type == 'gotomatch'){
|
|
@@ -151,16 +157,26 @@ class robot extends Command
|
|
|
|
|
|
//结算
|
|
|
if($json_data->type == 'round_end'){
|
|
|
+ file_get_contents($worker::$pidFile);
|
|
|
echo "回合结束,已结算";
|
|
|
}
|
|
|
|
|
|
//结算
|
|
|
if($json_data->type == 'game_end'){
|
|
|
+ $update_data = [
|
|
|
+ "is_login" => 0,
|
|
|
+ "client_id" => '',
|
|
|
+ ];
|
|
|
+ //更新机器人登陆状态
|
|
|
+ User::where("user_id", $user->user_id)->update($update_data);
|
|
|
unset($update_data);
|
|
|
$update_data['state'] = 2;
|
|
|
RoomUser::where("user_id", $user->user_id)->where("state", 1)->update($update_data);
|
|
|
- echo "已结算,机器人离开房间";
|
|
|
Gateway::leaveGroup($client_id, $room_id);
|
|
|
+ echo "已结算,机器人离开房间";
|
|
|
+ //结束进程
|
|
|
+ $master_pid = is_file($worker::$pidFile) ? file_get_contents($worker::$pidFile) : 0;
|
|
|
+ $master_pid && posix_kill($master_pid, $sig);
|
|
|
}
|
|
|
|
|
|
};
|