More proper checking for CanSee, combine /hide and /xhide's code.

This commit is contained in:
UnknownShadow200 2016-03-14 21:57:44 +11:00
parent c76d8edb82
commit f202f68a8b
10 changed files with 134 additions and 206 deletions

View File

@ -20,7 +20,7 @@ using System.Globalization;
using System.Threading;
using MCGalaxy.SQL;
namespace MCGalaxy.Commands {
/// <summary> Economy Beta v1.0 QuantumHive </summary>
public sealed class CmdEconomy : Command {
public override string name { get { return "economy"; } }
@ -38,10 +38,10 @@ namespace MCGalaxy.Commands {
for (int i = 0; i < raw.Length; i++)
args[i] = i < 2 ? raw[i].ToLower() : raw[i];
if (args[0] == "setup")
HandleSetup(p, message, args);
if (args[0] == "setup")
HandleSetup(p, message, args);
else
Help(p);
Help(p);
}
void HandleSetup(Player p, string message, string[] args) {
@ -143,8 +143,8 @@ namespace MCGalaxy.Commands {
if (!int.TryParse(args[5], out newPrice)) {
Player.SendMessage(p, "%cInvalid amount of %3" + Server.moneys); return;
}
if (newPrice < 0) {
Player.SendMessage(p, "%cAmount of %3" + Server.moneys + "%c cannot be negative"); return;
if (newPrice < 0) {
Player.SendMessage(p, "%cAmount of %3" + Server.moneys + "%c cannot be negative"); return;
}
lvl.price = newPrice;
Player.SendMessage(p, "%aSuccessfully changed preset price to %f" + lvl.price + " %3" + Server.moneys);
@ -157,10 +157,12 @@ namespace MCGalaxy.Commands {
break;
case "enable":
if (Economy.Settings.Levels) { Player.SendMessage(p, "%cMaps are already enabled for the economy system"); break; } else { Economy.Settings.Levels = true; Player.SendMessage(p, "%aMaps are now enabled for the economy system"); break; }
if (Economy.Settings.Levels) { Player.SendMessage(p, "%cMaps are already enabled for the economy system"); break; }
else { Economy.Settings.Levels = true; Player.SendMessage(p, "%aMaps are now enabled for the economy system"); break; }
case "disable":
if (Economy.Settings.Levels == false) { Player.SendMessage(p, "%cMaps are already disabled for the economy system"); break; } else { Economy.Settings.Levels = false; Player.SendMessage(p, "%aMaps are now disabled for the economy system"); break; }
if (!Economy.Settings.Levels) { Player.SendMessage(p, "%cMaps are already disabled for the economy system"); break; }
else { Economy.Settings.Levels = false; Player.SendMessage(p, "%aMaps are now disabled for the economy system"); break; }
default:
Player.SendMessage(p, "%cThat wasn't a valid command addition!");
@ -242,43 +244,44 @@ namespace MCGalaxy.Commands {
case "rank":
switch (args[2]) {
case "enable":
if (Economy.Settings.Ranks) { Player.SendMessage(p, "%cRanks are already enabled for the economy system"); break; } else { Economy.Settings.Ranks = true; Player.SendMessage(p, "%aRanks are now enabled for the economy system"); break; }
if (Economy.Settings.Ranks) { Player.SendMessage(p, "%cRanks are already enabled for the economy system"); break; }
else { Economy.Settings.Ranks = true; Player.SendMessage(p, "%aRanks are now enabled for the economy system"); break; }
case "disable":
if (Economy.Settings.Ranks == false) { Player.SendMessage(p, "%cRanks are already disabled for the economy system"); break; } else { Economy.Settings.Ranks = false; Player.SendMessage(p, "%aRanks are now disabled for the economy system"); break; }
if (!Economy.Settings.Ranks) { Player.SendMessage(p, "%cRanks are already disabled for the economy system"); break; }
else { Economy.Settings.Ranks = false; Player.SendMessage(p, "%aRanks are now disabled for the economy system"); break; }
case "price":
Economy.Settings.Rank rnk = Economy.FindRank(args[3]);
if (rnk == null) { Player.SendMessage(p, "%cThat wasn't a rank or it's past the max rank (maxrank is: " + Group.Find(Economy.Settings.MaxRank).color + Economy.Settings.MaxRank + "%c)"); break; } else {
try {
rnk.price = int.Parse(args[4]);
} catch { Player.SendMessage(p, "%cInvalid price input: that wasn't a number!"); return; }
Player.SendMessage(p, "%aSuccesfully changed the rank price for " + rnk.group.color + rnk.group.name + " to: %f" + rnk.price + " %3" + Server.moneys);
break;
}
if (rnk == null) {
Player.SendMessage(p, "%cThat wasn't a rank or it's past the max rank (maxrank is: " + Group.Find(Economy.Settings.MaxRank).color + Economy.Settings.MaxRank + "%c)"); return; }
try {
rnk.price = int.Parse(args[4]);
} catch { Player.SendMessage(p, "%cInvalid price input: that wasn't a number!"); return; }
Player.SendMessage(p, "%aSuccesfully changed the rank price for " + rnk.group.color + rnk.group.name + " to: %f" + rnk.price + " %3" + Server.moneys);
break;
case "maxrank":
case "max":
case "maximum":
case "maximumrank":
Group grp = Group.Find(args[3]);
if (grp == null) { Player.SendMessage(p, "%cThat wasn't a rank!"); } else {
if (p.group.Permission < grp.Permission) { Player.SendMessage(p, "%cCan't set a maxrank that is higher than yours!"); } else {
Economy.Settings.MaxRank = args[3].ToLower(); Player.SendMessage(p, "%aSuccessfully set max rank to: " + Group.Find(Economy.Settings.MaxRank).color + Economy.Settings.MaxRank);
int lasttrueprice = 0;
foreach (Group group in Group.GroupList) {
if (group.Permission > grp.Permission) { break; }
if (!(group.Permission <= Group.Find(Server.defaultRank).Permission)) {
Economy.Settings.Rank rank = new Economy.Settings.Rank();
rank = Economy.FindRank(group.name);
if (rank == null) {
rank = new Economy.Settings.Rank();
rank.group = group;
if (lasttrueprice == 0) { rank.price = 1000; } else { rank.price = lasttrueprice + 250; }
Economy.Settings.RanksList.Add(rank);
} else { lasttrueprice = rank.price; }
}
}
if (grp == null) { Player.SendMessage(p, "%cThat wasn't a rank!"); return; }
if (p.group.Permission < grp.Permission) { Player.SendMessage(p, "%cCan't set a maxrank that is higher than yours!"); return; }
Economy.Settings.MaxRank = args[3].ToLower();
Player.SendMessage(p, "%aSuccessfully set max rank to: " + Group.Find(Economy.Settings.MaxRank).color + Economy.Settings.MaxRank);
int lasttrueprice = 0;
foreach (Group group in Group.GroupList) {
if (group.Permission > grp.Permission) break;
if (!(group.Permission <= Group.Find(Server.defaultRank).Permission)) {
Economy.Settings.Rank rank = new Economy.Settings.Rank();
rank = Economy.FindRank(group.name);
if (rank == null) {
rank = new Economy.Settings.Rank();
rank.group = group;
if (lasttrueprice == 0) { rank.price = 1000; } else { rank.price = lasttrueprice + 250; }
Economy.Settings.RanksList.Add(rank);
} else { lasttrueprice = rank.price; }
}
}
break;

View File

@ -20,7 +20,7 @@ namespace MCGalaxy.Commands
public sealed class CmdInfected : Command
{
public override string name { get { return "infected"; } }
public override string shortcut { get { return ""; } }
public override string shortcut { get { return "dead"; } }
public override string type { get { return CommandTypes.Games; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }

View File

@ -37,7 +37,8 @@ namespace MCGalaxy.Commands
if (message == "list") {
foreach (string s in Server.afkset) {
if (p.hidden) continue;
Player pl = PlayerInfo.FindExact(s);
if (pl == null || !Player.CanSee(p, pl)) continue;
Player.SendMessage(p, s);
}
return;

View File

@ -39,10 +39,9 @@ namespace MCGalaxy.Commands {
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) {
if (!pl.hidden || p == null || Player.CanSee(p, pl)) {
count++;
if (pl.hidden) hiddenCount++;
}
if (!Player.CanSee(p, pl)) continue;
count++;
if (pl.hidden) hiddenCount++;
}
string verb = count == 1 ? "is " : "are ";

View File

@ -1,19 +1,19 @@
/*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/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
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 2010 MCSharp team (Modified for use with MCZall/MCLawl/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
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.IO;
namespace MCGalaxy.Commands
@ -22,71 +22,69 @@ namespace MCGalaxy.Commands
{
public override string name { get { return "hide"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Moderation; } }
public override string type { get { return CommandTypes.Moderation; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdHide() { }
public override void Use(Player p, string message)
{
public override void Use(Player p, string message) {
if (p == null) { MessageInGameOnly(p); return; }
if (message == "check")
{
if (p.hidden)
{
Player.SendMessage(p, "You are currently hidden!");
return;
}
else
{
Player.SendMessage(p, "You are not currently hidden!");
return;
}
}
else
if (message != "")
if (p.possess != "")
{
Player.SendMessage(p, "Stop your current possession first.");
return;
DoHide(p, message, true);
}
internal static void DoHide(Player p, string message, bool messageOps) {
if (message == "check") {
string state = p.hidden ? "" : "not ";
Player.SendMessage(p, "You are " + state + "currently hidden!"); return;
}
if (message != "" && p.possess != "") {
Player.SendMessage(p, "Stop your current possession first."); return;
}
Command opchat = Command.all.Find("opchat");
Command adminchat = Command.all.Find("adminchat");
p.hidden = !p.hidden;
if (p.hidden)
{
if (p.hidden) {
Player.GlobalDespawn(p, true);
Chat.GlobalMessageOps("To Ops -" + p.color + p.DisplayName + Server.DefaultColor + "- is now &finvisible" + Server.DefaultColor + ".");
Player.SendChatFrom(p, "&c- " + p.color + p.prefix + p.DisplayName + Server.DefaultColor + " " +
if (messageOps)
Chat.GlobalMessageOps("To Ops -" + p.color + p.DisplayName + "%S- is now &finvisible%S.");
Player.SendChatFrom(p, "&c- " + p.FullName + " %S" +
(File.Exists("text/logout/" + p.name + ".txt") ? CP437Reader.ReadAllText("text/logout/" + p.name + ".txt") : "Disconnected."), false);
Server.IRC.Say(p.DisplayName + " left the game (Disconnected.)");
if (!p.opchat)
{
opchat.Use(p, message);
}
//Player.SendMessage(p, "You're now &finvisible&e.");
}
else
{
if (messageOps && !p.opchat) opchat.Use(p, message);
} else {
Player.GlobalSpawn(p, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1], false);
Chat.GlobalMessageOps("To Ops -" + p.color + p.DisplayName + Server.DefaultColor + "- is now &8visible" + Server.DefaultColor + ".");
Player.SendChatFrom(p, "&a+ " + p.color + p.prefix + p.DisplayName + Server.DefaultColor + " " +
if (messageOps)
Chat.GlobalMessageOps("To Ops -" + p.color + p.DisplayName + "%S- is now &8visible%S.");
Player.SendChatFrom(p, "&a+ " + p.FullName + " %S" +
(File.Exists("text/login/" + p.name + ".txt") ? CP437Reader.ReadAllText("text/login/" + p.name + ".txt") : "joined the game."), false);
Server.IRC.Say(p.DisplayName + " joined the game");
if (p.opchat)
{
opchat.Use(p, message);
}
if (p.adminchat)
{
adminchat.Use(p, message);
}
//Player.SendMessage(p, "You're now &8visible&e.");
if (messageOps && p.opchat) opchat.Use(p, message);
if (p.adminchat) adminchat.Use(p, message);
}
}
public override void Help(Player p)
{
public override void Help(Player p) {
Player.SendMessage(p, "/hide - Toggles your visibility to other players, also toggles opchat.");
}
}
public sealed class CmdXhide : Command {
public override string name { get { return "xhide"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Moderation; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public override void Use(Player p, string message) {
if (p == null) { MessageInGameOnly(p); return; }
CmdHide.DoHide(p, message, false);
}
public override void Help(Player p) {
Player.SendMessage(p, "/xhide - like /hide, only it doesn't send a message to ops.");
}
}
}

View File

@ -1,70 +0,0 @@
/*
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.IO;
namespace MCGalaxy.Commands
{
public sealed class CmdXhide : Command
{
public override string name { get { return "xhide"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Moderation; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public override void Use(Player p, string message)
{
if (p == null) { MessageInGameOnly(p); return; }
if (message != "") { Help(p); return; }
if (p.possess != "")
{
Player.SendMessage(p, "Stop your current possession first.");
return;
}
Command adminchat = Command.all.Find("adminchat");
p.hidden = !p.hidden;
if (p.hidden)
{
Player.GlobalDespawn(p, true);
Player.SendChatFrom(p, "&c- " + p.color + p.prefix + p.DisplayName + Server.DefaultColor + " " +
(File.Exists("text/logout/" + p.name + ".txt") ? CP437Reader.ReadAllText("text/logout/" + p.name + ".txt") : "Disconnected."), false);
Server.IRC.Say(p.name + " left the game (Disconnected.)");
if (!p.adminchat)
{
adminchat.Use(p, message);
}
}
else
{
Player.GlobalSpawn(p, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1], false, "");
Player.SendChatFrom(p, "&a+ " + p.color + p.prefix + p.DisplayName + Server.DefaultColor + " " +
(File.Exists("text/login/" + p.name + ".txt") ? CP437Reader.ReadAllText("text/login/" + p.name + ".txt") : "joined the game."), false);
Server.IRC.Say(p.name + " joined the game");
if (p.adminchat)
{
adminchat.Use(p, message);
}
}
}
public override void Help(Player p)
{
Player.SendMessage(p, "/xhide - like /hide, only it doesn't send a message to ops.");
}
}
}

View File

@ -82,7 +82,7 @@ namespace MCGalaxy.Commands
level.name = "&cMuseum " + Server.DefaultColor + "(" + message.Split(' ')[0] + " " + message.Split(' ')[1] + ")";
if (!p.hidden)
Player.GlobalMessage(p.color + p.prefix + p.name + Server.DefaultColor + " went to the " + level.name);
Player.GlobalMessage(p.FullName + " %Swent to the " + level.name);
} else {
Player.SendMessage(p, "Level or backup could not be found.");
}

View File

@ -61,7 +61,7 @@ namespace MCGalaxy.Commands
bool isopson = false;
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) {
if (pl.group.Permission >= Server.reviewnext && !pl.hidden) {
if (pl.group.Permission >= Server.reviewnext && Player.CanSee(p, pl)) {
isopson = true; break;
}
}
@ -70,12 +70,12 @@ namespace MCGalaxy.Commands
{
Server.reviewlist.Add(p.name);
int reviewlistpos = Server.reviewlist.IndexOf(p.name);
if (reviewlistpos > 1) { Player.SendMessage(p, "You entered the &creview " + Server.DefaultColor + "queue. You have &c" + reviewlistpos.ToString() + Server.DefaultColor + " people in front of you in the queue"); }
if (reviewlistpos == 1) { Player.SendMessage(p, "You entered the &creview " + Server.DefaultColor + "queue. There is &c1 " + Server.DefaultColor + "person in front of you in the queue"); }
if ((reviewlistpos + 1) == 1) { Player.SendMessage(p, "You entered the &creview " + Server.DefaultColor + "queue. You are &cfirst " + Server.DefaultColor + "in line!"); }
if (reviewlistpos > 1) { Player.SendMessage(p, "You entered the &creview %Squeue. You have &c" + reviewlistpos + " %Speople in front of you in the queue"); }
if (reviewlistpos == 1) { Player.SendMessage(p, "You entered the &creview %Squeue. There is &c1 %Sperson in front of you in the queue"); }
if (reviewlistpos == 0) { Player.SendMessage(p, "You entered the &creview %Squeue. You are &cfirst %Sin line!"); }
Player.SendMessage(p, "The Online Operators have been notified. Someone should be with you shortly.");
string start = (reviewlistpos + 1) > 1 ? "There are now &c" + (reviewlistpos + 1) + " %Speople" : "There is now &c1 %Sperson";
string start = reviewlistpos > 0 ? "There are now &c" + (reviewlistpos + 1) + " %Speople" : "There is now &c1 %Sperson";
Chat.GlobalMessageMinPerms(p.color + p.name + " %Sentered the review queue", Server.reviewnext);
Chat.GlobalMessageMinPerms(start + " waiting for a &creview!", Server.reviewnext);
p.ReviewTimer();

View File

@ -299,7 +299,6 @@
<Compile Include="Commands\Moderation\CmdWarn.cs" />
<Compile Include="Commands\Moderation\CmdWhitelist.cs" />
<Compile Include="Commands\Moderation\CmdXban.cs" />
<Compile Include="Commands\Moderation\CmdXhide.cs" />
<Compile Include="Commands\Moderation\CmdXmute.cs" />
<Compile Include="Commands\Moderation\CmdZone.cs" />
<Compile Include="Commands\Other\CmdAgree.cs" />

View File

@ -479,42 +479,40 @@ namespace MCGalaxy {
}
}
public static void GlobalSpawn(Player from, ushort x, ushort y, ushort z, byte rotx, byte roty, bool self, string possession = "")
{
public static void GlobalSpawn(Player p, ushort x, ushort y, ushort z,
byte rotx, byte roty, bool self, string possession = "") {
Player[] players = PlayerInfo.Online.Items;
foreach (Player p in players) {
if (p.Loading && p != from) continue;
if (p.level != from.level || (from.hidden && !self)) continue;
foreach (Player other in players) {
if (other.Loading && p != other) continue;
if (p.level != other.level || (p.hidden && !self)) continue;
if (p != from)
{
if (Server.ZombieModeOn && !p.aka) {
if (from.infected) {
if (p != other) {
if (Server.ZombieModeOn && !other.aka) {
if (p.infected) {
if (Server.zombie.ZombieName != "")
p.SendSpawn(from.id, Colors.red + Server.zombie.ZombieName + possession, x, y, z, rotx, roty);
other.SendSpawn(p.id, Colors.red + Server.zombie.ZombieName + possession, x, y, z, rotx, roty);
else
p.SendSpawn(from.id, Colors.red + from.name + possession, x, y, z, rotx, roty);
} else if (!from.referee) {
p.SendSpawn(from.id, from.color + from.name + possession, x, y, z, rotx, roty);
other.SendSpawn(p.id, Colors.red + p.name + possession, x, y, z, rotx, roty);
} else if (!p.referee) {
other.SendSpawn(p.id, p.color + p.name + possession, x, y, z, rotx, roty);
}
} else {
p.SendSpawn(from.id, from.color + from.name + possession, x, y, z, rotx, roty);
other.SendSpawn(p.id, p.color + p.name + possession, x, y, z, rotx, roty);
}
}
else if (self)
{
p.pos = new ushort[3] { x, y, z }; p.rot = new byte[2] { rotx, roty };
p.oldpos = p.pos; p.basepos = p.pos; p.oldrot = p.rot;
p.SendSpawn(0xFF, from.color + from.name + possession, x, y, z, rotx, roty);
} else if (self) {
other.pos = new ushort[3] { x, y, z }; other.rot = new byte[2] { rotx, roty };
other.oldpos = other.pos; other.basepos = other.pos; other.oldrot = other.rot;
other.SendSpawn(0xFF, p.color + p.name + possession, x, y, z, rotx, roty);
}
}
}
public static void GlobalDespawn(Player from, bool self) {
public static void GlobalDespawn(Player p, bool self) {
Player[] players = PlayerInfo.Online.Items;
foreach (Player p in players) {
if ( p.level != from.level || ( from.hidden && !self ) ) continue;
if ( p != from ) { p.SendDespawn(from.id); }
else if ( self ) { p.SendDespawn(255); }
foreach (Player other in players) {
if (p.level != other.level || (p.hidden && !self) ) continue;
if (p != other) { other.SendDespawn(p.id); }
else if (self) { other.SendDespawn(255); }
}
}
@ -595,7 +593,7 @@ namespace MCGalaxy {
isFlying = false;
aiming = false;
SendKick(kickMsg, sync);
SendKick(kickMsg, sync);
if (!loggedIn) {
connections.Remove(this);
RemoveFromPending();
@ -615,7 +613,7 @@ namespace MCGalaxy {
GlobalDespawn(this, false);
if (discMsg != null) {
if (!hidden) {
string leavem = "&c- " + color + prefix + DisplayName + " %S" + discMsg;
string leavem = "&c- " + FullName + " %S" + discMsg;
if ((Server.guestLeaveNotify && group.Permission <= LevelPermission.Guest) || group.Permission > LevelPermission.Guest) {
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) { Player.SendMessage(pl, leavem); }