mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Now with less LINQ usage.
This commit is contained in:
parent
9b1fc58bfe
commit
8a7ed8637f
@ -16,11 +16,9 @@
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
namespace MCGalaxy
|
||||
{
|
||||
public sealed class CommandList
|
||||
{
|
||||
|
||||
namespace MCGalaxy {
|
||||
public sealed class CommandList {
|
||||
public List<Command> commands = new List<Command>();
|
||||
public bool AddOtherPerms = false;
|
||||
|
||||
@ -54,7 +52,10 @@ namespace MCGalaxy
|
||||
|
||||
public Command Find(string name) {
|
||||
name = name.ToLower();
|
||||
return commands.FirstOrDefault(cmd => cmd.name == name || cmd.shortcut == name);
|
||||
foreach (Command cmd in commands) {
|
||||
if (cmd.name == name || cmd.shortcut == name) return cmd;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public string FindShort(string shortcut) {
|
||||
|
@ -18,10 +18,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace MCGalaxy {
|
||||
|
||||
namespace MCGalaxy {
|
||||
/// <summary> These are extra permissions for certain commands </summary>
|
||||
public static class CommandOtherPerms {
|
||||
|
||||
@ -43,7 +41,10 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
public static OtherPerms Find(Command cmd, int number = 1) {
|
||||
return list.FirstOrDefault(OtPe => OtPe.cmd == cmd && OtPe.number == number);
|
||||
foreach (OtherPerms perms in list) {
|
||||
if (perms.cmd == cmd && perms.number == number) return perms;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void Add(Command command, int Perm, string desc, int number = 1) {
|
||||
|
@ -17,7 +17,6 @@
|
||||
*/
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace MCGalaxy.Commands {
|
||||
@ -72,8 +71,8 @@ namespace MCGalaxy.Commands {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Level[] loaded = LevelInfo.Loaded.Items;
|
||||
for (int i = start; i < end; i++) {
|
||||
string level = Path.GetFileNameWithoutExtension(files[i]);
|
||||
if (!all && loaded.Any(l => l.name.CaselessEq(level))) continue;
|
||||
string level = Path.GetFileNameWithoutExtension(files[i]);
|
||||
if (!all && IsLoaded(loaded, level)) continue;
|
||||
|
||||
LevelPermission visitP, buildP;
|
||||
bool loadOnGoto;
|
||||
@ -85,6 +84,13 @@ namespace MCGalaxy.Commands {
|
||||
return builder;
|
||||
}
|
||||
|
||||
static bool IsLoaded(Level[] loaded, string level) {
|
||||
foreach (Level lvl in loaded) {
|
||||
if (lvl.name.CaselessEq(level)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void RetrieveProps(string level, out LevelPermission visit,
|
||||
out LevelPermission build, out bool loadOnGoto) {
|
||||
visit = LevelPermission.Guest;
|
||||
|
@ -2,28 +2,26 @@
|
||||
Written by Jack1312
|
||||
|
||||
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.
|
||||
|
||||
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.Collections.Generic;
|
||||
using System.Linq;
|
||||
namespace MCGalaxy.Commands
|
||||
{
|
||||
public sealed class CmdPatrol : Command
|
||||
{
|
||||
|
||||
namespace MCGalaxy.Commands {
|
||||
public sealed class CmdPatrol : Command {
|
||||
public override string name { get { return "patrol"; } }
|
||||
public override string shortcut { get { return ""; } }
|
||||
public override string type { get { return CommandTypes.Moderation; } }
|
||||
@ -32,28 +30,33 @@ namespace MCGalaxy.Commands
|
||||
public override CommandPerm[] ExtraPerms {
|
||||
get { return new[] { new CommandPerm(LevelPermission.Guest, " and below are patrolled") }; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void Use(Player p, string message)
|
||||
{
|
||||
if (Player.IsSuper(p)) { MessageInGameOnly(p); return; }
|
||||
public override void Use(Player p, string message) {
|
||||
if (Player.IsSuper(p)) { MessageInGameOnly(p); return; }
|
||||
if (message != "") { Help(p); return; }
|
||||
|
||||
List<string> getpatrol = (from pl in PlayerInfo.players where (int) pl.@group.Permission <= CommandOtherPerms.GetPerm(this) select pl.name).ToList();
|
||||
if (getpatrol.Count <= 0)
|
||||
{
|
||||
Player.Message(p, "There must be at least one guest online to use this command!");
|
||||
return;
|
||||
List<string> getpatrol = FindToPatrol();
|
||||
if (getpatrol.Count <= 0) {
|
||||
Player.Message(p, "There must be at least one guest online to use this command!"); return;
|
||||
}
|
||||
Random random = new Random();
|
||||
int index = random.Next(getpatrol.Count);
|
||||
string value = getpatrol[index];
|
||||
|
||||
string value = getpatrol[new Random().Next(getpatrol.Count)];
|
||||
Player who = PlayerInfo.FindExact(value);
|
||||
Command.all.Find("tp").Use(p, who.name);
|
||||
Player.Message(p, "Now visiting " + who.ColoredName + "%S.");
|
||||
}
|
||||
|
||||
List<string> FindToPatrol() {
|
||||
List<string> players = new List<string>();
|
||||
int perm = CommandOtherPerms.GetPerm(this);
|
||||
Player[] online = PlayerInfo.Online.Items;
|
||||
|
||||
foreach (Player p in online) {
|
||||
if ((int)p.Rank <= perm) players.Add(p.name);
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/patrol");
|
||||
Player.Message(p, "%HTeleports you to a random " + Group.findPermInt(CommandOtherPerms.GetPerm(this)).name + " or lower");
|
||||
|
@ -17,7 +17,6 @@
|
||||
*/
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
@ -17,7 +17,6 @@
|
||||
*/
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
@ -38,13 +37,13 @@ namespace MCGalaxy.Util {
|
||||
plainText = plainText.Replace(">", ")");
|
||||
|
||||
MD5 hash = MD5.Create();
|
||||
|
||||
byte[] textBuffer = Encoding.ASCII.GetBytes(plainText);
|
||||
byte[] saltBuffer = Encoding.ASCII.GetBytes(salt);
|
||||
|
||||
byte[] hashedTextBuffer = hash.ComputeHash(textBuffer);
|
||||
byte[] hashedSaltBuffer = hash.ComputeHash(saltBuffer);
|
||||
return hash.ComputeHash(hashedSaltBuffer.Concat(hashedTextBuffer).ToArray());
|
||||
byte[] saltB = hash.ComputeHash(Encoding.ASCII.GetBytes(salt));
|
||||
byte[] textB = hash.ComputeHash(Encoding.ASCII.GetBytes(plainText));
|
||||
|
||||
byte[] data = new byte[saltB.Length + textB.Length];
|
||||
Array.Copy(saltB, 0, data, 0, saltB.Length);
|
||||
Array.Copy(textB, 0, data, saltB.Length, textB.Length);
|
||||
return hash.ComputeHash(data);
|
||||
}
|
||||
|
||||
internal static void StoreHash(string salt, string plainText) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user