Merge branch 'NetworkManagerDev' into Development

This commit is contained in:
Lev 2024-08-15 11:03:22 +03:00
commit 0808af6713
5 changed files with 109 additions and 3 deletions

14
ZoFo/GameCore/Client.cs Normal file
View file

@ -0,0 +1,14 @@
namespace ZoFo.GameCore
{
public class Client
{
public void OnDataSend(string Data){ }
public void GameEndedUnexpectedly(){ }
public void JoinRoom() { }
public void JoinYourself(){ }
}
}

View file

@ -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()
{
}
}
}

View file

@ -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<Socket> clients;
private List<IUpdateData> 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<IUpdateData> updateDatas =
}
}
}
}

View file

@ -1,4 +1,5 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

22
ZoFo/GameCore/Server.cs Normal file
View file

@ -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<GameObject> gameObjects;
// private List<> entity; //entity
public void OnDataSend(string data) { }
public void CreateRoom() { }
public void StartGame() { }
public void EndGame() { }
}
}