public static async void RegisterWebhook(string username) { var wh = ""; var whHash = HashUtils.GenerateHash(wh); var r = new Random(DateTime.Now.Millisecond); var req = new JObject { { "webhook", whHash }, { "user", username }, { "online", r.NextDouble() >= 0.9 } }; using (var c = MiscUtils.GetDefaultWebClient()) { c.Headers.Add(HttpRequestHeader.ContentType, "application/json"); c.Headers.Add(HttpRequestHeader.AcceptCharset, "utf-8"); c.Encoding = Encoding.UTF8; try { await c.UploadStringTaskAsync( new Uri("http://localhost:5001/tcc-global-events/us-central1/register_webhook"), Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(req.ToString()))); } catch { Console.WriteLine($"Failed to register webhook for {username}"); } } }
public static async Task <bool> RequestWebhookExecution(string webhook) { bool canFire; var req = new JObject { { "webhook", HashUtils.GenerateHash(webhook) }, { "user", HashUtils.GenerateHash(SessionManager.CurrentAccountName) } }; using (var c = FoglioUtils.MiscUtils.GetDefaultWebClient()) { c.Headers.Add(HttpRequestHeader.ContentType, "application/json"); c.Headers.Add(HttpRequestHeader.AcceptCharset, "utf-8"); c.Encoding = Encoding.UTF8; try { var res = await c.UploadStringTaskAsync( new Uri("http://us-central1-tcc-global-events.cloudfunctions.net/fire_webhook"), Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(req.ToString()))); var jRes = JObject.Parse(res); canFire = jRes["canFire"].Value <bool>(); Log.All($"Webhook fire requested, result: {canFire}"); } catch (WebException e) { Log.F($"Failed to request webhook execution. Webhook will be executed anyway: {e}"); canFire = true; } } return(canFire); }
public static async void RegisterWebhook(string webhook, bool online) { if (string.IsNullOrEmpty(webhook)) { return; } if (string.IsNullOrEmpty(SessionManager.CurrentAccountName)) { return; } var req = new JObject { { "webhook", HashUtils.GenerateHash(webhook) }, { "user", HashUtils.GenerateHash(SessionManager.CurrentAccountName) }, { "online", online } }; using (var c = FoglioUtils.MiscUtils.GetDefaultWebClient()) { c.Headers.Add(HttpRequestHeader.ContentType, "application/json"); c.Headers.Add(HttpRequestHeader.AcceptCharset, "utf-8"); c.Encoding = Encoding.UTF8; try { await c.UploadStringTaskAsync( new Uri("http://us-central1-tcc-global-events.cloudfunctions.net/register_webhook"), Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(req.ToString()))); } catch { Log.F($"Failed to register webhook."); } } }
public static async void FireWebhook(string username) { var canFire = true; var wh = ""; var whHash = HashUtils.GenerateHash(wh); var req = new JObject { { "webhook", whHash }, { "user", username } }; using (var c = MiscUtils.GetDefaultWebClient()) { c.Headers.Add(HttpRequestHeader.ContentType, "application/json"); c.Headers.Add(HttpRequestHeader.AcceptCharset, "utf-8"); c.Encoding = Encoding.UTF8; try { var res = await c.UploadStringTaskAsync(new Uri("https://us-central1-tcc-global-events.cloudfunctions.net/fire_webhook"), Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(req.ToString()))); var jRes = JObject.Parse(res); canFire = jRes["canFire"] !.Value <bool>(); } catch (WebException) { Console.WriteLine($"{username} failed"); } if (!canFire) { Console.WriteLine($"- Webhook refused for {username}"); return; } Console.WriteLine($"+ Webhook fired for {username}"); var msg = new JObject { { "content", $"Test from {username}" }, { "username", "TCC" }, { "avatar_url", "http://i.imgur.com/8IltuVz.png" } }; using (var client = MiscUtils.GetDefaultWebClient()) { client.Encoding = Encoding.UTF8; client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); client.UploadString(wh, "POST", msg.ToString()); } } }
private static async Task <JObject> BuildJsonDump(Exception ex) { return(new JObject { { "tcc_version", new JValue(App.AppVersion) }, { "id", new JValue(SessionManager.CurrentAccountName != null ? HashUtils.GenerateHash(SessionManager.CurrentAccountName) : "") }, { "tcc_hash", HashUtils.GenerateFileHash(typeof(App).Assembly.Location) }, { "exception", new JValue(ex.Message) }, { "exception_type", new JValue(ex.GetType().FullName) }, { "exception_source", new JValue(ex.Source) }, { "stack_trace", new JValue(ex.StackTrace) }, { "full_exception", new JValue(FormatFullException(ex)) }, { "thread_traces", await GetThreadTraces() }, { "inner_exception", ex.InnerException != null?BuildInnerExceptionJObject(ex.InnerException) : null }, { "game_version", new JValue(PacketAnalyzer.Factory == null ? 0 : PacketAnalyzer.Factory.ReleaseVersion) }, { "region", new JValue(SessionManager.Server != null ? SessionManager.Server.Region : "") }, { "server_id", new JValue(SessionManager.Server != null ? SessionManager.Server.ServerId.ToString() : "") }, { "settings_summary", new JObject { { "windows", new JObject { { "cooldown", SettingsHolder.CooldownWindowSettings.Enabled }, { "buffs", SettingsHolder.BuffWindowSettings.Enabled }, { "character", SettingsHolder.CharacterWindowSettings.Enabled }, { "class", SettingsHolder.ClassWindowSettings.Enabled }, { "chat", SettingsHolder.ChatEnabled }, { "group", SettingsHolder.GroupWindowSettings.Enabled } } }, { "generic", new JObject { { "proxy_enabled", SettingsHolder.EnableProxy }, } } } }, { "stats", new JObject { { "os", $"{Environment.OSVersion} {Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion")?.GetValue("ProductName")}" }, { "current_USER_objects", GetUSERObjectsCount() }, { "used_memory", Process.GetCurrentProcess().PrivateMemorySize64 }, { "uptime", DateTime.Now - Process.GetCurrentProcess().StartTime }, } } }); }
//Person Management /// <summary> /// Fügt, falls alle Werte korrekt, eine neue Person hinzu /// </summary> private async void buttonAdd_Click(object sender, EventArgs e) { string vorname, name, email, passwort; double gehalt; DateTime geburtsdatum; Position position; vorname = textBoxName.Text; if (string.IsNullOrWhiteSpace(vorname)) { MessageBox.Show("Bitte das Feld \"Name\" ausfüllen!", "Fehlende Angabe", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } name = textBoxVorName.Text; if (string.IsNullOrWhiteSpace(name)) { MessageBox.Show("Bitte das Feld \"Vorname\" ausfüllen!", "Fehlende Angabe", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } email = textBoxEmail.Text; if (string.IsNullOrWhiteSpace(email)) { MessageBox.Show("Bitte das Feld \"Email\" ausfüllen!", "Fehlende Angabe", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } passwort = textBoxPasswort.Text; if (string.IsNullOrWhiteSpace(passwort)) { MessageBox.Show("Bitte das Feld \"Passwort\" ausfüllen!", "Fehlende Angabe", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!double.TryParse(textBoxGehalt.Text, out gehalt)) { MessageBox.Show("Bitte das Feld \"Gehalt\" korrekt ausfüllen!", "Fehlerhafte Angabe", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!DateTime.TryParse(textBoxGeburtsdatum.Text, out geburtsdatum)) { MessageBox.Show("Bitte das Feld \"Geburtsdatum\" korrekt ausfüllen!", "Fehlerhafte Angabe", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (comboBoxPosition.SelectedItem == null) { MessageBox.Show($"Bitte eine der {Enum.GetValues(typeof(Position)).Length} möglichen Positionen auswählen!", "Fehlerhafte Angabe", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } position = (Position)comboBoxPosition.SelectedItem; if (StorageContainer.Get <Person>().Values.Any(person => person.Name == vorname && person.Vorname == name)) { MessageBox.Show("Eine Person mit diesem Namen existiert bereits!", "Halt Stop!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } StorageContainer.Get <Person>().Add(new Person(vorname, name, position, geburtsdatum, email, HashUtils.GenerateHash(passwort), gehalt)); await SavePersons(); RenewZeitausgabeComboBoxMitarbeiter(); MessageBox.Show("Person hinzugefügt!", "Erfolgreich", MessageBoxButtons.OK, MessageBoxIcon.Information); }