public CBReconnectReply GetReconnectData(long uid) { var player = m_players.FirstOrDefault(a => a.uid == uid); CBReconnectReply rep = new CBReconnectReply(); foreach (var p in m_players) { BattlePlayerInfo info = new BattlePlayerInfo(); info.Id = p.id; info.IsSelf = p == player; info.Level = p.user.level; info.Name = p.user.name; info.Gold = p.gold; info.Seat = p.seat; info.State = (int)p.state; foreach (var card in p.handCards) { if (p == player) { info.HandCards.Add(card.id); } else { info.HandCards.Add(0); // 其他玩家不同步卡牌,防作弊 } } rep.PlayerInfos.Add(info); } foreach (var card in m_cardMgr.allCards) { CardInfo info = new CardInfo(); info.Id = card.id; info.TableID = card.tableID; rep.Cards.Add(info); } rep.RoomInfo = new BattleRoomInfo(); rep.RoomInfo.Id = room.id; rep.RoomInfo.Name = room.name; if (m_whosTurn != null) { rep.WhoseTurn = m_whosTurn.id; } rep.RoomState = (int)state; rep.LeftCardCount = m_cardMgr.leftCards.Count; rep.LeftTurnTime = m_whosTurnCountDown; rep.LastPlayedCardId = 0; return(rep); }
void OnReconnect(string sessionID, CBReconnectRequest msg) { Logger.Log($"{sessionID} Reconnect with token: {msg.Token} "); UserData user = null; if (!m_users.TryGetValue(msg.Token, out user)) { Logger.LogError($"RECONNECT => {sessionID}'s token {msg.Token} is wrong, refuse reconnect."); return; } if (GetProxy <RoomProxy>().GetRoom(user.roomID) == null) { Logger.LogError($"RECONNECT => {sessionID}'s token {msg.Token} is wrong, refuse reconnect."); CBReconnectReply rep = new CBReconnectReply(); rep.RoomState = (int)SOS.SOS_Logic.State.Dismiss; SendMessage(sessionID, rep); return; } SOS.SOS_Logic sosLogic = GetProxy <BattleServerProxy>().GetSosLogic(user.roomID); user.SetSessionID(sessionID); if (sosLogic.state == SOS.SOS_Logic.State.Started) { user.SetState(UserState.Battle); } else { user.SetState(UserState.Login); } CBReconnectReply reply = sosLogic.GetReconnectData(user.uid); SendMessage(sessionID, reply); }