Ejemplo n.º 1
0
        protected override async UniTask OnLoadAsync()
        {
            await using var dbContext = m_ServiceProvider.GetRequiredService <PlayerInfoLibDbContext>();
            await dbContext.Database.MigrateAsync();

            await m_PlayerInfoRepository.CheckAndRegisterCurrentServerAsync();

            Logger.LogInformation("Player Info Library for Unturned by Pustalorc was loaded correctly.");
        }
Ejemplo n.º 2
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);
                }
            });