コード例 #1
0
        public NetSession CreateSession()
        {
            UInt64     nNewSessionID = GetNewSessionID();
            NetSession newSession    = new NetSession(nNewSessionID, m_refCommandQueue);

            m_dicSession.Add(nNewSessionID, newSession);
            return(newSession);
        }
コード例 #2
0
        public NetSession FindSession(UInt64 nSessionID)
        {
            NetSession session = null;

            try
            {
                session = m_dicSession[nSessionID];
            }
            catch {}
            return(session);
        }
コード例 #3
0
        public void DeleteSession(UInt64 nSessionID)
        {
            try
            {
                NetSession session = m_dicSession[nSessionID];
                m_dicSession.Remove(nSessionID);

                session.Close();
            }
            catch {}
        }
コード例 #4
0
        public void Destroy()
        {
            List <UInt64> listDestroyedSession = new List <UInt64>();

            foreach (KeyValuePair <UInt64, NetSession> pair in m_dicSession)
            {
                NetSession session = pair.Value;
                session.Close();
            }

            m_dicSession.Clear();
        }
コード例 #5
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)
                {
                    session.Close();
                    listDestroyedSession.Add(pair.Key);
                }
            }

            foreach (UInt64 Key in listDestroyedSession)
            {
                m_dicSession.Remove(Key);
            }
        }
コード例 #6
0
        public virtual bool NewClientSession(string strServerName, string strIP, int nPort, out UInt64 nSessionID)
        {
            nSessionID = 0;

            if (strServerName.Length == 0 && strIP.Length == 0)
            {
                return(false);
            }

            if (strServerName.Length != 0 && strIP.Length == 0)
            {
                IPHostEntry host;
                try
                {
                    host = Dns.GetHostEntry(strServerName);
                    if (host.AddressList.Length == 0)
                    {
                        return(false);
                    }
                }
                catch (System.Exception e)
                {
                    FileLog.Instance.Write("Error! HostName={0}, Msg={1}", strServerName, e.Message);
                    return(false);
                }

                IPAddress addr = host.AddressList[0];
                strIP = addr.ToString();
            }

            NetSession newSession = m_sessionMgr.CreateSession();

            if (newSession.RequestConnect(strIP, nPort) == false)
            {
                m_sessionMgr.DeleteSession(newSession.SessionID);
                return(false);
            }
            nSessionID = newSession.SessionID;
            return(true);
        }
コード例 #7
0
        public bool Post(NetCommand command)
        {
            if (command.SessionID == 0)
            {
                m_commandQueue.PushCommand(command);
            }
            else
            {
                NetSession session = m_sessionMgr.FindSession(command.SessionID);
                if (session == null)
                {
                    return(false);
                }

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

            return(true);
        }