From bd73824cb4b83650efca0d0e64be51556e75f0f0 Mon Sep 17 00:00:00 2001 From: Mootfrost777 Date: Fri, 23 Aug 2024 22:45:53 +0300 Subject: [PATCH] Fix GetIp --- ZoFo/Content/Content.mgcb | 263 +++++++----------- ZoFo/GameCore/GUI/DebugHUD.cs | 2 +- ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs | 2 +- .../NetworkManager/ClientNetworkManager.cs | 26 +- .../NetworkManager/ServerNetworkManager.cs | 27 +- ZoFo/ZoFo.csproj | 1 + 6 files changed, 136 insertions(+), 185 deletions(-) diff --git a/ZoFo/Content/Content.mgcb b/ZoFo/Content/Content.mgcb index 2eea727..d45f592 100644 --- a/ZoFo/Content/Content.mgcb +++ b/ZoFo/Content/Content.mgcb @@ -44,6 +44,9 @@ #begin MapData/TileMaps/main.tmj /copy:MapData/TileMaps/main.tmj +#begin MapData/TileSets/bonfire.tsj +/copy:MapData/TileSets/bonfire.tsj + #begin MapData/TileSets/IconSet.tsj /copy:MapData/TileSets/IconSet.tsj @@ -92,30 +95,12 @@ /processorParam:Quality=Best /build:sounds/Loot.wav -#begin sounds/Loot.wav -/importer:WavImporter -/processor:SoundEffectProcessor -/processorParam:Quality=Best -/build:sounds/Loot.wav - #begin sounds/Odevanie odezdi.wav /importer:WavImporter /processor:SoundEffectProcessor /processorParam:Quality=Best /build:sounds/Odevanie odezdi.wav -#begin sounds/Odevanie odezdi.wav -/importer:WavImporter -/processor:SoundEffectProcessor -/processorParam:Quality=Best -/build:sounds/Odevanie odezdi.wav - -#begin sounds/Pieot wodichky.wav -/importer:WavImporter -/processor:SoundEffectProcessor -/processorParam:Quality=Best -/build:sounds/Pieot wodichky.wav - #begin sounds/Pieot wodichky.wav /importer:WavImporter /processor:SoundEffectProcessor @@ -128,18 +113,6 @@ /processorParam:Quality=Best /build:sounds/Sshetchik geigera.wav -#begin sounds/Sshetchik geigera.wav -/importer:WavImporter -/processor:SoundEffectProcessor -/processorParam:Quality=Best -/build:sounds/Sshetchik geigera.wav - -#begin sounds/Tabletki 2.wav -/importer:WavImporter -/processor:SoundEffectProcessor -/processorParam:Quality=Best -/build:sounds/Tabletki 2.wav - #begin sounds/Tabletki 2.wav /importer:WavImporter /processor:SoundEffectProcessor @@ -152,18 +125,6 @@ /processorParam:Quality=Best /build:sounds/Zombi napal.wav -#begin sounds/Zombi napal.wav -/importer:WavImporter -/processor:SoundEffectProcessor -/processorParam:Quality=Best -/build:sounds/Zombi napal.wav - -#begin sounds/Zombi stoit.wav -/importer:WavImporter -/processor:SoundEffectProcessor -/processorParam:Quality=Best -/build:sounds/Zombi stoit.wav - #begin sounds/Zombi stoit.wav /importer:WavImporter /processor:SoundEffectProcessor @@ -182,14 +143,8 @@ /processorParam:Quality=Best /build:sounds/zombie sound.wav -#begin Textures/Animations/player_down_idle.animation -/copy:Textures/Animations/player_down_idle.animation - -#begin Textures/Animations/player_down-left_idle.animation -/copy:Textures/Animations/player_down-left_idle.animation - -#begin Textures/Animations/player_down-right_idle.animation -/copy:Textures/Animations/player_down-right_idle.animation +#begin Textures/Animations/explosion_1.animation +/copy:Textures/Animations/explosion_1.animation #begin Textures/Animations/player_idle_down_mining.animation /copy:Textures/Animations/player_idle_down_mining.animation @@ -215,77 +170,65 @@ #begin Textures/Animations/player_idle_top-rights_mining.animation /copy:Textures/Animations/player_idle_top-rights_mining.animation -#begin Textures/Animations/player_left_idle.animation -/copy:Textures/Animations/player_left_idle.animation +#begin Textures/Animations/player_look_down_weapon.animation +/copy:Textures/Animations/player_look_down_weapon.animation #begin Textures/Animations/player_look_down.animation /copy:Textures/Animations/player_look_down.animation -#begin Textures/Animations/player_look_down_weapon.animation -/copy:Textures/Animations/player_look_down_weapon.animation - -#begin Textures/Animations/player_look_left.animation -/copy:Textures/Animations/player_look_left.animation +#begin Textures/Animations/player_look_left_down_weapon.animation +/copy:Textures/Animations/player_look_left_down_weapon.animation #begin Textures/Animations/player_look_left_down.animation /copy:Textures/Animations/player_look_left_down.animation -#begin Textures/Animations/player_look_left_down_weapon.animation -/copy:Textures/Animations/player_look_left_down_weapon.animation +#begin Textures/Animations/player_look_left_up_weapon.animation +/copy:Textures/Animations/player_look_left_up_weapon.animation #begin Textures/Animations/player_look_left_up.animation /copy:Textures/Animations/player_look_left_up.animation -#begin Textures/Animations/player_look_left_up_weapon.animation -/copy:Textures/Animations/player_look_left_up_weapon.animation - #begin Textures/Animations/player_look_left_weapon.animation /copy:Textures/Animations/player_look_left_weapon.animation -#begin Textures/Animations/player_look_right.animation -/copy:Textures/Animations/player_look_right.animation - -#begin Textures/Animations/player_look_right_down.animation -/copy:Textures/Animations/player_look_right_down.animation +#begin Textures/Animations/player_look_left.animation +/copy:Textures/Animations/player_look_left.animation #begin Textures/Animations/player_look_right_down_weapon.animation /copy:Textures/Animations/player_look_right_down_weapon.animation -#begin Textures/Animations/player_look_right_up.animation -/copy:Textures/Animations/player_look_right_up.animation +#begin Textures/Animations/player_look_right_down.animation +/copy:Textures/Animations/player_look_right_down.animation #begin Textures/Animations/player_look_right_up_weapon.animation /copy:Textures/Animations/player_look_right_up_weapon.animation +#begin Textures/Animations/player_look_right_up.animation +/copy:Textures/Animations/player_look_right_up.animation + #begin Textures/Animations/player_look_right_weapon.animation /copy:Textures/Animations/player_look_right_weapon.animation -#begin Textures/Animations/player_look_up.animation -/copy:Textures/Animations/player_look_up.animation +#begin Textures/Animations/player_look_right.animation +/copy:Textures/Animations/player_look_right.animation #begin Textures/Animations/player_look_up_weapon.animation /copy:Textures/Animations/player_look_up_weapon.animation -#begin Textures/Animations/player_right_idle.animation -/copy:Textures/Animations/player_right_idle.animation +#begin Textures/Animations/player_look_up.animation +/copy:Textures/Animations/player_look_up.animation #begin Textures/Animations/player_run_down.animation /copy:Textures/Animations/player_run_down.animation -#begin Textures/Animations/player_run_left.animation -/copy:Textures/Animations/player_run_left.animation - #begin Textures/Animations/player_run_left_down.animation /copy:Textures/Animations/player_run_left_down.animation #begin Textures/Animations/player_run_left_up.animation /copy:Textures/Animations/player_run_left_up.animation -#begin Textures/Animations/player_run_right.animation -/copy:Textures/Animations/player_run_right.animation - -#begin Textures/Animations/player_run_right.zip -/copy:Textures/Animations/player_run_right.zip +#begin Textures/Animations/player_run_left.animation +/copy:Textures/Animations/player_run_left.animation #begin Textures/Animations/player_run_right_down.animation /copy:Textures/Animations/player_run_right_down.animation @@ -293,6 +236,12 @@ #begin Textures/Animations/player_run_right_up.animation /copy:Textures/Animations/player_run_right_up.animation +#begin Textures/Animations/player_run_right.animation +/copy:Textures/Animations/player_run_right.animation + +#begin Textures/Animations/player_run_right.zip +/copy:Textures/Animations/player_run_right.zip + #begin Textures/Animations/player_run_up.animation /copy:Textures/Animations/player_run_up.animation @@ -302,15 +251,30 @@ #begin Textures/Animations/player_top_mining.animation /copy:Textures/Animations/player_top_mining.animation -#begin Textures/Animations/player_top-left_idle.animation -/copy:Textures/Animations/player_top-left_idle.animation - -#begin Textures/Animations/player_top-right_idle.animation -/copy:Textures/Animations/player_top-right_idle.animation - #begin Textures/Animations/running_top.animation /copy:Textures/Animations/running_top.animation +#begin Textures/Animations/Simple Idles/player_down_idle.animation +/copy:Textures/Animations/Simple Idles/player_down_idle.animation + +#begin Textures/Animations/Simple Idles/player_down-left_idle.animation +/copy:Textures/Animations/Simple Idles/player_down-left_idle.animation + +#begin Textures/Animations/Simple Idles/player_down-right_idle.animation +/copy:Textures/Animations/Simple Idles/player_down-right_idle.animation + +#begin Textures/Animations/Simple Idles/player_left_idle.animation +/copy:Textures/Animations/Simple Idles/player_left_idle.animation + +#begin Textures/Animations/Simple Idles/player_right_idle.animation +/copy:Textures/Animations/Simple Idles/player_right_idle.animation + +#begin Textures/Animations/Simple Idles/player_top-left_idle.animation +/copy:Textures/Animations/Simple Idles/player_top-left_idle.animation + +#begin Textures/Animations/Simple Idles/player_top-right_idle.animation +/copy:Textures/Animations/Simple Idles/player_top-right_idle.animation + #begin Textures/Animations/testAnimation.animation /copy:Textures/Animations/testAnimation.animation @@ -332,18 +296,6 @@ #begin Textures/Animations/zombie_walk.animation /copy:Textures/Animations/zombie_walk.animation -#begin Textures/AnimationTextures/Character/hr-level1_idle.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/AnimationTextures/Character/hr-level1_idle.png - #begin Textures/AnimationTextures/Character/hr-level1_idle_gun.png /importer:TextureImporter /processor:TextureProcessor @@ -356,6 +308,18 @@ /processorParam:TextureFormat=Color /build:Textures/AnimationTextures/Character/hr-level1_idle_gun.png +#begin Textures/AnimationTextures/Character/hr-level1_idle.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/AnimationTextures/Character/hr-level1_idle.png + #begin Textures/AnimationTextures/Character/hr-level1_mining_tool-1.png /importer:TextureImporter /processor:TextureProcessor @@ -380,18 +344,6 @@ /processorParam:TextureFormat=Color /build:Textures/AnimationTextures/Character/hr-level1_mining_tool-2.png -#begin Textures/AnimationTextures/Character/hr-level1_running.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/AnimationTextures/Character/hr-level1_running.png - #begin Textures/AnimationTextures/Character/hr-level1_running_gun.png /importer:TextureImporter /processor:TextureProcessor @@ -404,6 +356,18 @@ /processorParam:TextureFormat=Color /build:Textures/AnimationTextures/Character/hr-level1_running_gun.png +#begin Textures/AnimationTextures/Character/hr-level1_running.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/AnimationTextures/Character/hr-level1_running.png + #begin Textures/AnimationTextures/unicorn.png /importer:TextureImporter /processor:TextureProcessor @@ -439,9 +403,8 @@ /processorParam:MakeSquare=False /processorParam:TextureFormat=Color /build:Textures/AnimationTextures/Zombie/zombie_spritesheet_v2.png - -#begin Textures/Effects/explosion.png +#begin Textures/Effects/explosion.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -451,9 +414,9 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/Effects/explosion.png +/build:Textures/Effects/explosion.png -#begin Textures/GUI/back.png +#begin Textures/GUI/back.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -462,8 +425,8 @@ /processorParam:PremultiplyAlpha=True /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/GUI/back.png +/processorParam:TextureFormat=Color +/build:Textures/GUI/back.png #begin Textures/GUI/background/base.png /importer:TextureImporter @@ -572,7 +535,7 @@ /processorParam:MakeSquare=False /processorParam:TextureFormat=Color /build:Textures/GUI/Button2.png - + #begin Textures/GUI/ButtonI.png /importer:TextureImporter /processor:TextureProcessor @@ -584,8 +547,20 @@ /processorParam:MakeSquare=False /processorParam:TextureFormat=Color /build:Textures/GUI/ButtonI.png - -#begin Textures/GUI/checkboxs_off.png + +#begin Textures/GUI/checkboxs_off-on.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/GUI/checkboxs_off-on.png + +#begin Textures/GUI/checkboxs_off.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -597,18 +572,6 @@ /processorParam:TextureFormat=Color /build:Textures/GUI/checkboxs_off.png -#begin Textures/GUI/checkboxs_off-on.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/GUI/checkboxs_off-on.png - #begin Textures/GUI/checkboxs_on.png /importer:TextureImporter /processor:TextureProcessor @@ -645,18 +608,6 @@ /processorParam:TextureFormat=Color /build:Textures/GUI/mouse.png -#begin Textures/GUI/switch.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/GUI/switch.png - #begin Textures/GUI/Switch_backgrownd.png /importer:TextureImporter /processor:TextureProcessor @@ -669,6 +620,18 @@ /processorParam:TextureFormat=Color /build:Textures/GUI/Switch_backgrownd.png +#begin Textures/GUI/switch.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/GUI/switch.png + #begin Textures/icons/12.png /importer:TextureImporter /processor:TextureProcessor @@ -885,18 +848,6 @@ /processorParam:TextureFormat=Color /build:Textures/icons/ExitZone.png -#begin Textures/icons/ExitZone.png -/importer:TextureImporter -/processor:TextureProcessor -/processorParam:ColorKeyColor=255,0,255,255 -/processorParam:ColorKeyEnabled=True -/processorParam:GenerateMipmaps=False -/processorParam:PremultiplyAlpha=True -/processorParam:ResizeToPowerOfTwo=False -/processorParam:MakeSquare=False -/processorParam:TextureFormat=Color -/build:Textures/icons/ExitZone.png - #begin Textures/icons/Material/Fabric.png /importer:TextureImporter /processor:TextureProcessor diff --git a/ZoFo/GameCore/GUI/DebugHUD.cs b/ZoFo/GameCore/GUI/DebugHUD.cs index a49c329..d728ada 100644 --- a/ZoFo/GameCore/GUI/DebugHUD.cs +++ b/ZoFo/GameCore/GUI/DebugHUD.cs @@ -31,7 +31,7 @@ public class DebugHUD public void Draw(SpriteBatch spriteBatch) { - return;//TODO delete + //return;//TODO delete var keysString = Join("\n", _text.Select(el => el.Key + ": " + el.Value).ToList()); spriteBatch.Begin(); spriteBatch.DrawString( diff --git a/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs b/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs index 94bde56..a316c81 100644 --- a/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs +++ b/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs @@ -28,7 +28,7 @@ public class WaitingForPlayersGUI : AbstractGUI int width = AppManager.Instance.CurentScreenResolution.X; int height = AppManager.Instance.CurentScreenResolution.Y; - menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures/GUI/background/Waiting" }; + menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures/GUI/background/waiting" }; Elements.Add(menuBackground); menuBackground.LoadTexture(AppManager.Instance.Content); // string pcIp = diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs index 1631a93..2d9d42f 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Data.SqlTypes; using System.Linq; using System.Net; +using System.Net.NetworkInformation; using System.Net.Sockets; using System.Security.Cryptography.X509Certificates; using System.Text; @@ -241,20 +242,19 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager } #endregion public static IPAddress GetIp() - { - string hostName = Dns.GetHostName(); // Retrive the Name of HOST - var ipList = Dns.GetHostEntry(hostName).AddressList; - var ipV4List = new List(); - foreach (var ip in ipList) + { + var ips = NetworkInterface.GetAllNetworkInterfaces() + .Where(x => x.OperationalStatus == OperationalStatus.Up) + .Where(x => x.NetworkInterfaceType is NetworkInterfaceType.Wireless80211 + or NetworkInterfaceType.Ethernet) + .SelectMany(x => x.GetIPProperties().UnicastAddresses) + .Where(x => x.Address.AddressFamily == AddressFamily.InterNetwork) + .Select(x => x.Address) + .ToList(); + + if (ips.Count > 0) { - if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) - { - ipV4List.Add(ip); - } - } - if (ipV4List.Count>0) - { - return ipV4List[ipV4List.Count - 1]; + return ips[^1]; } return IPAddress.Loopback; } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs index fc471d4..c2bb960 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; +using System.Net.NetworkInformation; using System.Net.Sockets; using System.Text; using System.Text.Json; @@ -64,22 +65,20 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager /// Получает IP устройства /// /// - public static IPAddress GetIp() + public static IPAddress GetIp() { - string hostName = Dns.GetHostName(); // Retrive the Name of HOST - var ipList = Dns.GetHostEntry(hostName).AddressList; - - var ipV4List = new List(); - foreach (var ip in ipList) + var ips = NetworkInterface.GetAllNetworkInterfaces() + .Where(x => x.OperationalStatus == OperationalStatus.Up) + .Where(x => x.NetworkInterfaceType is NetworkInterfaceType.Wireless80211 + or NetworkInterfaceType.Ethernet) + .SelectMany(x => x.GetIPProperties().UnicastAddresses) + .Where(x => x.Address.AddressFamily == AddressFamily.InterNetwork) + .Select(x => x.Address) + .ToList(); + + if (ips.Count > 0) { - if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) - { - ipV4List.Add(ip); - } - } - if (ipV4List.Count > 0) - { - return ipV4List[ipV4List.Count - 1]; + return ips[^1]; } return IPAddress.Loopback; } diff --git a/ZoFo/ZoFo.csproj b/ZoFo/ZoFo.csproj index 85b8274..f093910 100644 --- a/ZoFo/ZoFo.csproj +++ b/ZoFo/ZoFo.csproj @@ -29,6 +29,7 @@ +