예제 #1
0
        //Execution starts here
        static void Main(string[] StartupArgs)
        {
            //For testing, uncomment this line.
            //_DebugTest.Test();

            //This makes the program not do something stupid if you press Ctrl+C
            //Console.TreatControlCAsInput = true;
            Wrapper.Run         = true;
            Wrapper.InputTarget = Wrapper.Modes.Menu;
            Wrapper.WriteLine("Starting Up Wrapper!");

            //This line is just a convoluted way of setting the initial wrapper mode.
            //If I call the program from cmd with a mode argument, it'll set itself to that mode.
            //Otherwise it'll just default to the menu.
            Wrapper.Mode = Enum.IsDefined(typeof(Wrapper.Modes), ((StartupArgs.Length != 0) ? StartupArgs[0] : "-1")) ? (Wrapper.Modes)Enum.Parse(typeof(Wrapper.Modes), StartupArgs[0]) : Wrapper.Modes.Menu;

            while (Wrapper.Run == true) //Set this to false if too much dumb crap happens
            {
                switch (Wrapper.Mode)
                {
                case Wrapper.Modes.Menu:     //Wrapper Menu
                    Wrapper.Menu();
                    break;

                case Wrapper.Modes.MinecraftServer:     //Run MC Server
                    MinecraftServer.Run();
                    break;

                case Wrapper.Modes.FactorioServer:
                    FactorioServer.Run();
                    break;

                case Wrapper.Modes.FMCBridge:
                    FMCBridge.Run();
                    break;

                case Wrapper.Modes.UnturnedServer:
                    UnturnedServer.Run();
                    break;

                //case Wrapper.Modes.SRB2KServer:
                //    SRB2KServer.Run();
                //    break;
                default:
                    Wrapper.ErrorWriteLine("Invalid mode!");
                    break;
                }
            }
            Environment.Exit(0);
        }
예제 #2
0
 public static void ProcessInput(string InputText)
 {
     //Send it to the wrapper if it's a wrapper command
     if (InputText.StartsWith("wrapper"))
     {
         Wrapper.Command(InputText.Remove(0, 8));
     }
     else if (InputText == "/quit")
     {
         FMCBridge.Running = false;
         FMCBridge.StopRoutine();
     }
     //Send it to the Factorio server
     else
     {
         //FactorioServer.Input.WriteLine(InputText);
     }
 }
예제 #3
0
        public static void Run()
        {
            FactorioServer.Run(true);
            MinecraftServer.Run(true);

            Wrapper.WriteLine("Preparing FMCBridge...");

            string  SettingsFileName = "Settings.ini";
            string  SettingsFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SettingsFileName);
            IniFile s = new IniFile(SettingsFileName);

            RootPath = s.Read("ServerFolder", "Windows") + '\\';

            /*
             *                  Load in the item mappings file.
             */
            DualDictionary <String, String> itemMappings    = new DualDictionary <String, String>();
            Dictionary <String, double>     minecraftRatios = new Dictionary <String, double>();
            Dictionary <String, double>     factorioRatios  = new Dictionary <String, double>();

            //Open up the file stream for the item mappings
            string       itemMappingsPath = Path.Combine(RootPath, s.Read("MappingsFile", "FMCBridge"));
            FileStream   fileStream       = new FileStream(itemMappingsPath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read);
            StreamReader streamReader     = new StreamReader(fileStream, Encoding.Default);

            //This loops needs to do a couple of things.
            //The first is it needs to read in the mappings into the DualDictionary for better translation of names.
            //The second it needs to bind the item ratios to their respective lists.
            while (!streamReader.EndOfStream)
            {
                //Item Name Mappings first
                String readString = streamReader.ReadLine();
                if (readString.Contains("#") || readString.Equals("") || readString.Equals("\n"))
                {
                    continue;
                }
                String[] split = readString.Split('=');
                itemMappings.Add(split[0], split[1]);
                //Split the string again to get the ratios
                if (split.Length > 2)
                {
                    String[] ratios = split[2].Split(':');
                    minecraftRatios.Add(split[0], Double.Parse(ratios[0]));
                    factorioRatios.Add(split[1], Double.Parse(ratios[1]));
                }
            }
            streamReader.Close();
            fileStream.Close();

            RCON rcon2 = new RCON(IPAddress.Parse("127.0.0.1"), (ushort)25575, "test_password");

            FMCBridge.Running = true;
            Wrapper.Command("InputMode 3");
            Wrapper.WriteLine("Use \"wrapper InputMode 0\" to access Wrapper mode.");

            /*=======================================
            *  This loop monitors for user input in the console
            *  and sends it to the appropriate process
            *  =======================================*/
            string ConsoleInput = "";

            System.Threading.Tasks.Task.Run
                (async() =>
            {
                do
                {
                    if (Console.IsInputRedirected == false)
                    {
                        //BridgeInput = await Console.In.ReadLineAsync();
                        ConsoleInput = await Console.In.ReadLineAsync();
                        //BridgeInput = Console.ReadLine();
                    }
                } while (FMCBridge.Running == true);
            }
                );
            List <ItemPair> factorioItems;
            List <ItemPair> minecraftItems;

            do
            {
                try {
                    //If the user wasn't a squit
                    if (string.IsNullOrWhiteSpace(ConsoleInput) == false)
                    {
                        switch (Wrapper.InputTarget)
                        {
                        //Default to wrapper
                        case Wrapper.Modes.Menu:
                            Wrapper.Command(ConsoleInput);
                            break;

                        case Wrapper.Modes.MinecraftServer:
                            if (MinecraftServer.Running)
                            {
                                MinecraftServer.ProcessInput(ConsoleInput);
                            }
                            break;

                        case Wrapper.Modes.FactorioServer:
                            if (FactorioServer.Running)
                            {
                                FactorioServer.ProcessInput(ConsoleInput);
                            }
                            break;

                        case Wrapper.Modes.FMCBridge:
                            FMCBridge.ProcessInput(ConsoleInput);
                            break;

                        default:
                            Wrapper.InputTarget = Wrapper.Modes.Menu;
                            throw new TrashMonkeyException("Invalid input mode! Defaulting to wrapper mode.");
                        }
                    }
                    factorioItems  = parseFactorio(itemMappings, factorioRatios);
                    minecraftItems = parseVanillaMinecraft(itemMappings, minecraftRatios, rcon2).Result;
                    sendToFactorioExperimentalIO(minecraftItems);
                    sendToVanillaExperimentalIO(factorioItems);
                }
                catch (TrashMonkeyException e) { //Handled errors
                    Wrapper.ErrorWriteLine(e.Message);
                }
                catch (Exception e) {            //Something actually broke errors
                    Util.PrintErrorInfo(e);
                }
                ConsoleInput = "";
            } while (FMCBridge.Running == true);
            //Exiting this loop should return to the menu
        }