Exemple #1
0
        public NetSession FindSession(UInt64 nSessionID)
        {
            NetSession session = null;

            try
            {
                session = m_dicSession[nSessionID];
            }
            catch { }
            return(session);
        }
Exemple #2
0
        public void Destroy()
        {
            foreach (KeyValuePair <UInt64, NetSession> pair in m_dicSession)
            {
                NetSession session = pair.Value;
                session.Close();
            }

            lock (m_dicSession)
            {
                m_dicSession.Clear();
            }
        }
Exemple #3
0
        public void DeleteSession(UInt64 nSessionID)
        {
            NetSession sessionReceiver = FindSession(nSessionID);

            if (null == sessionReceiver)
            {
                return;
            }

            sessionReceiver.Close();
            lock (m_dicSession)
            {
                m_dicSession.Remove(nSessionID);
            }
        }
Exemple #4
0
        public UInt64 CreateSession(Socket socket, NetCmdQueue refCmdQueue)
        {
            UInt64 nNewSessionID = 0;

            lock (m_dicSession)
            {
                nNewSessionID = GetNewSessionID();
                NetSession newSession = new NetSession(nNewSessionID, socket, refCmdQueue);

                newSession.Start();

                m_dicSession.Add(nNewSessionID, newSession);
            }
            return(nNewSessionID);
        }
Exemple #5
0
        public bool Send(NetCommand command)
        {
            NetSession sessionReceiver = m_sessionMgr.FindSession(command.SessionID);

            if (null == sessionReceiver)
            {
                return(false);
            }

            if (sessionReceiver.Send(command.Buffer, command.BufferSize) == false)
            {
                return(false);
            }

            return(true);
        }
Exemple #6
0
        public void Update()
        {
            List <UInt64> listDestroyedSession = new List <UInt64>();

            foreach (KeyValuePair <UInt64, NetSession> pair in m_dicSession)
            {
                NetSession session = pair.Value;
                if (session.Destroyed)
                {
                    listDestroyedSession.Add(pair.Key);
                }
            }

            if (listDestroyedSession.Count > 0)
            {
                foreach (UInt64 nSessionID in listDestroyedSession)
                {
                    DeleteSession(nSessionID);
                }
            }
        }