diff options
Diffstat (limited to 'server/server.h')
| -rw-r--r-- | server/server.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/server/server.h b/server/server.h new file mode 100644 index 0000000..fecc446 --- /dev/null +++ b/server/server.h @@ -0,0 +1,84 @@ +#pragma once + +#include "raylib.h" +#include <stdbool.h> +#include "shared.h" +#include "queue.h" +#include "net_compat.h" + +#define TIMEOUT 10.0 +#define VISIBILITY_RANGE 20000.0f + +static int networkFd = -1; +static struct sockaddr_in server; + +// server owns full NPC state including AI + +typedef struct { + int index; + float dist; +} NPCDist; + +typedef struct { + int id; + Vec3 position; + Vec3 spawnPosition; + Vec3 target; + float rotation; + float scale; + float moveTimer; + float waitTimer; + bool isMoving; + bool active; + int health; + int state; + int model; +} ServerNPC; + +// server tracks each connected player +typedef struct { + int id; + bool connected; + char name[32]; + Vec3 position; + Vec3 velocity; + float yaw; + bool onGround; + float speed; + int sprint; + double lastHeartbeat; + int characterClass; // 0=warrior, 1=mage etc +} ServerPlayer; + +typedef struct { + int playerId; + struct sockaddr_in address; // their IP and port + bool connected; + double lastHeartbeat; // detect disconnects +} ClientConnection; + +extern ClientConnection connections[MAX_PLAYERS]; +extern PacketQueue incomingQueue; +extern PacketQueue outgoingQueue; +extern Mesh terrainMesh; +extern Matrix terrainTransform; +extern ServerPlayer players[MAX_PLAYERS]; +extern ServerNPC npcs[MAX_NPCS]; +extern int playerCount; +extern int npcCount; + +void NetworkInit(); +void NetworkShutdown(); +void *RecvThread(void *arg); +void *SendThread(void *arg); +void *GameThread(void *arg); +void ProcessIncoming(); +void HandleClientInput(ClientPacket *packet); +ServerSnapshot BuildSnapshotForPlayer(int playerId); +void CheckHeartbeats(); +void UpdateServerPlayer(ServerPlayer *p, int inputs, float yaw, float dt, + Mesh terrainMesh, Matrix terrainTransform); +float GetTerrainHeight(float x, float z); +void UpdateServerNPC(ServerNPC *npc, float dt); +int FindPlayerByAddress(struct sockaddr_in *addr); +void HandleNewConnection(struct sockaddr_in *addr, uint8_t *buffer, int size); |