Browse Source

Added RpcToken param

tags/1.0-rc
RogueException 8 years ago
parent
commit
e4569f1a39
2 changed files with 12 additions and 5 deletions
  1. +10
    -5
      src/Discord.Net/API/DiscordRpcAPIClient.cs
  2. +2
    -0
      src/Discord.Net/API/Rpc/AuthorizeParams.cs

+ 10
- 5
src/Discord.Net/API/DiscordRpcAPIClient.cs View File

@@ -148,13 +148,15 @@ namespace Discord.API
_webSocketClient.SetCancelToken(_connectCancelToken.Token); _webSocketClient.SetCancelToken(_connectCancelToken.Token);


bool success = false; bool success = false;
for (int port = DiscordRpcConfig.PortRangeStart; port <= DiscordRpcConfig.PortRangeEnd; port++)
int port;
string uuid = Guid.NewGuid().ToString();

for ( port = DiscordRpcConfig.PortRangeStart; port <= DiscordRpcConfig.PortRangeEnd; port++)
{ {
try try
{ {
string url = $"wss://discordapp.io:{port}/?v={DiscordRpcConfig.RpcAPIVersion}&client_id={_clientId}";
string url = $"wss://{uuid}.discordapp.io:{port}/?v={DiscordRpcConfig.RpcAPIVersion}&client_id={_clientId}";
await _webSocketClient.ConnectAsync(url).ConfigureAwait(false); await _webSocketClient.ConnectAsync(url).ConfigureAwait(false);
SetBaseUrl($"https://discordapp.io:{port}/");
success = true; success = true;
break; break;
} }
@@ -162,9 +164,11 @@ namespace Discord.API
{ {
} }
} }

if (!success) if (!success)
throw new Exception("Unable to connect to the RPC server."); throw new Exception("Unable to connect to the RPC server.");


SetBaseUrl($"https://{uuid}.discordapp.io:{port}/");
ConnectionState = ConnectionState.Connected; ConnectionState = ConnectionState.Connected;
} }
catch (Exception) catch (Exception)
@@ -238,12 +242,13 @@ namespace Discord.API
}; };
return await SendRpcAsync<AuthenticateResponse>("AUTHENTICATE", msg, options: options).ConfigureAwait(false); return await SendRpcAsync<AuthenticateResponse>("AUTHENTICATE", msg, options: options).ConfigureAwait(false);
} }
public async Task<AuthorizeResponse> SendAuthorizeAsync(string[] scopes, RequestOptions options = null)
public async Task<AuthorizeResponse> SendAuthorizeAsync(string[] scopes, string rpcToken = null, RequestOptions options = null)
{ {
var msg = new AuthorizeParams() var msg = new AuthorizeParams()
{ {
ClientId = _clientId, ClientId = _clientId,
Scopes = scopes
Scopes = scopes,
RpcToken = rpcToken != null ? rpcToken : Optional.Create<string>()
}; };
if (options == null) if (options == null)
options = new RequestOptions(); options = new RequestOptions();


+ 2
- 0
src/Discord.Net/API/Rpc/AuthorizeParams.cs View File

@@ -8,5 +8,7 @@ namespace Discord.API.Rpc
public string ClientId { get; set; } public string ClientId { get; set; }
[JsonProperty("scopes")] [JsonProperty("scopes")]
public string[] Scopes { get; set; } public string[] Scopes { get; set; }
[JsonProperty("rpc_token")]
public Optional<string> RpcToken { get; set; }
} }
} }

Loading…
Cancel
Save