Skip to content

Commit

Permalink
Added try-catch on each line, and now ignores blank lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Smaltin committed Jul 16, 2024
1 parent 8864874 commit 0fe1885
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions MDRP/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,36 +1172,47 @@ private static void LoadSettings()
try
{
string[] lines = File.ReadAllLines("../../../SupportedPlayers.dat");
int iterator = 0;
foreach (string line in lines)
{
if (!line.StartsWith("#"))
iterator++;
if (!line.StartsWith("#") && !string.IsNullOrWhiteSpace(line))
{
string[] explodedLine = Regex.Split(line, @"==");
if (bool.Parse(explodedLine[2]))
try
{
//Format: executable name==display name==enabled==discord application id==console color==asset link
string execName = explodedLine[0];
string displayName = explodedLine[1];
string appid = explodedLine[3];
ConsoleColor color = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), explodedLine[4], true);
string assetLink = explodedLine[5];

DefaultClients.Add(execName, new DiscordRpcClient(appid, autoEvents: false));
PlayerColors.Add(execName, color);
Aliases.Add(execName, displayName);
BigAssets.Add(execName, assetLink);
LittleAssets.Add(execName, assetLink);
Whatpeoplecallthisplayer.Add(execName, displayName);
if (!InverseWhatpeoplecallthisplayer.ContainsKey(displayName))
InverseWhatpeoplecallthisplayer.Add(displayName, execName);
ValidPlayers.Add(execName);
string[] explodedLine = Regex.Split(line, @"==");
if (bool.Parse(explodedLine[2]))
{
//Format: executable name==display name==enabled==discord application id==console color==asset link
string execName = explodedLine[0];
string displayName = explodedLine[1];
string appid = explodedLine[3];
ConsoleColor color =
(ConsoleColor)Enum.Parse(typeof(ConsoleColor), explodedLine[4], true);
string assetLink = explodedLine[5];

DefaultClients.Add(execName, new DiscordRpcClient(appid, autoEvents: false));
PlayerColors.Add(execName, color);
Aliases.Add(execName, displayName);
BigAssets.Add(execName, assetLink);
LittleAssets.Add(execName, assetLink);
Whatpeoplecallthisplayer.Add(execName, displayName);
if (!InverseWhatpeoplecallthisplayer.ContainsKey(displayName))
InverseWhatpeoplecallthisplayer.Add(displayName, execName);
ValidPlayers.Add(execName);
}
}
catch (Exception e)
{
Functions.SendToDebugServer(e);
Functions.SendToDebugServer("Invalid formatting on line " + iterator + ". Please follow the format 'executable name==display name==enabled==discord application id==console color==asset link'");
}
}
}
}
catch (Exception e)
{
Functions.SendToDebugServer("SupportedPlayers.dat INVALID"); //either no perms or formatted incorrectly
Functions.SendToDebugServer("SupportedPlayers.dat could not be found");
Functions.SendToDebugServer(e);
}
try
Expand Down
Binary file modified MDRP/bin/Release/MDRP.exe
Binary file not shown.

0 comments on commit 0fe1885

Please sign in to comment.