예제 #1
0
        protected override async UniTask OnLoadAsync()
        {
            await UniTask.SwitchToMainThread();

            m_Logger.LogInformation("UnturnedLog for Unturned by Edbtvplays was loaded correctly");

            await m_DbContext.OpenModMigrateAsync();

            await m_UnturnedLogRepository.CheckAndRegisterCurrentServerAsync();

            Subscribe();

            await UniTask.SwitchToThreadPool();
        }
예제 #2
0
        // On player connected
        public async Task HandleEventAsync(object sender, UnturnedPlayerConnectedEvent @event)
        {
            var player   = @event.Player;
            var playerId = player.SteamPlayer.playerID;
            var steamId  = player.SteamId;

            // Getting Steam Information
            var pfpHash = await GetProfilePictureHashAsync(steamId);

            var groupName = await GetSteamGroupNameAsync(playerId.group);

            // Getting the hardware ID
            var hwid = string.Join("", playerId.hwid);

            // Retrieving the playuers IP
            if (!player.SteamPlayer.transportConnection.TryGetIPv4Address(out var ip))
            {
                ip = uint.MinValue; // Changes the IP into a storable value
            }
            // Quest Status
            var questGroupId = player.Player.quests.groupID.m_SteamID;

            // Find player using there steam ID
            var pData = await m_UnturnedLogRepository.FindPlayerAsync(steamId.ToString(), UserSearchMode.FindById); // returns user in database

            // Finds the current server and if it doesnt exsist register current server.
            var server = await m_UnturnedLogRepository.GetCurrentServerAsync() ??
                         await m_UnturnedLogRepository.CheckAndRegisterCurrentServerAsync();

            if (pData == null) // If user does not exsist in database.
            {
                // Costruct the new user object using build playerdata
                pData = EventDatabase.BuildPlayerData(steamId.m_SteamID, player.SteamPlayer.playerID.characterName,
                                                      playerId.playerName, hwid, ip,
                                                      pfpHash, questGroupId, playerId.group.m_SteamID, groupName, 0, 0,
                                                      DateTime.Now, server);

                // which is then added to the database.
                await m_UnturnedLogRepository.AddPlayerDataAsync(pData);
            }
            else // If user does exsist in database.
            {
                // Set the stuff needed in pdata manually overwriting what was in there previously using the datat gathered above.
                pData.ProfilePictureHash = pfpHash;
                pData.CharacterName      = player.SteamPlayer.playerID.characterName;
                pData.Hwid            = hwid;
                pData.Ip              = ip;
                pData.LastLoginGlobal = DateTime.Now;

                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;

                // save changes in the datatabase
                await m_UnturnedLogRepository.SaveChangesAsync();
            }

            // Constructs a connected event
            var Eventdisconnected = EventDatabase.BuildEventData(pData, "Connected", "", server);

            // Adds event to the database.
            await m_UnturnedLogRepository.AddPlayerEventAsync(Eventdisconnected);
        }