libspades
Ace of Spades library
servergamestate.h
1#ifndef LIBSPADES_SERVER_GAMESTATE_H
2#define LIBSPADES_SERVER_GAMESTATE_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7#include <enet/enet.h>
8#include "../common/clock.h"
9#include "../common/grenade.h"
10#include "../common/map.h"
11#include "../common/protocol.h"
12#include "../config.h"
13#include "servergrenade.h"
14
15/* A handful of things which are related to particular players. TODO: move things into here where possible. */
17 uint64_t reloadClock; /* To reload ammunition. */
18 uint64_t nextBulletFireClock; /* To keep track of bullets contained within the gun's magazine, and maybe
19 prevent cheating. */
20#ifdef LIBSPADES_ANTICHEAT
21 uint64_t nextBlockPlacementClock;
22 uint64_t nextBlock1DestroyClock;
23 uint64_t nextBlock3DestroyClock;
24 uint64_t lastUpdatedPositionClock;
25 Vector3Float lastUpdatedPosition;
26#endif
27 Vector3Float velocity;
28 bool reloading;
29 bool sendWeaponInputsWhenReloadEnded;
30 bool alive;
31 bool limbo;
32 bool transformChangedSinceLastUpdate;
33 bool airborne;
34 bool wading;
35 uint_fast8_t handshakeStatus;
36 uint_fast8_t authenticationStatus;
37 uint_fast8_t magazineAmmo;
38 uint_fast8_t reserveAmmo;
39 uint_fast8_t blocks;
40 uint_fast8_t grenades;
41 uint_fast8_t HP;
42#ifdef LIBSPADES_ANTICHEAT
43 uint_fast8_t blockPlaceQuota;
44 uint_fast8_t block1DestroyQuota;
45 uint_fast8_t block3DestroyQuota;
46 uint_fast8_t
47 lastUpdatedPositionValid; /* Whether the last position update should be strictly and laxly checked by the anti-cheat, or just laxly checked.
48 This should be set to 0 for things like teleportation or respawning, for instance, in which case it will only be laxly checked
49 It will automatically be set to 1 after the client's next position update. */
50 uint_fast8_t
51 pelletsUsed; /* Fun fact: Voxlap and BetterSpades are capable of destroying multiple blocks at once
52 with one shot, but OpenSpades is not. Why? Pyspades! Why, pyspades? Pyspades! */
53 uint8_t canSee[32]; /* for use with ANTI-ESP. */
54#endif
55 uint8_t publicKey[32];
56 uint8_t nonce[32];
57 char client; /* As provided by PacketVersionResponse. NOTE: this is terrible for display, acceptable but
58 disgusting for comparison. It is recommended to switch to the OTHER version info thing where
59 possible. */
60 Vector3Uint8 clientVersion;
61};
62
63struct GameState;
64
66 void (*onConnect)(uint8_t playerID, struct GameState *gameState);
67 void (*onDisconnect)(uint8_t playerID, struct GameState *gameState);
68 void (*onJoin)(uint8_t playerID, struct GameState *gameState);
69 void (*onKill)(struct PacketKillAction killAction, struct GameState *gameState);
70 void (*onChat)(const struct PacketChatMessage *csUTF8message,
71 struct GameState *gameState); /* Does NOT have a prefix of 0xff. Well, at least SHOULD not. */
72
73 void (*getAcceptableSpawnPosition)(uint8_t playerID,
74 Vector3Float outputPosition,
75 struct GameState *gameState); /* Writes an acceptable position for the
76 given player to spawn at in
77 outputPosition. */
78 void (*playerHit)(
79 uint8_t hitterPlayerID,
80 struct PacketHit *hitPacket,
81 struct GameState *
82 gameState); /* Called after a player has been hit. SHOULD damage and kill the player if appropriate. */
83
84 void (*handleChat)(struct PacketChatMessage *message, size_t size, struct GameState *gameState);
85
86 void (*getRandomData)(void *buffer, size_t length);
87 int (*validateSignature)(const void *signature,
88 const void *nonce,
89 size_t nonceLength,
90 const void *publicKey); /* Returns 0 on successful validation. Otherwise, it returns
91 a non-zero value. */
92 const char *(*queryTrustLevelString)(const void *signature);
93};
94
96struct GameState {
97 ENetHost *host;
98 struct PacketStateData stateData;
99 struct PacketExistingPlayer playerData[MAX_PLAYERS];
100 struct PacketWorldUpdate playerTransforms;
101 struct PacketInputData playerInputs[MAX_PLAYERS];
102 struct PacketWeaponInput playerWeaponInputs[MAX_PLAYERS];
103 struct PlayerStats playerStats[MAX_PLAYERS];
104 struct LibspadesMapData mapData; /* 50 MiB. It used to be 80 MiB. */
105 struct GrenadeArray grenadeArray; /* Contains all the grenades. */
106 uint64_t updateClock;
107 enum ProtocolVersion protocolVersion;
108 void *data; /* A pointer that the user of libspades is free to do anything with. It will never be modified by
109 libspades. */
110 struct LibspadesCallbacks callbacks;
111};
112
113extern void libspades_server_gamestate_clear_callbacks(struct GameState *gameState);
114extern struct GameState *libspades_server_gamestate_create(uint8_t maxPlayers,
115 enum ProtocolVersion protocolVersion,
116 ENetAddress *address);
117
118#ifdef __cplusplus
119}
120#endif
121#endif
The main data structure for libspades clients.
Definition gamestate.h:33
Definition grenade.h:23
Definition servergamestate.h:65
Definition map.h:15
Sends a message in chat.
Definition protocol.h:524
Informs the client of in-game players and the server of the joining client player.
Definition protocol.h:257
Tells the server that a player has been hit.
Definition protocol.h:156
Changes the movement inputs of a player.
Definition protocol.h:127
Informs the client about the death of a player.
Definition protocol.h:498
Contains information about the game's state and the client player's ID.
Definition protocol.h:475
Changes the weapon inputs of a player.
Definition protocol.h:145
Regularly sent packet containing positions and orientations of all players.
Definition protocol.h:117
Definition servergamestate.h:16