示例#1
0
        public bool AddPlayer(uint playerId, uint sid)
        {
            Debuger.Log(LOG_TAG, "AddPlayer() playerId: {0}, sid: {1}", playerId, sid);

            if (m_State != FSPGameState.Create)
            {
                Debuger.LogError(LOG_TAG, "AddPlayer() 当前状态下无法AddPlayer! State = {0}", m_State);
                return(false);
            }

            // 移除老的
            RemovePlayer(playerId);

            if (m_ListPlayer.Count >= MaxPlayerNum)
            {
                Debuger.LogError(LOG_TAG, "AddPlayer() 玩家数达到上限 {0}", MaxPlayerNum);
                return(false);
            }

            FSPSession session = FSPServer.Instance.AddSession(sid);
            FSPPlayer  player  = new FSPPlayer(playerId, session, m_FSPParam.serverTimeout, OnPlayerReceive);

            m_ListPlayer.Add(player);

            return(true);
        }
示例#2
0
        public void Dispose()
        {
            m_Session         = null;
            m_ReceiveListener = null;

            m_FrameCache.Clear();
        }
示例#3
0
        public bool WaitForExit = false;  //标记


        public FSPPlayer(uint playerId, FSPSession session, int timeOut, Action <FSPPlayer, FSPVKey> listener)
        {
            _id       = playerId;
            m_Session = session;
            m_Session.SetReceiveListener(OnReceive);
            m_Timeout = timeOut;

            m_ReceiveListener = listener;
            WaitForExit       = false;

            LOG_TAG = LOG_TAG + "[" + playerId + "]";
        }
示例#4
0
        void OnReceive(byte[] buffer, int size, IPEndPoint remotePoint)
        {
            FSPData_CS data = PBSerializer.Deserialize<FSPData_CS>(buffer);

            FSPSession session = GetSession(data.sid);
            if (session == null)
            {
                Debuger.LogWarning(LOG_TAG_RECV, "DoReceive() 收到一个未知的SID = " + data.sid);
                return;
            }

            session.EndPoint = remotePoint;
            session.Receive(data);
        }
示例#5
0
        internal FSPSession AddSession(uint sid)
        {
            FSPSession session = GetSession(sid);
            if (session == null)
            {
                session = new FSPSession(sid, m_GameSocket);

                lock (m_ListSession)
                {
                    m_ListSession.Add(session);
                }
                Debuger.Log(LOG_TAG_MAIN, "AddSession() SID = " + sid);
            }
            return session;
        }