diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs new file mode 100644 index 0000000..3716e15 --- /dev/null +++ b/ZoFo/GameCore/Client.cs @@ -0,0 +1,14 @@ + +namespace ZoFo.GameCore +{ + public class Client + { + public void OnDataSend(string Data){ } + + public void GameEndedUnexpectedly(){ } + + public void JoinRoom() { } + + public void JoinYourself(){ } + } +} \ No newline at end of file diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs new file mode 100644 index 0000000..8e77a67 --- /dev/null +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs @@ -0,0 +1,17 @@ +using System.Security.Cryptography.X509Certificates; +using System.Threading; + + +namespace ZoFo.GameCore.GameManagers.NetworkManager +{ + public delegate void OnDataSent(string Data); + + public class ClientNetworkManager + { + public event OnDataSent DataSent; + public static void StartListening() + { + + } + } +} \ No newline at end of file diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs index bcace1e..899f610 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs @@ -1,12 +1,64 @@ -using System; +using Microsoft.Xna.Framework.Graphics.PackedVector; +using System; using System.Collections.Generic; using System.Linq; +using System.Net; +using System.Net.Sockets; using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.Threading; using System.Threading.Tasks; +using ZoFo.GameCore.GameManagers.NetworkManager.Updates; namespace ZoFo.GameCore.GameManagers.NetworkManager { - internal class ServerNetworkManager + public class ServerNetworkManager { + private IPAddress ip = IPAddress.Any; + private int port = 7632; + private IPEndPoint endPoint; + private Socket socket; + private List clients; + private List updates; + delegate void OnDataSend(string data); // + + public void Init() //create Socket + { + endPoint = new IPEndPoint(ip, port); + socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + } + + public void SendData() + { + + } + public void AddData(IUpdateData data) { } + + + //Поток 2 + public void StartWaitingForPlayers()//Слушает игроков, которые хотят подключиться + { + socket.Bind(endPoint); + socket.Listen(10); + for (int i = 0; i < 10; i++) + { + Socket client = socket.Accept(); + clients.Add(client); //добавляем клиентов в лист + } + + StartListening(); + } + + public void StartListening()//начать слушать клиентов в самой игре активируют Ивент + { + var buff = new byte[1024]; + foreach (var client in clients) + { + var answ = client.Receive(buff); + string response = Encoding.UTF8.GetString(buff, 0, answ); + // List updateDatas = + } + } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/IUpdateData.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/IUpdateData.cs index 1a0b8b9..edf1cd5 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/IUpdateData.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/IUpdateData.cs @@ -1,4 +1,5 @@ -using System; + +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs new file mode 100644 index 0000000..948ee0e --- /dev/null +++ b/ZoFo/GameCore/Server.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ZoFo.GameCore.GameObjects; + +namespace ZoFo.GameCore +{ + public class Server + { + private List gameObjects; + // private List<> entity; //entity + + public void OnDataSend(string data) { } + public void CreateRoom() { } + public void StartGame() { } + public void EndGame() { } + + + } +}