/// <summary> /// Used to load settings from the InitializeValues void /// </summary> /// <param name="SettingName">The name of the setting</param> /// <param name="DefaultValue">Baseline value</param> /// <returns></returns> private static string InvalidateSetting(string SettingName, string DefaultValue) { ILogger.AddToLog("GFS", "Checking " + SettingName + ", with datavalue " + DefaultValue + " exist."); //Check if the setting exist's if (manager.CheckSetting(SettingName)) { ILogger.AddToLog("GFS", SettingName + " exist! Returning value."); //Return the value of the setting return(manager.ReadSetting(SettingName)); } else { ILogger.AddToLog("GFS", SettingName + " does not exist! Creating setting with " + DefaultValue + " as a datavalue"); //Edit the setting and then return the default value. manager.EditSetting(SettingName, DefaultValue); return(DefaultValue); } }
private void CheckForSystemUpdate() { MoonbyteServerConnection = new UniversalClient(false); if (!settingsFramework.CheckSetting("UPDATEP")) { settingsFramework.EditSetting("UPDATEP", true.ToString()); } if (settingsFramework.ReadSetting("UPDATEP") == true.ToString()) { string IP = "moonbyte.us"; string externalip = new WebClient().DownloadString("http://icanhazip.com"); if (externalip.Contains(Dns.GetHostAddresses(new Uri("http://moonbyte.us").Host)[0].ToString())) { IP = "192.168.0.16"; } MoonbyteServerConnection.ConnectToRemoteServer(IP, 7777); AssemblyFileVersionAttribute UPFVersion = typeof(UniversalPluginFramework).GetTypeInfo().Assembly.GetCustomAttribute <AssemblyFileVersionAttribute>(); AssemblyFileVersionAttribute UCVersion = typeof(UniversalClient).GetTypeInfo().Assembly.GetCustomAttribute <AssemblyFileVersionAttribute>(); string CurrentVersion = MoonbyteServerConnection.SendCommand("dyn", new string[] { "GetVersion", "UniversalServer" }); Assembly assembly = Assembly.GetExecutingAssembly(); string Version = FileVersionInfo.GetVersionInfo(assembly.Location).ProductVersion; if (Version != CurrentVersion) { ILogger.AddToLog("WARN", "Universal Server is currently out of date! Current version installed : " + Version); ILogger.AddToLog("WARN", "With UniversalServer not updated, some plugins and features may not work correctly."); ILogger.AddToLog("WARN", "Please install the updated version " + CurrentVersion); } else { ILogger.AddToLog("INFO", "Universal Server - Version " + Version + ", is currently up to date!"); } ILogger.AddWhitespace(); ILogger.AddToLog("INFO", "UniversalPluginFramework version " + UPFVersion.Version); ILogger.AddToLog("INFO", "UniversalClient version " + UCVersion.Version); ILogger.AddWhitespace(); } }
public void StartListener() { string port = null; if (settingsFramework.CheckSetting("port")) { port = settingsFramework.ReadSetting("port"); } else { settingsFramework.EditSetting("port", "7777"); port = "7777"; } listener = new TcpListener(new IPEndPoint(IPAddress.Any, int.Parse(port))); listener.Start(); LoadPlugins(); listener.BeginAcceptTcpClient(OnClientAccepted, listener); this.Status = "Online"; }
public UniversalServerObject(string Name, string ServerDirectory) { ServerDirectory = ServerDirectory + @"\" + Name; PluginDirectory = ServerDirectory + @"\Plugins"; ServerStorageDirectory = ServerDirectory + @"\UserStorage"; PluginEditDirectory = ServerDirectory + @"\Plugin Settings"; if (!Directory.Exists(ServerDirectory)) { Directory.CreateDirectory(ServerDirectory); } ServerDirectory = ServerDirectory + @"\" + "settings.dll"; if (!Directory.Exists(PluginDirectory)) { Directory.CreateDirectory(PluginDirectory); } if (!Directory.Exists(PluginEditDirectory)) { Directory.CreateDirectory(PluginEditDirectory); } if (!Directory.Exists(ServerStorageDirectory)) { Directory.CreateDirectory(ServerStorageDirectory); } ServerName = Name; settingsFramework = new GFS(ServerDirectory); string port = null; if (settingsFramework.CheckSetting("port")) { port = settingsFramework.ReadSetting("port"); } else { settingsFramework.EditSetting("port", "7777"); port = "7777"; } }
/// <summary> /// Creates download objects out of the download list /// </summary> public void InitializeDownloadItems() { //Seperator for the download string[] Seperator = new string[] { "%20%|downloadSep|%20%" }; string DownloadDirectory = Application.StartupPath + @"\Download"; string DownloadFile = DownloadDirectory + @"\downloadfiles.dat"; //Creates the directory and file if it does not exist if (!Directory.Exists(DownloadDirectory)) { Directory.CreateDirectory(DownloadDirectory); } //Sets a new instance of GFS GFS gfs = new GFS(); gfs.SettingsDirectory = DownloadFile; //Check if the setting exist if (!gfs.CheckSetting(DownloadSettingHeader)) { gfs.EditSetting(DownloadSettingHeader, Seperator[0]); } //Gets the string and split it into an array string rawDownloadString = gfs.ReadSetting(DownloadSettingHeader); string[] formatDownloadString = rawDownloadString.Split(Seperator, StringSplitOptions.RemoveEmptyEntries); //Adds the download object foreach (string str in formatDownloadString) { string[] fileSeperator = new string[] { "%20%|downloadFileSep|%20%" }; string[] fileInfo = str.Split(fileSeperator, StringSplitOptions.None); DownloadList.Add(new DownloadObject(fileInfo[0], fileInfo[1], false)); } }