function onClose($serv, $client_id, $from_id) { parent::onClose($serv, $client_id, $from_id); }
final function onClose($serv, $fd, $reactor_id) { if (isset($this->fd_session_map[$fd])) { $session_id = $this->fd_session_map[$fd]; unset($this->fd_session_map[$fd], $this->wait_requests[$session_id], $this->sessions[$session_id]); //再执行一次 $this->onExit($session_id); } parent::onClose($serv, $fd, $reactor_id); }
/** * 下线时(离开房间),通知房间所有人 */ function onClose($serv, $client_id, $from_id) { $userInfo = $this->store->getUser($client_id); if (!$userInfo) { return; } $resMsg = array('cmd' => 'offline', 'fd' => $client_id, 'from' => 0, 'rim' => $userInfo['rid'], 'data' => $userInfo['name'] . "下线了。。"); //将下线消息发送给所有人 $this->log("onOffline: " . $client_id); $room_id = isset($userInfo['rid']) ? $userInfo['rid'] : 0; echo PHP_EOL . "onClose: room_id:" . $room_id . ", client_id:" . $client_id; if ($room_id > 0) { $flag = $this->rooms->leaveRooms($client_id, $room_id); echo PHP_EOL . "leaveRooms: room_id:" . $room_id . ", client_id:" . $client_id; $this->store->logout($client_id, $room_id); $this->broadcastRoomsJson($client_id, $room_id, $resMsg); echo PHP_EOL . "broadcastRooms: room_id:" . $room_id . ", client_id:" . $client_id; } else { $this->store->logout($client_id); $this->broadcastJson($client_id, $resMsg); } parent::onClose($serv, $client_id, $from_id); }