private static void PLAYER_LEAVE(byte[] bytes) { PlayerLeave input = PlayerLeave.Parser.ParseFrom(bytes); PlayerInfo pi = ServerLobbyManager.Instance.GetPlayer(_args); if (pi == null) { string msg = $"Do not find myself!"; // 没有找到自己! ServerLobbyManager.Instance.Log("LobbyMsgReply PLAYER_LEAVE Error - " + msg); return; } if (input.TokenId != pi.Enter.TokenId) { string msg = $"It's not me that leaves, it must be yourself!"; // 离开的不是自己, 必须是自己! ServerLobbyManager.Instance.Log("LobbyMsgReply PLAYER_LEAVE Error - " + msg); return; } ServerLobbyManager.Instance.RemovePlayer(_args); PlayerLeaveReply output = new PlayerLeaveReply() { TokenId = pi.Enter.TokenId, IsKicked = false, Ret = true, }; ServerLobbyManager.Instance.SendMsg(_args, LOBBY_REPLY.PlayerLeaveReply, output.ToByteArray()); ServerLobbyManager.Instance.Log($"MSG: User leaves the lobby! Account:<{pi.Enter.Account}> - TokenId:<{pi.Enter.TokenId}>"); // 用户离开大厅! }
static void PLAYER_LEAVE_REPLY(byte[] bytes) { PlayerLeaveReply input = PlayerLeaveReply.Parser.ParseFrom(bytes); if (input.TokenId != ClientManager.Instance.Player.TokenId) { string msg = "不是自己!"; ClientManager.Instance.LobbyManager.Log("MSG: LOBBY PLAYER_LEAVE_REPLY Error - " + msg); return; } if (input.IsKicked) { string msg = $"本用户在其他地方登录, 请确认是您的账号安全."; UIManager.Instance.MessageBox("警告", msg, (int)PanelMessageBox.BUTTON.OK, OnClickPlayerLeave); ClientManager.Instance.LobbyManager.Log("MSG: LOBBY PLAYER_LEAVE_REPLY OK - " + msg); } }
static void PLAYER_ENTER(byte[] bytes) { PlayerEnter input = PlayerEnter.Parser.ParseFrom(bytes); bool ret = false; // 写入redis string tableName = $"ACCOUNT:{input.TokenId.ToString()}"; if (!ServerLobbyManager.Instance.Redis.CSRedis.Exists(tableName)) { ret = ServerLobbyManager.Instance.Redis.CSRedis.HSet(tableName, "Account", input.Account); if (ret) { ret = ServerLobbyManager.Instance.Redis.CSRedis.HSet(tableName, "TokenId", input.TokenId); ServerLobbyManager.Instance.Log($"MSG:Create new user successful! Account:<{input.Account}> - TokenId:<{input.TokenId}>"); // 创建新用户成功! } else { ServerLobbyManager.Instance.Log($"MSG:New user create failed! Account:<{input.Account}> - TokenId:<{input.TokenId}>"); // 新用户创建失败! } } else { ret = true; } if (ret) { //检测是否重复登录,如果发现曾经有人登录,则将前面的人踢掉 var alreadyLoggedIn = ServerLobbyManager.Instance.FindDuplicatedPlayer(input.TokenId); if (alreadyLoggedIn != null) { PlayerInfo oldPlayer = ServerLobbyManager.Instance.GetPlayer(alreadyLoggedIn); if (oldPlayer != null) { ServerLobbyManager.Instance.RemovePlayer(alreadyLoggedIn); PlayerLeaveReply output2 = new PlayerLeaveReply() { TokenId = oldPlayer.Enter.TokenId, IsKicked = true, Ret = true, }; ServerLobbyManager.Instance.SendMsg(alreadyLoggedIn, LOBBY_REPLY.PlayerLeaveReply, output2.ToByteArray()); string msg = "Kicked out the same user that logged in previously."; // 踢掉之前登录的本用户. ServerLobbyManager.Instance.Log($"MSG: PLAYER_ENTER WARNING - " + msg + $" - {oldPlayer.Enter.Account}"); } } PlayerInfo pi = new PlayerInfo() { Enter = input, IsOnLine = true, IsInRoom = false, HasRoom = false, }; ServerLobbyManager.Instance.AddPlayer(_args, pi); } { PlayerEnterReply output = new PlayerEnterReply() { Ret = true, }; // 返回登录成功消息 ServerLobbyManager.Instance.SendMsg(_args, LOBBY_REPLY.PlayerEnterReply, output.ToByteArray()); ServerLobbyManager.Instance.Log($"MSG: PLAYER_ENTER OK - Old user logged in successful! Account:<{input.Account}> - TokenId:<{input.TokenId}>"); // 老用户登录成功! } }