void NetManager::event_onSessionDisconnect(TcpSessionPtr session) { LOGT("NetManager::event_onSessionDisconnect. SessionID=" << session->getSessionID() << ", remoteIP=" << session->getRemoteIP() << ", remotePort=" << session->getRemotePort()); if (isConnectID(session->getSessionID())) { } else { if (session->getUserParam() == SS_LOGINED) { auto info = UserManager::getRef().getInnerUserInfoBySID(session->getSessionID()); if (info) { UserManager::getRef().userLogout(info); info->sID = InvalidSeesionID; } } } if (UserManager::getRef().getAllOnlineUserCount() == 0 && _onSafeClosed) { SessionManager::getRef().post(_onSafeClosed); _onSafeClosed = nullptr; } }
void NetMgr::event_onClosed(TcpSessionPtr session) { LOGD("NetMgr::event_onClosed. SessionID=" << session->getSessionID() << ", remoteIP=" << session->getRemoteIP() << ", remotePort=" << session->getRemotePort()); if (isConnectID(session->getSessionID())) { } else { if (session->getUserParamNumber(UPARAM_SESSION_STATUS) == SSTATUS_LOGINED) { auto founder = _mapUserInfo.find(session->getUserParamNumber(UPARAM_USER_ID)); if (founder == _mapUserInfo.end() || founder->second->sID != session->getSessionID()) { _mapSession.erase(session->getSessionID()); return; } event_onLogout(founder->second); founder->second->sID = InvalidSessionID; } _mapSession.erase(session->getSessionID()); } if (_mapSession.size() == 0 && _onSafeClosed) { SessionManager::getRef().post(_onSafeClosed); _onSafeClosed = nullptr; } }