server CheckUpdates
This commit is contained in:
parent
369befe7f8
commit
88387461c9
7
.github/workflows/build_all.yml
vendored
7
.github/workflows/build_all.yml
vendored
@ -28,7 +28,7 @@ jobs:
|
|||||||
path: minecraft-launcher-server/bin/publish/
|
path: minecraft-launcher-server/bin/publish/
|
||||||
|
|
||||||
build-client:
|
build-client:
|
||||||
runs-on: windows-2019
|
runs-on: windows-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
@ -54,7 +54,8 @@ jobs:
|
|||||||
- name: Download artifacts
|
- name: Download artifacts
|
||||||
uses: actions/download-artifact@v3
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: minecraft-launcher-client
|
name: minecraft-launcher-client
|
||||||
|
path: public
|
||||||
- uses: actions/download-artifact@v3
|
- uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: minecraft-launcher-server
|
name: minecraft-launcher-server
|
||||||
@ -70,4 +71,4 @@ jobs:
|
|||||||
- name: Upload files
|
- name: Upload files
|
||||||
env:
|
env:
|
||||||
SSHPASS: ${{secrets.SSH_PASSWORD}}
|
SSHPASS: ${{secrets.SSH_PASSWORD}}
|
||||||
run: sshpass -e rsync --archive --compress --verbose --stats -e ssh . ${{secrets.SSH_DESTINATION}} 2>&1 | grep -v debug1
|
run: sshpass -e rsync --archive --compress --verbose --stats --mkpath -e ssh . ${{secrets.SSH_DESTINATION}} 2>&1 | grep -v debug1
|
||||||
|
|||||||
@ -10,6 +10,8 @@ global using DTLib.Extensions;
|
|||||||
global using DTLib.Filesystem;
|
global using DTLib.Filesystem;
|
||||||
global using DTLib.Logging;
|
global using DTLib.Logging;
|
||||||
global using DTLib.Network;
|
global using DTLib.Network;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using DTLib.Ben.Demystifier;
|
||||||
using Timer = DTLib.Timer;
|
using Timer = DTLib.Timer;
|
||||||
|
|
||||||
namespace launcher_server;
|
namespace launcher_server;
|
||||||
@ -26,7 +28,7 @@ static class Server
|
|||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Timer? manifestsUpdateTimer = null;
|
Timer? updateCheckTimer = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Console.Title = "minecraft_launcher_server";
|
Console.Title = "minecraft_launcher_server";
|
||||||
@ -35,14 +37,17 @@ static class Server
|
|||||||
|
|
||||||
Config = ServerConfig.LoadOrCreateDefault();
|
Config = ServerConfig.LoadOrCreateDefault();
|
||||||
|
|
||||||
|
CheckUpdates();
|
||||||
|
updateCheckTimer = new Timer(true, 5 * 60 * 1000, CheckUpdates);
|
||||||
|
updateCheckTimer.Start();
|
||||||
|
|
||||||
|
|
||||||
logger.LogInfo("Main", $"local address: {Config.LocalIp}");
|
logger.LogInfo("Main", $"local address: {Config.LocalIp}");
|
||||||
logger.LogInfo("Main", $"public address: {Functions.GetPublicIP()}");
|
logger.LogInfo("Main", $"public address: {Functions.GetPublicIP()}");
|
||||||
logger.LogInfo("Main", $"port: {Config.LocalPort}");
|
logger.LogInfo("Main", $"port: {Config.LocalPort}");
|
||||||
mainSocket.Bind(new IPEndPoint(IPAddress.Parse(Config.LocalIp), Config.LocalPort));
|
mainSocket.Bind(new IPEndPoint(IPAddress.Parse(Config.LocalIp), Config.LocalPort));
|
||||||
mainSocket.Listen(1000);
|
mainSocket.Listen(1000);
|
||||||
Manifests.CreateAllManifests();
|
|
||||||
manifestsUpdateTimer = new Timer(true, 5 * 60 * 1000, Manifests.CreateAllManifests);
|
|
||||||
manifestsUpdateTimer.Start();
|
|
||||||
logger.LogInfo("Main", "server started succesfully");
|
logger.LogInfo("Main", "server started succesfully");
|
||||||
// запуск отдельного потока для каждого юзера
|
// запуск отдельного потока для каждого юзера
|
||||||
logger.LogInfo("Main", "waiting for users");
|
logger.LogInfo("Main", "waiting for users");
|
||||||
@ -58,10 +63,41 @@ static class Server
|
|||||||
logger.LogError("Main", ex);
|
logger.LogError("Main", ex);
|
||||||
mainSocket.Close();
|
mainSocket.Close();
|
||||||
}
|
}
|
||||||
manifestsUpdateTimer?.Stop();
|
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void CheckUpdates()
|
||||||
|
{
|
||||||
|
IOPath updatesDir = "updates";
|
||||||
|
Directory.Create(updatesDir);
|
||||||
|
var updatedFiles = Directory.GetAllFiles(updatesDir);
|
||||||
|
foreach (var updatedFilePath in updatedFiles)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var relativeFilePath = updatedFilePath.RemoveBase(updatesDir);
|
||||||
|
if (relativeFilePath.Str is "minecraft-launcher-server" or "minecraft-launcher-server.exe")
|
||||||
|
{
|
||||||
|
logger.LogWarn(nameof(CheckUpdates), "program update found, restarting...");
|
||||||
|
string exeFile = relativeFilePath.Str;
|
||||||
|
string exeFileNew = exeFile + "_new";
|
||||||
|
File.Move(relativeFilePath, exeFileNew, true);
|
||||||
|
if(Environment.OSVersion.Platform == PlatformID.Win32NT)
|
||||||
|
Process.Start("cmd",$"/c move {exeFileNew} {exeFile} && {exeFile}");
|
||||||
|
else Process.Start("bash",$"-c 'mv {exeFileNew} {exeFile}'");
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
else File.Move(updatedFilePath, relativeFilePath, true);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.LogError(nameof(CheckUpdates), $"failed update of file '{updatedFilePath}'\n"
|
||||||
|
+ e.ToStringDemystified());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Manifests.CreateAllManifests();
|
||||||
|
}
|
||||||
|
|
||||||
// запускается для каждого юзера в отдельном потоке
|
// запускается для каждого юзера в отдельном потоке
|
||||||
static void HandleUser(Socket handlerSocket)
|
static void HandleUser(Socket handlerSocket)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user