Now the old review config keys set the extra command permissions for /review. Also remove /news [player], /faq [player], /changelog [player].

This commit is contained in:
UnknownShadow200 2016-06-18 17:03:04 +10:00
parent b581b39acd
commit b1b2a9b1cb
8 changed files with 146 additions and 230 deletions

View File

@ -1,95 +1,46 @@
/*
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using System.IO;
using System.Linq;
namespace MCGalaxy.Commands
{
public sealed class CmdChangeLog : Command
{
namespace MCGalaxy.Commands {
public sealed class CmdChangeLog : Command {
public override string name { get { return "changelog"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Other; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public override CommandPerm[] AdditionalPerms {
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can send the changelog to everybody") }; }
public override void Use(Player p, string message) {
if (!File.Exists("changelog.txt")) { Player.Message(p, "Unable to find changelog"); return; }
using (StreamReader r = new StreamReader("changelog.txt")) {
string line = null;
while ((line = r.ReadLine()) != null) {
// a blank line is used to separate the changelog for different versions
if (line == "") return;
Player.Message(p, "&f" + line);
}
}
}
public override void Use(Player p, string message)
{
if (!File.Exists("changelog.txt"))
{
Player.Message(p, "Unable to find changelog");
return;
}
// Read the changelog but stop reading if it encounters a blank line
// This is done so that a player will only see the latest changes even if multiple version info exists in the changelog
// Because of this, its really important that blank lines are ONLY used to separate different versions
string[] strArray = File.ReadAllLines("changelog.txt").TakeWhile(s => !String.IsNullOrEmpty(s.Trim())).ToArray();
if (message == "")
{
for (int j = 0; j < strArray.Length; j++)
{
Player.Message(p, strArray[j]);
}
}
else
{
string[] split = message.Split(' ');
if(split.Length != 1)
{
Help(p);
return;
}
if (split[0] == "all")
{
if (!CheckExtraPerm(p)) { MessageNeedPerms(p, "can send the changelog to all players."); return; }
for (int k = 0; k < strArray.Length; k++)
{
Player.GlobalMessage(strArray[k]);
}
return;
}
else
{
Player player = PlayerInfo.FindMatches(p, split[0]);
if (player == null) return;
Player.Message(player, "Changelog:");
for (int l = 0; l < strArray.Length; l++)
{
Player.Message(player, strArray[l]);
}
Player.Message(p, "The Changelog was successfully sent to " + player.name + ".");
return;
}
}
}
public override void Help(Player p)
{
Player.Message(p, "/changelog - View the most recent changelog!!");
Player.Message(p, "/changelog <player> - Sends the most recent changelog to <player>!!");
Player.Message(p, "/changelog all - Sends the most recent changelog to everyone!!");
public override void Help(Player p) {
Player.Message(p, "/changelog - View the most recent changelog.");
}
}
}

View File

@ -17,39 +17,27 @@
*/
using System.Collections.Generic;
using System.IO;
namespace MCGalaxy.Commands {
public sealed class CmdFaq : Command {
namespace MCGalaxy.Commands {
public sealed class CmdFaq : Command {
public override string name { get { return "faq"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Information; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public override CommandPerm[] AdditionalPerms {
get { return new[] { new CommandPerm(LevelPermission.Builder, "+ can send the faq to other players") }; }
}
public override void Use(Player p, string message) {
if (!File.Exists("text/faq.txt")) {
CP437Writer.WriteAllText("text/faq.txt", "Example: What does this server run on? This server runs on &bMCGalaxy");
}
List<string> faq = CP437Reader.ReadAllLines("text/faq.txt");
Player who = p;
if (message != "") {
if (!CheckExtraPerm(p)) { MessageNeedPerms(p, "can send the FAQ to a player."); return; }
who = PlayerInfo.FindMatches(p, message);
if (who == null) return;
}
Player.Message(who, "&cFAQ&f:");
List<string> faq = CP437Reader.ReadAllLines("text/faq.txt");
Player.Message(p, "&cFAQ&f:");
foreach (string line in faq)
Player.Message(who, "&f" + line);
Player.Message(p, "&f" + line);
}
public override void Help(Player p) {
Player.Message(p, "/faq [player]- Displays frequently asked questions");
Player.Message(p, "/faq - Displays frequently asked questions");
}
}
}

View File

@ -18,18 +18,13 @@
using System.Collections.Generic;
using System.IO;
namespace MCGalaxy.Commands
{
public sealed class CmdNews : Command
{
namespace MCGalaxy.Commands {
public sealed class CmdNews : Command {
public override string name { get { return "news"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Information; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public override CommandPerm[] AdditionalPerms {
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can send the news to everyone") }; }
}
const string newsFile = "text/news.txt";
public override void Use(Player p, string message) {
@ -38,31 +33,12 @@ namespace MCGalaxy.Commands
}
List<string> lines = CP437Reader.ReadAllLines(newsFile);
if (message == "") {
foreach (string line in lines)
Player.Message(p, line);
return;
}
string[] args = message.Split(' ');
if (args[0] == "all") {
if (!CheckExtraPerm(p)) { MessageNeedPerms(p, "can send the server news to all players."); return; }
foreach (string line in lines)
Player.GlobalMessage(line);
return;
}
Player who = PlayerInfo.FindMatches(p, args[0]);
if (who == null) return;
foreach (string line in lines)
Player.Message(who, line);
Player.Message(p, "The News were successfully sent to " + who.name + ".");
Player.Message(p, line);
}
public override void Help(Player p) {
Player.Message(p, "/news - Shows server news.");
Player.Message(p, "/news <player> - Sends the News to <player>.");
Player.Message(p, "/news all - Sends the News to everyone.");
}
}
}

View File

@ -37,7 +37,8 @@ namespace MCGalaxy {
}
Server.salt = sb.ToString();
if (PropertiesFile.Read(givenPath, LineProcessor))
reviewPerms = new ReviewPerms();
if (PropertiesFile.Read(givenPath, ref reviewPerms, LineProcessor))
Server.s.SettingsUpdate();
if (!Directory.Exists(Server.backupLocation))
@ -46,10 +47,27 @@ namespace MCGalaxy {
Save(givenPath);
}
static void LineProcessor(string key, string value) {
if (!ConfigElement.Parse(Server.serverConfig, key, value, null))
Server.s.Log("\"" + key + "\" was not a recognised config key.");
}
static void LineProcessor(string key, string value, ref ReviewPerms perms) {
switch (key.ToLower()) {
// Backwards compatibility with old config, where review permissions where global
case "review-enter-perm":
case "review-leave-perm":
break;
case "review-view-perm":
perms.viewPerm = int.Parse(value); break;
case "review-next-perm":
perms.nextPerm = int.Parse(value); break;
case "review-clear-perm":
perms.clearPerm = int.Parse(value); break;
default:
if (!ConfigElement.Parse(Server.serverConfig, key, value, null))
Server.s.Log("\"" + key + "\" was not a recognised level property key.");
break;
}
}
internal static ReviewPerms reviewPerms;
internal class ReviewPerms { public int viewPerm = -1, nextPerm = -1, clearPerm = -1; }
public static void Save() { Save("properties/server.properties"); }

View File

@ -371,8 +371,6 @@ namespace MCGalaxy.Gui
this.listPasswords = new System.Windows.Forms.ListBox();
this.label39 = new System.Windows.Forms.Label();
this.label38 = new System.Windows.Forms.Label();
this.pageReview = new System.Windows.Forms.TabPage();
this.gbReviewOptions = new System.Windows.Forms.GroupBox();
this.nudCooldownTime = new System.Windows.Forms.NumericUpDown();
this.label84 = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
@ -458,8 +456,6 @@ namespace MCGalaxy.Gui
((System.ComponentModel.ISupportInitialize)(this.numSpamMute)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numSpamMessages)).BeginInit();
this.gbPasswords.SuspendLayout();
this.pageReview.SuspendLayout();
this.gbReviewOptions.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudCooldownTime)).BeginInit();
this.chat_gbTab.SuspendLayout();
this.SuspendLayout();
@ -916,7 +912,7 @@ namespace MCGalaxy.Gui
this.pageCommandsCustom.Padding = new System.Windows.Forms.Padding(3);
this.pageCommandsCustom.Size = new System.Drawing.Size(468, 476);
this.pageCommandsCustom.TabIndex = 1;
this.pageCommandsCustom.Text = "Custom Commands";
this.pageCommandsCustom.Text = "Custom commands";
//
// lblLoadedCommands
//
@ -925,7 +921,7 @@ namespace MCGalaxy.Gui
this.lblLoadedCommands.Name = "lblLoadedCommands";
this.lblLoadedCommands.Size = new System.Drawing.Size(97, 13);
this.lblLoadedCommands.TabIndex = 40;
this.lblLoadedCommands.Text = "Loaded Commands";
this.lblLoadedCommands.Text = "Loaded commands";
//
// lstCommands
//
@ -947,7 +943,7 @@ namespace MCGalaxy.Gui
this.groupBox24.Size = new System.Drawing.Size(459, 100);
this.groupBox24.TabIndex = 38;
this.groupBox24.TabStop = false;
this.groupBox24.Text = "Quick Command";
this.groupBox24.Text = "Quick command";
//
// panel1
//
@ -994,7 +990,7 @@ namespace MCGalaxy.Gui
this.btnCreate.Name = "btnCreate";
this.btnCreate.Size = new System.Drawing.Size(149, 23);
this.btnCreate.TabIndex = 29;
this.btnCreate.Text = "Create Command";
this.btnCreate.Text = "Create command";
this.btnCreate.UseVisualStyleBackColor = true;
this.btnCreate.Click += new System.EventHandler(this.btnCreate_Click);
//
@ -1058,7 +1054,7 @@ namespace MCGalaxy.Gui
this.pageCommandPerms.Name = "pageCommandPerms";
this.pageCommandPerms.Size = new System.Drawing.Size(468, 476);
this.pageCommandPerms.TabIndex = 2;
this.pageCommandPerms.Text = "Additional Command Permissions";
this.pageCommandPerms.Text = "Extra command permissions";
//
// txtcmdranks2
//
@ -1085,7 +1081,7 @@ namespace MCGalaxy.Gui
this.label73.Name = "label73";
this.label73.Size = new System.Drawing.Size(179, 13);
this.label73.TabIndex = 44;
this.label73.Text = "Command Extra Permission Number:";
this.label73.Text = "Extra permission number:";
//
// extracmdpermnumber
//
@ -2195,28 +2191,56 @@ namespace MCGalaxy.Gui
this.buttonEco.Text = "Economy Settings";
this.buttonEco.UseVisualStyleBackColor = true;
this.buttonEco.Click += new System.EventHandler(this.buttonEco_Click);
//
// grpExtra
//
this.grpExtra.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.grpExtra.Controls.Add(this.lblOsMap);
this.grpExtra.Controls.Add(this.cmbOsMap);
this.grpExtra.Controls.Add(this.chkGuestLimitNotify);
this.grpExtra.Controls.Add(this.chkShowEmptyRanks);
this.grpExtra.Controls.Add(this.chkRepeatMessages);
this.grpExtra.Controls.Add(this.chkDeath);
this.grpExtra.Controls.Add(this.txtRestartTime);
this.grpExtra.Controls.Add(this.txtMoneys);
this.grpExtra.Controls.Add(this.chkRestartTime);
this.grpExtra.Controls.Add(this.chk17Dollar);
this.grpExtra.Controls.Add(this.chkSmile);
this.grpExtra.Controls.Add(this.label34);
this.grpExtra.Location = new System.Drawing.Point(10, 158);
this.grpExtra.Name = "grpExtra";
this.grpExtra.Size = new System.Drawing.Size(332, 234);
this.grpExtra.TabIndex = 40;
this.grpExtra.TabStop = false;
this.grpExtra.Text = "Extra";
//
// grpExtra
//
this.grpExtra.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.grpExtra.Controls.Add(this.nudCooldownTime);
this.grpExtra.Controls.Add(this.label84);
this.grpExtra.Controls.Add(this.lblOsMap);
this.grpExtra.Controls.Add(this.cmbOsMap);
this.grpExtra.Controls.Add(this.chkGuestLimitNotify);
this.grpExtra.Controls.Add(this.chkShowEmptyRanks);
this.grpExtra.Controls.Add(this.chkRepeatMessages);
this.grpExtra.Controls.Add(this.chkDeath);
this.grpExtra.Controls.Add(this.txtRestartTime);
this.grpExtra.Controls.Add(this.txtMoneys);
this.grpExtra.Controls.Add(this.chkRestartTime);
this.grpExtra.Controls.Add(this.chk17Dollar);
this.grpExtra.Controls.Add(this.chkSmile);
this.grpExtra.Controls.Add(this.label34);
this.grpExtra.Location = new System.Drawing.Point(10, 158);
this.grpExtra.Name = "grpExtra";
this.grpExtra.Size = new System.Drawing.Size(332, 270);
this.grpExtra.TabIndex = 40;
this.grpExtra.TabStop = false;
this.grpExtra.Text = "Extra";
//
// nudCooldownTime
//
this.nudCooldownTime.Location = new System.Drawing.Point(143, 234);
this.nudCooldownTime.Maximum = new decimal(new int[] {
86400,
0,
0,
0});
this.nudCooldownTime.Name = "nudCooldownTime";
this.nudCooldownTime.Size = new System.Drawing.Size(57, 21);
this.nudCooldownTime.TabIndex = 50;
this.nudCooldownTime.Value = new decimal(new int[] {
600,
0,
0,
0});
//
// label84
//
this.label84.AutoSize = true;
this.label84.Location = new System.Drawing.Point(23, 238);
this.label84.Name = "label84";
this.label84.Size = new System.Drawing.Size(115, 13);
this.label84.TabIndex = 49;
this.label84.Text = "Review cooldown time:";
//
// lblOsMap
//
@ -3039,7 +3063,6 @@ namespace MCGalaxy.Gui
this.tabControl.Controls.Add(this.pageCommands);
this.tabControl.Controls.Add(this.pageBlocks);
this.tabControl.Controls.Add(this.pageSecurity);
this.tabControl.Controls.Add(this.pageReview);
this.tabControl.Font = new System.Drawing.Font("Calibri", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.tabControl.Location = new System.Drawing.Point(0, 0);
this.tabControl.Name = "tabControl";
@ -4102,54 +4125,6 @@ namespace MCGalaxy.Gui
this.label38.TabIndex = 1;
this.label38.Text = "Rank:\r\n\r\n\r\n";
//
// pageReview
//
this.pageReview.BackColor = System.Drawing.Color.Transparent;
this.pageReview.Controls.Add(this.gbReviewOptions);
this.pageReview.Location = new System.Drawing.Point(4, 22);
this.pageReview.Name = "pageReview";
this.pageReview.Padding = new System.Windows.Forms.Padding(3);
this.pageReview.Size = new System.Drawing.Size(498, 521);
this.pageReview.TabIndex = 9;
this.pageReview.Text = "Review";
//
// gbReviewOptions
//
this.gbReviewOptions.Controls.Add(this.nudCooldownTime);
this.gbReviewOptions.Controls.Add(this.label84);
this.gbReviewOptions.Location = new System.Drawing.Point(154, 235);
this.gbReviewOptions.Name = "gbReviewOptions";
this.gbReviewOptions.Size = new System.Drawing.Size(328, 51);
this.gbReviewOptions.TabIndex = 4;
this.gbReviewOptions.TabStop = false;
this.gbReviewOptions.Text = "Options";
//
// nudCooldownTime
//
this.nudCooldownTime.Location = new System.Drawing.Point(202, 19);
this.nudCooldownTime.Maximum = new decimal(new int[] {
86400,
0,
0,
0});
this.nudCooldownTime.Name = "nudCooldownTime";
this.nudCooldownTime.Size = new System.Drawing.Size(120, 21);
this.nudCooldownTime.TabIndex = 1;
this.nudCooldownTime.Value = new decimal(new int[] {
600,
0,
0,
0});
//
// label84
//
this.label84.AutoSize = true;
this.label84.Location = new System.Drawing.Point(7, 21);
this.label84.Name = "label84";
this.label84.Size = new System.Drawing.Size(77, 13);
this.label84.TabIndex = 0;
this.label84.Text = "Cooldown time";
//
// chat_gbTab
//
this.chat_gbTab.Controls.Add(this.chat_cbTabRank);
@ -4324,9 +4299,6 @@ namespace MCGalaxy.Gui
((System.ComponentModel.ISupportInitialize)(this.numSpamMessages)).EndInit();
this.gbPasswords.ResumeLayout(false);
this.gbPasswords.PerformLayout();
this.pageReview.ResumeLayout(false);
this.gbReviewOptions.ResumeLayout(false);
this.gbReviewOptions.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudCooldownTime)).EndInit();
this.chat_gbTab.ResumeLayout(false);
this.chat_gbTab.PerformLayout();
@ -4600,8 +4572,6 @@ namespace MCGalaxy.Gui
private System.Windows.Forms.Label label76;
private System.Windows.Forms.ComboBox cmbAFKKickPerm;
private System.Windows.Forms.CheckBox chkGuestLimitNotify;
private System.Windows.Forms.TabPage pageReview;
private System.Windows.Forms.GroupBox gbReviewOptions;
private System.Windows.Forms.NumericUpDown nudCooldownTime;
private System.Windows.Forms.Label label84;
private System.Windows.Forms.Label lblMOTD;

View File

@ -196,6 +196,9 @@ namespace MCGalaxy.Gui {
}
if ( listCommands.SelectedIndex == -1 )
listCommands.SelectedIndex = 0;
// Sort the commands list
listCommands.Sorted = true;
listCommands.Sorted = false;
}
public void SaveCommands() {
GrpCommands.Save(storedCommands);
@ -1294,6 +1297,8 @@ txtBackupLocation.Text = folderDialog.SelectedPath;
listCommandsExtraCmdPerms.Items.Add(cmd.name);
}
}
listCommandsExtraCmdPerms.Sorted = true;
listCommandsExtraCmdPerms.Sorted = false;
}
private void txtGrpMOTD_TextChanged(object sender, EventArgs e) {

View File

@ -589,7 +589,10 @@ namespace MCGalaxy {
}
void CheckReviewList() {
if (group.Permission < Server.reviewview || !group.CanExecute("review")) return;
Command cmd = Command.all.Find("review");
int perm = CommandOtherPerms.GetPerm(cmd, 1);
if ((int)group.Permission < perm || !group.commands.Contains(cmd)) return;
int count = Server.reviewlist.Count;
if (count == 0) return;

View File

@ -376,19 +376,8 @@ namespace MCGalaxy
[ConfigBool("show-empty-ranks", "Other", null, false)]
public static bool showEmptyRanks = false;
//reviewoptions intitialize
[ConfigInt("review-cooldown", "Review", null, 600)]
public static int reviewcooldown = 600;
[ConfigPerm("review-enter-perm", "Review", null, LevelPermission.Guest)]
public static LevelPermission reviewenter = LevelPermission.Guest;
[ConfigPerm("review-leave-perm", "Review", null, LevelPermission.Guest)]
public static LevelPermission reviewleave = LevelPermission.Guest;
[ConfigPerm("review-view-perm", "Review", null, LevelPermission.Operator)]
public static LevelPermission reviewview = LevelPermission.Operator;
[ConfigPerm("review-next-perm", "Review", null, LevelPermission.Operator)]
public static LevelPermission reviewnext = LevelPermission.Operator;
[ConfigPerm("review-clear-perm", "Review", null, LevelPermission.Operator)]
public static LevelPermission reviewclear = LevelPermission.Operator;
[ConfigInt("draw-reload-limit", "Other", null, 10000)]
public static int DrawReloadLimit = 10000;
@ -647,6 +636,22 @@ namespace MCGalaxy
ProfanityFilter.Init();
Team.LoadList();
Chat.LoadCustomTokens();
FixupOldReviewPerms();
}
static void FixupOldReviewPerms() {
Command cmd = Command.all.Find("review");
var perms = SrvProperties.reviewPerms;
if (perms.clearPerm == -1 && perms.nextPerm == -1 && perms.viewPerm == -1) return;
// Backwards compatibility with old config, where review permissions where global
if (perms.viewPerm != -1)
CommandOtherPerms.Edit(CommandOtherPerms.Find(cmd, 1), perms.viewPerm);
if (perms.nextPerm != -1)
CommandOtherPerms.Edit(CommandOtherPerms.Find(cmd, 2), perms.nextPerm);
if (perms.clearPerm != -1)
CommandOtherPerms.Edit(CommandOtherPerms.Find(cmd, 3), perms.clearPerm);
CommandOtherPerms.Save();
}
public static void Setup()