예제 #1
0
 public DMPGame(Settings dmpSettings, UniverseSyncCache universeSyncCache, ModWorker modWorker, ConnectionWindow connectionWindow, DMPModInterface dmpModInterface, ToolbarSupport toolbarSupport, OptionsWindow optionsWindow)
 {
     this.dmpSettings          = dmpSettings;
     this.universeSyncCache    = universeSyncCache;
     this.modWorker            = modWorker;
     this.connectionWindow     = connectionWindow;
     this.dmpModInterface      = dmpModInterface;
     this.configNodeSerializer = new ConfigNodeSerializer();
     this.posistionStatistics  = new PosistionStatistics();
     this.networkWorker        = new NetworkWorker(this, dmpSettings, connectionWindow, modWorker, configNodeSerializer);
     this.adminSystem          = new AdminSystem(dmpSettings);
     this.flagSyncer           = new FlagSyncer(this, dmpSettings, networkWorker);
     this.lockSystem           = new LockSystem(dmpSettings, networkWorker);
     this.partKiller           = new PartKiller(lockSystem);
     this.dynamicTickWorker    = new DynamicTickWorker(this, networkWorker);
     this.kerbalReassigner     = new KerbalReassigner();
     this.vesselPackedUpdater  = new VesselInterFrameUpdater(lockSystem, posistionStatistics, dmpSettings);
     this.vesselWorker         = new VesselWorker(this, dmpSettings, modWorker, lockSystem, networkWorker, configNodeSerializer, dynamicTickWorker, kerbalReassigner, partKiller, posistionStatistics, vesselPackedUpdater);
     this.scenarioWorker       = new ScenarioWorker(this, vesselWorker, configNodeSerializer, networkWorker);
     this.playerStatusWorker   = new PlayerStatusWorker(this, dmpSettings, vesselWorker, lockSystem, networkWorker);
     this.timeSyncer           = new TimeSyncer(this, networkWorker, vesselWorker);
     this.warpWorker           = new WarpWorker(this, dmpSettings, timeSyncer, networkWorker, playerStatusWorker);
     this.chatWorker           = new ChatWorker(this, dmpSettings, networkWorker, adminSystem, playerStatusWorker);
     this.screenshotWorker     = new ScreenshotWorker(this, dmpSettings, chatWorker, networkWorker, playerStatusWorker);
     this.vesselRecorder       = new VesselRecorder(this, warpWorker, vesselWorker, networkWorker, dmpSettings);
     this.debugWindow          = new DebugWindow(this, dmpSettings, timeSyncer, networkWorker, vesselWorker, dynamicTickWorker, warpWorker, vesselRecorder, posistionStatistics);
     this.craftLibraryWorker   = new CraftLibraryWorker(this, dmpSettings, networkWorker);
     this.hackyInAtmoLoader    = new HackyInAtmoLoader(this, lockSystem, vesselWorker);
     this.asteroidWorker       = new AsteroidWorker(this, lockSystem, networkWorker, vesselWorker);
     this.playerColorWorker    = new PlayerColorWorker(dmpSettings, lockSystem, networkWorker);
     this.playerStatusWindow   = new PlayerStatusWindow(this, dmpSettings, warpWorker, chatWorker, craftLibraryWorker, debugWindow, screenshotWorker, timeSyncer, playerStatusWorker, optionsWindow, playerColorWorker);
     this.playerColorWorker.SetDependencies(playerStatusWindow);
     this.vesselWorker.SetDependencies(hackyInAtmoLoader, timeSyncer, asteroidWorker, chatWorker, playerStatusWorker);
     this.networkWorker.SetDependencies(timeSyncer, warpWorker, chatWorker, playerColorWorker, flagSyncer, partKiller, kerbalReassigner, asteroidWorker, vesselWorker, hackyInAtmoLoader, playerStatusWorker, scenarioWorker, dynamicTickWorker, craftLibraryWorker, screenshotWorker, toolbarSupport, adminSystem, lockSystem, dmpModInterface, universeSyncCache, vesselRecorder);
     //this.vesselPackedUpdater.SetVesselRecoder(this.vesselRecorder);
     optionsWindow.SetDependencies(this, networkWorker, playerColorWorker);
     this.dmpModInterface.DMPRun(networkWorker);
     this.stopEvent.Add(this.chatWorker.Stop);
     this.stopEvent.Add(this.craftLibraryWorker.Stop);
     this.stopEvent.Add(this.debugWindow.Stop);
     this.stopEvent.Add(this.dynamicTickWorker.Stop);
     this.stopEvent.Add(this.flagSyncer.Stop);
     this.stopEvent.Add(this.hackyInAtmoLoader.Stop);
     this.stopEvent.Add(this.kerbalReassigner.Stop);
     this.stopEvent.Add(this.playerColorWorker.Stop);
     this.stopEvent.Add(this.playerStatusWindow.Stop);
     this.stopEvent.Add(this.playerStatusWorker.Stop);
     this.stopEvent.Add(this.partKiller.Stop);
     this.stopEvent.Add(this.scenarioWorker.Stop);
     this.stopEvent.Add(this.screenshotWorker.Stop);
     this.stopEvent.Add(this.timeSyncer.Stop);
     this.stopEvent.Add(toolbarSupport.Stop);
     this.stopEvent.Add(optionsWindow.Stop);
     this.stopEvent.Add(this.vesselWorker.Stop);
     this.stopEvent.Add(this.warpWorker.Stop);
     this.stopEvent.Add(this.asteroidWorker.Stop);
     this.stopEvent.Add(this.vesselRecorder.Stop);
 }
