Esempio n. 1
0
        static void Main(string[] args)
        {
                        #if RELEASE
            try
            {
                        #endif
            string data_file      = Path.Combine(Directory.GetCurrentDirectory(), "data.xml");
            string turn_dir       = Directory.GetCurrentDirectory();
            string order_to_check = null;

            for (int i = 0; i < args.Length - 1; i++)
            {
                if (args[i] == "/data")
                {
                    data_file = args[i + 1];
                }
                else if (args[i] == "/turn-dir")
                {
                    turn_dir = args[i + 1];
                }
                else if (args[i] == "/check")
                {
                    order_to_check = args[i + 1];
                }
            }

            Console.WriteLine("Wasteland " + EngineVersion);
            Console.WriteLine("");
            Console.WriteLine("Loading data file");
            DataFile.LoadData(data_file);
            Console.WriteLine("Loading game");
            DataFile.LoadGame(turn_dir);

            if (order_to_check == null)
            {
                Console.WriteLine("Processing requests");
                Request.Load(turn_dir);
                Console.WriteLine("Loading orders");
                OrdersReader.Load(turn_dir);
                Console.WriteLine("Processing orders");
                OrdersProcessor.Process();
                Console.WriteLine("Generating reports");
                Report.Generate(turn_dir);
                Console.WriteLine("Saving game");
                DataFile.SaveGame(turn_dir);
            }
            else
            {
                Console.Write("Checking order");
                OrdersReader.Load(order_to_check, true);
            }
                        #if RELEASE
        }

        catch (Exception ex)
        {
            TextWriter tw = new StreamWriter("error.log", true, System.Text.Encoding.GetEncoding(1251));
            tw.WriteLine(ex.Message);
            tw.WriteLine(ex.StackTrace);
            tw.WriteLine();
            tw.Close();
            Environment.ExitCode = 1;
        }
                        #endif
        }
Esempio n. 2
0
        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();
            }
        }