NetworkManager

This commit is contained in:
MARKPRO44 2024-08-15 10:39:42 +03:00
commit 17677fbbf0
13 changed files with 218 additions and 9 deletions

View file

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ZoFo.GameCore.GameManagers.NetworkManager.Updates;
namespace ZoFo.GameCore.GameManagers.NetworkManager
{
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);
}
}
}
}

View file

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer
{
internal class UpdateInput
{
}
}

View file

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer
{
public class UpdatePlayerExit : IUpdateData
{
public int IdEntity { get; set; }
public string UpdateType { get; set; }
}
}

View file

@ -1,5 +1,15 @@
interface IUpdateData
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates
{
}
public interface IUpdateData
{
public int IdEntity { get; set; } //Id объекта
public string UpdateType { get; set; } //тип обновления
}
}

View file

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
{
public class UpdateAnimation : IUpdateData //хранит новую анимации
{
public int IdEntity { get; set; }
public string UpdateType { get; set; }
}
}

View file

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
{
public class UpdateEntityHealth : IUpdateData//хранит новое хп entity
{
public int IdEntity { get; set; }
public string UpdateType { get; set; }
}
}

View file

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
{
public class UpdateGameEnded : IUpdateData //хранит полученый лут и уведомляет о конце игры
{
public int IdEntity { get; set; }
public string UpdateType { get; set; }
}
}

View file

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
{
public class UpdateGameObjectCreated : IUpdateData //Хранит объект, который только отправили
{
public int IdEntity { get; set; }
public string UpdateType { get; set; }
}
}

View file

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
{
public class UpdateLoot : IUpdateData //Хранит лут
{
public int IdEntity { get; set; }
public string UpdateType { get; set; }
}
}

View file

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
{
public class UpdatePlayerParametrs : IUpdateData //Хранит хп, радиацию
{
public int IdEntity { get; set; }
public string UpdateType { get; set; }
}
}

View file

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
{
public class UpdatePosition : IUpdateData //Хранит новую позицию
{
public int IdEntity { get; set; }
public string UpdateType { get; set; }
}
}

View file

@ -1,6 +0,0 @@
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates;
public class Update
{
//helll
}

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