server side session enum and count
Posted: Mon Feb 06, 2017 2:33 am
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:
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.
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++;
}
}
}
}
can anyone hele me.thanks.