Archived
1
0
Fork 0

Don't recreate/alter strings that never change.

This commit is contained in:
flash 2017-11-13 12:57:28 +01:00
parent 2620ce3765
commit bf61e6f6d8
2 changed files with 15 additions and 12 deletions

View file

@ -295,13 +295,7 @@ namespace Maki
if (gi.Shards.HasValue)
shards = gi.Shards.Value;
}
if (Gateway.Contains("?"))
Gateway = Gateway.Substring(0, Gateway.IndexOf('?'));
if (!Gateway.EndsWith("/"))
Gateway += "/";
for (int i = 0; i < shards; i++)
ShardClient.Create(i);
}

View file

@ -10,6 +10,10 @@ namespace Maki.Gateway
/// </summary>
class GatewayShard : IDisposable
{
private const string GATEWAY_URL = "{0}?v={1}&encoding=json";
private readonly string GatewayUrl;
/// <summary>
/// Session key for continuing a resuming after disconnecting
/// </summary>
@ -54,13 +58,18 @@ namespace Maki.Gateway
/// Constructor
/// </summary>
/// <param name="id">Shard Id</param>
/// <param name="c">Parent DiscordClient instance</param>
public GatewayShard(int id, Discord c)
/// <param name="client">Parent DiscordClient instance</param>
/// <param name="connect">Whether to immediately call Connect()</param>
public GatewayShard(int id, Discord client, bool connect = true)
{
Id = id;
Client = c;
Client = client;
HeartbeatHandler = new GatewayHeartbeatManager(this);
Connect();
GatewayUrl = string.Format(GATEWAY_URL, Client.Gateway, Discord.GATEWAY_VERSION);
if (connect)
Connect();
}
/// <summary>
@ -165,7 +174,7 @@ namespace Maki.Gateway
/// </summary>
public void Connect()
{
WebSocket = new WebSocket($"{Client.Gateway}?v={Discord.GATEWAY_VERSION}&encoding=json");
WebSocket = new WebSocket(GatewayUrl);
// make wss not log anything on its own
WebSocket.Log.Output = (LogData logData, string path) => { };