예제 #2
0
 public static void Reset()
 {
     lock (Client.eventLock)
     {
         if (singleton != null)
         {
             singleton.workerEnabled = false;
         }
         singleton = new PlayerColorWorker();
     }
 }
예제 #3
0
 public PlayerStatusWindow(DMPGame dmpGame, Settings dmpSettings, WarpWorker warpWorker, ChatWorker chatWorker, CraftLibraryWorker craftLibraryWorker, DebugWindow debugWindow, ScreenshotWorker screenshotWorker, TimeSyncer timeSyncer, PlayerStatusWorker playerStatusWorker, OptionsWindow optionsWindow, PlayerColorWorker playerColorWorker)
 {
     this.dmpGame            = dmpGame;
     this.dmpSettings        = dmpSettings;
     this.warpWorker         = warpWorker;
     this.chatWorker         = chatWorker;
     this.craftLibraryWorker = craftLibraryWorker;
     this.debugWindow        = debugWindow;
     this.screenshotWorker   = screenshotWorker;
     this.timeSyncer         = timeSyncer;
     this.playerStatusWorker = playerStatusWorker;
     this.optionsWindow      = optionsWindow;
     this.playerColorWorker  = playerColorWorker;
     dmpGame.updateEvent.Add(Update);
     dmpGame.drawEvent.Add(Draw);
 }
예제 #4
0
 public PlayerStatusWindow(DMPGame dmpGame, Settings dmpSettings, WarpWorker warpWorker, ChatWorker chatWorker, CraftLibraryWorker craftLibraryWorker, ScreenshotWorker screenshotWorker, TimeSyncer timeSyncer, PlayerStatusWorker playerStatusWorker, OptionsWindow optionsWindow, PlayerColorWorker playerColorWorker, GroupsWindow groupsWindow, PermissionsWindow permissionsWindow)
 {
     this.dmpGame            = dmpGame;
     this.dmpSettings        = dmpSettings;
     this.warpWorker         = warpWorker;
     this.chatWorker         = chatWorker;
     this.craftLibraryWorker = craftLibraryWorker;
     this.screenshotWorker   = screenshotWorker;
     this.timeSyncer         = timeSyncer;
     this.playerStatusWorker = playerStatusWorker;
     this.optionsWindow      = optionsWindow;
     this.playerColorWorker  = playerColorWorker;
     this.groupsWindow       = groupsWindow;
     this.permissionsWindow  = permissionsWindow;
     updateAction            = new NamedAction(Update);
     drawAction = new NamedAction(Draw);
     this.dmpGame.updateEvent.Add(updateAction);
     this.dmpGame.drawEvent.Add(drawAction);
 }
 public static void Reset()
 {
     lock (Client.eventLock)
     {
         if (singleton != null)
         {
             singleton.workerEnabled = false;
         }
         singleton = new PlayerColorWorker();
     }
 }
