Exemplo n.º 1
0
    public bool AddPlayer(uint playerId, uint sid)
    {
        if (m_eState != FSPGameState.Create)
        {
            return(false);
        }

        FSPPlayer player = null;

        for (int i = 0; i < m_ListPlayer.Count; i++)
        {
            player = m_ListPlayer[i];
            if (player.Id == playerId)
            {
                m_ListPlayer.RemoveAt(i);
                FSPServer.Instance.DelSession(player.Sid);
                player.Dispose();
                break;
            }
        }

        if (m_ListPlayer.Count >= MaxPlayerNum)
        {
            return(false);
        }

        FSPSession session = FSPServer.Instance.AddSession(sid);

        player = new FSPPlayer(playerId, m_aFSPParam.serverTimeout, session, OnPlayerReceive);
        m_ListPlayer.Add(player);

        return(true);
    }
Exemplo n.º 2
0
 public FSPPlayer(uint playerId, int timeout, FSPSession session, Action <FSPPlayer, FSPVKey> listener)
 {
     m_id      = playerId;
     m_Timeout = timeout;
     m_Session = session;
     m_Session.SetReceiveListener(OnSessionReceive);
     m_RecvListener = listener;
     WaitForExit    = false;
     m_FrameCache   = new Queue <FSPFrame>();
 }
Exemplo n.º 3
0
    //------------------------------------------------------------

    private void OnReceive(byte[] buffer, int size, IPEndPoint remotePoint)
    {
        FSPDataC2S data = PBSerializer.NDeserialize <FSPDataC2S>(buffer);

        FSPSession session = GetSession(data.sid);

        if (session == null)
        {
            //没有这个玩家,不理它的数据
            return;
        }


        session.EndPoint = remotePoint;
        session.Receive(data);
    }
Exemplo n.º 4
0
    internal FSPSession AddSession(uint sid)
    {
        FSPSession s = GetSession(sid);

        if (s != null)
        {
            return(s);
        }

        s = new FSPSession(sid, m_aGameSocket);

        lock (m_ltSession)
        {
            m_ltSession.Add(s);
        }
        return(s);
    }
Exemplo n.º 5
0
 public void Dispose()
 {
     m_Session = null;
     m_FrameCache.Clear();
 }