Exemple #1
0
        private async void TShockAPI_JistChatCommand(TShockAPI.CommandArgs args)
        {
            if (args.Parameters.Count == 0)
            {
                //TODO: Print help
                return;
            }

            if (args.Parameters[0].Equals("dumpenv", StringComparison.CurrentCultureIgnoreCase))
            {
                if (Instance == null)
                {
                    return;
                }

                foreach (var property in Instance.DumpGlobalEnvironment().OrderBy(i => i.Key))
                {
                    args.Player.SendInfoMessage("{0}: {1}", property.Key,
                                                property.Value.Get.HasValue == false ? "undefined" : property.Value.Get.Value.ToString());
                }
            }
            else if (args.Parameters[0].Equals("dumptasks", StringComparison.CurrentCultureIgnoreCase))
            {
                foreach (Wolfje.Plugins.Jist.stdlib.RecurringFunction recur in Instance.stdTask.DumpTasks().OrderBy(i => i.NextRunTime))
                {
                    args.Player.SendInfoMessage(recur.ToString());
                }
            }
            else if (args.Parameters[0].Equals("eval", StringComparison.CurrentCultureIgnoreCase) ||
                     args.Parameters[0].Equals("ev", StringComparison.CurrentCultureIgnoreCase) &&
                     (args.Parameters.Count > 1))
            {
                args.Player.SendInfoMessage(Instance.Eval(args.Parameters[1]));
            }
            else if (args.Parameters[0].Equals("reload", StringComparison.CurrentCultureIgnoreCase) ||
                     args.Parameters[0].Equals("rl", StringComparison.CurrentCultureIgnoreCase))
            {
                Instance.Dispose();
                Instance = null;
                Instance = new JistEngine(this);
                await Instance.LoadEngineAsync();

                args.Player.SendInfoMessage("Jist reloaded");
            }
        }
        private void ChatCommand_GeneralCommand(TShockAPI.CommandArgs args)
        {
            if (args.Parameters.Count >= 1 && args.Parameters[0].Equals("reload", StringComparison.CurrentCultureIgnoreCase) && args.Player.Group.HasPermission("aliascmd.reloadconfig"))
            {
                args.Player.SendInfoMessage("aliascmd: Reloading configuration file.");

                ReloadConfigAfterDelayAsync(1).ContinueWith((task) => {
                    if (task.IsFaulted)
                    {
                        args.Player.SendErrorMessage("aliascmd: reload failed.  You need to check the server console to find out what went wrong.");
                        TShockAPI.Log.ConsoleError(task.Exception.ToString());
                    }
                    else
                    {
                        args.Player.SendInfoMessage("aliascmd: reload successful.");
                    }
                });
            }
            else
            {
                args.Player.SendErrorMessageFormat("aliascmd: usage: /aliascmd reload: reloads the AliasCmd configuration file.");
            }
        }
