Compare commits
10 Commits
46dce9d6c7
...
6624df6bc0
| Author | SHA1 | Date | |
|---|---|---|---|
| 6624df6bc0 | |||
| 991d0d47b1 | |||
| 5660e09092 | |||
| 097a5d0aca | |||
| 1cf556c87c | |||
| cfe9dfe362 | |||
| 4f7017e486 | |||
| e9313e8f9d | |||
| f30b7e1e4d | |||
| 96d87bdd97 |
@ -1,6 +1,4 @@
|
|||||||
using System.Diagnostics;
|
namespace launcher_client;
|
||||||
|
|
||||||
namespace launcher_client;
|
|
||||||
|
|
||||||
internal static partial class Launcher
|
internal static partial class Launcher
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,33 +2,27 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Dynamic;
|
using System.Dynamic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
|
||||||
using DTLib.Console;
|
using DTLib.Console;
|
||||||
using DTLib.Dtsod;
|
|
||||||
using DTLib.Extensions;
|
using DTLib.Extensions;
|
||||||
using DTLib.Logging;
|
using DTLib.Logging;
|
||||||
using DTLib.Network;
|
using DTLib.Network;
|
||||||
using DTLib.Filesystem;
|
using DTLib.Filesystem;
|
||||||
using Directory = DTLib.Filesystem.Directory;
|
using Directory = DTLib.Filesystem.Directory;
|
||||||
using File = DTLib.Filesystem.File;
|
using File = DTLib.Filesystem.File;
|
||||||
|
using static launcher_client.Network;
|
||||||
namespace launcher_client;
|
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(
|
public static ILogger Logger = new CompositeLogger(
|
||||||
_fileLogger,
|
_fileLogger,
|
||||||
new ConsoleLogger());
|
new ConsoleLogger());
|
||||||
private static Socket mainSocket = new(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
public static LauncherConfig Config = null!;
|
||||||
public static bool debug, offline, updated;
|
public static bool debug, offline, updated;
|
||||||
private static FSP FSP = new(mainSocket);
|
|
||||||
private static dynamic tabs = new ExpandoObject();
|
private static dynamic tabs = new ExpandoObject();
|
||||||
private static LauncherConfig config = null!;
|
|
||||||
|
|
||||||
private static void Main(string[] args)
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
@ -46,13 +40,12 @@ internal static partial class Launcher
|
|||||||
#endif
|
#endif
|
||||||
if (args.Contains("offline")) offline = true;
|
if (args.Contains("offline")) offline = true;
|
||||||
if (args.Contains("updated")) updated = true;
|
if (args.Contains("updated")) updated = true;
|
||||||
config = !File.Exists(LauncherConfig.ConfigFilePath)
|
Config = !File.Exists(LauncherConfig.ConfigFilePath)
|
||||||
? 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");
|
|
||||||
|
|
||||||
if(File.Exists("minecraft-launcher.exe_old"))
|
if(File.Exists("minecraft-launcher.exe_old"))
|
||||||
File.Delete("minecraft-launcher.exe_old");
|
File.Delete("minecraft-launcher.exe_old");
|
||||||
@ -62,8 +55,8 @@ internal static partial class Launcher
|
|||||||
{
|
{
|
||||||
ConnectToLauncherServer();
|
ConnectToLauncherServer();
|
||||||
mainSocket.SendPackage("requesting launcher update");
|
mainSocket.SendPackage("requesting launcher update");
|
||||||
FSP.DownloadFile("minecraft-launcher.exe_new");
|
Fsp.DownloadFile("minecraft-launcher.exe_new");
|
||||||
logger.LogInfo("Main", "minecraft-launcher.exe_new downloaded");
|
Logger.LogInfo("Main", "minecraft-launcher.exe_new downloaded");
|
||||||
System.IO.File.Move("minecraft-launcher.exe", "minecraft-launcher.exe_old");
|
System.IO.File.Move("minecraft-launcher.exe", "minecraft-launcher.exe_old");
|
||||||
Process.Start("cmd","/c " +
|
Process.Start("cmd","/c " +
|
||||||
"move minecraft-launcher.exe_new minecraft-launcher.exe && " +
|
"move minecraft-launcher.exe_new minecraft-launcher.exe && " +
|
||||||
@ -78,10 +71,10 @@ internal static partial class Launcher
|
|||||||
tabs.Log = "";
|
tabs.Log = "";
|
||||||
tabs.Current = "";
|
tabs.Current = "";
|
||||||
string username = "";
|
string username = "";
|
||||||
if (!config.Username.IsNullOrEmpty())
|
if (!Config.Username.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
tabs.Login = tabs.Login.Remove(833, config.Username.Length).Insert(833, config.Username);
|
tabs.Login = tabs.Login.Remove(833, Config.Username.Length).Insert(833, Config.Username);
|
||||||
username = config.Username;
|
username = Config.Username;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderTab(tabs.Login);
|
RenderTab(tabs.Login);
|
||||||
@ -111,8 +104,8 @@ internal static partial class Launcher
|
|||||||
RenderTab(tabs.Login);
|
RenderTab(tabs.Login);
|
||||||
if (_username.Length < 5)
|
if (_username.Length < 5)
|
||||||
throw new Exception("username length should be > 4 and < 17");
|
throw new Exception("username length should be > 4 and < 17");
|
||||||
config.Username = _username;
|
Config.Username = _username;
|
||||||
config.Save();
|
Config.Save();
|
||||||
username = _username;
|
username = _username;
|
||||||
tabs.Login = tabs.Login.Remove(833, _username.Length).Insert(833, _username);
|
tabs.Login = tabs.Login.Remove(833, _username.Length).Insert(833, _username);
|
||||||
RenderTab(tabs.Login);
|
RenderTab(tabs.Login);
|
||||||
@ -128,30 +121,21 @@ internal static partial class Launcher
|
|||||||
if (!offline)
|
if (!offline)
|
||||||
{
|
{
|
||||||
ConnectToLauncherServer();
|
ConnectToLauncherServer();
|
||||||
//обновление файлов клиента
|
UpdateGame();
|
||||||
logger.LogInfo("Main", "updating client...");
|
|
||||||
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")
|
|
||||||
.BytesToString())["dirs"])
|
|
||||||
FSP.DownloadByManifest("sync_and_remove\\" + dir,
|
|
||||||
Directory.GetCurrent() + '\\' + dir, true, true);
|
|
||||||
logger.LogInfo("Main", "client updated");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// запуск майнкрафта
|
// запуск майнкрафта
|
||||||
logger.LogInfo("Main", "launching minecraft");
|
Logger.LogInfo("Main", "launching minecraft");
|
||||||
string gameOptions = ConstructGameLaunchArgs(config.Username,
|
string gameOptions = ConstructGameLaunchArgs(Config.Username,
|
||||||
NameUUIDFromString("OfflinePlayer:" + config.Username),
|
NameUUIDFromString("OfflinePlayer:" + Config.Username),
|
||||||
config.GameMemory,
|
Config.GameMemory,
|
||||||
config.GameWindowWidth,
|
Config.GameWindowWidth,
|
||||||
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");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.F2:
|
case ConsoleKey.F2:
|
||||||
@ -168,7 +152,7 @@ internal static partial class Launcher
|
|||||||
if (tabs.Current == tabs.Exit)
|
if (tabs.Current == tabs.Exit)
|
||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.BufferHeight = 9999;
|
// Console.BufferHeight = 9999;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -181,50 +165,16 @@ internal static partial class Launcher
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.LogError("Main", ex);
|
Logger.LogError("Main", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.LogError("Main", ex);
|
Logger.LogError("Main", ex);
|
||||||
ColoredConsole.Write("gray", "press any key to close...");
|
ColoredConsole.Write("gray", "press any key to close...");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
}
|
}
|
||||||
}
|
Console.CursorVisible = true;
|
||||||
|
|
||||||
// подключение серверу
|
|
||||||
private static void ConnectToLauncherServer()
|
|
||||||
{
|
|
||||||
if (mainSocket.Connected)
|
|
||||||
{
|
|
||||||
logger.LogInfo(nameof(ConnectToLauncherServer), "socket is connected already. disconnecting...");
|
|
||||||
mainSocket.Shutdown(SocketShutdown.Both);
|
|
||||||
mainSocket.Close();
|
|
||||||
mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
|
||||||
FSP = new FSP(mainSocket);
|
|
||||||
FSP.debug = debug;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
try
|
|
||||||
{
|
|
||||||
logger.LogInfo(nameof(ConnectToLauncherServer), $"connecting to server {config.ServerAddress}:{config.ServerPort}");
|
|
||||||
var ip = Dns.GetHostAddresses(config.ServerAddress)[0];
|
|
||||||
mainSocket.Connect(new IPEndPoint(ip, config.ServerPort));
|
|
||||||
logger.LogInfo(nameof(ConnectToLauncherServer), $"connected to server {ip}");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
catch (SocketException ex)
|
|
||||||
{
|
|
||||||
logger.LogError(nameof(ConnectToLauncherServer), ex);
|
|
||||||
Thread.Sleep(2000);
|
|
||||||
}
|
|
||||||
|
|
||||||
mainSocket.ReceiveTimeout = 2500;
|
|
||||||
mainSocket.SendTimeout = 2500;
|
|
||||||
mainSocket.GetAnswer("requesting user name");
|
|
||||||
mainSocket.SendPackage("minecraft-launcher");
|
|
||||||
mainSocket.GetAnswer("minecraft-launcher OK");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RenderTab(string tab, ushort bufferHeight = 30)
|
private static void RenderTab(string tab, ushort bufferHeight = 30)
|
||||||
@ -232,7 +182,7 @@ internal static partial class Launcher
|
|||||||
tabs.Current = tab;
|
tabs.Current = tab;
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.SetWindowSize(80, 30);
|
Console.SetWindowSize(80, 30);
|
||||||
Console.SetBufferSize(80, bufferHeight);
|
// Console.SetBufferSize(80, bufferHeight);
|
||||||
ColoredConsole.Write("w", tab);
|
ColoredConsole.Write("w", tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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 },
|
||||||
|
|||||||
91
minecraft-launcher-client/Network.cs
Normal file
91
minecraft-launcher-client/Network.cs
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Threading;
|
||||||
|
using DTLib;
|
||||||
|
using DTLib.Dtsod;
|
||||||
|
using DTLib.Extensions;
|
||||||
|
using DTLib.Filesystem;
|
||||||
|
using DTLib.Logging;
|
||||||
|
using DTLib.Network;
|
||||||
|
using static launcher_client.Launcher;
|
||||||
|
|
||||||
|
namespace launcher_client;
|
||||||
|
|
||||||
|
public class Network
|
||||||
|
{
|
||||||
|
public static Socket mainSocket = new(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||||
|
public static FSP Fsp = new(mainSocket);
|
||||||
|
|
||||||
|
// подключение серверу
|
||||||
|
public static void ConnectToLauncherServer()
|
||||||
|
{
|
||||||
|
if (mainSocket.Connected)
|
||||||
|
{
|
||||||
|
Logger.LogInfo(nameof(Network), "socket is connected already. disconnecting...");
|
||||||
|
mainSocket.Shutdown(SocketShutdown.Both);
|
||||||
|
mainSocket.Close();
|
||||||
|
mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||||
|
Fsp = new(mainSocket);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Logger.LogInfo(nameof(Network), $"connecting to server {Config.ServerAddress}:{Config.ServerPort}");
|
||||||
|
var ip = Dns.GetHostAddresses(Config.ServerAddress)[0];
|
||||||
|
mainSocket.Connect(new IPEndPoint(ip, Config.ServerPort));
|
||||||
|
Logger.LogInfo(nameof(Network), $"connected to server {ip}");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (SocketException ex)
|
||||||
|
{
|
||||||
|
Logger.LogError(nameof(Network), ex);
|
||||||
|
Thread.Sleep(2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
mainSocket.ReceiveTimeout = 2500;
|
||||||
|
mainSocket.SendTimeout = 2500;
|
||||||
|
mainSocket.GetAnswer("requesting user name");
|
||||||
|
mainSocket.SendPackage("minecraft-launcher");
|
||||||
|
mainSocket.GetAnswer("minecraft-launcher OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DownloadByManifest(IOPath dirOnServer, IOPath dirOnClient, bool overwrite = false, bool delete_excess = false)
|
||||||
|
{
|
||||||
|
var manifestPath = Path.Concat(dirOnServer, "manifest.dtsod");
|
||||||
|
Logger.LogDebug(nameof(Network), manifestPath);
|
||||||
|
string manifestContent = Fsp.DownloadFileToMemory(manifestPath).BytesToString();
|
||||||
|
var manifest = new DtsodV23(manifestContent);
|
||||||
|
var hasher = new Hasher();
|
||||||
|
foreach (var fileOnServerData in manifest)
|
||||||
|
{
|
||||||
|
IOPath fileOnClient = Path.Concat(dirOnClient, fileOnServerData.Key);
|
||||||
|
if (!File.Exists(fileOnClient) || (overwrite && hasher.HashFile(fileOnClient).HashToString() != fileOnServerData.Value))
|
||||||
|
Fsp.DownloadFile(Path.Concat(dirOnServer, fileOnServerData.Key), fileOnClient);
|
||||||
|
}
|
||||||
|
// удаление лишних файлов
|
||||||
|
if (delete_excess)
|
||||||
|
{
|
||||||
|
foreach (var file in Directory.GetAllFiles(dirOnClient))
|
||||||
|
{
|
||||||
|
if (!manifest.ContainsKey(file.RemoveBase(dirOnClient).Str.Replace('\\','/')))
|
||||||
|
File.Delete(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UpdateGame()
|
||||||
|
{
|
||||||
|
//обновление файлов клиента
|
||||||
|
Logger.LogInfo(nameof(Network), "updating client...");
|
||||||
|
DownloadByManifest("download_if_not_exist", Directory.GetCurrent());
|
||||||
|
DownloadByManifest("sync_always", Directory.GetCurrent(), true);
|
||||||
|
var dirlistDtsod = new DtsodV23(Fsp
|
||||||
|
.DownloadFileToMemory(Path.Concat("sync_and_remove","dirlist.dtsod"))
|
||||||
|
.BytesToString());
|
||||||
|
foreach (string dir in dirlistDtsod["dirs"])
|
||||||
|
DownloadByManifest(Path.Concat("sync_and_remove", dir),
|
||||||
|
Path.Concat(Directory.GetCurrent(), dir), true, true);
|
||||||
|
Logger.LogInfo(nameof(Network), "client updated");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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.3" />
|
||||||
</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: "";
|
|
||||||
2
minecraft-launcher-client/publish.sh
Normal file → Executable file
2
minecraft-launcher-client/publish.sh
Normal file → Executable file
@ -1,6 +1,6 @@
|
|||||||
dotnet publish -c release -o bin/publish \
|
dotnet publish -c release -o bin/publish \
|
||||||
--self-contained \
|
--self-contained \
|
||||||
-r win-x64 \
|
--use-current-runtime \
|
||||||
-p:PublishSingleFile=true \
|
-p:PublishSingleFile=true \
|
||||||
-p:PublishTrimmed=true \
|
-p:PublishTrimmed=true \
|
||||||
-p:TrimMode=partial \
|
-p:TrimMode=partial \
|
||||||
|
|||||||
69
minecraft-launcher-server/Manifests.cs
Normal file
69
minecraft-launcher-server/Manifests.cs
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using DTLib;
|
||||||
|
using DTLib.Extensions;
|
||||||
|
using DTLib.Filesystem;
|
||||||
|
using static launcher_server.Server;
|
||||||
|
|
||||||
|
namespace launcher_server;
|
||||||
|
|
||||||
|
public static class Manifests
|
||||||
|
{
|
||||||
|
static object manifestLocker = new();
|
||||||
|
|
||||||
|
public static void CreateManifest(IOPath dir)
|
||||||
|
{
|
||||||
|
if(!Directory.Exists(dir))
|
||||||
|
{
|
||||||
|
Directory.Create(dir);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder manifestBuilder = new();
|
||||||
|
Hasher hasher = new();
|
||||||
|
var manifestPath = Path.Concat(dir, "manifest.dtsod");
|
||||||
|
if (Directory.GetFiles(dir).Contains(manifestPath))
|
||||||
|
File.Delete(manifestPath);
|
||||||
|
foreach (var fileInDir in Directory.GetAllFiles(dir))
|
||||||
|
{
|
||||||
|
var fileRelative = fileInDir.RemoveBase(dir);
|
||||||
|
manifestBuilder.Append(fileRelative);
|
||||||
|
manifestBuilder.Append(": \"");
|
||||||
|
byte[] hash = hasher.HashFile(Path.Concat(fileInDir));
|
||||||
|
manifestBuilder.Append(hash.HashToString());
|
||||||
|
manifestBuilder.Append("\";\n");
|
||||||
|
}
|
||||||
|
File.WriteAllText(manifestPath, manifestBuilder.ToString().Replace('\\','/'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void CreateAllManifests()
|
||||||
|
{
|
||||||
|
lock (manifestLocker)
|
||||||
|
{
|
||||||
|
var sync_and_remove_dir = Path.Concat(shared_dir, "sync_and_remove");
|
||||||
|
CreateManifest(Path.Concat(shared_dir, "download_if_not_exist"));
|
||||||
|
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))
|
||||||
|
CreateManifest(dir);
|
||||||
|
StringBuilder dirlist_content_builder = new("dirs: [\n");
|
||||||
|
|
||||||
|
var dirs = Directory.GetDirectories(sync_and_remove_dir);
|
||||||
|
for (var i = 0; i < dirs.Length-1; i++)
|
||||||
|
{
|
||||||
|
dirlist_content_builder
|
||||||
|
.Append("\t\"")
|
||||||
|
.Append(dirs[i].RemoveBase(sync_and_remove_dir).Str.Replace('\\','/'))
|
||||||
|
.Append("\",\n");
|
||||||
|
}
|
||||||
|
dirlist_content_builder
|
||||||
|
.Append("\t\"")
|
||||||
|
.Append(dirs[dirs.Length-1].RemoveBase(sync_and_remove_dir).Str.Replace('\\','/'))
|
||||||
|
.Append("\"\n");
|
||||||
|
|
||||||
|
dirlist_content_builder.Append("];");
|
||||||
|
File.WriteAllText(Path.Concat(sync_and_remove_dir, "dirlist.dtsod"), dirlist_content_builder.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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,13 +14,12 @@ 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;
|
public static readonly IOPath shared_dir = "public";
|
||||||
|
|
||||||
static object manifestLocker = new();
|
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
@ -30,15 +28,15 @@ 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);
|
||||||
CreateManifests();
|
Manifests.CreateAllManifests();
|
||||||
logger.LogInfo("Main", "server started succesfully");
|
logger.LogInfo("Main", "server started succesfully");
|
||||||
// запуск отдельного потока для каждого юзера
|
// запуск отдельного потока для каждого юзера
|
||||||
logger.LogInfo("Main", "waiting for users");
|
logger.LogInfo("Main", "waiting for users");
|
||||||
@ -67,7 +65,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 +81,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);
|
||||||
@ -114,30 +114,5 @@ static class Server
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CreateManifests()
|
|
||||||
{
|
|
||||||
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"))
|
|
||||||
FSP.CreateManifest(dir);
|
|
||||||
if(Directory.GetDirectories("share\\sync_and_remove").Length==0)
|
|
||||||
File.WriteAllText("share\\sync_and_remove\\dirlist.dtsod", "dirs: [ ];");
|
|
||||||
else
|
|
||||||
{
|
|
||||||
File.WriteAllText("share\\sync_and_remove\\dirlist.dtsod",
|
|
||||||
"dirs: [\""
|
|
||||||
+ Directory.GetDirectories("share\\sync_and_remove")
|
|
||||||
.MergeToString("\", \"")
|
|
||||||
.Replace("share\\sync_and_remove\\", "")
|
|
||||||
+ "\"];");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -9,13 +9,8 @@
|
|||||||
<ApplicationIcon>launcher.ico</ApplicationIcon>
|
<ApplicationIcon>launcher.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="launcher-server.dtsod">
|
<PackageReference Include="DTLib.Dtsod" Version="1.3.1" />
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<PackageReference Include="DTLib.Logging" Version="1.3.1" />
|
||||||
</None>
|
<PackageReference Include="DTLib.Network" Version="1.3.3" />
|
||||||
</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" />
|
|
||||||
</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;
|
||||||
11
minecraft-launcher-server/minecraft-launcher-server.service
Normal file
11
minecraft-launcher-server/minecraft-launcher-server.service
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# put this file in /etc/systemd/system/
|
||||||
|
[Unit]
|
||||||
|
Description=minecraft launcher backend in c#
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
WorkingDirectory=/opt/minecraft-launcher/minecraft-launcher-server/bin/publish
|
||||||
|
ExecStart=/opt/minecraft-launcher/minecraft-launcher-server/bin/publish/minecraft-launcher-server
|
||||||
|
Restart=always
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
10
minecraft-launcher-server/publish.sh
Executable file
10
minecraft-launcher-server/publish.sh
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
dotnet publish -c release -o bin/publish \
|
||||||
|
--self-contained \
|
||||||
|
--use-current-runtime \
|
||||||
|
-p:PublishSingleFile=true \
|
||||||
|
-p:PublishTrimmed=true \
|
||||||
|
-p:TrimMode=partial \
|
||||||
|
-p:EnableCompressionInSingleFile=true \
|
||||||
|
-p:OptimizationPreference=Size \
|
||||||
|
-p:InvariantGlobalization=true \
|
||||||
|
-p:DebugType=none
|
||||||
Loading…
Reference in New Issue
Block a user