Skip to content

Commit

Permalink
Mostly move Review to an internal module
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Dec 15, 2023
1 parent abfdcdf commit ee7718b
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 44 deletions.
12 changes: 7 additions & 5 deletions MCGalaxy/Chat/Colors.cs
Expand Up @@ -158,7 +158,8 @@ public static class Colors {
char[] chars = new char[value.Length];
for (int i = 0; i < chars.Length; i++) { chars[i] = value[i]; }

for (int i = 0; i < chars.Length;) {
for (int i = 0; i < chars.Length;)
{
int end = value.IndexOf(' ', i);
if (end == -1) end = value.Length;

Expand All @@ -169,14 +170,14 @@ public static class Colors {
}

static bool IsUrlAt(char[] chars, int i, int len) {
const int prefixLen = 7; // "http://".Length
if (len < prefixLen) return false;
const int PREFIX_LEN = 7; // "http://".Length
if (len < PREFIX_LEN) return false;

// skip color codes in url
while (len > 0 && chars[i] == '&') { len -= 2; i += 2; }

// Starts with "http" ?
if (len < prefixLen) return false;
if (len < PREFIX_LEN) return false;
if (chars[i] != 'h' || chars[i + 1] != 't' || chars[i + 2] != 't' || chars[i + 3] != 'p') return false;
len -= 4; i += 4;

Expand Down Expand Up @@ -230,7 +231,8 @@ public static class Colors {
char[] output = new char[message.Length];
int usedChars = 0;

for (int i = 0; i < message.Length; i++) {
for (int i = 0; i < message.Length; i++)
{
char c = message[i];
if ((c == '%' || c == '&') && UsedColor(message, i)) {
i++; // Skip over the following color code
Expand Down
13 changes: 0 additions & 13 deletions MCGalaxy/CorePlugin/ConnectHandler.cs
Expand Up @@ -22,24 +22,11 @@ namespace MCGalaxy.Core {
internal static class ConnectHandler {

internal static void HandleConnect(Player p) {
CheckReviewList(p);
if (p.CanUse("ReachDistance")) LoadReach(p);

p.Ignores.Load(p);
}

static void CheckReviewList(Player p) {
if (!p.CanUse("Review")) return;
ItemPerms checkPerms = CommandExtraPerms.Find("Review", 1);
if (!checkPerms.UsableBy(p)) return;

int count = Server.reviewlist.Count;
if (count == 0) return;

string suffix = count == 1 ? " player is " : " players are ";
p.Message(count + suffix + "waiting for a review. Type &T/Review view");
}

static void LoadReach(Player p) {
string reach = Server.reach.Get(p.name);
if (String.IsNullOrEmpty(reach)) return;
Expand Down
4 changes: 3 additions & 1 deletion MCGalaxy/MCGalaxy_.csproj
Expand Up @@ -265,7 +265,6 @@
<Compile Include="Commands\Moderation\CmdPossess.cs" />
<Compile Include="Commands\Moderation\CmdReport.cs" />
<Compile Include="Commands\Moderation\CmdRestoreSelection.cs" />
<Compile Include="Commands\Moderation\CmdReview.cs" />
<Compile Include="Commands\Moderation\CmdSetRank.cs" />
<Compile Include="Commands\Moderation\CmdTempBan.cs" />
<Compile Include="Commands\Moderation\CmdTempRank.cs" />
Expand Down Expand Up @@ -591,6 +590,8 @@
<Compile Include="Modules\Games\ZombieSurvival\ZSPlugin.cs" />
<Compile Include="Modules\Moderation\Notes\CmdNotes.cs" />
<Compile Include="Modules\Moderation\Notes\NotesPlugin.cs" />
<Compile Include="Modules\Moderation\Review\CmdReview.cs" />
<Compile Include="Modules\Moderation\Review\ReviewPlugin.cs" />
<Compile Include="Modules\Relay\BotControllersCmd.cs" />
<Compile Include="Modules\Relay\Discord\DiscordApiClient.cs" />
<Compile Include="Modules\Relay\Discord\DiscordBot.cs" />
Expand Down Expand Up @@ -713,6 +714,7 @@
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="Modules\Moderation\Review" />
<Folder Include="Modules\Warps" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
Expand Down
Expand Up @@ -20,10 +20,13 @@
*/
using System;
using System.Collections.Generic;
using MCGalaxy.Commands;
using MCGalaxy.Events.PlayerEvents;

namespace MCGalaxy.Commands.Moderation {
public sealed class CmdReview : Command2 {
namespace MCGalaxy.Modules.Moderation.Review
{
class CmdReview : Command2
{
public override string name { get { return "Review"; } }
public override string shortcut { get { return "rvw"; } }
public override string type { get { return CommandTypes.Moderation; } }
Expand Down Expand Up @@ -100,7 +103,8 @@ public sealed class CmdReview : Command2 {

p.Message("&9Players in the review queue:");
int pos = 1;
foreach (string name in inQueue) {
foreach (string name in inQueue)
{
Group grp = PlayerInfo.GetGroup(name);
p.Message("&a" + pos + ". &f" + name + " &a- Current Rank: " + grp.ColoredName);
pos++;
Expand Down Expand Up @@ -144,12 +148,13 @@ public sealed class CmdReview : Command2 {
Server.reviewlist.Clear();
p.Message("The review queue has been cleared");
}


static void AnnounceQueueChanged() {
List<string> inQueue = Server.reviewlist.All();
int pos = 1;

foreach (string name in inQueue) {
foreach (string name in inQueue)
{
Player who = PlayerInfo.FindExact(name);
if (who == null) continue;

Expand All @@ -161,7 +166,7 @@ public sealed class CmdReview : Command2 {
public override void Help(Player p) {
p.Message("&T/Review enter/view/leave/next/clear");
p.Message("&HLets you enter, view, leave, or clear the review queue, or " +
"teleport you to the next player in the review queue.");
"teleport you to the next player in the review queue.");
}
}
}
54 changes: 54 additions & 0 deletions MCGalaxy/Modules/Moderation/Review/ReviewPlugin.cs
@@ -0,0 +1,54 @@
/*
Copyright 2015 MCGalaxy
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
https://opensource.org/license/ecl-2-0/
https://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 MCGalaxy.Commands;
using MCGalaxy.Events;
using MCGalaxy.Events.PlayerEvents;

namespace MCGalaxy.Modules.Moderation.Review
{
public sealed class ReviewPlugin : Plugin
{
public override string name { get { return "Review"; } }

Command cmdReview = new CmdReview();

public override void Load(bool startup) {
OnPlayerConnectEvent.Register(CheckReviewList, Priority.Low);
Command.Register(cmdReview);
}

public override void Unload(bool shutdown) {
OnPlayerConnectEvent.Unregister(CheckReviewList);
Command.Unregister(cmdReview);
}


static void CheckReviewList(Player p) {
if (!p.CanUse("Review")) return;
ItemPerms checkPerms = CommandExtraPerms.Find("Review", 1);
if (!checkPerms.UsableBy(p)) return;

int count = Server.reviewlist.Count;
if (count == 0) return;

string suffix = count == 1 ? " player is " : " players are ";
p.Message(count + suffix + "waiting for a review. Type &T/Review view");
}
}
}
7 changes: 4 additions & 3 deletions MCGalaxy/Scripting/Plugin.cs
Expand Up @@ -126,14 +126,15 @@ public abstract class Plugin
public static void LoadAll() {
LoadCorePlugin(new CorePlugin());

LoadCorePlugin(new MCGalaxy.Modules.Moderation.Review.ReviewPlugin());
LoadCorePlugin(new MCGalaxy.Modules.Moderation.Notes.NotesPlugin());
LoadCorePlugin(new MCGalaxy.Modules.Relay.Discord.DiscordPlugin());
LoadCorePlugin(new MCGalaxy.Modules.Relay.IRC.IRCPlugin());
LoadCorePlugin(new MCGalaxy.Modules.Security.IPThrottler());
LoadCorePlugin(new MCGalaxy.Modules.Security.IPThrottler());
LoadCorePlugin(new MCGalaxy.Modules.Warps.WarpsPlugin());
#if !MCG_STANDALONE
LoadCorePlugin(new MCGalaxy.Modules.Compiling.CompilerPlugin());
LoadCorePlugin(new MCGalaxy.Modules.Compiling.CompilerPlugin());
#endif
LoadCorePlugin(new MCGalaxy.Modules.Warps.WarpsPlugin());

LoadCorePlugin(new MCGalaxy.Modules.Games.Countdown.CountdownPlugin());
LoadCorePlugin(new MCGalaxy.Modules.Games.CTF.CTFPlugin());
Expand Down
20 changes: 4 additions & 16 deletions MCGalaxy/Server/ServerProperties.cs
Expand Up @@ -44,13 +44,7 @@ public static class SrvProperties
static void LineProcessor(string key, string value, ref OldPerms perms) {
// Backwards compatibility: some command extra permissions used to be part of server.properties
// Backwards compatibility: map generation volume used to be part of server.properties
if (key.CaselessEq("review-view-perm")) {
perms.viewPerm = int.Parse(value);
} else if (key.CaselessEq("review-next-perm")) {
perms.nextPerm = int.Parse(value);
} else if (key.CaselessEq("review-clear-perm")) {
perms.clearPerm = int.Parse(value);
} else if (key.CaselessEq("opchat-perm")) {
if (key.CaselessEq("opchat-perm")) {
perms.opchatPerm = int.Parse(value);
} else if (key.CaselessEq("adminchat-perm")) {
perms.adminchatPerm = int.Parse(value);
Expand All @@ -70,7 +64,7 @@ public static class SrvProperties

static OldPerms old;
class OldPerms {
public int viewPerm = -1, nextPerm = -1, clearPerm = -1, opchatPerm = -1, adminchatPerm = -1;
public int opchatPerm = -1, adminchatPerm = -1;
public int mapGenLimit = -1, mapGenLimitAdmin = -1;
public int afkKickMins = -1; public LevelPermission afkKickMax = LevelPermission.Banned;
}
Expand All @@ -87,20 +81,14 @@ class OldPerms {
}

static void SetOldReview() {
if (old.clearPerm == -1 && old.nextPerm == -1 && old.viewPerm == -1
&& old.opchatPerm == -1 && old.adminchatPerm == -1) return;
if (old.opchatPerm == -1 && old.adminchatPerm == -1) return;

// Apply backwards compatibility
if (old.viewPerm != -1)
CommandExtraPerms.Find("Review", 1).MinRank = (LevelPermission)old.viewPerm;
if (old.nextPerm != -1)
CommandExtraPerms.Find("Review", 2).MinRank = (LevelPermission)old.nextPerm;
if (old.clearPerm != -1)
CommandExtraPerms.Find("Review", 3).MinRank = (LevelPermission)old.clearPerm;
if (old.opchatPerm != -1)
Chat.OpchatPerms.MinRank = (LevelPermission)old.opchatPerm;
if (old.adminchatPerm != -1)
Chat.AdminchatPerms.MinRank = (LevelPermission)old.adminchatPerm;

CommandExtraPerms.Save();
}

Expand Down

0 comments on commit ee7718b

Please sign in to comment.