Minor DateTime changes

This commit is contained in:
RogueException
2015-11-23 22:24:49 -04:00
parent c910523788
commit 05991f4c4b
7 changed files with 13 additions and 12 deletions

View File

@@ -14,7 +14,7 @@ namespace Discord.API
public class Data public class Data
{ {
[JsonProperty("idle_since")] [JsonProperty("idle_since")]
public ulong? IdleSince; public long? IdleSince;
[JsonProperty("game_id")] [JsonProperty("game_id")]
public int? GameId; public int? GameId;
} }

View File

@@ -92,7 +92,7 @@ namespace Discord.API
public SocketInfo SocketData = new SocketInfo(); public SocketInfo SocketData = new SocketInfo();
} }
} }
internal sealed class VoiceKeepAliveCommand : WebSocketMessage<ulong> internal sealed class VoiceKeepAliveCommand : WebSocketMessage<long>
{ {
public VoiceKeepAliveCommand() : base(3, EpochTime.GetMilliseconds()) { } public VoiceKeepAliveCommand() : base(3, EpochTime.GetMilliseconds()) { }
} }

View File

@@ -41,7 +41,7 @@ namespace Discord.API
} }
//Commands //Commands
internal sealed class KeepAliveCommand : WebSocketMessage<ulong> internal sealed class KeepAliveCommand : WebSocketMessage<long>
{ {
public KeepAliveCommand() : base(1, EpochTime.GetMilliseconds()) { } public KeepAliveCommand() : base(1, EpochTime.GetMilliseconds()) { }
} }

View File

@@ -297,7 +297,7 @@ namespace Discord
} }
private Task SendStatus() private Task SendStatus()
{ {
_dataSocket.SendStatus(_status == UserStatus.Idle ? EpochTime.GetMilliseconds() - (10 * 60 * 1000) : (ulong?)null, _gameId); _dataSocket.SendStatus(_status == UserStatus.Idle ? EpochTime.GetMilliseconds() - (10 * 60 * 1000) : (long?)null, _gameId);
return TaskHelper.CompletedTask; return TaskHelper.CompletedTask;
} }
} }

View File

@@ -4,7 +4,8 @@ namespace Discord
{ {
internal class EpochTime internal class EpochTime
{ {
private static readonly DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); private const long epoch = 621355968000000000L; //1/1/1970 in Ticks
public static ulong GetMilliseconds() => (ulong)(DateTime.UtcNow - epoch).TotalMilliseconds;
public static long GetMilliseconds() => (DateTime.UtcNow.Ticks - epoch) / TimeSpan.TicksPerMillisecond;
} }
} }

View File

@@ -120,7 +120,7 @@ namespace Discord.Net.WebSockets
return new KeepAliveCommand(); return new KeepAliveCommand();
} }
public void SendStatus(ulong? idleSince, int? gameId) public void SendStatus(long? idleSince, int? gameId)
{ {
var updateStatus = new UpdateStatusCommand(); var updateStatus = new UpdateStatusCommand();
updateStatus.Payload.IdleSince = idleSince; updateStatus.Payload.IdleSince = idleSince;

View File

@@ -36,14 +36,14 @@ namespace Discord.Net.WebSockets
private ushort _sequence; private ushort _sequence;
private long? _serverId, _channelId, _userId; private long? _serverId, _channelId, _userId;
private string _sessionId, _token, _encryptionMode; private string _sessionId, _token, _encryptionMode;
private ulong _ping; private int _ping;
private Thread _sendThread, _receiveThread; private Thread _sendThread, _receiveThread;
public long? CurrentServerId => _serverId; public long? CurrentServerId => _serverId;
public long? CurrentChannelId => _channelId; public long? CurrentChannelId => _channelId;
public VoiceBuffer OutputBuffer => _sendBuffer; public VoiceBuffer OutputBuffer => _sendBuffer;
public int Ping => (int)_ping; public int Ping => _ping;
public VoiceWebSocket(DiscordWSClient client) public VoiceWebSocket(DiscordWSClient client)
: base(client) : base(client)
@@ -471,9 +471,9 @@ namespace Discord.Net.WebSockets
break; break;
case 3: //PONG case 3: //PONG
{ {
ulong time = EpochTime.GetMilliseconds(); long time = EpochTime.GetMilliseconds();
var payload = (ulong)(long)msg.Payload; var payload = (long)msg.Payload;
_ping = payload - time; _ping = (int)(payload - time);
//TODO: Use this to estimate latency //TODO: Use this to estimate latency
} }
break; break;