Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extra chars in buffer from leaking into module #311

Merged
merged 3 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MBBSEmu.Tests/Integration/MBBSEmuIntegrationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected void ExecuteTest(TestLogic testLogic)
var host = _serviceResolver.GetService<IMbbsHost>();
var moduleConfigurations = new List<ModuleConfiguration>
{
new ModuleConfiguration {ModuleIdentifier = "MBBSEMU", ModulePath = _modulePath, MenuOptionKey = null}
new ModuleConfiguration {ModuleIdentifier = "MBBSEMU", ModulePath = _modulePath, MenuOptionKey = "A"}
};

host.Start(moduleConfigurations);
Expand Down
2 changes: 0 additions & 2 deletions MBBSEmu/HostProcess/ExportedModules/Majorbbs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1429,8 +1429,6 @@ private void register_module()
_logger.Info($"MODULE pointer ({Module.Memory.GetVariablePointer("MODULE") + (Module.StateCode * 2)}) set to {localModuleStructPointer}");
_logger.Info($"Module Description set to {Module.ModuleDescription}");
#endif

if (string.IsNullOrEmpty(Module.MenuOptionKey)) Module.MenuOptionKey = (Module.StateCode + 1).ToString();
}

/// <summary>
Expand Down
34 changes: 31 additions & 3 deletions MBBSEmu/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,33 @@ private void Run(string[] args) {
}
else if (_isModuleConfigFile)
{
//Load Menu Option Keys
var menuOptionKeyList = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789".ToCharArray().ToList();

//Load Config File
var moduleConfiguration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(_moduleConfigFileName, optional: false, reloadOnChange: true).Build();

foreach (var m in moduleConfiguration.GetSection("Modules").GetChildren())
{
//Check for Non Character MenuOptionKey or duplicate MenuOptionKey
if (!string.IsNullOrEmpty(m["MenuOptionKey"]) && (!char.IsLetter(m["MenuOptionKey"][0]) || _moduleConfigurations.Any(x => x.MenuOptionKey == m["MenuOptionKey"])))
//Check for available MenuOptionKeys
if (menuOptionKeyList.Count < 1)
{
_logger.Error($"Maximum module limit reached -- {m["Identifier"]} not loaded");
continue;
}

//Check for Non Character MenuOptionKey
if (!string.IsNullOrEmpty(m["MenuOptionKey"]) && (!char.IsLetter(m["MenuOptionKey"][0])))
{
_logger.Error($"Invalid menu option key for {m["Identifier"]}, module not loaded");
_logger.Error($"Invalid menu option key (NOT A-Z) for {m["Identifier"]}, module not loaded");
continue;
}

//Check for duplicate MenuOptionKey
if (!string.IsNullOrEmpty(m["MenuOptionKey"]) && _moduleConfigurations.Any(x => x.MenuOptionKey == m["MenuOptionKey"]))
{
_logger.Error($"Duplicate menu option key for {m["Identifier"]}, module not loaded");
continue;
}

Expand All @@ -255,6 +272,17 @@ private void Run(string[] args) {
continue;
}

//If MenuOptionKey, remove from allowable list
if (!string.IsNullOrEmpty(m["MenuOptionKey"]))
menuOptionKeyList.Remove(char.Parse(m["MenuOptionKey"]));

//Check for missing MenuOptionKey, assign, remove from allowable list
if (string.IsNullOrEmpty(m["MenuOptionKey"]))
{
m["MenuOptionKey"] = menuOptionKeyList[0].ToString();
menuOptionKeyList.RemoveAt(0);
}

//Load Modules
_logger.Info($"Loading {m["Identifier"]}");
_moduleConfigurations.Add(new ModuleConfiguration { ModuleIdentifier = m["Identifier"], ModulePath = m["Path"], MenuOptionKey = m["MenuOptionKey"]});
Expand Down