public static void Main(string[] args) { CommandLineParser cmd = CommandLineParser.Parse(args); Log.CreateInstance(true); string keyText = null; if (cmd["key"] != null) { keyText = cmd["key"].Value; } else { keyText = PasswordPrompt.Get("Please enter the encryption key"); string keyText2 = PasswordPrompt.Get("Please confirm the encryption key"); if (keyText != keyText2) { Log.Instance.Write(Log_Severity.Fatal, "Keys did not match"); } } if (cmd["to"] == null || cmd["from"] == null) { Log.Instance.Write(Log_Severity.Fatal, "Need arguments 'to' and 'from'"); } ulong sender = ulong.Parse(cmd["from"].Value); ulong recipient = ulong.Parse(cmd["to"].Value); var mt = new MersenneTwister((uint)Guid.NewGuid().GetHashCode()); var key = Encoding.UTF8.GetBytes(keyText); if (sender == 0) { sender = mt.NextULong(); } if (recipient == 0) { recipient = mt.NextULong(); } var iv = mt.NextBytes(BLOCK_SIZE); var data = BitShifter.ToByte(sender).Concat(BitShifter.ToByte(recipient)).ToArray(); BufferedBlockCipher cipher = new CtsBlockCipher(new CbcBlockCipher(new AesEngine())); ICipherParameters keyParam = new ParametersWithIV(new KeyParameter(key), iv); cipher.Init(true, keyParam); Log.Instance.Write(iv.Concat(cipher.DoFinal(data, 0, data.Length)).ToArray().ToHex()); }
public static void Main(string[] args) { CommandLineParser cmd = CommandLineParser.Parse(args); Log.CreateInstance(true); if (cmd["random"] != null) { int count = 0; if (!int.TryParse(cmd["random"].Value, out count)) { count = 10; } for (int i = 0; i < count; i++) { string text = StringHelper.GenerateRandomString(32); string key = StringHelper.GenerateRandomString(32); byte[] b64 = Convert.FromBase64String(text.Encrypt(key)); byte[] result = Reduce(Reduce(SHA256.Create().ComputeHash(b64))); Log.Instance.Write(Log_Severity.None, $"Random {i}: {result.ToHex()}"); } return; } string pw = null; if (cmd["password"] != null) { pw = cmd["password"].Value; } else { pw = PasswordPrompt.Get(); string pw2 = PasswordPrompt.Get("Please confirm your password"); if (pw != pw2) { Log.Instance.Write(Log_Severity.Fatal, "Passwords did not match"); } } if (cmd["encrypt"] != null) { string text = cmd["encrypt"].Value; if (File.Exists(text)) { text = File.ReadAllText(text); } try { Log.Instance.Write(Log_Severity.None, text.Encrypt(pw)); } catch { Log.Instance.Write(Log_Severity.Fatal, "Encryption failed"); } } if (cmd["decrypt"] != null) { string text = cmd["decrypt"].Value; if (File.Exists(text)) { text = File.ReadAllText(text); } try { Log.Instance.Write(Log_Severity.None, text.Decrypt(pw)); } catch { Log.Instance.Write(Log_Severity.Fatal, "Decryption failed"); } } }
public async Task MainAsync(string[] args) { CommandLineParser cmd = CommandLineParser.Parse(args); AngryWasp.Logger.Log.CreateInstance(true); string token = null; string botAssembly = null; if (cmd["token"] != null) { await Log.Write("Token loaded from command line"); token = cmd["token"].Value; } if (token == null && cmd["token-file"] != null) { await Log.Write("Token loaded from file"); token = File.ReadAllText(cmd["token-file"].Value); } if (token == null) { await Log.Write(Log_Severity.Fatal, "Bot token not provided!"); Environment.Exit(0); } else { await Log.Write($"Loaded token {token}"); } string pw = null; string decryptedToken = null; if (cmd["password"] != null) { pw = cmd["password"].Value; } else { pw = PasswordPrompt.Get("Please enter your token decryption password"); } try { decryptedToken = token.Decrypt(pw); } catch { await Log.Write(Log_Severity.Fatal, "Incorrect password"); Environment.Exit(0); } if (cmd["bot"] == null) { await Log.Write(Log_Severity.Fatal, "Bot plugin not provided!"); Environment.Exit(0); } else { botAssembly = cmd["bot"].Value; } if (!File.Exists(botAssembly)) { await Log.Write(Log_Severity.Fatal, "Bot plugin bot found!"); Environment.Exit(0); } if (cmd["debug"] != null) { Globals.RpcLogConfig = Nerva.Rpc.Log.Presets.Normal; } List <int> errorCodes = new List <int>(); for (int i = 0; i < cmd.Count; i++) { if (cmd[i].Flag == "debug-hide") { int j = 0; if (int.TryParse(cmd[i].Value, out j)) { errorCodes.Add(-j); } } } if (errorCodes.Count > 0) { Globals.RpcLogConfig.SuppressRpcCodes = errorCodes; } //load plugin Globals.BotAssembly = ReflectionHelper.Instance.LoadAssemblyFile(botAssembly); Type botPluginType = ReflectionHelper.Instance.GetTypesInheritingOrImplementing(Globals.BotAssembly, typeof(IBot))[0]; Globals.Bot = (IBot)Activator.CreateInstance(botPluginType); List <Type> botCommands = ReflectionHelper.Instance.GetTypesInheritingOrImplementing(Globals.BotAssembly, typeof(ICommand)); //common commands for all bots botCommands.Add(typeof(Help)); botCommands.Add(typeof(Ping)); Globals.Bot.Init(cmd); var client = new DiscordSocketClient(); Globals.Client = client; client.Log += Log.Write; await client.LoginAsync(TokenType.Bot, decryptedToken); await client.StartAsync(); foreach (Type t in botCommands) { CommandAttribute ca = t.GetCustomAttribute(typeof(CommandAttribute)) as CommandAttribute; if (ca == null) { continue; } Globals.BotHelp.Add($"{Globals.Bot.Config.CmdPrefix}{ca.Cmd}", ca.Help); Globals.Commands.Add($"{Globals.Bot.Config.CmdPrefix}{ca.Cmd}", t); } client.MessageReceived += MessageReceived; client.Ready += ClientReady; await Task.Delay(-1); }
public void Init(CommandLineParser cmd) { AngryWasp.Serializer.Serializer.Initialize(); if (cmd["donation-wallet-port"] != null) { cfg.DonationWalletPort = uint.Parse(cmd["donation-wallet-port"].Value); } if (cmd["user-wallet-port"] != null) { cfg.UserWalletPort = uint.Parse(cmd["user-wallet-port"].Value); } string donationWalletFile = string.Empty, donationWalletPassword = string.Empty; string userWalletFile = string.Empty, userWalletPassword = string.Empty; if (cmd["key-file"] != null) { string[] keys = File.ReadAllLines(cmd["key-file"].Value); string keyFilePassword = PasswordPrompt.Get("Please enter the key file decryption password"); donationWalletPassword = keys[0].Decrypt(keyFilePassword); userWalletPassword = keys[1].Decrypt(keyFilePassword); cfg.DonationPaymentIdKey = keys[2].Decrypt(keyFilePassword); keyFilePassword = null; } else { donationWalletPassword = PasswordPrompt.Get("Please enter the donation wallet password"); userWalletPassword = PasswordPrompt.Get("Please enter the user wallet password"); cfg.DonationPaymentIdKey = PasswordPrompt.Get("Please enter the payment id encryption key"); } if (cmd["donation-wallet-file"] != null) { donationWalletFile = cmd["donation-wallet-file"].Value; } if (cmd["user-wallet-file"] != null) { userWalletFile = cmd["user-wallet-file"].Value; } string jsonFile = Path.Combine(Environment.CurrentDirectory, $"Wallets/{donationWalletFile}.json"); Log.Write($"Loading Wallet JSON: {jsonFile}"); cfg.AccountJson = JsonConvert.DeserializeObject <AccountJson>(File.ReadAllText(jsonFile)); new OpenWallet(new OpenWalletRequestData { FileName = donationWalletFile, Password = donationWalletPassword }, (string result) => { Log.Write("Wallet loaded"); }, (RequestError error) => { Log.Write("Failed to load donation wallet"); Environment.Exit(1); }, cfg.WalletHost, cfg.DonationWalletPort).Run(); new OpenWallet(new OpenWalletRequestData { FileName = userWalletFile, Password = userWalletPassword }, (string r1) => { Log.Write("Wallet loaded"); new GetAccounts(null, (GetAccountsResponseData r2) => { foreach (var a in r2.Accounts) { ulong uid = 0; if (ulong.TryParse(a.Label, out uid)) { if (!cfg.UserWalletCache.ContainsKey(uid)) { cfg.UserWalletCache.Add(uid, new Tuple <uint, string>(a.Index, a.BaseAddress)); Log.Write($"Loaded wallet for user: {a.Label} - {a.BaseAddress}"); } else { Log.Write($"Duplicate wallet detected for user with id: {uid}"); } } else { //fusion owns address index 0 if (a.Index == 0) { cfg.UserWalletCache.Add(cfg.BotId, new Tuple <uint, string>(a.Index, a.BaseAddress)); } else { Log.Write($"Account index {a.Index} is not associated with a user"); } } } }, (RequestError error) => { Log.Write("Failed to load user wallet"); Environment.Exit(1); }, cfg.WalletHost, cfg.UserWalletPort).Run(); }, (RequestError error) => { Log.Write("Failed to load user wallet"); Environment.Exit(1); }, cfg.WalletHost, cfg.UserWalletPort).Run(); //todo: Check if an existing game is still running after restart and load that instead string fp = Path.Combine(Environment.CurrentDirectory, "lottery.xml"); if (File.Exists(fp)) { LotteryManager.Load(fp); } else { LotteryManager.Start(); } }