Пример #1
0
        static void Main(string[] args)
        {
            client = new DiscordRpcClient("711984686108508171");

            client.OnReady += (sender, e) =>
            {
                Console.WriteLine("Received Ready from user {0}", e.User.Username);
            };

            client.OnPresenceUpdate += (sender, e) =>
            {
                Console.WriteLine("Received Update! {0}", e.Presence);
            };

            client.Initialize();

            Secrets secrets = new Secrets()
            {
                JoinSecret     = "MTI4NzM0OjFpMmhuZToxMjMxMjM= ",
                SpectateSecret = "MTIzNDV8MTIzNDV8MTMyNDU0"
            };

            Party party = new Party()
            {
                ID = Secrets.CreateFriendlySecret(new Random()),
                //ID = "ae488379-351d-4a4f-ad32-2b9b01c91657",
                Size = 1,
                Max  = 64
            };

            //Give the game some time so we have a nice countdown
            Timestamps timestamps = new Timestamps()
            {
                Start = DateTime.UtcNow
            };

            client.RegisterUriScheme("711984686108508171");

            client.SetSubscription(EventType.Join | EventType.Spectate | EventType.JoinRequest);

            client.SetPresence(new RichPresence()
            {
                Details = "sadRP",
                State   = "sadRP",
                Assets  = new Assets()
                {
                    LargeImageKey  = "sadRP",
                    LargeImageText = "Galaksinin En Kötüsü",
                    SmallImageKey  = "küçük resim id",
                    SmallImageText = "küçük resim mesajı"
                },
                Secrets    = secrets,
                Party      = party,
                Timestamps = timestamps
            });

            Console.ReadKey();
        }
Пример #2
0
 public static void SetPlayers(int players, int slots)
 {
     GetService()?.client.UpdateParty(new Party
     {
         ID   = Secrets.CreateFriendlySecret(new Random()),
         Size = players,
         Max  = slots
     });
 }
        static async void IssueJoinLogic()
        {
            // == Create the client
            var random = new Random();
            var client = new DiscordRpcClient("424087019149328395", pipe: 0)
            {
                Logger = new Logging.ConsoleLogger(Logging.LogLevel.Info, true)
            };

            // == Subscribe to some events
            client.OnReady          += (sender, msg) => { Console.WriteLine("Connected to discord with user {0}", msg.User.Username); };
            client.OnPresenceUpdate += (sender, msg) => { Console.WriteLine("Presence has been updated! "); };

            //Setup the join event
            client.Subscribe(EventType.Join | EventType.JoinRequest);
            client.RegisterUriScheme();

            //= Request Event
            client.OnJoinRequested += (sender, msg) =>
            {
                Console.WriteLine("Someone wants to join us: {0}", msg.User.Username);
            };

            //= Join Event
            client.OnJoin += (sender, msg) =>
            {
                Console.WriteLine("Joining this dude: {0}", msg.Secret);
            };

            // == Initialize
            client.Initialize();

            //Set the presence
            client.SetPresence(new RichPresence()
            {
                State   = "Potato Pitata",
                Details = "Testing Join Feature",
                Party   = new Party()
                {
                    ID      = Secrets.CreateFriendlySecret(random),
                    Size    = 1,
                    Max     = 4,
                    Privacy = Party.PrivacySetting.Public
                },
                Secrets = new Secrets()
                {
                    JoinSecret = Secrets.CreateFriendlySecret(random),
                }
            });

            // == At the very end we need to dispose of it
            Console.ReadKey();
            client.Dispose();
        }
Пример #4
0
 public static void SetPlayers(int players, int slots)
 {
     if (Service.Value != null)
     {
         Service.Value.client.UpdateParty(new Party
         {
             ID   = Secrets.CreateFriendlySecret(new Random()),
             Size = players,
             Max  = slots
         });
     }
 }
Пример #5
0
 public void Application_SlideShowNextSlide(SlideShowWindow Wn)
 {
     presence.Details = Wn.Presentation.Name;
     presence.State   = Shared.Shared.getString("presenting");
     presence.Assets.LargeImageKey = "present";
     presence.Party = new Party()
     {
         ID   = Secrets.CreateFriendlySecret(new Random()),
         Max  = Wn.Presentation.Slides.Count,
         Size = Wn.View.CurrentShowPosition
     };
     client.SetPresence(presence);
 }
