Bugfixes for drawop rewrite.

This commit is contained in:
UnknownShadow200 2016-08-05 13:39:41 +10:00
parent 34cb2f7c7f
commit c13c4c5c26
11 changed files with 130 additions and 119 deletions

View File

@ -40,7 +40,7 @@ namespace MCGalaxy.Commands.Building {
return DrawMode.normal; return DrawMode.normal;
} }
protected override DrawOp GetDrawOp(DrawArgs dArgs, Vec3S32[] m) { protected override DrawOp GetDrawOp(DrawArgs dArgs) {
switch (dArgs.Mode) { switch (dArgs.Mode) {
case DrawMode.hollow: return new CuboidHollowsDrawOp(); case DrawMode.hollow: return new CuboidHollowsDrawOp();
case DrawMode.walls: return new CuboidWallsDrawOp(); case DrawMode.walls: return new CuboidWallsDrawOp();
@ -51,12 +51,12 @@ namespace MCGalaxy.Commands.Building {
return new CuboidDrawOp(); return new CuboidDrawOp();
} }
protected override BrushFactory GetBrush(Player p, DrawArgs dArgs, ref int brushOffset) { protected override string GetBrush(Player p, DrawArgs dArgs, ref int offset) {
brushOffset = dArgs.Mode == DrawMode.normal ? 0 : 1; offset = dArgs.Mode == DrawMode.normal ? 0 : 1;
if (dArgs.Mode == DrawMode.solid) return BrushFactory.Find("normal"); if (dArgs.Mode == DrawMode.solid) return "normal";
if (dArgs.Mode == DrawMode.holes) return BrushFactory.Find("checkered"); if (dArgs.Mode == DrawMode.holes) return "checkered";
if (dArgs.Mode == DrawMode.random) return BrushFactory.Find("random"); if (dArgs.Mode == DrawMode.random) return "random";
return BrushFactory.Find(p.BrushName); return p.BrushName;
} }
public override void Help(Player p) { public override void Help(Player p) {

View File

@ -42,7 +42,7 @@ namespace MCGalaxy.Commands.Building {
return DrawMode.normal; return DrawMode.normal;
} }
protected override DrawOp GetDrawOp(DrawArgs dArgs, Vec3S32[] m) { protected override DrawOp GetDrawOp(DrawArgs dArgs) {
switch (dArgs.Mode) { switch (dArgs.Mode) {
case DrawMode.cone: return new AdvConeDrawOp(); case DrawMode.cone: return new AdvConeDrawOp();
case DrawMode.hcone: return new AdvHollowConeDrawOp(); case DrawMode.hcone: return new AdvHollowConeDrawOp();
@ -59,29 +59,32 @@ namespace MCGalaxy.Commands.Building {
Help(dArgs.Player); return null; 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; ushort radius = 0, height = 0;
string[] args = dArgs.Message.Split(' '); string[] args = dArgs.Message.Split(' ');
AdvDrawOp op = (AdvDrawOp)dArgs.Op; AdvDrawOp op = (AdvDrawOp)dArgs.Op;
if ((op.UsesHeight && !CheckTwoArgs(dArgs.Player, ref radius, ref height, args)) || 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]; Vec3S32 P = m[0];
m[0] = new Vec3S32(P.X - radius, P.Y, P.Z - radius); m = new [] {
m[1] = new Vec3S32(P.X + radius, P.Y, P.Z + radius); new Vec3S32(P.X - radius, P.Y, P.Z - radius),
new Vec3S32(P.X + radius, P.Y, P.Z + radius),
};
if (op.UsesHeight) { if (op.UsesHeight) {
m[1].Y += height; m[1].Y += height;
} else { } else {
m[0].Y -= radius; m[1].Y += radius; m[0].Y -= radius; m[1].Y += radius;
} }
return true;
} }
protected override BrushFactory GetBrush(Player p, DrawArgs dArgs, ref int brushOffset) { protected override string GetBrush(Player p, DrawArgs dArgs, ref int offset) {
brushOffset = ((AdvDrawOp)dArgs.Op).UsesHeight ? 3 : 2; offset = ((AdvDrawOp)dArgs.Op).UsesHeight ? 3 : 2;
return BrushFactory.Find(p.BrushName); return p.BrushName;
} }
bool CheckTwoArgs(Player p, ref ushort radius, ref ushort height, string[] parts) { bool CheckTwoArgs(Player p, ref ushort radius, ref ushort height, string[] parts) {

View File

@ -39,7 +39,7 @@ namespace MCGalaxy.Commands.Building {
return DrawMode.normal; return DrawMode.normal;
} }
protected override DrawOp GetDrawOp(DrawArgs dArg, Vec3S32[] m) { protected override DrawOp GetDrawOp(DrawArgs dArg) {
return null; return null;
} }
@ -69,8 +69,8 @@ namespace MCGalaxy.Commands.Building {
FillDrawOp op = new FillDrawOp(); FillDrawOp op = new FillDrawOp();
op.Positions = buffer; op.Positions = buffer;
int brushOffset = cpos.Mode == DrawMode.normal ? 0 : 1; int offset = cpos.Mode == DrawMode.normal ? 0 : 1;
Brush brush = ParseBrush(p, cpos, brushOffset); Brush brush = ParseBrush(p, cpos, offset);
if (brush == null || !DrawOp.DoDrawOp(op, brush, p, marks)) return false; if (brush == null || !DrawOp.DoDrawOp(op, brush, p, marks)) return false;
bits.Clear(); bits.Clear();
op.Positions = null; op.Positions = null;

View File

@ -26,11 +26,14 @@ namespace MCGalaxy.Commands.Building {
protected override string PlaceMessage { get { return "Place two blocks to determine the endpoints."; } } 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) { 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; if (parts.Length < 2 || dArgs.Mode == DrawMode.normal) return;
string arg = parts[parts.Length - 1]; string arg = parts[parts.Length - 1];
ushort len; ushort len;
if (ushort.TryParse(arg, out len)) if (ushort.TryParse(arg, out len))
dArgs.Data = len; line.MaxLength = len;
} }
protected override DrawMode GetMode(string[] parts) { protected override DrawMode GetMode(string[] parts) {
@ -53,8 +56,12 @@ namespace MCGalaxy.Commands.Building {
return DrawMode.normal; return DrawMode.normal;
} }
protected override bool GetMarks(DrawArgs dArgs, Vec3S32[] m) { protected override DrawOp GetDrawOp(DrawArgs dArgs) {
if (dArgs.Mode != DrawMode.straight) return true; 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); 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) { if (dx > dy && dx > dz) {
@ -64,17 +71,14 @@ namespace MCGalaxy.Commands.Building {
} else if (dz > dy && dz > dx) { } else if (dz > dy && dz > dx) {
m[1].X = m[0].X; m[1].Y = m[0].Y; 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) { protected override string GetBrush(Player p, DrawArgs dArgs, ref int offset) {
brushOffset = dArgs.Mode == DrawMode.normal ? 0 : 1; LineDrawOp line = (LineDrawOp)dArgs.Op;
if (dArgs.Data != null) brushOffset++; offset = dArgs.Mode == DrawMode.normal ? 0 : 1;
return BrushFactory.Find(p.BrushName);
}
protected override DrawOp GetDrawOp(DrawArgs dArg, Vec3S32[] m) { if (line.MaxLength != int.MaxValue) offset++;
return new LineDrawOp(); return p.BrushName;
} }
public override void Help(Player p) { public override void Help(Player p) {

View File

@ -14,7 +14,7 @@
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.
*/ */
using System; using System;
using MCGalaxy.Drawing.Ops; using MCGalaxy.Drawing.Ops;
@ -31,12 +31,7 @@ namespace MCGalaxy.Commands.Building {
return DrawMode.normal; return DrawMode.normal;
} }
protected override DrawOp GetDrawOp(DrawArgs dArgs, Vec3S32[] m) { protected override DrawOp GetDrawOp(DrawArgs dArgs) {
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;
}
switch (dArgs.Mode) { switch (dArgs.Mode) {
case DrawMode.hollow: return new PyramidHollowDrawOp(); case DrawMode.hollow: return new PyramidHollowDrawOp();
case DrawMode.reverse: return new PyramidReverseDrawOp(); case DrawMode.reverse: return new PyramidReverseDrawOp();
@ -44,6 +39,12 @@ namespace MCGalaxy.Commands.Building {
return new PyramidSolidDrawOp(); 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) { public override void Help(Player p) {
Player.Message(p, "%T/pyramid [brush args] <mode>"); Player.Message(p, "%T/pyramid [brush args] <mode>");
Player.Message(p, "%HDraws a square pyramid, using two points for the base."); Player.Message(p, "%HDraws a square pyramid, using two points for the base.");

View File

@ -40,7 +40,7 @@ namespace MCGalaxy.Commands.Building {
return DrawMode.normal; return DrawMode.normal;
} }
protected override DrawOp GetDrawOp(DrawArgs dArgs, Vec3S32[] m) { protected override DrawOp GetDrawOp(DrawArgs dArgs) {
switch (dArgs.Mode) { switch (dArgs.Mode) {
case DrawMode.hollow: return new AdvHollowSphereDrawOp(); case DrawMode.hollow: return new AdvHollowSphereDrawOp();
case DrawMode.circle: return new EllipsoidDrawOp(); case DrawMode.circle: return new EllipsoidDrawOp();
@ -48,17 +48,16 @@ namespace MCGalaxy.Commands.Building {
return new AdvSphereDrawOp(); 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 p0 = m[0];
Vec3S32 radius = GetRadius(dArgs.Mode, m); Vec3S32 radius = GetRadius(dArgs.Mode, m);
m[0] = p0 - radius; m[1] = p0 + radius; m[0] = p0 - radius; m[1] = p0 + radius;
return true;
} }
protected override BrushFactory GetBrush(Player p, DrawArgs dArgs, ref int brushOffset) { protected override string GetBrush(Player p, DrawArgs dArgs, ref int offset) {
brushOffset = dArgs.Mode == DrawMode.normal ? 0 : 1; offset = dArgs.Mode == DrawMode.normal ? 0 : 1;
if (dArgs.Mode == DrawMode.solid) return BrushFactory.Find("normal"); if (dArgs.Mode == DrawMode.solid) return "normal";
return BrushFactory.Find(p.BrushName); return p.BrushName;
} }
static Vec3S32 GetRadius(DrawMode mode, Vec3S32[] m) { static Vec3S32 GetRadius(DrawMode mode, Vec3S32[] m) {

View File

@ -27,13 +27,13 @@ namespace MCGalaxy.Commands.Building {
get { return new[] { new CommandAlias("eh", null, "hollow"), new CommandAlias("cylinder", null, "vertical") }; } get { return new[] { new CommandAlias("eh", null, "hollow"), new CommandAlias("cylinder", null, "vertical") }; }
} }
protected override BrushFactory GetBrush(Player p, DrawArgs dArgs, ref int brushOffset) { protected override string GetBrush(Player p, DrawArgs dArgs, ref int offset) {
brushOffset = dArgs.Mode == DrawMode.normal ? 0 : 1; offset = dArgs.Mode == DrawMode.normal ? 0 : 1;
if (dArgs.Mode == DrawMode.solid) return BrushFactory.Find("normal"); if (dArgs.Mode == DrawMode.solid) return "normal";
return BrushFactory.Find(p.BrushName); return p.BrushName;
} }
protected override DrawOp GetDrawOp(DrawArgs dArgs, Vec3S32[] m) { protected override DrawOp GetDrawOp(DrawArgs dArgs) {
switch (dArgs.Mode) { switch (dArgs.Mode) {
case DrawMode.hollow: return new EllipsoidHollowDrawOp(); case DrawMode.hollow: return new EllipsoidHollowDrawOp();
case DrawMode.vertical: return new CylinderDrawOp(); case DrawMode.vertical: return new CylinderDrawOp();

View File

@ -30,17 +30,16 @@ namespace MCGalaxy.Commands.Building {
get { return "Place a block for the centre, then another for the radius."; } 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 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); int horR = (int)Math.Sqrt(dx * dx + dz * dz), verR = Math.Abs(dy);
Vec3S32 p0 = m[0]; Vec3S32 p0 = m[0];
m[0] = new Vec3S32(p0.X - horR, p0.Y - verR, p0.Z - horR); 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); 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(); return new TorusDrawOp();
} }

View File

@ -28,7 +28,7 @@ namespace MCGalaxy.Commands.Building {
get { return "Place three blocks to determine the edges."; } 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(); return new TriangleDrawOp();
} }

View File

@ -30,50 +30,51 @@ namespace MCGalaxy.Commands.Building {
if (Player.IsSuper(p)) { MessageInGameOnly(p); return; } if (Player.IsSuper(p)) { MessageInGameOnly(p); return; }
message = message.ToLower(); message = message.ToLower();
string[] parts = message.Split(' '); 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); Player.Message(p, PlaceMessage);
p.MakeSelection(MarksCount, cpos, DoDraw); p.MakeSelection(MarksCount, dArgs, DoDraw);
} }
protected virtual bool DoDraw(Player p, Vec3S32[] marks, protected virtual bool DoDraw(Player p, Vec3S32[] marks,
object state, byte block, byte extBlock) { object state, byte block, byte extBlock) {
DrawArgs dArgs = (DrawArgs)state; DrawArgs dArgs = (DrawArgs)state;
dArgs.Block = block; dArgs.ExtBlock = extBlock; dArgs.Block = block; dArgs.ExtBlock = extBlock;
dArgs.Player = p;
DrawOp op = GetDrawOp(dArgs, marks); GetMarks(dArgs, ref marks);
if (op == null) return false; if (marks == null) return false;
dArgs.Op = op;
GetMarks(dArgs, marks);
int offset = 0; 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); Brush brush = ParseBrush(p, dArgs, offset, factory);
dArgs.Op = null; return brush != null && DrawOp.DoDrawOp(dArgs.Op, brush, p, marks);
return brush != null && DrawOp.DoDrawOp(op, brush, p, marks);
} }
protected virtual string PlaceMessage { protected virtual string PlaceMessage {
get { return "Place two blocks to determine the edges."; } 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 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) { protected virtual void GetMarks(DrawArgs dArgs, ref Vec3S32[] m) { }
brushOffset = dArgs.Mode == DrawMode.normal ? 0 : 1;
return BrushFactory.Find(p.BrushName); 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) { internal static int GetBlock(Player p, string msg, out byte extBlock, bool checkPlacePerm = true) {
byte block = Block.Byte(msg); byte block = Block.Byte(msg);
@ -118,7 +119,6 @@ namespace MCGalaxy.Commands.Building {
public byte Block, ExtBlock; public byte Block, ExtBlock;
public string Message; public string Message;
public object Data;
public DrawOp Op; public DrawOp Op;
public Player Player; public Player Player;
} }

View File

@ -34,9 +34,11 @@ namespace MCGalaxy {
string nick, server; string nick, server;
bool reset = false; bool reset = false;
byte retries = 0; byte retries = 0;
Dictionary<string, List<string>> users = new Dictionary<string, List<string>>(); Dictionary<string, List<string>> users = new Dictionary<string, List<string>>();
static char[] trimChars = { ' ' }; static char[] trimChars = { ' ' };
ConnectionArgs args; ConnectionArgs args;
DateTime lastWho;
public IRCBot() { public IRCBot() {
UpdateState(); UpdateState();
@ -257,20 +259,18 @@ namespace MCGalaxy {
} }
Command cmd = Command.all.Find(cmdName); Command cmd = Command.all.Find(cmdName);
if (cmd != null) { 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 { Server.s.Log("IRC Command: /" + message + " (by " + user.Nick + ")");
if (!p.group.CanExecute(cmd)) { cmd.MessageCannotUse(p); return; } string args = parts.Length > 1 ? parts[1] : "";
cmd.Use(p, args); Player p = MakeIRCPlayer(user.Nick);
} catch (Exception e) {
Pm(user.Nick, "CMD Error: " + e.ToString()); 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) { void Listener_OnPublic(UserInfo user, string channel, string message) {
@ -290,43 +290,48 @@ namespace MCGalaxy {
} }
} }
if (ircCmd == ".x") { if (ircCmd == ".x" && !HandlePublicCommand(user, channel, message, parts, opchat)) return;
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 (channel.CaselessEq(opchannel)) { if (channel.CaselessEq(opchannel)) {
Server.s.Log(String.Format("(OPs): [IRC] {0}: {1}", user.Nick, message)); 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 { } else {
Server.s.Log(String.Format("[IRC] {0}: {1}", user.Nick, message)); 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) { bool CheckIRCCommand(UserInfo user, string cmdName, string channel, out string error) {
List<string> chanNicks; List<string> chanNicks;
error = null; error = null;