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); }
public void Dispose() { m_Session = null; m_ReceiveListener = null; m_FrameCache.Clear(); }
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 + "]"; }
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); }
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; }