Пример #6
0
        public static void SetPlayers(int players, int slots)
        {
            var service = GetService();

            if (service != null)
            {
                service.client.UpdateParty(new Party
                {
                    ID   = Secrets.CreateFriendlySecret(new Random()),
                    Size = players,
                    Max  = slots
                });
            }
        }
Пример #7
0
        void UpdateParty(int players, int slots)
        {
            if (client.CurrentPresence.Party != null)
            {
                client.UpdatePartySize(players, slots);
                return;
            }

            client.UpdateParty(new Party
            {
                ID   = Secrets.CreateFriendlySecret(new Random()),
                Size = players,
                Max  = slots
            });
        }
Пример #8
0
 private void Application_SlideSelectionChanged(SlideRange SldRange)
 {
     if (SldRange.Count > 0)
     {
         presence.Details = SldRange.Application.ActivePresentation.Name;
         presence.State   = Shared.Shared.getString("editing");
         presence.Assets.LargeImageKey = "editing";
         presence.Party = new Party()
         {
             ID   = Secrets.CreateFriendlySecret(new Random()),
             Max  = Application.ActivePresentation.Slides.Count,
             Size = SldRange[1].SlideNumber
         };
         client.SetPresence(presence);
     }
 }
Пример #9
0
        public void Application_WindowSelectionChange(Selection sel)
        {
            Range range = Application.ActiveDocument.Content;

            presence.Details = Application.ActiveDocument.Name;
            presence.State   = Shared.Shared.getString("editingPage");
            presence.Assets.LargeImageKey = "word_editing";
            presence.Party = new Party()
            {
                ID   = Secrets.CreateFriendlySecret(new Random()),
                Max  = range.ComputeStatistics(WdStatistic.wdStatisticPages),
                Size = (int)sel.get_Information(WdInformation.wdActiveEndPageNumber)
            };

            client.SetPresence(presence);
        }
 private void checkParty()
 {
     if (cbParty.Checked)
     {
         party = new Party()
         {
             ID      = Secrets.CreateFriendlySecret(new Random()),
             Size    = (int)partyCurrent.Value,
             Max     = (int)partyMax.Value,
             Privacy = Party.PrivacySetting.Public
         };
     }
     else
     {
         party = null;
     }
 }
Пример #11
0
        internal static void SetupRpc()
        {
            client = new DiscordRpcClient("652538071530864653");

            client.Initialize();

            Secrets secrets = new Secrets()
            {
                JoinSecret     = "MTI4NzM0OjFpMmhuZToxMjMxMjM",
                SpectateSecret = "MTIzNDV8MTIzNDV8MTMyNDU0"
            };

            Party party = new Party()
            {
                ID   = Secrets.CreateFriendlySecret(new Random()),
                Size = 1,
                Max  = 64
            };

            //Give the game some time so we have a nice countdown
            Timestamps timestamps = new Timestamps()
            {
                Start = DateTime.UtcNow
            };

            client.RegisterUriScheme("652538071530864653");

            client.SetSubscription(EventType.Join | EventType.Spectate | EventType.JoinRequest);

            client.SetPresence(new RichPresence()
            {
                Details = "Sunucuya Bağlanıyor.",
                State   = "Launcher Giriş Ekranında...",
                Assets  = new Assets()
                {
                    LargeImageKey  = "fadesx",
                    LargeImageText = "khchosting.com",
                    SmallImageKey  = "tikfade",
                    SmallImageText = "discord.gg/adonisrp"
                },
                Secrets    = secrets,
                Party      = party,
                Timestamps = timestamps
            });
        }