예제 #6
0
        public void LoadSettings()
        {
            try
            {
                if (File.Exists(backupOldSettingsFile) || File.Exists(oldSettingsFile))
                {
                    DarkLog.Debug("[Settings]: Loading old settings");
                    LoadOldSettings();
                    SaveSettings();
                    File.Delete(backupOldSettingsFile);
                    File.Delete(oldSettingsFile);
                }

                bool       saveAfterLoad = false;
                ConfigNode mainNode      = new ConfigNode();

                if (File.Exists(backupSettingsFile) && !File.Exists(settingsFile))
                {
                    DarkLog.Debug("[Settings]: Restoring backup file");
                    File.Copy(backupSettingsFile, settingsFile);
                }

                if (!File.Exists(settingsFile))
                {
                    mainNode   = GetDefaultSettings();
                    playerName = DEFAULT_PLAYER_NAME;
                    mainNode.Save(settingsFile);
                }

                if (!File.Exists(backupSettingsFile))
                {
                    DarkLog.Debug("[Settings]: Backing up settings");
                    File.Copy(settingsFile, backupSettingsFile);
                }

                mainNode = ConfigNode.Load(settingsFile);

                ConfigNode settingsNode = mainNode.GetNode("SETTINGS");
                ConfigNode playerNode   = settingsNode.GetNode("PLAYER");
                ConfigNode bindingsNode = settingsNode.GetNode("KEYBINDINGS");

                playerName = playerNode.GetValue("name");

                if (!int.TryParse(settingsNode.GetValue("cacheSize"), out cacheSize))
                {
                    DarkLog.Debug("[Settings]: Adding cache size to settings file");
                    cacheSize     = DEFAULT_CACHE_SIZE;
                    saveAfterLoad = true;
                }

                if (!int.TryParse(settingsNode.GetValue("disclaimer"), out disclaimerAccepted))
                {
                    DarkLog.Debug("[Settings]: Adding disclaimer to settings file");
                    disclaimerAccepted = 0;
                    saveAfterLoad      = true;
                }

                if (!int.TryParse(settingsNode.GetValue("serverlist-mode"), out serverlistMode))
                {
                    DarkLog.Debug("[Settings]: Adding serverlist-mode to settings file");
                    serverlistMode = 0;
                    saveAfterLoad  = true;
                }

                if (!playerNode.TryGetValue("color", ref playerColor))
                {
                    DarkLog.Debug("[Settings]: Adding color to settings file");
                    playerColor   = PlayerColorWorker.GenerateRandomColor();
                    saveAfterLoad = true;
                }

                int chatKey = (int)KeyCode.BackQuote, screenshotKey = (int)KeyCode.F8;
                if (!int.TryParse(bindingsNode.GetValue("chat"), out chatKey))
                {
                    DarkLog.Debug("[Settings]: Adding chat key to settings file");
                    this.chatKey  = KeyCode.BackQuote;
                    saveAfterLoad = true;
                }
                else
                {
                    this.chatKey = (KeyCode)chatKey;
                }

                if (!int.TryParse(bindingsNode.GetValue("screenshot"), out screenshotKey))
                {
                    DarkLog.Debug("[Settings]: Adding screenshot key to settings file");
                    this.screenshotKey = KeyCode.F8;
                    saveAfterLoad      = true;
                }
                else
                {
                    this.screenshotKey = (KeyCode)screenshotKey;
                }

                if (!playerNode.TryGetValue("flag", ref selectedFlag))
                {
                    DarkLog.Debug("[Settings]: Adding selected flag to settings file");
                    selectedFlag  = "Squad/Flags/default";
                    saveAfterLoad = true;
                }

                if (!settingsNode.TryGetValue("compression", ref compressionEnabled))
                {
                    DarkLog.Debug("[Settings]: Adding compression flag to settings file");
                    compressionEnabled = true;
                    saveAfterLoad      = true;
                }

                if (!settingsNode.TryGetValue("revert", ref revertEnabled))
                {
                    DarkLog.Debug("[Settings]: Adding revert flag to settings file");
                    revertEnabled = true;
                    saveAfterLoad = true;
                }

                string interpolatorString = null;
                int    interpolatorInt    = 0;
                try
                {
                    //Make sure we haven't saved to the old int type
                    if (settingsNode.TryGetValue("interpolation", ref interpolatorString) && !int.TryParse(interpolatorString, out interpolatorInt))
                    {
                        interpolatorType = (InterpolatorType)Enum.Parse(typeof(InterpolatorType), interpolatorString);
                    }
                    else
                    {
                        DarkLog.Debug("[Settings]: Adding interpolation flag to settings file");
                        interpolatorType = InterpolatorType.INTERPOLATE1S;
                        saveAfterLoad    = true;
                    }
                }
                catch
                {
                    interpolatorType = InterpolatorType.INTERPOLATE1S;
                    saveAfterLoad    = true;
                }

                int toolbarType;
                if (!int.TryParse(settingsNode.GetValue("toolbar"), out toolbarType))
                {
                    DarkLog.Debug("[Settings]: Adding toolbar flag to settings file");
                    this.toolbarType = DMPToolbarType.BLIZZY_IF_INSTALLED;
                    saveAfterLoad    = true;
                }
                else
                {
                    this.toolbarType = (DMPToolbarType)toolbarType;
                }

                ConfigNode serversNode = settingsNode.GetNode("SERVERS");
                servers.Clear();
                if (serversNode.HasNode("SERVER"))
                {
                    foreach (ConfigNode serverNode in serversNode.GetNodes("SERVER"))
                    {
                        ServerEntry newServer = new ServerEntry();
                        newServer.name    = serverNode.GetValue("name");
                        newServer.address = serverNode.GetValue("address");
                        serverNode.TryGetValue("port", ref newServer.port);
                        servers.Add(newServer);
                    }
                }

                if (saveAfterLoad)
                {
                    SaveSettings();
                }
            }
            catch (Exception e)
            {
                DarkLog.Debug("Error while loading settings:");
                DarkLog.Debug(e.ToString());
            }

            //Read player token
            try
            {
                //Restore backup if needed
                if (File.Exists(backupPublicKeyFile) && File.Exists(backupPrivateKeyFile) && (!File.Exists(publicKeyFile) || !File.Exists(privateKeyFile)))
                {
                    DarkLog.Debug("[Settings]: Restoring backed up keypair!");
                    File.Copy(backupPublicKeyFile, publicKeyFile, true);
                    File.Copy(backupPrivateKeyFile, privateKeyFile, true);
                }
                //Load or create token file
                if (File.Exists(privateKeyFile) && File.Exists(publicKeyFile))
                {
                    playerPublicKey  = File.ReadAllText(publicKeyFile);
                    playerPrivateKey = File.ReadAllText(privateKeyFile);
                }
                else
                {
                    DarkLog.Debug("[Settings]: Creating new keypair!");
                    GenerateNewKeypair();
                }
                //Save backup token file if needed
                if (!File.Exists(backupPublicKeyFile) || !File.Exists(backupPrivateKeyFile))
                {
                    DarkLog.Debug("[Settings]: Backing up keypair");
                    File.Copy(publicKeyFile, backupPublicKeyFile, true);
                    File.Copy(privateKeyFile, backupPrivateKeyFile, true);
                }
            }
            catch
            {
                DarkLog.Debug("Error processing keypair, creating new keypair");
                GenerateNewKeypair();
                DarkLog.Debug("[Settings]: Backing up keypair");
                File.Copy(publicKeyFile, backupPublicKeyFile, true);
                File.Copy(privateKeyFile, backupPrivateKeyFile, true);
            }
        }