Exemple #3
0
        /// <summary>
        /// Occurs when someone executes an alias command
        /// </summary>
        void ChatCommand_AliasExecuted(TShockAPI.CommandArgs e)
        {
            string commandIdentifier = e.Message;

            if (!string.IsNullOrEmpty(e.Message))
            {
                commandIdentifier = e.Message.Split(' ').FirstOrDefault();
            }

            //Get the corresponding alias in the config that matches what the user typed.
            foreach (AliasCommand alias in Configuration.CommandAliases.Where(i => i.CommandAlias == commandIdentifier))
            {
                if (alias != null)
                {
                    TimeSpan timeSinceLastUsedCommand = TimeSpan.MaxValue;
                    //cooldown key is a pair of the user's character name, and the command they have called.
                    //cooldown value is a DateTime they last used the command.
                    KeyValuePair <string, AliasCommand> cooldownReference = new KeyValuePair <string, AliasCommand>(e.Player.Name, alias);

                    if (CooldownList.ContainsKey(cooldownReference))
                    {
                        //UTC time so we don't get any daylight saving shit cuntery
                        timeSinceLastUsedCommand = DateTime.UtcNow.Subtract(CooldownList[cooldownReference]);
                    }

                    //has the time elapsed greater than the cooldown period?
                    if (timeSinceLastUsedCommand.TotalSeconds >= alias.CooldownSeconds || e.Player.Group.HasPermission("aliascmd.bypasscooldown"))
                    {
                        Money commandCost             = 0;
                        Economy.EconomyPlayer ePlayer = SEconomyPlugin.GetEconomyPlayerSafe(e.Player.Index);

                        if (!string.IsNullOrEmpty(alias.Cost) && Money.TryParse(alias.Cost, out commandCost) && !e.Player.Group.HasPermission("aliascmd.bypasscost"))
                        {
                            if (ePlayer.BankAccount != null)
                            {
                                if (!ePlayer.BankAccount.IsAccountEnabled)
                                {
                                    e.Player.SendErrorMessageFormat("You cannot use this command because your account is disabled.");
                                }
                                else if (ePlayer.BankAccount.Balance >= commandCost)
                                {
                                    //Take money off the player, and indicate that this is a payment for something tangible.
                                    Journal.BankTransferEventArgs trans = SEconomyPlugin.WorldAccount.TransferTo(ePlayer.BankAccount, -commandCost, Journal.BankAccountTransferOptions.AnnounceToReceiver | Journal.BankAccountTransferOptions.IsPayment);
                                    if (trans.TransferSucceeded)
                                    {
                                        DoCommands(alias, ePlayer.TSPlayer, e.Parameters);
                                    }
                                    else
                                    {
                                        e.Player.SendErrorMessageFormat("Your payment failed.");
                                    }
                                }
                                else
                                {
                                    e.Player.SendErrorMessageFormat("This command costs {0}. You need {1} more to be able to use this.", commandCost.ToLongString(), ((Money)(ePlayer.BankAccount.Balance - commandCost)).ToLongString());
                                }
                            }
                            else
                            {
                                e.Player.SendErrorMessageFormat("This command costs money and you don't have a bank account.  Please log in first.");
                            }
                        }
                        else
                        {
                            //Command is free
                            DoCommands(alias, e.Player, e.Parameters);
                        }

                        //populate the cooldown list.  This dictionary does not go away when people leave so they can't
                        //reset cooldowns by simply logging out or disconnecting.  They can reset it however by logging into
                        //a different account.
                        if (CooldownList.ContainsKey(cooldownReference))
                        {
                            CooldownList[cooldownReference] = DateTime.UtcNow;
                        }
                        else
                        {
                            CooldownList.Add(cooldownReference, DateTime.UtcNow);
                        }
                    }
                    else
                    {
                        e.Player.SendErrorMessageFormat("{0}: You need to wait {1:0} more seconds to be able to use that.", alias.CommandAlias, (alias.CooldownSeconds - timeSinceLastUsedCommand.TotalSeconds));
                    }
                }
            }
        }
