public bool Deserialize(ref UDPConnectionData element) { if (GetDataSize() == 0) { // 데이터가 설정되지 않았다. return(false); } bool ret = true; byte playerNum = 0; string total; ret &= Deserialize(ref playerNum); ret &= Deserialize(out total, (int)GetDataSize()); string[] str = total.Split(','); if (str.Length < playerNum) { return(false); } element.playerNum = playerNum; element.endPoint = new string[element.playerNum]; for (int i = 0; i < playerNum; i++) { element.endPoint[i] = str[i]; } return(ret); }
//UDP 연결 public void RequestUDPConnection(DataPacket packet) { Console.WriteLine(packet.client.RemoteEndPoint.ToString() + "UDP 연결 요청"); string id = loginUser[packet.client]; int roomNum = userState[id].state; string[] ip = new string[roomManager.Room[roomNum].PlayerNum]; int ipIndex = 0; for (int i = 0; i < RoomManager.maxPlayerNum; i++) { if (roomManager.Room[roomNum].Socket[i] != null) { ip[ipIndex] = roomManager.Room[roomNum].Socket[i].RemoteEndPoint.ToString(); ipIndex++; } } UDPConnectionData udpConnctionData = new UDPConnectionData(ip); UDPConnectionPacket udpConnctionDataPacket = new UDPConnectionPacket(udpConnctionData); udpConnctionDataPacket.SetPacketId((int)ServerPacketId.UdpConnection); byte[] msg = CreatePacket(udpConnctionDataPacket); packet = new DataPacket(msg, packet.client); Console.WriteLine("UDP연결 정보 송신"); lock (sendLock) { sendMsgs.Enqueue(packet); } }
public bool Serialize(UDPConnectionData data) { bool ret = true; ret &= Serialize(data.playerNum); for (int i = 0; i < data.playerNum; i++) { ret &= Serialize(data.endPoint[i]); ret &= Serialize(','); } return(ret); }
//Server - 연결 시작 public void UdpConnection(DataPacket packet) { Debug.Log("연결 시작"); UDPConnectionPacket udpConnectionPacket = new UDPConnectionPacket(packet.msg); UDPConnectionData udpConnectionData = udpConnectionPacket.GetData(); DataSender.Instance.udpId = new int[udpConnectionData.playerNum]; for (int userIndex = 0; userIndex < udpConnectionData.playerNum; userIndex++) { string endPoint = udpConnectionData.endPoint[userIndex]; if (endPoint == NetworkManager.Instance.ServerSock.LocalEndPoint.ToString()) { NetworkManager.Instance.SetMyIndex(userIndex); } } StartCoroutine(SceneChanger.Instance.CheckLoading(udpConnectionData.playerNum + 3)); NetworkManager.Instance.InitializeUdpConnection(); NetworkManager.Instance.ReSendManager.Initialize(udpConnectionData.playerNum); DataSender.Instance.InitializeUdpSend(NetworkManager.Instance.ClientSock); for (int userIndex = 0; userIndex < udpConnectionData.playerNum; userIndex++) { string endPoint = udpConnectionData.endPoint[userIndex]; string ip = endPoint.Substring(0, endPoint.IndexOf(":")); IPEndPoint newEndPoint = new IPEndPoint(IPAddress.Parse(ip), NetworkManager.clientPortNumber + userIndex); NetworkManager.Instance.UserIndex.Add(new UserIndex(newEndPoint, userIndex)); if (endPoint != NetworkManager.Instance.ServerSock.LocalEndPoint.ToString()) { Debug.Log("연결 아이피 : " + newEndPoint.ToString()); NetworkManager.Instance.ConnectP2P(newEndPoint); } } DungeonManager.Instance.InitializePlayer(udpConnectionData.playerNum); DataSender.Instance.RequestMonsterSpawnList(DungeonManager.Instance.DungeonId, DungeonManager.Instance.DungeonLevel); DataSender.Instance.RequestMonsterStatusData(DungeonManager.Instance.DungeonId, DungeonManager.Instance.DungeonLevel); }
//Server - 연결 시작 public void UdpConnection(DataPacket packet) { Debug.Log("연결 시작"); UDPConnectionPacket udpConnectionPacket = new UDPConnectionPacket(packet.msg); UDPConnectionData udpConnectionData = udpConnectionPacket.GetData(); DataSender.Instance.udpId = new int[udpConnectionData.playerNum]; for (int userIndex = 0; userIndex < udpConnectionData.playerNum; userIndex++) { string endPoint = udpConnectionData.endPoint[userIndex]; if (endPoint == networkManager.ServerSock.LocalEndPoint.ToString()) { networkManager.SetMyIndex(userIndex); } } networkManager.InitializeUdpConnection(); networkManager.ReSendManager.Initialize(udpConnectionData.playerNum); DataSender.Instance.InitializeUdpSend(networkManager.ClientSock); for (int userIndex = 0; userIndex < udpConnectionData.playerNum; userIndex++) { string endPoint = udpConnectionData.endPoint[userIndex]; string ip = endPoint.Substring(0, endPoint.IndexOf(":")); IPEndPoint newEndPoint = new IPEndPoint(IPAddress.Parse(ip), NetworkManager.clientPortNumber + userIndex); networkManager.UserIndex.Add(new UserIndex(newEndPoint, userIndex)); if (endPoint != networkManager.ServerSock.LocalEndPoint.ToString()) { Debug.Log("연결 아이피 : " + newEndPoint.ToString()); networkManager.ConnectP2P(newEndPoint); } } if (SceneChanger.Instance.CurrentScene == SceneChanger.SceneName.LoadingScene) { SceneChanger.Instance.LoadingCheck[2] = true; } }