Started working on better error handling, by throwing exceptions and displaying error messages in the GUI
This commit is contained in:
@@ -1,38 +1,32 @@
|
||||
#include <iostream>
|
||||
#include "includes/easysock.hpp"
|
||||
#include "includes/easysock.h"
|
||||
#include "includes/connect_code.hpp"
|
||||
#include "includes/server.hpp"
|
||||
#include "includes/client.hpp"
|
||||
#include "includes/check_input.hpp"
|
||||
#include "includes/raygui/raygui.h"
|
||||
#include "includes/exception_consts.hpp"
|
||||
#include "includes/raygui_helpers.hpp"
|
||||
#include "includes/timer.h"
|
||||
|
||||
/* Display the given text, centered on the screen, as a label */
|
||||
void display_text_centered(std::string to_disp) {
|
||||
const char* to_disp_cstr = to_disp.c_str();
|
||||
Vector2 label_size = MeasureTextEx(GetFontDefault(), to_disp_cstr, GuiGetStyle(DEFAULT, TEXT_SIZE)+1, GuiGetStyle(DEFAULT, TEXT_SPACING)+1); // The '+1' is there to account for any rounding errors
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
GuiLabel(Rectangle{(GetScreenWidth()/2) - (label_size.x/2), (GetScreenHeight()/2) - (label_size.y/2), label_size.x, label_size.y}, to_disp_cstr);
|
||||
EndDrawing();
|
||||
return;
|
||||
}
|
||||
|
||||
GameType check_server(char* ip_text, char* port_text) {
|
||||
GameType type;
|
||||
std::string addr;
|
||||
uint16_t port;
|
||||
|
||||
/* Check if IP address and port are in valid forms */
|
||||
if (check_ip_ver(ip_text) < 0) {
|
||||
throw std::invalid_argument("Invalid IP address");
|
||||
}
|
||||
if (port_to_num(port_text) < 0) {
|
||||
throw std::invalid_argument("Invalid port");
|
||||
}
|
||||
|
||||
/* From here on, we assume that the IP and port are valid */
|
||||
|
||||
addr = std::string(ip_text);
|
||||
port = std::stoi(std::string(port_text));
|
||||
|
||||
/* Check if IP is valid */
|
||||
if (check_ip_ver(addr.data()) < 0) {
|
||||
throw EXCEPT_INVALIDIP;
|
||||
}
|
||||
|
||||
std::string code = connect_code::encode(addr, std::to_string(port));
|
||||
|
||||
/* Create server socket and wait for client to connect */
|
||||
|
Reference in New Issue
Block a user