AddServerClass

This commit is contained in:
rawer470 2024-08-15 10:31:46 +03:00
parent ccc784b79c
commit a6fb094bfb
2 changed files with 70 additions and 1 deletions

View file

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

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