Remove usage of class fields in /copy and /drawimage (can be used by multiple people independently now), also fix /hackrank only worked once for the entire duration of the server.

This commit is contained in:
UnknownShadow200 2016-03-13 20:06:58 +11:00
parent 2cfaaa5afc
commit 42300d5617
4 changed files with 83 additions and 134 deletions

View File

@ -30,11 +30,10 @@ namespace MCGalaxy.Commands
public override string type { get { return CommandTypes.Building; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
public int allowoffset = 0;
public CmdCopy() { }
public override void Use(Player p, string message) {
allowoffset = message.IndexOf('@');
int allowoffset = message.IndexOf('@');
if (allowoffset != -1)
message = message.Replace("@ ", "").Replace("@", "");
@ -68,13 +67,14 @@ namespace MCGalaxy.Commands
Player.SendMessage(p, name);
}
} else {
HandleOther(p, opt, parts);
HandleOther(p, opt, parts, allowoffset);
}
}
void HandleOther(Player p, string opt, string[] parts) {
CatchPos cpos = default(CatchPos);;
void HandleOther(Player p, string opt, string[] parts, int allowoffset) {
CatchPos cpos = default(CatchPos);
p.copyoffset[0] = 0; p.copyoffset[1] = 0; p.copyoffset[2] = 0;
cpos.allowoffset = allowoffset;
if (opt == "cut") {
cpos.type = 1;
@ -93,9 +93,7 @@ namespace MCGalaxy.Commands
void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
CatchPos bp = (CatchPos)p.blockchangeObject;
p.copystart[0] = x;
p.copystart[1] = y;
p.copystart[2] = z;
p.copystart[0] = x; p.copystart[1] = y; p.copystart[2] = z;
bp.x = x; bp.y = y; bp.z = z; p.blockchangeObject = bp;
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2);
@ -148,7 +146,7 @@ namespace MCGalaxy.Commands
}
Player.SendMessage(p, (state.Volume - totalAir) + " blocks copied.");
if (allowoffset != -1) {
if (cpos.allowoffset != -1) {
Player.SendMessage(p, "Place a block to determine where to paste from");
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange3);
}
@ -208,7 +206,7 @@ namespace MCGalaxy.Commands
Player.SendMessage(p, "Loaded copy as " + file);
}
struct CatchPos { public ushort x, y, z; public int type; }
struct CatchPos { public ushort x, y, z; public int type; public int allowoffset; }
public override void Help(Player p) {
Player.SendMessage(p, "/copy - Copies the blocks in an area.");

View File

@ -37,8 +37,9 @@ namespace MCGalaxy.Commands
public override void Use(Player p, string message)
{
if (!Directory.Exists("extra/images/")) { Directory.CreateDirectory("extra/images/"); }
layer = false;
popType = 1;
bool layer = false;
byte popType = 1;
string bitmapLoc = null;
if (message == "") { Help(p); return; }
if (message.IndexOf(' ') != -1) //Yay parameters
{
@ -67,8 +68,7 @@ namespace MCGalaxy.Commands
web.DownloadFile("http://www.imgur.com/" + message, "extra/images/tempImage_" + p.name + ".bmp");
}
Player.SendMessage(p, "Download complete.");
bitmaplocation = "tempImage_" + p.name;
message = bitmaplocation;
bitmapLoc = "tempImage_" + p.name;
}
catch { }
}
@ -86,38 +86,39 @@ namespace MCGalaxy.Commands
web.DownloadFile(message, "extra/images/tempImage_" + p.name + ".bmp");
}
Player.SendMessage(p, "Download complete.");
bitmaplocation = "tempImage_" + p.name;
bitmapLoc = "tempImage_" + p.name;
}
catch { }
}
else
{
bitmaplocation = message;
bitmapLoc = message;
}
if (!File.Exists("extra/images/" + bitmaplocation + ".bmp")) { Player.SendMessage(p, "The URL entered was invalid!"); return; }
if (!File.Exists("extra/images/" + bitmapLoc + ".bmp")) { Player.SendMessage(p, "The URL entered was invalid!"); return; }
CatchPos cpos;
cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
CatchPos cpos = default(CatchPos);
cpos.layer = layer;
cpos.bitmapLoc = bitmapLoc;
cpos.popType = popType;
p.blockchangeObject = cpos;
Player.SendMessage(p, "Place two blocks to determine direction.");
p.ClearBlockchange();
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
}
public void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType)
void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType)
{
RevertAndClearState(p, x, y, z);
CatchPos bp = (CatchPos)p.blockchangeObject;
bp.x = x; bp.y = y; bp.z = z; p.blockchangeObject = bp;
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2);
}
public void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType)
void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType)
{
RevertAndClearState(p, x, y, z);
Bitmap myBitmap = new Bitmap("extra/images/" + bitmaplocation + ".bmp");
myBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
CatchPos cpos = (CatchPos)p.blockchangeObject;
Bitmap myBitmap = new Bitmap("extra/images/" + cpos.bitmapLoc + ".bmp");
myBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
if (x == cpos.x && z == cpos.z) { Player.SendMessage(p, "No direction was selected"); return; }
@ -138,6 +139,8 @@ namespace MCGalaxy.Commands
direction = 3;
}
}
byte popType = cpos.popType;
bool layer = cpos.layer;
if (layer)
{
if (popType == 1) popType = 2;
@ -289,7 +292,8 @@ namespace MCGalaxy.Commands
p.level.UpdateBlock(p, colblock.x, colblock.y, colblock.z, colblock.type, 0);
}
}
if (bitmaplocation == "tempImage_" + p.name) File.Delete("extra/images/tempImage_" + p.name + ".bmp");
if (cpos.bitmapLoc == "tempImage_" + p.name)
File.Delete("extra/images/tempImage_" + p.name + ".bmp");
string printType;
switch (popType)
@ -308,8 +312,8 @@ namespace MCGalaxy.Commands
printThread.Name = "MCG_ImagePrint";
printThread.Start();
}
public override void Help(Player p)
{
public override void Help(Player p) {
Player.SendMessage(p, "/imageprint <switch> <localfile> - Print local file in extra/images/ folder. Must be type .bmp, type filename without extension.");
Player.SendMessage(p, "/imageprint <switch> <imgurfile.extension> - Print IMGUR stored file. Example: /i piCCm.gif will print www.imgur.com/piCCm.gif. Case-sensitive");
Player.SendMessage(p, "/imageprint <switch> <webfile> - Print web file in format domain.com/folder/image.jpg. Does not need http:// or www.");
@ -318,11 +322,7 @@ namespace MCGalaxy.Commands
Player.SendMessage(p, "Use switch (&flayer" + Server.DefaultColor + ") or (&fl" + Server.DefaultColor + ") to print horizontally.");
}
struct CatchPos { public ushort x, y, z; }
string bitmaplocation;
bool layer = false;
byte popType = 1;
struct CatchPos { public bool layer; public byte popType; public string bitmapLoc; public ushort x, y, z; }
}
}

