Archived
1
0
Fork 0

Shard cleanup part 1

This commit is contained in:
flash 2017-11-13 11:38:12 +01:00
parent b39def528d
commit 75e7e29b0a

View file

@ -23,13 +23,8 @@ namespace Maki.Gateway
/// <summary>
/// Websocket container
/// </summary>
private WebSocket webSocket;
/// <summary>
/// Active gateway version
/// </summary>
private int gatewayVersion = Discord.GATEWAY_VERSION;
private WebSocket WebSocket;
/// <summary>
/// Interval at which heartbeats are sent
/// </summary>
@ -167,7 +162,7 @@ namespace Maki.Gateway
if (!e.IsText)
return;
//Console.WriteLine(e.Data.Replace(client.Token, new string('*', client.Token.Length)));
Console.WriteLine(e.Data.Replace(client.Token, new string('*', client.Token.Length)));
OnSocketMessage?.Invoke(this, e.Data);
GatewayPayload payload = JsonConvert.DeserializeObject<GatewayPayload>(e.Data);
@ -352,7 +347,6 @@ namespace Maki.Gateway
#region State
case GatewayEvent.READY:
GatewayReady ready = payload.DataAs<GatewayReady>();
gatewayVersion = ready.Version;
session = ready.Session;
OnReady?.Invoke(this, ready);
break;
@ -393,11 +387,11 @@ namespace Maki.Gateway
Token = client.Token,
Compress = false,
LargeThreshold = 250,
Shard = new int[2] { Id, client.ShardClient.ShardCount },
Shard = new int[] { Id, client.ShardClient.ShardCount },
Properties = new GatewayIdentificationProperties {
OperatingSystem = @"windows",
Browser = @"Maki",
Device = @"Maki",
OperatingSystem = "windows",
Browser = "Maki",
Device = "Maki",
Referrer = string.Empty,
ReferringDomain = string.Empty,
}
@ -441,17 +435,17 @@ namespace Maki.Gateway
/// </summary>
public void Connect()
{
webSocket = new WebSocket($"{client.Gateway}?v={gatewayVersion}&encoding=json");
WebSocket = new WebSocket($"{client.Gateway}?v={Discord.GATEWAY_VERSION}&encoding=json");
// make wss not log anything on its own
webSocket.Log.Output = (LogData logData, string path) => { };
WebSocket.Log.Output = (LogData logData, string path) => { };
webSocket.OnOpen += WebSocket_OnOpen;
webSocket.OnClose += WebSocket_OnClose;
webSocket.OnError += WebSocket_OnError;
webSocket.OnMessage += WebSocket_OnMessage;
WebSocket.OnOpen += WebSocket_OnOpen;
WebSocket.OnClose += WebSocket_OnClose;
WebSocket.OnError += WebSocket_OnError;
WebSocket.OnMessage += WebSocket_OnMessage;
webSocket.Connect();
WebSocket.Connect();
}
/// <summary>
@ -461,8 +455,8 @@ namespace Maki.Gateway
{
heartbeatHandler.Stop();
if (webSocket.ReadyState != WebSocketState.Closed)
webSocket?.Close(CloseStatusCode.Normal);
if (WebSocket.ReadyState != WebSocketState.Closed)
WebSocket?.Close(CloseStatusCode.Normal);
}
/// <summary>
@ -472,20 +466,11 @@ namespace Maki.Gateway
/// <param name="data">Data to serialise and send</param>
public void Send<T>(T data)
{
/*Console.WriteLine(
JsonConvert.SerializeObject(
data,
typeof(T),
new JsonSerializerSettings()
).Replace(client.Token, new string('*', client.Token.Length)));*/
string json = JsonConvert.SerializeObject(data, typeof(T), new JsonSerializerSettings());
webSocket.Send(
JsonConvert.SerializeObject(
data,
typeof(T),
new JsonSerializerSettings()
)
);
Console.WriteLine(json.Replace(client.Token, new string('*', client.Token.Length)));
WebSocket.Send(json);
}
/// <summary>