Пример #1
0
        protected override async UniTask OnExecuteAsync()
        {
            if (Context.Parameters.Length != 2)
            {
                throw new CommandWrongUsageException(Context);
            }

            string playerSearchTerm = Context.Parameters[0];

            if (!PlayerTool.tryGetSteamPlayer(playerSearchTerm, out SteamPlayer recipient))
            {
                throw new UserFriendlyException(m_StringLocalizer["vehicle:invalid_player", new { Player = playerSearchTerm }]);
            }

            string vehicleSearchTerm = Context.Parameters[1];

            if (!UnturnedAssetHelper.GetVehicle(vehicleSearchTerm, out VehicleAsset vehicle))
            {
                throw new UserFriendlyException(m_StringLocalizer["vehicle:invalid",
                                                                  new { Vehicle = vehicleSearchTerm }]);
            }

            await UniTask.SwitchToMainThread();

            if (VehicleTool.giveVehicle(recipient.player, vehicle.id))
            {
                await Context.Actor.PrintMessageAsync(m_StringLocalizer["vehicle:success_given",
                                                                        new { Vehicle = vehicle.vehicleName, Player = recipient.playerID.characterName }]);
            }
            else
            {
                throw new UserFriendlyException(m_StringLocalizer["vehicle:failure"]);
            }
        }
        private static IEnumerator UnbanPlayerCoroutine(SteamPlayer executor, string target)
        {
            PlayerTool.tryGetSteamPlayer(target, out var steamPlayer);
            PlayerTool.tryGetSteamID(target, out var cSteamID);

            var steamId = steamPlayer?.playerID.steamID ?? cSteamID;

            if (!steamId.IsValid())
            {
                if (executor != null)
                {
                    ChatManager.SendServerMessage("Target not found", executor, EChatMode.SAY);
                }
                else
                {
                    CommandWindow.LogError("Target not found");
                }
                yield break;
            }

            Provider.requestUnbanPlayer(Provider.server, steamId);
            var unbanData = new SocketData("UnbanPlayer", steamId.ToString());

            SocketManager.Emit(unbanData);
            ChatManager.SendServerMessage("Unbanned target successfully", executor, EChatMode.SAY);

            yield return(null);
        }
Пример #3
0
        protected override async UniTask OnExecuteAsync()
        {
            if (Context.Parameters.Length != 1)
            {
                throw new CommandWrongUsageException(Context);
            }

            string searchTerm = Context.Parameters[0];

            if (!PlayerTool.tryGetSteamPlayer(searchTerm, out SteamPlayer player))
            {
                throw new UserFriendlyException(m_StringLocalizer["general:invalid_player", new { Player = searchTerm }]);
            }

            ulong playerSteamID = player.playerID.steamID.m_SteamID;

            if (m_PlayerFreezer.IsPlayerFrozen(playerSteamID))
            {
                m_PlayerFreezer.UnfreezePlayer(playerSteamID);
                await Context.Actor.PrintMessageAsync(m_StringLocalizer["freeze:unfrozen",
                                                                        new { Player = player.playerID.characterName }]);
            }
            else
            {
                m_PlayerFreezer.FreezePlayer(playerSteamID, player.player.transform.position);
                await Context.Actor.PrintMessageAsync(m_StringLocalizer["freeze:frozen",
                                                                        new { Player = player.playerID.characterName }]);
            }
        }
