diff --git a/Commands/building/CmdCuboid.cs b/Commands/building/CmdCuboid.cs index 8428da2f8..65d287bdf 100644 --- a/Commands/building/CmdCuboid.cs +++ b/Commands/building/CmdCuboid.cs @@ -40,7 +40,7 @@ namespace MCGalaxy.Commands.Building { return DrawMode.normal; } - protected override DrawOp GetDrawOp(DrawArgs dArgs, Vec3S32[] m) { + protected override DrawOp GetDrawOp(DrawArgs dArgs) { switch (dArgs.Mode) { case DrawMode.hollow: return new CuboidHollowsDrawOp(); case DrawMode.walls: return new CuboidWallsDrawOp(); @@ -51,12 +51,12 @@ namespace MCGalaxy.Commands.Building { return new CuboidDrawOp(); } - protected override BrushFactory GetBrush(Player p, DrawArgs dArgs, ref int brushOffset) { - brushOffset = dArgs.Mode == DrawMode.normal ? 0 : 1; - if (dArgs.Mode == DrawMode.solid) return BrushFactory.Find("normal"); - if (dArgs.Mode == DrawMode.holes) return BrushFactory.Find("checkered"); - if (dArgs.Mode == DrawMode.random) return BrushFactory.Find("random"); - return BrushFactory.Find(p.BrushName); + protected override string GetBrush(Player p, DrawArgs dArgs, ref int offset) { + offset = dArgs.Mode == DrawMode.normal ? 0 : 1; + if (dArgs.Mode == DrawMode.solid) return "normal"; + if (dArgs.Mode == DrawMode.holes) return "checkered"; + if (dArgs.Mode == DrawMode.random) return "random"; + return p.BrushName; } public override void Help(Player p) { diff --git a/Commands/building/CmdDraw.cs b/Commands/building/CmdDraw.cs index 8cf278074..984fb25e2 100644 --- a/Commands/building/CmdDraw.cs +++ b/Commands/building/CmdDraw.cs @@ -42,7 +42,7 @@ namespace MCGalaxy.Commands.Building { return DrawMode.normal; } - protected override DrawOp GetDrawOp(DrawArgs dArgs, Vec3S32[] m) { + protected override DrawOp GetDrawOp(DrawArgs dArgs) { switch (dArgs.Mode) { case DrawMode.cone: return new AdvConeDrawOp(); case DrawMode.hcone: return new AdvHollowConeDrawOp(); @@ -59,29 +59,32 @@ namespace MCGalaxy.Commands.Building { Help(dArgs.Player); return null; } - protected override bool GetMarks(DrawArgs dArgs, Vec3S32[] m) { + protected override void GetMarks(DrawArgs dArgs, ref Vec3S32[] m) { ushort radius = 0, height = 0; string[] args = dArgs.Message.Split(' '); AdvDrawOp op = (AdvDrawOp)dArgs.Op; if ((op.UsesHeight && !CheckTwoArgs(dArgs.Player, ref radius, ref height, args)) || - (!op.UsesHeight && !CheckOneArg(dArgs.Player, ref radius, args))) return false; + (!op.UsesHeight && !CheckOneArg(dArgs.Player, ref radius, args))) { + m = null; return; + } Vec3S32 P = m[0]; - m[0] = new Vec3S32(P.X - radius, P.Y, P.Z - radius); - m[1] = new Vec3S32(P.X + radius, P.Y, P.Z + radius); + m = new [] { + new Vec3S32(P.X - radius, P.Y, P.Z - radius), + new Vec3S32(P.X + radius, P.Y, P.Z + radius), + }; if (op.UsesHeight) { m[1].Y += height; } else { m[0].Y -= radius; m[1].Y += radius; } - return true; } - protected override BrushFactory GetBrush(Player p, DrawArgs dArgs, ref int brushOffset) { - brushOffset = ((AdvDrawOp)dArgs.Op).UsesHeight ? 3 : 2; - return BrushFactory.Find(p.BrushName); + protected override string GetBrush(Player p, DrawArgs dArgs, ref int offset) { + offset = ((AdvDrawOp)dArgs.Op).UsesHeight ? 3 : 2; + return p.BrushName; } bool CheckTwoArgs(Player p, ref ushort radius, ref ushort height, string[] parts) { diff --git a/Commands/building/CmdFill.cs b/Commands/building/CmdFill.cs index 91b22f52a..585bfd273 100644 --- a/Commands/building/CmdFill.cs +++ b/Commands/building/CmdFill.cs @@ -39,7 +39,7 @@ namespace MCGalaxy.Commands.Building { return DrawMode.normal; } - protected override DrawOp GetDrawOp(DrawArgs dArg, Vec3S32[] m) { + protected override DrawOp GetDrawOp(DrawArgs dArg) { return null; } @@ -69,8 +69,8 @@ namespace MCGalaxy.Commands.Building { FillDrawOp op = new FillDrawOp(); op.Positions = buffer; - int brushOffset = cpos.Mode == DrawMode.normal ? 0 : 1; - Brush brush = ParseBrush(p, cpos, brushOffset); + int offset = cpos.Mode == DrawMode.normal ? 0 : 1; + Brush brush = ParseBrush(p, cpos, offset); if (brush == null || !DrawOp.DoDrawOp(op, brush, p, marks)) return false; bits.Clear(); op.Positions = null; diff --git a/Commands/building/CmdLine.cs b/Commands/building/CmdLine.cs index 2aa7b4054..80f766fb6 100644 --- a/Commands/building/CmdLine.cs +++ b/Commands/building/CmdLine.cs @@ -26,11 +26,14 @@ namespace MCGalaxy.Commands.Building { protected override string PlaceMessage { get { return "Place two blocks to determine the endpoints."; } } protected override void OnUse(Player p, string msg, string[] parts, ref DrawArgs dArgs) { + LineDrawOp line = (LineDrawOp)dArgs.Op; + line.WallsMode = dArgs.Mode == DrawMode.walls; if (parts.Length < 2 || dArgs.Mode == DrawMode.normal) return; + string arg = parts[parts.Length - 1]; ushort len; if (ushort.TryParse(arg, out len)) - dArgs.Data = len; + line.MaxLength = len; } protected override DrawMode GetMode(string[] parts) { @@ -53,8 +56,12 @@ namespace MCGalaxy.Commands.Building { return DrawMode.normal; } - protected override bool GetMarks(DrawArgs dArgs, Vec3S32[] m) { - if (dArgs.Mode != DrawMode.straight) return true; + protected override DrawOp GetDrawOp(DrawArgs dArgs) { + return new LineDrawOp(); + } + + protected override void GetMarks(DrawArgs dArgs, ref Vec3S32[] m) { + if (dArgs.Mode != DrawMode.straight) return; int dx = Math.Abs(m[0].X - m[1].X), dy = Math.Abs(m[0].Y - m[1].Y), dz = Math.Abs(m[0].Z - m[1].Z); if (dx > dy && dx > dz) { @@ -64,17 +71,14 @@ namespace MCGalaxy.Commands.Building { } else if (dz > dy && dz > dx) { m[1].X = m[0].X; m[1].Y = m[0].Y; } - return true; } - protected override BrushFactory GetBrush(Player p, DrawArgs dArgs, ref int brushOffset) { - brushOffset = dArgs.Mode == DrawMode.normal ? 0 : 1; - if (dArgs.Data != null) brushOffset++; - return BrushFactory.Find(p.BrushName); - } - - protected override DrawOp GetDrawOp(DrawArgs dArg, Vec3S32[] m) { - return new LineDrawOp(); + protected override string GetBrush(Player p, DrawArgs dArgs, ref int offset) { + LineDrawOp line = (LineDrawOp)dArgs.Op; + offset = dArgs.Mode == DrawMode.normal ? 0 : 1; + + if (line.MaxLength != int.MaxValue) offset++; + return p.BrushName; } public override void Help(Player p) { diff --git a/Commands/building/CmdPyramid.cs b/Commands/building/CmdPyramid.cs index d768cc55b..2176f1071 100644 --- a/Commands/building/CmdPyramid.cs +++ b/Commands/building/CmdPyramid.cs @@ -14,7 +14,7 @@ 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.Drawing.Ops; @@ -31,12 +31,7 @@ namespace MCGalaxy.Commands.Building { return DrawMode.normal; } - protected override DrawOp GetDrawOp(DrawArgs dArgs, Vec3S32[] m) { - if (m[0].Y != m[1].Y) { - Player.Message(dArgs.Player, "The two edges of the pyramid must be on the same level"); - return null; - } - + protected override DrawOp GetDrawOp(DrawArgs dArgs) { switch (dArgs.Mode) { case DrawMode.hollow: return new PyramidHollowDrawOp(); case DrawMode.reverse: return new PyramidReverseDrawOp(); @@ -44,11 +39,17 @@ namespace MCGalaxy.Commands.Building { return new PyramidSolidDrawOp(); } + protected override void GetMarks(DrawArgs dArgs, ref Vec3S32[] m) { + if (m[0].Y == m[1].Y) return; + Player.Message(dArgs.Player, "The two corners of the pyramid must be on the same level"); + m = null; + } + public override void Help(Player p) { Player.Message(p, "%T/pyramid [brush args] "); Player.Message(p, "%HDraws a square pyramid, using two points for the base."); Player.Message(p, " %HFor help about brushes, type %T/help brush%H."); - Player.Message(p, " %HModes: &fsolid/hollow/reverse"); + Player.Message(p, " %HModes: &fsolid/hollow/reverse"); } } } diff --git a/Commands/building/CmdSphere.cs b/Commands/building/CmdSphere.cs index 97e7e7b5f..b5100924b 100644 --- a/Commands/building/CmdSphere.cs +++ b/Commands/building/CmdSphere.cs @@ -40,7 +40,7 @@ namespace MCGalaxy.Commands.Building { return DrawMode.normal; } - protected override DrawOp GetDrawOp(DrawArgs dArgs, Vec3S32[] m) { + protected override DrawOp GetDrawOp(DrawArgs dArgs) { switch (dArgs.Mode) { case DrawMode.hollow: return new AdvHollowSphereDrawOp(); case DrawMode.circle: return new EllipsoidDrawOp(); @@ -48,17 +48,16 @@ namespace MCGalaxy.Commands.Building { return new AdvSphereDrawOp(); } - protected override bool GetMarks(DrawArgs dArgs, Vec3S32[] m) { + protected override void GetMarks(DrawArgs dArgs, ref Vec3S32[] m) { Vec3S32 p0 = m[0]; Vec3S32 radius = GetRadius(dArgs.Mode, m); m[0] = p0 - radius; m[1] = p0 + radius; - return true; } - protected override BrushFactory GetBrush(Player p, DrawArgs dArgs, ref int brushOffset) { - brushOffset = dArgs.Mode == DrawMode.normal ? 0 : 1; - if (dArgs.Mode == DrawMode.solid) return BrushFactory.Find("normal"); - return BrushFactory.Find(p.BrushName); + protected override string GetBrush(Player p, DrawArgs dArgs, ref int offset) { + offset = dArgs.Mode == DrawMode.normal ? 0 : 1; + if (dArgs.Mode == DrawMode.solid) return "normal"; + return p.BrushName; } static Vec3S32 GetRadius(DrawMode mode, Vec3S32[] m) { diff --git a/Commands/building/CmdSpheroid.cs b/Commands/building/CmdSpheroid.cs index 592b7a47f..d1a40dae9 100644 --- a/Commands/building/CmdSpheroid.cs +++ b/Commands/building/CmdSpheroid.cs @@ -27,13 +27,13 @@ namespace MCGalaxy.Commands.Building { get { return new[] { new CommandAlias("eh", null, "hollow"), new CommandAlias("cylinder", null, "vertical") }; } } - protected override BrushFactory GetBrush(Player p, DrawArgs dArgs, ref int brushOffset) { - brushOffset = dArgs.Mode == DrawMode.normal ? 0 : 1; - if (dArgs.Mode == DrawMode.solid) return BrushFactory.Find("normal"); - return BrushFactory.Find(p.BrushName); + protected override string GetBrush(Player p, DrawArgs dArgs, ref int offset) { + offset = dArgs.Mode == DrawMode.normal ? 0 : 1; + if (dArgs.Mode == DrawMode.solid) return "normal"; + return p.BrushName; } - protected override DrawOp GetDrawOp(DrawArgs dArgs, Vec3S32[] m) { + protected override DrawOp GetDrawOp(DrawArgs dArgs) { switch (dArgs.Mode) { case DrawMode.hollow: return new EllipsoidHollowDrawOp(); case DrawMode.vertical: return new CylinderDrawOp(); diff --git a/Commands/building/CmdTorus.cs b/Commands/building/CmdTorus.cs index 47ef9d841..2dcdad99d 100644 --- a/Commands/building/CmdTorus.cs +++ b/Commands/building/CmdTorus.cs @@ -30,17 +30,16 @@ namespace MCGalaxy.Commands.Building { get { return "Place a block for the centre, then another for the radius."; } } - protected override bool GetMarks(DrawArgs dArgs, Vec3S32[] m) { + protected override void GetMarks(DrawArgs dArgs, ref Vec3S32[] m) { int dx = m[0].X - m[1].X, dy = m[0].Y - m[1].Y, dz = m[0].Z - m[1].Z; int horR = (int)Math.Sqrt(dx * dx + dz * dz), verR = Math.Abs(dy); Vec3S32 p0 = m[0]; m[0] = new Vec3S32(p0.X - horR, p0.Y - verR, p0.Z - horR); m[1] = new Vec3S32(p0.X + horR, p0.Y + verR, p0.Z + horR); - return true; } - protected override DrawOp GetDrawOp(DrawArgs dArgs, Vec3S32[] m) { + protected override DrawOp GetDrawOp(DrawArgs dArgs) { return new TorusDrawOp(); } diff --git a/Commands/building/CmdTriangle.cs b/Commands/building/CmdTriangle.cs index 1f694335c..44171698e 100644 --- a/Commands/building/CmdTriangle.cs +++ b/Commands/building/CmdTriangle.cs @@ -28,7 +28,7 @@ namespace MCGalaxy.Commands.Building { get { return "Place three blocks to determine the edges."; } } - protected override DrawOp GetDrawOp(DrawArgs dArgs, Vec3S32[] m) { + protected override DrawOp GetDrawOp(DrawArgs dArgs) { return new TriangleDrawOp(); } diff --git a/Commands/building/DrawCmd.cs b/Commands/building/DrawCmd.cs index cd771bfb2..c8fef5a51 100644 --- a/Commands/building/DrawCmd.cs +++ b/Commands/building/DrawCmd.cs @@ -30,50 +30,51 @@ namespace MCGalaxy.Commands.Building { if (Player.IsSuper(p)) { MessageInGameOnly(p); return; } message = message.ToLower(); string[] parts = message.Split(' '); - DrawArgs cpos = default(DrawArgs); - cpos.Message = message; - cpos.Mode = GetMode(parts); - OnUse(p, message, parts, ref cpos); + DrawArgs dArgs = default(DrawArgs); + dArgs.Message = message; + dArgs.Mode = GetMode(parts); + dArgs.Op = GetDrawOp(dArgs); + if (dArgs.Op == null) return; + + OnUse(p, message, parts, ref dArgs); Player.Message(p, PlaceMessage); - p.MakeSelection(MarksCount, cpos, DoDraw); + p.MakeSelection(MarksCount, dArgs, DoDraw); } protected virtual bool DoDraw(Player p, Vec3S32[] marks, object state, byte block, byte extBlock) { DrawArgs dArgs = (DrawArgs)state; dArgs.Block = block; dArgs.ExtBlock = extBlock; + dArgs.Player = p; - DrawOp op = GetDrawOp(dArgs, marks); - if (op == null) return false; - dArgs.Op = op; - GetMarks(dArgs, marks); + GetMarks(dArgs, ref marks); + if (marks == null) return false; int offset = 0; - BrushFactory factory = GetBrush(p, dArgs, ref offset); + BrushFactory factory = BrushFactory.Find(GetBrush(p, dArgs, ref offset)); Brush brush = ParseBrush(p, dArgs, offset, factory); - dArgs.Op = null; - return brush != null && DrawOp.DoDrawOp(op, brush, p, marks); + return brush != null && DrawOp.DoDrawOp(dArgs.Op, brush, p, marks); } protected virtual string PlaceMessage { get { return "Place two blocks to determine the edges."; } } - protected virtual void OnUse(Player p, string msg, string[] parts, ref DrawArgs cpos) { } + protected virtual void OnUse(Player p, string msg, string[] parts, ref DrawArgs dArgs) { } protected virtual DrawMode GetMode(string[] parts) { return DrawMode.normal; } - protected virtual bool GetMarks(DrawArgs dArgs, Vec3S32[] m) { return true; } + protected abstract DrawOp GetDrawOp(DrawArgs dArgs); - protected virtual BrushFactory GetBrush(Player p, DrawArgs dArgs, ref int brushOffset) { - brushOffset = dArgs.Mode == DrawMode.normal ? 0 : 1; - return BrushFactory.Find(p.BrushName); + protected virtual void GetMarks(DrawArgs dArgs, ref Vec3S32[] m) { } + + protected virtual string GetBrush(Player p, DrawArgs dArgs, ref int offset) { + offset = dArgs.Mode == DrawMode.normal ? 0 : 1; + return p.BrushName; } - - protected abstract DrawOp GetDrawOp(DrawArgs dArgs, Vec3S32[] m); - + internal static int GetBlock(Player p, string msg, out byte extBlock, bool checkPlacePerm = true) { byte block = Block.Byte(msg); @@ -118,7 +119,6 @@ namespace MCGalaxy.Commands.Building { public byte Block, ExtBlock; public string Message; - public object Data; public DrawOp Op; public Player Player; } diff --git a/Network/IRCBot.cs b/Network/IRCBot.cs index 5a3a34ed7..ba602db79 100644 --- a/Network/IRCBot.cs +++ b/Network/IRCBot.cs @@ -34,12 +34,14 @@ namespace MCGalaxy { string nick, server; bool reset = false; byte retries = 0; + Dictionary> users = new Dictionary>(); static char[] trimChars = { ' ' }; ConnectionArgs args; + DateTime lastWho; public IRCBot() { - UpdateState(); + UpdateState(); if (!Server.irc) return; connection = new Connection(new UTF8Encoding(false), args); LoadBannedCommands(); @@ -257,20 +259,18 @@ namespace MCGalaxy { } Command cmd = Command.all.Find(cmdName); - if (cmd != null) { - Server.s.Log("IRC Command: /" + message + " (by " + user.Nick + ")"); - string args = parts.Length > 1 ? parts[1] : ""; - Player p = MakeIRCPlayer(user.Nick); - - try { - if (!p.group.CanExecute(cmd)) { cmd.MessageCannotUse(p); return; } - cmd.Use(p, args); - } catch (Exception e) { - Pm(user.Nick, "CMD Error: " + e.ToString()); - } + if (cmd == null) { Pm(user.Nick, "Unknown command!"); return; } + + Server.s.Log("IRC Command: /" + message + " (by " + user.Nick + ")"); + string args = parts.Length > 1 ? parts[1] : ""; + Player p = MakeIRCPlayer(user.Nick); + + try { + if (!p.group.CanExecute(cmd)) { cmd.MessageCannotUse(p); return; } + cmd.Use(p, args); + } catch (Exception ex) { + Pm(user.Nick, "CMD Error: " + ex); } - else - Pm(user.Nick, "Unknown command!"); } void Listener_OnPublic(UserInfo user, string channel, string message) { @@ -290,42 +290,47 @@ namespace MCGalaxy { } } - if (ircCmd == ".x") { - string cmdName = parts.Length > 1 ? parts[1].ToLower() : ""; - string cmdArgs = parts.Length > 2 ? parts[2] : ""; - Command.Search(ref cmdName, ref cmdArgs); - - string error; - if (!CheckIRCCommand(user, cmdName, channel, out error)) { - if (error != null) Say(error, opchat); - return; - } - - Command cmd = Command.all.Find(cmdName); - if (cmdName != "" && cmd != null) { - Server.s.Log("IRC Command: /" + message.Replace(".x ", "") + " (by " + user.Nick + ")"); - string nick = opchat ? "#@private@#" : "#@public@#"; - Player p = MakeIRCPlayer(nick); - - try { - if (!p.group.CanExecute(cmd)) { cmd.MessageCannotUse(p); return; } - cmd.Use(p, cmdArgs); - } catch (Exception ex) { - Say("CMD Error: " + ex, opchat); - } - } else { - Say("Unknown command!", opchat); - } - } + if (ircCmd == ".x" && !HandlePublicCommand(user, channel, message, parts, opchat)) return; if (channel.CaselessEq(opchannel)) { Server.s.Log(String.Format("(OPs): [IRC] {0}: {1}", user.Nick, message)); - Chat.GlobalMessageOps(String.Format("To Ops &f-%I[IRC] {0}&f- {1}", user.Nick, Server.profanityFilter ? ProfanityFilter.Parse(message) : message)); + Chat.GlobalMessageOps(String.Format("To Ops &f-%I[IRC] {0}&f- {1}", user.Nick, + Server.profanityFilter ? ProfanityFilter.Parse(message) : message)); } else { Server.s.Log(String.Format("[IRC] {0}: {1}", user.Nick, message)); - Player.GlobalIRCMessage(String.Format("%I[IRC] {0}: &f{1}", user.Nick, Server.profanityFilter ? ProfanityFilter.Parse(message) : message)); + Player.GlobalIRCMessage(String.Format("%I[IRC] {0}: &f{1}", user.Nick, + Server.profanityFilter ? ProfanityFilter.Parse(message) : message)); } } + + bool HandlePublicCommand(UserInfo user, string channel, string message, + string[] parts, bool opchat) { + string cmdName = parts.Length > 1 ? parts[1].ToLower() : ""; + string cmdArgs = parts.Length > 2 ? parts[2] : ""; + Command.Search(ref cmdName, ref cmdArgs); + + string error; + if (!CheckIRCCommand(user, cmdName, channel, out error)) { + if (error != null) Say(error, opchat); + return false; + } + + Command cmd = Command.all.Find(cmdName); + if (cmdName == "" || cmd == null) { + Say("Unknown command!", opchat); return false; + } + Server.s.Log("IRC Command: /" + message.Substring(3) + " (by " + user.Nick + ")"); + string nick = opchat ? "#@private@#" : "#@public@#"; + Player p = MakeIRCPlayer(nick); + + try { + if (!p.group.CanExecute(cmd)) { cmd.MessageCannotUse(p); return false; } + cmd.Use(p, cmdArgs); + } catch (Exception ex) { + Say("CMD Error: " + ex, opchat); + } + return true; + } bool CheckIRCCommand(UserInfo user, string cmdName, string channel, out string error) { List chanNicks;