Exemple #4
0
        static void Chat_BankCommand(TShockAPI.CommandArgs args)
        {
            //The initator of the command with bank account...
            Economy.EconomyPlayer selectedPlayer = SEconomyPlugin.GetEconomyPlayerSafe(args.Player.Index);
            Economy.EconomyPlayer caller         = SEconomyPlugin.GetEconomyPlayerSafe(args.Player.Index);

            string namePrefix = "Your";

            if (args.Parameters.Count == 0)
            {
                args.Player.SendInfoMessageFormat("This server is running SEconomy v{0}", SEconomyPlugin.PluginVersion);
                args.Player.SendInfoMessage("You can:");

                args.Player.SendInfoMessage("* View your balance with /bank bal");

                if (args.Player.Group.HasPermission("bank.transfer"))
                {
                    args.Player.SendInfoMessage("* Trade players with /bank pay <player> <amount>");
                }

                if (args.Player.Group.HasPermission("bank.viewothers"))
                {
                    args.Player.SendInfoMessage("* View other people's balance with /bank bal <player>");
                }

                if (args.Player.Group.HasPermission("bank.worldtransfer"))
                {
                    args.Player.SendInfoMessage("* Spawn/delete money with /bank give|take <player> <amount>");
                }

                if (args.Player.Group.HasPermission("bank.mgr"))
                {
                    args.Player.SendInfoMessage("* Spawn the account manager GUI on the server with /bank mgr");
                }

                if (args.Player.Group.HasPermission("bank.savejournal"))
                {
                    args.Player.SendInfoMessage("* Save the journal with /bank savejournal");
                }

                if (args.Player.Group.HasPermission("bank.loadjournal"))
                {
                    args.Player.SendInfoMessage("* Load the journal with /bank loadjournal");
                }

                if (args.Player.Group.HasPermission("bank.squashjournal"))
                {
                    args.Player.SendInfoMessage("* Compress the journal with /bank squashjournal");
                }

                return;
            }

            //Bank balance
            if (args.Parameters[0].Equals("bal", StringComparison.CurrentCultureIgnoreCase) ||
                args.Parameters[0].Equals("balance", StringComparison.CurrentCultureIgnoreCase))
            {
                //The command supports viewing other people's balance if the caller has permission
                if (args.Player.Group.HasPermission("bank.viewothers"))
                {
                    if (args.Parameters.Count >= 2)
                    {
                        selectedPlayer = SEconomyPlugin.GetEconomyPlayerSafe(args.Parameters[1]);
                    }

                    if (selectedPlayer != null)
                    {
                        namePrefix = selectedPlayer.TSPlayer.Name + "'s";
                    }
                }

                if (selectedPlayer != null && selectedPlayer.BankAccount != null)
                {
                    if (!selectedPlayer.BankAccount.IsAccountEnabled && !args.Player.Group.HasPermission("bank.viewothers"))
                    {
                        args.Player.SendErrorMessage("bank balance: your account is disabled");
                    }
                    else
                    {
                        args.Player.SendInfoMessageFormat("{1} balance: {0} {2}", selectedPlayer.BankAccount.Balance.ToLongString(true), namePrefix, selectedPlayer.BankAccount.IsAccountEnabled ? "" : "(disabled)");
                    }
                }
                else
                {
                    args.Player.SendInfoMessage("bank balance: Cannot find player or no bank account.");
                }
            }
            else if (args.Parameters[0].Equals("mgr"))
            {
                if (args.Player.Group.HasPermission("bank.mgr"))
                {
                    if (args.Player is TShockAPI.TSServerPlayer)
                    {
                        Forms.CAccountManagementWnd wnd = new Forms.CAccountManagementWnd();

                        Task.Factory.StartNew(() => {
                            TShockAPI.Log.ConsoleInfo("seconomy management: opening bank manager window");

                            //writing the journal is not possible when you're f*****g with it in the manager
                            //last thing you want is for half baked changes to be pushed to disk
                            SEconomyPlugin.BackupCanRun = false;

                            wnd.ShowDialog();
                        }, creationOptions: TaskCreationOptions.LongRunning).ContinueWith((task) => {
                            SEconomyPlugin.BackupCanRun = true;

                            TShockAPI.Log.ConsoleInfo("seconomy management: window closed");
                            Journal.TransactionJournal.BackupJournalAsync();
                        });
                    }
                    else
                    {
                        args.Player.SendErrorMessage("Only the console can do that.");
                    }
                }
            }
            else if (args.Parameters[0].Equals("savejournal"))
            {
                if (args.Player.Group.HasPermission("bank.savejournal"))
                {
                    args.Player.SendInfoMessage("seconomy xml: Backing up transaction journal.");

                    Journal.TransactionJournal.SaveXml(Configuration.JournalPath);
                }
            }
            else if (args.Parameters[0].Equals("loadjournal"))
            {
                if (args.Player.Group.HasPermission("bank.loadjournal"))
                {
                    args.Player.SendInfoMessage("seconomy xml: Loading transaction journal from file");

                    Journal.TransactionJournal.LoadFromXmlFile(Configuration.JournalPath);
                }
            }
            else if (args.Parameters[0].Equals("squashjournal", StringComparison.CurrentCultureIgnoreCase))
            {
                if (args.Player.Group.HasPermission("bank.squashjournal"))
                {
                    Guid p = SEconomyPlugin.Profiler.Enter("Squash journal");
                    Journal.TransactionJournal.SquashJournalAsync().ContinueWith((task) => {
                        Journal.TransactionJournal.SaveXml(Configuration.JournalPath);

                        SEconomyPlugin.Profiler.ExitLog(p);
                    });
                }
                else
                {
                    args.Player.SendErrorMessage("bank squashjournal: You do not have permission to perform this command.");
                }
            }
            else if (args.Parameters[0].Equals("listbal", StringComparison.CurrentCultureIgnoreCase))
            {
                //Admin command: lists people's balances
                if (args.Player.Group.HasPermission("bank.listbal"))
                {
                    int takeFrom = 0, takeTo = 25, page = 1;

                    if (args.Parameters.Count >= 2 && int.TryParse(args.Parameters[1], out page))
                    {
                        takeFrom = page * 25;
                        takeTo   = takeFrom + 25;
                    }

                    args.Player.SendInfoMessage("Bank Balances - Page " + page);
                    args.Player.SendInfoMessage("===");

                    foreach (Journal.XBankAccount bankAccount in Journal.TransactionJournal.BankAccounts.Skip(takeFrom).Take(25))
                    {
                        bankAccount.SyncBalanceAsync().ContinueWith((task) => {
                            args.Player.SendInfoMessageFormat("* {0} : {1}", bankAccount.UserAccountName, bankAccount.Balance);
                        });
                    }
                }
            }
            else if (args.Parameters[0].Equals("ena", StringComparison.CurrentCultureIgnoreCase) ||
                     args.Parameters[0].Equals("enable", StringComparison.CurrentCultureIgnoreCase) ||
                     args.Parameters[0].Equals("dis", StringComparison.CurrentCultureIgnoreCase) ||
                     args.Parameters[0].Equals("disable", StringComparison.CurrentCultureIgnoreCase))
            {
                //Account enable

                //Flag to set the account to
                bool enableAccount = args.Parameters[0].Equals("ena", StringComparison.CurrentCultureIgnoreCase) || args.Parameters[0].Equals("enable", StringComparison.CurrentCultureIgnoreCase);

                if (args.Player.Group.HasPermission("bank.modifyothers"))
                {
                    if (args.Parameters.Count >= 2)
                    {
                        selectedPlayer = SEconomyPlugin.GetEconomyPlayerSafe(args.Parameters[1]);
                    }

                    if (selectedPlayer != null)
                    {
                        namePrefix = selectedPlayer.TSPlayer.Name + "'s";
                    }
                }

                if (selectedPlayer != null && selectedPlayer.BankAccount != null)
                {
                    selectedPlayer.BankAccount.SetAccountEnabled(args.Player.Index, enableAccount);
                }
            }
            else if (args.Parameters[0].Equals("pay", StringComparison.CurrentCultureIgnoreCase) ||
                     args.Parameters[0].Equals("transfer", StringComparison.CurrentCultureIgnoreCase) ||
                     args.Parameters[0].Equals("tfr", StringComparison.CurrentCultureIgnoreCase))
            {
                //Player-to-player transfer

                if (selectedPlayer.TSPlayer.Group.HasPermission("bank.transfer"))
                {
                    // /bank pay wolfje 1p
                    if (args.Parameters.Count >= 3)
                    {
                        selectedPlayer = SEconomyPlugin.GetEconomyPlayerSafe(args.Parameters[1]);
                        Money amount = 0;

                        if (selectedPlayer == null)
                        {
                            args.Player.SendErrorMessageFormat("Cannot find player by the name of {0}.", args.Parameters[1]);
                        }
                        else
                        {
                            if (Money.TryParse(args.Parameters[2], out amount))
                            {
                                //Instruct the world bank to give the player money.
                                caller.BankAccount.TransferTo(selectedPlayer.BankAccount, amount, Journal.BankAccountTransferOptions.AnnounceToReceiver | Journal.BankAccountTransferOptions.AnnounceToSender | Journal.BankAccountTransferOptions.IsPlayerToPlayerTransfer, Message: string.Format("SE: tfr: {0} to {1} for {2}", caller.TSPlayer.Name, selectedPlayer.TSPlayer.Name, amount.ToString()));
                            }
                            else
                            {
                                args.Player.SendErrorMessageFormat("bank give: \"{0}\" isn't a valid amount of money.", args.Parameters[2]);
                            }
                        }
                    }
                    else
                    {
                        args.Player.SendErrorMessage("Usage: /bank pay <Player> <Amount>");
                    }
                }
                else
                {
                    args.Player.SendErrorMessageFormat("bank pay: You don't have permission to do that.");
                }
            }
            else if (args.Parameters[0].Equals("give", StringComparison.CurrentCultureIgnoreCase) ||
                     args.Parameters[0].Equals("take", StringComparison.CurrentCultureIgnoreCase))
            {
                //World-to-player transfer

                if (selectedPlayer.TSPlayer.Group.HasPermission("bank.worldtransfer"))
                {
                    // /bank give wolfje 1p
                    if (args.Parameters.Count >= 3)
                    {
                        selectedPlayer = SEconomyPlugin.GetEconomyPlayerSafe(args.Parameters[1]);
                        Money amount = 0;

                        if (selectedPlayer == null)
                        {
                            args.Player.SendErrorMessageFormat("Cannot find player by the name of {0}.", args.Parameters[1]);
                        }
                        else
                        {
                            if (Money.TryParse(args.Parameters[2], out amount))
                            {
                                //eliminate a double-negative.  saying "take Player -1p1c" will give them 1 plat 1 copper!
                                if (args.Parameters[0].Equals("take", StringComparison.CurrentCultureIgnoreCase) && amount > 0)
                                {
                                    amount = -amount;
                                }

                                //Instruct the world bank to give the player money.
                                SEconomyPlugin.WorldAccount.TransferTo(selectedPlayer.BankAccount, amount, Journal.BankAccountTransferOptions.AnnounceToReceiver, Message: string.Format("SE: pay: {0} to {1} ", amount.ToString(), selectedPlayer.TSPlayer.Name));
                            }
                            else
                            {
                                args.Player.SendErrorMessageFormat("bank give: \"{0}\" isn't a valid amount of money.", args.Parameters[2]);
                            }
                        }
                    }
                    else
                    {
                        args.Player.SendErrorMessage("Usage: /bank give|take <Player> <Amount");
                    }
                }
                else
                {
                    args.Player.SendErrorMessageFormat("bank give: You don't have permission to do that.");
                }
            }
        }