diff --git a/ClassicalSharp/Program.cs b/ClassicalSharp/Program.cs index 3f4009805..3a65fe221 100644 --- a/ClassicalSharp/Program.cs +++ b/ClassicalSharp/Program.cs @@ -18,13 +18,37 @@ namespace ClassicalSharp { string defPath = Path.Combine("texpacks", "default.zip"); if (!Platform.FileExists(defPath)) { - ErrorHandler.ShowDialog("Missing file", "default.zip not found, try running the launcher first."); + ErrorHandler.ShowDialog("Failed to start", "default.zip is missing, try running the launcher first."); return; } ErrorHandler.InstallHandler("client.log"); OpenTK.Configuration.SkipPerfCountersHack(); Utils.LogDebug("Starting " + AppName + ".."); + + IPAddress ip = null; + int port = 0; + string user = null, mppass = null; + string skinServer = "http://static.classicube.net/skins/"; + + if (args.Length == 0 || args.Length == 1) { + user = args.Length > 0 ? args[0] : "Singleplayer"; + } else if (args.Length < 4) { + ErrorHandler.ShowDialog("Failed to start", "ClassicalSharp.exe is only the raw client\n\n." + + "Use the launcher instead, or provide command line arguments."); + return; + } else { + user = args[0]; + mppass = args[1]; + if (args.Length > 4) skinServer = args[4]; + + if (!IPAddress.TryParse(args[2], out ip)) { + ErrorHandler.ShowDialog("Failed to start", "Invalid IP " + args[2]); return; + } + if (!Int32.TryParse(args[3], out port) || port < 0 || port > ushort.MaxValue) { + ErrorHandler.ShowDialog("Failed to start", "Invalid port " + args[3]); return; + } + } Options.Load(); DisplayDevice device = DisplayDevice.Default; @@ -37,36 +61,7 @@ namespace ClassicalSharp { if (device.Bounds.Width < 854) width = 640; } - if (args.Length == 0 || args.Length == 1) { - const string skinServer = "http://static.classicube.net/skins/"; - string user = args.Length > 0 ? args[0] : "Singleplayer"; - using (Game game = new Game(user, null, skinServer, width, height)) - game.Run(); - } else if (args.Length < 4) { - Utils.LogDebug("ClassicalSharp.exe is only the raw client. You must either use the launcher or" - + " provide command line arguments to start the client."); - } else { - RunMultiplayer(args, width, height); - } - } - - static void RunMultiplayer(string[] args, int width, int height) { - IPAddress ip = null; - if (!IPAddress.TryParse(args[2], out ip)) { - Utils.LogDebug("Invalid IP \"" + args[2] + '"'); return; - } - - int port = 0; - if (!Int32.TryParse(args[3], out port)) { - Utils.LogDebug("Invalid port \"" + args[3] + '"'); - return; - } else if (port < ushort.MinValue || port > ushort.MaxValue) { - Utils.LogDebug("Specified port " + port + " is out of valid range."); - return; - } - - string skinServer = args.Length >= 5 ? args[4] : "http://static.classicube.net/skins/"; - using (Game game = new Game(args[0], args[1], skinServer, width, height)) { + using (Game game = new Game(user, mppass, skinServer, width, height)) { game.IPAddress = ip; game.Port = port; game.Run(); diff --git a/src/ErrorHandler.c b/src/ErrorHandler.c index 031c78283..6b4a0161d 100644 --- a/src/ErrorHandler.c +++ b/src/ErrorHandler.c @@ -11,11 +11,9 @@ void ErrorHandler_FailWithCode(ReturnCode result, const char* raw_msg) { char logMsgBuffer[3070 + 1] = { 0 }; String logMsg = { logMsgBuffer, 0, 3070 }; - String_Format3(&logMsg, "ClassiCube crashed.%cMessge: %c%c", - Platform_NewLine, raw_msg, Platform_NewLine); - if (result) { - String_Format2(&logMsg, "%y%c", &result, Platform_NewLine); - } else { result = 1; } + String_Format1(&logMsg, "ClassiCube crashed.\nMessge: %c\n", raw_msg); + if (result) { String_Format1(&logMsg, "%y\n", &result); } + else { result = 1; } ErrorHandler_Backtrace(&logMsg); /* TODO: write to log file */ diff --git a/src/Program.c b/src/Program.c index 76149ba59..12786b5a8 100644 --- a/src/Program.c +++ b/src/Program.c @@ -53,15 +53,6 @@ int main(void) { main_imdct(); #endif - /*Http_Init(); - AsyncRequest req = { 0 }; - String url = String_FromArray(req.URL); - String_AppendConst(&url, "http://static.classicube.net/skins/UnknownShadow200.png"); - void* reqHandle = NULL; - ReturnCode ret = Http_MakeRequest(&req, &reqHandle); - ReturnCode ret2 = Http_FreeRequest(reqHandle); - ReturnCode ret3 = Http_Free();*/ - Utils_EnsureDirectory("maps"); Utils_EnsureDirectory("texpacks"); Utils_EnsureDirectory("texturecache"); @@ -71,14 +62,48 @@ int main(void) { String_Format1(&defPath, "texpacks%rdefault.zip", &Directory_Separator); if (!File_Exists(&defPath)) { - ErrorHandler_ShowDialog("Missing file", "default.zip missing, try running launcher first"); - Platform_Exit(1); - return 1; + ErrorHandler_ShowDialog("Failed to start", "default.zip is missing, try running launcher first"); + Platform_Exit(1); return 1; } Platform_LogConst("Starting " PROGRAM_APP_NAME " .."); - Options_Load(); + String title = String_FromConst(PROGRAM_APP_NAME); + String rawArgs = Platform_GetCommandLineArgs(); + /* NOTE: Make sure to comment this out before pushing a commit */ + //rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.1 25565"); + String args[5]; Int32 argsCount = Array_Elems(args); + String_UNSAFE_Split(&rawArgs, ' ', args, &argsCount); + + if (argsCount == 1) { + String name = args[0]; + if (!name.length) name = String_FromReadonly("Singleplayer"); + String_Copy(&Game_Username, &name); + } else if (argsCount < 4) { + ErrorHandler_ShowDialog("Failed to start", "ClassiCube.exe is only the raw client.\n\n" \ + "Use the launcher instead, or provide command line arguments"); + Platform_Exit(1); + return 1; + } else { + String_Copy(&Game_Username, &args[0]); + String_Copy(&Game_Mppass, &args[1]); + String_Copy(&Game_IPAddress, &args[2]); + + UInt8 ip[4]; + if (!Utils_ParseIP(&args[2], ip)) { + ErrorHandler_ShowDialog("Failed to start", "Invalid IP"); + Platform_Exit(1); return 1; + } + + UInt16 port; + if (!Convert_TryParseUInt16(&args[3], &port)) { + ErrorHandler_ShowDialog("Failed to start", "Invalid port"); + Platform_Exit(1); return 1; + } + Game_Port = port; + } + + Options_Load(); struct DisplayDevice device = DisplayDevice_Default; Int32 width = Options_GetInt(OPT_WINDOW_WIDTH, 0, device.Bounds.Width, 0); Int32 height = Options_GetInt(OPT_WINDOW_HEIGHT, 0, device.Bounds.Height, 0); @@ -89,40 +114,6 @@ int main(void) { if (device.Bounds.Width < 854) width = 640; } - String title = String_FromConst(PROGRAM_APP_NAME); - String rawArgs = Platform_GetCommandLineArgs(); - /* NOTE: Make sure to comment this out before pushing a commit */ - //rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.0.1 25565"); - - String args[5]; Int32 argsCount = Array_Elems(args); - String_UNSAFE_Split(&rawArgs, ' ', args, &argsCount); - - if (argsCount == 1) { - String name = args[0]; - if (!name.length) name = String_FromReadonly("Singleplayer"); - String_Copy(&Game_Username, &name); - } else if (argsCount < 4) { - Platform_LogConst("ClassiCube.exe is only the raw client. You must either use the launcher or provide command line arguments to start the client."); - return 1; - } else { - String_Copy(&Game_Username, &args[0]); - String_Copy(&Game_Mppass, &args[1]); - String_Copy(&Game_IPAddress, &args[2]); - - UInt8 ip[4]; - if (!Utils_ParseIP(&args[2], ip)) { - Platform_LogConst("Invalid IP"); - return 1; - } - - UInt16 port; - if (!Convert_TryParseUInt16(&args[3], &port)) { - Platform_LogConst("Invalid port"); - return 1; - } - Game_Port = port; - } - Game_Run(width, height, &title, &device); Platform_Exit(0); return 0;