From 1674273e2c921683ab08a893c282dd28ff2954cf Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 31 Jul 2017 15:53:32 -0400 Subject: [PATCH] Removes visibility configuration. Adds a world announce filed and command. --- TGCommandLine/DDCommands.cs | 72 +++++++++++----------------- TGControlPanel/Main.Designer.cs | 79 +++++++++++++++++-------------- TGControlPanel/ServerPage.cs | 20 +++++--- TGServerService/DreamDaemon.cs | 64 ++++++------------------- TGServerService/Interop.cs | 5 -- TGServiceInterface/DreamDaemon.cs | 45 ++++-------------- 6 files changed, 107 insertions(+), 178 deletions(-) diff --git a/TGCommandLine/DDCommands.cs b/TGCommandLine/DDCommands.cs index 63170b1e3d..ef41ff1ffd 100644 --- a/TGCommandLine/DDCommands.cs +++ b/TGCommandLine/DDCommands.cs @@ -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 ""; + } + + protected override ExitCode Run(IList parameters) + { + var res = Server.GetComponent().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 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().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 ""; - } - } - class DDSecurityCommand : Command { public DDSecurityCommand() diff --git a/TGControlPanel/Main.Designer.cs b/TGControlPanel/Main.Designer.cs index 20c4e75974..f998e2984d 100644 --- a/TGControlPanel/Main.Designer.cs +++ b/TGControlPanel/Main.Designer.cs @@ -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; } } diff --git a/TGControlPanel/ServerPage.cs b/TGControlPanel/ServerPage.cs index 97cf19924a..afa83ac31a 100644 --- a/TGControlPanel/ServerPage.cs +++ b/TGControlPanel/ServerPage.cs @@ -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(); var DD = Server.GetComponent(); @@ -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().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().WorldAnnounce(msg); + if(res != null) + { + MessageBox.Show(res); + return; + } + } + WorldAnnounceField.Text = ""; } } } diff --git a/TGServerService/DreamDaemon.cs b/TGServerService/DreamDaemon.cs index d523a3548b..9cdca9f1eb 100644 --- a/TGServerService/DreamDaemon.cs +++ b/TGServerService/DreamDaemon.cs @@ -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; } } + + /// + public string WorldAnnounce(string message) + { + var res = SendCommand(SCWorldAnnounce + ";message=" + message); + if (res == "SUCCESS") + return null; + return res; + } } } diff --git a/TGServerService/Interop.cs b/TGServerService/Interop.cs index e9a2b943ba..6d0652b7ec 100644 --- a/TGServerService/Interop.cs +++ b/TGServerService/Interop.cs @@ -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)); diff --git a/TGServiceInterface/DreamDaemon.cs b/TGServiceInterface/DreamDaemon.cs index 1d52ca5b41..a9e8ab6bd7 100644 --- a/TGServiceInterface/DreamDaemon.cs +++ b/TGServiceInterface/DreamDaemon.cs @@ -39,26 +39,7 @@ namespace TGServiceInterface /// Ultrasafe } - - /// - /// DreamDaemon's hub visibility - /// - public enum TGDreamDaemonVisibility - { - /// - /// Server will be visible on the hub - /// - Public, - /// - /// 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 - /// - Private, - /// - /// Server will not be visible on the hub - /// - Invisible = 2, //default config - } - + /// /// Interface for managing the actual BYOND game server /// @@ -140,22 +121,6 @@ namespace TGServiceInterface [OperationContract] bool SetSecurityLevel(TGDreamDaemonSecurity level); - /// - /// Get the configured (not running) visibility level - /// - /// The configured (not running) visibility level - [OperationContract] - TGDreamDaemonVisibility VisibilityLevel(); - - /// - /// Sets the visiblity level of the server. Requires reboot to apply - /// Implies a call to RequestRestart() - /// - /// The new visibility level - /// True if the change was immediately applied, false if a graceful restart was queued - [OperationContract] - bool SetVisibility(TGDreamDaemonVisibility vis); - /// /// Get the configured port. Not necessarily the running port if it has since changed /// @@ -191,5 +156,13 @@ namespace TGServiceInterface /// true if RequestStop has been called since the last server start, false otherwise [OperationContract] bool ShutdownInProgress(); + + /// + /// Sends a message to everyone on the server + /// + /// The message to send + /// null on success, error message on failure + [OperationContract] + string WorldAnnounce(string msg); } }