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