internal static bool Logout(this SliceUser user) { if (!Connected || !LoggedIn) { MessageBox.Show($"This application has been setup incorrectly!", SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(0); } user.IPAddress = string.Empty; user.HardwareID = string.Empty; user.Username = string.Empty; user.Password = string.Empty; return(true); }
static void LoginExample() { Console.Clear(); WriteColor("\n\n [", ConsoleColor.DarkRed); WriteColor("*"); WriteColor("] Username: "******" [", ConsoleColor.DarkRed); WriteColor("*"); WriteColor("] Password: "******" Login successful!", ConsoleColor.Green); // All user properties WriteLineColor($" IP Address: {user.IPAddress}", ConsoleColor.Green); WriteLineColor($" Hardware ID: {user.HardwareID}", ConsoleColor.Green); } else // Login fail { WriteLineColor(" Login failed!", ConsoleColor.DarkRed); Console.ReadLine(); return; } // All server-sided variables will be downloaded on a successful login attempt WriteColor("\n Grab Variables", ConsoleColor.DarkYellow); WriteColor("\n [", ConsoleColor.DarkRed); WriteColor("*"); WriteColor("] Variable Name: ", ConsoleColor.DarkRed); string varName = Console.ReadLine(); // Attempt to grab variable, if it doesn't exist or the user isn't logged in it will return a default message variable string varData = exampleApp.GrabVariable(varName); WriteLineColor($" Variable Data: {varData}", ConsoleColor.Yellow); Console.ReadLine(); return; }
static void RegisterExample() { Console.Clear(); WriteColor("\n\n [", ConsoleColor.DarkRed); WriteColor("*"); WriteColor("] Username: "******" [", ConsoleColor.DarkRed); WriteColor("*"); WriteColor("] Password: "******" [", ConsoleColor.DarkRed); WriteColor("*"); WriteColor("] Token: ", ConsoleColor.DarkRed); string token = Console.ReadLine(); // Ask for token SliceUser user = new SliceUser(username, password, token); // Initialize a new user using the entered info bool registerResult = user.Register(exampleApp); // Attempt to register the user using the initialized credentials // NOTE: The default register function has message boxes for responses from our servers, you can remove those to make your own! if (registerResult) // Register success { WriteLineColor(" Registration successful!", ConsoleColor.Green); } else // Register fail { WriteLineColor(" Registration failed!", ConsoleColor.DarkRed); Console.ReadLine(); return; } Console.ReadLine(); return; }
internal static bool Register(this SliceUser user, SliceApp app) { if (!Connected) { MessageBox.Show($"This application isn't connected to our servers!", SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(0); } string[] response = new string[] { }; bool Successful = false; using (WebClient client = new WebClient()) { try { client.Headers.Add(HttpRequestHeader.UserAgent, SliceConstants.UserAgent); Security.StartSession(); string token = Guid.NewGuid().ToString(); response = Encoding.Default.GetString(client.UploadValues(SliceConstants.ApiUrl, new NameValueCollection { ["session_id"] = Security.IV, ["request_id"] = Security.Key, ["api_token"] = Security.Encrypt(app.ApiToken), ["app_secret"] = Security.Encrypt(app.Secret), ["username"] = Security.Encrypt(user.Username), ["password"] = Security.Encrypt(user.Password), ["user_token"] = Security.Encrypt(user.Token), ["hwid"] = Security.Encrypt(Identification.HardwareID), ["token"] = Security.Encrypt(token), ["action"] = Security.Encrypt("register") })).Split(SliceConstants.ApiChar.ToCharArray()); if (response[0] != Security.Encrypt(token)) { MessageBox.Show($"Invalid response from our servers! Please try again later.", SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Error); return(false); } switch (Security.Decrypt(response[2])) { case "success": Successful = true; MessageBox.Show(Security.Decrypt(response[1]), SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Information); break; case "error": MessageBox.Show(Security.Decrypt(response[1]), SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Error); Security.EndSession(); return(false); case "warning": MessageBox.Show(Security.Decrypt(response[1]), SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Warning); Security.EndSession(); return(false); default: MessageBox.Show("Unknown error occured during request! Please try again later.", SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Warning); Environment.Exit(0); return(false); } if (Successful) { Security.EndSession(); } return(true); } catch { MessageBox.Show($"Error while connecting to our authentication servers!", SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Error); } } if (Security.SessionStarted) { Security.EndSession(); } return(false); }
internal static bool Login(this SliceUser user, SliceApp app) { if (!Connected) { MessageBox.Show($"This application isn't connected to our servers!", SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(0); } if (app.Freemode) { return(true); } string[] response = new string[] { }; bool Successful = false; using (WebClient client = new WebClient()) { try { client.Headers.Add(HttpRequestHeader.UserAgent, SliceConstants.UserAgent); Security.StartSession(); string token = Guid.NewGuid().ToString(); response = Encoding.Default.GetString(client.UploadValues(SliceConstants.ApiUrl, new NameValueCollection { ["session_id"] = Security.IV, ["request_id"] = Security.Key, ["api_token"] = Security.Encrypt(app.ApiToken), ["app_secret"] = Security.Encrypt(app.Secret), ["username"] = Security.Encrypt(user.Username), ["password"] = Security.Encrypt(user.Password), ["token"] = Security.Encrypt(token), ["action"] = Security.Encrypt("login") })).Split(SliceConstants.ApiChar.ToCharArray()); if (response[0] != Security.Encrypt(token)) { MessageBox.Show($"Invalid response from our servers! Please try again later.", SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Error); return(false); } switch (Security.Decrypt(response[2])) { case "success": Successful = true; LoggedIn = true; MessageBox.Show(Security.Decrypt(response[1]), SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Information); break; case "error": MessageBox.Show(Security.Decrypt(response[1]), SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Error); Security.EndSession(); return(false); case "warning": MessageBox.Show(Security.Decrypt(response[1]), SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Warning); Security.EndSession(); return(false); default: MessageBox.Show("Unknown error occured during request! Please try again later.", SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Warning); Environment.Exit(0); return(false); } if (Successful) { user.IPAddress = Security.Decrypt(response[3]); user.HardwareID = Security.Decrypt(response[4]); // This is pretty hacky and will be refined string tempVars = Security.Decrypt(response[5]); foreach (string pair in tempVars.Split('~')) { string[] items = pair.Split('^'); try { app.Variables.Add(items[0], items[1]); } catch { // TODO: Maybe add a handler for failed variables } } Security.EndSession(); return(true); } return(false); } catch (Exception ex) { MessageBox.Show($"Error while connecting to our authentication servers!\n{ex.ToString()}", SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Error); } } if (Security.SessionStarted) { Security.EndSession(); } return(false); }