First commit

This commit is contained in:
EnderIce2
2020-10-25 16:19:43 +02:00
parent 9d78d84acb
commit b91db81473
73 changed files with 7634 additions and 0 deletions

View File

@ -0,0 +1,26 @@
namespace DiscordRPC.Message
{
/// <summary>
/// Called when the IPC has closed.
/// </summary>
public class CloseMessage : IMessage
{
/// <summary>
/// The type of message
/// </summary>
public override MessageType Type { get { return MessageType.Close; } }
/// <summary>
/// The reason for the close
/// </summary>
public string Reason { get; internal set; }
/// <summary>
/// The closure code
/// </summary>
public int Code { get; internal set; }
internal CloseMessage() { }
internal CloseMessage(string reason) { this.Reason = reason; }
}
}

View File

@ -0,0 +1,24 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DiscordRPC.Message
{
/// <summary>
/// The connection to the discord client was succesfull. This is called before <see cref="MessageType.Ready"/>.
/// </summary>
public class ConnectionEstablishedMessage : IMessage
{
/// <summary>
/// The type of message received from discord
/// </summary>
public override MessageType Type { get { return MessageType.ConnectionEstablished; } }
/// <summary>
/// The pipe we ended up connecting too
/// </summary>
public int ConnectedPipe { get; internal set; }
}
}

View File

@ -0,0 +1,24 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DiscordRPC.Message
{
/// <summary>
/// Failed to establish any connection with discord. Discord is potentially not running?
/// </summary>
public class ConnectionFailedMessage : IMessage
{
/// <summary>
/// The type of message received from discord
/// </summary>
public override MessageType Type { get { return MessageType.ConnectionFailed; } }
/// <summary>
/// The pipe we failed to connect too.
/// </summary>
public int FailedPipe { get; internal set; }
}
}

View File

@ -0,0 +1,76 @@
using Newtonsoft.Json;
namespace DiscordRPC.Message
{
/// <summary>
/// Created when a error occurs within the ipc and it is sent to the client.
/// </summary>
public class ErrorMessage : IMessage
{
/// <summary>
/// The type of message received from discord
/// </summary>
public override MessageType Type { get { return MessageType.Error; } }
/// <summary>
/// The Discord error code.
/// </summary>
[JsonProperty("code")]
public ErrorCode Code { get; internal set; }
/// <summary>
/// The message associated with the error code.
/// </summary>
[JsonProperty("message")]
public string Message { get; internal set; }
}
/// <summary>
/// The error message received by discord. See https://discordapp.com/developers/docs/topics/rpc#rpc-server-payloads-rpc-errors for documentation
/// </summary>
public enum ErrorCode
{
//Pipe Error Codes
/// <summary> Pipe was Successful </summary>
Success = 0,
///<summary>The pipe had an exception</summary>
PipeException = 1,
///<summary>The pipe received corrupted data</summary>
ReadCorrupt = 2,
//Custom Error Code
///<summary>The functionality was not yet implemented</summary>
NotImplemented = 10,
//Discord RPC error codes
///<summary>Unkown Discord error</summary>
UnkownError = 1000,
///<summary>Invalid Payload received</summary>
InvalidPayload = 4000,
///<summary>Invalid command was sent</summary>
InvalidCommand = 4002,
/// <summary>Invalid event was sent </summary>
InvalidEvent = 4004,
/*
InvalidGuild = 4003,
InvalidChannel = 4005,
InvalidPermissions = 4006,
InvalidClientID = 4007,
InvalidOrigin = 4008,
InvalidToken = 4009,
InvalidUser = 4010,
OAuth2Error = 5000,
SelectChannelTimeout = 5001,
GetGuildTimeout = 5002,
SelectVoiceForceRequired = 5003,
CaptureShortcutAlreadyListening = 5004
*/
}
}

View File

@ -0,0 +1,29 @@
using System;
namespace DiscordRPC.Message
{
/// <summary>
/// Messages received from discord.
/// </summary>
public abstract class IMessage
{
/// <summary>
/// The type of message received from discord
/// </summary>
public abstract MessageType Type { get; }
/// <summary>
/// The time the message was created
/// </summary>
public DateTime TimeCreated { get { return _timecreated; } }
private DateTime _timecreated;
/// <summary>
/// Creates a new instance of the message
/// </summary>
public IMessage()
{
_timecreated = DateTime.Now;
}
}
}

View File

@ -0,0 +1,25 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DiscordRPC.Message
{
/// <summary>
/// Called when the Discord Client wishes for this process to join a game. D -> C.
/// </summary>
public class JoinMessage : IMessage
{
/// <summary>
/// The type of message received from discord
/// </summary>
public override MessageType Type { get { return MessageType.Join; } }
/// <summary>
/// The <see cref="Secrets.JoinSecret" /> to connect with.
/// </summary>
[JsonProperty("secret")]
public string Secret { get; internal set; }
}
}

View File

@ -0,0 +1,25 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DiscordRPC.Message
{
/// <summary>
/// Called when some other person has requested access to this game. C -> D -> C.
/// </summary>
public class JoinRequestMessage : IMessage
{
/// <summary>
/// The type of message received from discord
/// </summary>
public override MessageType Type { get { return MessageType.JoinRequest; } }
/// <summary>
/// The discord user that is requesting access.
/// </summary>
[JsonProperty("user")]
public User User { get; internal set; }
}
}

