internal static void SendDataLog(this SliceApp app, string data) { if (!Connected) { MessageBox.Show($"This applications isn't connected to our servers!", SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(0); } string[] response = new string[] { }; 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), ["log_data"] = Security.Encrypt(data), ["token"] = Security.Encrypt(token), ["action"] = Security.Encrypt("log") })).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; } // We do not check if the log failed to keep it slient (It most likely didn't) } catch { MessageBox.Show($"Error while connecting to our authentication servers!", SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(0); } } if (Security.SessionStarted) { Security.EndSession(); } return; }
public static string GrabVariable(this SliceApp app, string name) { try { if (LoggedIn || app.Freemode) { return(app.Variables[name]); } else { return("[Not logged in!]"); } } catch { return("[The requested variable doesn't exist!]"); } }
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); }
internal static void Connect(this SliceApp app) { if (Connected) { MessageBox.Show($"This application is already connected to our servers! Please try again later or contact the developer of this SliceApp.", SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(0); } string[] response = new string[] { }; 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), ["app_version"] = Security.Encrypt(app.Version), ["token"] = Security.Encrypt(token), ["action"] = Security.Encrypt("connect") })).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; } switch (Security.Decrypt(response[2])) { case "success": Connected = 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; case "warning": MessageBox.Show(Security.Decrypt(response[1]), SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Warning); Security.EndSession(); return; default: MessageBox.Show("Unknown error occured during request! Please try again later.", SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Warning); Environment.Exit(0); return; } if (Connected) { app.Name = Security.Decrypt(response[3]); app.Version = Security.Decrypt(response[4]); app.Freemode = bool.Parse(Security.Decrypt(response[5])); app.Hash = Security.Decrypt(response[6]); // Uncomment if you want to check hash //if (app.Hash != Security.Md5CheckSum(Process.GetCurrentProcess().MainModule.FileName)) //{ // MessageBox.Show($"Couldn't verify the integrity of this application!", SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Error); // Environment.Exit(0); //} } } catch { MessageBox.Show($"Error while connecting to our authentication servers!", SliceConstants.Name, MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(0); } } if (Security.SessionStarted) { Security.EndSession(); } return; }