diff --git a/ServerOverall/Program.cs b/ServerOverall/Program.cs new file mode 100644 index 0000000..3751555 --- /dev/null +++ b/ServerOverall/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/ServerOverall/Server/NetworkManager.cs b/ServerOverall/Server/NetworkManager.cs new file mode 100644 index 0000000..fb5f678 --- /dev/null +++ b/ServerOverall/Server/NetworkManager.cs @@ -0,0 +1,296 @@ +using System; +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; +using System.Text.Json.Serialization; +using System.Threading; +using System.Threading.Tasks; +using ServerOverall.Server.Updates.ServerToClient; +using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json; +using ServerOverall.Server.Updates.ClientToServer; +using ServerOverall.Server.Updates; +using System.Xml.Linq; + +/*namespace ServerOverall.Server +{ + public class ServerNetworkManager + { + private Socket socket; + private IPAddress ip; + private bool isMultiplayer; + //Player Id to Player endPoint + public List clientsEP; + public IPEndPoint endPoint; + private List commonUpdates; + private List importantUpdates; + private List sendedData; + private List arrivingDataId; + private int currentDatagrammId = 0; + public delegate void OnDataSend(string data); + public event OnDataSend GetDataSend; // event + Thread serverThread; + int datapackSize = 150; + public ServerNetworkManager() { Init(); } + + /// + /// Initialize varibles and Sockets + /// + private void Init() + { + endPoint = new IPEndPoint(GetIp(), 8080); + socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); + clientsEP = new List(); + commonUpdates = new List(); + importantUpdates = new List(); + sendedData = new List(); + arrivingDataId = new List(); + + GetDataSend += AnalyzeData; + + socket.Bind(endPoint); + + } + + /// + /// Получает IP устройства + /// + /// + public static IPAddress GetIp() + { + 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) + { + return ips[^1]; + } + return IPAddress.Loopback; + } + public void SetIsMultiplayer(bool isMultiplayer) + { + this.isMultiplayer = isMultiplayer; + } + + /// + /// отправляет клиенту Data + /// + public void SendData() + { + #region Network Sending SinglePlayerFix + //for (int i = 0; i < updates.Count; i++) + //{ + + // AppManager.Instance.client.GotData(updates[i]); + //} + //updates.Clear(); + //return; //TODO TODO REMOVE TO ADD NETWORK TODO REMOVE TO ADD NETWORK TODO REMOVE TO ADD NETWORK TODO REMOVE TO ADD NETWORK + //Что это? + //по 10 паков за раз TODO FIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXIT + #endregion + if (arrivingDataId.Count != 0) + { + List actualArrivingId = arrivingDataId; + for (int i = 0; i < actualArrivingId.Count; i++) + { + sendedData.Remove(sendedData.Find(x => x.DatagrammId == actualArrivingId[i].DatagrammId + && x.PlayerId == actualArrivingId[i].PlayerId)); + } + arrivingDataId.Clear(); + } + List dataToSend; + if (importantUpdates.Count > 0) + { + dataToSend = new List(); + for (int j = 0; j < datapackSize && j < importantUpdates.Count; j++) + dataToSend.Add(importantUpdates[j]); + for (int i = 0; i < clientsEP.Count; i++) + { + Datagramm impDgramm = new Datagramm(); + impDgramm.DatagrammId = currentDatagrammId; + impDgramm.updateDatas = dataToSend; + impDgramm.isImportant = true; + impDgramm.PlayerId = i + 1; + sendedData.Add(impDgramm); + } + for (int j = 0; j < datapackSize && j < dataToSend.Count; j++) + importantUpdates.RemoveAt(0); + currentDatagrammId++; + } + + if (sendedData.Count != 0) + { + for (int i = 0; i < clientsEP.Count; i++) + { + foreach (Datagramm Dgramm in sendedData.Where(x => x.PlayerId == i + 1)) + { + string impData = System.Text.Json.JsonSerializer.Serialize(Dgramm); + byte[] impBuffer = Encoding.UTF8.GetBytes(impData); + socket.SendTo(impBuffer, clientsEP[i]); + } + } + } + Datagramm unImpDgramm = new Datagramm(); + + dataToSend = new List(); + for (int i = 0; i < 200 && i < commonUpdates.Count; i++) + dataToSend.Add(commonUpdates[i]); + + unImpDgramm.updateDatas = dataToSend; + string data = System.Text.Json.JsonSerializer.Serialize(unImpDgramm); + byte[] buffer = Encoding.UTF8.GetBytes(data); + foreach (EndPoint sendingEP in clientsEP) + { + socket.SendTo(buffer, sendingEP); + } + for (int i = 0; i < 200 && i < dataToSend.Count; i++) + commonUpdates.RemoveAt(0); + } + + /// + /// добавляет в лист updates новую data + /// + /// + public void AddData(UpdateData data) + { + if (data.isImportant) + { + importantUpdates.Add(data); + } + else + { + commonUpdates.Add(data); + } + } + + /// + /// Начинает работу сервера (Ожидает подключений) + /// + /// + public void Start() + { + serverThread = new Thread(StartWaitingForPlayers); + serverThread.IsBackground = true; + serverThread.Start(); + } + public void StartGame() + { + for (int i = 0; i < clientsEP.Count; i++) + { + Datagramm initDgramm = new Datagramm(); + initDgramm.isImportant = true; + initDgramm.DatagrammId = currentDatagrammId; + initDgramm.PlayerId = i + 1; + sendedData.Add(initDgramm); + string data = System.Text.Json.JsonSerializer.Serialize(initDgramm); + byte[] buffer = Encoding.UTF8.GetBytes(data); + socket.SendTo(buffer, clientsEP[i]); + } + currentDatagrammId++; + AppManager.Instance.ChangeState(GameState.HostPlaying); + AppManager.Instance.SetGUI(new HUD());//// + } + public void CloseConnection() + { + //socket.Shutdown(SocketShutdown.Both); + clientsEP.Clear(); + socket.Close(); + } + + //Потоки Клиентов + /// + /// Слушает игроков, которые хотят подключиться + /// + /// + public void StartWaitingForPlayers() + { + byte[] buffer = new byte[65535]; + string data; + int size; + try + { + while (socket != null) + { + EndPoint senderRemote = (EndPoint)new IPEndPoint(IPAddress.Any, 0); + size = socket.ReceiveFrom(buffer, buffer.Length, SocketFlags.None, ref senderRemote); + if (AppManager.Instance.gamestate != GameState.HostPlaying && !clientsEP.Contains(senderRemote) && + senderRemote != new IPEndPoint(IPAddress.Any, 0)) + { + clientsEP.Add((IPEndPoint)senderRemote); + AppManager.Instance.debugHud.Log($"Connect {senderRemote.ToString()}"); + if (!isMultiplayer) AppManager.Instance.ChangeState(GameState.HostPlaying); + // Отправлять Init апдейт с информацией об ID игрока и ID датаграмма на сервере + //Можно добавить bool isInit для Датаграммов + } + byte[] correctedBuffer = new byte[size]; + Array.Copy(buffer, correctedBuffer, size); + data = Encoding.UTF8.GetString(correctedBuffer); + GetDataSend(data); + + } + } + catch (Exception) + { + return; + } + } + public void AnalyzeData(string data) + { + JObject jObj = JsonConvert.DeserializeObject(data) as JObject; + JToken token = JToken.FromObject(jObj); + JToken updateDatas = token["updateDatas"]; + Datagramm Dgramm = new Datagramm(); + Dgramm.PlayerId = token["PlayerId"].ToObject(); + if (!updateDatas.HasValues) + { + //Обработка acknowledgement + Dgramm.DatagrammId = token["DatagrammId"].ToObject(); + arrivingDataId.Add(Dgramm); + } + else + { + List updates = GetSentUpdates(updateDatas); + AppManager.Instance.server.UpdatesList(updates); + } + } + public List GetSentUpdates(JToken updatesToken) + { + List data = new List(); + JArray updateDatas = updatesToken as JArray; + UpdateData update = new UpdateData(); + foreach (JObject token in updateDatas.Children()) + { + switch (token["UpdateType"].ToObject()) + { + case "UpdateInput": + update = token.ToObject(); + data.Add(update); + break; + case "UpdateInputInteraction": + update = token.ToObject(); + data.Add(update); + break; + case "UpdateInputShoot": + update = token.ToObject(); + data.Add(update); + break; + } + } + return data; + } + + } +} +*/ //TODO: Перелопатить весь код и вынести на удалённый сервер \ No newline at end of file diff --git a/ServerOverall/Server/SerializableDTO/SerializablePoint.cs b/ServerOverall/Server/SerializableDTO/SerializablePoint.cs new file mode 100644 index 0000000..8db620a --- /dev/null +++ b/ServerOverall/Server/SerializableDTO/SerializablePoint.cs @@ -0,0 +1,19 @@ +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO +{ + public class SerializablePoint + { + public int X { get; set; } + public int Y { get; set; } + + public SerializablePoint(Point point) { X = point.X; Y = point.Y;} + public SerializablePoint() { } + public Point GetPoint() { return new Point(X, Y);} + } +} diff --git a/ServerOverall/Server/SerializableDTO/SerializableRectangle.cs b/ServerOverall/Server/SerializableDTO/SerializableRectangle.cs new file mode 100644 index 0000000..22ea155 --- /dev/null +++ b/ServerOverall/Server/SerializableDTO/SerializableRectangle.cs @@ -0,0 +1,29 @@ +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; +using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO; + +namespace ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO +{ + [Serializable] + public class SerializableRectangle + { + public SerializablePoint Size { get; set; } + public SerializablePoint Location { get; set; } + public SerializableRectangle() + { + + } + + public SerializableRectangle(Rectangle rectangle) { Size = new SerializablePoint(rectangle.Size); Location = new SerializablePoint(rectangle.Location); } + + public Rectangle GetRectangle() + { + return new Rectangle(Location.GetPoint(), Size.GetPoint()); + } + } +} diff --git a/ServerOverall/Server/SerializableDTO/SerializableVector2.cs b/ServerOverall/Server/SerializableDTO/SerializableVector2.cs new file mode 100644 index 0000000..53414e2 --- /dev/null +++ b/ServerOverall/Server/SerializableDTO/SerializableVector2.cs @@ -0,0 +1,28 @@ +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices.JavaScript; +using System.Text; +using System.Threading.Tasks; + +namespace ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO +{ + [Serializable] + public class SerializableVector2 + { + public float X { get; set; } + public float Y { get; set; } + public SerializableVector2(Vector2 vector) + { + X = vector.X; + Y = vector.Y; + } + public Vector2 GetVector2() + { + return new Vector2(X, Y); + } + } + + +} diff --git a/ServerOverall/Server/Updates/ClientToServer/UpdateInput.cs b/ServerOverall/Server/Updates/ClientToServer/UpdateInput.cs new file mode 100644 index 0000000..89fcb81 --- /dev/null +++ b/ServerOverall/Server/Updates/ClientToServer/UpdateInput.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Xna.Framework; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; +using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO; + +namespace ServerOverall.Server.Updates.ClientToServer +{ + public class UpdateInput :UpdateData + { + // public int IdEntity { get; set; } + public SerializableVector2 InputMovementDirection{get;set;} + public SerializableVector2 InputAttackDirection {get;set;} + + public int PlayerId {get;set;} + public UpdateInput() + { + UpdateType = "UpdateInput"; + } + + } +} diff --git a/ServerOverall/Server/Updates/ClientToServer/UpdateInputInteraction.cs b/ServerOverall/Server/Updates/ClientToServer/UpdateInputInteraction.cs new file mode 100644 index 0000000..5df7f84 --- /dev/null +++ b/ServerOverall/Server/Updates/ClientToServer/UpdateInputInteraction.cs @@ -0,0 +1,14 @@ +using System; +using ZoFo.GameCore.GameManagers.NetworkManager; + +namespace ServerOverall.Server.Updates.ClientToServer; + +/// +/// уведомляет сервер о том, что игрок взаимодействует +/// +public class UpdateInputInteraction : UpdateData +{ + public UpdateInputInteraction() { UpdateType = "UpdateInputInteraction"; } + public int PlayerId { get; set; } + +} diff --git a/ServerOverall/Server/Updates/ClientToServer/UpdatePlayerExit.cs b/ServerOverall/Server/Updates/ClientToServer/UpdatePlayerExit.cs new file mode 100644 index 0000000..a708b54 --- /dev/null +++ b/ServerOverall/Server/Updates/ClientToServer/UpdatePlayerExit.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ServerOverall.Server.Updates.ClientToServer +{ + public class UpdatePlayerExit : UpdateData + { + public UpdatePlayerExit() { UpdateType = "UpdatePlayerExit"; } + } +} diff --git a/ServerOverall/Server/Updates/ClientToServer/UpdateShootInteraction.cs b/ServerOverall/Server/Updates/ClientToServer/UpdateShootInteraction.cs new file mode 100644 index 0000000..672236d --- /dev/null +++ b/ServerOverall/Server/Updates/ClientToServer/UpdateShootInteraction.cs @@ -0,0 +1,10 @@ +using System; +using ZoFo.GameCore.GameManagers.NetworkManager.Updates; + +namespace ServerOverall.Server.Updates.ClientToServer; + +public class UpdateInputShoot : UpdateData +{ + public UpdateInputShoot() { UpdateType = "UpdateInputShoot"; } + public int PlayerId { get; set; } +} diff --git a/ServerOverall/Server/Updates/Datagramm.cs b/ServerOverall/Server/Updates/Datagramm.cs new file mode 100644 index 0000000..0a5b979 --- /dev/null +++ b/ServerOverall/Server/Updates/Datagramm.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ServerOverall.Server.Updates +{ + public class Datagramm + { + public int DatagrammId { get; set; } + public bool isImportant { get; set; } + public List updateDatas { get; set; } + public int PlayerId { get; set; } + } +} diff --git a/ServerOverall/Server/Updates/ServerToClient/UpdateAnimation.cs b/ServerOverall/Server/Updates/ServerToClient/UpdateAnimation.cs new file mode 100644 index 0000000..2010916 --- /dev/null +++ b/ServerOverall/Server/Updates/ServerToClient/UpdateAnimation.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ServerOverall.Server.Updates.ServerToClient +{ + /// + /// Хранит новое сосотяние анимации + /// + public class UpdateAnimation : UpdateData + { + public UpdateAnimation() { UpdateType = "UpdateAnimation"; } + public string animationId { get; set; } + } +} diff --git a/ServerOverall/Server/Updates/ServerToClient/UpdateCreatePlayer.cs b/ServerOverall/Server/Updates/ServerToClient/UpdateCreatePlayer.cs new file mode 100644 index 0000000..0c9eadb --- /dev/null +++ b/ServerOverall/Server/Updates/ServerToClient/UpdateCreatePlayer.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO; + +namespace ServerOverall.Server.Updates.ServerToClient +{ + public class UpdateCreatePlayer : UpdateData + { + public int PlayerId { get; set; } + public UpdateCreatePlayer() + { + isImportant = true; + UpdateType = "UpdateCreatePlayer"; + } + + } +} diff --git a/ServerOverall/Server/Updates/ServerToClient/UpdateEntityHealth.cs b/ServerOverall/Server/Updates/ServerToClient/UpdateEntityHealth.cs new file mode 100644 index 0000000..8890757 --- /dev/null +++ b/ServerOverall/Server/Updates/ServerToClient/UpdateEntityHealth.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ServerOverall.Server.Updates.ServerToClient +{ + /// + /// Обнивляет хп сущности + /// + public class UpdateEntityHealth : UpdateData + { + public UpdateEntityHealth() { UpdateType = "UpdateEntityHealth"; } + } +} diff --git a/ServerOverall/Server/Updates/ServerToClient/UpdateGameEnded.cs b/ServerOverall/Server/Updates/ServerToClient/UpdateGameEnded.cs new file mode 100644 index 0000000..2bc5257 --- /dev/null +++ b/ServerOverall/Server/Updates/ServerToClient/UpdateGameEnded.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ServerOverall.Server.Updates.ServerToClient +{ + /// + /// Хранит полученый лут и уведомляет о конце игры + /// + public class UpdateGameEnded : UpdateData + { + public UpdateGameEnded() { UpdateType = "UpdateGameEnded"; } + } +} diff --git a/ServerOverall/Server/Updates/ServerToClient/UpdateGameOBjectWithoutIdCreated.cs b/ServerOverall/Server/Updates/ServerToClient/UpdateGameOBjectWithoutIdCreated.cs new file mode 100644 index 0000000..c6e3a4f --- /dev/null +++ b/ServerOverall/Server/Updates/ServerToClient/UpdateGameOBjectWithoutIdCreated.cs @@ -0,0 +1,16 @@ + +using Microsoft.Xna.Framework; +using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO; + +namespace ServerOverall.Server.Updates.ServerToClient +{ + /// + /// Хранит новое сосотяние анимации + /// + public class UpdateGameObjectWithoutIdCreated : UpdateData + { + public UpdateGameObjectWithoutIdCreated() { UpdateType = "UpdateGameObjectWithoutIdCreated"; isImportant = true; } + public string GameObjectClassName { get; set; } + public SerializableVector2 position { get; set; } + } +} diff --git a/ServerOverall/Server/Updates/ServerToClient/UpdateGameObjectCreated.cs b/ServerOverall/Server/Updates/ServerToClient/UpdateGameObjectCreated.cs new file mode 100644 index 0000000..460fe99 --- /dev/null +++ b/ServerOverall/Server/Updates/ServerToClient/UpdateGameObjectCreated.cs @@ -0,0 +1,24 @@ +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO; + +namespace ServerOverall.Server.Updates.ServerToClient +{ + /// + /// Хранит объект, который только отправили + /// + public class UpdateGameObjectCreated : UpdateData + { + public UpdateGameObjectCreated() { UpdateType = "UpdateGameObjectCreated"; isImportant = true; } + + public string GameObjectType { get; set; } + + public string GameObjectId { get; set; } + + public SerializableVector2 position { get; set; } + } +} diff --git a/ServerOverall/Server/Updates/ServerToClient/UpdateGameObjectDeleted.cs b/ServerOverall/Server/Updates/ServerToClient/UpdateGameObjectDeleted.cs new file mode 100644 index 0000000..b80dc42 --- /dev/null +++ b/ServerOverall/Server/Updates/ServerToClient/UpdateGameObjectDeleted.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ServerOverall.Server.Updates.ServerToClient +{ + /// + /// Хранит объект, который надо удлить + /// + public class UpdateGameObjectDeleted : UpdateData + { + public UpdateGameObjectDeleted() { UpdateType = "UpdateGameObjectDeleted"; isImportant = false; } + public string GameObjectType { get; set; } + } +} \ No newline at end of file diff --git a/ServerOverall/Server/Updates/ServerToClient/UpdateInteraction.cs b/ServerOverall/Server/Updates/ServerToClient/UpdateInteraction.cs new file mode 100644 index 0000000..75da246 --- /dev/null +++ b/ServerOverall/Server/Updates/ServerToClient/UpdateInteraction.cs @@ -0,0 +1,18 @@ +namespace ServerOverall.Server.Updates.ServerToClient; + +/// +/// При попытке взаимодействия с объектом +/// отправляет пользователю разрешение на взаимодействие +/// TODO: Вероятно убрать(обсудить) +/// +public class UpdateInteraction : UpdateData +{ + public UpdateInteraction() { UpdateType = "UpdateInteraction"; } + public UpdateInteraction(int id) + { + IdEntity = id; + } + + public int IdEntity { get; set; } + public string UpdateType { get; set; } +} \ No newline at end of file diff --git a/ServerOverall/Server/Updates/ServerToClient/UpdateInteractionReady.cs b/ServerOverall/Server/Updates/ServerToClient/UpdateInteractionReady.cs new file mode 100644 index 0000000..b871527 --- /dev/null +++ b/ServerOverall/Server/Updates/ServerToClient/UpdateInteractionReady.cs @@ -0,0 +1,14 @@ +namespace ServerOverall.Server.Updates.ServerToClient; + +/// +/// При изменении возможности повзаимодействовать с объектом +/// +/// +/// +public class UpdateInteractionReady(int idEntity, bool isReady) + : UpdateData +{ + public int IdEntity { get; set; } = idEntity; + public string UpdateType { get; set; } = "UpdateInteractionReady"; + public bool IsReady { get; set; } = isReady; +} \ No newline at end of file diff --git a/ServerOverall/Server/Updates/ServerToClient/UpdateLoot.cs b/ServerOverall/Server/Updates/ServerToClient/UpdateLoot.cs new file mode 100644 index 0000000..79b1862 --- /dev/null +++ b/ServerOverall/Server/Updates/ServerToClient/UpdateLoot.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ServerOverall.Server.Updates.ServerToClient +{ + /// + /// Хранит лут + /// + public class UpdateLoot : UpdateData + { + public string lootName { get; set; } + public int quantity { get; set; } + public UpdateLoot() { UpdateType = "UpdateLoot"; isImportant = true; } + public UpdateLoot(string lootName, int quantity, int id) + { + UpdateType = "UpdateLoot"; + this.lootName = lootName; + this.quantity = quantity; + IdEntity = id; + isImportant = true; + } + } +} diff --git a/ServerOverall/Server/Updates/ServerToClient/UpdatePlayerParametrs.cs b/ServerOverall/Server/Updates/ServerToClient/UpdatePlayerParametrs.cs new file mode 100644 index 0000000..de5593b --- /dev/null +++ b/ServerOverall/Server/Updates/ServerToClient/UpdatePlayerParametrs.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ServerOverall.Server.Updates.ServerToClient +{ + /// + /// Хранит хп, радиацию + /// + public class UpdatePlayerParametrs : UpdateData + { + public UpdatePlayerParametrs() { UpdateType = "UpdatePlayerParametrs"; isImportant = true; } + public float radiatoin { get; set; } + public float health { get; set; } + } +} diff --git a/ServerOverall/Server/Updates/ServerToClient/UpdatePosition.cs b/ServerOverall/Server/Updates/ServerToClient/UpdatePosition.cs new file mode 100644 index 0000000..f681596 --- /dev/null +++ b/ServerOverall/Server/Updates/ServerToClient/UpdatePosition.cs @@ -0,0 +1,21 @@ +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO; +using ZoFo.GameCore.GameObjects.Entities.LivingEntities; + +namespace ServerOverall.Server.Updates.ServerToClient +{ + /// + /// Хранит новую позицию + /// + public class UpdatePosition : UpdateData + { + public UpdatePosition() { UpdateType = "UpdatePosition"; } + + public SerializableVector2 NewPosition { get; set; } + } +} diff --git a/ServerOverall/Server/Updates/ServerToClient/UpdateStopObjectCreated.cs b/ServerOverall/Server/Updates/ServerToClient/UpdateStopObjectCreated.cs new file mode 100644 index 0000000..a94b5a5 --- /dev/null +++ b/ServerOverall/Server/Updates/ServerToClient/UpdateStopObjectCreated.cs @@ -0,0 +1,22 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO; + +namespace ServerOverall.Server.Updates.ServerToClient +{ + internal class UpdateStopObjectCreated : UpdateData + { + public UpdateStopObjectCreated() { UpdateType = "UpdateStopObjectCreated"; isImportant = true; } + public Texture2D TextureTile { get; set; } + public SerializableVector2 Position { get; set; } + public SerializablePoint Size { get; set; } + public SerializableRectangle sourceRectangle { get; set; } + public string tileSetName { get; set; } + public SerializableRectangle[] collisions { get; set; } + } +} diff --git a/ServerOverall/Server/Updates/ServerToClient/UpdateTileCreated.cs b/ServerOverall/Server/Updates/ServerToClient/UpdateTileCreated.cs new file mode 100644 index 0000000..68185bf --- /dev/null +++ b/ServerOverall/Server/Updates/ServerToClient/UpdateTileCreated.cs @@ -0,0 +1,27 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; +using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO; +using ServerOverall.Server.Updates.ClientToServer; + +namespace ServerOverall.Server.Updates.ServerToClient +{ + + /// + /// При создании тайла + /// + public class UpdateTileCreated : UpdateData + { + public UpdateTileCreated() { UpdateType = "UpdateTileCreated"; isImportant = true; } + [JsonInclude] + public SerializableVector2 Position { get; set; } + public SerializablePoint Size { get; set; } + public SerializableRectangle sourceRectangle { get; set; } + public string tileSetName { get; set; } + } +} diff --git a/ServerOverall/Server/Updates/UpdateData.cs b/ServerOverall/Server/Updates/UpdateData.cs new file mode 100644 index 0000000..7b1e880 --- /dev/null +++ b/ServerOverall/Server/Updates/UpdateData.cs @@ -0,0 +1,43 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; +using ServerOverall.Server.Updates.ServerToClient; + +namespace ServerOverall.Server.Updates +{ + [JsonDerivedType(typeof(UpdateAnimation))] + [JsonDerivedType(typeof(UpdateEntityHealth))] + [JsonDerivedType(typeof(UpdateGameEnded))] + [JsonDerivedType(typeof(UpdateGameObjectCreated))] + [JsonDerivedType(typeof(UpdateGameObjectDeleted))] + [JsonDerivedType(typeof(UpdateInteraction))] + [JsonDerivedType(typeof(UpdateInteractionReady))] + [JsonDerivedType(typeof(UpdateLoot))] + [JsonDerivedType(typeof(UpdateGameObjectWithoutIdCreated))] + [JsonDerivedType(typeof(UpdatePlayerParametrs))] + [JsonDerivedType(typeof(UpdatePosition))] + [JsonDerivedType(typeof(UpdateStopObjectCreated))] + [JsonDerivedType(typeof(UpdateTileCreated))] + [JsonDerivedType(typeof(UpdateCreatePlayer))] + + public class UpdateData + { + public int IdEntity { get; set; } //Id объекта + public string UpdateType { get; set; } //тип обновления + public bool isImportant { get; set; } + + public UpdateData() + { + + } + + public UpdateData(int idEntity) + { + this.IdEntity = idEntity; + } + } +} diff --git a/ServerOverall/ServerOverall.csproj b/ServerOverall/ServerOverall.csproj new file mode 100644 index 0000000..ce4a38b --- /dev/null +++ b/ServerOverall/ServerOverall.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + diff --git a/ServerOverall1/App.config b/ServerOverall1/App.config new file mode 100644 index 0000000..91126fc --- /dev/null +++ b/ServerOverall1/App.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ServerOverall1/Program.cs b/ServerOverall1/Program.cs new file mode 100644 index 0000000..eade679 --- /dev/null +++ b/ServerOverall1/Program.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ServerOverall +{ + internal class Program + { + static void Main(string[] args) + { + } + } +} diff --git a/ServerOverall1/Properties/AssemblyInfo.cs b/ServerOverall1/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..cc4fbe1 --- /dev/null +++ b/ServerOverall1/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Общие сведения об этой сборке предоставляются следующим набором +// набора атрибутов. Измените значения этих атрибутов для изменения сведений, +// связанные с этой сборкой. +[assembly: AssemblyTitle("ServerOverall")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ServerOverall")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми +// для компонентов COM. Если необходимо обратиться к типу в этой сборке через +// из модели COM задайте для атрибута ComVisible этого типа значение true. +[assembly: ComVisible(false)] + +// Следующий GUID представляет идентификатор typelib, если этот проект доступен из модели COM +[assembly: Guid("7a1873b0-1318-460a-aacd-f7ca1e78e5e0")] + +// Сведения о версии сборки состоят из указанных ниже четырех значений: +// +// Основной номер версии +// Дополнительный номер версии +// Номер сборки +// Номер редакции +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ServerOverall1/ServerOverall1.csproj b/ServerOverall1/ServerOverall1.csproj new file mode 100644 index 0000000..c46c961 --- /dev/null +++ b/ServerOverall1/ServerOverall1.csproj @@ -0,0 +1,83 @@ + + + + + Debug + AnyCPU + {7A1873B0-1318-460A-AACD-F7CA1E78E5E0} + Exe + ServerOverall + ServerOverall + v4.8 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll + + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Text.Encodings.Web.8.0.0\lib\net462\System.Text.Encodings.Web.dll + + + ..\packages\System.Text.Json.8.0.4\lib\net462\System.Text.Json.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + + + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ServerOverall1/packages.config b/ServerOverall1/packages.config new file mode 100644 index 0000000..2f9e97d --- /dev/null +++ b/ServerOverall1/packages.config @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/ZoFo.sln b/ZoFo.sln index 4310366..44dd495 100644 --- a/ZoFo.sln +++ b/ZoFo.sln @@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MonogameLibrary", "Monogame EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AnimationsFileCreator", "AnimationsFileCreator\AnimationsFileCreator.csproj", "{7B143D5C-5198-4ADE-9291-ECC924B78633}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnimatorFileCreatorAdvanced", "AnimatorFileCreatorAdvanced\AnimatorFileCreatorAdvanced.csproj", "{AAEC2150-3BBF-4B59-A22F-47B30CA6B34B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AnimatorFileCreatorAdvanced", "AnimatorFileCreatorAdvanced\AnimatorFileCreatorAdvanced.csproj", "{AAEC2150-3BBF-4B59-A22F-47B30CA6B34B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServerOverall", "ServerOverall\ServerOverall.csproj", "{A97BE14F-A7F7-4272-9F24-FBC105AF0115}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,8 +35,15 @@ Global {AAEC2150-3BBF-4B59-A22F-47B30CA6B34B}.Debug|Any CPU.Build.0 = Debug|Any CPU {AAEC2150-3BBF-4B59-A22F-47B30CA6B34B}.Release|Any CPU.ActiveCfg = Release|Any CPU {AAEC2150-3BBF-4B59-A22F-47B30CA6B34B}.Release|Any CPU.Build.0 = Release|Any CPU + {A97BE14F-A7F7-4272-9F24-FBC105AF0115}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A97BE14F-A7F7-4272-9F24-FBC105AF0115}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A97BE14F-A7F7-4272-9F24-FBC105AF0115}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A97BE14F-A7F7-4272-9F24-FBC105AF0115}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {BC970026-AE46-4703-8325-D065CFEE9756} + EndGlobalSection EndGlobal