AddComments
This commit is contained in:
parent
86c73093c5
commit
f874938a13
3 changed files with 26 additions and 13 deletions
|
@ -26,7 +26,6 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
public event OnDataSend GetDataSend; // event
|
||||
Dictionary<Socket, Thread> managerThread;
|
||||
|
||||
|
||||
public void Init() //create Socket
|
||||
{
|
||||
endPoint = new IPEndPoint(ip, port);
|
||||
|
@ -46,11 +45,11 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
{
|
||||
updates.Add(data);
|
||||
}
|
||||
|
||||
public void CloseConnection()
|
||||
public void CloseConnection() //По сути коне игры и отключение игроков
|
||||
{
|
||||
foreach (var item in clients)
|
||||
{
|
||||
//Закрывает сокеты клиентов
|
||||
item.Shutdown(SocketShutdown.Both);
|
||||
item.Close();
|
||||
}
|
||||
|
@ -58,14 +57,16 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
{
|
||||
foreach (var socket in clients)
|
||||
{
|
||||
//Закрывает потоки клиентов
|
||||
managerThread[socket].Interrupt();
|
||||
}
|
||||
}
|
||||
//очищает листы
|
||||
managerThread.Clear();
|
||||
clients.Clear();
|
||||
}
|
||||
//Поток 2
|
||||
|
||||
//Потоки Клиентов
|
||||
public void StartWaitingForPlayers(object players)//Слушает игроков, которые хотят подключиться
|
||||
{
|
||||
int playNumber = (int)players;
|
||||
|
@ -81,7 +82,6 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
private void StartListening(object socket)//начать слушать клиентов в самой игре активируют Ивент
|
||||
{
|
||||
// obj to Socket
|
||||
|
@ -94,7 +94,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
GetDataSend(response);
|
||||
}
|
||||
Thread.Sleep(-1);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,22 @@ 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.Updates.ClientToServer;
|
||||
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
|
||||
|
||||
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates
|
||||
{
|
||||
[JsonDerivedType(typeof(UpdateAnimation))]
|
||||
[JsonDerivedType(typeof(UpdateEntityHealth))]
|
||||
[JsonDerivedType(typeof(UpdateGameEnded))]
|
||||
[JsonDerivedType(typeof(UpdateGameObjectCreated))]
|
||||
[JsonDerivedType(typeof(UpdateLoot))]
|
||||
[JsonDerivedType(typeof(UpdatePlayerParametrs))]
|
||||
[JsonDerivedType(typeof(UpdatePosition))]
|
||||
[JsonDerivedType(typeof(UpdateInput))]
|
||||
[JsonDerivedType(typeof(UpdatePlayerExit))]
|
||||
public interface IUpdateData
|
||||
{
|
||||
public int IdEntity { get; set; } //Id объекта
|
||||
|
|
|
@ -15,27 +15,28 @@ namespace ZoFo.GameCore
|
|||
{
|
||||
private List<GameObject> gameObjects;
|
||||
private ServerNetworkManager networkManager;
|
||||
// private List<> entity; //entity
|
||||
private List<Entity> entity; //entity
|
||||
public Server()
|
||||
{
|
||||
networkManager = new ServerNetworkManager();
|
||||
networkManager.GetDataSend += OnDataSend;
|
||||
}
|
||||
|
||||
public void OnDataSend(string data)
|
||||
{
|
||||
List<IUpdateData> updateDatas = JsonSerializer.Deserialize<List<IUpdateData>>(data);
|
||||
//ТУТ Switch case будет честное слово
|
||||
}
|
||||
public void CreateRoom(int players) {
|
||||
public void CreateRoom(int players) //Создает комнату и запускает ожидание подключений
|
||||
{
|
||||
networkManager.StartWaitingForPlayers(players);
|
||||
}
|
||||
// public void StartGame() { } принудительный запуск
|
||||
public void EndGame() {
|
||||
|
||||
// public void StartGame() { } принудительный запуск
|
||||
public void EndGame() //Добавляет UpdateGameEnded и отключает игроков
|
||||
{
|
||||
UpdateGameEnded gameEnded = new UpdateGameEnded();
|
||||
networkManager.AddData(gameEnded);
|
||||
networkManager.CloseConnection();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue