Fully Working Game

This commit is contained in:
2026-04-26 18:39:43 -04:00
parent ab35c9216e
commit 5c2bb282ce
9 changed files with 334 additions and 119 deletions

View File

@@ -6,8 +6,12 @@
#include <arpa/inet.h>
#include <netdb.h>
static Server *g_server = NULL;
Server StartServer(int port) {
Server s;
g_server = &s;
s.clientID = 0;
s.client_count = 0;
@@ -23,6 +27,9 @@ Server StartServer(int port) {
s.address.sin_addr.s_addr = INADDR_ANY; // listen on all interfaces
s.address.sin_port = htons(port);
signal(SIGINT, KillServer); // ctrl+c
signal(SIGTERM, KillServer);
// Bind Port
if (bind(s.server_fd, (struct sockaddr *)&s.address, sizeof(s.address)) < 0) {
perror("bind failed");
@@ -48,6 +55,15 @@ void RemoveClient(Server* s, int index) {
s->client_count--;
}
void KillServer() {
close(g_server->server_fd);
int c = g_server->client_count;
for (int i = 0; i < c; ++i) {
RemoveClient(g_server,i);
}
}
Client StartClient(char* host, int port) {
Client c;