Esempio n. 1
0
        public async void Events_OnResourceKill(CSteamID player, ResourceAsset asset)
        {
            var instigatorplayer = await m_UnturnedLogRepository.FindPlayerAsync(player.ToString(), UserSearchMode.FindById);

            var server = await m_UnturnedLogRepository.GetCurrentServerAsync() ??
                         await m_UnturnedLogRepository.CheckAndRegisterCurrentServerAsync();

            var EventTreeCut = EventDatabase.BuildEventData(instigatorplayer, "Resource harvested", " ", server);

            await m_UnturnedLogRepository.AddPlayerEventAsync(EventTreeCut);
        }
        // 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);
        }