public void TestIp() { PlayerModel player = new PlayerModel() { Ip = "1.1.1.1" }; Assert.AreEqual("1.1.1.1", player.Ip); }
public static PlayerModel Parse(IList<String> parameters, IList<String> variables) { PlayerModel player = new PlayerModel(); // Make sure the parameter's passed in are correct. if (parameters.Count == variables.Count) { // Parse and normalize the parameters. for (int i = 0; i < parameters.Count; i++) { int intValue = 0; switch (parameters[i].ToLower()) { case "guid": player.Uid = variables[i]; break; case "name": player.Name = variables[i]; break; case "clantag": player.ClanTag = variables[i]; break; case "teamid": if (int.TryParse(variables[i], out intValue)) { player.Groups.Add(new GroupModel() { Type = GroupModel.Team, Uid = intValue.ToString(CultureInfo.InvariantCulture) }); } break; case "squadid": if (int.TryParse(variables[i], out intValue)) { player.Groups.Add(new GroupModel() { Type = GroupModel.Squad, Uid = intValue.ToString(CultureInfo.InvariantCulture) }); } break; case "kills": if (int.TryParse(variables[i], out intValue)) player.Kills = intValue; break; case "deaths": if (int.TryParse(variables[i], out intValue)) player.Deaths = intValue; break; case "score": if (int.TryParse(variables[i], out intValue)) player.Score = intValue; break; case "ping": uint uintValue = 0; if (uint.TryParse(variables[i], out uintValue)) player.Ping = uintValue; break; } } } return player; }
public void TestKdrNoDeaths() { PlayerModel player = new PlayerModel() { Kills = 10, Deaths = 0 }; Assert.AreEqual(10, player.Kdr); }
public void TestKdr() { PlayerModel player = new PlayerModel() { Kills = 10, Deaths = 5 }; Assert.AreEqual(2, player.Kdr); }
public void TestIpPort() { PlayerModel player = new PlayerModel() { Ip = "1.1.1.1:9000" }; Assert.AreEqual("1.1.1.1", player.Ip); Assert.AreEqual("9000", player.Port); }
public void TestModifyGroupDoesNotExist() { PlayerModel player = new PlayerModel(); player.ModifyGroup( new GroupModel() { Type = GroupModel.Team, Uid = "1" } ); Assert.AreEqual("1", player.Groups.First(group => group.Type == GroupModel.Team).Uid); Assert.AreEqual(1, player.Groups.Count); }
public override void PlayerOnJoinDispatchHandler(IPacketWrapper request, IPacketWrapper response) { if (request.Packet.Words.Count >= 2) { PlayerModel player = new PlayerModel() { Name = request.Packet.Words[1], Uid = request.Packet.Words[2] }; IProtocolStateDifference difference = new ProtocolStateDifference() { Modified = { Players = new ConcurrentDictionary<String, PlayerModel>(new Dictionary<String, PlayerModel>() { { player.Uid, player } }) } }; this.ApplyProtocolStateDifference(difference); this.OnProtocolEvent( ProtocolEventType.ProtocolPlayerJoin, difference, new ProtocolEventData() { Players = new List<PlayerModel>() { player } } ); } }
public void TestNameStripped() { PlayerModel player = new PlayerModel { Name = "P]-[0gu3 Brösel" }; Assert.AreEqual("P]-[0gu3 Brösel", player.Name); Assert.AreEqual("PHOguE Brosel", player.NameStripped); }
protected ICommandResult TestPluginParameters(ICommand command, Dictionary<String, ICommandParameter> parameters) { String name = parameters["name"].First<String>(); int score = parameters["score"].First<int>(); PlayerModel player = new PlayerModel() { Name = name, Score = score }; TestParameterPageView index = new TestParameterPageView() { Player = player }; command.Result = new CommandResult() { Now = new CommandData() { Content = new List<string>() { index.TransformText() } }, ContentType = Mime.TextHtml, CommandResultType = CommandResultType.Success, Success = true, Message = name }; return command.Result; }
public virtual void PlayerOnAuthenticatedDispatchHandler(IPacketWrapper request, IPacketWrapper response) { if (request.Packet.Words.Count >= 3) { PlayerModel statePlayer = this.State.Players.Select(p => p.Value).FirstOrDefault(p => p.Name == request.Packet.Words[1]); if (statePlayer != null) { statePlayer.Uid = request.Packet.Words[2]; } else { statePlayer = new PlayerModel() { Name = request.Packet.Words[1], Uid = request.Packet.Words[2] }; } IProtocolStateDifference difference = new ProtocolStateDifference() { Modified = { Players = new ConcurrentDictionary<String, PlayerModel>(new Dictionary<String, PlayerModel>() { { statePlayer.Uid, statePlayer } }) } }; this.ApplyProtocolStateDifference(difference); this.OnProtocolEvent( ProtocolEventType.ProtocolPlayerJoin, difference, new ProtocolEventData() { Players = new List<PlayerModel>() { statePlayer } } ); } }
/// <summary> /// Runs through the various parsers for all of the text commands. /// </summary> /// <remarks> /// This method may fire multiple events to execute multiple commands /// when more than one parser is included in the future. This is expected /// behaviour. /// </remarks> /// <param name="speakerNetworkPlayer"></param> /// <param name="speakerAccount"></param> /// <param name="prefix"></param> /// <param name="text"></param> /// <returns>The generated event, if any.</returns> protected ICommandResult Parse(PlayerModel speakerNetworkPlayer, AccountModel speakerAccount, String prefix, String text) { List<ITextCommandParser> parsers = new List<ITextCommandParser>() { this.BuildFuzzyParser(speakerNetworkPlayer, speakerAccount), this.BuildRouteParser(speakerNetworkPlayer, speakerAccount) }; return parsers.Select(parser => parser.Parse(prefix, text)).FirstOrDefault(result => result != null); }
/// <summary> /// Fetches a route text parser /// </summary> /// <param name="speaker">The player executing the command</param> /// <param name="speakerAccount">The account executing the command</param> /// <returns>The route parser, provided a language could be found.</returns> protected ITextCommandParser BuildRouteParser(PlayerModel speaker, AccountModel speakerAccount) { return new RouteParser() { Connection = this.Connection, TextCommands = this.TextCommands.Where(textCommand => textCommand.Parser == TextCommandParserType.Any || textCommand.Parser == TextCommandParserType.Route).ToList(), SpeakerPlayer = speaker, SpeakerAccount = speakerAccount }; }
/// <summary> /// Fetches a fuzzy text parser /// </summary> /// <param name="speaker">The player executing the command</param> /// <param name="speakerAccount">The account executing the command</param> /// <returns>The fuzzy parser, provided a language could be found.</returns> protected ITextCommandParser BuildFuzzyParser(PlayerModel speaker, AccountModel speakerAccount) { LanguageConfig selectedLanguage = null; if (speakerAccount != null && speakerAccount.PreferredLanguageCode != String.Empty) { selectedLanguage = this.Shared.Languages.FindOptimalLanguageConfig(speakerAccount.PreferredLanguageCode); } else { selectedLanguage = this.Shared.Languages.Default; } return new FuzzyParser() { Connection = this.Connection, TextCommands = this.TextCommands.Where(textCommand => textCommand.Parser == TextCommandParserType.Any || textCommand.Parser == TextCommandParserType.Fuzzy).ToList(), Document = selectedLanguage.Config.Document, SpeakerPlayer = speaker, SpeakerAccount = speakerAccount }; }