Logo Search packages:      
Sourcecode: verlihub version File versions

bool nDirectConnect::cServerDC::VerifyUniqueNick ( cConnDC conn  )  [protected]

check if user is logged in with same nick, eventually decide if old conn should be closed, return tru if conn can login

return true if user is free to login

add user to the list or fail

Definition at line 611 of file cserverdc.cpp.

References nServer::cAsyncConn::AddrIP(), nDirectConnect::cConnDC::CloseNow(), DCPublicHS(), cObj::ErrLog(), cObj::Log(), cObj::LogStream(), nDirectConnect::cUserBase::mClass, nDirectConnect::cUserBase::mMyINFO_basic, nDirectConnect::cUserBase::mNick, nDirectConnect::cConnDC::mpUser, nDirectConnect::cUser::mShare, nDirectConnect::cUser::mxConn, RemoveNick(), and nDirectConnect::cConnDC::Send().

Referenced by BeginUserLogin(), and DoUserLogin().

{
      string UsrKey, omsg;
      mUserList.Nick2Key(conn->mpUser->mNick,UsrKey);
      /// add user to the list or fail
      if( mUserList.ContainsKey(UsrKey) )
      {
            bool CloseOld = false;
            cUser *old_usr = mUserList.GetUserByKey(UsrKey);

            if(conn->mpUser->mClass >= eUC_REGUSER) CloseOld = true;
            if (    !CloseOld &&
                  old_usr->mxConn &&
                  (conn->AddrIP() == old_usr->mxConn->AddrIP()) &&
                  (conn->mpUser->mShare == old_usr->mShare) &&
                  (conn->mpUser->mMyINFO_basic == old_usr->mMyINFO_basic)
            ) CloseOld = true;

            if (CloseOld)
            {
                  if(old_usr)
                  {
                        if(old_usr->mxConn)
                        {
                              if(old_usr->mxConn->Log(2)) old_usr->mxConn->LogStream() << "Closing, because of a new connection" << endl;
                              omsg = "Another instance of yourself is connecting. Bye and Hi.";
                              old_usr->mxConn->Send(omsg,true);
                              old_usr->mxConn->CloseNow();
                        } else {
                              if(ErrLog(1)) LogStream() << "Closing, user " << old_usr->mNick << " , but there's no connection :(" << endl;
                        }
                        RemoveNick(old_usr);
                  }
                  else
                  {
                        if(ErrLog(0)) LogStream() << "Classical example of what never happens " << old_usr->mNick << "'" << endl;
                        conn->CloseNow();
                        return false;
                  }
            }
            else
            {
                  omsg = "You are already in the hub.";
                  DCPublicHS(omsg, conn);
                  conn->CloseNow();
                  return false;
            }
      }
      return true;      
}


Generated by  Doxygen 1.6.0   Back to index