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 string type { get { return CommandTypes.Building; } }
public override bool museumUsable { get { return true; } } public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
public int allowoffset = 0;
public CmdCopy() { } public CmdCopy() { }
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
allowoffset = message.IndexOf('@'); int allowoffset = message.IndexOf('@');
if (allowoffset != -1) if (allowoffset != -1)
message = message.Replace("@ ", "").Replace("@", ""); message = message.Replace("@ ", "").Replace("@", "");
@ -68,13 +67,14 @@ namespace MCGalaxy.Commands
Player.SendMessage(p, name); Player.SendMessage(p, name);
} }
} else { } else {
HandleOther(p, opt, parts); HandleOther(p, opt, parts, allowoffset);
} }
} }
void HandleOther(Player p, string opt, string[] parts) { void HandleOther(Player p, string opt, string[] parts, int allowoffset) {
CatchPos cpos = default(CatchPos);; CatchPos cpos = default(CatchPos);
p.copyoffset[0] = 0; p.copyoffset[1] = 0; p.copyoffset[2] = 0; p.copyoffset[0] = 0; p.copyoffset[1] = 0; p.copyoffset[2] = 0;
cpos.allowoffset = allowoffset;
if (opt == "cut") { if (opt == "cut") {
cpos.type = 1; cpos.type = 1;
@ -93,9 +93,7 @@ namespace MCGalaxy.Commands
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); RevertAndClearState(p, x, y, z);
CatchPos bp = (CatchPos)p.blockchangeObject; CatchPos bp = (CatchPos)p.blockchangeObject;
p.copystart[0] = x; p.copystart[0] = x; p.copystart[1] = y; p.copystart[2] = z;
p.copystart[1] = y;
p.copystart[2] = z;
bp.x = x; bp.y = y; bp.z = z; p.blockchangeObject = bp; bp.x = x; bp.y = y; bp.z = z; p.blockchangeObject = bp;
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2); p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2);
@ -148,7 +146,7 @@ namespace MCGalaxy.Commands
} }
Player.SendMessage(p, (state.Volume - totalAir) + " blocks copied."); 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"); Player.SendMessage(p, "Place a block to determine where to paste from");
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange3); p.Blockchange += new Player.BlockchangeEventHandler(Blockchange3);
} }
@ -208,7 +206,7 @@ namespace MCGalaxy.Commands
Player.SendMessage(p, "Loaded copy as " + file); 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) { public override void Help(Player p) {
Player.SendMessage(p, "/copy - Copies the blocks in an area."); 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) public override void Use(Player p, string message)
{ {
if (!Directory.Exists("extra/images/")) { Directory.CreateDirectory("extra/images/"); } if (!Directory.Exists("extra/images/")) { Directory.CreateDirectory("extra/images/"); }
layer = false; bool layer = false;
popType = 1; byte popType = 1;
string bitmapLoc = null;
if (message == "") { Help(p); return; } if (message == "") { Help(p); return; }
if (message.IndexOf(' ') != -1) //Yay parameters 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"); web.DownloadFile("http://www.imgur.com/" + message, "extra/images/tempImage_" + p.name + ".bmp");
} }
Player.SendMessage(p, "Download complete."); Player.SendMessage(p, "Download complete.");
bitmaplocation = "tempImage_" + p.name; bitmapLoc = "tempImage_" + p.name;
message = bitmaplocation;
} }
catch { } catch { }
} }
@ -86,38 +86,39 @@ namespace MCGalaxy.Commands
web.DownloadFile(message, "extra/images/tempImage_" + p.name + ".bmp"); web.DownloadFile(message, "extra/images/tempImage_" + p.name + ".bmp");
} }
Player.SendMessage(p, "Download complete."); Player.SendMessage(p, "Download complete.");
bitmaplocation = "tempImage_" + p.name; bitmapLoc = "tempImage_" + p.name;
} }
catch { } catch { }
} }
else 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; CatchPos cpos = default(CatchPos);
cpos.layer = layer;
cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos; cpos.bitmapLoc = bitmapLoc;
cpos.popType = popType;
p.blockchangeObject = cpos;
Player.SendMessage(p, "Place two blocks to determine direction."); Player.SendMessage(p, "Place two blocks to determine direction.");
p.ClearBlockchange(); p.ClearBlockchange();
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); 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); RevertAndClearState(p, x, y, z);
CatchPos bp = (CatchPos)p.blockchangeObject; CatchPos bp = (CatchPos)p.blockchangeObject;
bp.x = x; bp.y = y; bp.z = z; p.blockchangeObject = bp; bp.x = x; bp.y = y; bp.z = z; p.blockchangeObject = bp;
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2); 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); RevertAndClearState(p, x, y, z);
Bitmap myBitmap = new Bitmap("extra/images/" + bitmaplocation + ".bmp");
myBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
CatchPos cpos = (CatchPos)p.blockchangeObject; 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; } if (x == cpos.x && z == cpos.z) { Player.SendMessage(p, "No direction was selected"); return; }
@ -138,6 +139,8 @@ namespace MCGalaxy.Commands
direction = 3; direction = 3;
} }
} }
byte popType = cpos.popType;
bool layer = cpos.layer;
if (layer) if (layer)
{ {
if (popType == 1) popType = 2; 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); 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; string printType;
switch (popType) switch (popType)
@ -308,8 +312,8 @@ namespace MCGalaxy.Commands
printThread.Name = "MCG_ImagePrint"; printThread.Name = "MCG_ImagePrint";
printThread.Start(); 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> <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> <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."); 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."); Player.SendMessage(p, "Use switch (&flayer" + Server.DefaultColor + ") or (&fl" + Server.DefaultColor + ") to print horizontally.");
} }
struct CatchPos { public ushort x, y, z; } struct CatchPos { public bool layer; public byte popType; public string bitmapLoc; public ushort x, y, z; }
string bitmaplocation;
bool layer = false;
byte popType = 1;
} }
} }