예제 #7
0
        private void DrawContent(int windowID)
        {
            if (!loadEventHandled)
            {
                loadEventHandled = true;
                tempColor        = Settings.fetch.playerColor;
                newCacheSize     = Settings.fetch.cacheSize.ToString();
            }
            //Player color
            GUILayout.BeginVertical();
            GUI.DragWindow(moveRect);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Player name color: ");
            GUILayout.Label(Settings.fetch.playerName, tempColorLabelStyle);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("R: ");
            tempColor.r = GUILayout.HorizontalScrollbar(tempColor.r, 0, 0, 1);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("G: ");
            tempColor.g = GUILayout.HorizontalScrollbar(tempColor.g, 0, 0, 1);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("B: ");
            tempColor.b = GUILayout.HorizontalScrollbar(tempColor.b, 0, 0, 1);
            GUILayout.EndHorizontal();
            tempColorLabelStyle.active.textColor = tempColor;
            tempColorLabelStyle.normal.textColor = tempColor;
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Random", buttonStyle))
            {
                tempColor = PlayerColorWorker.GenerateRandomColor();
            }
            if (GUILayout.Button("Set", buttonStyle))
            {
                PlayerStatusWindow.fetch.colorEventHandled = false;
                Settings.fetch.playerColor = tempColor;
                Settings.fetch.SaveSettings();
                if (NetworkWorker.fetch.state == DarkMultiPlayerCommon.ClientState.RUNNING)
                {
                    PlayerColorWorker.fetch.SendPlayerColorToServer();
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(10);
            //Cache
            GUILayout.Label("Cache size");
            GUILayout.Label("Current size: " + Math.Round((UniverseSyncCache.fetch.currentCacheSize / (float)(1024 * 1024)), 3) + "MB.");
            GUILayout.Label("Max size: " + Settings.fetch.cacheSize + "MB.");
            newCacheSize = GUILayout.TextArea(newCacheSize);
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Set", buttonStyle))
            {
                int tempCacheSize;
                if (Int32.TryParse(newCacheSize, out tempCacheSize))
                {
                    if (tempCacheSize < 1)
                    {
                        tempCacheSize = 1;
                        newCacheSize  = tempCacheSize.ToString();
                    }
                    if (tempCacheSize > 1000)
                    {
                        tempCacheSize = 1000;
                        newCacheSize  = tempCacheSize.ToString();
                    }
                    Settings.fetch.cacheSize = tempCacheSize;
                    Settings.fetch.SaveSettings();
                }
                else
                {
                    newCacheSize = Settings.fetch.cacheSize.ToString();
                }
            }
            if (GUILayout.Button("Expire cache"))
            {
                UniverseSyncCache.fetch.ExpireCache();
            }
            if (GUILayout.Button("Delete cache"))
            {
                UniverseSyncCache.fetch.DeleteCache();
            }
            GUILayout.EndHorizontal();
            //Key bindings
            GUILayout.Space(10);
            string chatDescription = "Set chat key (current: " + Settings.fetch.chatKey + ")";

            if (settingChat)
            {
                chatDescription = "Setting chat key (click to cancel)...";
                if (Event.current.isKey)
                {
                    if (Event.current.keyCode != KeyCode.Escape)
                    {
                        Settings.fetch.chatKey = Event.current.keyCode;
                        Settings.fetch.SaveSettings();
                        settingChat = false;
                    }
                    else
                    {
                        settingChat = false;
                    }
                }
            }
            if (GUILayout.Button(chatDescription))
            {
                settingChat = !settingChat;
            }
            string screenshotDescription = "Set screenshot key (current: " + Settings.fetch.screenshotKey.ToString() + ")";

            if (settingScreenshot)
            {
                screenshotDescription = "Setting screenshot key (click to cancel)...";
                if (Event.current.isKey)
                {
                    if (Event.current.keyCode != KeyCode.Escape)
                    {
                        Settings.fetch.screenshotKey = Event.current.keyCode;
                        Settings.fetch.SaveSettings();
                        settingScreenshot = false;
                    }
                    else
                    {
                        settingScreenshot = false;
                    }
                }
            }
            if (GUILayout.Button(screenshotDescription))
            {
                settingScreenshot = !settingScreenshot;
            }
            GUILayout.Space(10);
            GUILayout.Label("Generate a server DMPModControl:");
            if (GUILayout.Button("Generate blacklist DMPModControl.txt"))
            {
                ModWorker.fetch.GenerateModControlFile(false);
            }
            if (GUILayout.Button("Generate whitelist DMPModControl.txt"))
            {
                ModWorker.fetch.GenerateModControlFile(true);
            }
            UniverseConverterWindow.fetch.display = GUILayout.Toggle(UniverseConverterWindow.fetch.display, "Generate Universe from saved game", buttonStyle);
            if (GUILayout.Button("Reset disclaimer"))
            {
                Settings.fetch.disclaimerAccepted = 0;
                Settings.fetch.SaveSettings();
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Close", buttonStyle))
            {
                display = false;
            }
            GUILayout.EndVertical();
        }
예제 #8
0
 public void SetDependencies(DMPGame dmpGame, NetworkWorker networkWorker, PlayerColorWorker playerColorWorker)
 {
     this.networkWorker     = networkWorker;
     this.playerColorWorker = playerColorWorker;
     this.dmpGame           = dmpGame;
 }
예제 #9
0
 public void Stop()
 {
     networkWorker     = null;
     playerColorWorker = null;
     dmpGame           = null;
 }
예제 #10
0
        private void DrawContent(int windowID)
        {
            if (GUI.Button(new Rect(windowRect.width - 24, 0, 19, 19), "X"))
            {
                display = false;
            }
            //Player color
            GUI.DragWindow(moveRect);
            GUI.Box(new Rect(2, 20, windowRect.width - 4, 20), string.Empty, sectionHeaderStyle);
            selectedTab = (OptionsTab)GUILayout.Toolbar((int)selectedTab, GetOptionsTabStrings(), toolbarBtnStyle);

            int windowY = 17;

            windowY += 20 + 2;
            int groupY = 0;

            if (selectedTab == OptionsTab.PLAYER)
            {
                GUI.BeginGroup(new Rect(10, windowY, windowRect.width - 20, 106));
                groupY = 0;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Name:", descriptorStyle);
                plrNameStyle.normal.textColor = dmpSettings.playerColor;
                if (networkWorker != null && networkWorker.state == DarkMultiPlayerCommon.ClientState.RUNNING)
                {
                    GUI.Label(new Rect(descWidth + sepWidth, groupY,
                                       windowRect.width - (descWidth + sepWidth) - 20, 20),
                              dmpSettings.playerName, plrNameStyle);
                }
                else
                {
                    string newName = GUI.TextField(new Rect(
                                                       descWidth + sepWidth,
                                                       0,
                                                       windowRect.width - (descWidth + sepWidth) - 20,
                                                       20), dmpSettings.playerName, plrNameStyle);

                    if (!newName.Equals(dmpSettings.playerName))
                    {
                        dmpSettings.playerName = newName;
                        dmpSettings.SaveSettings();
                    }
                }
                groupY += 20 + 4;


                Color playerColor = dmpSettings.playerColor;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Red:", descriptorStyle);
                playerColor.r = GUI.HorizontalSlider(new Rect(
                                                         descWidth + sepWidth,
                                                         groupY + 5,
                                                         windowRect.width - (descWidth + sepWidth) - 20,
                                                         12
                                                         ), dmpSettings.playerColor.r, 0, 1);
                groupY += 20;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Green:", descriptorStyle);
                playerColor.g = GUI.HorizontalSlider(new Rect(
                                                         descWidth + sepWidth,
                                                         groupY + 5,
                                                         windowRect.width - (descWidth + sepWidth) - 20,
                                                         12
                                                         ), dmpSettings.playerColor.g, 0, 1);
                groupY += 20;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Blue:", descriptorStyle);
                playerColor.b = GUI.HorizontalSlider(new Rect(
                                                         descWidth + sepWidth,
                                                         groupY + 5,
                                                         windowRect.width - (descWidth + sepWidth) - 20,
                                                         12
                                                         ), dmpSettings.playerColor.b, 0, 1);
                groupY += 22;

                if (GUI.Button(new Rect(0, groupY, windowRect.width - 20, 20), "Random Color", buttonStyle))
                {
                    playerColor = PlayerColorWorker.GenerateRandomColor();
                }

                if (!playerColor.Equals(dmpSettings.playerColor))
                {
                    dmpSettings.playerColor = playerColor;
                    dmpSettings.SaveSettings();

                    if (networkWorker != null && playerColorWorker != null && networkWorker.state == DarkMultiPlayerCommon.ClientState.RUNNING)
                    {
                        playerColorWorker.SendPlayerColorToServer();
                    }
                }

                GUI.EndGroup();
                // windowY += 106 + 5;
            }
            if (selectedTab == OptionsTab.CACHE)
            {
                GUI.BeginGroup(new Rect(10, windowY, windowRect.width - 20, 84));
                groupY = 0;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Current:", descriptorStyle);
                GUI.Label(
                    new Rect(descWidth + sepWidth, groupY, windowRect.width - (descWidth + sepWidth) - 102, 20),
                    Mathf.Round(universeSyncCache.currentCacheSize / 1024).ToString() + " KB");

                groupY += 20;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Maximum:", descriptorStyle);
                string newSizeStr = GUI.TextField(new Rect(descWidth + sepWidth, groupY, windowRect.width - (descWidth + sepWidth) - 152, 20), (dmpSettings.cacheSize / 1024).ToString(), textFieldStyle);
                GUI.Label(new Rect(descWidth + sepWidth + 80, groupY, 100, 20), "kilobytes (KB)");
                int newSize;
                if (string.IsNullOrEmpty(newSizeStr))
                {
                    newSize = 1;
                }
                else
                {
                    if (int.TryParse(newSizeStr, out newSize))
                    {
                        if (newSize < 1)
                        {
                            newSize = 1;
                        }
                        else if (newSize > 1000000)
                        {
                            newSize = 1000000;
                        }
                    }
                    else
                    {
                        newSize = 100000;
                    }
                }

                if (newSize != dmpSettings.cacheSize)
                {
                    dmpSettings.cacheSize = newSize * 1024;
                    dmpSettings.SaveSettings();
                }
                groupY += 22;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Manage:", descriptorStyle);
                if (GUI.Button(new Rect(descWidth + sepWidth, groupY, windowRect.width - (descWidth + sepWidth) - 20, 20), "Expire"))
                {
                    universeSyncCache.ExpireCache();
                }

                groupY += 22;

                if (GUI.Button(new Rect(descWidth + sepWidth, groupY, windowRect.width - (descWidth + sepWidth) - 20, 20), "Delete"))
                {
                    universeSyncCache.DeleteCache();
                }
                GUI.EndGroup();
            }
            //Key bindings
            if (selectedTab == OptionsTab.CONTROLS)
            {
                GUI.BeginGroup(new Rect(10, windowY, windowRect.width - 20, 92));
                groupY = 0;

                GUI.Label(new Rect(0, groupY, windowRect.width - 20, 48),
                          "Click a button below to select the action you want to change. Then press a key to set the binding. To cancel, click the button again or press Escape.",
                          noteStyle);
                groupY += 48;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Chat:", descriptorStyle);
                string chatKey = dmpSettings.chatKey.ToString();
                if (settingChat)
                {
                    chatKey = settingKeyMessage;
                    if (Event.current.isKey)
                    {
                        if (Event.current.keyCode != KeyCode.Escape)
                        {
                            dmpSettings.chatKey = Event.current.keyCode;
                            dmpSettings.SaveSettings();
                        }
                        settingChat = false;
                    }
                }

                if (GUI.Button(new Rect(descWidth + sepWidth, groupY, windowRect.width - (descWidth + sepWidth) - 20, 20), chatKey, buttonStyle))
                {
                    settingScreenshot = false;
                    settingChat       = !settingChat;
                }
                groupY += 22;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Screenshot:", descriptorStyle);
                string screenshotKey = dmpSettings.screenshotKey.ToString();
                if (settingScreenshot)
                {
                    screenshotKey = settingKeyMessage;
                    if (Event.current.isKey)
                    {
                        if (Event.current.keyCode != KeyCode.Escape)
                        {
                            dmpSettings.screenshotKey = Event.current.keyCode;
                            dmpSettings.SaveSettings();
                        }
                        settingScreenshot = false;
                    }
                }

                if (GUI.Button(new Rect(descWidth + sepWidth, groupY, windowRect.width - (descWidth + sepWidth) - 20, 20), screenshotKey, buttonStyle))
                {
                    settingChat       = false;
                    settingScreenshot = !settingScreenshot;
                }
                GUI.EndGroup();
            }
            if (selectedTab == OptionsTab.ADVANCED)
            {
                GUI.Box(new Rect(2, windowY, windowRect.width - 4, 20), "Mod Control", sectionHeaderStyle);
                windowY += 22;

                GUI.BeginGroup(new Rect(10, windowY, windowRect.width - 20, 42));
                groupY = 0;

                GUI.Label(new Rect(0, groupY, descWidth, 20), "Generate:", descriptorStyle);
                if (GUI.Button(new Rect(descWidth + sepWidth, groupY, windowRect.width - (descWidth + sepWidth) - 20, 20), "Whitelist", buttonStyle))
                {
                    modWorker.GenerateModControlFile(true);
                }

                groupY += 22;

                if (GUI.Button(new Rect(descWidth + sepWidth, groupY, windowRect.width - (descWidth + sepWidth) - 20, 20), "Blacklist", buttonStyle))
                {
                    modWorker.GenerateModControlFile(false);
                }

                GUI.EndGroup();
                windowY += 47;

                GUI.Box(new Rect(2, windowY, windowRect.width - 4, 20), "Other", sectionHeaderStyle);
                windowY += 22;

                GUI.BeginGroup(new Rect(10, windowY, windowRect.width - 20, 148));
                groupY = 0;

                bool toggleCompression = GUI.Toggle(new Rect(0, groupY, windowRect.width - 20, 20), dmpSettings.compressionEnabled, "Compress Network Traffic");
                if (toggleCompression != dmpSettings.compressionEnabled)
                {
                    dmpSettings.compressionEnabled = toggleCompression;
                    dmpSettings.SaveSettings();
                }
                groupY += 22;

                bool toggleRevert = GUI.Toggle(new Rect(0, groupY, windowRect.width - 20, 20), dmpSettings.revertEnabled, "Enable Revert");
                if (toggleRevert != dmpSettings.revertEnabled)
                {
                    dmpSettings.revertEnabled = toggleRevert;
                    dmpSettings.SaveSettings();
                }
                groupY += 22;

                universeConverterWindow.display = GUI.Toggle(new Rect(0, groupY, windowRect.width - 20, 20), universeConverterWindow.display, "Generate DMP universe from saved game...", buttonStyle);
                groupY += 22;

                if (GUI.Button(new Rect(0, groupY, windowRect.width - 20, 20), "Reset Disclaimer", buttonStyle))
                {
                    dmpSettings.disclaimerAccepted = 0;
                    dmpSettings.SaveSettings();
                }
                groupY += 22;

                if (GUI.Button(new Rect(0, groupY, windowRect.width - 20, 20), toolbarMode, buttonStyle))
                {
                    int newSetting = (int)dmpSettings.toolbarType + 1;
                    //Overflow to 0
                    if (!Enum.IsDefined(typeof(DMPToolbarType), newSetting))
                    {
                        newSetting = 0;
                    }
                    dmpSettings.toolbarType = (DMPToolbarType)newSetting;
                    dmpSettings.SaveSettings();
                    UpdateToolbarString();
                    toolbarSupport.DetectSettingsChange();
                }
                groupY += 22;

#if DEBUG
                if (GUI.Button(new Rect(0, groupY, windowRect.width - 20, 20), "Check missing parts", buttonStyle))
                {
                    modWorker.CheckCommonStockParts();
                }
#endif

                GUI.EndGroup();
            }
        }
예제 #11
0
        public void LoadSettings()
        {
            //Read XML settings
            try
            {
                bool        saveXMLAfterLoad = false;
                XmlDocument xmlDoc           = new XmlDocument();
                if (File.Exists(backupSettingsFile) && !File.Exists(settingsFile))
                {
                    DarkLog.Debug("Restoring player settings file!");
                    File.Copy(backupSettingsFile, settingsFile);
                }
                if (!File.Exists(settingsFile))
                {
                    xmlDoc.LoadXml(newXMLString());
                    playerName = DEFAULT_PLAYER_NAME;
                    xmlDoc.Save(settingsFile);
                }
                if (!File.Exists(backupSettingsFile))
                {
                    DarkLog.Debug("Backing up player token and settings file!");
                    File.Copy(settingsFile, backupSettingsFile);
                }
                xmlDoc.Load(settingsFile);
                playerName = xmlDoc.SelectSingleNode("/settings/global/@username").Value;
                try
                {
                    cacheSize = Int32.Parse(xmlDoc.SelectSingleNode("/settings/global/@cache-size").Value);
                }
                catch
                {
                    DarkLog.Debug("Adding cache size to settings file");
                    saveXMLAfterLoad = true;
                    cacheSize        = DEFAULT_CACHE_SIZE;
                }
                try
                {
                    disclaimerAccepted = Int32.Parse(xmlDoc.SelectSingleNode("/settings/global/@disclaimer").Value);
                }
                catch
                {
                    DarkLog.Debug("Adding disclaimer to settings file");
                    saveXMLAfterLoad = true;
                }
                try
                {
                    string   floatArrayString      = xmlDoc.SelectSingleNode("/settings/global/@player-color").Value;
                    string[] floatArrayStringSplit = floatArrayString.Split(',');
                    float    redColor   = float.Parse(floatArrayStringSplit[0].Trim());
                    float    greenColor = float.Parse(floatArrayStringSplit[1].Trim());
                    float    blueColor  = float.Parse(floatArrayStringSplit[2].Trim());
                    //Bounds checking - Gotta check up on those players :)
                    if (redColor < 0f)
                    {
                        redColor = 0f;
                    }
                    if (redColor > 1f)
                    {
                        redColor = 1f;
                    }
                    if (greenColor < 0f)
                    {
                        greenColor = 0f;
                    }
                    if (greenColor > 1f)
                    {
                        greenColor = 1f;
                    }
                    if (blueColor < 0f)
                    {
                        blueColor = 0f;
                    }
                    if (blueColor > 1f)
                    {
                        blueColor = 1f;
                    }
                    playerColor = new Color(redColor, greenColor, blueColor, 1f);
                }
                catch
                {
                    DarkLog.Debug("Adding player color to settings file");
                    saveXMLAfterLoad = true;
                    playerColor      = PlayerColorWorker.GenerateRandomColor();
                }
                try
                {
                    chatKey = (KeyCode)Int32.Parse(xmlDoc.SelectSingleNode("/settings/global/@chat-key").Value);
                }
                catch
                {
                    DarkLog.Debug("Adding chat key to settings file");
                    saveXMLAfterLoad = true;
                    chatKey          = KeyCode.BackQuote;
                }
                try
                {
                    screenshotKey = (KeyCode)Int32.Parse(xmlDoc.SelectSingleNode("/settings/global/@screenshot-key").Value);
                }
                catch
                {
                    DarkLog.Debug("Adding screenshot key to settings file");
                    saveXMLAfterLoad = true;
                    chatKey          = KeyCode.F8;
                }
                try
                {
                    selectedFlag = xmlDoc.SelectSingleNode("/settings/global/@selected-flag").Value;
                }
                catch
                {
                    DarkLog.Debug("Adding selected flag to settings file");
                    saveXMLAfterLoad = true;
                    selectedFlag     = "Squad/Flags/default";
                }
                try
                {
                    compressionEnabled = Boolean.Parse(xmlDoc.SelectSingleNode("/settings/global/@compression").Value);
                }
                catch
                {
                    DarkLog.Debug("Adding compression flag to settings file");
                    compressionEnabled = true;
                }
                try
                {
                    revertEnabled = Boolean.Parse(xmlDoc.SelectSingleNode("/settings/global/@revert").Value);
                }
                catch
                {
                    DarkLog.Debug("Adding revert flag to settings file");
                    revertEnabled = true;
                }
                try
                {
                    toolbarType = (DMPToolbarType)Int32.Parse(xmlDoc.SelectSingleNode("/settings/global/@toolbar").Value);
                }
                catch
                {
                    DarkLog.Debug("Adding toolbar flag to settings file");
                    toolbarType = DMPToolbarType.BLIZZY_IF_INSTALLED;
                }
                XmlNodeList serverNodeList = xmlDoc.GetElementsByTagName("server");
                servers = new List <ServerEntry>();
                foreach (XmlNode xmlNode in serverNodeList)
                {
                    ServerEntry newServer = new ServerEntry();
                    newServer.name    = xmlNode.Attributes["name"].Value;
                    newServer.address = xmlNode.Attributes["address"].Value;
                    Int32.TryParse(xmlNode.Attributes["port"].Value, out newServer.port);
                    servers.Add(newServer);
                }
                if (saveXMLAfterLoad)
                {
                    SaveSettings();
                }
            }
            catch (Exception e)
            {
                DarkLog.Debug("XML Exception: " + e);
            }

            //Read player token
            try
            {
                //Restore backup if needed
                if (File.Exists(backupPublicKeyFile) && File.Exists(backupPrivateKeyFile) && (!File.Exists(publicKeyFile) || !File.Exists(privateKeyFile)))
                {
                    DarkLog.Debug("Restoring backed up keypair!");
                    File.Copy(backupPublicKeyFile, publicKeyFile, true);
                    File.Copy(backupPrivateKeyFile, privateKeyFile, true);
                }
                //Load or create token file
                if (File.Exists(privateKeyFile) && File.Exists(publicKeyFile))
                {
                    playerPublicKey  = File.ReadAllText(publicKeyFile);
                    playerPrivateKey = File.ReadAllText(privateKeyFile);
                }
                else
                {
                    DarkLog.Debug("Creating new keypair!");
                    GenerateNewKeypair();
                }
                //Save backup token file if needed
                if (!File.Exists(backupPublicKeyFile) || !File.Exists(backupPrivateKeyFile))
                {
                    DarkLog.Debug("Backing up keypair");
                    File.Copy(publicKeyFile, backupPublicKeyFile, true);
                    File.Copy(privateKeyFile, backupPrivateKeyFile, true);
                }
            }
            catch
            {
                DarkLog.Debug("Error processing keypair, creating new keypair");
                GenerateNewKeypair();
                DarkLog.Debug("Backing up keypair");
                File.Copy(publicKeyFile, backupPublicKeyFile, true);
                File.Copy(privateKeyFile, backupPrivateKeyFile, true);
            }
        }
예제 #12
0
        public void LoadSettings()
        {
            //Read XML settings
            try
            {
                bool        saveXMLAfterLoad = false;
                XmlDocument xmlDoc           = new XmlDocument();
                if (File.Exists(backupSettingsFile) && !File.Exists(settingsFile))
                {
                    DarkLog.Debug("Restoring player settings file!");
                    File.Copy(backupSettingsFile, settingsFile);
                }
                if (!File.Exists(settingsFile))
                {
                    xmlDoc.LoadXml(newXMLString());
                    playerName = DEFAULT_PLAYER_NAME;
                    xmlDoc.Save(settingsFile);
                }
                if (!File.Exists(backupSettingsFile))
                {
                    DarkLog.Debug("Backing up player token and settings file!");
                    File.Copy(settingsFile, backupSettingsFile);
                }
                xmlDoc.Load(settingsFile);
                playerName = xmlDoc.SelectSingleNode("/settings/global/@username").Value;
                try
                {
                    cacheSize = Int32.Parse(xmlDoc.SelectSingleNode("/settings/global/@cache-size").Value);
                }
                catch
                {
                    DarkLog.Debug("Adding cache size to settings file");
                    saveXMLAfterLoad = true;
                    cacheSize        = DEFAULT_CACHE_SIZE;
                }
                try
                {
                    string   floatArrayString      = xmlDoc.SelectSingleNode("/settings/global/@player-color").Value;
                    string[] floatArrayStringSplit = floatArrayString.Split(',');
                    float    redColor   = float.Parse(floatArrayStringSplit[0].Trim());
                    float    greenColor = float.Parse(floatArrayStringSplit[1].Trim());
                    float    blueColor  = float.Parse(floatArrayStringSplit[2].Trim());
                    //Bounds checking - Gotta check up on those players :)
                    if (redColor < 0f)
                    {
                        redColor = 0f;
                    }
                    if (redColor > 1f)
                    {
                        redColor = 1f;
                    }
                    if (greenColor < 0f)
                    {
                        greenColor = 0f;
                    }
                    if (greenColor > 1f)
                    {
                        greenColor = 1f;
                    }
                    if (blueColor < 0f)
                    {
                        blueColor = 0f;
                    }
                    if (blueColor > 1f)
                    {
                        blueColor = 1f;
                    }
                    playerColor = new Color(redColor, greenColor, blueColor, 1f);
                    OptionsWindow.fetch.loadEventHandled = false;
                }
                catch
                {
                    DarkLog.Debug("Adding player color to settings file");
                    saveXMLAfterLoad = true;
                    playerColor      = PlayerColorWorker.GenerateRandomColor();
                }
                try
                {
                    chatKey = (KeyCode)Int32.Parse(xmlDoc.SelectSingleNode("/settings/global/@chat-key").Value);
                }
                catch
                {
                    DarkLog.Debug("Adding chat key to settings file");
                    saveXMLAfterLoad = true;
                    chatKey          = KeyCode.BackQuote;
                }
                try
                {
                    screenshotKey = (KeyCode)Int32.Parse(xmlDoc.SelectSingleNode("/settings/global/@screenshot-key").Value);
                }
                catch
                {
                    DarkLog.Debug("Adding screenshot key to settings file");
                    saveXMLAfterLoad = true;
                    chatKey          = KeyCode.F8;
                }
                try
                {
                    selectedFlag = xmlDoc.SelectSingleNode("/settings/global/@selected-flag").Value;
                }
                catch
                {
                    DarkLog.Debug("Adding selected flag to settings file");
                    saveXMLAfterLoad = true;
                    selectedFlag     = "Squad/Flags/default";
                }
                XmlNodeList serverNodeList = xmlDoc.GetElementsByTagName("server");
                servers = new List <ServerEntry>();
                foreach (XmlNode xmlNode in serverNodeList)
                {
                    ServerEntry newServer = new ServerEntry();
                    newServer.name    = xmlNode.Attributes["name"].Value;
                    newServer.address = xmlNode.Attributes["address"].Value;
                    Int32.TryParse(xmlNode.Attributes["port"].Value, out newServer.port);
                    servers.Add(newServer);
                }
                if (saveXMLAfterLoad)
                {
                    SaveSettings();
                }
            }
            catch (Exception e)
            {
                DarkLog.Debug("XML Exception: " + e);
            }

            //Read player token
            try
            {
                //Restore backup if needed
                if (File.Exists(backupTokenFile) && !File.Exists(tokenFile))
                {
                    DarkLog.Debug("Restoring backed up token file!");
                    File.Copy(backupTokenFile, tokenFile);
                }
                //Load or create token file
                if (File.Exists(tokenFile))
                {
                    using (StreamReader sr = new StreamReader(tokenFile))
                    {
                        playerGuid = new Guid(sr.ReadLine());
                    }
                }
                else
                {
                    DarkLog.Debug("Creating new token file.");
                    using (StreamWriter sw = new StreamWriter(tokenFile))
                    {
                        playerGuid = Guid.NewGuid();
                        sw.WriteLine(playerGuid.ToString());
                    }
                }
                //Save backup token file if needed
                if (!File.Exists(backupTokenFile))
                {
                    DarkLog.Debug("Backing up token file.");
                    File.Copy(tokenFile, backupTokenFile);
                }
            }
            catch
            {
                DarkLog.Debug("Error processing token, creating new token file.");
                playerGuid = Guid.NewGuid();
                if (File.Exists(tokenFile))
                {
                    File.Move(tokenFile, tokenFile + ".bak");
                }
                using (StreamWriter sw = new StreamWriter(tokenFile))
                {
                    sw.WriteLine(playerGuid.ToString());
                }
                DarkLog.Debug("Backing up token file.");
                File.Copy(tokenFile, backupTokenFile, true);
            }
        }