Пример #4
0
        private static async Task <KeyValuePair <string, string> > CheckPair(CSteamID steamP, CSteamID steamG)
        {
            var isOnline     = PlayerTool.tryGetSteamPlayer(steamP.ToString(), out var player);
            var nameAndGroup = await RequestUtil.GetNameAndGroup(steamP, steamG);

            return(new KeyValuePair <string, string>(isOnline ? player.playerID.characterName : nameAndGroup.Key, nameAndGroup.Value));
        }
        private static IEnumerator BanPlayerCoroutine(SteamPlayer executor, string target)
        {
            var ip = 0u;

            if (PlayerTool.tryGetSteamPlayer(target, out var steamPlayer))
            {
                ip = steamPlayer.getIPv4AddressOrZero();
            }
            PlayerTool.tryGetSteamID(target, out var cSteamID);

            var steamId = steamPlayer?.playerID.steamID ?? cSteamID;

            if (!steamId.IsValid())
            {
                if (executor != null)
                {
                    ChatManager.SendServerMessage("Target not found", executor, EChatMode.SAY);
                }
                else
                {
                    CommandWindow.LogError("Target not found");
                }
                yield break;
            }

            Provider.requestBanPlayer(Provider.server, steamId, ip, "Banned", SteamBlacklist.PERMANENT);
            var banData = new SocketData("BanPlayer", steamId.ToString());

            SocketManager.Emit(banData);
            ChatManager.SendServerMessage("Banned target successfully", executor, EChatMode.SAY);

            yield return(null);
        }
Пример #6
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);
        }
Пример #7
0
        public void Execute(IRocketPlayer caller, params string[] command)
        {
            SteamPlayer   otherSteamPlayer = null;
            SteamPlayerID steamPlayerID    = null;

            if (command.Length == 0 || command.Length > 2)
            {
                UnturnedChat.Say(caller, GlobalBan.Instance.Translate("command_generic_invalid_parameter"));
                return;
            }

            var      isOnline = false;
            CSteamID steamid;
            string   charactername = null;

            if (!PlayerTool.tryGetSteamPlayer(command[0], out otherSteamPlayer))
            {
                var player = GlobalBan.GetPlayer(command[0]);
                if (player.Key != null)
                {
                    steamid       = player.Key;
                    charactername = player.Value;
                }
                else
                {
                    UnturnedChat.Say(caller, GlobalBan.Instance.Translate("command_generic_player_not_found"));
                    return;
                }
            }
            else
            {
                isOnline      = true;
                steamid       = otherSteamPlayer.playerID.steamID;
                charactername = otherSteamPlayer.playerID.characterName;
            }

            if (command.Length >= 2)
            {
                GlobalBan.Instance.Database.BanPlayer(charactername, steamid.ToString(), caller.DisplayName, command[1],
                                                      31536000);
                UnturnedChat.Say(GlobalBan.Instance.Translate("command_ban_public_reason", charactername, command[1]));
                if (isOnline)
                {
                    Provider.kick(steamPlayerID.steamID, command[1]);
                }
            }
            else
            {
                GlobalBan.Instance.Database.BanPlayer(charactername, steamid.ToString(), caller.DisplayName, "",
                                                      31536000);
                UnturnedChat.Say(GlobalBan.Instance.Translate("command_ban_public", charactername));
                if (isOnline)
                {
                    Provider.kick(steamPlayerID.steamID,
                                  GlobalBan.Instance.Translate("command_ban_private_default_reason"));
                }
            }
        }
Пример #8
0
        protected override async UniTask OnExecuteAsync()
        {
            if (Context.Parameters.Length > 1)
            {
                throw new CommandWrongUsageException(Context);
            }

            bool isGod;

            if (Context.Parameters.Length == 0)
            {
                if (!(Context.Actor is UnturnedUser uPlayer))
                {
                    throw new CommandWrongUsageException(Context);
                }

                isGod = m_GodManager.ToggleGod(uPlayer.SteamId.m_SteamID);

                if (isGod)
                {
                    await uPlayer.PrintMessageAsync(m_StringLocalizer["god:god"]);
                }
                else
                {
                    await uPlayer.PrintMessageAsync(m_StringLocalizer["god:mortal"]);
                }

                return;
            }

            string searchTerm = Context.Parameters[0];

            if (!PlayerTool.tryGetSteamPlayer(searchTerm, out SteamPlayer target))
            {
                throw new UserFriendlyException(m_StringLocalizer["general:invalid_player", new { Player = searchTerm }]);
            }

            await UniTask.SwitchToMainThread();

            isGod = m_GodManager.ToggleGod(target.playerID.steamID.m_SteamID);
            if (isGod)
            {
                await Context.Actor.PrintMessageAsync(m_StringLocalizer["god:god_other",
                                                                        new { Player = target.playerID.characterName }]);

                ChatManager.serverSendMessage(m_StringLocalizer["god:god"], Color.white, toPlayer: target, useRichTextFormatting: true);
            }
            else
            {
                await Context.Actor.PrintMessageAsync(m_StringLocalizer["god:mortal_other",
                                                                        new { Player = target.playerID.characterName }]);

                ChatManager.serverSendMessage(m_StringLocalizer["god:mortal"], Color.white, toPlayer: target, useRichTextFormatting: true);
            }
        }