View File

@ -1,127 +1,77 @@
/* /*
Copyright 2011 MCForge Copyright 2011 MCForge
Made originally by 501st_commander, in something called SharpDevelop. Made originally by 501st_commander, in something called SharpDevelop.
Made into a safe and reasonabal command by EricKilla, in Visual Studio 2010. Made into a safe and reasonabal command by EricKilla, in Visual Studio 2010.
Dual-licensed under the Educational Community License, Version 2.0 and Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing, Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS" software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
namespace MCGalaxy.Commands namespace MCGalaxy.Commands {
{
public sealed class CmdHackRank : Command public sealed class CmdHackRank : Command {
{
public override string name { get { return "hackrank"; } } public override string name { get { return "hackrank"; } }
public override string shortcut { get { return ""; } } public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Other; } } public override string type { get { return CommandTypes.Other; } }
public override bool museumUsable { get { return true; } } public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public CmdHackRank() { } public CmdHackRank() { }
private bool hackrank = false;
public override void Use(Player p, string message) public override void Use(Player p, string message) {
{ if (message == "") { Help(p); return; }
if (message == "") if (p == null) { MessageInGameOnly(p); return; }
{
Help(p);
return;
}
if (hackrank) if (p.hackrank) {
{ Player.SendMessage(p, Colors.red + "You have already hacked a rank!"); return;
Player.SendMessage(p, Colors.red + "You have already hacked a rank!");
return;
} }
Group grp = Group.Find(message);
if(p == null) if (grp != null) {
{ DoFakeRank(p, grp);
Player.SendMessage(p, "Console can't use hackrank, that doesn't make any sense!"); } else {
return; Player.SendMessage(p, "Invalid Rank!");
}
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 color = newRank.color;
string oldrank = p.group.name; string oldrank = p.group.name;
p.color = newRank.color; p.color = newRank.color;
//sent the trick text p.hackrank = true;
hackrank = true; Player.GlobalMessage(p.FullName + "%S's rank was set to " + newRank.color + newRank.name + "%S. (Congratulations!)");
Player.GlobalMessage(p.color + p.DisplayName + Server.DefaultColor + "'s rank was set to " + newRank.color + newRank.name); p.SendMessage("You are now ranked " + newRank.color + newRank.name + "%S, type /help for your new set of commands.");
Player.GlobalMessage("&6Congratulations!"); DoKick(p, newRank);
p.SendMessage("You are now ranked " + newRank.color + newRank.name + Server.DefaultColor + ", type /help for your new set of commands.");
kick(p, newRank);
} }
private void kick(Player p, Group newRank) void DoKick(Player p, Group newRank) {
{ if (!Server.hackrank_kick) return;
try string oldCol = p.color;
System.Timers.Timer messageTimer = new System.Timers.Timer(Server.hackrank_kick_time * 1000);
messageTimer.Start();
messageTimer.Elapsed += delegate
{ {
string msg = "You have been kicked for hacking the rank " + newRank.color + newRank.name;
if (Server.hackrank_kick) p.LeaveServer(msg, msg);
{ p.color = oldCol;
int kicktime = (Server.hackrank_kick_time * 1000); messageTimer.Stop();
messageTimer.Dispose();
string oldCol = p.color; };
//make the timer for the kick
System.Timers.Timer messageTimer = new System.Timers.Timer(kicktime);
//start the timer
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);
};
}
}
catch
{
Player.SendMessage(p, "An error has happend! It wont kick you now! :|");
}
} }
public override void Help(Player p) public override void Help(Player p) {
{ Player.SendMessage(p, "/hackrank [rank] - Hacks a rank");
p.SendMessage("/hackrank [rank] - Hacks a rank"); Player.SendMessage(p, "Available ranks: " + Group.concatList());
p.SendMessage("Usable Ranks:");
p.SendMessage(Group.concatList(true, true, false));
} }
private void killTimer(System.Timers.Timer time)
{
time.Stop();
time.Dispose();
}
} }
} }

View File

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