diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs
index 5b7f1bd..665179e 100644
--- a/ZoFo/GameCore/Client.cs
+++ b/ZoFo/GameCore/Client.cs
@@ -12,7 +12,9 @@ using ZoFo.GameCore.GameObjects.MapObjects;
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
using System.Drawing;
using System.Reflection;
-using ZoFo.GameCore.GameObjects.Entities;
+using ZoFo.GameCore.GameObjects.Entities;
+using System.Net.Sockets;
+using System.Net;
using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer;
using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player;
@@ -20,7 +22,7 @@ using System.Linq;
using System.Web;
using ZoFo.GameCore.GUI;
using ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables;
-using ZoFo.GameCore.GameObjects.MapObjects.StopObjects;
+using ZoFo.GameCore.GameObjects.MapObjects.StopObjects;
namespace ZoFo.GameCore
{
public class Client
@@ -30,6 +32,8 @@ namespace ZoFo.GameCore
ClientNetworkManager networkManager;
public bool IsConnected { get { return networkManager.IsConnected; } }
+ public IPEndPoint InfoConnect => networkManager.InfoConnect;
+
public Client()
{
networkManager = new ClientNetworkManager();
diff --git a/ZoFo/GameCore/GUI/SelectingServerGUI.cs b/ZoFo/GameCore/GUI/SelectingServerGUI.cs
index fafc259..9460341 100644
--- a/ZoFo/GameCore/GUI/SelectingServerGUI.cs
+++ b/ZoFo/GameCore/GUI/SelectingServerGUI.cs
@@ -21,30 +21,32 @@ public class SelectingServerGUI : AbstractGUI
{
int width = AppManager.Instance.CurentScreenResolution.X;
int height = AppManager.Instance.CurentScreenResolution.Y;
-
+
menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures/GUI/background/join" };
Elements.Add(menuBackground);
menuBackground.LoadTexture(AppManager.Instance.Content);
-
- Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 7, (int)(width / 4), (int)(height / 20)), text = "Select server", fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts/Font"});
- TextBox ipBox = new TextBox(Manager)
+ Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 7, (int)(width / 4), (int)(height / 20)), text = "Select server", fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts/Font" });
+
+ TextBox ipBox = new TextBox(Manager)
{
rectangle = new Rectangle(width / 4 - (width / 4) / 2, height / 4, (int)(width / 4), (int)(height / 20)),
text = "ip",
- scale = 0.2f,
+ scale = 0.5f,
fontColor = Color.White,
mainColor = Color.Gray,
textAligment = MonogameLibrary.UI.Enums.TextAligment.Left,
- fontName = "Fonts/Font"
+ fontName = "Fonts/Font3"
};
- ipBox.TextChanged += input => {
+ ipBox.TextChanged += input =>
+ {
if (input == "ip")
{
ipBox.text = ""; ipBox.fontColor = Color.White;
}
};
- ipBox.StopChanging += input => {
+ ipBox.StopChanging += input =>
+ {
if (input.Length == 0)
{
ipBox.fontColor = Color.White;
@@ -52,7 +54,7 @@ public class SelectingServerGUI : AbstractGUI
}
};
Elements.Add(ipBox);
- Button joinButton = new Button(Manager)
+ Button joinButton = new Button(Manager)
{
rectangle = new Rectangle(width / 4 + (width / 4) / 2, height / 4, (int)(width / 15), (int)(height / 20)),
text = "Join",
@@ -61,23 +63,32 @@ public class SelectingServerGUI : AbstractGUI
mainColor = Color.Gray,
fontName = "Fonts/Font"
};
- joinButton.LeftButtonPressed += () =>
+ joinButton.LeftButtonPressed += () =>
{
// join
Client client = new Client();
- var endpoint = ipBox.text.Split(':');
+ var endpoint = ipBox.text.Split(':');
int port;
- if (int.TryParse(endpoint[1], out port))
+ try
{
- client.JoinRoom(endpoint[0], port);
- AppManager.Instance.SetClient(client);
- AppManager.Instance.SetGUI(new WaitingForPlayersGUI(false));
+ if (int.TryParse(endpoint[1], out port))
+ {
+ client.JoinRoom(endpoint[0], port);
+ AppManager.Instance.SetClient(client);
+ AppManager.Instance.SetGUI(new WaitingForPlayersGUI(false));
+ }
}
+ catch (Exception)
+ {
+
+ // throw;
+ }
+
// ваш код здесь
};
Elements.Add(joinButton);
- Button hostButton = new Button(Manager)
+ Button hostButton = new Button(Manager)
{
rectangle = new Rectangle(width / 4 + (width / 4) / 2 + (width / 15), height / 4, (int)(width / 15), (int)(height / 20)),
text = "Host",
@@ -86,22 +97,25 @@ public class SelectingServerGUI : AbstractGUI
mainColor = Color.Gray,
fontName = "Fonts/Font"
};
- hostButton.LeftButtonPressed += () =>
+ hostButton.LeftButtonPressed += () =>
{
-
+
// host
Server server = new Server(); //Server Logic MultiPlayer
- server.CreateRoom(5);
+ Client client = new Client();
+ server.CreateRoom(2);
+ client.JoinYourself(server.MyIp.Port);
AppManager.Instance.SetServer(server);
+ AppManager.Instance.SetClient(client);
string key = server.MyIp.ToString();
AppManager.Instance.debugHud.Set(key, "MultiPlayer");
// ваш код здесь
AppManager.Instance.SetGUI(new WaitingForPlayersGUI(true));
};
Elements.Add(hostButton);
-
+
Button bTExit = new Button(Manager)
- { fontName = "Fonts/Font3", scale = 0.4f, text = "<-", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40), textureName = "Textures/GUI/checkboxs_off"};
+ { fontName = "Fonts/Font3", scale = 0.4f, text = "<-", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40), textureName = "Textures/GUI/checkboxs_off" };
Elements.Add(bTExit);
bTExit.LeftButtonPressed += () =>
{
diff --git a/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs b/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs
index 2632e0a..2764fb1 100644
--- a/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs
+++ b/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs
@@ -30,13 +30,17 @@ public class WaitingForPlayersGUI : AbstractGUI
menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures/GUI/background/Waiting" };
Elements.Add(menuBackground);
- menuBackground.LoadTexture(AppManager.Instance.Content);
+ menuBackground.LoadTexture(AppManager.Instance.Content);
+ // string pcIp =
+
// string pcIp =
ip = new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 7, (int)(width / 4), (int)(height / 20)), text = AppManager.Instance.server.MyIp.ToString(), fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts/Font3" };
- Elements.Add(ip);
+ Elements.Add(ip);
if (isHost)
{
- Button startButton = new Button(Manager)
+ ip = new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 7, (int)(width / 4), (int)(height / 20)), text = AppManager.Instance.server.MyIp.ToString(), fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font3" };
+ Elements.Add(ip);
+ Button startButton = new Button(Manager)
{
rectangle = new Rectangle(width / 2 - (width / 15) / 2, height / 2 + height / 4, (int)(width / 15), (int)(height / 20)),
text = "Start",
@@ -45,14 +49,34 @@ public class WaitingForPlayersGUI : AbstractGUI
mainColor = Color.Gray,
fontName = "Fonts/Font"
};
- startButton.LeftButtonPressed += () =>
+ startButton.LeftButtonPressed += () =>
{
// start
-
+ AppManager.Instance.ChangeState(GameState.HostPlaying);
// ваш код здесь
};
Elements.Add(startButton);
}
+ else {
+ ip = new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 7, (int)(width / 4), (int)(height / 20)), text = AppManager.Instance.client.InfoConnect.ToString(), fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font3" };
+ Elements.Add(ip);
+ Button waitButton = new Button(Manager)
+ {
+ rectangle = new Rectangle(width / 2 - (width / 15) / 2, height / 2 + height / 4, (int)(width / 15), (int)(height / 20)),
+ text = "WAITING",
+ scale = 0.3f,
+ fontColor = Color.White,
+ mainColor = Color.Gray,
+ fontName = "Fonts/Font"
+ };
+ waitButton.LeftButtonPressed += () =>
+ {
+ // start
+ AppManager.Instance.ChangeState(GameState.ClientPlaying);
+ // ваш код здесь
+ };
+ Elements.Add(waitButton);
+ }
Button bTExit = new Button(Manager)
{ fontName = "Fonts/Font3", scale = 0.4f, text = "<-", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40), textureName = "Textures/GUI/checkboxs_off"};
diff --git a/ZoFo/GameCore/GameManagers/AppManager.cs b/ZoFo/GameCore/GameManagers/AppManager.cs
index 42e886a..b879078 100644
--- a/ZoFo/GameCore/GameManagers/AppManager.cs
+++ b/ZoFo/GameCore/GameManagers/AppManager.cs
@@ -94,7 +94,7 @@ namespace ZoFo.GameCore.GameManagers
Keyboard.GetState().IsKeyDown(Keys.Escape)) { server.CloseConnection(); Exit(); }
- debugHud.Set("key", "value");
+ // debugHud.Set("key", "value");
InputManager.Update();
currentGUI.Update(gameTime);
@@ -107,7 +107,7 @@ namespace ZoFo.GameCore.GameManagers
client.Update(gameTime);
break;
case GameState.ClientPlaying:
- server.Update(gameTime);
+ client.Update(gameTime);
break;
default:
break;
diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs
index 67c09bc..00f5005 100644
--- a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs
+++ b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs
@@ -108,7 +108,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
while(socket.Connected)
{
byte[] bytes = new byte[2048];
- var countAnsw = socket.Receive(bytes);
+ var countAnsw = socket.Receive(bytes); //Вылетает если кто то закрыл
string update = Encoding.UTF8.GetString(bytes, 0, countAnsw); // обновление отосланные сервером
GetDataSent(update);
}
diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs
index e51577e..4bc5425 100644
--- a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs
+++ b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs
@@ -52,8 +52,9 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
///
public static IPAddress GetIp()
{
- string hostName = Dns.GetHostName(); // Retrive the Name of HOST
- string myIP = Dns.GetHostByName(hostName).AddressList[1].ToString();// Get the IP
+ string hostName = Dns.GetHostName(); // Retrive the Name of HOST
+ var ipList = Dns.GetHostByName(hostName).AddressList;
+ string myIP = ipList[ipList.Count()-1].ToString();// Get the IP
return IPAddress.Parse(myIP);
}
@@ -69,7 +70,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
}
updates.Clear();
return; //TODO TODO REMOVE TO ADD NETWORK TODO REMOVE TO ADD NETWORK TODO REMOVE TO ADD NETWORK TODO REMOVE TO ADD NETWORK
-
+ //Что это?
//по 10 паков за раз TODO FIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXIT
List datasToSend = new List();
for (int i = 0; i < 5 && i
diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateInteraction.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateInteraction.cs
index 09b0bc3..6f4711d 100644
--- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateInteraction.cs
+++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateInteraction.cs
@@ -4,12 +4,13 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
/// При попытке взаимодействия с объектом
///
public class UpdateInteraction : UpdateData
-{
+{
+ public UpdateInteraction() { UpdateType = "UpdateInteraction"; }
public UpdateInteraction(int id)
{
IdEntity = id;
}
public int IdEntity { get; set; }
- public string UpdateType { get; set; }
+ public string UpdateType { get; set; }
}
\ No newline at end of file
diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateInteractionReady.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateInteractionReady.cs
index db4d01d..591bc1b 100644
--- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateInteractionReady.cs
+++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateInteractionReady.cs
@@ -9,6 +9,6 @@ public class UpdateInteractionReady(int idEntity, bool isReady)
: UpdateData
{
public int IdEntity { get; set; } = idEntity;
- public string UpdateType { get; set; }
+ public string UpdateType { get; set; } = "UpdateInteractionReady";
public bool IsReady { get; set; } = isReady;
}
\ No newline at end of file
diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs
index 575778e..26c939f 100644
--- a/ZoFo/GameCore/Server.cs
+++ b/ZoFo/GameCore/Server.cs
@@ -27,8 +27,7 @@ namespace ZoFo.GameCore
{
private ServerNetworkManager networkManager;
private int ticks = 0;
- public IPEndPoint MyIp { get { return networkManager.InfoConnect; } }
-
+ public IPEndPoint MyIp { get { return networkManager.InfoConnect; } }
public Server()
{
networkManager = new ServerNetworkManager();
@@ -56,6 +55,32 @@ namespace ZoFo.GameCore
{
//ТУТ Switch case будет честное слово
+ switch (updateData.UpdateType)
+ {
+ case "UpdateAnimation":
+ break;
+ case "UpdateEntityHealth":
+ break;
+ case "UpdateGameEnded":
+ break;
+ case "UpdateGameObjectCreated":
+ break;
+ case "UpdateGameObjectDeleted":
+ break;
+ case "UpdateInteraction":
+ break;
+ case "UpdateInteractionReady":
+ break;
+ case "UpdateLoot":
+ break;
+ case "UpdatePlayerParametrs":
+ break;
+ case "UpdatePosition":
+ break;
+ case "UpdateTileCreated":
+ break;
+
+ }
}
public void CloseConnection()
@@ -179,14 +204,14 @@ namespace ZoFo.GameCore
AddData(new UpdateGameObjectCreated() { GameObjectType = gameObject.GetType().Name,
position = gameObject.position
});
-
+
////var elems = gameObject.GetType().GetProperties(System.Reflection.BindingFlags.Public);
////if (elems.Count()>0) TODO
////{
//// AppManager.Instance.server.collisionManager.Register((elems.First().GetValue(gameObject) as CollisionComponent));
////}
-
+
}
///