mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-24 21:46:52 +01:00
Merge pull request #177 from Cyberboss/FixUnres
Fixes update errors on server page
This commit is contained in:
+502
-497
@@ -1,497 +1,502 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
using TGServiceInterface;
|
||||
|
||||
namespace TGControlPanel
|
||||
{
|
||||
partial class Main
|
||||
{
|
||||
enum FullUpdateAction
|
||||
{
|
||||
UpdateHard,
|
||||
UpdateMerge,
|
||||
UpdateHardTestmerge,
|
||||
Reset,
|
||||
Testmerge,
|
||||
}
|
||||
|
||||
FullUpdateAction fuAction;
|
||||
ushort testmergePR;
|
||||
string updateError;
|
||||
bool updatingFields = false;
|
||||
|
||||
string DDStatusString = null;
|
||||
void InitServerPage()
|
||||
{
|
||||
LoadServerPage();
|
||||
ServerTimer.Start();
|
||||
WorldStatusChecker.RunWorkerAsync();
|
||||
WorldStatusChecker.RunWorkerCompleted += WorldStatusChecker_RunWorkerCompleted;
|
||||
FullUpdateWorker.RunWorkerCompleted += FullUpdateWorker_RunWorkerCompleted;
|
||||
ServerPathTextbox.LostFocus += ServerPathTextbox_LostFocus;
|
||||
ServerPathTextbox.KeyDown += ServerPathTextbox_KeyDown;
|
||||
projectNameText.LostFocus += ProjectNameText_LostFocus;
|
||||
projectNameText.KeyDown += ProjectNameText_KeyDown;
|
||||
ServerStartBGW.RunWorkerCompleted += ServerStartBGW_RunWorkerCompleted;
|
||||
}
|
||||
|
||||
private void ServerStartBGW_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
||||
{
|
||||
if (e.Result != null)
|
||||
MessageBox.Show((string)e.Result);
|
||||
}
|
||||
|
||||
private void ProjectNameText_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode == Keys.Enter)
|
||||
UpdateProjectName();
|
||||
}
|
||||
|
||||
private void ServerPathTextbox_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode == Keys.Enter)
|
||||
UpdateServerPath();
|
||||
}
|
||||
|
||||
private void FullUpdateWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
||||
{
|
||||
if (updateError != null)
|
||||
MessageBox.Show(updateError);
|
||||
UpdateHardButton.Enabled = true;
|
||||
UpdateMergeButton.Enabled = true;
|
||||
TestmergeButton.Enabled = true;
|
||||
UpdateTestmergeButton.Enabled = true;
|
||||
LoadServerPage();
|
||||
ServerTimer.Start();
|
||||
}
|
||||
|
||||
private void WorldStatusChecker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
||||
{
|
||||
if (DDStatusString != "Topic recieve error!" || ServerStatusLabel.Text == "OFFLINE")
|
||||
ServerStatusLabel.Text = DDStatusString;
|
||||
WorldStatusTimer.Start();
|
||||
}
|
||||
|
||||
private void CompileCancelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var res = Server.GetComponent<ITGCompiler>().Cancel();
|
||||
if (res != null)
|
||||
MessageBox.Show(res);
|
||||
LoadServerPage();
|
||||
}
|
||||
|
||||
private void ServerPathTextbox_LostFocus(object sender, EventArgs e)
|
||||
{
|
||||
UpdateServerPath();
|
||||
}
|
||||
|
||||
void UpdateServerPath()
|
||||
{
|
||||
var Config = Server.GetComponent<ITGConfig>();
|
||||
if (updatingFields || ServerPathTextbox.Text.Trim() == Config.ServerDirectory())
|
||||
return;
|
||||
var DialogResult = MessageBox.Show("This will move the entire server installation.", "Confim", MessageBoxButtons.YesNo);
|
||||
if (DialogResult != DialogResult.Yes)
|
||||
return;
|
||||
MessageBox.Show(Config.MoveServer(ServerPathTextbox.Text) ?? "Success!");
|
||||
}
|
||||
|
||||
void LoadServerPage()
|
||||
{
|
||||
var RepoExists = Server.GetComponent<ITGRepository>().Exists();
|
||||
compileButton.Visible = RepoExists;
|
||||
initializeButton.Visible = RepoExists;
|
||||
NudgePortSelector.Visible = RepoExists;
|
||||
AutostartCheckbox.Visible = RepoExists;
|
||||
WebclientCheckBox.Visible = RepoExists;
|
||||
PortSelector.Visible = RepoExists;
|
||||
projectNameText.Visible = RepoExists;
|
||||
compilerProgressBar.Visible = RepoExists;
|
||||
CompilerStatusLabel.Visible = RepoExists;
|
||||
CompileCancelButton.Visible = RepoExists;
|
||||
NudgePortLabel.Visible = RepoExists;
|
||||
CompilerLabel.Visible = RepoExists;
|
||||
ProjectPathLabel.Visible = RepoExists;
|
||||
ServerPRLabel.Visible = RepoExists;
|
||||
ServerGStopButton.Visible = RepoExists;
|
||||
ServerStartButton.Visible = RepoExists;
|
||||
ServerGRestartButton.Visible = RepoExists;
|
||||
ServerRestartButton.Visible = RepoExists;
|
||||
PortLabel.Visible = RepoExists;
|
||||
ServerStopButton.Visible = RepoExists;
|
||||
TestmergeButton.Visible = RepoExists;
|
||||
ServerTestmergeInput.Visible = RepoExists;
|
||||
UpdateHardButton.Visible = RepoExists;
|
||||
UpdateMergeButton.Visible = RepoExists;
|
||||
UpdateTestmergeButton.Visible = RepoExists;
|
||||
ResetTestmerge.Visible = RepoExists;
|
||||
WorldAnnounceField.Visible = RepoExists;
|
||||
WorldAnnounceButton.Visible = RepoExists;
|
||||
|
||||
var DM = Server.GetComponent<ITGCompiler>();
|
||||
var DD = Server.GetComponent<ITGDreamDaemon>();
|
||||
var Config = Server.GetComponent<ITGConfig>();
|
||||
|
||||
if (updatingFields)
|
||||
return;
|
||||
|
||||
updatingFields = true;
|
||||
|
||||
if (!ServerPathTextbox.Focused)
|
||||
ServerPathTextbox.Text = Config.ServerDirectory();
|
||||
|
||||
SecuritySelector.SelectedIndex = (int)DD.SecurityLevel();
|
||||
|
||||
if (!RepoExists)
|
||||
{
|
||||
updatingFields = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var Online = DD.DaemonStatus() == TGDreamDaemonStatus.Online;
|
||||
ServerGStopButton.Enabled = Online;
|
||||
ServerGRestartButton.Enabled = Online;
|
||||
|
||||
var ShuttingDown = DD.ShutdownInProgress();
|
||||
ServerGStopButton.Checked = ShuttingDown;
|
||||
ServerGStopButton.Enabled = !ShuttingDown;
|
||||
|
||||
AutostartCheckbox.Checked = DD.Autostart();
|
||||
WebclientCheckBox.Checked = DD.Webclient();
|
||||
if (!PortSelector.Focused)
|
||||
PortSelector.Value = DD.Port();
|
||||
if (!projectNameText.Focused)
|
||||
projectNameText.Text = DM.ProjectName();
|
||||
|
||||
var val = Config.InteropPort(out string error);
|
||||
if (error != null)
|
||||
{
|
||||
updatingFields = false;
|
||||
NudgePortSelector.Value = 4567;
|
||||
MessageBox.Show("Error (I will try and recover): " + error);
|
||||
}
|
||||
else
|
||||
{
|
||||
updatingFields = false;
|
||||
NudgePortSelector.Value = val;
|
||||
}
|
||||
|
||||
switch (DM.GetStatus())
|
||||
{
|
||||
case TGCompilerStatus.Compiling:
|
||||
CompilerStatusLabel.Text = "Compiling...";
|
||||
compilerProgressBar.Style = ProgressBarStyle.Marquee;
|
||||
compileButton.Enabled = false;
|
||||
initializeButton.Enabled = false;
|
||||
CompileCancelButton.Enabled = true;
|
||||
break;
|
||||
case TGCompilerStatus.Initializing:
|
||||
CompilerStatusLabel.Text = "Initializing...";
|
||||
compilerProgressBar.Style = ProgressBarStyle.Marquee;
|
||||
compileButton.Enabled = false;
|
||||
initializeButton.Enabled = false;
|
||||
CompileCancelButton.Enabled = false;
|
||||
break;
|
||||
case TGCompilerStatus.Initialized:
|
||||
CompilerStatusLabel.Text = "Idle";
|
||||
compilerProgressBar.Style = ProgressBarStyle.Blocks;
|
||||
initializeButton.Enabled = true;
|
||||
compileButton.Enabled = true;
|
||||
CompileCancelButton.Enabled = false;
|
||||
break;
|
||||
case TGCompilerStatus.Uninitialized:
|
||||
CompilerStatusLabel.Text = "Uninitialized";
|
||||
compilerProgressBar.Style = ProgressBarStyle.Blocks;
|
||||
compileButton.Enabled = false;
|
||||
initializeButton.Enabled = true;
|
||||
CompileCancelButton.Enabled = false;
|
||||
break;
|
||||
default:
|
||||
CompilerStatusLabel.Text = "Unknown!";
|
||||
compilerProgressBar.Style = ProgressBarStyle.Blocks;
|
||||
initializeButton.Enabled = true;
|
||||
compileButton.Enabled = true;
|
||||
CompileCancelButton.Enabled = true;
|
||||
break;
|
||||
}
|
||||
error = DM.CompileError();
|
||||
if (error != null)
|
||||
MessageBox.Show("Error: " + error);
|
||||
}
|
||||
|
||||
private void ServerTimer_Tick(object sender, System.EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
LoadServerPage();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ServerTimer.Stop();
|
||||
Program.ServiceDisconnectException(ex);
|
||||
}
|
||||
}
|
||||
private void ProjectNameText_LostFocus(object sender, EventArgs e)
|
||||
{
|
||||
UpdateProjectName();
|
||||
}
|
||||
|
||||
void UpdateProjectName()
|
||||
{
|
||||
if (!updatingFields)
|
||||
Server.GetComponent<ITGCompiler>().SetProjectName(projectNameText.Text);
|
||||
}
|
||||
|
||||
private void PortSelector_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!updatingFields)
|
||||
Server.GetComponent<ITGDreamDaemon>().SetPort((ushort)PortSelector.Value);
|
||||
}
|
||||
|
||||
private void RunServerUpdate(FullUpdateAction fua, ushort tm = 0)
|
||||
{
|
||||
if (FullUpdateWorker.IsBusy)
|
||||
return;
|
||||
testmergePR = tm;
|
||||
fuAction = fua;
|
||||
initializeButton.Enabled = false;
|
||||
compileButton.Enabled = false;
|
||||
UpdateHardButton.Enabled = false;
|
||||
UpdateMergeButton.Enabled = false;
|
||||
TestmergeButton.Enabled = false;
|
||||
UpdateTestmergeButton.Enabled = false;
|
||||
compilerProgressBar.Style = ProgressBarStyle.Marquee;
|
||||
switch (fuAction)
|
||||
{
|
||||
case FullUpdateAction.Testmerge:
|
||||
CompilerStatusLabel.Text = String.Format("Testmerging pull request #{0}...", testmergePR);
|
||||
break;
|
||||
case FullUpdateAction.UpdateHard:
|
||||
CompilerStatusLabel.Text = String.Format("Updating Server (RESET)...");
|
||||
break;
|
||||
case FullUpdateAction.UpdateMerge:
|
||||
CompilerStatusLabel.Text = String.Format("Updating Server (MERGE)...");
|
||||
break;
|
||||
case FullUpdateAction.UpdateHardTestmerge:
|
||||
CompilerStatusLabel.Text = String.Format("Updating and testmerging pull request #{0}...", testmergePR);
|
||||
break;
|
||||
}
|
||||
ServerTimer.Stop();
|
||||
FullUpdateWorker.RunWorkerAsync();
|
||||
}
|
||||
|
||||
private void InitializeButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!Server.GetComponent<ITGCompiler>().Initialize())
|
||||
MessageBox.Show("Unable to start initialization!");
|
||||
LoadServerPage();
|
||||
}
|
||||
private void CompileButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!Server.GetComponent<ITGCompiler>().Compile())
|
||||
MessageBox.Show("Unable to start compilation!");
|
||||
LoadServerPage();
|
||||
}
|
||||
//because of lol byond this can take some time...
|
||||
private void WorldStatusChecker_DoWork(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Server.GetComponent<ITGRepository>().Exists())
|
||||
DDStatusString = "NOT INSTALLED";
|
||||
else
|
||||
DDStatusString = Server.GetComponent<ITGDreamDaemon>().StatusString(true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
DDStatusString = "ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
private void WorldStatusTimer_Tick(object sender, System.EventArgs e)
|
||||
{
|
||||
WorldStatusTimer.Stop();
|
||||
WorldStatusChecker.RunWorkerAsync();
|
||||
}
|
||||
|
||||
private void AutostartCheckbox_CheckedChanged(object sender, System.EventArgs e)
|
||||
{
|
||||
if (!updatingFields)
|
||||
Server.GetComponent<ITGDreamDaemon>().SetAutostart(AutostartCheckbox.Checked);
|
||||
}
|
||||
private void ServerStartButton_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
if (!ServerStartBGW.IsBusy)
|
||||
ServerStartBGW.RunWorkerAsync();
|
||||
}
|
||||
|
||||
private void ServerStartBGW_DoWork(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
e.Result = Server.GetComponent<ITGDreamDaemon>().Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
e.Result = ex.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private void ServerStopButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var DialogResult = MessageBox.Show("This will immediately shut down the server. Continue?", "Confim", MessageBoxButtons.YesNo);
|
||||
if (DialogResult == DialogResult.No)
|
||||
return;
|
||||
var res = Server.GetComponent<ITGDreamDaemon>().Stop();
|
||||
if (res != null)
|
||||
MessageBox.Show(res);
|
||||
}
|
||||
|
||||
private void ServerRestartButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var DialogResult = MessageBox.Show("This will immediately restart the server. Continue?", "Confim", MessageBoxButtons.YesNo);
|
||||
if (DialogResult == DialogResult.No)
|
||||
return;
|
||||
var res = Server.GetComponent<ITGDreamDaemon>().Restart();
|
||||
if (res != null)
|
||||
MessageBox.Show(res);
|
||||
}
|
||||
|
||||
private void ServerGStopButton_Checked(object sender, EventArgs e)
|
||||
{
|
||||
if (updatingFields)
|
||||
return;
|
||||
var DialogResult = MessageBox.Show("This will shut down the server when the current round ends. Continue?", "Confim", MessageBoxButtons.YesNo);
|
||||
if (DialogResult == DialogResult.No)
|
||||
return;
|
||||
Server.GetComponent<ITGDreamDaemon>().RequestStop();
|
||||
LoadServerPage();
|
||||
}
|
||||
|
||||
private void ServerGRestartButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var DialogResult = MessageBox.Show("This will restart the server when the current round ends. Continue?", "Confim", MessageBoxButtons.YesNo);
|
||||
if (DialogResult == DialogResult.No)
|
||||
return;
|
||||
Server.GetComponent<ITGDreamDaemon>().RequestRestart();
|
||||
}
|
||||
|
||||
|
||||
private void FullUpdateWorker_DoWork(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
var Repo = Server.GetComponent<ITGRepository>();
|
||||
var DM = Server.GetComponent<ITGCompiler>();
|
||||
switch (fuAction)
|
||||
{
|
||||
case FullUpdateAction.Testmerge:
|
||||
updateError = Repo.MergePullRequest(testmergePR);
|
||||
if (updateError == null)
|
||||
{
|
||||
Repo.GenerateChangelog(out updateError);
|
||||
updateError = DM.Compile(true) ? updateError : "Compilation failed!";
|
||||
}
|
||||
break;
|
||||
case FullUpdateAction.UpdateHard:
|
||||
updateError = Repo.Update(true);
|
||||
if (updateError == null)
|
||||
{
|
||||
Repo.GenerateChangelog(out updateError);
|
||||
if(updateError == null)
|
||||
updateError = Repo.PushChangelog();
|
||||
updateError = DM.Compile(true) ? updateError : "Compilation failed!";
|
||||
}
|
||||
break;
|
||||
case FullUpdateAction.UpdateHardTestmerge:
|
||||
updateError = Repo.Update(true);
|
||||
if (updateError == null)
|
||||
{
|
||||
Repo.GenerateChangelog(out updateError);
|
||||
if (updateError == null)
|
||||
updateError = Repo.PushChangelog();
|
||||
updateError = Repo.MergePullRequest(testmergePR);
|
||||
if (updateError == null)
|
||||
{
|
||||
Repo.GenerateChangelog(out updateError);
|
||||
updateError = DM.Compile(true) ? updateError : "Compilation failed!";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FullUpdateAction.UpdateMerge:
|
||||
updateError = Repo.Update(false);
|
||||
if (updateError == null)
|
||||
{
|
||||
Repo.GenerateChangelog(out updateError);
|
||||
if (updateError == null)
|
||||
Repo.PushChangelog(); //not an error 99% of the time if this fails, just a dirty tree
|
||||
updateError = DM.Compile(true) ? updateError : "Compilation failed!";
|
||||
}
|
||||
break;
|
||||
case FullUpdateAction.Reset:
|
||||
updateError = Repo.Reset(true);
|
||||
if (updateError == null)
|
||||
{
|
||||
Repo.GenerateChangelog(out updateError);
|
||||
updateError = DM.Compile(true) ? updateError : "Compilation failed!";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void ResetTestmerge_Click(object sender, EventArgs e)
|
||||
{
|
||||
RunServerUpdate(FullUpdateAction.Reset);
|
||||
}
|
||||
|
||||
private void UpdateHardButton_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
RunServerUpdate(FullUpdateAction.UpdateHard);
|
||||
}
|
||||
|
||||
private void UpdateTestmergeButton_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
RunServerUpdate(FullUpdateAction.UpdateHardTestmerge, (ushort)ServerTestmergeInput.Value);
|
||||
}
|
||||
|
||||
private void UpdateMergeButton_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
RunServerUpdate(FullUpdateAction.UpdateMerge);
|
||||
}
|
||||
private void TestmergeButton_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
RunServerUpdate(FullUpdateAction.Testmerge, (ushort)ServerTestmergeInput.Value);
|
||||
}
|
||||
|
||||
private void NudgePortSelector_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!updatingFields)
|
||||
Server.GetComponent<ITGConfig>().SetInteropPort((ushort)NudgePortSelector.Value);
|
||||
}
|
||||
|
||||
private void SecuritySelector_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!updatingFields)
|
||||
if (!Server.GetComponent<ITGDreamDaemon>().SetSecurityLevel((TGDreamDaemonSecurity)SecuritySelector.SelectedIndex))
|
||||
MessageBox.Show("Security change will be applied after next server reboot.");
|
||||
}
|
||||
|
||||
private void WorldAnnounceButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var msg = WorldAnnounceField.Text;
|
||||
if (!String.IsNullOrWhiteSpace(msg)) {
|
||||
var res = Server.GetComponent<ITGDreamDaemon>().WorldAnnounce(msg);
|
||||
if(res != null)
|
||||
{
|
||||
MessageBox.Show(res);
|
||||
return;
|
||||
}
|
||||
}
|
||||
WorldAnnounceField.Text = "";
|
||||
}
|
||||
|
||||
private void WebclientCheckBox_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!updatingFields)
|
||||
Server.GetComponent<ITGDreamDaemon>().SetWebclient(WebclientCheckBox.Checked);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
using TGServiceInterface;
|
||||
|
||||
namespace TGControlPanel
|
||||
{
|
||||
partial class Main
|
||||
{
|
||||
enum FullUpdateAction
|
||||
{
|
||||
UpdateHard,
|
||||
UpdateMerge,
|
||||
UpdateHardTestmerge,
|
||||
Reset,
|
||||
Testmerge,
|
||||
}
|
||||
|
||||
FullUpdateAction fuAction;
|
||||
ushort testmergePR;
|
||||
string updateError;
|
||||
bool updatingFields = false;
|
||||
|
||||
string DDStatusString = null;
|
||||
void InitServerPage()
|
||||
{
|
||||
LoadServerPage();
|
||||
ServerTimer.Start();
|
||||
WorldStatusChecker.RunWorkerAsync();
|
||||
WorldStatusChecker.RunWorkerCompleted += WorldStatusChecker_RunWorkerCompleted;
|
||||
FullUpdateWorker.RunWorkerCompleted += FullUpdateWorker_RunWorkerCompleted;
|
||||
ServerPathTextbox.LostFocus += ServerPathTextbox_LostFocus;
|
||||
ServerPathTextbox.KeyDown += ServerPathTextbox_KeyDown;
|
||||
projectNameText.LostFocus += ProjectNameText_LostFocus;
|
||||
projectNameText.KeyDown += ProjectNameText_KeyDown;
|
||||
ServerStartBGW.RunWorkerCompleted += ServerStartBGW_RunWorkerCompleted;
|
||||
}
|
||||
|
||||
private void ServerStartBGW_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
||||
{
|
||||
if (e.Result != null)
|
||||
MessageBox.Show((string)e.Result);
|
||||
}
|
||||
|
||||
private void ProjectNameText_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode == Keys.Enter)
|
||||
UpdateProjectName();
|
||||
}
|
||||
|
||||
private void ServerPathTextbox_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode == Keys.Enter)
|
||||
UpdateServerPath();
|
||||
}
|
||||
|
||||
private void FullUpdateWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
||||
{
|
||||
if (updateError != null)
|
||||
MessageBox.Show(updateError);
|
||||
UpdateHardButton.Enabled = true;
|
||||
UpdateMergeButton.Enabled = true;
|
||||
TestmergeButton.Enabled = true;
|
||||
UpdateTestmergeButton.Enabled = true;
|
||||
LoadServerPage();
|
||||
ServerTimer.Start();
|
||||
}
|
||||
|
||||
private void WorldStatusChecker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
||||
{
|
||||
if (DDStatusString != "Topic recieve error!" || ServerStatusLabel.Text == "OFFLINE")
|
||||
ServerStatusLabel.Text = DDStatusString;
|
||||
WorldStatusTimer.Start();
|
||||
}
|
||||
|
||||
private void CompileCancelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var res = Server.GetComponent<ITGCompiler>().Cancel();
|
||||
if (res != null)
|
||||
MessageBox.Show(res);
|
||||
LoadServerPage();
|
||||
}
|
||||
|
||||
private void ServerPathTextbox_LostFocus(object sender, EventArgs e)
|
||||
{
|
||||
UpdateServerPath();
|
||||
}
|
||||
|
||||
void UpdateServerPath()
|
||||
{
|
||||
var Config = Server.GetComponent<ITGConfig>();
|
||||
if (updatingFields || ServerPathTextbox.Text.Trim() == Config.ServerDirectory())
|
||||
return;
|
||||
var DialogResult = MessageBox.Show("This will move the entire server installation.", "Confim", MessageBoxButtons.YesNo);
|
||||
if (DialogResult != DialogResult.Yes)
|
||||
return;
|
||||
MessageBox.Show(Config.MoveServer(ServerPathTextbox.Text) ?? "Success!");
|
||||
}
|
||||
|
||||
void LoadServerPage()
|
||||
{
|
||||
var RepoExists = Server.GetComponent<ITGRepository>().Exists();
|
||||
compileButton.Visible = RepoExists;
|
||||
initializeButton.Visible = RepoExists;
|
||||
NudgePortSelector.Visible = RepoExists;
|
||||
AutostartCheckbox.Visible = RepoExists;
|
||||
WebclientCheckBox.Visible = RepoExists;
|
||||
PortSelector.Visible = RepoExists;
|
||||
projectNameText.Visible = RepoExists;
|
||||
compilerProgressBar.Visible = RepoExists;
|
||||
CompilerStatusLabel.Visible = RepoExists;
|
||||
CompileCancelButton.Visible = RepoExists;
|
||||
NudgePortLabel.Visible = RepoExists;
|
||||
CompilerLabel.Visible = RepoExists;
|
||||
ProjectPathLabel.Visible = RepoExists;
|
||||
ServerPRLabel.Visible = RepoExists;
|
||||
ServerGStopButton.Visible = RepoExists;
|
||||
ServerStartButton.Visible = RepoExists;
|
||||
ServerGRestartButton.Visible = RepoExists;
|
||||
ServerRestartButton.Visible = RepoExists;
|
||||
PortLabel.Visible = RepoExists;
|
||||
ServerStopButton.Visible = RepoExists;
|
||||
TestmergeButton.Visible = RepoExists;
|
||||
ServerTestmergeInput.Visible = RepoExists;
|
||||
UpdateHardButton.Visible = RepoExists;
|
||||
UpdateMergeButton.Visible = RepoExists;
|
||||
UpdateTestmergeButton.Visible = RepoExists;
|
||||
ResetTestmerge.Visible = RepoExists;
|
||||
WorldAnnounceField.Visible = RepoExists;
|
||||
WorldAnnounceButton.Visible = RepoExists;
|
||||
|
||||
var DM = Server.GetComponent<ITGCompiler>();
|
||||
var DD = Server.GetComponent<ITGDreamDaemon>();
|
||||
var Config = Server.GetComponent<ITGConfig>();
|
||||
|
||||
if (updatingFields)
|
||||
return;
|
||||
try
|
||||
{
|
||||
updatingFields = true;
|
||||
|
||||
if (!ServerPathTextbox.Focused)
|
||||
ServerPathTextbox.Text = Config.ServerDirectory();
|
||||
|
||||
SecuritySelector.SelectedIndex = (int)DD.SecurityLevel();
|
||||
|
||||
if (!RepoExists)
|
||||
return;
|
||||
|
||||
var Online = DD.DaemonStatus() == TGDreamDaemonStatus.Online;
|
||||
ServerGStopButton.Enabled = Online;
|
||||
ServerGRestartButton.Enabled = Online;
|
||||
|
||||
var ShuttingDown = DD.ShutdownInProgress();
|
||||
ServerGStopButton.Checked = ShuttingDown;
|
||||
ServerGStopButton.Enabled = !ShuttingDown;
|
||||
|
||||
AutostartCheckbox.Checked = DD.Autostart();
|
||||
WebclientCheckBox.Checked = DD.Webclient();
|
||||
if (!PortSelector.Focused)
|
||||
PortSelector.Value = DD.Port();
|
||||
if (!projectNameText.Focused)
|
||||
projectNameText.Text = DM.ProjectName();
|
||||
|
||||
var val = Config.InteropPort(out string error);
|
||||
if (error != null)
|
||||
{
|
||||
updatingFields = false;
|
||||
NudgePortSelector.Value = 4567;
|
||||
updatingFields = true;
|
||||
MessageBox.Show("Error (I will try and recover): " + error);
|
||||
}
|
||||
else
|
||||
{
|
||||
NudgePortSelector.Value = val;
|
||||
updatingFields = true;
|
||||
}
|
||||
|
||||
switch (DM.GetStatus())
|
||||
{
|
||||
case TGCompilerStatus.Compiling:
|
||||
CompilerStatusLabel.Text = "Compiling...";
|
||||
compilerProgressBar.Style = ProgressBarStyle.Marquee;
|
||||
compileButton.Enabled = false;
|
||||
initializeButton.Enabled = false;
|
||||
CompileCancelButton.Enabled = true;
|
||||
break;
|
||||
case TGCompilerStatus.Initializing:
|
||||
CompilerStatusLabel.Text = "Initializing...";
|
||||
compilerProgressBar.Style = ProgressBarStyle.Marquee;
|
||||
compileButton.Enabled = false;
|
||||
initializeButton.Enabled = false;
|
||||
CompileCancelButton.Enabled = false;
|
||||
break;
|
||||
case TGCompilerStatus.Initialized:
|
||||
CompilerStatusLabel.Text = "Idle";
|
||||
compilerProgressBar.Style = ProgressBarStyle.Blocks;
|
||||
initializeButton.Enabled = true;
|
||||
compileButton.Enabled = true;
|
||||
CompileCancelButton.Enabled = false;
|
||||
break;
|
||||
case TGCompilerStatus.Uninitialized:
|
||||
CompilerStatusLabel.Text = "Uninitialized";
|
||||
compilerProgressBar.Style = ProgressBarStyle.Blocks;
|
||||
compileButton.Enabled = false;
|
||||
initializeButton.Enabled = true;
|
||||
CompileCancelButton.Enabled = false;
|
||||
break;
|
||||
default:
|
||||
CompilerStatusLabel.Text = "Unknown!";
|
||||
compilerProgressBar.Style = ProgressBarStyle.Blocks;
|
||||
initializeButton.Enabled = true;
|
||||
compileButton.Enabled = true;
|
||||
CompileCancelButton.Enabled = true;
|
||||
break;
|
||||
}
|
||||
error = DM.CompileError();
|
||||
if (error != null)
|
||||
MessageBox.Show("Error: " + error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
updatingFields = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void ServerTimer_Tick(object sender, System.EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
LoadServerPage();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ServerTimer.Stop();
|
||||
Program.ServiceDisconnectException(ex);
|
||||
}
|
||||
}
|
||||
private void ProjectNameText_LostFocus(object sender, EventArgs e)
|
||||
{
|
||||
UpdateProjectName();
|
||||
}
|
||||
|
||||
void UpdateProjectName()
|
||||
{
|
||||
if (!updatingFields)
|
||||
Server.GetComponent<ITGCompiler>().SetProjectName(projectNameText.Text);
|
||||
}
|
||||
|
||||
private void PortSelector_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!updatingFields)
|
||||
Server.GetComponent<ITGDreamDaemon>().SetPort((ushort)PortSelector.Value);
|
||||
}
|
||||
|
||||
private void RunServerUpdate(FullUpdateAction fua, ushort tm = 0)
|
||||
{
|
||||
if (FullUpdateWorker.IsBusy)
|
||||
return;
|
||||
testmergePR = tm;
|
||||
fuAction = fua;
|
||||
initializeButton.Enabled = false;
|
||||
compileButton.Enabled = false;
|
||||
UpdateHardButton.Enabled = false;
|
||||
UpdateMergeButton.Enabled = false;
|
||||
TestmergeButton.Enabled = false;
|
||||
UpdateTestmergeButton.Enabled = false;
|
||||
compilerProgressBar.Style = ProgressBarStyle.Marquee;
|
||||
switch (fuAction)
|
||||
{
|
||||
case FullUpdateAction.Testmerge:
|
||||
CompilerStatusLabel.Text = String.Format("Testmerging pull request #{0}...", testmergePR);
|
||||
break;
|
||||
case FullUpdateAction.UpdateHard:
|
||||
CompilerStatusLabel.Text = String.Format("Updating Server (RESET)...");
|
||||
break;
|
||||
case FullUpdateAction.UpdateMerge:
|
||||
CompilerStatusLabel.Text = String.Format("Updating Server (MERGE)...");
|
||||
break;
|
||||
case FullUpdateAction.UpdateHardTestmerge:
|
||||
CompilerStatusLabel.Text = String.Format("Updating and testmerging pull request #{0}...", testmergePR);
|
||||
break;
|
||||
}
|
||||
ServerTimer.Stop();
|
||||
FullUpdateWorker.RunWorkerAsync();
|
||||
}
|
||||
|
||||
private void InitializeButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!Server.GetComponent<ITGCompiler>().Initialize())
|
||||
MessageBox.Show("Unable to start initialization!");
|
||||
LoadServerPage();
|
||||
}
|
||||
private void CompileButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!Server.GetComponent<ITGCompiler>().Compile())
|
||||
MessageBox.Show("Unable to start compilation!");
|
||||
LoadServerPage();
|
||||
}
|
||||
//because of lol byond this can take some time...
|
||||
private void WorldStatusChecker_DoWork(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Server.GetComponent<ITGRepository>().Exists())
|
||||
DDStatusString = "NOT INSTALLED";
|
||||
else
|
||||
DDStatusString = Server.GetComponent<ITGDreamDaemon>().StatusString(true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
DDStatusString = "ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
private void WorldStatusTimer_Tick(object sender, System.EventArgs e)
|
||||
{
|
||||
WorldStatusTimer.Stop();
|
||||
WorldStatusChecker.RunWorkerAsync();
|
||||
}
|
||||
|
||||
private void AutostartCheckbox_CheckedChanged(object sender, System.EventArgs e)
|
||||
{
|
||||
if (!updatingFields)
|
||||
Server.GetComponent<ITGDreamDaemon>().SetAutostart(AutostartCheckbox.Checked);
|
||||
}
|
||||
private void ServerStartButton_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
if (!ServerStartBGW.IsBusy)
|
||||
ServerStartBGW.RunWorkerAsync();
|
||||
}
|
||||
|
||||
private void ServerStartBGW_DoWork(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
e.Result = Server.GetComponent<ITGDreamDaemon>().Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
e.Result = ex.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private void ServerStopButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var DialogResult = MessageBox.Show("This will immediately shut down the server. Continue?", "Confim", MessageBoxButtons.YesNo);
|
||||
if (DialogResult == DialogResult.No)
|
||||
return;
|
||||
var res = Server.GetComponent<ITGDreamDaemon>().Stop();
|
||||
if (res != null)
|
||||
MessageBox.Show(res);
|
||||
}
|
||||
|
||||
private void ServerRestartButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var DialogResult = MessageBox.Show("This will immediately restart the server. Continue?", "Confim", MessageBoxButtons.YesNo);
|
||||
if (DialogResult == DialogResult.No)
|
||||
return;
|
||||
var res = Server.GetComponent<ITGDreamDaemon>().Restart();
|
||||
if (res != null)
|
||||
MessageBox.Show(res);
|
||||
}
|
||||
|
||||
private void ServerGStopButton_Checked(object sender, EventArgs e)
|
||||
{
|
||||
if (updatingFields)
|
||||
return;
|
||||
var DialogResult = MessageBox.Show("This will shut down the server when the current round ends. Continue?", "Confim", MessageBoxButtons.YesNo);
|
||||
if (DialogResult == DialogResult.No)
|
||||
return;
|
||||
Server.GetComponent<ITGDreamDaemon>().RequestStop();
|
||||
LoadServerPage();
|
||||
}
|
||||
|
||||
private void ServerGRestartButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var DialogResult = MessageBox.Show("This will restart the server when the current round ends. Continue?", "Confim", MessageBoxButtons.YesNo);
|
||||
if (DialogResult == DialogResult.No)
|
||||
return;
|
||||
Server.GetComponent<ITGDreamDaemon>().RequestRestart();
|
||||
}
|
||||
|
||||
|
||||
private void FullUpdateWorker_DoWork(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
var Repo = Server.GetComponent<ITGRepository>();
|
||||
var DM = Server.GetComponent<ITGCompiler>();
|
||||
switch (fuAction)
|
||||
{
|
||||
case FullUpdateAction.Testmerge:
|
||||
updateError = Repo.MergePullRequest(testmergePR);
|
||||
if (updateError == null)
|
||||
{
|
||||
Repo.GenerateChangelog(out updateError);
|
||||
updateError = DM.Compile(true) ? updateError : "Compilation failed!";
|
||||
}
|
||||
break;
|
||||
case FullUpdateAction.UpdateHard:
|
||||
updateError = Repo.Update(true);
|
||||
if (updateError == null)
|
||||
{
|
||||
Repo.GenerateChangelog(out updateError);
|
||||
if (updateError == null)
|
||||
updateError = Repo.PushChangelog();
|
||||
updateError = DM.Compile(true) ? updateError : "Compilation failed!";
|
||||
}
|
||||
break;
|
||||
case FullUpdateAction.UpdateHardTestmerge:
|
||||
updateError = Repo.Update(true);
|
||||
if (updateError == null)
|
||||
{
|
||||
Repo.GenerateChangelog(out updateError);
|
||||
if (updateError == null)
|
||||
updateError = Repo.PushChangelog();
|
||||
updateError = Repo.MergePullRequest(testmergePR);
|
||||
if (updateError == null)
|
||||
{
|
||||
Repo.GenerateChangelog(out updateError);
|
||||
updateError = DM.Compile(true) ? updateError : "Compilation failed!";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FullUpdateAction.UpdateMerge:
|
||||
updateError = Repo.Update(false);
|
||||
if (updateError == null)
|
||||
{
|
||||
Repo.GenerateChangelog(out updateError);
|
||||
if (updateError == null)
|
||||
Repo.PushChangelog(); //not an error 99% of the time if this fails, just a dirty tree
|
||||
updateError = DM.Compile(true) ? updateError : "Compilation failed!";
|
||||
}
|
||||
break;
|
||||
case FullUpdateAction.Reset:
|
||||
updateError = Repo.Reset(true);
|
||||
if (updateError == null)
|
||||
{
|
||||
Repo.GenerateChangelog(out updateError);
|
||||
updateError = DM.Compile(true) ? updateError : "Compilation failed!";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void ResetTestmerge_Click(object sender, EventArgs e)
|
||||
{
|
||||
RunServerUpdate(FullUpdateAction.Reset);
|
||||
}
|
||||
|
||||
private void UpdateHardButton_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
RunServerUpdate(FullUpdateAction.UpdateHard);
|
||||
}
|
||||
|
||||
private void UpdateTestmergeButton_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
RunServerUpdate(FullUpdateAction.UpdateHardTestmerge, (ushort)ServerTestmergeInput.Value);
|
||||
}
|
||||
|
||||
private void UpdateMergeButton_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
RunServerUpdate(FullUpdateAction.UpdateMerge);
|
||||
}
|
||||
private void TestmergeButton_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
RunServerUpdate(FullUpdateAction.Testmerge, (ushort)ServerTestmergeInput.Value);
|
||||
}
|
||||
|
||||
private void NudgePortSelector_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!updatingFields)
|
||||
Server.GetComponent<ITGConfig>().SetInteropPort((ushort)NudgePortSelector.Value);
|
||||
}
|
||||
|
||||
private void SecuritySelector_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!updatingFields)
|
||||
if (!Server.GetComponent<ITGDreamDaemon>().SetSecurityLevel((TGDreamDaemonSecurity)SecuritySelector.SelectedIndex))
|
||||
MessageBox.Show("Security change will be applied after next server reboot.");
|
||||
}
|
||||
|
||||
private void WorldAnnounceButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var msg = WorldAnnounceField.Text;
|
||||
if (!String.IsNullOrWhiteSpace(msg))
|
||||
{
|
||||
var res = Server.GetComponent<ITGDreamDaemon>().WorldAnnounce(msg);
|
||||
if (res != null)
|
||||
{
|
||||
MessageBox.Show(res);
|
||||
return;
|
||||
}
|
||||
}
|
||||
WorldAnnounceField.Text = "";
|
||||
}
|
||||
|
||||
private void WebclientCheckBox_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!updatingFields)
|
||||
Server.GetComponent<ITGDreamDaemon>().SetWebclient(WebclientCheckBox.Checked);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user