Пример #12
0
        void SetStatus(DiscordState state, string details = null, string secret = null, int?players = null, int?slots = null)
        {
            if (currentState == state)
            {
                return;
            }

            if (instance == null)
            {
                return;
            }

            string   stateText;
            DateTime?timestamp = null;
            Party    party     = null;
            Secrets  secrets   = null;

            switch (state)
            {
            case DiscordState.InMenu:
                stateText = "In menu";
                break;

            case DiscordState.InMapEditor:
                stateText = "In Map Editor";
                break;

            case DiscordState.InSkirmishLobby:
                stateText = "In Skirmish Lobby";
                break;

            case DiscordState.InMultiplayerLobby:
                stateText = "In Multiplayer Lobby";
                timestamp = DateTime.UtcNow;
                party     = new Party
                {
                    ID   = Secrets.CreateFriendlySecret(new Random()),
                    Size = players.Value,
                    Max  = slots.Value
                };
                secrets = new Secrets
                {
                    JoinSecret = secret
                };
                break;

            case DiscordState.PlayingMultiplayer:
                stateText = "Playing Multiplayer";
                timestamp = DateTime.UtcNow;
                break;

            case DiscordState.PlayingCampaign:
                stateText = "Playing Campaign";
                timestamp = DateTime.UtcNow;
                break;

            case DiscordState.WatchingReplay:
                stateText = "Watching Replay";
                timestamp = DateTime.UtcNow;
                break;

            case DiscordState.PlayingSkirmish:
                stateText = "Playing Skirmish";
                timestamp = DateTime.UtcNow;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(state), state, null);
            }

            var richPresence = new RichPresence
            {
                Details = details,
                State   = stateText,
                Assets  = new Assets
                {
                    LargeImageKey  = "large",
                    LargeImageText = Game.ModData.Manifest.Metadata.Title,
                },
                Timestamps = timestamp.HasValue ? new Timestamps(timestamp.Value) : null,
                Party      = party,
                Secrets    = secrets
            };

            client.SetPresence(richPresence);
            currentState = state;
        }
