public void Parse(string arguments) { string targetToken = MyStrings.GetToken(ref arguments).ToLower(); #region switch target switch (targetToken) { case "person": this.What = DescribeOrder.Target.Person; break; case "object": this.What = DescribeOrder.Target.Object; break; default: throw new Exception("Bad target " + targetToken); } #endregion string desc = MyStrings.GetQuotedToken(ref arguments); string descriptionToken = MyStrings.GetValidString(desc); if (desc != descriptionToken) { throw new Exception("Invalid characters in description"); } this.Description = descriptionToken.Trim(); }
public void Parse(Faction faction, string arguments) { // declare 12 neutral string factionToken = MyStrings.GetToken(ref arguments).ToLower(); if (factionToken == "default") { // TODO: correct the logic // the logic here is mangled, it does work but I don't like it // it would be better to have class element public bool default instead this.FactionNum = faction.Num; } else { if (!MyStrings.IsNumber(factionToken)) { throw new Exception("Bad faction"); } // TODO: missing check for existance of faction this.FactionNum = Convert.ToInt32(factionToken); } string attitudeToken = MyStrings.GetQuotedToken(ref arguments).ToLower(); Attitude attitude = Attitude.Hostile; while (attitude <= Attitude.Ally && attitude.ToString().ToLower() != attitudeToken) { attitude++; } if (attitude > Attitude.Ally) { throw new Exception("Bad attitude " + attitudeToken); } this.Attitude = attitude; }
private static DescribeOrder ReadDescribeOrder(string s) { DescribeOrder ord = new DescribeOrder(); string t1 = MyStrings.GetToken(ref s).ToLower(); if (t1 == "person") { ord.What = DescribeOrder.Target.Person; } else if (t1 == "object") { ord.What = DescribeOrder.Target.Object; } else { throw new Exception("Bad target"); } string t2 = MyStrings.GetValidString(MyStrings.GetQuotedToken(ref s)); if (t2.Trim() == "") { throw new Exception("Bad description"); } ord.Description = t2; return(ord); }
private static NameOrder ReadNameOrder(string s) { NameOrder ord = new NameOrder(); string t1 = MyStrings.GetToken(ref s).ToLower(); if (t1 == "person") { ord.What = NameOrder.Target.Person; } else if (t1 == "faction") { ord.What = NameOrder.Target.Faction; } else if (t1 == "object") { ord.What = NameOrder.Target.Object; } else { throw new Exception("Bad target"); } string t2 = MyStrings.GetValidString(MyStrings.GetQuotedToken(ref s)); if (t2.Trim() == "") { throw new Exception("Bad name"); } ord.Name = t2; return(ord); }
private static DeclareOrder ReadDeclareOrder(Faction faction, string s) { // declare 12 neutral DeclareOrder ord = new DeclareOrder(); string t1 = MyStrings.GetToken(ref s).ToLower(); if (t1 == "default") { ord.FactionNum = faction.Num; } else if (!MyStrings.IsNumber(t1)) { throw new Exception("Bad faction"); } ord.FactionNum = Convert.ToInt32(t1); string t2 = MyStrings.GetQuotedToken(ref s); Attitude a = Attitude.Hostile; while (a <= Attitude.Ally && a.ToString().ToLower() != t2) { a++; } if (a > Attitude.Ally) { throw new Exception("Bad attitude"); } ord.Attitude = a; return(ord); }
public void Parse(string arguments) { string targetToken = MyStrings.GetToken(ref arguments); if (!MyStrings.IsNumber(targetToken)) { throw new Exception("Bad target " + targetToken); } this.Target = Convert.ToInt32(targetToken); string amountToken = MyStrings.GetToken(ref arguments).ToLower(); if (amountToken == "all") { this.Amount = -1; } else { if (!MyStrings.IsNumber(amountToken)) { throw new Exception("Bad amount " + amountToken); } this.Amount = Convert.ToInt32(amountToken); } string itemToken = MyStrings.GetQuotedToken(ref arguments); this.What = ItemType.GetByAnyName(itemToken); if (this.What == null) { throw new Exception("Bad item " + itemToken); } }
public void Parse(string arguments) { string targetToken = MyStrings.GetToken(ref arguments).ToLower(); switch (targetToken) { case "person": this.What = NameOrder.Target.Person; break; case "faction": this.What = NameOrder.Target.Faction; break; case "object": this.What = NameOrder.Target.Object; break; default: throw new Exception("Bad target " + targetToken); } string name = MyStrings.GetQuotedToken(ref arguments); string nameToken = MyStrings.GetValidString(name); if (nameToken != name) { throw new Exception("Invalid characters in name"); } if (nameToken.Trim() == "") { throw new Exception("Bad name"); } this.Name = nameToken.Trim(); }
public void Parse(Faction faction, string arguments) { string passwordToken = MyStrings.GetQuotedToken(ref arguments); if (passwordToken != faction.Password) { throw new Exception("Wrong password"); } }
public void Parse(string arguments) { string token = MyStrings.GetQuotedToken(ref arguments); if (token.Trim() == "") { throw new Exception("Address can't be empty"); } this.Email = token; }
public void Parse(string arguments) { string token = MyStrings.GetQuotedToken(ref arguments); ItemType itemType = ItemType.GetByAnyName(token); if (itemType == null) { throw new Exception("Bad item " + token); } this.ItemType = itemType; }
public void Parse(string arguments) { string token = MyStrings.GetQuotedToken(ref arguments).ToLower(); this.What = BuildingType.GetByAnyName(token); if (this.What == null) { throw new Exception("Bad object " + token); } // TODO: missing check if item is buildable }
private static InstallOrder ReadInstallOrder(string s) { InstallOrder ord = new InstallOrder(); ord.What = ItemType.GetByAnyName(MyStrings.GetQuotedToken(ref s)); if (ord.What == null) { throw new Exception("Bad item"); } return(ord); }
private static BuildOrder ReadBuildOrder(string s) { string t1 = MyStrings.GetQuotedToken(ref s).ToLower(); BuildOrder ord = new BuildOrder(); ord.What = BuildingType.GetByAnyName(t1); if (ord.What == null) { throw new Exception("Bad object"); } return(ord); }
private static QuitOrder ReadQuitOrder(string s, Faction f) { string t1 = MyStrings.GetQuotedToken(ref s); if (t1 != f.Password) { throw new Exception("Wrong password"); } QuitOrder ord = new QuitOrder(); return(ord); }
private static AddressOrder ReadAddressOrder(string s) { string t2 = MyStrings.GetQuotedToken(ref s); if (t2.Trim() == "") { throw new Exception("Address can't be empty"); } AddressOrder ord = new AddressOrder(); ord.Email = t2; return(ord); }
public void Parse(string arguments) { string targetToken = MyStrings.GetToken(ref arguments).ToLower(); #region target token switch switch (targetToken) { case "faction": string factionToken = MyStrings.GetToken(ref arguments); if (!MyStrings.IsNumber(factionToken)) { throw new Exception("Bad faction " + factionToken); } this.FactionNum = Convert.ToInt32(factionToken); break; case "item": string itemToken = MyStrings.GetQuotedToken(ref arguments).ToLower(); ItemType itemType = ItemType.GetByAnyName(itemToken); if (itemType == null) { throw new Exception("Bad item " + itemToken); } this.ItemType = itemType; break; case "skill": string skillToken = MyStrings.GetQuotedToken(ref arguments).ToLower(); SkillType skillType = SkillType.GetByAnyName(skillToken); if (skillType == null) { throw new Exception("Bad skill " + skillToken); } this.SkillType = skillType; break; case "object": string objectToken = MyStrings.GetQuotedToken(ref arguments).ToLower(); BuildingType buildingType = BuildingType.GetByAnyName(objectToken); if (buildingType == null) { throw new Exception("Bad object"); } this.BuildingType = buildingType; break; default: throw new Exception("Bad parameter " + targetToken); } #endregion }
private static ProduceOrder ReadProduceOrder(string s) { string t1 = MyStrings.GetQuotedToken(ref s); ItemType it = ItemType.GetByAnyName(t1); if (it == null) { throw new Exception("Bad item"); } ProduceOrder ord = new ProduceOrder(); ord.ItemType = it; return(ord); }
public void Parse(string arguments) { string token = MyStrings.GetQuotedToken(ref arguments); if (token.Trim() == string.Empty) { throw new Exception("Password can't be empty"); } if (token != MyStrings.GetValidString(token)) { throw new Exception("Bad symbols in password"); } this.Password = token; }
private static Order ReadItemTypeListOrder(string s, ItemTypeListOrder ord) { while (s.Trim() != "") { string t2 = MyStrings.GetQuotedToken(ref s).ToLower(); ItemType it = ItemType.GetByAnyName(t2); if (it == null) { throw new Exception("Bad item"); } ord.What.Add(it); } return(ord); }
private static ShowOrder ReadShowOrder(string s) { ShowOrder ord = new ShowOrder(); string t1 = MyStrings.GetToken(ref s).ToLower(); if (t1 == "faction") { string t2 = MyStrings.GetToken(ref s); if (!MyStrings.IsNumber(t2)) { throw new Exception("Bad faction"); } ord.FactionNum = Convert.ToInt32(t2); } else if (t1 == "item") { string t2 = MyStrings.GetQuotedToken(ref s).ToLower(); ord.ItemType = ItemType.GetByAnyName(t2); if (ord.ItemType == null) { throw new Exception("Bad item"); } } else if (t1 == "skill") { string t2 = MyStrings.GetQuotedToken(ref s).ToLower(); ord.SkillType = SkillType.GetByAnyName(t2); if (ord.SkillType == null) { throw new Exception("Bad skill"); } } else if (t1 == "object") { string t2 = MyStrings.GetQuotedToken(ref s).ToLower(); ord.BuildingType = BuildingType.GetByAnyName(t2); if (ord.BuildingType == null) { throw new Exception("Bad object"); } } else { throw new Exception("Bad parameter"); } return(ord); }
public virtual void Parse(string arguments) { while (arguments.Trim() != "") { string token = MyStrings.GetQuotedToken(ref arguments).ToLower(); ItemType it = ItemType.GetByAnyName(token); if (it == null) { throw new Exception("Bad item " + token); } if (this.What.Contains(it)) { throw new Exception("Duplicate item " + token); } this.What.Add(it); } }
private static PasswordOrder ReadPasswordOrder(string s) { string t1 = MyStrings.GetQuotedToken(ref s); if (t1.Trim() == "") { throw new Exception("Password can't be empty"); } if (t1 != MyStrings.GetValidString(t1)) { throw new Exception("Bad symbols in password"); } PasswordOrder ord = new PasswordOrder(); ord.Password = t1; return(ord); }
private static UninstallOrder ReadUninstallOrder(string s) { UninstallOrder ord = new UninstallOrder(); string t1 = MyStrings.GetQuotedToken(ref s); if (MyStrings.IsNumber(t1)) { ord.Amount = Convert.ToInt32(t1); t1 = MyStrings.GetQuotedToken(ref s); } else { ord.Amount = -1; } ord.What = ItemType.GetByAnyName(t1); if (ord.What == null) { throw new Exception("Bad item"); } return(ord); }
private static GiveOrder ReadGiveOrder(string s) { GiveOrder ord = new GiveOrder(); string t1 = MyStrings.GetToken(ref s); if (!MyStrings.IsNumber(t1)) { throw new Exception("Bad target"); } ord.Target = Convert.ToInt32(t1); string t2 = MyStrings.GetToken(ref s).ToLower(); if (t2 == "all") { ord.Amount = -1; } else { if (!MyStrings.IsNumber(t2)) { throw new Exception("Bad amount"); } ord.Amount = Convert.ToInt32(t2); } string t3 = MyStrings.GetQuotedToken(ref s); ord.What = ItemType.GetByAnyName(t3); if (ord.What == null) { throw new Exception("Bad item"); } return(ord); }
public override void Parse(string arguments) { string argumentsCopy = arguments; string token = MyStrings.GetQuotedToken(ref argumentsCopy); if (MyStrings.IsNumber(token)) { // UNINSTALL 10 BLOC this.Amount = Convert.ToInt32(token); string itemToken = MyStrings.GetQuotedToken(ref argumentsCopy); ItemType itemType = ItemType.GetByAnyName(itemToken); if (itemType == null) { throw new Exception("Bad item " + itemToken); } this.What.Add(itemType); } else { // UNINSTALL BLOC CONS this.Amount = -1; base.Parse(arguments); } }
public static void Load(string filename, bool checker) { TextReader tr = new StreamReader(filename, System.Text.Encoding.GetEncoding(1251)); bool do_read = false; Person person = null; Faction faction = null; bool errors = false; ArrayList CheckerOutput = new ArrayList(); while (true) { try { string line = tr.ReadLine(); string s = line; if (s == null) { break; } // Store repeating lines if (s.Length > 0 && s[0] == '@') { if (person != null) { person.RepeatingLines.Add(line); } s = s.Substring(1); } // Strip comments s = MyStrings.Uncomment(s).Trim(); // Get first word as command string cmd = MyStrings.GetToken(ref s).ToLower(); // Directives if (cmd == "#orders") { string t2 = MyStrings.GetToken(ref s); if (!MyStrings.IsNumber(t2)) { throw new Exception("Bad faction"); } int num = Convert.ToInt32(t2); string password = MyStrings.GetQuotedToken(ref s); faction = (Faction)Faction.Get(num); if (faction == null) { throw new Exception("No such faction"); } if (password != faction.Password || faction.IsNPC) { throw new Exception("Wrong password"); } Console.WriteLine("..orders for " + faction.Num.ToString()); CheckerOutput.Add("To: " + faction.Email); CheckerOutput.Add("Subject: [Wasteland] Checker Output"); CheckerOutput.Add(""); CheckerOutput.Add(line); do_read = true; continue; } if (cmd == "#end") { do_read = false; } if (!do_read || cmd == "") { continue; } if (cmd == "person") { string t2 = MyStrings.GetToken(ref s); if (!MyStrings.IsNumber(t2)) { throw new Exception("Bad person"); } int num = Convert.ToInt32(t2); person = faction.Persons.GetByNumber(num); if (person == null) { throw new Exception("This person is not in your faction"); } CheckerOutput.Add("\r\n" + line); continue; } CheckerOutput.Add(line); if (person == null) { throw new Exception("Order given with no person specified"); } Order order = OrdersReader.ParseOrder(person, faction, cmd, s); // Overwrite monthlong order if (order.IsMonthlong) { int i = 0; while (i < person.Orders.Count) { if (((Order)person.Orders[i]).IsMonthlong) { person.Orders.RemoveAt(i); CheckerOutput.Add("; **** Overwriting previous monthlong order ****\r\n"); errors = true; } else { i++; } } } // Overwrite trade order if (order.GetType() == typeof(TradeOrder)) { int i = 0; while (i < person.Orders.Count) { if (person.Orders[i].GetType() == typeof(TradeOrder)) { person.Orders.RemoveAt(i); CheckerOutput.Add("; **** Overwriting previous trade order ****\r\n"); errors = true; } else { i++; } } } person.Orders.Add(order); } catch (Exception ex) { CheckerOutput.Add("; **** " + ex.Message + " ****\r\n"); errors = true; } } tr.Close(); if (checker) { string checkername = Path.Combine(Path.GetDirectoryName(filename), "checker." + Path.GetFileName(filename)); TextWriter tw = new StreamWriter(checkername, false, System.Text.Encoding.GetEncoding(1251)); if (errors) { foreach (string s in CheckerOutput) { tw.WriteLine(s); } } else { // Write only message header foreach (string s in CheckerOutput) { tw.WriteLine(s); if (s == "") { break; } } tw.WriteLine("Your order was accepted without errors."); } tw.Close(); } }
public void Parse(string arguments) { string token = MyStrings.GetToken(ref arguments).ToLower(); string itemToken; ItemType itemType; // TODO: refactor needed, this logic isn't very clear if (token == "with") { token = MyStrings.GetToken(ref arguments); if (!MyStrings.IsNumber(token)) { throw new Exception("Bad target " + token); } this.PersonNum = Convert.ToInt32(token); token = MyStrings.GetToken(ref arguments).ToLower(); } else { this.PersonNum = 0; } if (token == "all") { this.SellAmount = -1; } else { if (!MyStrings.IsNumber(token)) { throw new Exception("Bad sell amount " + token); } this.SellAmount = Convert.ToInt32(token); } itemToken = MyStrings.GetQuotedToken(ref arguments); itemType = ItemType.GetByAnyName(itemToken); if (itemType == null) { throw new Exception("Bad sell item " + itemToken); } this.SellWhat = itemType; token = MyStrings.GetToken(ref arguments).ToLower(); if (token == "all") { this.BuyAmount = -1; } else { if (!MyStrings.IsNumber(token)) { throw new Exception("Bad buy amount " + token); } this.BuyAmount = Convert.ToInt32(token); } itemToken = MyStrings.GetQuotedToken(ref arguments); itemType = ItemType.GetByAnyName(itemToken); if (itemType == null) { throw new Exception("Bad buy item " + itemToken); } this.BuyWhat = itemType; }
private static TradeOrder ReadTradeOrder(string s) { TradeOrder ord = new TradeOrder(); string t1 = MyStrings.GetToken(ref s).ToLower(); if (t1 == "with") { string num = MyStrings.GetToken(ref s); if (!MyStrings.IsNumber(num)) { throw new Exception("Bad target"); } ord.PersonNum = Convert.ToInt32(num); t1 = MyStrings.GetToken(ref s).ToLower(); } else { ord.PersonNum = 0; } if (t1 == "all") { ord.SellAmount = -1; } else { if (!MyStrings.IsNumber(t1)) { throw new Exception("Bad sell amount"); } ord.SellAmount = Convert.ToInt32(t1); } ord.SellWhat = ItemType.GetByAnyName(MyStrings.GetQuotedToken(ref s)); if (ord.SellWhat == null) { throw new Exception("Bad sell item"); } string t2 = MyStrings.GetToken(ref s).ToLower(); if (t2 == "all") { ord.BuyAmount = -1; } else { if (!MyStrings.IsNumber(t2)) { throw new Exception("Bad buy amount"); } ord.BuyAmount = Convert.ToInt32(t2); } ord.BuyWhat = ItemType.GetByAnyName(MyStrings.GetQuotedToken(ref s)); if (ord.BuyWhat == null) { throw new Exception("Bad buy item"); } return(ord); }
public static void Load(string filename, bool checker) { TextReader tr = new StreamReader(filename, System.Text.Encoding.GetEncoding(1251)); bool do_read = false; Person person = null; Faction faction = null; bool errors = false; ArrayList CheckerOutput = new ArrayList(); while (true) { try { string line = tr.ReadLine(); string s = line; if (s == null) { break; } // Store repeating lines if (s.Length > 0 && s[0] == '@') { if (person != null) { person.RepeatingLines.Add(line); } s = s.Substring(1); } // Strip comments s = MyStrings.Uncomment(s).Trim(); // Get first word as command string cmd = MyStrings.GetToken(ref s).ToLower(); // Directives if (cmd == "#orders") { string t2 = MyStrings.GetToken(ref s); if (!MyStrings.IsNumber(t2)) { throw new Exception("Bad faction"); } int num = Convert.ToInt32(t2); string password = MyStrings.GetQuotedToken(ref s); faction = (Faction)Faction.Get(num); if (faction == null) { throw new Exception("No such faction"); } if (password != faction.Password || faction.IsNPC) { throw new Exception("Wrong password"); } Console.WriteLine("..orders for " + faction.Num.ToString()); CheckerOutput.Add("To: " + faction.Email); CheckerOutput.Add("Subject: Checker Output"); CheckerOutput.Add(""); CheckerOutput.Add(line); do_read = true; continue; } if (cmd == "#end") { do_read = false; } if (!do_read || cmd == "") { continue; } if (cmd == "person") { string t2 = MyStrings.GetToken(ref s); if (!MyStrings.IsNumber(t2)) { throw new Exception("Bad person"); } int num = Convert.ToInt32(t2); person = faction.Persons.GetByNumber(num); if (person == null) { throw new Exception("This person is not in your faction"); } CheckerOutput.Add("\r\n" + line); continue; } CheckerOutput.Add(line); if (person == null) { throw new Exception("Order given with no person specified"); } Order order; if (cmd == "address") { order = ReadAddressOrder(s); } else if (cmd == "attack") { order = ReadPersonNumOrder(s, new AttackOrder()); } else if (cmd == "avoid") { order = ReadAvoidOrder(s); } else if (cmd == "build") { order = ReadBuildOrder(s); } else if (cmd == "burn") { order = ReadItemTypeListOrder(s, new BurnOrder()); } else if (cmd == "consume") { order = ReadItemTypeListOrder(s, new ConsumeOrder()); } else if (cmd == "cure") { order = ReadCureOrder(s); } else if (cmd == "declare") { order = ReadDeclareOrder(faction, s); } else if (cmd == "describe") { order = ReadDescribeOrder(s); } else if (cmd == "drive") { order = ReadDriveOrder(s); } else if (cmd == "enter") { order = ReadEnterOrder(s); } else if (cmd == "equipment") { order = ReadItemTypeListOrder(s, new EquipmentOrder()); } else if (cmd == "evict") { order = ReadPersonNumOrder(s, new EvictOrder()); } else if (cmd == "give") { order = ReadGiveOrder(s); } else if (cmd == "hide") { order = ReadHideOrder(s); } else if (cmd == "install") { order = ReadInstallOrder(s); } else if (cmd == "kick") { order = new KickOrder(); } else if (cmd == "leave") { order = new LeaveOrder(); } else if (cmd == "maintain") { order = new MaintainOrder(); } else if (cmd == "move") { order = ReadMoveOrder(s); } else if (cmd == "name") { order = ReadNameOrder(s); } else if (cmd == "option") { order = ReadOptionOrder(s); } else if (cmd == "password") { order = ReadPasswordOrder(s); } else if (cmd == "patrol") { order = new PatrolOrder(); } else if (cmd == "produce") { order = ReadProduceOrder(s); } else if (cmd == "quit") { order = ReadQuitOrder(s, faction); } else if (cmd == "scavenge") { order = ReadItemTypeListOrder(s, new ScavengeOrder()); } else if (cmd == "show") { order = ReadShowOrder(s); } else if (cmd == "team") { order = ReadTeamOrder(s); } else if (cmd == "trade") { order = ReadTradeOrder(s); } else if (cmd == "uninstall") { order = ReadUninstallOrder(s); } else { throw new Exception("Bad order"); } // Overwrite monthlong order if (order.IsMonthlong) { int i = 0; while (i < person.Orders.Count) { if (((Order)person.Orders[i]).IsMonthlong) { person.Orders.RemoveAt(i); CheckerOutput.Add("; **** Overwriting previous monthlong order ****\r\n"); errors = true; } else { i++; } } } // Overwrite trade order if (order.GetType() == typeof(TradeOrder)) { int i = 0; while (i < person.Orders.Count) { if (person.Orders[i].GetType() == typeof(TradeOrder)) { person.Orders.RemoveAt(i); CheckerOutput.Add("; **** Overwriting previous trade order ****\r\n"); errors = true; } else { i++; } } } person.Orders.Add(order); } catch (Exception ex) { CheckerOutput.Add("; **** " + ex.Message + " ****\r\n"); errors = true; } } tr.Close(); if (checker) { TextWriter tw = new StreamWriter(filename + ".checker", false, System.Text.Encoding.GetEncoding(1251)); if (errors) { foreach (string s in CheckerOutput) { tw.WriteLine(s); } } else { // Write only message header foreach (string s in CheckerOutput) { tw.WriteLine(s); if (s == "") { break; } } tw.WriteLine("Your order was accepted without errors."); } tw.Close(); } }