View File

@ -18,110 +18,60 @@
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
namespace MCGalaxy.Commands
{
public sealed class CmdHackRank : Command
{
namespace MCGalaxy.Commands {
public sealed class CmdHackRank : Command {
public override string name { get { return "hackrank"; } }
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 CmdHackRank() { }
private bool hackrank = false;
public override void Use(Player p, string message)
{
if (message == "")
{
Help(p);
return;
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
if (p == null) { MessageInGameOnly(p); return; }
if (p.hackrank) {
Player.SendMessage(p, Colors.red + "You have already hacked a rank!"); return;
}
Group grp = Group.Find(message);
if (grp != null) {
DoFakeRank(p, grp);
} else {
Player.SendMessage(p, "Invalid Rank!");
}
}
if (hackrank)
{
Player.SendMessage(p, Colors.red + "You have already hacked a rank!");
return;
}
if(p == null)
{
Player.SendMessage(p, "Console can't use hackrank, that doesn't make any sense!");
return;
}
string[] msg = message.Split(' ');
if (Group.Exists(msg[0]))
{
Group newRank = Group.Find(msg[0]);
ranker(p, newRank);
}
else { Player.SendMessage(p, "Invalid Rank!"); return; }
}
public void ranker(Player p, Group newRank)
{
void DoFakeRank(Player p, Group newRank) {
string color = newRank.color;
string oldrank = p.group.name;
p.color = newRank.color;
//sent the trick text
hackrank = true;
Player.GlobalMessage(p.color + p.DisplayName + Server.DefaultColor + "'s rank was set to " + newRank.color + newRank.name);
Player.GlobalMessage("&6Congratulations!");
p.SendMessage("You are now ranked " + newRank.color + newRank.name + Server.DefaultColor + ", type /help for your new set of commands.");
kick(p, newRank);
p.hackrank = true;
Player.GlobalMessage(p.FullName + "%S's rank was set to " + newRank.color + newRank.name + "%S. (Congratulations!)");
p.SendMessage("You are now ranked " + newRank.color + newRank.name + "%S, type /help for your new set of commands.");
DoKick(p, newRank);
}
private void kick(Player p, Group newRank)
{
try
{
if (Server.hackrank_kick)
{
int kicktime = (Server.hackrank_kick_time * 1000);
void DoKick(Player p, Group newRank) {
if (!Server.hackrank_kick) return;
string oldCol = p.color;
//make the timer for the kick
System.Timers.Timer messageTimer = new System.Timers.Timer(kicktime);
//start the timer
System.Timers.Timer messageTimer = new System.Timers.Timer(Server.hackrank_kick_time * 1000);
messageTimer.Start();
//delegate the timer
messageTimer.Elapsed += delegate
{
//kick him!
string msg = "You have been kicked for hacking the rank " + newRank.color + newRank.name;
p.LeaveServer(msg, msg);
p.color = oldCol;
killTimer(messageTimer);
messageTimer.Stop();
messageTimer.Dispose();
};
}
}
catch
{
Player.SendMessage(p, "An error has happend! It wont kick you now! :|");
}
}
public override void Help(Player p)
{
p.SendMessage("/hackrank [rank] - Hacks a rank");
p.SendMessage("Usable Ranks:");
p.SendMessage(Group.concatList(true, true, false));
}
private void killTimer(System.Timers.Timer time)
{
time.Stop();
time.Dispose();
}
public override void Help(Player p) {
Player.SendMessage(p, "/hackrank [rank] - Hacks a rank");
Player.SendMessage(p, "Available ranks: " + Group.concatList());
}
}
}

View File

@ -103,6 +103,7 @@ namespace MCGalaxy {
public bool hasreadrules = false;
public bool canusereview = true;
public float ReachDistance = 5;
public bool hackrank;
public string FullName { get { return color + prefix + DisplayName; } }