mirror of
https://github.com/perfect-dark-pc-port/perfect_dark.git
synced 2026-10-24 00:02:43 +02:00
157 lines
4.5 KiB
C
157 lines
4.5 KiB
C
#ifndef _IN_NET_H
|
|
#define _IN_NET_H
|
|
|
|
#include "types.h"
|
|
#include "constants.h"
|
|
#include "net/netbuf.h"
|
|
|
|
#define NET_PROTOCOL_VER 9
|
|
|
|
#define NET_MAX_CLIENTS MAX_PLAYERS
|
|
#define NET_MAX_NAME MAX_PLAYERNAME
|
|
#define NET_MAX_ADDR 256
|
|
|
|
#define NET_BUFSIZE 1440
|
|
|
|
#define NET_DEFAULT_PORT 27100
|
|
|
|
#define NET_NULL_CLIENT 0xFF
|
|
#define NET_NULL_PROP 0
|
|
|
|
#define NETCHAN_DEFAULT 0
|
|
#define NETCHAN_CONTROL 1
|
|
#define NETCHAN_COUNT 2
|
|
|
|
#define DISCONNECT_UNKNOWN 0
|
|
#define DISCONNECT_SHUTDOWN 1
|
|
#define DISCONNECT_VERSION 2
|
|
#define DISCONNECT_KICKED 3
|
|
#define DISCONNECT_BANNED 4
|
|
#define DISCONNECT_TIMEOUT 5
|
|
#define DISCONNECT_FULL 6
|
|
#define DISCONNECT_LATE 7
|
|
#define DISCONNECT_FILES 8
|
|
|
|
#define CLSTATE_DISCONNECTED 0
|
|
#define CLSTATE_CONNECTING 1
|
|
#define CLSTATE_AUTH 2
|
|
#define CLSTATE_LOBBY 3
|
|
#define CLSTATE_GAME 4
|
|
|
|
#define UCMD_FIRE (1 << 0)
|
|
#define UCMD_ACTIVATE (1 << 1)
|
|
#define UCMD_RELOAD (1 << 2)
|
|
#define UCMD_AIMMODE (1 << 3)
|
|
#define UCMD_DUCK (1 << 4)
|
|
#define UCMD_SQUAT (1 << 5)
|
|
#define UCMD_ZOOMIN (1 << 6)
|
|
#define UCMD_SELECT (1 << 7)
|
|
#define UCMD_SELECT_DUAL (1 << 8)
|
|
#define UCMD_EYESSHUT (1 << 9)
|
|
#define UCMD_SECONDARY (1 << 10)
|
|
#define UCMD_RESPAWN (1 << 27)
|
|
#define UCMD_CHAT (1 << 28)
|
|
#define UCMD_IMPORTANT_MASK (UCMD_FIRE | UCMD_ACTIVATE | UCMD_RELOAD | UCMD_AIMMODE | UCMD_SELECT | UCMD_SELECT_DUAL)
|
|
#define UCMD_FL_FORCEPOS (1 << 29)
|
|
#define UCMD_FL_FORCEANGLE (1 << 30)
|
|
#define UCMD_FL_FORCEGROUND (1 << 31)
|
|
#define UCMD_FL_FORCEMASK (UCMD_FL_FORCEPOS | UCMD_FL_FORCEANGLE | UCMD_FL_FORCEGROUND)
|
|
|
|
struct netplayermove {
|
|
u32 tick; // g_NetTIck value when this struct was written; if 0, this struct is invalid
|
|
u32 ucmd; // player commands (UCMD_)
|
|
f32 leanofs; // analog lean value (-1 .. 1; equal to player->swaytarget / 75.f)
|
|
f32 crouchofs; // analog crouch value (-90 for SQUAT, 0 for STAND; player->crouchofs)
|
|
f32 zoomfov; // manual zoom fov for the current gun; synced only if UCMD_AIMING is set
|
|
f32 movespeed[2]; // move inputs, [0] is forward, [1] is sideways; used mostly for animation
|
|
f32 angles[2]; // view angles, [0] is theta, [1] is verta
|
|
f32 crosspos[2]; // crosshair position in aiming mode; normalized to default aspect ratio
|
|
s8 weaponnum; // switch to this weapon if UCMD_SELECT is set
|
|
struct coord pos; // player position at g_NetTick == tick
|
|
};
|
|
|
|
struct netclient {
|
|
struct _ENetPeer *peer;
|
|
u32 id; // remote client number, server is always 0, even on clients
|
|
u32 state; // CLSTATE_
|
|
u32 flags; // CLFLAG_
|
|
|
|
struct {
|
|
char name[NET_MAX_NAME];
|
|
u16 options;
|
|
u8 headnum;
|
|
u8 bodynum;
|
|
u8 team;
|
|
f32 fovy;
|
|
f32 fovzoommult;
|
|
} settings;
|
|
|
|
struct mpplayerconfig *config;
|
|
struct player *player;
|
|
u8 playernum;
|
|
|
|
struct netplayermove outmove[2]; // last 2 outgoing player inputs, newest one first
|
|
struct netplayermove inmove[2]; // last 2 incoming player inputs, newest one first
|
|
u32 inmovetick; // last inmove tick which was applied to the player
|
|
u32 outmoveack; // last acked outmove tick
|
|
u32 forcetick; // tick on which the client's position was forced, or 0 if not forcing
|
|
u32 lerpticks; // how many ticks we've been lerping the position
|
|
|
|
struct netbuf out; // outbound messages are written here, except broadcasts
|
|
struct netbuf in; // incoming packets are fed here
|
|
|
|
u8 out_data[NET_BUFSIZE]; // buffer for out
|
|
};
|
|
|
|
extern s32 g_NetMode;
|
|
|
|
// net frame, ticks at 60 fps, starts at 0 when the server is started
|
|
extern u32 g_NetTick;
|
|
extern u32 g_NetNextSyncId;
|
|
|
|
extern u64 g_NetRngSeeds[2];
|
|
extern u32 g_NetRngLatch;
|
|
|
|
extern u32 g_NetInterpTicks;
|
|
extern u32 g_NetServerPort;
|
|
extern char g_NetLastJoinAddr[NET_MAX_ADDR + 1];
|
|
|
|
extern s32 g_NetDebugDraw;
|
|
|
|
extern s32 g_NetMaxClients;
|
|
extern s32 g_NetNumClients;
|
|
extern struct netclient g_NetClients[NET_MAX_CLIENTS + 1]; // last is an extra temporary client
|
|
extern struct netclient *g_NetLocalClient;
|
|
|
|
extern struct netbuf g_NetMsg;
|
|
extern struct netbuf g_NetMsgRel;
|
|
|
|
const char *netFormatClientAddr(const struct netclient *cl);
|
|
|
|
void netInit(void);
|
|
s32 netDisconnect(void);
|
|
void netStartFrame(void);
|
|
void netEndFrame(void);
|
|
|
|
s32 netStartServer(u16 port, s32 maxclients);
|
|
s32 netStartClient(const char *addr);
|
|
|
|
u32 netSend(struct netclient *dstcl, struct netbuf *buf, const s32 reliable, const s32 chan);
|
|
|
|
void netChat(struct netclient *dst, const char *text);
|
|
void netChatPrintf(struct netclient *dst, const char *fmt, ...);
|
|
|
|
void netServerStageStart(void);
|
|
void netServerStageEnd(void);
|
|
void netServerKick(struct netclient *cl, const u32 reason);
|
|
|
|
void netClientSyncRng(void);
|
|
void netClientSettingsChanged(void);
|
|
|
|
void netPlayersAllocate(void);
|
|
void netSyncIdsAllocate(void);
|
|
|
|
Gfx *netDebugRender(Gfx *gdl);
|
|
|
|
#endif // _IN_NET_H
|