Started working on better error handling, by throwing exceptions and displaying error messages in the GUI
This commit is contained in:
17
main.cpp
17
main.cpp
@@ -26,11 +26,12 @@
|
||||
#include "includes/paddle.hpp"
|
||||
#include "includes/ball.hpp"
|
||||
#include "includes/connect_code.hpp"
|
||||
#include "includes/easysock.hpp"
|
||||
#include "includes/client.hpp"
|
||||
#include "includes/server.hpp"
|
||||
#include "includes/exception_consts.hpp"
|
||||
#include "includes/check_input.hpp"
|
||||
#include "includes/raygui_helpers.hpp"
|
||||
#include "includes/easysock.h"
|
||||
#include "includes/serialization.h"
|
||||
#include "includes/timer.h"
|
||||
|
||||
@@ -272,7 +273,7 @@ int main(int argc, char** argv) {
|
||||
/* Server mode, ask user to input IP address and port */
|
||||
if (selected_item == M_SERVER) {
|
||||
button_pressed = false; // Whether submit button is pressed
|
||||
char* ip_text = (char *)calloc(100, sizeof(char)); // Holds input of IP text box
|
||||
char* ip_text = (char *)calloc(150, sizeof(char)); // Holds input of IP text box
|
||||
char* port_text = (char *)calloc(20, sizeof(char)); // Holds input of port text box
|
||||
const char* ip_label = "Local IP address";
|
||||
const char* port_label = "Port number (1024 - 65535)";
|
||||
@@ -303,14 +304,22 @@ int main(int argc, char** argv) {
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
type = check_server(ip_text, port_text);
|
||||
try {
|
||||
type = check_server(ip_text, port_text);
|
||||
} catch (std::invalid_argument& inv) {
|
||||
display_text_centered(std::string(inv.what()) + "\nClosing game...");
|
||||
Timer timer = timer_init(2); // Wait for two seconds
|
||||
while (!timer_done(timer));
|
||||
CloseWindow(); // Close and exit
|
||||
return -1;
|
||||
}
|
||||
free(ip_text);
|
||||
free(port_text);
|
||||
}
|
||||
|
||||
if (selected_item == M_CLIENT) {
|
||||
button_pressed = false; // Whether submit button is pressed
|
||||
char* code_text = (char *)calloc(100, sizeof(char)); // Holds the connect code
|
||||
char* code_text = (char *)calloc(150, sizeof(char)); // Holds the connect code
|
||||
const char* code_label = "Enter code:";
|
||||
bool editing_code = false; // Indicates whether the port text box is being edited
|
||||
while (button_pressed == false || ((strlen(code_text) == 0))) {
|
||||
|
Reference in New Issue
Block a user