public Interpreter(IConveyor c) { this.Conveyor = c; // Reflect over all of the IHashCommands that are available. var type = typeof(IHashCommand); var types = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(x => x.GetTypes()) .Where(x => type.IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract); foreach (var t in types) { var cmd = (IHashCommand)Activator.CreateInstance(t, this); HashCommands.Add(cmd); } }
public Interpreter() { this.Conveyor = AppServices.GetService <Conveyor>(); // Reflect over all of the IHashCommands that are available. var type = typeof(IHashCommand); var types = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(x => x.GetTypes()) .Where(x => type.IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract); foreach (var t in types) { var cmd = (IHashCommand)Activator.CreateInstance(t, this); HashCommands.Add(cmd); } // Setup the scripting environment. Error handlers are set here allowing the actual scripting // environment to stay generic while the client worries about the implementation details. _scriptCommands = new ScriptCommands(this); _winScriptCommands = new WindowScriptCommands(this); this.MoonSharpInit(); }
public Task <string[]> HKeysAsync(string key) => MultiAsync(HashCommands.HKeys(key));
public string[] HKeys(string key) => Multi(HashCommands.HKeys(key));
public Task <double?> HIncrByFloatAsync(string key, string field, double increment) => MultiAsync(HashCommands.HIncrByFloat(key, field, increment));
public Task <bool> HSetNxAsync(string key, string field, object value) => MultiAsync(HashCommands.HSetNx(key, field, value));
public Task <string> HMSetAsync(string key, Dictionary <string, string> dict) => MultiAsync(HashCommands.HMSet(key, dict));
public string[] HMGet(string key, params string[] fields) => Multi(HashCommands.HMGet(key, fields));
public Dictionary <string, string> HGetAll(string key) => Multi(HashCommands.HGetAll(key));
public Task <string> HGetAsync(string key, string field) => MultiAsync(HashCommands.HGet(key, field));
public string HGet(string key, string field) => Multi(HashCommands.HGet(key, field));
public Task <bool> HExistsAsync(string key, string field) => MultiAsync(HashCommands.HExists(key, field));
public bool HExists(string key, string field) => Multi(HashCommands.HExists(key, field));
public Task <long> HDelAsync(string key, params string[] fields) => MultiAsync(HashCommands.HDel(key, fields));
public long HDel(string key, params string[] fields) => Multi(HashCommands.HDel(key, fields));
public long HLen(string key) => Multi(HashCommands.HLen(key));
public Task <long> HLenAsync(string key) => MultiAsync(HashCommands.HLen(key));
public Task <Dictionary <string, string> > HGetAllAsync(string key) => MultiAsync(HashCommands.HGetAll(key));
public string HMSet(string key, Dictionary <string, string> dict) => Multi(HashCommands.HMSet(key, dict));
public long HIncrBy(string key, string field, long increment) => Multi(HashCommands.HIncrBy(key, field, increment));
public bool HSetNx(string key, string field, object value) => Multi(HashCommands.HSetNx(key, field, value));
public Task <long> HIncrByAsync(string key, string field, long increment) => MultiAsync(HashCommands.HIncrBy(key, field, increment));
/// <summary> /// Sends a command string to the mud. /// </summary> /// <param name="cmd"></param> /// <param name="silent">Whether the commands should be outputted to the game window.</param> public async Task Send(string cmd, bool silent, bool addToInputHistory) { // Add the whole thing to the command history if (addToInputHistory) { AddInputHistory(cmd); } _aliasRecursionDepth = 0; var cmdList = ParseCommand(cmd); foreach (string item in cmdList) { if (Telnet == null) { Conveyor.EchoLog("You are not connected to the game.", LogType.Error); return; } try { if (item.SafeLeft(1) != "#") { // Show the command in the window that was sent. if (!silent) { EchoText(item, AnsiColors.Yellow); } // Spam guard if (App.Settings.ProfileSettings.SpamGuard) { // TODO, make this check carriage return and > 1 instead of > 2 if (_spamGuardLastCommand == item && item.Length > 2) { // Increment, we don't need to change the last command, it was the same. _spamGuardCounter++; } else { _spamGuardLastCommand = item; _spamGuardCounter = 0; } if (_spamGuardCounter == 15) { EchoText("where", AnsiColors.Yellow); await Telnet.Send("where"); _spamGuardCounter = 0; } } await Telnet.Send(item); } else { var hashCmd = HashCommands.FirstOrDefault(x => x.Name == item.FirstWord()); if (hashCmd == null) { Conveyor.EchoLog($"Hash command '{item.FirstWord()}' was not found.\r\n", LogType.Error); } else { string parameters = item.RemoveWord(1); hashCmd.Parameters = parameters; if (hashCmd.IsAsync) { await hashCmd.ExecuteAsync(); } else { hashCmd.Execute(); } } } } catch (Exception ex) { EchoText(ex.Message, AnsiColors.Red); } } }
public double?HIncrByFloat(string key, string field, double increment) => Multi(HashCommands.HIncrByFloat(key, field, increment));