Пример #9
0
        protected override async UniTask OnExecuteAsync()
        {
            if (Context.Parameters.Length > 2 || Context.Parameters.Length < 1)
            {
                throw new CommandWrongUsageException(Context);
            }


            //TODO: throw UserFriendlyException on bad input
            int additionReputation = await Context.Parameters.GetAsync <int>(0);

            if (Context.Parameters.Length == 1)
            {
                if (Context.Actor.Type == KnownActorTypes.Console)
                {
                    throw new CommandWrongUsageException(Context);
                }

                UnturnedUser uPlayer = (UnturnedUser)Context.Actor;

                await UniTask.SwitchToMainThread();

                uPlayer.Player.Player.skills.askRep(additionReputation);
                await uPlayer.PrintMessageAsync(m_StringLocalizer["reputation:success", new { Reputation = additionReputation.ToString() }]);
            }
            else
            {
                string nestedPermission = "give";
                if (await CheckPermissionAsync(nestedPermission) == PermissionGrantResult.Deny)
                {
                    throw new NotEnoughPermissionException(Context, nestedPermission);
                }

                string searchTerm = Context.Parameters[1];
                if (!PlayerTool.tryGetSteamPlayer(searchTerm, out SteamPlayer player))
                {
                    throw new UserFriendlyException(m_StringLocalizer["general:invalid_player",
                                                                      new { Player = searchTerm }]);
                }

                await UniTask.SwitchToMainThread();

                player.player.skills.askRep(additionReputation);
                await Context.Actor.PrintMessageAsync(m_StringLocalizer["reputation:gave",
                                                                        new
                                                                        {
                                                                            Player = player.playerID.characterName, Reputation = additionReputation.ToString()
                                                                        }]);
            }
        }
Пример #10
0
 public void Execute(IRocketPlayer caller, string[] command)
 {
     if (command.Length == 0)
     {
         DirectoryInfo directory = new DirectoryInfo(Plugin.Instance.pathTemp + "\\" + ((UnturnedPlayer)caller).CSteamID.ToString());
         if (!directory.Exists || directory.GetFiles().Length == 0)
         {
             Rocket.Unturned.Chat.UnturnedChat.Say(caller, $"No boxes exist in your virtual inventory!", Color.red);
             return;
         }
         string boxes = "";
         foreach (FileInfo file in directory.GetFiles())
         {
             boxes += file.Name.Split('.')[0] + ", ";
         }
         boxes = boxes.Substring(0, boxes.Length - 2);
         Rocket.Unturned.Chat.UnturnedChat.Say(caller, $"Boxes: {boxes}");
     }
     else if (command.Length == 1)
     {
         if (PlayerTool.tryGetSteamPlayer(command[0], out SteamPlayer player))
         {
             DirectoryInfo directory = new DirectoryInfo(Plugin.Instance.pathTemp + "\\" + player.playerID.steamID.ToString());
             if (!directory.Exists)
             {
                 Rocket.Unturned.Chat.UnturnedChat.Say(caller, $"No boxes exist in your virtual inventory!", Color.red);
                 return;
             }
             string boxes = "";
             foreach (FileInfo file in directory.GetFiles())
             {
                 boxes += file.Name.Split('.')[0] + " ";
             }
             Rocket.Unturned.Chat.UnturnedChat.Say(caller, $"Boxes: {boxes}");
         }
         else
         {
             Rocket.Unturned.Chat.UnturnedChat.Say(caller, $"Player: {command[0]} was not found!", Color.red);
         }
     }
     else
     {
         Rocket.Unturned.Chat.UnturnedChat.Say(caller, U.Translate("command_generic_invalid_parameter"));
         throw new WrongUsageOfCommandException(caller, this);
     }
 }
