mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-26 22:48:20 +01:00
Sanely namespaces the project
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using TGS.Interface;
|
||||
using TGS.Interface.Components;
|
||||
|
||||
namespace TGS.ControlPanel
|
||||
{
|
||||
/// <summary>
|
||||
/// The main <see cref="ControlPanel"/> form
|
||||
/// </summary>
|
||||
sealed partial class ControlPanel : CountedForm
|
||||
{
|
||||
/// <summary>
|
||||
/// List of instances being used by open control panels
|
||||
/// </summary>
|
||||
public static IDictionary<string, ControlPanel> InstancesInUse { get; private set; } = new Dictionary<string, ControlPanel>();
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IServerInterface"/> instance for this <see cref="ControlPanel"/>
|
||||
/// </summary>
|
||||
readonly IServerInterface Interface;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a <see cref="ControlPanel"/>
|
||||
/// </summary>
|
||||
/// <param name="I">The <see cref="IServerInterface"/> for the <see cref="ControlPanel"/></param>
|
||||
public ControlPanel(IServerInterface I)
|
||||
{
|
||||
InitializeComponent();
|
||||
FormClosed += ControlPanel_FormClosed;
|
||||
Interface = I;
|
||||
if (Interface.IsRemoteConnection)
|
||||
{
|
||||
var splits = Interface.GetServiceComponent<ITGLanding>().Version().Split(' ');
|
||||
Text = String.Format("TGS {0}: {1}:{2}", splits[splits.Length - 1], Interface.HTTPSURL, Interface.HTTPSPort);
|
||||
}
|
||||
Text += " Instance: " + I.InstanceName;
|
||||
if (Interface.VersionMismatch(out string error) && MessageBox.Show(error, "Warning", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
|
||||
{
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
Panels.SelectedIndexChanged += Panels_SelectedIndexChanged;
|
||||
Panels.SelectedIndex += Math.Min(Properties.Settings.Default.LastPageIndex, Panels.TabCount - 1);
|
||||
InitRepoPage();
|
||||
InitBYONDPage();
|
||||
InitServerPage();
|
||||
UpdateSelectedPanel();
|
||||
InstancesInUse.Add(I.InstanceName, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the <see cref="ControlPanel"/> is closed
|
||||
/// </summary>
|
||||
/// <param name="sender">The sender of the event</param>
|
||||
/// <param name="e">The <see cref="EventArgs"/></param>
|
||||
void ControlPanel_FormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
InstancesInUse.Remove(Interface.InstanceName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called from <see cref="Dispose(bool)"/>
|
||||
/// </summary>
|
||||
void Cleanup()
|
||||
{
|
||||
InstancesInUse.Remove(Interface.InstanceName);
|
||||
Interface.Dispose();
|
||||
}
|
||||
|
||||
private void Main_Resize(object sender, EventArgs e)
|
||||
{
|
||||
Panels.Location = new Point(10, 10);
|
||||
Panels.Width = ClientSize.Width - 20;
|
||||
Panels.Height = ClientSize.Height - 20;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the content of <see cref="TabControl.SelectedTab"/> of <see cref="Panels"/>
|
||||
/// </summary>
|
||||
void UpdateSelectedPanel()
|
||||
{
|
||||
switch (Panels.SelectedIndex)
|
||||
{
|
||||
case 0: //repo
|
||||
PopulateRepoFields();
|
||||
break;
|
||||
case 1: //byond
|
||||
UpdateBYONDButtons();
|
||||
break;
|
||||
case 2: //scp
|
||||
LoadServerPage();
|
||||
break;
|
||||
case 3: //chat
|
||||
LoadChatPage();
|
||||
break;
|
||||
case 4: //static
|
||||
InitStaticPage();
|
||||
break;
|
||||
}
|
||||
Properties.Settings.Default.LastPageIndex = Panels.SelectedIndex;
|
||||
}
|
||||
|
||||
void Panels_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
UpdateSelectedPanel();
|
||||
}
|
||||
|
||||
bool CheckAdminWithWarning()
|
||||
{
|
||||
if (!Interface.ConnectToInstance().HasFlag(ConnectivityLevel.Administrator))
|
||||
{
|
||||
MessageBox.Show("Only system administrators may use this command!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user