Removes visibility configuration. Adds a world announce filed and command.

This commit is contained in:
Cyberboss
2017-07-31 15:53:32 -04:00
parent ca920e4674
commit 1674273e2c
6 changed files with 107 additions and 178 deletions
+27 -45
View File
@@ -9,7 +9,7 @@ namespace TGCommandLine
public DDCommand()
{
Keyword = "dd";
Children = new Command[] { new DDStartCommand(), new DDStopCommand(), new DDRestartCommand(), new DDStatusCommand(), new DDAutostartCommand(), new DDPortCommand(), new DDVisibilityCommand(), new DDSecurityCommand() };
Children = new Command[] { new DDStartCommand(), new DDStopCommand(), new DDRestartCommand(), new DDStatusCommand(), new DDAutostartCommand(), new DDPortCommand(), new DDSecurityCommand(), new DDWorldAnnounceCommand() };
}
public override string GetHelpText()
{
@@ -17,6 +17,32 @@ namespace TGCommandLine
}
}
class DDWorldAnnounceCommand : Command
{
public DDWorldAnnounceCommand()
{
Keyword = "announce";
RequiredParameters = 1;
}
public override string GetHelpText()
{
return "Sends a message all players on the server";
}
public override string GetArgumentString()
{
return "<message>";
}
protected override ExitCode Run(IList<string> parameters)
{
var res = Server.GetComponent<ITGDreamDaemon>().WorldAnnounce(String.Join(" ", parameters));
OutputProc(res ?? "Success!");
return res == null ? ExitCode.Normal : ExitCode.ServerError;
}
}
class DDStartCommand : Command
{
public DDStartCommand()
@@ -201,50 +227,6 @@ namespace TGCommandLine
}
}
class DDVisibilityCommand : Command
{
public DDVisibilityCommand()
{
Keyword = "set-visibility";
RequiredParameters = 1;
}
protected override ExitCode Run(IList<string> parameters)
{
TGDreamDaemonVisibility vis;
switch (parameters[0].ToLower())
{
case "invisible":
case "invis":
vis = TGDreamDaemonVisibility.Invisible;
break;
case "private":
case "priv":
vis = TGDreamDaemonVisibility.Private;
break;
case "public":
case "pub":
vis = TGDreamDaemonVisibility.Public;
break;
default:
OutputProc("Invalid visiblity word!");
return ExitCode.BadCommand;
}
Server.GetComponent<ITGDreamDaemon>().SetVisibility(vis);
return ExitCode.Normal;
}
public override string GetHelpText()
{
return "Sets the visibility option for the DreamDaemon world. Requires a server restart to apply and queues a graceful one up";
}
public override string GetArgumentString()
{
return "<public|private|invisible>";
}
}
class DDSecurityCommand : Command
{
public DDSecurityCommand()
+43 -36
View File
@@ -71,7 +71,6 @@
this.MajorVersionNumeric = new System.Windows.Forms.NumericUpDown();
this.UpdateProgressBar = new System.Windows.Forms.ProgressBar();
this.ServerPanel = new System.Windows.Forms.TabPage();
this.VisibilitySelector = new System.Windows.Forms.ComboBox();
this.VisibilityTitle = new System.Windows.Forms.Label();
this.SecuritySelector = new System.Windows.Forms.ComboBox();
this.SecurityTitle = new System.Windows.Forms.Label();
@@ -80,7 +79,6 @@
this.NudgePortLabel = new System.Windows.Forms.Label();
this.ServerPathLabel = new System.Windows.Forms.Label();
this.ServerPathTextbox = new System.Windows.Forms.TextBox();
this.CompileCancelButton = new System.Windows.Forms.Button();
this.ProjectPathLabel = new System.Windows.Forms.Label();
this.projectNameText = new System.Windows.Forms.TextBox();
this.PortLabel = new System.Windows.Forms.Label();
@@ -177,6 +175,9 @@
this.WorldStatusTimer = new System.Windows.Forms.Timer(this.components);
this.FullUpdateWorker = new System.ComponentModel.BackgroundWorker();
this.ServerStartBGW = new System.ComponentModel.BackgroundWorker();
this.WorldAnnounceField = new System.Windows.Forms.TextBox();
this.CompileCancelButton = new System.Windows.Forms.Button();
this.WorldAnnounceButton = new System.Windows.Forms.Button();
this.Panels.SuspendLayout();
this.RepoPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.TestmergeSelector)).BeginInit();
@@ -722,7 +723,8 @@
// ServerPanel
//
this.ServerPanel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(39)))), ((int)(((byte)(40)))), ((int)(((byte)(34)))));
this.ServerPanel.Controls.Add(this.VisibilitySelector);
this.ServerPanel.Controls.Add(this.WorldAnnounceButton);
this.ServerPanel.Controls.Add(this.WorldAnnounceField);
this.ServerPanel.Controls.Add(this.VisibilityTitle);
this.ServerPanel.Controls.Add(this.SecuritySelector);
this.ServerPanel.Controls.Add(this.SecurityTitle);
@@ -762,32 +764,17 @@
this.ServerPanel.TabIndex = 2;
this.ServerPanel.Text = "Server";
//
// VisibilitySelector
//
this.VisibilitySelector.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.VisibilitySelector.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.VisibilitySelector.FormattingEnabled = true;
this.VisibilitySelector.Items.AddRange(new object[] {
"Public",
"Private",
"Invisible"});
this.VisibilitySelector.Location = new System.Drawing.Point(566, 136);
this.VisibilitySelector.Name = "VisibilitySelector";
this.VisibilitySelector.Size = new System.Drawing.Size(121, 21);
this.VisibilitySelector.TabIndex = 40;
this.VisibilitySelector.SelectedIndexChanged += new System.EventHandler(this.VisibilitySelector_SelectedIndexChanged);
//
// VisibilityTitle
//
this.VisibilityTitle.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.VisibilityTitle.AutoSize = true;
this.VisibilityTitle.Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.VisibilityTitle.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(242)))));
this.VisibilityTitle.Location = new System.Drawing.Point(474, 139);
this.VisibilityTitle.Location = new System.Drawing.Point(466, 139);
this.VisibilityTitle.Name = "VisibilityTitle";
this.VisibilityTitle.Size = new System.Drawing.Size(86, 18);
this.VisibilityTitle.Size = new System.Drawing.Size(94, 18);
this.VisibilityTitle.TabIndex = 39;
this.VisibilityTitle.Text = "Visibility:";
this.VisibilityTitle.Text = "Announce:";
this.VisibilityTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// SecuritySelector
@@ -884,18 +871,6 @@
this.ServerPathTextbox.Size = new System.Drawing.Size(296, 20);
this.ServerPathTextbox.TabIndex = 32;
//
// CompileCancelButton
//
this.CompileCancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.CompileCancelButton.Enabled = false;
this.CompileCancelButton.Location = new System.Drawing.Point(737, 302);
this.CompileCancelButton.Name = "CompileCancelButton";
this.CompileCancelButton.Size = new System.Drawing.Size(69, 31);
this.CompileCancelButton.TabIndex = 31;
this.CompileCancelButton.Text = "Cancel";
this.CompileCancelButton.UseVisualStyleBackColor = true;
this.CompileCancelButton.Click += new System.EventHandler(this.CompileCancelButton_Click);
//
// ProjectPathLabel
//
this.ProjectPathLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
@@ -1608,7 +1583,6 @@
this.AdminModeSpecial.TabStop = true;
this.AdminModeSpecial.Text = "Channel Mode";
this.AdminModeSpecial.UseVisualStyleBackColor = true;
this.AdminModeNormal.CheckedChanged += new System.EventHandler(this.AdminModeSpecial_CheckedChanged);
//
// AdminModeNormal
//
@@ -1987,6 +1961,38 @@
//
this.ServerStartBGW.DoWork += new System.ComponentModel.DoWorkEventHandler(this.ServerStartBGW_DoWork);
//
// WorldAnnounceField
//
this.WorldAnnounceField.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.WorldAnnounceField.Location = new System.Drawing.Point(566, 136);
this.WorldAnnounceField.Name = "WorldAnnounceField";
this.WorldAnnounceField.Size = new System.Drawing.Size(213, 20);
this.WorldAnnounceField.TabIndex = 40;
//
// CompileCancelButton
//
this.CompileCancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.CompileCancelButton.Enabled = false;
this.CompileCancelButton.Location = new System.Drawing.Point(737, 302);
this.CompileCancelButton.Name = "CompileCancelButton";
this.CompileCancelButton.Size = new System.Drawing.Size(69, 31);
this.CompileCancelButton.TabIndex = 31;
this.CompileCancelButton.Text = "Cancel";
this.CompileCancelButton.UseVisualStyleBackColor = true;
this.CompileCancelButton.Click += new System.EventHandler(this.CompileCancelButton_Click);
//
// WorldAnnounceButton
//
this.WorldAnnounceButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.WorldAnnounceButton.Enabled = false;
this.WorldAnnounceButton.Location = new System.Drawing.Point(785, 136);
this.WorldAnnounceButton.Name = "WorldAnnounceButton";
this.WorldAnnounceButton.Size = new System.Drawing.Size(77, 20);
this.WorldAnnounceButton.TabIndex = 41;
this.WorldAnnounceButton.Text = "Send";
this.WorldAnnounceButton.UseVisualStyleBackColor = true;
this.WorldAnnounceButton.Click += new System.EventHandler(this.WorldAnnounceButton_Click);
//
// Main
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -2082,7 +2088,6 @@
private System.Windows.Forms.NumericUpDown PortSelector;
private System.Windows.Forms.Label ProjectPathLabel;
private System.Windows.Forms.TextBox projectNameText;
private System.Windows.Forms.Button CompileCancelButton;
private System.Windows.Forms.Label ServerPathLabel;
private System.Windows.Forms.TextBox ServerPathTextbox;
private System.Windows.Forms.Label LatestVersionLabel;
@@ -2159,7 +2164,6 @@
private System.Windows.Forms.ComboBox SecuritySelector;
private System.Windows.Forms.Label SecurityTitle;
private System.Windows.Forms.Label VisibilityTitle;
private System.Windows.Forms.ComboBox VisibilitySelector;
private System.ComponentModel.BackgroundWorker ServerStartBGW;
private System.Windows.Forms.Button RepoRefreshButton;
private System.Windows.Forms.ComboBox IRCModesComboBox;
@@ -2175,5 +2179,8 @@
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button WorldAnnounceButton;
private System.Windows.Forms.TextBox WorldAnnounceField;
private System.Windows.Forms.Button CompileCancelButton;
}
}
+14 -6
View File
@@ -125,6 +125,8 @@ namespace TGControlPanel
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>();
@@ -137,8 +139,7 @@ namespace TGControlPanel
if (!ServerPathTextbox.Focused)
ServerPathTextbox.Text = Config.ServerDirectory();
VisibilitySelector.SelectedIndex = (int)DD.VisibilityLevel();
SecuritySelector.SelectedIndex = (int)DD.SecurityLevel();
if (!RepoExists)
@@ -432,11 +433,18 @@ namespace TGControlPanel
MessageBox.Show("Security change will be applied after next server reboot.");
}
private void VisibilitySelector_SelectedIndexChanged(object sender, EventArgs e)
private void WorldAnnounceButton_Click(object sender, EventArgs e)
{
if (!updatingFields)
if (!Server.GetComponent<ITGDreamDaemon>().SetVisibility((TGDreamDaemonVisibility)VisibilitySelector.SelectedIndex))
MessageBox.Show("Visibility change will be applied after next server reboot.");
var msg = WorldAnnounceField.Text;
if (!String.IsNullOrWhiteSpace(msg)) {
var res = Server.GetComponent<ITGDreamDaemon>().WorldAnnounce(msg);
if(res != null)
{
MessageBox.Show(res);
return;
}
}
WorldAnnounceField.Text = "";
}
}
}
+14 -50
View File
@@ -31,7 +31,6 @@ namespace TGServerService
bool RestartInProgress = false;
TGDreamDaemonSecurity StartingSecurity;
TGDreamDaemonVisibility StartingVisiblity;
ShutdownRequestPhase AwaitingShutdown;
@@ -364,23 +363,6 @@ namespace TGServerService
}
}
//same thing with visibility
string VisibilityWord(bool starting = false)
{
var level = starting ? StartingVisiblity : (TGDreamDaemonVisibility)Properties.Settings.Default.ServerVisiblity;
switch (level)
{
case TGDreamDaemonVisibility.Invisible:
return "invisible";
case TGDreamDaemonVisibility.Private:
return "private";
case TGDreamDaemonVisibility.Public:
return "public";
default:
throw new Exception(String.Format("Bad DreamDaemon visibility level: {0}", level));
}
}
//used by Start and Watchdog to start a DD instance
string StartImpl(bool watchdog)
{
@@ -394,11 +376,9 @@ namespace TGServerService
var Config = Properties.Settings.Default;
var DMB = GameDirLive + "/" + Config.ProjectName + ".dmb";
GenCommsKey();
StartingVisiblity = (TGDreamDaemonVisibility)Config.ServerVisiblity;
StartingSecurity = (TGDreamDaemonSecurity)Config.ServerSecurity;
Proc.StartInfo.Arguments = String.Format("{0} -port {1} -close -verbose -params server_service={4} -{2} -{3}", DMB, Config.ServerPort, SecurityWord(), VisibilityWord(), serviceCommsKey);
Proc.StartInfo.Arguments = String.Format("{0} -port {1} -close -verbose -params server_service={3} -{2} -public", DMB, Config.ServerPort, SecurityWord(), serviceCommsKey);
InitInterop();
Proc.Start();
@@ -429,31 +409,6 @@ namespace TGServerService
}
}
//public api
public TGDreamDaemonVisibility VisibilityLevel()
{
lock (watchdogLock)
{
return (TGDreamDaemonVisibility)Properties.Settings.Default.ServerVisiblity;
}
}
//public api
public bool SetVisibility(TGDreamDaemonVisibility NewVis)
{
var Config = Properties.Settings.Default;
var visInt = (int)NewVis;
bool needReboot;
lock (watchdogLock)
{
needReboot = Config.ServerVisiblity != visInt;
Config.ServerVisiblity = visInt;
}
if (needReboot)
RequestRestart();
return DaemonStatus() != TGDreamDaemonStatus.Online;
}
//public api
public TGDreamDaemonSecurity SecurityLevel()
{
@@ -494,7 +449,7 @@ namespace TGServerService
//public api
public string StatusString(bool includeMetaInfo)
{
const string visSecStr = " (Vis: {0}, Sec: {1})";
const string visSecStr = " (Sec: {1})";
string res;
var ds = DaemonStatus();
switch (ds)
@@ -512,7 +467,7 @@ namespace TGServerService
string secandvis;
lock (watchdogLock)
{
secandvis = String.Format(visSecStr, VisibilityWord(true), SecurityWord(true));
secandvis = String.Format(visSecStr, SecurityWord(true));
}
res += secandvis;
}
@@ -522,7 +477,7 @@ namespace TGServerService
break;
}
if (includeMetaInfo && ds != TGDreamDaemonStatus.Online)
res += String.Format(visSecStr, VisibilityWord(), SecurityWord());
res += String.Format(visSecStr, SecurityWord());
return res;
}
@@ -540,5 +495,14 @@ namespace TGServerService
return AwaitingShutdown != ShutdownRequestPhase.None;
}
}
/// <inheritdoc />
public string WorldAnnounce(string message)
{
var res = SendCommand(SCWorldAnnounce + ";message=" + message);
if (res == "SUCCESS")
return null;
return res;
}
}
}
-5
View File
@@ -77,11 +77,6 @@ namespace TGServerService
}
}
bool WorldAnnounce(string message)
{
return SendCommand(SCWorldAnnounce + ";message=" + message) == "SUCCESS" ;
}
public string SendPM(string targetCkey, string sender, string message)
{
return SendCommand(String.Format("{3};target={0};sender={1};message={2}", targetCkey, sender, message, SCAdminPM));
+9 -36
View File
@@ -39,26 +39,7 @@ namespace TGServiceInterface
/// </summary>
Ultrasafe
}
/// <summary>
/// DreamDaemon's hub visibility
/// </summary>
public enum TGDreamDaemonVisibility
{
/// <summary>
/// Server will be visible on the hub
/// </summary>
Public,
/// <summary>
/// Server will not be visible on the hub to anyone but the host's friends. Since the service does not have a BYOND account, this is effectively the same as Invisible
/// </summary>
Private,
/// <summary>
/// Server will not be visible on the hub
/// </summary>
Invisible = 2, //default config
}
/// <summary>
/// Interface for managing the actual BYOND game server
/// </summary>
@@ -140,22 +121,6 @@ namespace TGServiceInterface
[OperationContract]
bool SetSecurityLevel(TGDreamDaemonSecurity level);
/// <summary>
/// Get the configured (not running) visibility level
/// </summary>
/// <returns>The configured (not running) visibility level</returns>
[OperationContract]
TGDreamDaemonVisibility VisibilityLevel();
/// <summary>
/// Sets the visiblity level of the server. Requires reboot to apply
/// Implies a call to RequestRestart()
/// </summary>
/// <param name="vis">The new visibility level</param>
/// <returns>True if the change was immediately applied, false if a graceful restart was queued</returns>
[OperationContract]
bool SetVisibility(TGDreamDaemonVisibility vis);
/// <summary>
/// Get the configured port. Not necessarily the running port if it has since changed
/// </summary>
@@ -191,5 +156,13 @@ namespace TGServiceInterface
/// <returns>true if RequestStop has been called since the last server start, false otherwise</returns>
[OperationContract]
bool ShutdownInProgress();
/// <summary>
/// Sends a message to everyone on the server
/// </summary>
/// <param name="msg">The message to send</param>
/// <returns>null on success, error message on failure</returns>
[OperationContract]
string WorldAnnounce(string msg);
}
}