//处理大厅的加入房间数据 private static void DealLobbyData2(DataCenter dataCenter, Socket socket, string[] strs) { int rNum = int.Parse(strs[2]); int index = dataCenter.LobbyPlayerList.FindIndex(i => i.Mail == strs[3]); dataCenter.LobbyPlayerList[index].RNum = rNum; dataCenter.LobbyPlayerList[index].SNum = dataCenter.RoomDataDic[rNum].PlayerDataList.Count + 1; dataCenter.RoomDataDic[rNum].PlayerDataList.Add(dataCenter.LobbyPlayerList[index]); NetCtrl.Send(socket, "2|2|1|" + rNum + "|" + dataCenter.RoomDataDic[rNum].PlayerDataList.Count + "|"); NetCtrl.Send(dataCenter.RoomDataDic[rNum].PlayerDataList[0].Socket, "2|4|2"); SendDetailLobbyData(dataCenter, rNum); SendRoughLobbyData(dataCenter); }
//魔术师与牌堆交换的牌,将牌放入到牌堆中,然后牌堆中取出相应的牌 private static void DealGameBuilding4(DataCenter dataCenter, int rNum, int sNum, string[] strs) { for (int i = 5; i < strs.Length; i++) { dataCenter.RoomDataDic[rNum].BackB.Add(dataCenter.CardRes.OrderBuildings[int.Parse(strs[i]) - 1]); dataCenter.RoomDataDic[rNum].PlayerDataList[sNum - 1].PocketB.RemoveAll(b => b.ID == int.Parse(strs[i])); } string s = "3|6|3|"; for (int i = 0; i < strs.Length - 5; i++) { dataCenter.RoomDataDic[rNum].PlayerDataList[sNum - 1].PocketB.Add(dataCenter.RoomDataDic[rNum].BackB[0]); s += (dataCenter.RoomDataDic[rNum].BackB[0].ID + "|"); dataCenter.RoomDataDic[rNum].BackB.RemoveAt(0); } NetCtrl.Send(dataCenter.RoomDataDic[rNum].PlayerDataList[sNum - 1].Socket, s); SendToRoom(dataCenter, rNum, "3|2|1|" + sNum + "|5|5|" + (strs.Length - 5) + "|"); }
//给在特定房间内的人发送详细信息 private static void SendDetailLobbyData(DataCenter dataCenter, int rNum) { string str = "2|3|2|" + rNum + "|"; foreach (var item in dataCenter.RoomDataDic[rNum].PlayerDataList) { str += item.SNum; str += "|"; str += item.Nick; str += "|"; str += item.Exp; str += "|"; } foreach (var item in dataCenter.RoomDataDic[rNum].PlayerDataList) { NetCtrl.Send(item.Socket, str); } }
//处理大厅创建房间的数据 private static void DealLobbyData1(DataCenter dataCenter, Socket socket, string[] strs) { dataCenter.RoomNum = 1; while (dataCenter.RoomDataDic.Keys.Contains(dataCenter.RoomNum)) { dataCenter.RoomNum++; } int index = dataCenter.LobbyPlayerList.FindIndex(i => i.Mail == strs[2]); RoomData rd = new RoomData(); dataCenter.LobbyPlayerList[index].IsKing = true; dataCenter.LobbyPlayerList[index].RNum = dataCenter.RoomNum; dataCenter.LobbyPlayerList[index].SNum = 1; rd.PlayerDataList.Add(dataCenter.LobbyPlayerList[index]); dataCenter.RoomDataDic.Add(dataCenter.RoomNum, rd); NetCtrl.Send(socket, "2|1|1|" + dataCenter.RoomNum + "|" + "1|"); SendDetailLobbyData(dataCenter, dataCenter.RoomNum); SendRoughLobbyData(dataCenter); }
//给在大厅中的人发送粗略信息数据 private static void SendRoughLobbyData(DataCenter dataCenter) { string str = "2|3|1|"; foreach (var item in dataCenter.RoomDataDic) { str += item.Key; str += "|"; str += item.Value.PlayerDataList.Count; str += "|"; str += item.Value.PlayerDataList[0].Nick; str += "|"; str += item.Value.Status; str += "|"; } foreach (var item in dataCenter.LobbyPlayerList) { NetCtrl.Send(item.Socket, str); } }
//处理信息请求的数据 private static void DealLobbyData3(DataCenter dataCenter, Socket socket, string[] strs) { switch (strs[2]) { //请求粗略信息 case "1": string str = "2|3|1|"; foreach (var item in dataCenter.RoomDataDic) { str += item.Key; str += "|"; str += item.Value.PlayerDataList.Count; str += "|"; str += item.Value.PlayerDataList[0].Nick; str += "|"; str += item.Value.Status; str += "|"; } NetCtrl.Send(socket, str); break; } }
public static void DealData(DataCenter dataCenter, Socket socket, string str) { string[] strs = str.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); //此处处理客户端传过来的信息 //1信息。2大厅。 switch (strs[0]) { case "1": //1连接请求。2注册信息。3登录信息。 PlayerData playerData = InfoDeal.InfoDataDeal(App.vM.SQLCtrl, socket, strs); if (playerData.Status.Contains("1|1|1|")) { break; } if (playerData.Status.Contains("1|3|1|")) { SignDeal(dataCenter, socket, playerData); } NetCtrl.Send(socket, playerData.Status); if (playerData.Status.Contains("1|3|1|")) { playerData.Status = "Online"; dataCenter.LobbyPlayerList.Add(playerData); } break; //处理大厅信息 case "2": DealLobbyData(dataCenter, socket, strs); break; case "3": //1请求数据。2聊天 DealGameData(dataCenter, socket, strs); break; //测试信息 case "9": DealTestData(dataCenter, socket, strs); break; } }