public CModifyBalanceWnd(SEconomy parent, IBankAccount BankAccount) { this.account = BankAccount; this.parent = parent; InitializeComponent(); rbTradeWith.CheckedChanged += (sender, args) => SwitchRegions(); rbSetTo.CheckedChanged += (sender, args) => SwitchRegions(); txtSetCurrency.TextChanged += (sender, args) => ParseMoneyFromControl(sender as TextBox); txtTradeCurrency.TextChanged += (sender, args) => ParseMoneyFromControl(sender as TextBox); txtSetCurrency.LostFocus += (sender, args) => ConvertMoneyToNumber(sender as TextBox); txtTradeCurrency.LostFocus += (sender, args) => ConvertMoneyToNumber(sender as TextBox); txtSetCurrency.Focus(); ddlTradeAccount.DataSource = parent.RunningJournal.BankAccounts.OrderBy(i => i.UserAccountName).ToList(); ddlTradeAccount.DisplayMember = "UserAccountName"; ddlTradeAccount.ValueMember = "BankAccountK"; this.Text = "Modify Balance - " + account.UserAccountName; lblCurrencyName.Text = Money.CurrencyName; lblCurrencyName2.Text = Money.CurrencyName; }
internal ChatCommands(SEconomy parent) { this.Parent = parent; TShockAPI.Commands.ChatCommands.Add(new TShockAPI.Command(Chat_BankCommand, "bank") { AllowServer = true }); }
public WorldEconomy(SEconomy parent) { this.WorldConfiguration = Configuration.WorldConfiguration.WorldConfig.LoadConfigurationFromFile( "tshock" + System.IO.Path.DirectorySeparatorChar + "SEconomy" + System.IO.Path.DirectorySeparatorChar + "SEconomy.WorldConfig.json"); this.Parent = parent; ServerApi.Hooks.NetGetData.Register(Parent.PluginInstance, NetHooks_GetData); ServerApi.Hooks.NetSendData.Register(Parent.PluginInstance, NetHooks_SendData); ServerApi.Hooks.GameUpdate.Register(Parent.PluginInstance, Game_Update); this.CustomMultiplier = 1; }
protected override void Dispose(bool disposing) { if (disposing) { if (Instance != null) { Instance.Dispose(); Instance = null; } } base.Dispose(disposing); }
public EventHandlers(SEconomy Parent) { this.Parent = Parent; if (Parent.Configuration.PayIntervalMinutes > 0) { PayRunTimer = new System.Timers.Timer(Parent.Configuration.PayIntervalMinutes * 60000); PayRunTimer.Elapsed += PayRunTimer_Elapsed; PayRunTimer.Start(); } TShockAPI.Hooks.PlayerHooks.PlayerPostLogin += PlayerHooks_PlayerPostLogin; Parent.RunningJournal.BankTransferCompleted += BankAccount_BankTransferCompleted; TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; ServerApi.Hooks.GamePostInitialize.Register(this.Parent.PluginInstance, GameHooks_PostInitialize); ServerApi.Hooks.ServerJoin.Register(this.Parent.PluginInstance, ServerHooks_Join); ServerApi.Hooks.ServerLeave.Register(this.Parent.PluginInstance, ServerHooks_Leave); ServerApi.Hooks.NetGetData.Register(this.Parent.PluginInstance, NetHooks_GetData); }
public override void Initialize() { Lang.Localization.PrepareLanguages(); Locale = new Lang.Localization("en-AU"); PrintIntro(); TShockAPI.Commands.ChatCommands.Add(new TShockAPI.Command("seconomy.cmd", TShock_CommandExecuted, "seconomy", "sec")); try { Instance = new SEconomy(this); if (Instance.LoadSEconomy() < 0) { throw new Exception("LoadSEconomy() failed."); } } catch { Instance = null; TShock.Log.ConsoleError(genericErrorMessage); } ServerApi.Hooks.GameInitialize.Register(this, (init) => { }); }
protected async void TShock_CommandExecuted(TShockAPI.CommandArgs args) { if (args.Parameters.Count == 0) { args.Player.SendInfoMessage(string.Format(Locale.StringOrDefault(3, "{0} by Wolfje"), GetVersionString())); args.Player.SendInfoMessage(" * http://plugins.tw.id.au"); args.Player.SendInfoMessage(Locale.StringOrDefault(5, " * /sec[onomy] reload|rl - Reloads SEconomy")); args.Player.SendInfoMessage(Locale.StringOrDefault(6, " * /sec[onomy] stop - Stops and unloads SEconomy")); args.Player.SendInfoMessage(Locale.StringOrDefault(7, " * /sec[onomy] start - Starts SEconomy")); return; } if ((args.Parameters[0].Equals("reload", StringComparison.CurrentCultureIgnoreCase) || args.Parameters[0].Equals("rl", StringComparison.CurrentCultureIgnoreCase)) && args.Player.Group.HasPermission("seconomy.command.reload") == true) { try { await Task.Run(async() => { if (Instance != null) { Instance.Dispose(); Instance = null; RaiseUnloadedEvent(); } try { Instance = new SEconomy(this); if (Instance.LoadSEconomy() < 0) { throw new Exception("LoadSEconomy() failed."); } await Instance.BindToWorldAsync(); RaiseLoadedEvent(); } catch { Instance = null; TShock.Log.ConsoleError(genericErrorMessage); throw; } }); } catch { RaiseUnloadedEvent(); args.Player.SendErrorMessage(Locale.StringOrDefault(12, "SEconomy failed to initialize, and will be unavailable for this session.")); return; } args.Player.SendSuccessMessage(Locale.StringOrDefault(8, "SEconomy is reloaded.")); } else if (args.Parameters[0].Equals("stop", StringComparison.CurrentCultureIgnoreCase) && args.Player.Group.HasPermission("seconomy.command.stop") == true) { if (Instance == null) { args.Player.SendErrorMessage(Locale.StringOrDefault(9, "seconomy stop: SEconomy is already stopped. Use /sec start to start")); return; } await Task.Run(() => { Instance.Dispose(); Instance = null; }); args.Player.SendSuccessMessage(Locale.StringOrDefault(10, "SEconomy is stopped.")); RaiseUnloadedEvent(); } else if (args.Parameters[0].Equals("start", StringComparison.CurrentCultureIgnoreCase) && args.Player.Group.HasPermission("seconomy.command.start") == true) { if (Instance != null) { args.Player.SendErrorMessage(Locale.StringOrDefault(11, "seconomy stop: SEconomy is already started. Use /sec stop to stop.")); return; } try { await Task.Run(async() => { try { Instance = new SEconomy(this); if (Instance.LoadSEconomy() < 0) { throw new Exception("LoadSEconomy() failed."); } await Instance.BindToWorldAsync(); } catch { RaiseUnloadedEvent(); Instance = null; TShock.Log.ConsoleError(genericErrorMessage); throw; } }); } catch { args.Player.SendErrorMessage(Locale.StringOrDefault(12, "SEconomy failed to initialize, and will be unavailable for this session.")); return; } args.Player.SendSuccessMessage(Locale.StringOrDefault(13, "SEconomy has started.")); RaiseLoadedEvent(); } else if ((args.Parameters[0].Equals("multi", StringComparison.CurrentCultureIgnoreCase) || args.Parameters[0].Equals("multiplier", StringComparison.CurrentCultureIgnoreCase)) && args.Player.Group.HasPermission("seconomy.command.multi") == true) { RaiseUnloadedEvent(); int multi = 0; if (args.Parameters.Count == 1) { args.Player.SendInfoMessage("sec multi: Reward multiplier: {0}", SEconomyPlugin.Instance.WorldEc.CustomMultiplier); return; } if (int.TryParse(args.Parameters[1], out multi) == false || multi < 0 || multi > 100) { args.Player.SendErrorMessage("sec multi: Syntax: /sec multi[plier] 1-100"); return; } SEconomyPlugin.Instance.WorldEc.CustomMultiplier = multi; args.Player.SendInfoMessage("sec multi: Multiplier of {0} set successfully.", multi); } }
protected async void TShock_CommandExecuted(TShockAPI.CommandArgs args) { if (args.Parameters.Count == 0) { args.Player.SendInfoMessage(string.Format(Locale.StringOrDefault(3, "{0} by Wolfje"), GetVersionString())); args.Player.SendInfoMessage(" * http://plugins.tw.id.au"); args.Player.SendInfoMessage(Locale.StringOrDefault(5, " * /sec[onomy] reload|rl - Reloads SEconomy")); args.Player.SendInfoMessage(Locale.StringOrDefault(6, " * /sec[onomy] stop - Stops and unloads SEconomy")); args.Player.SendInfoMessage(Locale.StringOrDefault(7, " * /sec[onomy] start - Starts SEconomy")); return; } if ((args.Parameters[0].Equals("reload", StringComparison.CurrentCultureIgnoreCase) || args.Parameters[0].Equals("rl", StringComparison.CurrentCultureIgnoreCase)) && args.Player.Group.HasPermission("seconomy.command.reload") == true) { try { await Task.Run(async () => { if (Instance != null) { Instance.Dispose(); Instance = null; RaiseUnloadedEvent(); } try { Instance = new SEconomy(this); if (Instance.LoadSEconomy() < 0) { throw new Exception("LoadSEconomy() failed."); } await Instance.BindToWorldAsync(); RaiseLoadedEvent(); } catch { Instance = null; TShock.Log.ConsoleError(genericErrorMessage); throw; } }); } catch { RaiseUnloadedEvent(); args.Player.SendErrorMessage(Locale.StringOrDefault(12, "SEconomy failed to initialize, and will be unavailable for this session.")); return; } args.Player.SendSuccessMessage(Locale.StringOrDefault(8, "SEconomy is reloaded.")); } else if (args.Parameters[0].Equals("stop", StringComparison.CurrentCultureIgnoreCase) && args.Player.Group.HasPermission("seconomy.command.stop") == true) { if (Instance == null) { args.Player.SendErrorMessage(Locale.StringOrDefault(9, "seconomy stop: SEconomy is already stopped. Use /sec start to start")); return; } await Task.Run(() => { Instance.Dispose(); Instance = null; }); args.Player.SendSuccessMessage(Locale.StringOrDefault(10, "SEconomy is stopped.")); RaiseUnloadedEvent(); } else if (args.Parameters[0].Equals("start", StringComparison.CurrentCultureIgnoreCase) && args.Player.Group.HasPermission("seconomy.command.start") == true) { if (Instance != null) { args.Player.SendErrorMessage(Locale.StringOrDefault(11, "seconomy stop: SEconomy is already started. Use /sec stop to stop.")); return; } try { await Task.Run(async () => { try { Instance = new SEconomy(this); if (Instance.LoadSEconomy() < 0) { throw new Exception("LoadSEconomy() failed."); } await Instance.BindToWorldAsync(); } catch { RaiseUnloadedEvent(); Instance = null; TShock.Log.ConsoleError(genericErrorMessage); throw; } }); } catch { args.Player.SendErrorMessage(Locale.StringOrDefault(12, "SEconomy failed to initialize, and will be unavailable for this session.")); return; } args.Player.SendSuccessMessage(Locale.StringOrDefault(13, "SEconomy has started.")); RaiseLoadedEvent(); } else if ((args.Parameters[0].Equals("multi", StringComparison.CurrentCultureIgnoreCase) || args.Parameters[0].Equals("multiplier", StringComparison.CurrentCultureIgnoreCase)) && args.Player.Group.HasPermission("seconomy.command.multi") == true) { RaiseUnloadedEvent(); int multi = 0; if (args.Parameters.Count == 1) { args.Player.SendInfoMessage("sec multi: Reward multiplier: {0}", SEconomyPlugin.Instance.WorldEc.CustomMultiplier); return; } if (int.TryParse(args.Parameters[1], out multi) == false || multi < 0 || multi > 100) { args.Player.SendErrorMessage("sec multi: Syntax: /sec multi[plier] 1-100"); return; } SEconomyPlugin.Instance.WorldEc.CustomMultiplier = multi; args.Player.SendInfoMessage("sec multi: Multiplier of {0} set successfully.", multi); } }
protected void Process() { sec = new SEconomy(null); SEconomyPlugin.Instance = sec; XmlTransactionJournal journal = null; int oldPercent = 0, skipped = 0; Dictionary<long, long> oldNewTransactions = new Dictionary<long, long>(); JournalLoadingPercentChangedEventArgs args = new JournalLoadingPercentChangedEventArgs() { Label = "Accounts" }; sec.Configuration = Config.FromFile(Config.BaseDirectory + Path.DirectorySeparatorChar + "seconomy.config.json"); journal = new XmlTransactionJournal(sec, Config.BaseDirectory + Path.DirectorySeparatorChar + "SEconomy.journal.xml.gz"); JournalLoadingPercentChanged += journal_JournalLoadingPercentChanged; journal.JournalLoadingPercentChanged += journal_JournalLoadingPercentChanged; journal.LoadJournal(); Console.WriteLine(); if (DatabaseExists() == false) { Console.WriteLine("Your SEconomy database does not exist. Create it?"); Console.Write("[y/n] "); if (Console.ReadKey().KeyChar != 'y') { return; } CreateDatabase(); } Console.WriteLine("Your SEconomy database will be flushed. All accounts, and transactions will be deleted before the import."); Console.Write("Continue? [y/n] "); if (Console.ReadKey().KeyChar != 'y') { return; } Console.WriteLine(); Connection.Query(string.Format("DELETE FROM `{0}`.`bank_account`;", sec.Configuration.SQLConnectionProperties.DbName)); Connection.Query(string.Format("ALTER TABLE `{0}`.`bank_account` AUTO_INCREMENT 0;", sec.Configuration.SQLConnectionProperties.DbName)); Connection.Query(string.Format("DELETE FROM `{0}`.`bank_account_transaction`;", sec.Configuration.SQLConnectionProperties.DbName)); Connection.Query(string.Format("ALTER TABLE `{0}`.`bank_account_transaction` AUTO_INCREMENT 0;", sec.Configuration.SQLConnectionProperties.DbName)); Console.WriteLine("This will probably take a while...\r\n"); Console.WriteLine(); if (JournalLoadingPercentChanged != null) { JournalLoadingPercentChanged(null, args); } for (int i = 0; i < journal.BankAccounts.Count; i++) { IBankAccount account = journal.BankAccounts.ElementAtOrDefault(i); double percentComplete = (double)i / (double)journal.BankAccounts.Count * 100; long id = -1; string query = null; if (account == null) { continue; } query = @"INSERT INTO `bank_account` (user_account_name, world_id, flags, flags2, description, old_bank_account_k) VALUES (@0, @1, @2, @3, @4, @5);"; try { Connection.QueryIdentity(query, out id, account.UserAccountName, account.WorldID, (int)account.Flags, 0, account.Description, account.BankAccountK); } catch (Exception ex) { TShock.Log.ConsoleError(" seconomy mysql: sql error adding bank account: " + ex.ToString()); continue; } for (int t = 0; t < account.Transactions.Count(); t++) { long tranId = -1; ITransaction transaction = account.Transactions.ElementAtOrDefault(t); string txQuery = @"INSERT INTO `bank_account_transaction` (bank_account_fk, amount, message, flags, flags2, transaction_date_utc, old_bank_account_transaction_k) VALUES (@0, @1, @2, @3, @4, @5, @6);"; try { Connection.QueryIdentity(txQuery, out tranId, id, (long)transaction.Amount, transaction.Message, (int)BankAccountTransactionFlags.FundsAvailable, (int)transaction.Flags2, transaction.TransactionDateUtc, transaction.BankAccountTransactionK); if (oldNewTransactions.ContainsKey(transaction.BankAccountTransactionK) == false) { oldNewTransactions[transaction.BankAccountTransactionK] = tranId; } } catch (Exception ex) { TShock.Log.ConsoleError(" seconomy mysql: Database error in BeginSourceTransaction: " + ex.Message); continue; } } if (oldPercent != (int)percentComplete) { args.Percent = (int)percentComplete; if (JournalLoadingPercentChanged != null) { JournalLoadingPercentChanged(null, args); } oldPercent = (int)percentComplete; } } args.Label = "Reseed"; args.Percent = 0; if (JournalLoadingPercentChanged != null) { JournalLoadingPercentChanged(null, args); } string updateQuery = @"update bank_account_transaction as OLDT inner join ( select bank_account_transaction_id, old_bank_account_transaction_k from bank_account_transaction ) as NEWT on OLDT.old_bank_account_transaction_k = NEWT.old_bank_account_transaction_k set OLDT.bank_account_transaction_fk = NEWT.bank_account_transaction_id"; Connection.Query(updateQuery); Connection.Query("update `bank_account_transaction` set `old_bank_account_transaction_k` = null;"); args.Percent = 100; if (JournalLoadingPercentChanged != null) { JournalLoadingPercentChanged(null, args); } Console.WriteLine("import complete", skipped); Console.WriteLine("Press any key to exit"); Console.Read(); }