We don't need a MasterServer class
This commit is contained in:
101
Server/Server.cs
101
Server/Server.cs
@ -17,17 +17,53 @@ namespace CoopServer
|
|||||||
public string Country { get; set; }
|
public string Country { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
class MasterServer
|
class Server
|
||||||
{
|
{
|
||||||
private Thread MainThread;
|
public static readonly string CurrentModVersion = Enum.GetValues(typeof(ModVersion)).Cast<ModVersion>().Last().ToString();
|
||||||
|
|
||||||
public void Start()
|
public static readonly Settings MainSettings = Util.Read<Settings>("CoopSettings.xml");
|
||||||
|
private readonly Blocklist MainBlocklist = Util.Read<Blocklist>("Blocklist.xml");
|
||||||
|
private readonly Allowlist MainAllowlist = Util.Read<Allowlist>("Allowlist.xml");
|
||||||
|
|
||||||
|
public static NetServer MainNetServer;
|
||||||
|
|
||||||
|
private static readonly Dictionary<string, EntitiesPlayer> Players = new();
|
||||||
|
|
||||||
|
public Server()
|
||||||
{
|
{
|
||||||
MainThread = new Thread(Listen);
|
// 6d4ec318f1c43bd62fe13d5a7ab28650 = GTACOOP:R
|
||||||
MainThread.Start();
|
NetPeerConfiguration config = new("6d4ec318f1c43bd62fe13d5a7ab28650")
|
||||||
|
{
|
||||||
|
MaximumConnections = MainSettings.MaxPlayers,
|
||||||
|
Port = MainSettings.ServerPort,
|
||||||
|
EnableUPnP = MainSettings.UPnP
|
||||||
|
};
|
||||||
|
|
||||||
|
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
|
||||||
|
|
||||||
|
MainNetServer = new NetServer(config);
|
||||||
|
MainNetServer.Start();
|
||||||
|
|
||||||
|
Logging.Info(string.Format("Server listening on {0}:{1}", config.LocalAddress.ToString(), config.Port));
|
||||||
|
|
||||||
|
if (MainSettings.UPnP)
|
||||||
|
{
|
||||||
|
Logging.Info(string.Format("Attempting to forward port {0}", MainSettings.ServerPort));
|
||||||
|
|
||||||
|
if (MainNetServer.UPnP.ForwardPort(MainSettings.ServerPort, "GTACOOP:R server"))
|
||||||
|
{
|
||||||
|
Logging.Info(string.Format("Server available on {0}:{1}", MainNetServer.UPnP.GetExternalIP().ToString(), config.Port));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logging.Error("Port forwarding failed!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Listen()
|
if (MainSettings.AnnounceSelf)
|
||||||
|
{
|
||||||
|
#region -- MASTERSERVER --
|
||||||
|
new Thread(async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -80,57 +116,8 @@ namespace CoopServer
|
|||||||
{
|
{
|
||||||
Logging.Error(ex.Message);
|
Logging.Error(ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}).Start();
|
||||||
}
|
#endregion
|
||||||
|
|
||||||
class Server
|
|
||||||
{
|
|
||||||
public static readonly string CurrentModVersion = Enum.GetValues(typeof(ModVersion)).Cast<ModVersion>().Last().ToString();
|
|
||||||
|
|
||||||
public static readonly Settings MainSettings = Util.Read<Settings>("CoopSettings.xml");
|
|
||||||
private readonly Blocklist MainBlocklist = Util.Read<Blocklist>("Blocklist.xml");
|
|
||||||
private readonly Allowlist MainAllowlist = Util.Read<Allowlist>("Allowlist.xml");
|
|
||||||
|
|
||||||
public static NetServer MainNetServer;
|
|
||||||
|
|
||||||
private readonly MasterServer MainMasterServer = new();
|
|
||||||
|
|
||||||
private static readonly Dictionary<string, EntitiesPlayer> Players = new();
|
|
||||||
|
|
||||||
public Server()
|
|
||||||
{
|
|
||||||
// 6d4ec318f1c43bd62fe13d5a7ab28650 = GTACOOP:R
|
|
||||||
NetPeerConfiguration config = new("6d4ec318f1c43bd62fe13d5a7ab28650")
|
|
||||||
{
|
|
||||||
MaximumConnections = MainSettings.MaxPlayers,
|
|
||||||
Port = MainSettings.ServerPort,
|
|
||||||
EnableUPnP = MainSettings.UPnP
|
|
||||||
};
|
|
||||||
|
|
||||||
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
|
|
||||||
|
|
||||||
MainNetServer = new NetServer(config);
|
|
||||||
MainNetServer.Start();
|
|
||||||
|
|
||||||
Logging.Info(string.Format("Server listening on {0}:{1}", config.LocalAddress.ToString(), config.Port));
|
|
||||||
|
|
||||||
if (MainSettings.UPnP)
|
|
||||||
{
|
|
||||||
Logging.Info(string.Format("Attempting to forward port {0}", MainSettings.ServerPort));
|
|
||||||
|
|
||||||
if (MainNetServer.UPnP.ForwardPort(MainSettings.ServerPort, "GTACOOP:R server"))
|
|
||||||
{
|
|
||||||
Logging.Info(string.Format("Server available on {0}:{1}", MainNetServer.UPnP.GetExternalIP().ToString(), config.Port));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Logging.Error("Port forwarding failed!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (MainSettings.AnnounceSelf)
|
|
||||||
{
|
|
||||||
MainMasterServer.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Listen();
|
Listen();
|
||||||
|
Reference in New Issue
Block a user