コード例 #1
0
        public FSPPlayer AddPlayer(uint playerId, FSPSession session)
        {
            if (state != FSPGameState.Create)
            {
                Debuger.LogError("当前状态下无法AddPlayer! State = {0}", state);
                return(null);
            }

            FSPPlayer player = null;

            for (int i = 0; i < listPlayer.Count; i++)
            {
                player = listPlayer[i];
                if (player.ID == playerId)
                {
                    Debuger.LogWarning("PlayerId已经存在!用新的替代旧的! PlayerId = " + playerId);
                    listPlayer.RemoveAt(i);
                    player.Release();
                    break;
                }
            }

            if (listPlayer.Count >= MaxPlayerNum)
            {
                Debuger.LogError("已经达到最大玩家数了! MaxPlayerNum = {0}", MaxPlayerNum);
                return(null);
            }

            player = new FSPPlayer();
            player.Create(playerId, authID, session, OnRecvFromPlayer);
            listPlayer.Add(player);

            return(player);
        }
コード例 #2
0
        public FSPSession CreateSession()
        {
            Debuger.Log();
            uint       sid     = FSPSessionIDGenerator.GetNextSessionID();
            FSPSession session = new FSPSession(sid, HandleSessionSend);

            mapSession.Add(sid, session);
            return(session);
        }
コード例 #3
0
 public void Release()
 {
     if (session != null)
     {
         session.SetReceiveListener(null);
         session.Active(false);
         session = null;
     }
 }
コード例 #4
0
 public void Create(uint id, int authId, FSPSession session, Action <FSPPlayer, FSPMessage> listener)
 {
     this.id      = id;
     this.authID  = authId;
     recvListener = listener;
     this.session = session;
     this.session.SetReceiveListener(OnRecvFromSession);
     frameCache = new Queue <FSPFrameData>();
 }
コード例 #5
0
        public FSPSession GetSession(uint sid)
        {
            FSPSession session = null;

            lock (mapSession)
            {
                if (mapSession.ContainsKey(sid))
                {
                    session = mapSession[sid];
                }
            }
            return(session);
        }
コード例 #6
0
        private void DoReceiveInThread()
        {
            EndPoint remotePoint = IPUtility.GetIPEndPointAny(AddressFamily.InterNetwork, 0);
            int      cnt         = systemSocket.ReceiveFrom(recvBufferTemp, recvBufferTemp.Length, SocketFlags.None, ref remotePoint);

            if (cnt > 0)
            {
                recvBufferTempReader.Attach(recvBufferTemp, cnt);
                byte[] m_32b = new byte[4];
                recvBufferTempReader.ReadBytes(m_32b, 0, 4);
                uint sid = BitConverter.ToUInt32(m_32b, 0);

                lock (mapSession)
                {
                    FSPSession session = null;
                    if (sid == 0)
                    {
                        Debuger.LogError("基于KCP的Sid为0,该包需要被丢掉");
                    }
                    else
                    {
                        if (mapSession.ContainsKey(sid))
                        {
                            session = mapSession[sid];
                        }
                    }

                    if (session != null)
                    {
                        session.Active(remotePoint as IPEndPoint);
                        session.DoReceiveInGateway(recvBufferTemp, cnt);
                    }
                    else
                    {
                        Debuger.LogWarning("无效的包! sid:{0}", sid);
                    }
                }
            }
        }