Пример #11
0
        private void DoQueuedUpdateCommands()
        {
            if (reloadCalled)       //Reload settings if called.
            {
                this.ReloadConfiguration();
                GetSettings();
                BuildProfessionWeighedList();
                logHelper.LogMessage(LogHelper.MESSAGELEVEL_WARNING, "Configuration Reloaded! Any active changes not saved.");
                reloadCalled = false;
            }

            if (adminGiveRequested)       //Admin gives kit TODO: CLEANUP

            {
                SteamPlayer steamPlayer;

                if (PlayerTool.tryGetSteamPlayer(givePlayerName, out steamPlayer) && DoesKitExist(giveKitName))           //If steam playername is found.
                {
                    ClearInventory(RocketPlayer.FromName(givePlayerName));
                    GivePlayerKit(RocketPlayer.FromName(givePlayerName), giveKitName, true);
                    logHelper.LogMessage(LogHelper.MESSAGELEVEL_INFO, "Admin gave " + givePlayerName + " the " + giveKitName + " kit.");
                }
                else
                {
                    logHelper.LogMessage(LogHelper.MESSAGELEVEL_WARNING, "givekit: no such player or kit.");
                }

                adminGiveRequested = false;
            }

            if (saveCalled)
            {
                ApplySettings();
                this.Configuration.Save();
                logHelper.LogMessage(LogHelper.MESSAGELEVEL_WARNING, "Configuration written to disk.");
                saveCalled = false;
            }
        }
Пример #12
0
        protected override async UniTask OnExecuteAsync()
        {
            if (Context.Parameters.Length > 1)
            {
                throw new CommandWrongUsageException(Context);
            }

            if (Context.Parameters.Length == 0)
            {
                //TODO: Use a more descriptive error message
                if (Context.Actor.Type == KnownActorTypes.Console)
                {
                    throw new CommandWrongUsageException(Context);
                }

                UnturnedUser uPlayer = (UnturnedUser)Context.Actor;

                await UniTask.SwitchToMainThread();

                uPlayer.Player.Player.ClearInventory();
                await uPlayer.PrintMessageAsync(m_StringLocalizer["clear:inventory"]);
            }
            else
            {
                string searchTerm = Context.Parameters[0];
                if (!PlayerTool.tryGetSteamPlayer(searchTerm, out SteamPlayer recipient))
                {
                    throw new UserFriendlyException(m_StringLocalizer["general:invalid_player", new { Player = searchTerm }]);
                }

                await UniTask.SwitchToMainThread();

                recipient.player.ClearInventory();
                await Context.Actor.PrintMessageAsync(m_StringLocalizer["clear:inventory_other",
                                                                        new { Player = recipient.playerID.characterName }]);
            }
        }
