0
0
mirror of https://github.com/sp-tarkov/launcher.git synced 2025-02-13 09:30:45 -05:00

119 lines
2.7 KiB
C#
Raw Normal View History

2023-03-03 19:25:33 +00:00
/* ServerManager.cs
* License: NCSA Open Source License
*
2024-05-21 20:15:19 +01:00
* Copyright: SPT
2023-03-03 19:25:33 +00:00
* AUTHORS:
*/
2024-05-21 20:15:19 +01:00
using SPT.Launcher.MiniCommon;
using SPT.Launcher.Models.SPT;
2023-08-13 11:00:10 -04:00
using System.Collections.Generic;
2023-03-03 19:25:33 +00:00
using System.Threading.Tasks;
2024-05-21 20:15:19 +01:00
namespace SPT.Launcher
2023-03-03 19:25:33 +00:00
{
public static class ServerManager
{
public static ServerInfo SelectedServer { get; private set; } = null;
public static bool PingServer()
{
string json = "";
try
{
json = RequestHandler.SendPing();
if(json != null) return true;
}
catch
{
return false;
}
return false;
}
public static string GetVersion()
{
try
{
string json = RequestHandler.RequestServerVersion();
return Json.Deserialize<string>(json);
}
catch
{
return "";
}
}
public static string GetCompatibleGameVersion()
{
try
{
string json = RequestHandler.RequestCompatibleGameVersion();
return Json.Deserialize<string>(json);
}
catch
{
return "";
}
}
2024-05-21 20:15:19 +01:00
public static Dictionary<string, SPTServerModInfo> GetLoadedServerMods()
2023-08-13 11:00:10 -04:00
{
try
{
string json = RequestHandler.RequestLoadedServerMods();
2024-05-21 20:15:19 +01:00
return Json.Deserialize<Dictionary<string, SPTServerModInfo>>(json);
2023-08-13 11:00:10 -04:00
}
catch
{
2024-05-21 20:15:19 +01:00
return new Dictionary<string, SPTServerModInfo>();
2023-08-13 11:00:10 -04:00
}
}
2024-05-21 20:15:19 +01:00
public static SPTProfileModInfo[] GetProfileMods()
2023-08-13 11:00:10 -04:00
{
try
{
string json = RequestHandler.RequestProfileMods();
2024-05-21 20:15:19 +01:00
return Json.Deserialize<SPTProfileModInfo[]>(json);
2023-08-13 11:00:10 -04:00
}
catch
{
2024-05-21 20:15:19 +01:00
return new SPTProfileModInfo[] { };
2023-08-13 11:00:10 -04:00
}
}
2023-12-05 10:00:37 -05:00
public static bool LoadServer(string backendUrl)
2023-03-03 19:25:33 +00:00
{
string json = "";
try
{
RequestHandler.ChangeBackendUrl(backendUrl);
json = RequestHandler.RequestConnect();
2023-12-05 10:00:37 -05:00
SelectedServer = Json.Deserialize<ServerInfo>(json);
2023-03-03 19:25:33 +00:00
}
catch
{
SelectedServer = null;
2023-12-05 10:00:37 -05:00
return false;
2023-03-03 19:25:33 +00:00
}
2023-12-05 10:00:37 -05:00
return true;
2023-03-03 19:25:33 +00:00
}
2023-12-05 10:00:37 -05:00
public static async Task<bool> LoadDefaultServerAsync(string server)
2023-03-03 19:25:33 +00:00
{
2023-12-05 10:00:37 -05:00
return await Task.Run(() => LoadServer(server));
2023-03-03 19:25:33 +00:00
}
}
}