예제 #1
0
 public void AddSession(int sessionId, Session session)
 {
     lock (m_Sessions)
     {
         if (!m_Sessions.ContainsKey(sessionId)) m_Sessions.Add(sessionId, session);
         else m_Sessions[sessionId] = session;
     }
 }
예제 #2
0
 public void OnError(Session session, Int32 errortype, String errormsg)
 {
     LogMsg("Client Error (" + session.GetId() + ") : " + errormsg);
 }
예제 #3
0
        public void OnDisconnect(Session session)
        {
            LogMsg("Client Disconnected, ID: " + session.GetId());
            Invoke((Action)(() =>
            {
                if (m_UserName.Length > 0 && m_UserToken.Length > 0)
                {
                    ShowText("ERROR: " + "Lost connection to chat server.");
                }
                gbLobby.Enabled = false;
                gbChatRoom.Enabled = false;

                gbLogin.Enabled = false;

                if (m_UserName.Length > 0 && m_UserToken.Length > 0)
                {
                    ShowText("Trying to re-login, please wait...");
                    timerAutoRelogin.Enabled = true;
                    timerAutoRelogin.Start();
                }
                else gbLogin.Enabled = true;

            }));
        }
예제 #4
0
        public void OnConnect(Session session)
        {
            LogMsg("Client Connected, ID: " + session.GetId());

            if (m_UserName.Length > 0 && m_UserToken.Length > 0)
            {
                EnterLobbyRequest request = new EnterLobbyRequest();
                request.UserName = m_UserName;
                request.UserToken = m_UserToken;

                m_Client.SendString("lobby/enter/" + WebMessage.ToJsonString<EnterLobbyRequest>(request));
            }
        }
예제 #5
0
        public void AcceptCallback(IAsyncResult ar)
        {
            // Signal the main thread to continue.

            Socket socket = null;

            lock (m_ListenWatcher)
            {
                try
                {
                    // Get the socket that handles the client request.
                    Socket listener = (Socket)ar.AsyncState;
                    if (listener != null) socket = listener.EndAccept(ar);
                }
                catch { }
            }

            // after unlock the watcher, re-activate it ...
            m_ListenWatcher.Set();

            if (socket == null) return;

            if (!m_Acceptable || m_State <= 0)
            {
                try { socket.Close(); }
                catch { }
                return;
            }

            if (m_MaxClientCount > 0 && m_SessionGroup.GetSessionCount() >= m_MaxClientCount)
            {
                try { socket.Close(); }
                catch { }
                return;
            }

            // set every new session's io buffer size to a global value by default
            // but you still can change it in every session's OnConnect event function
            socket.ReceiveBufferSize = m_IoBufferSize;
            socket.SendBufferSize = m_IoBufferSize;

            // Create the session object.

            Session session = null;

            lock (m_SessionGroup)
            {
                m_NextSessionID++;
                session = new Session(m_NextSessionID, socket, m_IoHandler, m_IoFilter, m_Cert != null);
                session.SetSessionGroup(m_SessionGroup);
            }

            if (session != null)
            {
                Stream stream = session.GetStream();
                if (stream != null)
                {
                    if (stream is SslStream && m_Cert != null)
                    {
                        (stream as SslStream).BeginAuthenticateAsServer(m_Cert,
                                new AsyncCallback(AuthenticateCallback), session);
                    }
                    else if (stream is NetworkStream)
                    {
                        if (session != null) session.Open();
                    }
                }
            }
        }
예제 #6
0
 public SessionContext(Session session, Object data)
 {
     Session = session;
     Data = data;
 }
예제 #7
0
 public virtual void OnError(Session session, Int32 errortype, String errormsg)
 {
     try
     {
         if (m_Events != null) m_Events.FireErrorEvent(session, errortype, errormsg);
     }
     finally
     {
         if (session != null) session.Close();
     }
 }
예제 #8
0
 public virtual void OnDisconnect(Session session)
 {
     if (m_Events != null) m_Events.FireDisconnectEvent(session);
 }
예제 #9
0
 public int FireSendEvent(Session session, Object data)
 {
     if (OnSend != null) return OnSend(session, data);
     else return 0;
 }
예제 #10
0
 public int FireReceiveEvent(Session session, Object data)
 {
     if (OnReceive != null) return OnReceive(session, data);
     else return 0;
 }
예제 #11
0
 public void FireIdleEvent(Session session, Int32 optype)
 {
     if (OnIdle != null) OnIdle(session, optype);
 }
예제 #12
0
 public void FireErrorEvent(Session session, Int32 errortype, String errormsg)
 {
     if (OnError != null) OnError(session, errortype, errormsg);
 }
예제 #13
0
 public void FireDisconnectEvent(Session session)
 {
     if (OnDisconnect != null) OnDisconnect(session);
 }
예제 #14
0
 public virtual int OnSend(Session session, Object data)
 {
     if (m_Events != null) return m_Events.FireSendEvent(session, data);
     else return 0;
 }
예제 #15
0
 public virtual int OnReceive(Session session, Object data)
 {
     if (m_Events != null) return m_Events.FireReceiveEvent(session, data);
     else return 0;
 }
예제 #16
0
 public virtual void OnIdle(Session session, Int32 optype)
 {
     if (m_Events != null) m_Events.FireIdleEvent(session, optype);
 }