public static bool OpenYS_Command_Options_ConsoleName_Method(Client ThisClient, CommandReader Command) { if (Command._CmdArguments.Count() < 1) { ThisClient.SendMessage("&eCurrent server name: &2" + OpenYS.OpenYSConsole.Username + "&e."); return(false); } OpenYS.OpenYSConsole.Username = Command._CmdRawArguments; SettingsHandler.SaveAll(); ThisClient.SendMessage("&aServer name is now: &2" + OpenYS.OpenYSConsole.Username + "&a."); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set the server name to: &2" + OpenYS.OpenYSConsole.Username + "&a."); return(true); }
public static bool OpenYS_Command_Weather_GndColor_Method(Client ThisClient, CommandReader Command) { if (Command._CmdArguments.Count() < 1) { ThisClient.SendMessage("&eFormat incorrect: Use instead: \"/GroundColor Red Green Blue\"!"); return(false); } if (Command._CmdArguments[0].ToUpperInvariant() == "DEFAULT" | Command._CmdArguments[0].ToUpperInvariant() == "OFF") { Settings.Weather.Advanced.EnableGndColor = false; ThisClient.SendMessage("&eGroundColor turned &cOFF&e."); SettingsHandler.SaveAll(); return(true); } if (Command._CmdArguments[0].ToUpperInvariant() == "ON") { Settings.Weather.Advanced.EnableGndColor = true; ThisClient.SendMessage("&eGroundColor turned &aON&e."); SettingsHandler.SaveAll(); return(true); } if (Command._CmdArguments.Count() < 3) { ThisClient.SendMessage("&eFormat incorrect: Use instead: \"/GroundColor Red Green Blue\"!"); return(false); } byte Red = 255; byte Green = 255; byte Blue = 255; if (!Byte.TryParse(Command._CmdArguments[0], out Red) & !Byte.TryParse(Command._CmdArguments[1], out Green) & !Byte.TryParse(Command._CmdArguments[2], out Blue)) { ThisClient.SendMessage("&eFormat incorrect: Be sure you are using values between 0 and 255!"); return(false); } Settings.Weather.Advanced.EnableGndColor = true; OpenYS.AdvancedWeatherOptions.GndColor = new Colors.XRGBColor(Red, Green, Blue); Packets.Packet_50_GroundColor GndColor = new Packets.Packet_50_GroundColor(Red, Green, Blue); Clients.AllClients.SendPacket(GndColor); ThisClient.SendMessage("&eGround Color is now: " + GndColor.Red + " " + GndColor.Green + " " + GndColor.Blue + "."); SettingsHandler.SaveAll(); return(true); }
public static bool OpenYS_Command_Options_RestartTimer_Method(Client ThisClient, CommandReader Command) { if (Command._CmdArguments.Count() < 1) { if (Settings.Server.RestartTimer > 0) { ThisClient.SendMessage("&eServer Restart Timer is set to " + Settings.Server.RestartTimer + " minutes."); ThisClient.SendMessage("&eServer is schedualed to restart in " + (Settings.Server.RestartTimer - (int)((DateTime.Now - OpenYS.Time_ResetTimerStarted).TotalMinutes)) + " minutes."); return(true); } if (Settings.Server.RestartTimer == 0) { ThisClient.SendMessage("&eServer Restart Timer is disabled."); return(true); } else { ThisClient.SendMessage("&eServer is restarting."); } return(false); } uint output = 0; if (!UInt32.TryParse(Command._CmdArguments[0], out output)) { ThisClient.SendMessage("&eFormat incorrect: Be sure you are using an integer value!"); return(false); } //OpenYS.ResetTimerThread.Abort(); Clients.AllClients.SendMessage("&6*** Current Server Restart Timer Stopped! ***"); Settings.Server.RestartTimer = (int)output; if (Settings.Server.RestartTimer == 0) { ThisClient.SendMessage("&aServer Restart Timer &cDISABLED&a."); SettingsHandler.SaveAll(); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " &cDISABLED&a the Server Restart Timer."); } else { ThisClient.SendMessage("&aServer Restart Timer set to " + Settings.Server.RestartTimer + " minutes."); SettingsHandler.SaveAll(); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set the Server Restart Timer to " + Settings.Server.RestartTimer + " minutes."); } return(true); }
public static bool OpenYS_Command_Weather_Variable_Method(Client ThisClient, CommandReader Command) { if (Command._CmdArguments.Count() < 1) { if (OpenYS.AdvancedWeatherOptions._Weather_Variable) { ThisClient.SendMessage("&eServer automatically updates the weather."); } else { ThisClient.SendMessage("&eServer does not automatically update the weather."); } return(false); } if (Command._CmdArguments[0].ToUpperInvariant() == "ON" | Command._CmdArguments[0].ToUpperInvariant() == "TRUE") { OpenYS.AdvancedWeatherOptions._WindX = OpenYS._Weather.WindX; //m/s OpenYS.AdvancedWeatherOptions._WindY = OpenYS._Weather.WindY; //m/s OpenYS.AdvancedWeatherOptions._WindZ = OpenYS._Weather.WindZ; //m/s OpenYS.AdvancedWeatherOptions._Fog__ = OpenYS._Weather.Fog; //m; OpenYS.AdvancedWeatherOptions._WindX_DUDX1 = 0; //m/s OpenYS.AdvancedWeatherOptions._WindY_DUDX1 = 0; //m/s OpenYS.AdvancedWeatherOptions._WindZ_DUDX1 = 0; //m/s OpenYS.AdvancedWeatherOptions._Fog___DUDX1 = 0; //m //OpenYS.Weather = OpenYS._Weather; //force an update. OpenYS.AdvancedWeatherOptions._Weather_Variable = true; //Clients.AllClients.SendPacket(OpenYS.Weather); ThisClient.SendMessage("&aServer automatic weather updates set to &aON&a."); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set automatic weather updates to &aON&a."); SettingsHandler.SaveAll(); return(true); } if (Command._CmdArguments[0].ToUpperInvariant() == "OFF" | Command._CmdArguments[0].ToUpperInvariant() == "FALSE") { OpenYS.AdvancedWeatherOptions._Weather_Variable = false; Clients.AllClients.SendPacket(OpenYS.Weather); ThisClient.SendMessage("&aServer automatic weather updates set to &cOFF&a."); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set automatic weather updates to &cOFF&a."); SettingsHandler.SaveAll(); return(true); } ThisClient.SendMessage("&eUnrecognised option - \"" + Command._CmdArguments[0] + "\"."); return(false); }
public static bool OpenYS_Command_Weather_ELE_Method(Client ThisClient, CommandReader Command) { if (Command._CmdArguments.Count() < 1) { if (OpenYS.Weather.Enable_LandEverywhere) { ThisClient.SendMessage("&eServer enables its \"Land Everywhere\" setting."); } else { ThisClient.SendMessage("&eServer disables its \"Land Everywhere\" setting."); } return(false); } if (Command._CmdArguments[0].ToUpperInvariant() == "ON" | Command._CmdArguments[0].ToUpperInvariant() == "TRUE") { OpenYS.Weather = new Packets.Packet_33_Weather(OpenYS._Weather) { Enable_LandEverywhere = true }; Clients.AllClients.SendPacket(OpenYS.Weather); SettingsHandler.SaveAll(); ThisClient.SendMessage("&aServer \"Land Everywhere\" set to &aON&a."); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set \"Land Everywhere\" to &aON&a."); return(true); } if (Command._CmdArguments[0].ToUpperInvariant() == "OFF" | Command._CmdArguments[0].ToUpperInvariant() == "FALSE") { OpenYS.Weather = new Packets.Packet_33_Weather(OpenYS._Weather) { Enable_LandEverywhere = false }; Clients.AllClients.SendPacket(OpenYS.Weather); SettingsHandler.SaveAll(); ThisClient.SendMessage("&aServer \"Land Everywhere\" set to &cOFF&a."); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set \"Land Everywhere\" to &cOFF&a."); return(true); } ThisClient.SendMessage("&eUnrecognised option - \"" + Command._CmdArguments[0] + "\"."); return(false); }
public static bool OpenYS_Command_Weather_FColl_Method(Client ThisClient, CommandReader Command) { if (Command._CmdArguments.Count() < 1) { if (OpenYS.Weather.Control_Collisions) { ThisClient.SendMessage("&eServer is forcing its \"Collisions\" setting."); } else { ThisClient.SendMessage("&eServer is not forcing its \"Collisions\" setting."); } return(false); } if (Command._CmdArguments[0].ToUpperInvariant() == "ON" | Command._CmdArguments[0].ToUpperInvariant() == "TRUE") { OpenYS.Weather = new Packets.Packet_33_Weather(OpenYS._Weather) { Control_Collisions = true }; Clients.AllClients.SendPacket(OpenYS.Weather); SettingsHandler.SaveAll(); ThisClient.SendMessage("&aServer Force \"Collisions\" Setting set to &aON&a."); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set Force \"Collisions\" Setting to &aON&a."); return(true); } if (Command._CmdArguments[0].ToUpperInvariant() == "OFF" | Command._CmdArguments[0].ToUpperInvariant() == "FALSE") { OpenYS.Weather = new Packets.Packet_33_Weather(OpenYS._Weather) { Control_Collisions = false }; Clients.AllClients.SendPacket(OpenYS.Weather); SettingsHandler.SaveAll(); ThisClient.SendMessage("&aServer Force \"Collisions\" Setting set to &cOFF&a."); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set Force \"Collisions\" Setting to &cOFF&a."); return(true); } ThisClient.SendMessage("&eUnrecognised option - \"" + Command._CmdArguments[0] + "\"."); return(false); }
public static bool OpenYS_Command_Options_Field_Method(Client ThisClient, CommandReader Command) { if (Command._CmdArguments.Count() < 1) { if (OpenYS.Field != null) { ThisClient.SendMessage("&eCurrent Field: &a" + OpenYS.Field.FieldName + "&e."); } else { ThisClient.SendMessage("&cERROR: Server Field handler not found."); } return(false); } if (Command._CmdRawArguments.Contains(' ')) { Command._CmdRawArguments = '"' + Command._CmdRawArguments + '"'; } if (MetaData._Scenery.List.Where(x => x.Identify.ToUpperInvariant().StartsWith(Command._CmdRawArguments.ToUpperInvariant())).Count() <= 0) { ThisClient.SendMessage("&eTarget Field not found: " + Command._CmdRawArguments + "&e."); return(false); } if (Environment.CommandLineArguments.Length == 0) { Environment.CommandLineArguments = new string[] { Settings.Loading.YSFlightDirectory, MetaData._Scenery.List.Where(x => x.Identify.ToUpperInvariant().StartsWith(Command._CmdRawArguments.ToUpperInvariant())).ToArray()[0].Identify, Settings.Server.ListenerPort.ToString() }; } else if (Environment.CommandLineArguments.Length > 1) { Environment.CommandLineArguments[1] = MetaData._Scenery.List.Where(x => x.Identify.ToUpperInvariant().StartsWith(Command._CmdRawArguments.ToUpperInvariant())).ToArray()[0].Identify; } Settings.Loading.FieldName = Environment.CommandLineArguments[1]; SettingsHandler.SaveAll(); ThisClient.SendMessage("&cTarget Server Field changed to &e" + Environment.CommandLineArguments[1] + "&c."); ThisClient.SendMessage("&cTO CHANGE THE Field NOW, RESTART THE SERVER!"); //Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set the server name to: &2" + OpenYS.OpenYSConsole.Info.Username + "&a."); return(true); }
public static bool OpenYS_Command_Weather_Turbulemce_Method(Client ThisClient, CommandReader Command) { if (Command._CmdArguments.Count() < 1) { if (OpenYS.AdvancedWeatherOptions._Turbulence > 0) { ThisClient.SendMessage("&eServer turbulence is " + OpenYS.AdvancedWeatherOptions._Turbulence + "."); } else { ThisClient.SendMessage("&eServer disables turbulence."); } return(false); } uint ID = 0; if (!UInt32.TryParse(Command._CmdArguments[0], out ID)) { ThisClient.SendMessage("&eFormat incorrect: Be sure you are using an integer value!"); return(false); } if (ID > 0) { OpenYS.AdvancedWeatherOptions._Turbulence = (int)ID; ThisClient.SendMessage("&aServer turbulence set to &a" + ID + "&a percent."); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set turbulence to &a" + ID + "&a percent."); SettingsHandler.SaveAll(); return(true); } else { OpenYS.AdvancedWeatherOptions._Turbulence = 0; ThisClient.SendMessage("&aServer turbulence set to &cOFF&a."); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set turbulence to &cOFF&a."); SettingsHandler.SaveAll(); return(true); } }
public static bool OpenYS_Command_Weather_Time_Method(Client ThisClient, CommandReader Command) { if (Command._CmdArguments.Count() < 1) { ThisClient.SendMessage("&eServer time is currently " + OpenYS.GetServerTimeString() + "J."); return(false); } if (Command._CmdArguments[0].ToUpperInvariant() == "DAY") { OpenYS.Weather = new Packets.Packet_33_Weather(OpenYS._Weather) { Lighting = 0 }; int incrementticks = (int)(12 * 1000) + (int)Math.Round(0 * 1000d / 60d); TimeSpan Adjustment = new TimeSpan(0, 0, 0, 0, (int)(incrementticks / 24000d * OpenYS.AdvancedWeatherOptions._DayNightCycleLength * 60 * 1000d)); OpenYS.AdvancedWeatherOptions._LastDayNightCycleRestart = DateTime.Now - Adjustment; Clients.AllClients.SendPacket(OpenYS.Weather); ThisClient.SendMessage("&aServer time set to 1200J."); Settings.Weather.Time = 1200; SettingsHandler.SaveAll(); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set the time to 1200J."); return(true); } if (Command._CmdArguments[0].ToUpperInvariant() == "NIGHT") { OpenYS.Weather = new Packets.Packet_33_Weather(OpenYS._Weather) { Lighting = 65537 }; int incrementticks = (int)(0 * 1000) + (int)Math.Round(0 * 1000d / 60d); TimeSpan Adjustment = new TimeSpan(0, 0, 0, 0, (int)(incrementticks / 24000d * OpenYS.AdvancedWeatherOptions._DayNightCycleLength * 60 * 1000d)); OpenYS.AdvancedWeatherOptions._LastDayNightCycleRestart = DateTime.Now - Adjustment; Clients.AllClients.SendPacket(OpenYS.Weather); ThisClient.SendMessage("&aServer time set to 0000J."); Settings.Weather.Time = 0000; SettingsHandler.SaveAll(); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set the time to 0000J."); return(true); } if (Command._CmdArguments[0].ToUpperInvariant() == "DAWN") { OpenYS.Weather = new Packets.Packet_33_Weather(OpenYS._Weather) { Lighting = 0 }; int incrementticks = (int)(6 * 1000) + (int)Math.Round(0 * 1000d / 60d); TimeSpan Adjustment = new TimeSpan(0, 0, 0, 0, (int)(incrementticks / 24000d * OpenYS.AdvancedWeatherOptions._DayNightCycleLength * 60 * 1000d)); OpenYS.AdvancedWeatherOptions._LastDayNightCycleRestart = DateTime.Now - Adjustment; Clients.AllClients.SendPacket(OpenYS.Weather); ThisClient.SendMessage("&aServer time set to 0600J."); Settings.Weather.Time = 0600; SettingsHandler.SaveAll(); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set the time to 0600J."); return(true); } if (Command._CmdArguments[0].ToUpperInvariant() == "DUSK") { OpenYS.Weather = new Packets.Packet_33_Weather(OpenYS._Weather) { Lighting = 65537 }; Clients.AllClients.SendPacket(OpenYS.Weather); SettingsHandler.SaveAll(); OpenYS.AdvancedWeatherOptions._LastDayNightCycleRestart = DateTime.Now; int incrementticks = (int)(18 * 1000) + (int)Math.Round(0 * 1000d / 60d); TimeSpan Adjustment = new TimeSpan(0, 0, 0, 0, (int)(incrementticks / 24000d * OpenYS.AdvancedWeatherOptions._DayNightCycleLength * 60 * 1000d)); OpenYS.AdvancedWeatherOptions._LastDayNightCycleRestart = DateTime.Now - Adjustment; ThisClient.SendMessage("&aServer time set to 1800J."); Settings.Weather.Time = 1800; SettingsHandler.SaveAll(); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set the time to 1800J."); return(true); } try { String Input = Command._CmdArguments[0]; if (Input.Length == 5 && Input.ToUpperInvariant().EndsWith("J")) { Input = Input.Substring(0, Input.Length - 1); } if (Input.Length != 4) { ThisClient.SendMessage("&eTime must be in 24 Hour Format!"); return(false); } uint hours = UInt32.Parse(Input.ToUpperInvariant().Substring(0, 2)); uint minutes = UInt32.Parse(Input.ToUpperInvariant().Substring(2, 2)); if (hours >= 24) { ThisClient.SendMessage("&aServer Time Invalid! Must be between 0000 and 2359!"); } if (minutes >= 60) { ThisClient.SendMessage("&aServer Time Invalid! Minutes >= 60???"); } uint incrementticks = (hours * 1000) + (uint)Math.Round(minutes * 1000d / 60d); OpenYS.SetServerTimeTicks(incrementticks); Settings.Weather.Time = OpenYS.GetServerTimeUint(); SettingsHandler.SaveAll(); ThisClient.SendMessage("&aServer time set to " + OpenYS.GetServerTimeString() + "J."); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set the time to " + OpenYS.GetServerTimeString() + "J."); return(true); } catch { } ThisClient.SendMessage("&eUnrecognised time - \"" + Command._CmdArguments[0] + "\"."); return(false); }
public static bool OpenYS_Command_Weather_DNCycle_Method(Client ThisClient, CommandReader Command) { if (Command._CmdArguments.Count() < 1) { if (OpenYS.AdvancedWeatherOptions._DayNightCycleLength > 0) { ThisClient.SendMessage("&eServer enables its day/night cycle (" + OpenYS.AdvancedWeatherOptions._DayNightCycleLength + ")."); } else { ThisClient.SendMessage("&eServer disables its day/night cycle."); } return(false); } uint ID = 0; if (!UInt32.TryParse(Command._CmdArguments[0], out ID)) { ThisClient.SendMessage("&eFormat incorrect: Be sure you are using an integer value!"); return(false); } if (ID > 0) { uint CurrentTick = OpenYS.GetServerTimeTicks(); OpenYS.AdvancedWeatherOptions._DayNightCycleLength = (int)ID; OpenYS.SetServerTimeTicks((uint)CurrentTick); Random ThisRandom = new Random(); ThisClient.SendMessage("&aServer day/night cycle set to &a" + ID + "&a Minutes."); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set day/night cycle to &a" + ID + "&a Minutes."); if (OpenYS.GetServerTimeTicks() > 7000 && OpenYS.GetServerTimeTicks() < 19000) { if (ThisRandom.Next(1, 100) == 99) { Clients.AllClients.SendMessage("&6Dawn of the first day. (Lol, YSZelda.)"); } else { Clients.AllClients.SendMessage("&6The sun rises... (Day/Night Sequencer Started!)"); } } else { if (ThisRandom.Next(1, 100) == 99) { Clients.AllClients.SendMessage("&5The Dark (k)Night rises. (Lol, YSBatman.)"); } else { Clients.AllClients.SendMessage("&5The sun sets... (Day/Night Sequencer Started!)"); } } if (OpenYS.GetServerTimeTicks() > 7000 && OpenYS.GetServerTimeTicks() < 19000) { OpenYS._Weather.Lighting = 0; } else { OpenYS._Weather.Lighting = 65537; } OpenYS.UpdateWeather(); SettingsHandler.SaveAll(); return(true); } else { uint CurrentTick = OpenYS.GetServerTimeTicks(); OpenYS.AdvancedWeatherOptions._DayNightCycleLength = 0; OpenYS.SetServerTimeTicks((uint)CurrentTick); ThisClient.SendMessage("&aServer day/night cycle set to &cOFF&a."); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set day/night cycle to &cOFF&a."); SettingsHandler.SaveAll(); return(true); } }
private void Authenticate() { //Disable all inputs! Username_TextBox.Enabled = false; Password_TextBox.Enabled = false; Authentication_Button.Enabled = false; ShowPassword_CheckBox.Enabled = false; AuthenticationStatus_Label.Text = "AUTHENTICATING..."; AuthenticationStatus_Label.ForeColor = Color.FromArgb(240, 200, 0); AuthenticationStatus_Label.BackColor = Color.Transparent; OpenYS_Link.Stats._id = 0; Application.DoEvents(); using (var client = new WebClient()) { var values = new NameValueCollection(); values["username"] = Username_TextBox.Text; if (PasswordIsEncrypted) { values["password"] = OYS_Cryptography.DecryptPassword(Password_TextBox.Text); } else { values["password"] = Password_TextBox.Text; } try { //Key Verification: //https://forum.ysfhq.com/api-check.php?apikey= string APIKey = Environment.GetAPIKey(); if (APIKey == "MISSINGNO." | APIKey == "") { MessageBox.Show("APIKey not supplied for this custom build of OYS!\n\nTo get your own API Key, contact YSFHQ Webmasters, then place that key inside APIKey.txt, inside OpenYS-Library/Utilities!", "API Key Not Found!"); Username_TextBox.Enabled = false; Password_TextBox.Enabled = false; ShowPassword_CheckBox.Enabled = false; Authentication_Button.Enabled = false; //leave this false, unable to authenticate without reloading! AuthenticationStatus_Label.Text = "API KEY MISSING"; AuthenticationStatus_Label.ForeColor = Color.FromArgb(128, 0, 0); AuthenticationStatus_Label.BackColor = Color.FromArgb(240, 200, 0); OpenYS_Link.Stats._id = 0; Application.DoEvents(); return; } var response = client.UploadValues("https://forum.ysfhq.com/api-login.php?apikey=" + APIKey, values); var responseString = Encoding.Default.GetString(response); System.Console.WriteLine(responseString); bool Failed = !Int32.TryParse(responseString.Replace("\"", ""), out OpenYS_Link.Stats._id); if (Failed | OpenYS_Link.Stats._id <= 0) { //NO GOOD! Username_TextBox.Enabled = true; Password_TextBox.Enabled = true; ShowPassword_CheckBox.Enabled = true; Authentication_Button.Enabled = true; AuthenticationStatus_Label.Text = "AUTHENTICATION FAIL!"; AuthenticationStatus_Label.ForeColor = Color.FromArgb(240, 0, 0); AuthenticationStatus_Label.BackColor = Color.Transparent; Application.DoEvents(); return; } else { //ALL GOOD! if (!PasswordIsEncrypted) { //Only update if the password has been modified! SettingsHandler.LoadAll(); Settings.YSFHQ.Username = Username_TextBox.Text; Settings.YSFHQ.EncryptedPassword = OYS_Cryptography.EncryptPassword(Password_TextBox.Text); SettingsHandler.SaveAll(); } Username_TextBox.Enabled = true; Password_TextBox.Enabled = true; ShowPassword_CheckBox.Enabled = true; Authentication_Button.Enabled = true; AuthenticationStatus_Label.Text = "AUTHENTICATED"; AuthenticationStatus_Label.ForeColor = Color.FromArgb(0, 128, 0); AuthenticationStatus_Label.BackColor = Color.Transparent; Application.DoEvents(); OpenYS_Link.GetAllStats(); //OpenYS_Link.OYS_Link_Response Response = OpenYS_Link.Get(YSFHQ_ID, "/stats_total_flight_seconds"); //MessageBox.Show(Response.Response, Response.Reason); //^^ WORKING! return; } } catch (System.Net.WebException WebError) { HttpStatusCode ErrorCode = ((HttpWebResponse)WebError.Response).StatusCode; if (ErrorCode == HttpStatusCode.BadRequest) //400 { //Missing Username / Password Username_TextBox.Enabled = true; Password_TextBox.Enabled = true; ShowPassword_CheckBox.Enabled = true; Authentication_Button.Enabled = true; AuthenticationStatus_Label.Text = "NO USER OR PASS?"; AuthenticationStatus_Label.ForeColor = Color.FromArgb(240, 0, 0); AuthenticationStatus_Label.BackColor = Color.Transparent; Application.DoEvents(); return; } if (ErrorCode == HttpStatusCode.Unauthorized) //401 { //Bad API Key MessageBox.Show("APIKey not accepted for this release of OYS!\n\nPlease confirm your API Key with YSFHQ Webmasters, then update OpenYS-Library/Utilities/APIKey.txt!", "API Key Rejected!"); Username_TextBox.Enabled = false; Password_TextBox.Enabled = false; ShowPassword_CheckBox.Enabled = false; Authentication_Button.Enabled = false; //leave this false, unable to authenticate without reloading! AuthenticationStatus_Label.Text = "API KEY REJECTED"; AuthenticationStatus_Label.ForeColor = Color.FromArgb(128, 0, 0); AuthenticationStatus_Label.BackColor = Color.FromArgb(240, 200, 0); Application.DoEvents(); return; } if (ErrorCode == HttpStatusCode.Forbidden) //403 { //Bad Username / Password Username_TextBox.Enabled = true; Password_TextBox.Enabled = true; ShowPassword_CheckBox.Enabled = true; Authentication_Button.Enabled = true; AuthenticationStatus_Label.Text = "AUTHENTICATION FAIL!"; AuthenticationStatus_Label.ForeColor = Color.FromArgb(240, 0, 0); AuthenticationStatus_Label.BackColor = Color.Transparent; Application.DoEvents(); return; } //Generic Error? MessageBox.Show("Generic Error Occured:\n\n" + WebError.Message, "Genereric Error!"); Username_TextBox.Enabled = true; Password_TextBox.Enabled = true; ShowPassword_CheckBox.Enabled = true; Authentication_Button.Enabled = true; AuthenticationStatus_Label.Text = "GENERIC ERROR!"; AuthenticationStatus_Label.ForeColor = Color.FromArgb(240, 0, 0); AuthenticationStatus_Label.BackColor = Color.Transparent; Application.DoEvents(); return; //System.Console.WriteLine(WebError); } } }
public static bool OpenYS_Command_Weather_Wind_Method(Client ThisClient, CommandReader Command) { int Angle; int Speed; string _Angle; string _Speed; string TAF; if (Command._CmdArguments.Count() < 1) { Angle = 90 - (int)(Math.Atan2(OpenYS.Weather.WindZ, OpenYS.Weather.WindX) / Math.PI * 180) + 180; while (Angle < 0) { Angle += 360; } while (Angle >= 360) { Angle -= 360; } Speed = (int)(Math.Sqrt(Math.Pow(OpenYS.Weather.WindZ, 2) + Math.Pow(OpenYS.Weather.WindX, 2)) * 1.943844492440605); //ThisClient.SendMessage("&eServer Wind Angle is currently " + Angle + "deg."); //ThisClient.SendMessage("&eServer Wind Speed is currently " + Speed + "kt."); if (Speed <= 0) { Angle = 0; } _Angle = Angle.ToString(); if (_Angle.Length > 3) { _Angle = "XXX"; } while (_Angle.Length < 3) { _Angle = "0" + _Angle; } _Speed = Speed.ToString(); if (_Speed.Length > 2) { _Speed = "99"; } while (_Speed.Length < 2) { _Speed = "0" + _Speed; } TAF = _Angle + _Speed + "KT"; if (TAF == "00000KT") { TAF = "calm"; } ThisClient.SendMessage("&eServer Wind is currently " + TAF + "."); return(true); } TAF = Command._CmdArguments[0].ToLowerInvariant(); if (TAF == "calm") { TAF = "00000KT"; } uint output = 0; if (!UInt32.TryParse(TAF.Substring(0, 3), out output)) { ThisClient.SendMessage("&eUnrecognised value - \"" + Command._CmdArguments[0] + "\"."); return(false); } Angle = 90 - (int)output; while (Angle < 0) { Angle += 360; } while (Angle >= 360) { Angle -= 360; } output = 0; if (!UInt32.TryParse(TAF.Substring(3, 2), out output)) { ThisClient.SendMessage("&eUnrecognised value - \"" + Command._CmdArguments[0] + "\"."); return(false); } Speed = (int)output; OpenYS.Weather = new Packets.Packet_33_Weather(OpenYS._Weather) { WindZ = (float)((Math.Sin((double)Angle / 180 * Math.PI)) * Speed * 0.5144444444444444), WindX = (float)((Math.Cos((double)Angle / 180 * Math.PI)) * Speed * 0.5144444444444444) }; TAF = Command._CmdArguments[0].ToUpperInvariant(); if (TAF == "CALM") { TAF = "calm"; } else if (TAF.Substring(3, 2) == "00") { TAF = "calm"; } Clients.AllClients.SendPacket(OpenYS.Weather); SettingsHandler.SaveAll(); ThisClient.SendMessage("&eServer Wind set to " + TAF + "."); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set the Wind to " + TAF + "."); return(true); }