public void TestDeferredActionDone() { bool doneFlag = false; INetworkAction chat = new NetworkAction(); DeferredAction<INetworkAction> deferredAction = new DeferredAction<INetworkAction>() { Action = chat, Done = (action, requests, responses) => { doneFlag = true; } }; Assert.IsTrue(deferredAction.TryInsertDone(chat, new List<IPacket>() { new Packet() { Origin = PacketOrigin.Client, Type = PacketType.Request, RequestId = 1 } }, new List<IPacket>() { new Packet() { Origin = PacketOrigin.Client, Type = PacketType.Response, RequestId = 1 } })); Assert.IsTrue(doneFlag); }
public void TestDeferredActionAlways() { bool alwaysFlag = false; INetworkAction chat = new NetworkAction(); DeferredAction<INetworkAction> deferredAction = new DeferredAction<INetworkAction>() { Action = chat, Always = action => { alwaysFlag = true; } }; Assert.IsTrue(deferredAction.TryInsertAlways(chat)); Assert.IsTrue(alwaysFlag); }
protected ICommandResult TestCommand(ICommand command, Dictionary<String, ICommandParameter> parameters) { ICommandResult e = parameters["e"].First<ICommandResult>(); NetworkAction output = new NetworkAction() { ActionType = NetworkActionType.NetworkTextSay, Now = { Content = new List<String>() } }; Console.WriteLine(e.Now.TextCommands.First().Description); TextCommandMatchModel match = e.Now.TextCommandMatches.First(); if (match.Players != null && match.Players.Count > 0) { output.Now.Content.Add("Players: " + String.Join(", ", match.Players.Select(x => x.Name).ToArray())); } if (match.Maps != null && match.Maps.Count > 0) { output.Now.Content.Add("Maps: " + String.Join(", ", match.Maps.Select(x => x.Name).ToArray())); } if (match.Numeric != null && match.Numeric.Count > 0) { output.Now.Content.Add("Numeric: " + String.Join(", ", match.Numeric.Select(x => String.Format("{0:F2}", x)).ToArray())); } if (match.Delay != null) { output.Now.Content.Add(String.Format("Delay: {0} (UTC+9:30 Adelaide)", match.Delay)); } if (match.Interval != null) { output.Now.Content.Add(String.Format("Interval: {0}", match.Interval)); } if (match.Period != null) { output.Now.Content.Add(String.Format("Duration: {0}", match.Period)); } if (e.Now.TextCommands.Count > 1) { output.Now.Content.Add("Alternate Commands: " + String.Join(" ", e.Now.TextCommands.Skip(1).Select(x => x.PluginCommand).ToArray())); } if (match.Quotes != null && match.Quotes.Count > 0) { output.Now.Content.Add("Quotes: " + String.Join(", ", match.Quotes.Select(x => String.Format("--{0}--", x)).ToArray())); } this.Action(output); return command.Result; }
protected ICommandResult HelpCommand(ICommand command, Dictionary<String, ICommandParameter> parameters) { ICommandResult e = parameters["e"].First<ICommandResult>(); NetworkAction output = new NetworkAction() { ActionType = NetworkActionType.NetworkTextSay }; if (e.Now.TextCommands.Count > 1) { output.Now.Content.Add("Place Holder"); /* // List of commands. this.ProxyNetworkAction(new Chat() { Text = "Place Holder", //this.PlayerLoc(e.Now.Players.First(), "HelpCommandHeader", e.Now.TextCommandMatches.First().Prefix), Subset = new PlayerSubset() }); */ if (this.ProtocolState.Settings.Maximum.ChatLinesCount.HasValue == true) { foreach (string line in String.Join(", ", this.ShortCommandList(e).ToArray()).WordWrap(this.ProtocolState.Settings.Maximum.ChatLinesCount.Value)) { output.Now.Content.Add(line); } } } else { foreach (TextCommandModel alternate in e.Now.TextCommands.Skip(1)) { //string description = String.Format("> {0}: {1}", alternate.Commands.FirstOrDefault(), this.NamespacePlayerLoc(e.Now.Players.First(), this.GetType().Namespace + "." + alternate.PluginUid, alternate.PluginCommand)); string description = String.Format("> {0}", alternate.Commands.FirstOrDefault()); if (this.ProtocolState.Settings.Maximum.ChatLinesCount.HasValue == true) { foreach (string line in description.WordWrap(this.ProtocolState.Settings.Maximum.ChatLinesCount.Value)) { output.Now.Content.Add(line); } } } } this.Action(output); return command.Result; }
public void TestDeferredActionSent() { bool sentFlag = false; INetworkAction chat = new NetworkAction(); DeferredAction<INetworkAction> deferredAction = new DeferredAction<INetworkAction>() { Action = chat, Sent = (action, requests) => { sentFlag = true; } }; Assert.IsTrue(deferredAction.TryInsertSent(chat, new List<IPacket>() { new Packet() { Origin = PacketOrigin.Client, Type = PacketType.Request, RequestId = 1 } })); Assert.IsTrue(sentFlag); }
public void TestDeferredActionRelease() { INetworkAction chat = new NetworkAction(); DeferredAction<INetworkAction> deferredAction = new DeferredAction<INetworkAction>() { Action = chat, Sent = (action, requests) => { }, Each = (action, request, response) => { }, Done = (action, requests, responses) => { }, Expired = (action, requests, responses) => { }, Always = action => { } }; deferredAction.Release(); Assert.IsNull(deferredAction.Sent); Assert.IsNull(deferredAction.Each); Assert.IsNull(deferredAction.Done); Assert.IsNull(deferredAction.Expired); Assert.IsNull(deferredAction.Always); }
public void TestDeferredActionGetAction() { INetworkAction chat = new NetworkAction() { ActionType = NetworkActionType.NetworkTextSay }; DeferredAction<INetworkAction> deferredAction = new DeferredAction<INetworkAction>() { Action = chat }; Assert.AreEqual(chat.Uid, deferredAction.GetAction().Uid); }