Improve Proxy Client

This commit is contained in:
TheBrokenRail 2022-07-13 17:02:18 -04:00
parent 69d3832815
commit c87a6fa3c0
1 changed files with 7 additions and 6 deletions

View File

@ -9,13 +9,14 @@
#include "../common/common.h" #include "../common/common.h"
// Store Handlers // Store Handlers
static std::vector<proxy_handler_t> handlers; #define MAX_HANDLERS 100
static proxy_handler_t handlers[MAX_HANDLERS];
void _add_handler(unsigned char unique_id, proxy_handler_t handler) { void _add_handler(unsigned char unique_id, proxy_handler_t handler) {
if (handlers.size() > unique_id && handlers[unique_id] != NULL) { if (unique_id >= MAX_HANDLERS) {
PROXY_ERR("Duplicate ID: %i", (int) unique_id); PROXY_ERR("ID Too Big: %i", (int) unique_id);
} }
if (handlers.size() <= unique_id) { if (handlers[unique_id] != NULL) {
handlers.resize(unique_id + 1); PROXY_ERR("Duplicate ID: %i", (int) unique_id);
} }
handlers[unique_id] = handler; handlers[unique_id] = handler;
} }
@ -78,7 +79,7 @@ int main(int argc, char *argv[]) {
int running = is_connection_open(); int running = is_connection_open();
while (running && !exit_requested) { while (running && !exit_requested) {
unsigned char unique_id = read_byte(); unsigned char unique_id = read_byte();
if (handlers.size() > unique_id && handlers[unique_id] != NULL) { if (handlers[unique_id] != NULL) {
// Run Method // Run Method
handlers[unique_id](); handlers[unique_id]();
// Check If Connection Is Still Open // Check If Connection Is Still Open