コード例 #1
0
        private void CommandAuth(IPlayer player, string command, string[] args)
        {
            // Already authenticated-check
            if (PlayerData.FindByGame(player.Id) != null)
            {
                player.Reply(GetMsg("Already Authenticated", player.Id), _config.Prefix);
                return;
            }

            var info = KeyInfo.FindByID(player.Id);
            var code = GenerateCode();

            if (info == null)
            {
                info = new KeyInfo();
                _keys.Add(info);
            }

            info.Key    = code;
            info.Player = player;
            info.ResetValidUntil();

            player.Reply(GetMsg("Code Generation", player.Id).Replace("{code}", code));
        }
コード例 #2
0
 private string GetDiscordOf(string id) => PlayerData.FindByGame(id)?.DiscordId;
コード例 #3
0
        // Called when a message is created on the Discord server
        private void Discord_MessageCreate(Message message)
        {
            // Bot-check
            if (message.author.bot == true)
            {
                return;
            }

            Channel.GetChannel(_client, message.channel_id, channel =>
            {
                // DM-check
                if (channel.type != ChannelType.DM)
                {
                    return;
                }

                // No code found
                var info = KeyInfo.FindByKey(message.content);
                if (info == null)
                {
                    channel.CreateMessage(_client, GetMsg("Unable To Find Code"));
                    return;
                }

                var canAuthenticate = Interface.Oxide.CallHook("CanDiscordAuthenticate", info.Player.Id, message.author.id);
                if (canAuthenticate is bool && !(bool)canAuthenticate)
                {
                    channel.CreateMessage(_client, GetMsg("Authentication Denied By Plugin", info.Player.Id));
                    return;
                }

                // Already authenticated-check
                var data1 = PlayerData.FindByGame(info.Player.Id);
                var data2 = PlayerData.FindByDiscord(message.author.id);

                if (!_config.OverwriteData && (data1 != null || data2 != null))
                {
                    channel.CreateMessage(_client, GetMsg("Already Authenticated"));
                }
                else
                {
                    if (data1 != null)
                    {
                        channel.CreateMessage(_client, GetMsg("In-Game Overwrite", info.Player.Id));
                        Interface.Oxide.CallHook("OnDiscordAuthOverwrite", data1.GameId, info.Player.Id, data1.DiscordId,
                                                 message.author.id);

                        _data.Remove(data1);
                    }

                    if (data2 != null)
                    {
                        channel.CreateMessage(_client, GetMsg("Discord Overwrite", info.Player.Id));
                        Interface.Oxide.CallHook("OnDiscordAuthOverwrite", data2.GameId, info.Player.Id, data2.DiscordId,
                                                 message.author.id);

                        _data.Remove(data2);
                    }
                }

                // Adds to data file
                _data.Add(new PlayerData
                {
                    DiscordId = message.author.id,
                    GameId    = info.Player.Id
                });

                channel.CreateMessage(_client, GetMsg("Authenticated", info.Player.Id));

                if (!string.IsNullOrEmpty(_config.AuthLogChannel))
                {
                    Channel.GetChannel(_client, _config.AuthLogChannel, logChannel =>
                    {
                        logChannel?.CreateMessage(_client,
                                                  new StringBuilder(GetMsg("Log")).Replace("{discordName}", message.author.username)
                                                  .Replace("{discordId}", message.author.id).Replace("{gameId}", info.Player.Id)
                                                  .Replace("{gameName}", info.Player.Name).ToString());
                    });
                }

                if (!string.IsNullOrEmpty(_config.GroupConnected))
                {
                    info.Player.AddToGroup(_config.GroupConnected);
                }

                Interface.Oxide.CallHook("OnDiscordAuthenticate", info.Player.Id, message.author.id);
            });
        }