WorkServerWithGUI2
This commit is contained in:
parent
a644d6c02a
commit
b1f24ce81b
7 changed files with 18 additions and 9 deletions
|
@ -47,7 +47,7 @@ namespace ZoFo.GameCore
|
|||
{
|
||||
networkManager.JoinRoom(ip,port);
|
||||
}
|
||||
public void JoinYourself() { networkManager.JoinYourself(); }
|
||||
public void JoinYourself(int port) { networkManager.JoinYourself(port); }
|
||||
|
||||
|
||||
List<MapObject> mapObjects = new List<MapObject>();
|
||||
|
|
|
@ -42,7 +42,7 @@ public class SelectModeMenu : AbstractGUI
|
|||
Server server = new Server();
|
||||
Client client = new Client();
|
||||
server.CreateRoom(1);
|
||||
client.JoinYourself();
|
||||
client.JoinYourself(server.MyIp.Port);
|
||||
AppManager.Instance.SetServer(server);
|
||||
AppManager.Instance.SetClient(client);
|
||||
AppManager.Instance.ChangeState(GameState.HostPlaying);
|
||||
|
|
|
@ -84,7 +84,7 @@ public class SelectingServerGUI : AbstractGUI
|
|||
Server server = new Server(); //Server Logic MultiPlayer
|
||||
server.CreateRoom(5);
|
||||
AppManager.Instance.SetServer(server);
|
||||
string key = server.MyIp;
|
||||
string key = server.MyIp.ToString();
|
||||
AppManager.Instance.debugHud.Set(key, "MultiPlayer");
|
||||
// ваш код здесь
|
||||
AppManager.Instance.SetGUI(new WaitingForPlayersGUI(true));
|
||||
|
|
|
@ -32,7 +32,7 @@ public class WaitingForPlayersGUI : AbstractGUI
|
|||
Elements.Add(menuBackground);
|
||||
menuBackground.LoadTexture(AppManager.Instance.Content);
|
||||
// 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, fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font3" };
|
||||
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);
|
||||
if (isHost)
|
||||
{
|
||||
|
|
|
@ -16,12 +16,13 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
public class ClientNetworkManager
|
||||
{
|
||||
private int port = 0;
|
||||
private EndPoint endPoint;
|
||||
private IPEndPoint endPoint;
|
||||
private Socket socket;
|
||||
List<UpdateData> updates = new List<UpdateData>();
|
||||
public delegate void OnDataSent(string Data);
|
||||
public event OnDataSent GetDataSent; // event
|
||||
public bool IsConnected { get { return socket.Connected; } }
|
||||
public IPEndPoint InfoConnect => (IPEndPoint)socket.LocalEndPoint ?? endPoint;
|
||||
|
||||
public ClientNetworkManager()
|
||||
{
|
||||
|
@ -74,9 +75,9 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
/// <summary>
|
||||
/// создается одиночная комната к которой ты подключаешься
|
||||
/// </summary>
|
||||
public void JoinYourself() // single player
|
||||
public void JoinYourself(int port) // single player
|
||||
{
|
||||
endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);
|
||||
endPoint = new IPEndPoint(GetIp(), port);
|
||||
socket.Connect(endPoint);
|
||||
SendData();
|
||||
Thread listen = new Thread(StartListening);
|
||||
|
@ -84,6 +85,13 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
listen.Start();
|
||||
}
|
||||
|
||||
public static IPAddress GetIp()
|
||||
{
|
||||
string hostName = Dns.GetHostName(); // Retrive the Name of HOST
|
||||
string myIP = Dns.GetHostByName(hostName).AddressList[1].ToString();// Get the IP
|
||||
return IPAddress.Parse(myIP);
|
||||
}
|
||||
|
||||
//поток 2
|
||||
public void StartListening()
|
||||
{
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
public event OnDataSend GetDataSend; // event
|
||||
Dictionary<Socket, Thread> managerThread;
|
||||
Thread serverTheread;
|
||||
public IPEndPoint InfoConnect => endPoint;
|
||||
public IPEndPoint InfoConnect => (IPEndPoint)socket.LocalEndPoint ?? endPoint;
|
||||
|
||||
public ServerNetworkManager() { Init(); }
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -19,7 +20,7 @@ namespace ZoFo.GameCore
|
|||
{
|
||||
private ServerNetworkManager networkManager;
|
||||
private int ticks = 0;
|
||||
public string MyIp { get { return networkManager.InfoConnect.ToString(); } }
|
||||
public IPEndPoint MyIp { get { return networkManager.InfoConnect; } }
|
||||
public Server()
|
||||
{
|
||||
networkManager = new ServerNetworkManager();
|
||||
|
|
Loading…
Add table
Reference in a new issue