Пример #13
0
        protected override async UniTask OnExecuteAsync()
        {
            if (Context.Parameters.Length > 1)
            {
                throw new CommandWrongUsageException(Context);
            }

            bool           vanished;
            PlayerLook     look;
            PlayerMovement movement;

            if (Context.Parameters.Length == 0)
            {
                if (!(Context.Actor is UnturnedUser uPlayer))
                {
                    throw new CommandWrongUsageException(Context);
                }

                movement = uPlayer.Player.Player.movement;
                look     = uPlayer.Player.Player.look;
                vanished = !movement.canAddSimulationResultsToUpdates;
                if (vanished)
                {
                    await uPlayer.PrintMessageAsync(m_StringLocalizer["vanish:unvanished"]);

                    movement.updates.Add(new PlayerStateUpdate(movement.real, look.angle, look.rot));
                }
                else
                {
                    await uPlayer.PrintMessageAsync(m_StringLocalizer["vanish:vanished"]);
                }

                uPlayer.Player.Player.movement.canAddSimulationResultsToUpdates = vanished;
                return;
            }

            string searchTerm = Context.Parameters[0];

            if (!PlayerTool.tryGetSteamPlayer(searchTerm, out SteamPlayer target))
            {
                throw new UserFriendlyException(m_StringLocalizer["general:invalid_player", new { Player = searchTerm }]);
            }

            await UniTask.SwitchToMainThread();

            string targetName = target.playerID.characterName;

            movement = target.player.movement;
            look     = target.player.look;
            vanished = !movement.canAddSimulationResultsToUpdates;
            if (vanished)
            {
                await Context.Actor.PrintMessageAsync(m_StringLocalizer["vanish:unvanished_other", new { Player = targetName }]);

                ChatManager.serverSendMessage(m_StringLocalizer["vanish:unvanished"], Color.white, toPlayer: target);
                movement.updates.Add(new PlayerStateUpdate(movement.real, look.angle, look.rot));
            }
            else
            {
                await Context.Actor.PrintMessageAsync(m_StringLocalizer["vanish:vanished_other", new { Player = targetName }]);

                ChatManager.serverSendMessage(m_StringLocalizer["vanish:vanished"], Color.white, toPlayer: target);
            }

            target.player.movement.canAddSimulationResultsToUpdates = vanished;
        }
        private static async Task MessageReceived(object sender, MessageReceivedEventArgs args)
        {
            try
            {
                if (Encoding.UTF8.GetString(args.Data) == "ack")
                {
                    _ack = Now();
                    return;
                }

                var socketData = JsonConvert.DeserializeObject <SocketData>(Encoding.UTF8.GetString(args.Data));
                switch (socketData.Event)
                {
                case "Close":
                    _forceClosed = true;
                    _client.Dispose();
                    CommandWindow.LogError("Connection Disposed Successfully");
                    break;

                case "Authorization":
                    var authorizationToken = new SocketData("Authorization", Main.Config.AuthorizationToken);
                    Emit(authorizationToken);
                    break;

                case "JoinResponse":
                    var response = JsonConvert.DeserializeObject <JoinResponse>(socketData.Data);
                    if (response.Banned)
                    {
                        PlayerManager.BanPlayer(PlayerTool.getSteamPlayer(Provider.server), response.SteamId);
                    }
                    else
                    {
                        UnityThread.executeCoroutine(BrowserRequest(response.SteamId));
                    }
                    break;

                case "ServerInfo":
                    var data = new ServerInfo(Provider.serverName, Provider.port, Provider.map,
                                              Provider.APP_VERSION, Provider.clients.ToList());
                    var newSocketData = new SocketData("ServerInfo", JsonConvert.SerializeObject(data));
                    Emit(newSocketData);
                    break;

                case "RemoteCommand":
                    var remoteCommand = JsonConvert.DeserializeObject <RemoteCommand>(socketData.Data);
                    UnityThread.executeCoroutine(ExecuteRemoteCommand(remoteCommand));
                    break;

                case "ChatMessage":
                    var remoteChat = JsonConvert.DeserializeObject <ChatMessage>(socketData.Data);
                    ChatManager.DiscordToServer(remoteChat);
                    break;

                case "LinkResponse":
                    var link = JsonConvert.DeserializeObject <Link>(socketData.Data);
                    if (!PlayerTool.tryGetSteamPlayer(link.Steam, out var steamPlayer))
                    {
                        return;
                    }
                    ChatManager.SendServerMessage(
                        link.Discord != ""
                                ? "You have already linked your account"
                                : $"Use ?link {link.Code} in discord!", steamPlayer, EChatMode.SAY);
                    break;

                default:
                    CommandWindow.LogError($"Unexpected Event Received: {socketData.Event}");
                    break;
                }
            }
            catch (Exception ex)
            {
                CommandWindow.LogError(ex);
            }
        }
 private static IEnumerator BrowserRequest(string steamId)
 {
     PlayerTool.tryGetSteamPlayer(steamId, out var steamPlayer);
     steamPlayer?.player.sendBrowserRequest("Join our discord!", Main.Config.DiscordLink);
     yield return(null);
 }