updated to be platform-agnostic
This commit is contained in:
parent
46dce9d6c7
commit
96d87bdd97
@ -1,6 +1,4 @@
|
|||||||
using System.Diagnostics;
|
namespace launcher_client;
|
||||||
|
|
||||||
namespace launcher_client;
|
|
||||||
|
|
||||||
internal static partial class Launcher
|
internal static partial class Launcher
|
||||||
{
|
{
|
||||||
|
|||||||
@ -20,7 +20,7 @@ namespace launcher_client;
|
|||||||
|
|
||||||
internal static partial class Launcher
|
internal static partial class Launcher
|
||||||
{
|
{
|
||||||
private static FileLogger _fileLogger = new("launcher-logs", "launcher_client");
|
private static FileLogger _fileLogger = new("launcher-logs", "launcher-client");
|
||||||
private static ILogger logger = new CompositeLogger(
|
private static ILogger logger = new CompositeLogger(
|
||||||
_fileLogger,
|
_fileLogger,
|
||||||
new ConsoleLogger());
|
new ConsoleLogger());
|
||||||
@ -50,7 +50,6 @@ internal static partial class Launcher
|
|||||||
? LauncherConfig.CreateDefault()
|
? LauncherConfig.CreateDefault()
|
||||||
: LauncherConfig.LoadFromFile();
|
: LauncherConfig.LoadFromFile();
|
||||||
|
|
||||||
DTLibInternalLogging.SetLogger(logger);
|
|
||||||
logger.DebugLogEnabled = debug;
|
logger.DebugLogEnabled = debug;
|
||||||
logger.LogInfo("Main", "launcher is starting");
|
logger.LogInfo("Main", "launcher is starting");
|
||||||
|
|
||||||
@ -133,9 +132,9 @@ internal static partial class Launcher
|
|||||||
FSP.DownloadByManifest("download_if_not_exist", Directory.GetCurrent());
|
FSP.DownloadByManifest("download_if_not_exist", Directory.GetCurrent());
|
||||||
FSP.DownloadByManifest("sync_always", Directory.GetCurrent(), true);
|
FSP.DownloadByManifest("sync_always", Directory.GetCurrent(), true);
|
||||||
foreach (string dir in new DtsodV23(FSP
|
foreach (string dir in new DtsodV23(FSP
|
||||||
.DownloadFileToMemory("sync_and_remove\\dirlist.dtsod")
|
.DownloadFileToMemory(Path.Concat("sync_and_remove","dirlist.dtsod"))
|
||||||
.BytesToString())["dirs"])
|
.BytesToString())["dirs"])
|
||||||
FSP.DownloadByManifest("sync_and_remove\\" + dir,
|
FSP.DownloadByManifest(Path.Concat("sync_and_remove", dir),
|
||||||
Directory.GetCurrent() + '\\' + dir, true, true);
|
Directory.GetCurrent() + '\\' + dir, true, true);
|
||||||
logger.LogInfo("Main", "client updated");
|
logger.LogInfo("Main", "client updated");
|
||||||
}
|
}
|
||||||
@ -149,7 +148,7 @@ internal static partial class Launcher
|
|||||||
config.GameWindowHeight,
|
config.GameWindowHeight,
|
||||||
Directory.GetCurrent());
|
Directory.GetCurrent());
|
||||||
logger.LogDebug("LaunchGame", gameOptions);
|
logger.LogDebug("LaunchGame", gameOptions);
|
||||||
var gameProcess = Process.Start($"{config.JavaPath}\\java.exe", gameOptions);
|
var gameProcess = Process.Start(config.JavaPath.Str, gameOptions);
|
||||||
gameProcess.WaitForExit();
|
gameProcess.WaitForExit();
|
||||||
logger.LogInfo("Main", "minecraft closed");
|
logger.LogInfo("Main", "minecraft closed");
|
||||||
}
|
}
|
||||||
@ -202,7 +201,6 @@ internal static partial class Launcher
|
|||||||
mainSocket.Close();
|
mainSocket.Close();
|
||||||
mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||||
FSP = new FSP(mainSocket);
|
FSP = new FSP(mainSocket);
|
||||||
FSP.debug = debug;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
|
|||||||
@ -5,12 +5,12 @@ namespace launcher_client;
|
|||||||
|
|
||||||
public class LauncherConfig
|
public class LauncherConfig
|
||||||
{
|
{
|
||||||
public static string ConfigFilePath = "launcher.dtsod";
|
public static IOPath ConfigFilePath = "minecraft-launcher.dtsod";
|
||||||
|
|
||||||
public int GameMemory = 3000;
|
public int GameMemory = 3000;
|
||||||
public int GameWindowHeight = 500;
|
public int GameWindowHeight = 500;
|
||||||
public int GameWindowWidth = 900;
|
public int GameWindowWidth = 900;
|
||||||
public string JavaPath = "jre\\bin";
|
public IOPath JavaPath = "jre/bin/java.exe";
|
||||||
public string ServerAddress = "127.0.0.1";
|
public string ServerAddress = "127.0.0.1";
|
||||||
public int ServerPort = 25000;
|
public int ServerPort = 25000;
|
||||||
public string Username = "";
|
public string Username = "";
|
||||||
@ -36,7 +36,7 @@ public class LauncherConfig
|
|||||||
{ "gameMemory", GameMemory },
|
{ "gameMemory", GameMemory },
|
||||||
{ "gameWindowHeight", GameWindowHeight },
|
{ "gameWindowHeight", GameWindowHeight },
|
||||||
{ "gameWindowWidth", GameWindowWidth },
|
{ "gameWindowWidth", GameWindowWidth },
|
||||||
{ "javaPath", JavaPath },
|
{ "javaPath", JavaPath.Str },
|
||||||
{ "serverAddress", ServerAddress },
|
{ "serverAddress", ServerAddress },
|
||||||
{ "serverPort", ServerPort },
|
{ "serverPort", ServerPort },
|
||||||
{ "username", Username },
|
{ "username", Username },
|
||||||
|
|||||||
@ -13,8 +13,8 @@
|
|||||||
<EmbeddedResource Include="gui\**" />
|
<EmbeddedResource Include="gui\**" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DTLib.Dtsod" Version="1.3.0" />
|
<PackageReference Include="DTLib.Dtsod" Version="1.3.1" />
|
||||||
<PackageReference Include="DTLib.Logging" Version="1.3.0" />
|
<PackageReference Include="DTLib.Logging" Version="1.3.1" />
|
||||||
<PackageReference Include="DTLib.Network" Version="1.3.0" />
|
<PackageReference Include="DTLib.Network" Version="1.3.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@ -1,8 +0,0 @@
|
|||||||
gameMemory: "3000";
|
|
||||||
gameWindowWidth: "1600";
|
|
||||||
gameWindowHeight: "1000";
|
|
||||||
javaPath: "java\bin";
|
|
||||||
serverAddress: "127.0.0.1";
|
|
||||||
serverPort: 25000;
|
|
||||||
username: "";
|
|
||||||
uuid: "";
|
|
||||||
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -15,11 +14,11 @@ namespace launcher_server;
|
|||||||
static class Server
|
static class Server
|
||||||
{
|
{
|
||||||
private static ILogger logger = new CompositeLogger(
|
private static ILogger logger = new CompositeLogger(
|
||||||
new FileLogger("logs","launcher_server"),
|
new FileLogger("logs","launcher-server"),
|
||||||
new ConsoleLogger());
|
new ConsoleLogger());
|
||||||
static readonly Socket mainSocket = new(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
static readonly Socket mainSocket = new(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||||
static DtsodV23 config = null!;
|
static DtsodV23 config = null!;
|
||||||
static bool debug;
|
private static readonly IOPath shared_dir = "public";
|
||||||
|
|
||||||
static object manifestLocker = new();
|
static object manifestLocker = new();
|
||||||
|
|
||||||
@ -30,11 +29,11 @@ static class Server
|
|||||||
Console.Title = "minecraft_launcher_server";
|
Console.Title = "minecraft_launcher_server";
|
||||||
Console.InputEncoding = Encoding.Unicode;
|
Console.InputEncoding = Encoding.Unicode;
|
||||||
Console.OutputEncoding = Encoding.Unicode;
|
Console.OutputEncoding = Encoding.Unicode;
|
||||||
DTLibInternalLogging.SetLogger(logger);
|
|
||||||
config = new DtsodV23(File.ReadAllText("launcher-server.dtsod"));
|
config = new DtsodV23(File.ReadAllText("minecraft-launcher-server.dtsod"));
|
||||||
if (args.Contains("debug")) debug = true;
|
|
||||||
logger.LogInfo("Main", $"local address: {config["local_ip"]}");
|
logger.LogInfo("Main", $"local address: {config["local_ip"]}");
|
||||||
logger.LogInfo("Main", $"public address: {OldNetwork.GetPublicIP()}");
|
logger.LogInfo("Main", $"public address: {Functions.GetPublicIP()}");
|
||||||
logger.LogInfo("Main", $"port: {config["local_port"]}");
|
logger.LogInfo("Main", $"port: {config["local_port"]}");
|
||||||
mainSocket.Bind(new IPEndPoint(IPAddress.Parse(config["local_ip"]), config["local_port"]));
|
mainSocket.Bind(new IPEndPoint(IPAddress.Parse(config["local_ip"]), config["local_port"]));
|
||||||
mainSocket.Listen(1000);
|
mainSocket.Listen(1000);
|
||||||
@ -67,7 +66,7 @@ static class Server
|
|||||||
handlerSocket.SendPackage("requesting user name");
|
handlerSocket.SendPackage("requesting user name");
|
||||||
string connectionString = handlerSocket.GetPackage().BytesToString();
|
string connectionString = handlerSocket.GetPackage().BytesToString();
|
||||||
FSP fsp = new(handlerSocket);
|
FSP fsp = new(handlerSocket);
|
||||||
FSP.debug = debug;
|
|
||||||
// запрос от апдейтера
|
// запрос от апдейтера
|
||||||
if (connectionString == "minecraft-launcher")
|
if (connectionString == "minecraft-launcher")
|
||||||
{
|
{
|
||||||
@ -83,12 +82,14 @@ static class Server
|
|||||||
{
|
{
|
||||||
case "requesting launcher update":
|
case "requesting launcher update":
|
||||||
logger.LogInfo(nameof(HandleUser), "updater requested launcher update");
|
logger.LogInfo(nameof(HandleUser), "updater requested launcher update");
|
||||||
fsp.UploadFile("share\\minecraft-launcher.exe");
|
// ReSharper disable once InconsistentlySynchronizedField
|
||||||
|
fsp.UploadFile(Path.Concat(shared_dir, "minecraft-launcher.exe"));
|
||||||
break;
|
break;
|
||||||
case "requesting file download":
|
case "requesting file download":
|
||||||
var file = handlerSocket.GetPackage().BytesToString();
|
var file = handlerSocket.GetPackage().BytesToString();
|
||||||
logger.LogInfo(nameof(HandleUser), $"updater requested file {file}");
|
logger.LogInfo(nameof(HandleUser), $"updater requested file {file}");
|
||||||
fsp.UploadFile($"share\\{file}");
|
// ReSharper disable once InconsistentlySynchronizedField
|
||||||
|
fsp.UploadFile(Path.Concat(shared_dir, file));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Exception("unknown request: " + request);
|
throw new Exception("unknown request: " + request);
|
||||||
@ -118,26 +119,23 @@ static class Server
|
|||||||
{
|
{
|
||||||
lock (manifestLocker)
|
lock (manifestLocker)
|
||||||
{
|
{
|
||||||
FSP.CreateManifest("share\\download_if_not_exist");
|
var sync_and_remove_dir = Path.Concat(shared_dir, "sync_and_remove");
|
||||||
FSP.CreateManifest("share\\sync_always");
|
FSP.CreateManifest(Path.Concat(shared_dir, "download_if_not_exist"));
|
||||||
if(!Directory.Exists("share\\sync_and_remove"))
|
FSP.CreateManifest(Path.Concat(shared_dir, "sync_always"));
|
||||||
{
|
if (!Directory.Exists(sync_and_remove_dir))
|
||||||
Directory.Create("share\\sync_and_remove");
|
Directory.Create(sync_and_remove_dir);
|
||||||
logger.LogInfo(nameof(CreateManifests), "can't create manifest, dir <share\\sync_and_remove> doesn't exist");
|
else foreach (var dir in Directory.GetDirectories(sync_and_remove_dir))
|
||||||
}
|
|
||||||
else foreach (string dir in Directory.GetDirectories("share\\sync_and_remove"))
|
|
||||||
FSP.CreateManifest(dir);
|
FSP.CreateManifest(dir);
|
||||||
if(Directory.GetDirectories("share\\sync_and_remove").Length==0)
|
string dirlist_content = "dirs: [ ];";
|
||||||
File.WriteAllText("share\\sync_and_remove\\dirlist.dtsod", "dirs: [ ];");
|
if(Directory.GetDirectories(sync_and_remove_dir).Length > 0)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
File.WriteAllText("share\\sync_and_remove\\dirlist.dtsod",
|
dirlist_content = "dirs: [\""
|
||||||
"dirs: [\""
|
+ Directory.GetDirectories(sync_and_remove_dir)
|
||||||
+ Directory.GetDirectories("share\\sync_and_remove")
|
.MergeToString("\", \"")
|
||||||
.MergeToString("\", \"")
|
.Replace(sync_and_remove_dir.Str, "")
|
||||||
.Replace("share\\sync_and_remove\\", "")
|
+ "\"];";
|
||||||
+ "\"];");
|
|
||||||
}
|
}
|
||||||
|
File.WriteAllText(Path.Concat(sync_and_remove_dir, "dirlist.dtsod"), dirlist_content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -9,13 +9,13 @@
|
|||||||
<ApplicationIcon>launcher.ico</ApplicationIcon>
|
<ApplicationIcon>launcher.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="launcher-server.dtsod">
|
<None Update="minecraft-launcher-server.dtsod">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DTLib.Dtsod" Version="1.3.0" />
|
<PackageReference Include="DTLib.Dtsod" Version="1.3.1" />
|
||||||
<PackageReference Include="DTLib.Logging" Version="1.3.0" />
|
<PackageReference Include="DTLib.Logging" Version="1.3.1" />
|
||||||
<PackageReference Include="DTLib.Network" Version="1.3.0" />
|
<PackageReference Include="DTLib.Network" Version="1.3.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@ -1,2 +1,2 @@
|
|||||||
local_ip: "127.0.0.1";
|
local_ip: "127.0.0.1";
|
||||||
local_port: 25000;
|
local_port: 25000;
|
||||||
Loading…
Reference in New Issue
Block a user