server side session enum and count

RCF support and general discussion.
Post Reply
smutjhwxf
Posts: 3
Joined: Mon May 30, 2016 5:29 pm

server side session enum and count

Post by smutjhwxf »

I want to limit : "only one username can login the server "
so I wan't to count if a username already connected,I write this code in the server method function:

Code: Select all

		int nUserOnlineCount = 0;
		std::vector<RCF::NetworkSessionWeakPtr>  mSessionsTemp;
		mSessionsTemp.resize(0);
		session.getRcfServer().enumerateSessions(std::back_inserter(mSessionsTemp));
		for(size_t i = 0;i < mSessionsTemp.size();i++)
		{
			RCF::NetworkSessionPtr networkSessionPtr = mSessionsTemp[i].lock();
			if(networkSessionPtr)
			{
				RCF::RcfSessionPtr rcfSessionPtr = networkSessionPtr->getSessionPtr();
				if(rcfSessionPtr)
				{
					CServerSession * pSessionObject =  rcfSessionPtr->querySessionObject<CServerSession>();
					if(pSessionObject && pSessionObject->HasLogined())
					{
						if(pSessionObject->GetUserName() == strUser)
							nUserOnlineCount++;
					}
				}
			}
		}
but this code is mistake.because sometimes the client's connection has disconnected.but the server session and the session object don't not destroyed.so i can't get the "UserOnlineCount".
can anyone hele me.thanks.
Last edited by smutjhwxf on Wed Feb 15, 2017 5:53 am, edited 1 time in total.

smutjhwxf
Posts: 3
Joined: Mon May 30, 2016 5:29 pm

Re: server side session enum and count

Post by smutjhwxf »

can you help me? thanks

Post Reply