void World::AddSession_ (WorldSession* s) { //NOTE - Still there is race condition in WorldSession* being used in the Sockets ///- kick already loaded player with same account (if any) and remove session ///- if player is in loading and want to load again, return if (!RemoveSession (s->GetAccountId ())) { s->KickPlayer (); delete s; // session not added yet in session list, so not listed in queue return; } // if session already exist, prepare to it deleting at next world update // NOTE - KickPlayer() should be called on "old" in RemoveSession() { SessionMap::const_iterator old = m_sessions.find(s->GetAccountId ()); if(old != m_sessions.end()) { delete old->second; } } m_sessions[s->GetAccountId ()] = s; }
void AdviceManager::RemoveAdvisor(uint32_t id, int connectionId) { //Remove an advisor for (size_t i = 0; i < advisors.GetSize(); i++) { if (advisors[i].id == id) { Client * client = psserver->GetConnections()->Find(advisors[i].id); if (client) client->SetAdvisor( false ); advisors.DeleteIndex(i); break; } } AdviceSession *activeSession = AdviseeList.Get(id, NULL); while ( activeSession ) { // Notify advisee his/her advisor is no longer available. CancelAdvisorSession( NULL, activeSession, "been canceled"); RemoveSession( activeSession ); activeSession = AdviseeList.Get(id, NULL); } //Send message to non-advisor that he/she isn't an advisor any more psserver->SendSystemInfo(connectionId,"You have just laid down your advisor role."); }
void AdviceManager::AddAdvisor(Client *client) { if (!client) return; uint32_t id = client->GetClientNum(); // make sure we didn't do an "/advisor on" twice... for (size_t i = 0; i < advisors.GetSize(); i++) { if ( id == advisors[i].id) return; } //check to see if there is an advice session from this user, and close it AdviceSession *adviceSession = AdviseeList.Get(id, NULL); if (adviceSession) { CancelAdvisorSession( NULL, adviceSession, "been canceled" ); RemoveSession( adviceSession ); } // Create new Advisor structure AdvisorStruct advisor; advisor.id = id; advisor.ready = true; advisor.GM = client->GetSecurityLevel() >= GM_TESTER; advisors.Push(advisor); client->SetAdvisor( true ); //Send message to advisor that he/she is an advisor psserver->SendSystemInfo(id,"Your request to become an advisor has been granted."); //psserver->SendSystemInfo(id, "You currently have %d advisor points.", client->GetAdvisorPoints() ); }
void XnSensorServer::CleanUpSessions() { XnStatus nRetVal = XN_STATUS_OK; XnAutoCSLocker locker(m_hSessionsLock); if (!m_sessions.IsEmpty()) { XnSessionsList::Iterator it = m_sessions.Begin(); while (it != m_sessions.End()) { XnSessionsList::Iterator curr = it; ++it; XnServerSession* pSession = *curr; if (pSession->HasEnded()) { nRetVal = RemoveSession(curr); if (nRetVal != XN_STATUS_OK) { xnLogWarning(XN_MASK_SENSOR_SERVER, "failed to remove session: %s", xnGetStatusString(nRetVal)); } } } } }
void UmcFramework::ProcessSessionExit(UmcSession* pUmcSession) { if(!pUmcSession) return; RemoveSession(pUmcSession); delete pUmcSession; }
void SessionMgr::DestroySession(Session* pSession ) { if( !RemoveSession( pSession->GetID() ) ) { LOG_ERROR( logger, __FUNCTION__ << " failed to remove session from s_SessionMgr, id: " << pSession->GetID() ); } s_SessionPool.DeallocateSession( pSession ); }
bool CDialogSystem::DeleteSession(CDialogSystem::SessionID id) { TDialogSessionMap::iterator iter = m_allSessions.find(id); if (iter == m_allSessions.end()) return false; CDialogSession* pSession = iter->second; // remove it from the active sessions RemoveSession(pSession); stl::push_back_unique(m_pendingDeleteSessions, pSession); m_allSessions.erase(iter); stl::find_and_erase(m_restoreSessions, id); // erase it from sessions which will be restored return true; }
CLogSession::~CLogSession() /** * Destructor */ { // Check for null // Session close without a createlog call leaves iControl null // A logfile control structure can have multiple server sessions // decrement its server session count RemoveSession(); CLogServer* p=(CLogServer*) Server(); // Shuts Down the server if this is the last open session p->ControlComplete(*this); }
Debugger::EventLoopResult Debugger::EnterEventLoop() { DEBUG_EVENT dbgEvent; m_flagEventLoopExit = false; while (!m_flagEventLoopExit) { if (m_sessions.size() == 0) return EventLoopResult::AllDetached; DebugSession::ContinueStatus contStatus = DebugSession::ContinueStatus::ContinueThread; // continue by default if (::WaitForDebugEvent(&dbgEvent, INFINITE) == 0) return EventLoopResult::ErrorOccurred; auto itr = m_sessions.find(dbgEvent.dwProcessId); if (itr == m_sessions.end()) continue; // this shouldn't happen though auto pSession = itr->second; DebugSession::PreEvent preEvent = { dbgEvent.dwDebugEventCode, dbgEvent.dwThreadId }; pSession->OnPreEvent(preEvent); switch (dbgEvent.dwDebugEventCode) { case EXCEPTION_DEBUG_EVENT: { contStatus = pSession->OnExceptionTriggered(dbgEvent.u.Exception); break; } case CREATE_THREAD_DEBUG_EVENT: { contStatus = pSession->OnThreadCreated(dbgEvent.u.CreateThread); break; } case CREATE_PROCESS_DEBUG_EVENT: { contStatus = pSession->OnProcessCreated(dbgEvent.u.CreateProcessInfo); CloseHandle(dbgEvent.u.CreateProcessInfo.hFile); break; } case EXIT_THREAD_DEBUG_EVENT: { contStatus = pSession->OnThreadExited(dbgEvent.u.ExitThread); break; } case EXIT_PROCESS_DEBUG_EVENT: { contStatus = pSession->OnProcessExited(dbgEvent.u.ExitProcess); break; } case LOAD_DLL_DEBUG_EVENT: { contStatus = pSession->OnDllLoaded(dbgEvent.u.LoadDll); CloseHandle(dbgEvent.u.LoadDll.hFile); break; } case UNLOAD_DLL_DEBUG_EVENT: { contStatus = pSession->OnDllUnloaded(dbgEvent.u.UnloadDll); break; } case OUTPUT_DEBUG_STRING_EVENT: { contStatus = pSession->OnStringOutput(dbgEvent.u.DebugString); break; } case RIP_EVENT: { contStatus = pSession->OnRipEvent(dbgEvent.u.RipInfo); break; } default: { break; } } ::ContinueDebugEvent( dbgEvent.dwProcessId, dbgEvent.dwThreadId, contStatus == DebugSession::ContinueStatus::NotHandled ? DBG_EXCEPTION_NOT_HANDLED : DBG_CONTINUE ); if (contStatus == DebugSession::ContinueStatus::CloseSession) RemoveSession(dbgEvent.dwProcessId, DebugSession::EndOption::Detach); } return EventLoopResult::ExitRequested; }
int LSelectServer::ThreadDoing(void* pParam) { while (1) { unsigned short usProcessedCloseWorkCount = 0; unsigned int unSessionIDForClose = 0; while (GetOneCloseSessionWork(unSessionIDForClose)) { LSelectServerSession* pSession = FindSession(unSessionIDForClose); if (pSession != NULL) { bool bReconnect = pSession->GetReconnect(); pSession->ReleaseAllPacketInSendQueue(); #ifndef WIN32 close(pSession->GetSocket()); #else closesocket(pSession->GetSocket()); #endif RemoveSession(unSessionIDForClose); FreeSession(pSession); AddOneRecvedPacket(unSessionIDForClose, NULL); if (bReconnect) { char szIP[32]; unsigned short usPort = 0; #ifndef WIN32 pthread_mutex_lock(&m_mutexForConnectToServer); #else EnterCriticalSection(&m_mutexForConnectToServer); #endif if (!m_ConnectorWorkManager.AddConnectWork(szIP, usPort, NULL, 0)) { // error print } #ifndef WIN32 pthread_mutex_unlock(&m_mutexForConnectToServer); #else LeaveCriticalSection(&m_mutexForConnectToServer); #endif } } usProcessedCloseWorkCount++; if (usProcessedCloseWorkCount >= 200) { break; } } t_Connector_Work_Result cwr; memset(&cwr, 0, sizeof(cwr)); int nProcessConnecttedWorkCount = 0; while (GetOneConnectedSession(cwr)) { LSelectServerSession* pSession = AllocSession(); if (pSession == NULL) { #ifndef WIN32 close(cwr.nSocket); pthread_mutex_lock(&m_mutexForConnectToServer); #else closesocket(cwr.nSocket); EnterCriticalSection(&m_mutexForConnectToServer); #endif if (!m_ConnectorWorkManager.AddConnectWork(cwr.szIP, cwr.usPort, NULL, 0)) { // error print } #ifndef WIN32 pthread_mutex_unlock(&m_mutexForConnectToServer); #else LeaveCriticalSection(&m_mutexForConnectToServer); #endif nProcessConnecttedWorkCount++; if (nProcessConnecttedWorkCount >= 200) { break; } continue; } else { pSession->SetSocket(cwr.nSocket); if (!AddSession(pSession)) { #ifndef WIN32 close(cwr.nSocket); pthread_mutex_lock(&m_mutexForConnectToServer); #else closesocket(cwr.nSocket); EnterCriticalSection(&m_mutexForConnectToServer); #endif if (!m_ConnectorWorkManager.AddConnectWork(cwr.szIP, cwr.usPort, NULL, 0)) { // error print } #ifndef WIN32 pthread_mutex_unlock(&m_mutexForConnectToServer); #else LeaveCriticalSection(&m_mutexForConnectToServer); #endif FreeSession(pSession); } else { pSession->SetReconnect(true); AddOneRecvedPacket(pSession->GetSessionID(), (LPacketSingle*)0xFFFFFFFF); } } nProcessConnecttedWorkCount++; if (nProcessConnecttedWorkCount >= 200) { break; } } int nWorkCount = CheckForSocketEvent(); if (nWorkCount < 0) { return 0; } int nSendWorkCount = SendData(); if (nWorkCount == 0 && nSendWorkCount == 0) { // sched_yield(); #ifndef WIN32 struct timespec timeReq; timeReq.tv_sec = 0; timeReq.tv_nsec = 10; nanosleep(&timeReq, NULL); #else Sleep(0); #endif } if (CheckForStop()) { return 0; } } return 0; }