Пример #1
0
        //Loop checking cooldown list and removing players after cooldown expiry
        public void RemoveCooldownLoop()
        {
            try
            {
                List <CSteamID> keys = new List <CSteamID>(Cooldown.Keys);
                foreach (var key in keys)
                {
                    var value       = Cooldown[key];
                    var currentTime = CurrentTime.Millis;

                    if (value <= currentTime)
                    {
                        Cooldown.Remove(key);
                        Ad_Views[key] = 0;

                        if (Provider.clients.Contains(PlayerTool.getSteamPlayer(key)))
                        {
                            UnturnedPlayer player = UnturnedPlayer.FromCSteamID(key);
                            UnturnedChat.Say(player, Translation_dictionary["COOLDOWN_EXPIRED"].Key, Translation_dictionary["COOLDOWN_EXPIRED"].Value);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Rocket.Core.Logging.Logger.LogException(e);
            }
        }
Пример #2
0
            protected override void execute(CSteamID executorID, string parameter)
            {
                SteamPlayer player = PlayerTool.getSteamPlayer(executorID);

                List <InteractableVehicle> nearbyVehicles = new List <InteractableVehicle>();

                VehicleManager.getVehiclesInRadius(player.player.movement.transform.position, 15f, nearbyVehicles);

                foreach (InteractableVehicle v in nearbyVehicles)
                {
                    byte     seat;
                    CSteamID escorteeID;

                    if (EscortingPlayers.TryGetValue(executorID, out escorteeID))
                    {
                        Player ply = PlayerTool.getPlayer(escorteeID);


                        if (v.tryAddPlayer(out seat, ply) && !v.isLocked)
                        {
                            EscortedPlayers.Remove(escorteeID);
                            EscortingPlayers.Remove(executorID);
                            VehicleManager.instance.channel.send("tellEnterVehicle", ESteamCall.ALL, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] {
                                v.instanceID,
                                seat,
                                escorteeID
                            });
                        }
                    }
                }
            }
Пример #3
0
        protected virtual void OnPlayerConnected(CSteamID steamID)
        {
            var pending = m_PendingUsers.FirstOrDefault(d => d.SteamId == steamID);

            if (pending != null)
            {
                FinishSession(pending);
            }

            var steamPlayer = PlayerTool.getSteamPlayer(steamID);

            if (steamPlayer == null)
            {
                return;
            }

            var user = new UnturnedUser(this, m_UserDataStore, steamPlayer.player, pending);

            m_Users.Add(user);

            AsyncContext.Run(async() =>
            {
                var @event = new UnturnedUserConnectedEvent(user);
                await m_EventBus.EmitAsync(m_Runtime, this, @event);
            });
        }
        private static void OnPlayerDied(PlayerLife sender, EDeathCause cause, ELimb limb, CSteamID instigator)
        {
            var killedSteamPlayer = sender.channel.owner;
            var combat            = CombatManager.CombatTracker.ContainsKey(killedSteamPlayer) ? CombatManager.CombatTracker[killedSteamPlayer] : null;

            if (combat != null && PlayerTool.getSteamPlayer(instigator) == null &&
                DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() -
                combat.LastHit <
                Main.Config.CombatExpiration)
            {
                instigator = combat.Aggressor.playerID.steamID;
            }

            var killInfo = new PlayerDeath(killedSteamPlayer, instigator, cause);

            var killer = PlayerTool.getSteamPlayer(instigator);

            if (killer != null)
            {
                killInfo.KillerShotsHit   = CombatManager.Accuracies.ContainsKey(killer) ? CombatManager.Accuracies[killer].ShotsHit : 0;
                killInfo.KillerShotsFired = CombatManager.Accuracies.ContainsKey(killer) ? CombatManager.Accuracies[killer].ShotsFired : 0;
                UnityThread.executeCoroutine(CaptureScreen(killInfo, killer));
            }
            else
            {
                var socketData = new SocketData("PlayerDeath", JsonConvert.SerializeObject(killInfo));
                SocketManager.Emit(socketData);
            }
        }
Пример #5
0
        public void Start()
        {
            Stats = new XMLFileAsset <StatKeeper.Stats>(Path.Combine(Plugin.Instance.Directory, "Stats/" + Player.Id + ".xml"));
            Stats.Instance.SteamID = (ulong)Player.CSteamID;

            //TODO: Add tracking of acc when player is in combat

            Player.Events.OnDeath += (UnturnedPlayer player, SDG.Unturned.EDeathCause cause, SDG.Unturned.ELimb limb, Steamworks.CSteamID m) => {
                UnturnedPlayer murderer = UnturnedPlayer.FromCSteamID(m);

                if (murderer != null && PlayerTool.getSteamPlayer(m) != null && cause != SDG.Unturned.EDeathCause.SUICIDE)
                {
                    XMLFileAsset <Stats> killerStats = murderer.GetComponent <StatsPlayerComponent>().Stats;

                    if (limb == SDG.Unturned.ELimb.SKULL)
                    {
                        killerStats.Instance.HeadShots += 1;
                    }

                    killerStats.Instance.Kills += 1;
                    killerStats.Instance.RecalculateStats();
                    killerStats.Save();
                }

                Stats.Instance.Deaths += 1;
                Stats.Instance.RecalculateStats();
                Stats.Save();
                Plugin.Instance.UpdateRank();
            };
            Stats.Instance.RecalculateStats();
            Plugin.Instance.UpdateRank();
        }
Пример #6
0
        protected override void execute(CSteamID executor, string parameter)
        {
            SteamPlayer ply = PlayerTool.getSteamPlayer(executor);

            if (ply is null)
            {
                return;
            }
            TTTPlayer tttplayer = PlayerManager.GetTTTPlayer(executor);

            switch (parameter)
            {
            case "t":
                tttplayer.Role = PlayerRole.TRAITOR;
                tttplayer.SendMessage("Role set to traitor");
                InterfaceManager.ToggleShop(ply.player, tttplayer, 8501);
                break;

            case "d":
                tttplayer.Role = PlayerRole.DETECTIVE;
                tttplayer.SendMessage("Role set to detective");
                InterfaceManager.ToggleShop(ply.player, tttplayer, 8502);
                break;
            }

            tttplayer.SendMessage(parameter);
        }
        private async UniTask RequestExpirationThread(ulong recipientID, ulong requesterID, int lifetime)
        {
            await UniTask.Delay(TimeSpan.FromMilliseconds(lifetime));

            if (!m_OpenRequests[recipientID].Contains(requesterID))
            {
                return;
            }

            m_OpenRequests[recipientID].Remove(requesterID);

            SteamPlayer requester = PlayerTool.getSteamPlayer(requesterID);

            if (requester == null)
            {
                return;
            }

            SteamPlayer recipient = PlayerTool.getSteamPlayer(recipientID);

            if (recipient == null)
            {
                return;
            }

            await UniTask.SwitchToMainThread();

            ChatManager.serverSendMessage(m_StringLocalizer["tpa:expired", new { Recipient = recipient.playerID.characterName }], Color.red, toPlayer: requester);
        }
Пример #8
0
            public override void execute(CSteamID executor, string[] args)
            {
                SteamPlayer player = PlayerTool.getSteamPlayer(executor);

                if (Main.Config.allowToggle || player.isAdmin)
                {
                    if (enabledNameplatesList.Contains(player.playerID.steamID))
                    {
                        enabledNameplatesList.Remove(player.playerID.steamID);
                        disabledNameplatesList.Add(player.playerID.steamID);
                        UnityThread.executeInUpdate(() =>
                        {
                            ChatManager.say(player.playerID.steamID, $"Nameplate disabled", Color.cyan);
                        });
                    }
                    else
                    {
                        disabledNameplatesList.Remove(player.playerID.steamID);
                        enabledNameplatesList.Add(player.playerID.steamID);
                        UnityThread.executeInUpdate(() =>
                        {
                            ChatManager.say(player.playerID.steamID, $"Nameplate enabled", Color.cyan);
                        });
                    }
                }
            }
Пример #9
0
        protected override async UniTask OnExecuteAsync()
        {
            if (Context.Parameters.Length > 1)
            {
                throw new CommandWrongUsageException(Context);
            }

            UnturnedUser uPlayer          = (UnturnedUser)Context.Actor;
            ulong        recipientSteamID = uPlayer.SteamId.m_SteamID;

            SteamPlayer requester;

            switch (Context.Parameters.Length)
            {
            case 0:
                if (!m_TpaRequestManager.IsRequestOpen(recipientSteamID))
                {
                    throw new UserFriendlyException(m_StringLocalizer["tpa:no_requests"]);
                }

                ulong firstRequester = m_TpaRequestManager.AcceptRequest(recipientSteamID);
                requester = PlayerTool.getSteamPlayer(firstRequester);

                if (requester == null)
                {
                    throw new UserFriendlyException(m_StringLocalizer["tpa:disconnected",
                                                                      new { Requester = firstRequester.ToString() }]);
                }
                break;

            case 1:
                string requesterName = Context.Parameters[0];
                if (!PlayerTool.tryGetSteamPlayer(requesterName, out requester))
                {
                    throw new UserFriendlyException(m_StringLocalizer["tpa:invalid_recipient",
                                                                      new { Recipient = requesterName }]);
                }

                if (!m_TpaRequestManager.IsRequestOpen(recipientSteamID, requester.playerID.steamID.m_SteamID))
                {
                    throw new UserFriendlyException(m_StringLocalizer["tpa:no_requests_from",
                                                                      new { Requester = requester.playerID.characterName }]);
                }
                break;

            default:
                throw new UserFriendlyException("This is a placeholder so that we can reassure the compiler that requester will never be null.");
            }

            //TODO: Change name to be less misleading.
            m_TpaRequestManager.AcceptRequest(recipientSteamID, requester.playerID.steamID.m_SteamID);

            await uPlayer.PrintMessageAsync(m_StringLocalizer["tpa:denied_self",
                                                              new { Requester = requester.playerID.characterName }]);

            await UniTask.SwitchToMainThread();

            ChatManager.serverSendMessage(m_StringLocalizer["tpa:denied_other",
                                                            new { Recipient = uPlayer.DisplayName }], Color.red, toPlayer: requester, useRichTextFormatting: true);
        }
        public PlayerDeath(SteamPlayer killed, CSteamID killerId, EDeathCause deathCause)
        {
            Cause         = Enum.GetName(typeof(EDeathCause), deathCause)?.ToLower();
            KilledSteamId = killed.playerID.steamID.ToString();
            KilledName    = killed.playerID.playerName;
            var killer = PlayerTool.getSteamPlayer(killerId);

            if (killer == null)
            {
                return;
            }
            if (killer.Equals(killed))
            {
                return;
            }

            KillerSteamId = killer.playerID.steamID.ToString();
            KillerName    = killer.playerID.playerName;
            Distance      = Vector3.Distance(killed.player.transform.position, killer.player.transform.position);

            if (killer.player.equipment == null)
            {
                return;
            }
            if (killer.player.equipment.asset != null)
            {
                KillerWeapon = killer.player.equipment.asset.name;
            }
        }
Пример #11
0
        protected override void execute(CSteamID executorID, string parameter)
        {
            var steamPlayer  = PlayerTool.getSteamPlayer(executorID);
            var thingLocated = TraceRay(steamPlayer, 2048f,
                                        RayMasks.VEHICLE | RayMasks.BARRICADE | RayMasks.STRUCTURE | RayMasks.BARRICADE_INTERACT |
                                        RayMasks.STRUCTURE_INTERACT);

            if (thingLocated.transform == null)
            {
                ChatManager.SendServerMessage("Could not find barricade", steamPlayer, EChatMode.SAY);
                return;
            }

            var component = thingLocated.transform.GetComponent <Interactable2>();

            if (component?.transform == null)
            {
                ChatManager.SendServerMessage("Could not find barricade", steamPlayer, EChatMode.SAY);
                return;
            }

            var ownerId = (CSteamID)component.owner;

            ChatManager.SendServerMessage($"Owner: {ownerId}", steamPlayer, EChatMode.SAY);
        }
Пример #12
0
        protected override void execute(CSteamID executorID, string parameter)
        {
            var steamPlayer = PlayerTool.getSteamPlayer(executorID);
            var socketData  = new SocketData("LinkCreate", steamPlayer.playerID.steamID.ToString());

            SocketManager.Emit(socketData);
        }
Пример #13
0
        public async Task Stop()
        {
            CommandWindow.Log("Stopping round");
            RoundManager.Broadcast("Round has ended.");
            RoundTime = 600;

            State = RoundState.INTERMISSION;

            await Task.Delay(6000);

            Players.ToList().ForEach(p =>
            {
                if (p.Status == PlayerStatus.ALIVE)
                {
                    p.ReviveUnsafe();
                    TTTPlayer.ClearInventoryUnsafe(PlayerTool.getSteamPlayer(p.SteamID));
                }
            });

            await Task.Delay(6000);

            State = RoundState.SETUP;

            LevelManager.ClearBarricadesUnsafe();
            C4Manager.ClearC4();
            TrackerGunManager.ClearTrackedPlayers();
        }
Пример #14
0
            protected override void execute(CSteamID executorID, string parameter)
            {
                SteamPlayer player = PlayerTool.getSteamPlayer(executorID);

                List <InteractableVehicle> nearbyVehicles = new List <InteractableVehicle>();

                VehicleManager.getVehiclesInRadius(player.player.movement.transform.position, 15f, nearbyVehicles);

                foreach (InteractableVehicle v in nearbyVehicles)
                {
                    if (!v.isLocked)
                    {
                        for (int i = 0; i < v.passengers.Length; i++)
                        {
                            Passenger passenger = v.passengers[i];
                            if (passenger != null)
                            {
                                SteamPlayer ply = passenger.player;
                                if (ply != null)
                                {
                                    Player player2 = ply.player;
                                    if (!(player2 == null) && !player2.life.isDead)
                                    {
                                        if (ply.player.animator.gesture == EPlayerGesture.ARREST_START)
                                        {
                                            VehicleManager.forceRemovePlayer(ply.playerID.steamID);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
Пример #15
0
        public static void PostFixObj(CSteamID steamIDRemote, ref P2PSessionState_t pConnectionState)
        {
            SteamPlayer pl = PlayerTool.getSteamPlayer(steamIDRemote);

            if (pl.transportConnection.TryGetIPv4Address(out uint IP))
            {
                pConnectionState.m_nRemoteIP = IP;
            }
        }
Пример #16
0
        public void Say(Player player, string message, Color color, string imageURL)
        {
            SteamPlayer steamPlayer = PlayerTool.getSteamPlayer(player.channel.owner.playerID.steamID);

            foreach (string text in WrapMessage(message))
            {
                ChatManager.serverSendMessage(text, color, null, steamPlayer, EChatMode.SAY, imageURL, true);
            }
        }
Пример #17
0
 public static void Prefix(byte amount, EDeathCause newCause, ELimb newLimb, CSteamID newKiller, ref EPlayerKill kill, bool trackKill, bool canCauseBleeding, PlayerLife __instance)
 {
     if (PlayerTool.getSteamPlayer(newKiller) == null)
     {
         return;
     }
     CombatManager.CombatTracker[__instance.channel.owner] =
         new Combat(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), PlayerTool.getSteamPlayer(newKiller));
 }
Пример #18
0
        private void OnPlayerDamaged(Player player, ref EDeathCause cause, ref ELimb limb, ref CSteamID killer, ref Vector3 direction, ref float damage, ref float times, ref bool canDamage)
        {
            var killerPlayer = PlayerTool.getSteamPlayer(killer);

            if (killerPlayer != null && !Configuration.Instance.AllowCombat)
            {
                this.StartPlayerCombat(killer);
                this.StartPlayerCombat(player.channel.owner.playerID.steamID);
            }
        }
Пример #19
0
        /*
         * Deletes a players last used character files.
         */
        private void DeleteLastUsedPlayerData(CSteamID _playerID)
        {
            byte lastUsedChar = PlayerTool.getSteamPlayer(_playerID).SteamPlayerID.characterID;

            try
            {
                System.IO.Directory.Delete(Path.GetFullPath(serverFolder + "/Players/" + _playerID.ToString() + "_" + lastUsedChar), true);                 //Delete the latest character files/inventory.
            }
            catch (IOException e) {}
        }
        public IPlayer GetOnlinePlayerById(string id)
        {
            var player = PlayerTool.getSteamPlayer(new CSteamID(ulong.Parse(id)));

            if (player == null)
            {
                return(null);
            }

            return(new UnturnedPlayer(container, player, this));
        }
        public async Task <IPlayer> GetPlayerByIdAsync(string id)
        {
            var player = PlayerTool.getSteamPlayer(ulong.Parse(id));

            if (player == null)
            {
                throw new PlayerIdNotFoundException(id);
            }

            return(new UnturnedPlayer(container, player, this));
        }
        public async Task <IPlayer> GetPlayerByNameAsync(string name)
        {
            SteamPlayer player = PlayerTool.getSteamPlayer(name);

            if (player == null)
            {
                throw new PlayerNameNotFoundException(name);
            }

            return(new UnturnedPlayer(container, player, this));
        }
        public IPlayer GetOnlinePlayerByName(string displayName)
        {
            SteamPlayer player = PlayerTool.getSteamPlayer(displayName);

            if (player == null)
            {
                return(null);
            }

            return(new UnturnedPlayer(container, player, this));
        }
Пример #24
0
        protected override void execute(CSteamID executor, string parameter)
        {
            SteamPlayer ply = PlayerTool.getSteamPlayer(executor);

            if (ply is null)
            {
                return;
            }

            ply.player.sendBrowserRequest("Join our discord!", "https://discord.gg/CXNy9wt");
        }
        public IPlayer GetPlayerByName(string displayName)
        {
            SteamPlayer player = PlayerTool.getSteamPlayer(displayName);

            if (player == null)
            {
                throw new PlayerNameNotFoundException(displayName);
            }

            return(new UnturnedPlayer(container, player, this));
        }
        private void TellUser(IRocketPlayer caller, string message, Color color)
        {
            if (caller.Id == "Console")
            {
                Logger.Log(message);
                return;
            }

            SteamPlayer steamPlayer = PlayerTool.getSteamPlayer(ulong.Parse(caller.Id));

            ChatManager.serverSendMessage(message, color, toPlayer: steamPlayer);
        }
Пример #27
0
        protected override void execute(CSteamID executor, string parameter)
        {
            SteamPlayer ply = PlayerTool.getSteamPlayer(executor);

            if (ply is null)
            {
                return;
            }

            Vector3 position = ply.player.transform.position;

            PlayerManager.GetTTTPlayer(executor).SendMessageUnsafe($"X: {Math.Round(position.x, 1)} Y: {Math.Round(position.y, 1)} Z: {Math.Round(position.z, 1)}");
        }
        protected override void execute(CSteamID executorID, string parameter)
        {
            var ply = PlayerTool.getSteamPlayer(executorID);

            Provider.hasCheats = !Provider.hasCheats;
            var state = Provider.hasCheats ? "Enabled" : "Disabled";

            if (Provider.server != executorID)
            {
                ChatManager.serverSendMessage($"Cheats: {state}", Color.white, null, ply, EChatMode.SAY, "https://i.imgur.com/tcZ3u3R.png", true);
            }
            CommandWindow.Log($"Cheats: {state}");
        }
        public static void OV_receiveChatMessage(CSteamID speakerSteamID, string iconURL, EChatMode mode, Color color, bool isRich, string text)
        {
            G.Settings.Mute.TryGetValue(speakerSteamID.m_SteamID, out Mute MuteState);
            if (MuteState == Mute.All)
            {
                return;
            }
            if (MuteState == Mute.Global && mode == EChatMode.GLOBAL)
            {
                return;
            }
            if (MuteState == Mute.Area && mode == EChatMode.LOCAL)
            {
                return;
            }
            if (MuteState == Mute.Group && mode == EChatMode.GROUP)
            {
                return;
            }
            text = text.Trim();
            ControlsSettings.formatPluginHotkeysIntoText(ref text);
            if (OptionsSettings.streamer)
            {
                color = Color.white;
            }
            SteamPlayer speaker;

            if (speakerSteamID == CSteamID.Nil)
            {
                speaker = null;
            }
            else
            {
                if (!OptionsSettings.chatText && speakerSteamID != Provider.client)
                {
                    return;
                }
                speaker = PlayerTool.getSteamPlayer(speakerSteamID);
            }
            ReceivedChatMessage item = new ReceivedChatMessage(speaker, iconURL, mode, color, isRich, text);

            ChatManager.receivedChatHistory.Insert(0, item);
            if (ChatManager.receivedChatHistory.Count > Provider.preferenceData.Chat.History_Length)
            {
                ChatManager.receivedChatHistory.RemoveAt(ChatManager.receivedChatHistory.Count - 1);
            }
            if (ChatManager.onChatMessageReceived != null)
            {
                ChatManager.onChatMessageReceived();
            }
        }
Пример #30
0
        private void OnBuildingDamaged(CSteamID instigatorSteamID, Transform barricadeTransform, ref ushort pendingTotalDamage, ref bool shouldAllow, EDamageOrigin damageOrigin)
        {
            SteamPlayer steamPlayer;

            if ((steamPlayer = PlayerTool.getSteamPlayer(instigatorSteamID)) != null)
            {
                var player = UnturnedPlayer.FromSteamPlayer(steamPlayer);

                if (player != null && !Configuration.Instance.AllowRaid)
                {
                    this.StartPlayerRaid(instigatorSteamID);
                }
            }
        }