public static WebRequest PrepareRequest(RichPresence presence, string applicationID, int port = 6463) { //Validate the presence if (presence != null) { //Send valid presence //Validate the presence with our settings if (presence.HasSecrets()) { throw new BadPresenceException("Cannot send a presence with secrets as HTTP endpoint does not suppport events."); } if (presence.HasParty() && presence.Party.Max < presence.Party.Size) { throw new BadPresenceException("Presence maximum party size cannot be smaller than the current size."); } } //Prepare some params int pid = System.Diagnostics.Process.GetCurrentProcess().Id; //Prepare the payload PresenceCommand command = new PresenceCommand() { PID = pid, Presence = presence }; var payload = command.PreparePayload(DateTime.UtcNow.ToFileTime()); string json = JsonConvert.SerializeObject(payload); string url = "http://127.0.0.1:" + port + "/rpc?v=" + RpcConnection.VERSION + "&client_id=" + applicationID; return(new WebRequest(url, json)); }
public static WebRequest PrepareRequest( RichPresence presence, string applicationID, int port = 6463) { if (presence != null) { if (presence.HasSecrets()) { throw new BadPresenceException("Cannot send a presence with secrets as HTTP endpoint does not suppport events."); } if (presence.HasParty() && presence.Party.Max < presence.Party.Size) { throw new BadPresenceException("Presence maximum party size cannot be smaller than the current size."); } } int id = Process.GetCurrentProcess().Id; string json = JsonConvert.SerializeObject((object)new PresenceCommand() { PID = id, Presence = presence }.PreparePayload(DateTime.UtcNow.ToFileTime())); return(new WebRequest("http://127.0.0.1:" + (object)port + "/rpc?v=" + (object)RpcConnection.VERSION + "&client_id=" + applicationID, json)); }
private void setPresence(string serverName, string word1, string word2, string word3, int playerCount, string zone) { presence.Details = "Area Server: " + serverName; presence.State = "Not currently in an area."; //Only checking the first word. If this isn't set then it's save to assume that we weren't in a zone //Used to display the area words however since adding the party count's they end up not showing because the world list was too long. if (word1 != "") { presence.State = "Currently in field."; // "Area: " + word1 + " " + word2 + " " + word3; } presence.Assets = new Assets(); presence.Assets.LargeImageKey = zone; presence.Assets.SmallImageKey = zone; presence.Party = new Party() { ID = new Guid().ToString(), Size = playerCount, Max = 3, Privacy = Party.PrivacySetting.Private }; presence.HasParty(); client.SetPresence(presence); }
public static bool TrySetRichPresence(RichPresence presence, out RichPresence response, string applicationID, int port = 6463) { //Validate the presence if (presence != null) { //Send valid presence //Validate the presence with our settings if (presence.HasSecrets()) { throw new BadPresenceException("Cannot send a presence with secrets as HTTP endpoint does not suppport events."); } if (presence.HasParty() && presence.Party.Max < presence.Party.Size) { throw new BadPresenceException("Presence maximum party size cannot be smaller than the current size."); } } //Iterate over the ports until the first succesfull one for (int p = port; p < 6472; p++) { //Prepare the url and json using (WebClient client = new WebClient()) { try { WebRequest request = PrepareRequest(presence, applicationID, p); client.Headers.Add("content-type", "application/json"); var result = client.UploadString(request.URL, request.Data); if (TryParseResponse(result, out response)) { return(true); } } catch (Exception) { //Something went wrong, but we are just going to ignore it and try the next port. } } } //we failed, return null response = null; return(false); }
public static bool TrySetRichPresence( RichPresence presence, out RichPresence response, string applicationID, int port = 6463) { if (presence != null) { if (presence.HasSecrets()) { throw new BadPresenceException("Cannot send a presence with secrets as HTTP endpoint does not suppport events."); } if (presence.HasParty() && presence.Party.Max < presence.Party.Size) { throw new BadPresenceException("Presence maximum party size cannot be smaller than the current size."); } } for (int port1 = port; port1 < 6472; ++port1) { using (WebClient webClient = new WebClient()) { try { WebRequest webRequest = WebRPC.PrepareRequest(presence, applicationID, port1); webClient.Headers.Add("content-type", "application/json"); if (WebRPC.TryParseResponse(webClient.UploadString(webRequest.URL, webRequest.Data), out response)) { return(true); } } catch (Exception ex) { } } } response = (RichPresence)null; return(false); }