Пример #13
0
        public void Initialize(ISharpControl control)
        {
            IConfigurationPanelProvider configurationPanelProvider;

            if (Utils.GetBooleanSetting("ShowWelcomePage", true))
            {
                new WelcomeForm().ShowDialog();
            }

            _controlPanel  = new SettingsPanel();
            windowMessages = new TopWindowMessages(); // TODO: do something when "EnableRPCInvite" is set to false
            _control       = control;
            try
            {
                if (Utils.GetBooleanSetting("EnableRPCInvite", false))
                {
                    _control.RegisterFrontControl(windowMessages, PluginPosition.Top);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            if (Utils.GetBooleanSetting("EnableRPCInvite", false))
            {
                presence.Secrets = new Secrets()
                {
                    JoinSecret = "invalid_secret"
                };
                presence.Party = new Party()
                {
                    ID   = Secrets.CreateFriendlySecret(new Random()),
                    Size = 1,
                    Max  = 100
                };
            }

            if (Utils.GetBooleanSetting("EnableRPCInvite", false))
            {
                windowMessages.Show();
            }

            if (Utils.GetBooleanSetting("EnableRPC", true))
            {
                if (RPCalreadyLoaded)
                {
                    _controlPanel.ChangeStatus = "Restart required";
                    return;
                }
                if (Utils.GetStringSetting("ClientID").Replace(" ", "").Length != 18)
                {
                    client = new DiscordRpcClient("765213507321856078", pipe: discordPipe)
                    {
                        Logger = new ConsoleLogger(logLevel, true)
                    };
                }
                else
                {
                    client = new DiscordRpcClient(Utils.GetStringSetting("ClientID"), pipe: discordPipe)
                    {
                        Logger = new ConsoleLogger(logLevel, true)
                    };
                }

                client.RegisterUriScheme();
                client.OnRpcMessage            += Client_OnRpcMessage;
                client.OnPresenceUpdate        += Client_OnPresenceUpdate;
                client.OnReady                 += OnReady;
                client.OnClose                 += OnClose;
                client.OnError                 += OnError;
                client.OnConnectionEstablished += OnConnectionEstablished;
                client.OnConnectionFailed      += OnConnectionFailed;
                client.OnSubscribe             += OnSubscribe;
                client.OnUnsubscribe           += OnUnsubscribe;
                client.OnJoin          += OnJoin;
                client.OnJoinRequested += OnJoinRequested;
                presence.Timestamps     = new Timestamps()
                {
                    Start = DateTime.UtcNow
                };

                if (Utils.GetBooleanSetting("EnableRPCInvite", false))
                {
                    client.SetSubscription(EventType.Join | EventType.JoinRequest);
                }

                client.SetPresence(presence);
                client.Initialize();
                try
                {
                    configurationPanelProvider = (IConfigurationPanelProvider)_control.Source;
                    controllerPanel            = (SDRSharp.FrontEnds.SpyServer.ControllerPanel)configurationPanelProvider.Gui;
                }
                catch (Exception ex)
                {
                    LogWriter.WriteToFile("----> " + ex);
                    MessageBox.Show($"Cannot get Spy Server Network address\n\nError:\n{ex}", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                _ = MainLoop();
            }
            else
            {
                _controlPanel.ChangeStatus = "RPC is disabled";
            }
            LogWriter.WriteToFile("EOM Initialize");
        }
Пример #14
0
        static void FullClientExample()
        {
            //Create a new DiscordRpcClient. We are filling some of the defaults as examples.
            using (client = new DiscordRpcClient("424087019149328395",                              //The client ID of your Discord Application
                                                 pipe: discordPipe,                                 //The pipe number we can locate discord on. If -1, then we will scan.
                                                 logger: new Logging.ConsoleLogger(logLevel, true), //The loger to get information back from the client.
                                                 autoEvents: true,                                  //Should the events be automatically called?
                                                 client: new IO.ManagedNamedPipeClient()            //The pipe client to use. Required in mono to be changed.
                                                 ))
            {
                //If you are going to make use of the Join / Spectate buttons, you are required to register the URI Scheme with the client.
                client.RegisterUriScheme();

                //Set the logger. This way we can see the output of the client.
                //We can set it this way, but doing it directly in the constructor allows for the Register Uri Scheme to be logged too.
                //System.IO.File.WriteAllBytes("discord-rpc.log", new byte[0]);
                //client.Logger = new Logging.FileLogger("discord-rpc.log", DiscordLogLevel);

                //Register to the events we care about. We are registering to everyone just to show off the events

                client.OnReady += OnReady;                                      //Called when the client is ready to send presences
                client.OnClose += OnClose;                                      //Called when connection to discord is lost
                client.OnError += OnError;                                      //Called when discord has a error

                client.OnConnectionEstablished += OnConnectionEstablished;      //Called when a pipe connection is made, but not ready
                client.OnConnectionFailed      += OnConnectionFailed;           //Called when a pipe connection failed.

                client.OnPresenceUpdate += OnPresenceUpdate;                    //Called when the presence is updated

                client.OnSubscribe   += OnSubscribe;                            //Called when a event is subscribed too
                client.OnUnsubscribe += OnUnsubscribe;                          //Called when a event is unsubscribed from.

                client.OnJoin          += OnJoin;                               //Called when the client wishes to join someone else. Requires RegisterUriScheme to be called.
                client.OnSpectate      += OnSpectate;                           //Called when the client wishes to spectate someone else. Requires RegisterUriScheme to be called.
                client.OnJoinRequested += OnJoinRequested;                      //Called when someone else has requested to join this client.

                //Before we send a initial presence, we will generate a random "game ID" for this example.
                // For a real game, this "game ID" can be a unique ID that your Match Maker / Master Server generates.
                // This is used for the Join / Specate feature. This can be ignored if you do not plan to implement that feature.
                presence.Secrets = new Secrets()
                {
                    //These secrets should contain enough data for external clients to be able to know which
                    // game to connect too. A simple approach would be just to use IP address, but this is highly discouraged
                    // and can leave your players vulnerable!
                    JoinSecret     = "join_myuniquegameid",
                    SpectateSecret = "spectate_myuniquegameid"
                };

                //We also need to generate a initial party. This is because Join requires the party to be created too.
                // If no party is set, the join feature will not work and may cause errors within the discord client itself.
                presence.Party = new Party()
                {
                    ID   = Secrets.CreateFriendlySecret(new Random()),
                    Size = 1,
                    Max  = 4
                };

                //Give the game some time so we have a nice countdown
                presence.Timestamps = new Timestamps()
                {
                    Start = DateTime.UtcNow,
                    End   = DateTime.UtcNow + TimeSpan.FromSeconds(15)
                };

                //Subscribe to the join / spectate feature.
                //These require the RegisterURI to be true.
                client.SetSubscription(EventType.Join | EventType.Spectate | EventType.JoinRequest);        //This will alert us if discord wants to join a game

                //Set some new presence to tell Discord we are in a game.
                // If the connection is not yet available, this will be queued until a Ready event is called,
                // then it will be sent. All messages are queued until Discord is ready to receive them.
                client.SetPresence(presence);

                //Initialize the connection. This must be called ONLY once.
                //It must be called before any updates are sent or received from the discord client.
                client.Initialize();

                //Start our main loop. In a normal game you probably don't have to do this step.
                // Just make sure you call .Invoke() or some other dequeing event to receive your events.
                MainLoop();
            }
        }
Пример #15
0
        static void FullClientExample()
        {
            //Creates a new Discord RPC Client. Below are some of the ways to register:
            //using (DiscordRpcClient client = new DiscordRpcClient("424087019149328395", null, true, DiscordPipe, new IO.NativeNamedPipeClient()))	//This will create a new client with the specified pipe client
            //using (DiscordRpcClient client = new DiscordRpcClient("424087019149328395", null, true, DiscordPipe))									//This will create a new client on the specified pipe
            //using (DiscordRpcClient client = new DiscordRpcClient("424087019149328395", null, true))												//This will create a new client with a SteamID (null if no steam)
            using (client = new DiscordRpcClient(ClientID, true, DiscordPipe))                                                                                                  //This will create a new client that will register itself a URI scheme (for join / spectate)
            {
                //Set the logger. This way we can see the output of the client.
                client.Logger = new Logging.ConsoleLogger()
                {
                    Level = DiscordLogLevel, Coloured = true
                };

                //Register to the events we care about. We are registering to everyone just to show off the events
                client.OnReady += OnReady;
                client.OnClose += OnClose;
                client.OnError += OnError;

                client.OnConnectionEstablished += OnConnectionEstablished;
                client.OnConnectionFailed      += OnConnectionFailed;

                client.OnPresenceUpdate += OnPresenceUpdate;

                client.OnSubscribe   += OnSubscribe;
                client.OnUnsubscribe += OnUnsubscribe;

                client.OnJoin          += OnJoin;
                client.OnSpectate      += OnSpectate;
                client.OnJoinRequested += OnJoinRequested;

                //Before we send a initial presence, we will generate a random "game ID" for this example.
                // For a real game, this "game ID" can be a unique ID that your Match Maker / Master Server generates.
                // This is used for the Join / Specate feature. This can be ignored if you do not plan to implement that feature.
                presence.Secrets = new Secrets()
                {
                    //These secrets should contain enough data for external clients to be able to know which
                    // game to connect too. A simple approach would be just to use IP address, but this is highly discouraged
                    // and can leave your players vulnerable!
                    JoinSecret     = "join_myuniquegameid",
                    SpectateSecret = "spectate_myuniquegameid"
                };

                presence.Timestamps = new Timestamps()
                {
                    Start = DateTime.UtcNow
                };

                //We also need to generate a initial party. This is because Join requires the party to be created too.
                // If no party is set, the join feature will not work and may cause errors within the discord client itself.
                presence.Party = new Party()
                {
                    ID   = Secrets.CreateFriendlySecret(new Random()),
                    Size = 1,
                    Max  = 4
                };

                //Set some new presence to tell Discord we are in a game.
                // If the connection is not yet available, this will be queued until a Ready event is called,
                // then it will be sent. All messages are queued until Discord is ready to receive them.
                client.SetPresence(presence);

                //Subscribe to the join / spectate feature.
                //These require the RegisterURI to be true.
                client.SetSubscription(EventType.Join | EventType.Spectate | EventType.JoinRequest);                        //This will alert us if discord wants to join a game

                //Initialize the connection. This must be called ONLY once.
                //It must be called before any updates are sent or received from the discord client.
                client.Initialize();


                //Start our main loop. In a normal game you probably don't have to do this step.
                // Just make sure you call .Invoke() or some other dequeing event to receive your events.
                MainLoop();
            }
        }