private void RoomSwitch(Client client, MyData data) { switch (data.Protocol) { case protocol.CreateRoom: CreateRoom(client, JsonUntity.Json2Object <GameSetting>(data.Body[0])); break; case protocol.JoinRoom: int room_id = -1; string pass = string.Empty; if (data.Body.Count > 0) { room_id = int.Parse(data.Body[0]); pass = data.Body[1].ToString(); } else { room_id = client.GameRoom; } Room room = RId2Room.ContainsKey(room_id) ? RId2Room[room_id] : null; bool result = false; if (room != null) { //if (JoinRoom != null) //{ // Delegate[] delArray = JoinRoom.GetInvocationList(); // foreach (Delegate del in delArray) // { // Room target = (Room)del.Target; // if (target != null && target.RoomId == room_id) // { // JoinRoomDelegate method = (JoinRoomDelegate)del; // result = method(client, room_id, pass); // } // } //} //JoinRoom?.Invoke(client, room_id, pass); result = room.OnClientRequestInter(client, room_id, pass); } if (!result) { Debug(string.Format("{0} join request fail at hall", client.UserName)); data = new MyData { Description = PacketDescription.Hall2Cient, Protocol = protocol.JoinRoom, }; client.SendSwitchReply(data); } else { ClientList.Instance().AddClient(client.UserID, client.Profile.NickName, room_id); UpdateUsers(ClientList.Instance().GetUserList(0)); } break; case protocol.LeaveRoom: if (RId2Room.ContainsKey(client.GameRoom)) { client.RequestLeaveRoom(); //更新form ClientList.Instance().AddClient(client.UserID, client.Profile.NickName); UpdateUsers(ClientList.Instance().GetUserList(0)); } break; case protocol.UpdateRoom: client.RequstReady(bool.Parse(data.Body[0])); break; case protocol.RoleReserved: if (client.UserRight >= 2 && RId2Room.ContainsKey(client.GameRoom)) { room = RId2Room[client.GameRoom]; if (!room.GameStarted && room.Setting.GameMode == "Classic") { client.RoleReserved = data.Body[0]; } } break; case protocol.KickOff: room = RId2Room.ContainsKey(client.GameRoom) ? RId2Room[client.GameRoom] : null; if (room != null && room.Host == client && !room.GameStarted) { int victim_id = int.Parse(data.Body[0]); Client victim = GetClient(victim_id); if (victim != null || victim_id < 0) { victim.RequestLeaveRoom(true); //更新form ClientList.Instance().AddClient(client.UserID, client.Profile.NickName); UpdateUsers(ClientList.Instance().GetUserList(0)); } } break; case protocol.ConfigChange: room = RId2Room.ContainsKey(client.GameRoom) ? RId2Room[client.GameRoom] : null; if (room != null && room.Host == client && !room.GameStarted) { room.ChangeSetting(JsonUntity.Json2Object <GameSetting>(data.Body[0])); } break; default: break; } }
private void RoomSwitch(Client client, MyData data) { try { Room room = null; switch (data.Protocol) { case Protocol.CreateRoom: CreateRoom(client, JsonUntity.Json2Object <GameSetting>(data.Body[0])); break; case Protocol.JoinRoom: int room_id = -1; string pass = string.Empty; if (data.Body.Count > 0) { room_id = int.Parse(data.Body[0]); pass = data.Body[1].ToString(); } else { room_id = client.GameRoom; } bool result = false; if (RId2Room.TryGetValue(room_id, out room)) { //if (JoinRoom != null) //{ // Delegate[] delArray = JoinRoom.GetInvocationList(); // foreach (Delegate del in delArray) // { // Room target = (Room)del.Target; // if (target != null && target.RoomId == room_id) // { // JoinRoomDelegate method = (JoinRoomDelegate)del; // result = method(client, room_id, pass); // } // } //} //JoinRoom?.Invoke(client, room_id, pass); result = room.OnClientRequestInter(client, room_id, pass); } if (!result) { Debug(string.Format("{0} join request fail at hall", client.UserName)); data = new MyData { Description = PacketDescription.Hall2Cient, Protocol = Protocol.JoinRoom, }; client.SendSwitchReply(data); } break; case Protocol.LeaveRoom: if (RId2Room.TryGetValue(client.GameRoom, out room)) { client.RequestLeaveRoom(); } break; case Protocol.UpdateRoom: client.RequstReady(bool.Parse(data.Body[0])); break; case Protocol.RoleReserved: if (client.UserRight >= 2 && RId2Room.TryGetValue(client.GameRoom, out room)) { if (!room.GameStarted && room.Setting.GameMode == "Classic") { client.RoleReserved = data.Body[0]; } } break; case Protocol.GeneralReserved: if (client.UserRight >= 2 && RId2Room.TryGetValue(client.GameRoom, out room) && !room.GameStarted && (room.Setting.GameMode == "Classic" || room.Setting.GameMode == "Hegemony") && data.Body.Count <= 2) { client.GeneralReserved = data.Body; } break; case Protocol.KickOff: if (RId2Room.TryGetValue(client.GameRoom, out room) && room != null && room.Host == client && !room.GameStarted) { int victim_id = int.Parse(data.Body[0]); if (!UId2ClientTable.TryGetValue(victim_id, out Client victim) || victim != null || victim_id < 0) { victim.RequestLeaveRoom(true); } } break; case Protocol.ConfigChange: if (RId2Room.TryGetValue(client.GameRoom, out room) && room != null && room.Host == client && !room.GameStarted) { GameSetting setting = JsonUntity.Json2Object <GameSetting>(data.Body[0]); GameMode mode = Engine.GetMode(room.Setting.GameMode); if (room.Setting.GameMode == setting.GameMode && room.Setting.PlayerNum == setting.PlayerNum && setting.GeneralPackage.Count > 0 && setting.CardPackage.Count > 0) { foreach (string general in setting.GeneralPackage) { if (!mode.GeneralPackage.Contains(general)) { return; } } foreach (string card in setting.CardPackage) { if (!mode.CardPackage.Contains(card)) { return; } } room.ChangeSetting(setting); } } break; default: break; } } catch (Exception e) { LogHelper.WriteLog(null, e); Debug(string.Format("error on switch room {0} {1}", e.Message, e.TargetSite)); } }