View File

@ -0,0 +1,64 @@

namespace DiscordRPC.Message
{
/// <summary>
/// Type of message.
/// </summary>
public enum MessageType
{
/// <summary>
/// The Discord Client is ready to send and receive messages.
/// </summary>
Ready,
/// <summary>
/// The connection to the Discord Client is lost. The connection will remain close and unready to accept messages until the Ready event is called again.
/// </summary>
Close,
/// <summary>
/// A error has occured during the transmission of a message. For example, if a bad Rich Presence payload is sent, this event will be called explaining what went wrong.
/// </summary>
Error,
/// <summary>
/// The Discord Client has updated the presence.
/// </summary>
PresenceUpdate,
/// <summary>
/// The Discord Client has subscribed to an event.
/// </summary>
Subscribe,
/// <summary>
/// The Discord Client has unsubscribed from an event.
/// </summary>
Unsubscribe,
/// <summary>
/// The Discord Client wishes for this process to join a game.
/// </summary>
Join,
/// <summary>
/// The Discord Client wishes for this process to spectate a game.
/// </summary>
Spectate,
/// <summary>
/// Another discord user requests permission to join this game.
/// </summary>
JoinRequest,
/// <summary>
/// The connection to the discord client was succesfull. This is called before <see cref="Ready"/>.
/// </summary>
ConnectionEstablished,
/// <summary>
/// Failed to establish any connection with discord. Discord is potentially not running?
/// </summary>
ConnectionFailed
}
}

View File

@ -0,0 +1,47 @@

namespace DiscordRPC.Message
{
/// <summary>
/// Representation of the message received by discord when the presence has been updated.
/// </summary>
public class PresenceMessage : IMessage
{
/// <summary>
/// The type of message received from discord
/// </summary>
public override MessageType Type { get { return MessageType.PresenceUpdate; } }
internal PresenceMessage() : this(null) { }
internal PresenceMessage(RichPresenceResponse rpr)
{
if (rpr == null)
{
Presence = null;
Name = "No Rich Presence";
ApplicationID = "";
}
else
{
Presence = (RichPresence)rpr;
Name = rpr.Name;
ApplicationID = rpr.ClientID;
}
}
/// <summary>
/// The rich presence Discord has set
/// </summary>
public RichPresence Presence { get; internal set; }
/// <summary>
/// The name of the application Discord has set it for
/// </summary>
public string Name { get; internal set; }
/// <summary>
/// The ID of the application discord has set it for
/// </summary>
public string ApplicationID { get; internal set; }
}
}

View File

@ -0,0 +1,35 @@

using Newtonsoft.Json;
namespace DiscordRPC.Message
{
/// <summary>
/// Called when the ipc is ready to send arguments.
/// </summary>
public class ReadyMessage : IMessage
{
/// <summary>
/// The type of message received from discord
/// </summary>
public override MessageType Type { get { return MessageType.Ready; } }
/// <summary>
/// The configuration of the connection
/// </summary>
[JsonProperty("config")]
public Configuration Configuration { get; set; }
/// <summary>
/// User the connection belongs too
/// </summary>
[JsonProperty("user")]
public User User { get; set; }
/// <summary>
/// The version of the RPC
/// </summary>
[JsonProperty("v")]
public int Version { get; set; }
}
}

View File

@ -0,0 +1,19 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DiscordRPC.Message
{
/// <summary>
/// Called when the Discord Client wishes for this process to spectate a game. D -> C.
/// </summary>
public class SpectateMessage : JoinMessage
{
/// <summary>
/// The type of message received from discord
/// </summary>
public override MessageType Type { get { return MessageType.Spectate; } }
}
}

View File

@ -0,0 +1,40 @@
using DiscordRPC.RPC.Payload;
namespace DiscordRPC.Message
{
/// <summary>
/// Called as validation of a subscribe
/// </summary>
public class SubscribeMessage : IMessage
{
/// <summary>
/// The type of message received from discord
/// </summary>
public override MessageType Type { get { return MessageType.Subscribe; } }
/// <summary>
/// The event that was subscribed too.
/// </summary>
public EventType Event { get; internal set; }
internal SubscribeMessage(ServerEvent evt)
{
switch (evt)
{
default:
case ServerEvent.ActivityJoin:
Event = EventType.Join;
break;
case ServerEvent.ActivityJoinRequest:
Event = EventType.JoinRequest;
break;
case ServerEvent.ActivitySpectate:
Event = EventType.Spectate;
break;
}
}
}
}

View File

@ -0,0 +1,39 @@
using DiscordRPC.RPC.Payload;
namespace DiscordRPC.Message
{
/// <summary>
/// Called as validation of a subscribe
/// </summary>
public class UnsubscribeMessage : IMessage
{
/// <summary>
/// The type of message received from discord
/// </summary>
public override MessageType Type { get { return MessageType.Unsubscribe; } }
/// <summary>
/// The event that was subscribed too.
/// </summary>
public EventType Event { get; internal set; }
internal UnsubscribeMessage(ServerEvent evt)
{
switch (evt)
{
default:
case ServerEvent.ActivityJoin:
Event = EventType.Join;
break;
case ServerEvent.ActivityJoinRequest:
Event = EventType.JoinRequest;
break;
case ServerEvent.ActivitySpectate:
Event = EventType.Spectate;
break;
}
}
}
}