Ejemplo n.º 1
0
        public Task HandleEventAsync(object sender, UnturnedPlayerConnectedEvent @event)
        {
            var joinTime = DateTime.Now;

            AsyncHelper.Schedule("PlayerInfoLib_PlayerConnected", async() =>
            {
                var player    = @event.Player;
                var playerId  = player.SteamPlayer.playerID;
                var steamId   = player.SteamId;
                var pfpHash   = await GetProfilePictureHashAsync(steamId);
                var groupName = await GetSteamGroupNameAsync(playerId.group);
                var hwid      = string.Join("", playerId.hwid);
                if (!player.SteamPlayer.transportConnection.TryGetIPv4Address(out var ip))
                {
                    ip = uint.MinValue;
                }
                var questGroupId = player.Player.quests.groupID.m_SteamID;

                var pData  = await m_PlayerInfoRepository.FindPlayerAsync(steamId.ToString(), UserSearchMode.FindById);
                var server = await m_PlayerInfoRepository.GetCurrentServerAsync() ??
                             await m_PlayerInfoRepository.CheckAndRegisterCurrentServerAsync();

                if (pData == null)
                {
                    pData = BuildPlayerData(steamId.m_SteamID, player.SteamPlayer.playerID.characterName,
                                            playerId.playerName, hwid, ip,
                                            pfpHash, questGroupId, playerId.group.m_SteamID, groupName, 0,
                                            joinTime, server);

                    await m_PlayerInfoRepository.AddPlayerDataAsync(pData);
                }
                else
                {
                    pData.ProfilePictureHash = pfpHash;
                    pData.CharacterName      = player.SteamPlayer.playerID.characterName;
                    pData.Hwid            = hwid;
                    pData.Ip              = ip;
                    pData.LastLoginGlobal = joinTime;

                    if (questGroupId != 0)
                    {
                        pData.LastQuestGroupId = questGroupId;
                    }

                    pData.SteamGroup     = playerId.group.m_SteamID;
                    pData.SteamGroupName = groupName;
                    pData.SteamName      = playerId.playerName;
                    pData.Server         = server;
                    pData.ServerId       = server.Id;

                    await m_PlayerInfoRepository.UpdatePlayerDataAsync(pData);
                }
            });
Ejemplo n.º 2
0
        protected override async Task OnExecuteAsync()
        {
            var actor = Context.Actor;

            // Parse arguments
            var target = await Context.Parameters.GetAsync <string>(0);

            var reason = m_StringLocalizer["commands:global:no_reason_specified"].Value;

            if (Context.Parameters.Count >= 2)
            {
                reason = Context.Parameters.GetArgumentLine(1);
            }

            // Try to find user to ban
            var user = await m_UserManager.FindUserAsync(KnownActorTypes.Player, target, UserSearchMode.FindByNameOrId);

            var pData = await m_PlayerInfoRepository.FindPlayerAsync(target, UserSearchMode.FindByNameOrId);

            var isId = ulong.TryParse(target, out var pId) && pId >= 76561197960265728 && pId <= 103582791429521408;

            if (!(user is UnturnedUser) && pData == null && !isId)
            {
                await actor.PrintMessageAsync(m_StringLocalizer["commands:global:playernotfound",
                                                                new { Input = target }]);

                return;
            }

            var      adminId = ulong.TryParse(actor.Id, out var id) ? id : 0ul;
            CSteamID steamId;
            string   characterName;
            string   hwid;
            uint     ip;

            if (user is UnturnedUser player)
            {
                steamId       = player.SteamId;
                characterName = player.DisplayName;
                SteamGameServerNetworking.GetP2PSessionState(steamId, out var sessionState);
                ip   = sessionState.m_nRemoteIP == 0 ? 0 : sessionState.m_nRemoteIP;
                hwid = string.Join("", player.Player.SteamPlayer.playerID.hwid);

                await UniTask.SwitchToMainThread();

                player.Player.Player.life.askDamage(101, Vector3.up * 101f, EDeathCause.KILL, ELimb.SKULL, (CSteamID)adminId,
                                                    out _);
                await UniTask.SwitchToThreadPool();
            }
            else if (pData != null)
            {
                steamId       = (CSteamID)pData.Id;
                characterName = pData.CharacterName;
                ip            = (uint)pData.Ip;
                hwid          = pData.Hwid;
            }
            else
            {
                steamId       = (CSteamID)pId;
                characterName = pId.ToString();
                ip            = 0;
                hwid          = "";
            }

            var server = await m_PlayerInfoRepository.GetCurrentServerAsync();

            await m_GlobalBanRepository.BanPlayerAsync(server?.Id ?? 0, steamId.m_SteamID, ip, hwid, uint.MaxValue,
                                                       adminId, reason);

            if (user is UnturnedUser)
            {
                await UniTask.SwitchToMainThread();

                Provider.ban(steamId, reason, uint.MaxValue);
                await UniTask.SwitchToThreadPool();
            }

            var translated = m_StringLocalizer["commands:ban:banned", new { Player = characterName, Reason = reason }];
            await m_UserManager.BroadcastAsync(translated);

            await actor.PrintMessageAsync(translated);

            if (!(actor is ConsoleActor))
            {
                m_Logger.LogInformation(translated);
            }

            if (m_Plugin.Instance != null)
            {
                await m_Plugin.Instance.SendWebhookAsync(WebhookType.Ban, characterName, actor.DisplayName, reason,
                                                         steamId.ToString(), uint.MaxValue);
            }
        }