Browse Source

Minor DateTime changes

tags/docs-0.9
RogueException 9 years ago
parent
commit
05991f4c4b
7 changed files with 13 additions and 12 deletions
  1. +1
    -1
      src/Discord.Net/API/Presence.cs
  2. +1
    -1
      src/Discord.Net/API/Voice.cs
  3. +1
    -1
      src/Discord.Net/API/WebSockets.cs
  4. +1
    -1
      src/Discord.Net/DiscordClient.Users.cs
  5. +3
    -2
      src/Discord.Net/Helpers/EpochTime.cs
  6. +1
    -1
      src/Discord.Net/Net/WebSockets/DataWebSocket.cs
  7. +5
    -5
      src/Discord.Net/Net/WebSockets/VoiceWebSocket.cs

+ 1
- 1
src/Discord.Net/API/Presence.cs 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;
} }


+ 1
- 1
src/Discord.Net/API/Voice.cs 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()) { }
} }


+ 1
- 1
src/Discord.Net/API/WebSockets.cs 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()) { }
} }


+ 1
- 1
src/Discord.Net/DiscordClient.Users.cs 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;
} }
} }

+ 3
- 2
src/Discord.Net/Helpers/EpochTime.cs 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);
public static ulong GetMilliseconds() => (ulong)(DateTime.UtcNow - epoch).TotalMilliseconds;
private const long epoch = 621355968000000000L; //1/1/1970 in Ticks

public static long GetMilliseconds() => (DateTime.UtcNow.Ticks - epoch) / TimeSpan.TicksPerMillisecond;
} }
} }

+ 1
- 1
src/Discord.Net/Net/WebSockets/DataWebSocket.cs 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;


+ 5
- 5
src/Discord.Net/Net/WebSockets/VoiceWebSocket.cs 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();
var payload = (ulong)(long)msg.Payload;
_ping = payload - time;
long time = EpochTime.GetMilliseconds();
var payload = (long)msg.Payload;
_ping = (int)(payload - time);
//TODO: Use this to estimate latency //TODO: Use this to estimate latency
} }
break; break;


Loading…
Cancel
Save