Compare commits

...
35 Commits
Author SHA1 Message Date
alufolie91 3204b5c3b4 Merge branch 'Saturn-Next' into netstuff 2026-02-23 17:02:32 +01:00
alufolie91 cd02242a01 fix splitscreen clients being unable to join saturn servers
lmao oops idk dumb copy paste sry
2026-02-23 17:02:13 +01:00
alufolie91 e35dc9e097 fix g_in_exiting_signal_handler
every "flag" set by signal handlers must be of type "volatile sig_atomic_t"
everything else may fail to be correctly set, read or get optimized away which rendered this basically useless
2026-02-23 16:20:48 +01:00
alufolie91 f4dc161831 dont let SIGINT/SIGTERM do work in signal handler take 2
the earlier approach still raised the default signal within this, which basically just skipped everything and ended up NOT calling I_Quit at all
Basically this is to ensure we dont call I_Quit at all from a signal handler as it is NOT async safe and can cause serious issues like deadlocks and such, instead SIGINT and SIGTERM will just signal the main loop/thread to safely call I_Quit instead
2026-02-23 16:01:14 +01:00
alufolie91 1d6c27baca lua_pushlstring: prefer luaS_newlstr over luaS_new
the latter calls strlen which is not needed as the empty string has no length
2026-02-22 14:01:27 +01:00
alufolie91 009df228d6 fix memory leak when fetching masterserver rules
strdup returns a malloc´d string!
2026-02-22 13:33:57 +01:00
alufolie91 7746e494cf fix memory leak within http masterserver handling
errbuf gets malloc´d!
2026-02-22 13:33:54 +01:00
alufolie91 90a88983f1 k_hud: make the hud offset vars static 2026-02-22 13:33:49 +01:00
alufolie91 22a4fe63db Fix minimap angle display colour for skins that use non default startcolor
i.e. they use a different colour than "green" to remap their skincolor on
2026-02-22 13:33:46 +01:00
Alug d77508f481 init superactions global
was missed before
2026-02-16 19:27:56 +01:00
Alug 53321d33d5 mark some nightsmode stuff with likely/unlikely i missed
and in some cases move around the conditionals
i love backwards compat Zzz....
2026-02-16 19:27:52 +01:00
Alug 5c28f6afd8 Revert "fix new compiler warnings from new gcc version"
This reverts commit d49001143f.
2026-02-16 19:04:51 +01:00
Alug d49001143f fix new compiler warnings from new gcc version
just throw const at everything :blobthumbsup:
2026-02-11 17:48:16 +01:00
Alug 6cbb8a36cf Merge branch 'Saturn-Next' into netstuff 2026-01-21 20:48:47 +01:00
Gustaf Alhäll bf1aa47854 Simplify textcmd handling 2026-01-09 20:53:15 +01:00
Alug be423b2910 Merge branch 'Saturn-Next' into netstuff 2026-01-08 00:34:19 +01:00
Alug 3bf3bdf641 enable "Wzero-as-null-pointer-constant", fix cases of it
prevent ambiguity and bad practices, i like expressive and "correct" code
shoutout blankart for making me aware this exists
2026-01-08 00:34:15 +01:00
Alug e923777eb6 Acessability: add basic "reducevfx" toggle to disable/reduce certain effects
toggles certain effects, which may be troublesome to some players

-disabled hyudoro flashing, instead makes player translucent
- Makes rainbow colour effects, such as invul, change colours very slowly
- Disables underwater and heatwave screen effects
- Disables palette flashing
- Disables vhs effect

not the most pretty implementation, but im lazy and this works

feel free to suggest more things
2026-01-08 00:33:53 +01:00
Alug cf6eb0010e K_SpawnSparkleTrail: check for blend effect apply outside the loop
tiny optimization
2026-01-08 00:33:50 +01:00
Alug 5184115216 enable "Wzero-as-null-pointer-constant", fix cases of it
prevent ambiguity and bad practices, i like expressive and "correct" code
shoutout blankart for making me aware this exists
2026-01-08 00:33:43 +01:00
Alug 39a46e8f79 Revert "Remove tic provision (vanilla compat edition)"
This reverts commit 4a3c9ccfbb.
2025-12-30 01:09:14 +01:00
Alug d9712cf85e Merge branch 'Saturn-Next' into netstuff 2025-12-27 15:13:50 +01:00
Alug 0691e2d9e2 Merge branch 'Saturn-Next' into netstuff 2025-12-27 13:40:19 +01:00
PAS 08864e27b2 Fix double byte-swap in SV_MakeTic 2025-12-26 21:44:39 +01:00
Alug 4a3c9ccfbb Remove tic provision (vanilla compat edition)
based on https://codeberg.org/srb2classic/srb2classic/commit/7cf14fbe740998c3246dd190904f49a236b2ccec

seems to get rid of some jitter in localhost
2025-12-26 21:44:37 +01:00
Alug cedd789a27 Merge branch 'Saturn-Next' into netstuff 2025-12-26 21:44:34 +01:00
Alug 8f91707164 Merge branch 'Saturn-Next' into netstuff 2025-12-09 18:07:06 +01:00
Alug 37eba186f5 netcode: replace some stuff with memsets + add a little bounds safety in some places 2025-12-09 18:07:02 +01:00
Alug 7eb2ad1e35 slightly cleanup SV_AddWaitingPlayers 2025-12-02 23:23:41 +01:00
Alug f49e57a38c d_cliserv: Cleanup PT_ClientJoin
move refuse message handling into its own function
2025-12-02 23:23:38 +01:00
Alug 265f4a50ef readd check for node before SV_SendSaveGame
Apparently in some cases the server will connect to itself, in this case the server tries to send itself the savegame, leading to a crash in some cases. oops
2025-12-02 23:23:36 +01:00
Alug e83e2659a7 reorder packets again 2025-12-02 23:23:29 +01:00
Alug c680dd3222 fix some packet types not being correctly handled 2025-12-02 23:23:15 +01:00
Alug 96aaaf5261 merge SendNameAndColor & SendWeaponPref
TODO: make a bunch of player specific cvars arrays for splitscreen handling

- also cleanup some strlen usage
2025-12-02 23:23:07 +01:00
Alug efb29e6be5 d_cliserv: do some cleanups
- expose SAVEGAMESIZE
- pass node number to SV_AddWaitingPlayers (saves iterating through all 128 net nodes everytime a player joins) lifted from RR
- move all packet handling to the packet handlers
- Reorder packethandling switches a little, so common/important packets get checked first
- fix wrong clamp for realfirsttic that was too early
- add nowtime division by NEWTICRATERATIO (no change unless ticrate changes)
2025-12-02 23:23:02 +01:00
31 changed files with 503 additions and 772 deletions

No files matched your search

+1 -1
View File
@@ -434,7 +434,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) {
lua_lock(L); lua_lock(L);
luaC_checkGC(L); luaC_checkGC(L);
setsvalue2s(L, L->top, (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len)); setsvalue2s(L, L->top, (len == 0) ? luaS_newlstr(L, "", 0) : luaS_newlstr(L, s, len));
api_incr_top(L); api_incr_top(L);
lua_unlock(L); lua_unlock(L);
} }
+1 -1
View File
@@ -1178,7 +1178,7 @@ consvar_t *CV_FindVar(const char *name)
consvar_t *cvar; consvar_t *cvar;
for (cvar = consvar_vars; cvar; cvar = cvar->next) for (cvar = consvar_vars; cvar; cvar = cvar->next)
if (fasticmp(name,cvar->name)) if (fasticmp(name, cvar->name))
return cvar; return cvar;
return NULL; return NULL;
+5 -5
View File
@@ -46,16 +46,16 @@
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_mutex con_mutex; I_mutex con_mutex;
// g_in_exiting_signal_handler is an evil hack // I_In_Exiting_Signal_Handler is an evil hack
// to avoid infinite SIGABRT recursion in the signal handler // to avoid infinite SIGABRT recursion in the signal handler
// due to poisoned locks or mach-o kernel not supporting locks in signals // due to poisoned locks or mach-o kernel not supporting locks in signals
// or something like that. idk // or something like that. idk
# define Lock_state() if (!g_in_exiting_signal_handler) { I_lock_mutex(&con_mutex); } # define Lock_state() if (!I_In_Exiting_Signal_Handler()) { I_LockMutex(&con_mutex); }
# define Unlock_state() if (!g_in_exiting_signal_handler) { I_unlock_mutex(con_mutex); } # define Unlock_state() if (!I_In_Exiting_Signal_Handler()) { I_UnlockMutex(con_mutex); }
#else/*HAVE_THREADS*/ #else /*HAVE_THREADS*/
# define Lock_state() # define Lock_state()
# define Unlock_state() # define Unlock_state()
#endif/*HAVE_THREADS*/ #endif /*HAVE_THREADS*/
static boolean con_started = false; // console has been initialised static boolean con_started = false; // console has been initialised
boolean con_startup = false; // true at game startup, screen need refreshing boolean con_startup = false; // true at game startup, screen need refreshing
+227 -197
View File
@@ -212,14 +212,9 @@ tic_t firstconnectattempttime = 0;
// engine // engine
// Must be a power of two
#define TEXTCMD_HASH_SIZE 4
typedef struct textcmdtic_s typedef struct textcmdtic_s
{ {
tic_t tic;
UINT8 *playercmds[MAXPLAYERS]; UINT8 *playercmds[MAXPLAYERS];
struct textcmdtic_s *next;
} textcmdtic_t; } textcmdtic_t;
typedef struct textcmdbuf_s textcmdbuf_t; typedef struct textcmdbuf_s textcmdbuf_t;
@@ -234,7 +229,7 @@ static textcmdbuf_t *textcmdbuf[MAXSPLITSCREENPLAYERS] = {NULL};
static ticcmd_t playercmds[MAXPLAYERS]; static ticcmd_t playercmds[MAXPLAYERS];
ticcmd_t netcmds[BACKUPTICS][MAXPLAYERS] = {}; ticcmd_t netcmds[BACKUPTICS][MAXPLAYERS] = {};
static textcmdtic_t *textcmds[TEXTCMD_HASH_SIZE] = {NULL}; static textcmdtic_t *textcmds[BACKUPTICS] = {NULL};
consvar_t cv_showjoinaddress = {"showjoinaddress", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_showjoinaddress = {"showjoinaddress", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
@@ -396,20 +391,10 @@ void SendNetXCmdForPlayer(UINT8 playerid, netxcmd_t id, const void *param, size_
// Frees all textcmd memory for the specified tic // Frees all textcmd memory for the specified tic
static void D_FreeTextcmd(tic_t tic) static void D_FreeTextcmd(tic_t tic)
{ {
textcmdtic_t **tctprev = &textcmds[tic & (TEXTCMD_HASH_SIZE - 1)]; textcmdtic_t *textcmdtic = textcmds[tic%BACKUPTICS];
textcmdtic_t *textcmdtic = *tctprev;
while (textcmdtic && textcmdtic->tic != tic)
{
tctprev = &textcmdtic->next;
textcmdtic = textcmdtic->next;
}
if (textcmdtic) if (textcmdtic)
{ {
// Remove this tic from the list.
*tctprev = textcmdtic->next;
// Free all players. // Free all players.
for (INT32 i = 0; i < MAXPLAYERS; i++) for (INT32 i = 0; i < MAXPLAYERS; i++)
{ {
@@ -418,14 +403,14 @@ static void D_FreeTextcmd(tic_t tic)
// Free this tic's own memory. // Free this tic's own memory.
Z_Free(textcmdtic); Z_Free(textcmdtic);
textcmds[tic%BACKUPTICS] = NULL;
} }
} }
// Gets the buffer for the specified ticcmd, or NULL if there isn't one // Gets the buffer for the specified ticcmd, or NULL if there isn't one
static UINT8* D_GetExistingTextcmd(tic_t tic, INT32 playernum) static UINT8* D_GetExistingTextcmd(tic_t tic, INT32 playernum)
{ {
textcmdtic_t *textcmdtic = textcmds[tic & (TEXTCMD_HASH_SIZE - 1)]; textcmdtic_t *textcmdtic = textcmds[tic%BACKUPTICS];
while (textcmdtic && textcmdtic->tic != tic) textcmdtic = textcmdtic->next;
// Do we have an entry for the tic? If so, look for player. // Do we have an entry for the tic? If so, look for player.
if (textcmdtic) if (textcmdtic)
@@ -441,22 +426,11 @@ static UINT8* D_GetExistingTextcmd(tic_t tic, INT32 playernum)
// Gets the buffer for the specified ticcmd, creating one if necessary // Gets the buffer for the specified ticcmd, creating one if necessary
static UINT8* D_GetTextcmd(tic_t tic, INT32 playernum) static UINT8* D_GetTextcmd(tic_t tic, INT32 playernum)
{ {
textcmdtic_t *textcmdtic = textcmds[tic & (TEXTCMD_HASH_SIZE - 1)]; textcmdtic_t *textcmdtic = textcmds[tic%BACKUPTICS];
textcmdtic_t **tctprev = &textcmds[tic & (TEXTCMD_HASH_SIZE - 1)];
// Look for the tic.
while (textcmdtic && textcmdtic->tic != tic)
{
tctprev = &textcmdtic->next;
textcmdtic = textcmdtic->next;
}
// If we don't have an entry for the tic, make it. // If we don't have an entry for the tic, make it.
if (!textcmdtic) if (!textcmdtic)
{ textcmds[tic%BACKUPTICS] = textcmdtic = (textcmdtic_t*)Z_Calloc(sizeof(textcmdtic_t), PU_STATIC, NULL);
textcmdtic = *tctprev = (textcmdtic_t*)Z_Calloc(sizeof (textcmdtic_t), PU_STATIC, NULL);
textcmdtic->tic = tic;
}
// If we don't have an entry for the player, make it. // If we don't have an entry for the player, make it.
if (!textcmdtic->playercmds[playernum]) if (!textcmdtic->playercmds[playernum])
@@ -540,9 +514,8 @@ void D_ResetTiccmds(void)
} }
// Reset the net command list // Reset the net command list
for (i = 0; i < TEXTCMD_HASH_SIZE; i++) for (i = 0; i < BACKUPTICS; i++)
while (textcmds[i]) D_Clearticcmd(i);
D_Clearticcmd(textcmds[i]->tic);
} }
void SendKick(UINT8 playernum, UINT8 msg) void SendKick(UINT8 playernum, UINT8 msg)
@@ -1946,16 +1919,17 @@ static boolean SV_SendServerConfig(INT32 node)
return waspacketsent; return waspacketsent;
} }
#define SAVEGAMESIZE (768*1024)
#ifdef SATURNPAK #ifdef SATURNPAK
static boolean SV_ResendingSavegameToAnyone(void) static boolean SV_ResendingSavegameToAnyone(void)
{ {
INT32 i; INT32 i;
for (i = 0; i < MAXNETNODES; i++) for (i = 0; i < MAXNETNODES; i++)
{
if (nodeingame[i] && resendingsavegame[i]) if (nodeingame[i] && resendingsavegame[i])
return true; return true;
}
return false; return false;
} }
#endif #endif
@@ -2938,10 +2912,12 @@ static void CL_ConnectToServer(void)
{ {
pnumnodes = 0; pnumnodes = 0;
for (i = 0; i < MAXNETNODES; i++) for (i = 0; i < MAXNETNODES; i++)
{
if (nodeingame[i]) if (nodeingame[i])
pnumnodes++; pnumnodes++;
} }
} }
}
while (!(cl_mode == CL_CONNECTED && (client || (server && nodewaited <= pnumnodes)))); while (!(cl_mode == CL_CONNECTED && (client || (server && nodewaited <= pnumnodes))));
if (netgame) if (netgame)
@@ -3350,7 +3326,7 @@ void CL_ClearPlayer(INT32 playernum)
if (players[playernum].mo) if (players[playernum].mo)
{ {
// Don't leave a NiGHTS ghost! // Don't leave a NiGHTS ghost!
if ((players[playernum].pflags & PF_NIGHTSMODE) && players[playernum].mo->tracer) if (UNLIKELY((players[playernum].pflags & PF_NIGHTSMODE) && players[playernum].mo->tracer))
P_RemoveMobj(players[playernum].mo->tracer); P_RemoveMobj(players[playernum].mo->tracer);
P_RemoveMobj(players[playernum].mo); P_RemoveMobj(players[playernum].mo);
} }
@@ -3496,6 +3472,7 @@ static void Command_GetPlayerNum(void)
INT32 i; INT32 i;
for (i = 0; i < MAXPLAYERS; i++) for (i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i]) if (playeringame[i])
{ {
if (serverplayer == i) if (serverplayer == i)
@@ -3503,6 +3480,7 @@ static void Command_GetPlayerNum(void)
else else
CONS_Printf(M_GetText("\x82num:%2d node:%2d %s\n"), i, playernode[i], player_names[i]); CONS_Printf(M_GetText("\x82num:%2d node:%2d %s\n"), i, playernode[i], player_names[i]);
} }
}
} }
SINT8 nametonum(const char *name) SINT8 nametonum(const char *name)
@@ -4145,7 +4123,7 @@ static void Command_ResendGamestate(void)
} }
playernum = nametonum(COM_Argv(1)); playernum = nametonum(COM_Argv(1));
if (playernum == -1 || playernum == 0) if (playernum <= 0)
return; return;
doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); doomdata_t *netbuffer = DOOMCOM_DATA(doomcom);
@@ -4421,8 +4399,10 @@ void D_QuitNetGame(void)
netbuffer->packettype = PT_SERVERSHUTDOWN; netbuffer->packettype = PT_SERVERSHUTDOWN;
for (i = 0; i < MAXNETNODES; i++) for (i = 0; i < MAXNETNODES; i++)
{
if (nodeingame[i]) if (nodeingame[i])
HSendPacket(i, true, 0, 0); HSendPacket(i, true, 0, 0);
}
#ifdef MASTERSERVER #ifdef MASTERSERVER
if (serverrunning && netgame && cv_advertise.value) // see mserv.c Online() if (serverrunning && netgame && cv_advertise.value) // see mserv.c Online()
UnregisterServer(); UnregisterServer();
@@ -4466,18 +4446,21 @@ static inline void SV_AddNode(INT32 node)
// Xcmd XD_ADDPLAYER // Xcmd XD_ADDPLAYER
static void Got_AddPlayer(const UINT8 **p, INT32 playernum) static void Got_AddPlayer(const UINT8 **p, INT32 playernum)
{ {
UINT8 i;
INT16 node, newplayernum; INT16 node, newplayernum;
UINT8 splitscreenplayer = 0; UINT8 splitscreenplayer = 0;
UINT8 i; player_t *newplayer;
if (playernum != serverplayer && !IsPlayerAdmin(playernum)) if (playernum != serverplayer && !IsPlayerAdmin(playernum))
{ {
// protect against hacked/buggy client // protect against hacked/buggy client
CONS_Alert(CONS_WARNING, M_GetText("Illegal add player command received from %s\n"), player_names[playernum]); CONS_Alert(CONS_WARNING, M_GetText("Illegal add player command received from %s\n"), player_names[playernum]);
if (server) if (server)
{ {
SendKick(playernum, KICK_MSG_CON_FAIL); SendKick(playernum, KICK_MSG_CON_FAIL);
} }
return; return;
} }
@@ -4486,14 +4469,19 @@ static void Got_AddPlayer(const UINT8 **p, INT32 playernum)
splitscreenplayer = newplayernum/MAXPLAYERS; splitscreenplayer = newplayernum/MAXPLAYERS;
newplayernum %= MAXPLAYERS; newplayernum %= MAXPLAYERS;
CONS_Debug(DBG_NETPLAY, "addplayer: %d %d\n", node, newplayernum);
// Clear player before joining, lest some things get set incorrectly // Clear player before joining, lest some things get set incorrectly
CL_ClearPlayer(newplayernum); CL_ClearPlayer(newplayernum);
playeringame[newplayernum] = true; playeringame[newplayernum] = true;
G_AddPlayer(newplayernum); G_AddPlayer(newplayernum);
if (newplayernum+1 > doomcom->numslots) if (newplayernum+1 > doomcom->numslots)
doomcom->numslots = (INT16)(newplayernum+1); doomcom->numslots = (INT16)(newplayernum+1);
newplayer = &players[newplayernum];
// the server is creating my player // the server is creating my player
if (node == mynode) if (node == mynode)
{ {
@@ -4504,7 +4492,7 @@ static void Got_AddPlayer(const UINT8 **p, INT32 playernum)
displayplayers[splitscreenplayer] = newplayernum; displayplayers[splitscreenplayer] = newplayernum;
DEBFILE(va("spawning one of my sister number %d\n", splitscreenplayer)); DEBFILE(va("spawning one of my sister number %d\n", splitscreenplayer));
if (splitscreenplayer == 1 && botingame) if (splitscreenplayer == 1 && botingame)
players[newplayernum].bot = 1; newplayer->bot = 1; // do we really want this löl
} }
else else
{ {
@@ -4514,13 +4502,13 @@ static void Got_AddPlayer(const UINT8 **p, INT32 playernum)
DEBFILE("spawning me\n"); DEBFILE("spawning me\n");
} }
P_ForceLocalAngle(&players[newplayernum], (angle_t)(players[newplayernum].cmd.angleturn << TICCMD_REDUCE)); P_ForceLocalAngle(newplayer, (angle_t)(newplayer->cmd.angleturn << TICCMD_REDUCE));
D_SendPlayerConfig(); D_SendPlayerConfig(splitscreenplayer);
addedtogame = true; addedtogame = true;
} }
players[newplayernum].splitscreenindex = splitscreenplayer; newplayer->splitscreenindex = splitscreenplayer;
if (netgame) if (netgame)
{ {
@@ -4584,32 +4572,34 @@ static void Got_RemovePlayer(const UINT8 **p, INT32 playernum)
#endif #endif
} }
static boolean SV_AddWaitingPlayers(void) static boolean SV_AddWaitingPlayers(SINT8 node)
{ {
INT32 node, n, newplayer = false; INT32 n;
UINT8 buf[2]; UINT8 buf[2];
UINT8 newplayernum = 0; UINT8 newplayernum = 0;
boolean newplayer = false;
// What is the reason for this? Why can't newplayernum always be 0?
// Sal: Because the dedicated player is stupidly forced into players[0].....
if (dedicated)
newplayernum = 1;
for (node = 0; node < MAXNETNODES; node++)
{
// splitscreen can allow 2+ players in one node // splitscreen can allow 2+ players in one node
for (; nodewaiting[node] > 0; nodewaiting[node]--) for (; nodewaiting[node] > 0; nodewaiting[node]--)
{ {
newplayer = true; newplayer = true;
// search for a free playernum // search for a free playernum
// we can't use playeringame since it is not updated here // we can't solely use playeringame since it is not updated here
for (; newplayernum < MAXPLAYERS; newplayernum++) for (newplayernum = dedicated ? 1 : 0; newplayernum < MAXPLAYERS; newplayernum++)
{ {
if (playeringame[newplayernum])
continue;
for (n = 0; n < MAXNETNODES; n++) for (n = 0; n < MAXNETNODES; n++)
if (nodetoplayer[n] == newplayernum || nodetoplayer2[n] == newplayernum {
|| nodetoplayer3[n] == newplayernum || nodetoplayer4[n] == newplayernum) if (nodetoplayer[n] == newplayernum ||
nodetoplayer2[n] == newplayernum ||
nodetoplayer3[n] == newplayernum ||
nodetoplayer4[n] == newplayernum)
break; break;
}
if (n == MAXNETNODES) if (n == MAXNETNODES)
break; break;
} }
@@ -4618,10 +4608,9 @@ static boolean SV_AddWaitingPlayers(void)
// before accepting the join // before accepting the join
I_Assert(newplayernum < MAXPLAYERS); I_Assert(newplayernum < MAXPLAYERS);
playernode[newplayernum] = (UINT8)node;
buf[0] = (UINT8)node; buf[0] = (UINT8)node;
buf[1] = newplayernum; buf[1] = newplayernum;
if (playerpernode[node] < 1) if (playerpernode[node] < 1)
{ {
nodetoplayer[node] = newplayernum; nodetoplayer[node] = newplayernum;
@@ -4636,11 +4625,21 @@ static boolean SV_AddWaitingPlayers(void)
nodetoplayer3[node] = newplayernum; nodetoplayer3[node] = newplayernum;
buf[1] += MAXPLAYERS*2; buf[1] += MAXPLAYERS*2;
} }
else else if (playerpernode[node] < 4)
{ {
nodetoplayer4[node] = newplayernum; nodetoplayer4[node] = newplayernum;
buf[1] += MAXPLAYERS*3; buf[1] += MAXPLAYERS*3;
} }
else
{
// I don't know if it's safe to assert here,
// but I do know this should not be allowed
// to be reached.
return newplayer;
}
playernode[newplayernum] = (UINT8)node;
playerpernode[node]++; playerpernode[node]++;
SendNetXCmd(XD_ADDPLAYER, &buf, 2); SendNetXCmd(XD_ADDPLAYER, &buf, 2);
@@ -4649,7 +4648,6 @@ static boolean SV_AddWaitingPlayers(void)
// use the next free slot (we can't put playeringame[newplayernum] = true here) // use the next free slot (we can't put playeringame[newplayernum] = true here)
newplayernum++; newplayernum++;
} }
}
return newplayer; return newplayer;
} }
@@ -4685,6 +4683,8 @@ boolean Playing(void)
boolean SV_SpawnServer(void) boolean SV_SpawnServer(void)
{ {
boolean result = false;
if (demo.playback) if (demo.playback)
G_StopDemo(); // reset engine parameter G_StopDemo(); // reset engine parameter
@@ -4705,7 +4705,15 @@ boolean SV_SpawnServer(void)
else doomcom->numslots = 1; else doomcom->numslots = 1;
} }
return SV_AddWaitingPlayers(); // strictly speaking, i'm not convinced the following is necessary
// but I'm not confident enough to remove it entirely in case it breaks something
{
SINT8 node = 0;
for (; node < MAXNETNODES; node++)
result |= SV_AddWaitingPlayers(node);
}
return result;
} }
void SV_StopServer(void) void SV_StopServer(void)
@@ -4759,17 +4767,6 @@ void SV_StartSinglePlayerServer(void)
multiplayer = true; multiplayer = true;
} }
static void SV_SendRefuse(INT32 node, const char *reason)
{
doomdata_t *netbuffer = DOOMCOM_DATA(doomcom);
strcpy(netbuffer->u.serverrefuse.reason, reason);
netbuffer->packettype = PT_SERVERREFUSE;
HSendPacket(node, false, 0, strlen(netbuffer->u.serverrefuse.reason) + 1);
Net_CloseConnection(node);
}
// used at txtcmds received to check packetsize bound // used at txtcmds received to check packetsize bound
static size_t TotalTextCmdPerTic(tic_t tic) static size_t TotalTextCmdPerTic(tic_t tic)
{ {
@@ -4786,15 +4783,25 @@ static size_t TotalTextCmdPerTic(tic_t tic)
return total; return total;
} }
/** Called when a PT_CLIENTJOIN packet is received static void SV_SendRefuse(INT32 node, const char *reason)
*
* \param node The packet sender
*
*/
static void HandleConnect(SINT8 node)
{ {
doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); doomdata_t *netbuffer = DOOMCOM_DATA(doomcom);
strcpy(netbuffer->u.serverrefuse.reason, reason);
netbuffer->packettype = PT_SERVERREFUSE;
HSendPacket(node, false, 0, strlen(netbuffer->u.serverrefuse.reason) + 1);
Net_CloseConnection(node);
}
static const char *GetRefuseMessage(SINT8 node)
{
doomdata_t *netbuffer = DOOMCOM_DATA(doomcom);
clientconfig_pak *cc = &netbuffer->u.clientcfg;
if (!node) /* server connecting to itself */
return NULL;
// Sal: Dedicated mode is INCREDIBLY hacked together. // Sal: Dedicated mode is INCREDIBLY hacked together.
// If a server filled out, then it'd overwrite the host and turn everyone into weird husks..... // If a server filled out, then it'd overwrite the host and turn everyone into weird husks.....
// It's too much effort to legimately fix right now. Just prevent it from reaching that state. // It's too much effort to legimately fix right now. Just prevent it from reaching that state.
@@ -4802,11 +4809,19 @@ static void HandleConnect(SINT8 node)
UINT8 connectedplayers = 0; UINT8 connectedplayers = 0;
for (UINT8 i = dedicated ? 1 : 0; i < MAXPLAYERS; i++) for (UINT8 i = dedicated ? 1 : 0; i < MAXPLAYERS; i++)
if (playernode[i] != UINT8_MAX) // We use this to count players because it is affected by SV_AddWaitingPlayers when more than one client joins on the same tic, unlike playeringame and D_NumPlayers. UINT8_MAX denotes no node for that player {
// We use this to count players because it is affected by SV_AddWaitingPlayers when
// more than one client joins on the same tic, unlike playeringame and D_NumPlayers.
// UINT8_MAX denotes no node for that player.
if (playernode[i] != UINT8_MAX)
{
connectedplayers++; connectedplayers++;
}
}
#ifdef SATURNJOIN #ifdef SATURNJOIN
const boolean issaturn = (((doomcom->datalength) == sizeof(clientconfig_pak)) && netbuffer->u.clientcfg.issaturn == ISSATURN); // Check the packet lenght to skip potential garbo data! const boolean issaturn = (((doomcom->datalength) == sizeof(clientconfig_pak)) && (cc->issaturn == ISSATURN)); // Check the packet length to skip garbo data!
#endif #endif
if (bannednode && bannednode[node].banid != SIZE_MAX) if (bannednode && bannednode[node].banid != SIZE_MAX)
@@ -4826,40 +4841,37 @@ static void HandleConnect(SINT8 node)
if (days) if (days)
{ {
SV_SendRefuse(node, va("K|%s\n(Time remaining: %d day%s)", reason, days, days > 1 ? "s" : "")); return va("K|%s\n(Time remaining: %d day%s)", reason, days, days > 1 ? "s" : "");
} }
else if (hours) else if (hours)
{ {
SV_SendRefuse(node, va("K|%s\n(Time remaining: %d hour%s)", reason, hours, hours > 1 ? "s" : "")); return va("K|%s\n(Time remaining: %d hour%s)", reason, hours, hours > 1 ? "s" : "");
} }
else if (minutes) else if (minutes)
{ {
SV_SendRefuse(node, va("K|%s\n(Time remaining: %d minute%s)", reason, minutes, minutes > 1 ? "s" : "")); return va("K|%s\n(Time remaining: %d minute%s)", reason, minutes, minutes > 1 ? "s" : "");
} }
else else
{ {
SV_SendRefuse(node, va("K|%s\n(Time remaining: <1 minute)", reason)); return va("K|%s\n(Time remaining: <1 minute)", reason);
} }
} }
else else
{ {
SV_SendRefuse(node, va("B|%s", reason)); return va("B|%s", reason);
} }
} }
else if (netbuffer->u.clientcfg._255 != 255 || else if (cc->_255 != 255 || cc->packetversion != PACKETVERSION)
netbuffer->u.clientcfg.packetversion != PACKETVERSION)
{ {
SV_SendRefuse(node, "Incompatible packet formats."); return "Incompatible packet formats.";
} }
else if (strncmp(netbuffer->u.clientcfg.application, SRB2APPLICATION, else if (strncmp(cc->application, SRB2APPLICATION, sizeof(cc->application)))
sizeof netbuffer->u.clientcfg.application))
{ {
SV_SendRefuse(node, "Different SRB2Kart modifications\nare not compatible."); return "Different SRB2Kart modifications\nare not compatible.";
} }
else if (netbuffer->u.clientcfg.version != VERSION else if (cc->version != VERSION || cc->subversion != SUBVERSION)
|| netbuffer->u.clientcfg.subversion != SUBVERSION)
{ {
SV_SendRefuse(node, va(M_GetText("Different SRB2Kart versions cannot\nplay a netgame!\n(server version %d.%d)"), VERSION, SUBVERSION)); return va("Different SRB2Kart versions cannot\nplay a netgame!\n(server version %d.%d)", VERSION, SUBVERSION);
} }
#ifdef SATURNJOIN #ifdef SATURNJOIN
else if (((!cv_allownewplayer.value && !issaturn) || (!cv_allownewsaturnplayer.value && issaturn)) && node) else if (((!cv_allownewplayer.value && !issaturn) || (!cv_allownewsaturnplayer.value && issaturn)) && node)
@@ -4867,37 +4879,54 @@ static void HandleConnect(SINT8 node)
else if (!cv_allownewplayer.value && node) else if (!cv_allownewplayer.value && node)
#endif #endif
{ {
SV_SendRefuse(node, M_GetText(cv_joinrefusemessage.string)); return cv_joinrefusemessage.string;
} }
else if (connectedplayers >= maxplayers) else if (connectedplayers >= maxplayers)
{ {
SV_SendRefuse(node, va(M_GetText("Maximum players reached: %d"), maxplayers)); return va("Maximum players reached: %d", maxplayers);
} }
else if (netgame && netbuffer->u.clientcfg.localplayers > 4) // Hacked client? else if (netgame && !cc->localplayers) // Stealth join?
{ {
SV_SendRefuse(node, M_GetText("Too many players from\nthis node.")); return "No players from\nthis node.";
} }
else if (netgame && connectedplayers + netbuffer->u.clientcfg.localplayers > maxplayers) else if (netgame && cc->localplayers > 4) // Hacked client?
{ {
SV_SendRefuse(node, va(M_GetText("Number of local players\nwould exceed maximum: %d"), maxplayers)); return "Too many players from\nthis node.";
} }
else if (netgame && !netbuffer->u.clientcfg.localplayers) // Stealth join? else if (netgame && connectedplayers + cc->localplayers > maxplayers)
{ {
SV_SendRefuse(node, M_GetText("No players from\nthis node.")); return va("Number of local players\nwould exceed maximum: %d", maxplayers);
} }
else
return NULL;
}
/** Called when a PT_CLIENTJOIN packet is received
*
* \param node The packet sender
*
*/
static void PT_ClientJoin(SINT8 node)
{
// Ignore duplicate packets
if (client || nodeingame[node] || levelloading)
return;
const char *refuse = GetRefuseMessage(node);
if (refuse)
{ {
boolean newnode = false; SV_SendRefuse(node, refuse);
return;
}
doomdata_t *netbuffer = DOOMCOM_DATA(doomcom);
// client authorised to join // client authorised to join
nodewaiting[node] = (UINT8)(netbuffer->u.clientcfg.localplayers - playerpernode[node]); nodewaiting[node] = (UINT8)(netbuffer->u.clientcfg.localplayers - playerpernode[node]);
if (!nodeingame[node])
{
gamestate_t backupstate = gamestate; gamestate_t backupstate = gamestate;
newnode = true;
SV_AddNode(node); SV_AddNode(node);
/// \note Wait what??? /// \note Wait what???
@@ -4910,29 +4939,25 @@ static void HandleConnect(SINT8 node)
{ {
G_SetGamestate(backupstate); G_SetGamestate(backupstate);
/// \note Shouldn't SV_SendRefuse be called before ResetNode? /// \note Shouldn't SV_SendRefuse be called before ResetNode?
SV_SendRefuse(node, M_GetText("Server couldn't send info, please try again")); SV_SendRefuse(node, "Server couldn't send info, please try again");
ResetNode(node); // Yeah, lets try it! ResetNode(node); // Yeah, lets try it!
/// \todo fix this !!! /// \todo fix this !!!
return; // restart the while return; // restart the while
} }
SV_SendServerInfo(node, 0); // Dunno if 0 time is good idea SV_SendServerInfo(node, 0); // Dunno if 0 time is good idea
//if (gamestate != GS_LEVEL) // GS_INTERMISSION, etc?
// SV_SendPlayerConfigs(node); // send bare minimum player info
G_SetGamestate(backupstate); G_SetGamestate(backupstate);
DEBFILE("new node joined\n"); DEBFILE("new node joined\n");
}
if (nodewaiting[node]) if (nodewaiting[node])
{ {
if (node && newnode) if (node)
{ {
SV_SendSaveGame(node, false); // send a complete game state SV_SendSaveGame(node, false); // send a complete game state
DEBFILE("send savegame\n"); DEBFILE("send savegame\n");
} }
SV_AddWaitingPlayers(); SV_AddWaitingPlayers(node);
}
} }
} }
@@ -4941,8 +4966,11 @@ static void HandleConnect(SINT8 node)
* \param node The packet sender (should be the server) * \param node The packet sender (should be the server)
* *
*/ */
static void HandleShutdown(SINT8 node) static void PT_ServerShutdown(SINT8 node)
{ {
if (node != servernode || server || cl_mode == CL_SEARCHING)
return;
(void)node; (void)node;
D_QuitNetGame(); D_QuitNetGame();
CL_Reset(); CL_Reset();
@@ -4970,7 +4998,7 @@ static void HandleTimeout(SINT8 node)
* \note What happens if the packet comes from a client or something like that? * \note What happens if the packet comes from a client or something like that?
* *
*/ */
static void HandleServerInfo(SINT8 node) static void PT_ServerInfo(SINT8 node)
{ {
char servername[MAXSERVERNAME]; char servername[MAXSERVERNAME];
doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); doomdata_t *netbuffer = DOOMCOM_DATA(doomcom);
@@ -4993,7 +5021,7 @@ static void HandleServerInfo(SINT8 node)
memcpy(connectedservername, netbuffer->u.serverinfo.servername, MAXSERVERNAME); memcpy(connectedservername, netbuffer->u.serverinfo.servername, MAXSERVERNAME);
} }
static void HandlePlayerInfo(void) static void PT_PlayerInfo(void)
{ {
INT32 i; INT32 i;
doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); doomdata_t *netbuffer = DOOMCOM_DATA(doomcom);
@@ -5391,6 +5419,9 @@ static void HandlePacketFromAwayNode(SINT8 node)
case PT_ASKINFOVIAMS: case PT_ASKINFOVIAMS:
Net_CloseConnection(node); Net_CloseConnection(node);
break; break;
case PT_SERVERINFO:
PT_ServerInfo(node);
break;
case PT_TELLFILESNEEDED: case PT_TELLFILESNEEDED:
PT_TellFilesNeeded(node); PT_TellFilesNeeded(node);
break; break;
@@ -5421,7 +5452,7 @@ static void HandlePacketFromAwayNode(SINT8 node)
case PT_CLIENTCMD: case PT_CLIENTCMD:
break; // This is not an "unknown packet" break; // This is not an "unknown packet"
case PT_PLAYERINFO: case PT_PLAYERINFO:
HandlePlayerInfo(); PT_PlayerInfo();
break; break;
case PT_MAPICON: case PT_MAPICON:
PT_MapIcon(); PT_MapIcon();
@@ -5429,12 +5460,17 @@ static void HandlePacketFromAwayNode(SINT8 node)
case PT_NEEDMAPICON: case PT_NEEDMAPICON:
PT_NeedMapIcon(node); PT_NeedMapIcon(node);
break; break;
case PT_SERVERSHUTDOWN:
PT_ServerShutdown(node);
break;
case PT_CLIENTJOIN:
PT_ClientJoin(node);
break;
case PT_SERVERTICS: case PT_SERVERTICS:
// Do not remove my own server (we have just get a out of order packet) // Do not remove my own server (we have just get a out of order packet)
if (node == servernode) if (node == servernode)
break; break;
/* FALLTHRU */ /* FALLTHRU */
default: default:
DEBFILE(va("unknown packet received (%d) from unknown host\n", netbuffer->packettype)); DEBFILE(va("unknown packet received (%d) from unknown host\n", netbuffer->packettype));
Net_CloseConnection(node); Net_CloseConnection(node);
@@ -5678,6 +5714,10 @@ static void PT_BasicKeepAlive(INT32 netconsole, SINT8 node)
static void PT_TextCmd(INT32 netconsole, SINT8 node) static void PT_TextCmd(INT32 netconsole, SINT8 node)
{ {
size_t j;
tic_t tic;
UINT8 *textcmd;
if (client) if (client)
return; return;
@@ -5699,12 +5739,10 @@ static void PT_TextCmd(INT32 netconsole, SINT8 node)
} }
if (netconsole < 0 || netconsole >= MAXPLAYERS) if (netconsole < 0 || netconsole >= MAXPLAYERS)
Net_UnAcknowledgePacket(node);
else
{ {
size_t j; Net_UnAcknowledgePacket(node);
tic_t tic = maketic; return;
UINT8 *textcmd; }
// ignore if the textcmd has a reported size of zero // ignore if the textcmd has a reported size of zero
// this shouldn't be sent at all // this shouldn't be sent at all
@@ -5731,6 +5769,8 @@ static void PT_TextCmd(INT32 netconsole, SINT8 node)
// doomcom->numslots+1 "+1" since doomcom->numslots can change within this time and sent time // doomcom->numslots+1 "+1" since doomcom->numslots can change within this time and sent time
j = (software_MAXPACKETLENGTH - (netbuffer->u.textcmd[0]+2+BASESERVERTICSSIZE + (doomcom->numslots+1)*sizeof(ticcmd_t))); j = (software_MAXPACKETLENGTH - (netbuffer->u.textcmd[0]+2+BASESERVERTICSSIZE + (doomcom->numslots+1)*sizeof(ticcmd_t)));
tic = maketic;
// search a tic that have enougth space in the ticcmd // search a tic that have enougth space in the ticcmd
while ((textcmd = D_GetExistingTextcmd(tic, netconsole)), while ((textcmd = D_GetExistingTextcmd(tic, netconsole)),
(TotalTextCmdPerTic(tic) > j || netbuffer->u.textcmd[0] + (textcmd ? textcmd[0] : 0) > MAXTEXTCMD) (TotalTextCmdPerTic(tic) > j || netbuffer->u.textcmd[0] + (textcmd ? textcmd[0] : 0) > MAXTEXTCMD)
@@ -5757,21 +5797,26 @@ static void PT_TextCmd(INT32 netconsole, SINT8 node)
memcpy(&textcmd[textcmd[0]+1], netbuffer->u.textcmd+1, netbuffer->u.textcmd[0]); memcpy(&textcmd[textcmd[0]+1], netbuffer->u.textcmd+1, netbuffer->u.textcmd[0]);
textcmd[0] += (UINT8)netbuffer->u.textcmd[0]; textcmd[0] += (UINT8)netbuffer->u.textcmd[0];
}
} }
static void PT_ClientQuit(INT32 netconsole, SINT8 node) static void PT_ClientQuit(INT32 netconsole, SINT8 node)
{ {
doomdata_t *netbuffer = DOOMCOM_DATA(doomcom);
if (client) if (client)
{
if (node == servernode && cl_mode != CL_SEARCHING && netbuffer->packettype == PT_NODETIMEOUT)
HandleTimeout(node);
return; return;
}
// nodeingame will be put false in the execution of kick command // nodeingame will be put false in the execution of kick command
// this allow to send some packets to the quitting client to have their ack back // this allow to send some packets to the quitting client to have their ack back
nodewaiting[node] = 0; nodewaiting[node] = 0;
if (netconsole != -1 && playeringame[netconsole]) if (netconsole != -1 && playeringame[netconsole])
{ {
doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); const int quitreason = ((netbuffer->packettype == PT_NODETIMEOUT) ? KICK_MSG_TIMEOUT : KICK_MSG_PLAYER_QUIT);
SendKick(netconsole, (netbuffer->packettype == PT_NODETIMEOUT) ? KICK_MSG_TIMEOUT : KICK_MSG_PLAYER_QUIT); SendKick(netconsole, quitreason);
} }
Net_CloseConnection(node); Net_CloseConnection(node);
nodeingame[node] = false; nodeingame[node] = false;
@@ -5957,9 +6002,6 @@ static void HandlePacketFromPlayer(SINT8 node)
switch (netbuffer->packettype) switch (netbuffer->packettype)
{ {
// -------------------------------------------- SERVER RECEIVE ---------- // -------------------------------------------- SERVER RECEIVE ----------
case PT_RESYNCHGET:
SV_AcknowledgeResynchAck(node, netbuffer->u.resynchgot);
break;
case PT_CLIENTCMD: case PT_CLIENTCMD:
case PT_CLIENT2CMD: case PT_CLIENT2CMD:
case PT_CLIENT3CMD: case PT_CLIENT3CMD:
@@ -5985,24 +6027,6 @@ static void HandlePacketFromPlayer(SINT8 node)
case PT_CLIENTQUIT: case PT_CLIENTQUIT:
PT_ClientQuit(netconsole, node); PT_ClientQuit(netconsole, node);
break; break;
// -------------------------------------------- CLIENT RECEIVE ----------
case PT_RESYNCHEND:
PT_Resynched(node);
break;
case PT_SERVERTICS:
PT_ServerTics(node);
break;
case PT_RESYNCHING:
PT_Resynching(node);
break;
case PT_PING:
PT_Ping(node);
break;
case PT_SERVERCFG:
break;
case PT_FILEFRAGMENT:
PT_FileFragmentFromPlayer(node);
break;
#ifdef SATURNPAK #ifdef SATURNPAK
case PT_CANRECEIVEGAMESTATE: case PT_CANRECEIVEGAMESTATE:
PT_CanReceiveGamestate(node); PT_CanReceiveGamestate(node);
@@ -6010,6 +6034,25 @@ static void HandlePacketFromPlayer(SINT8 node)
case PT_RECEIVEDGAMESTATE: case PT_RECEIVEDGAMESTATE:
PT_ReceivedGamestate(node); PT_ReceivedGamestate(node);
break; break;
#endif
case PT_SERVERINFO:
PT_ServerInfo(node);
break;
case PT_RESYNCHGET:
SV_AcknowledgeResynchAck(node, netbuffer->u.resynchgot);
break;
// -------------------------------------------- CLIENT RECEIVE ----------
case PT_SERVERTICS:
PT_ServerTics(node);
break;
case PT_PING:
PT_Ping(node);
break;
case PT_FILEFRAGMENT:
PT_FileFragmentFromPlayer(node);
break;
#ifdef SATURNPAK
case PT_WILLRESENDGAMESTATE: case PT_WILLRESENDGAMESTATE:
PT_WillResendGamestate(); PT_WillResendGamestate();
break; break;
@@ -6018,6 +6061,20 @@ static void HandlePacketFromPlayer(SINT8 node)
is_client_saturn[node] = true; is_client_saturn[node] = true;
break; break;
#endif #endif
case PT_SERVERSHUTDOWN:
PT_ServerShutdown(node);
break;
case PT_SERVERCFG:
break;
case PT_CLIENTJOIN:
PT_ClientJoin(node);
break;
case PT_RESYNCHING:
PT_Resynching(node);
break;
case PT_RESYNCHEND:
PT_Resynched(node);
break;
default: default:
DEBFILE(va("UNKNOWN PACKET TYPE RECEIVED %d from host %d\n", netbuffer->packettype, node)); DEBFILE(va("UNKNOWN PACKET TYPE RECEIVED %d from host %d\n", netbuffer->packettype, node));
} }
@@ -6038,36 +6095,6 @@ static void GetPackets(void)
{ {
node = (SINT8)doomcom->remotenode; node = (SINT8)doomcom->remotenode;
if (server && netbuffer->packettype == PT_CLIENTJOIN)
{
if (!levelloading) // Otherwise just ignore
{
HandleConnect(node);
}
continue;
}
if (client && node == servernode && cl_mode != CL_SEARCHING)
{
if (netbuffer->packettype == PT_SERVERSHUTDOWN)
{
HandleShutdown(node);
continue;
}
if (netbuffer->packettype == PT_NODETIMEOUT)
{
HandleTimeout(node);
continue;
}
}
if (netbuffer->packettype == PT_SERVERINFO)
{
HandleServerInfo(node);
continue;
}
/*if (netbuffer->packettype == PT_PLAYERINFO) /*if (netbuffer->packettype == PT_PLAYERINFO)
continue; // We do nothing with PLAYERINFO, that's for the MS browser. Not quite true anymore :p*/ continue; // We do nothing with PLAYERINFO, that's for the MS browser. Not quite true anymore :p*/
@@ -6386,21 +6413,7 @@ static void CL_SendClientCmd(void)
{ {
if (localtextcmd[i][0]) if (localtextcmd[i][0])
{ {
switch (i) netbuffer->packettype = PT_TEXTCMD + i;
{
case 3:
netbuffer->packettype = PT_TEXTCMD4;
break;
case 2:
netbuffer->packettype = PT_TEXTCMD3;
break;
case 1:
netbuffer->packettype = PT_TEXTCMD2;
break;
default:
netbuffer->packettype = PT_TEXTCMD;
break;
}
memcpy(netbuffer->u.textcmd, localtextcmd[i], localtextcmd[i][0]+1); memcpy(netbuffer->u.textcmd, localtextcmd[i], localtextcmd[i][0]+1);
@@ -6444,7 +6457,7 @@ static void SV_SendTics(void)
continue; continue;
// assert supposedtics[n]>=nettics[n] // assert supposedtics[n]>=nettics[n]
realfirsttic = max(supposedtics[n], firstticstosend); realfirsttic = supposedtics[n];
lasttictosend = min(maketic, nettics[n] + CLIENTBACKUPTICS); lasttictosend = min(maketic, nettics[n] + CLIENTBACKUPTICS);
if (realfirsttic >= lasttictosend) if (realfirsttic >= lasttictosend)
@@ -6618,7 +6631,7 @@ void SV_SpawnPlayer(INT32 playernum, INT32 x, INT32 y, angle_t angle)
// create missed tic // create missed tic
static void SV_Maketic(void) static void SV_Maketic(void)
{ {
G_MoveTiccmd(netcmds[maketic % BACKUPTICS], playercmds, MAXPLAYERS); G_CopyTiccmd(netcmds[maketic % BACKUPTICS], playercmds, MAXPLAYERS);
maketic++; maketic++;
} }
@@ -6835,8 +6848,10 @@ static inline void PingUpdate(void)
//send out our ping packets //send out our ping packets
for (i = 0; i < MAXNETNODES; i++) for (i = 0; i < MAXNETNODES; i++)
{
if (nodeingame[i]) if (nodeingame[i])
HSendPacket(i, true, 0, sizeof(INT32) * (MAXPLAYERS+1)); HSendPacket(i, true, 0, sizeof(INT32) * (MAXPLAYERS+1));
}
pingmeasurecount = 0; //Reset count pingmeasurecount = 0; //Reset count
} }
@@ -6939,10 +6954,15 @@ static void RenewHolePunch(void)
static void HandleNodeTimeouts(void) static void HandleNodeTimeouts(void)
{ {
INT32 i; INT32 i;
if (server) if (server)
{
for (i = 1; i < MAXNETNODES; i++) for (i = 1; i < MAXNETNODES; i++)
{
if (nodeingame[i] && freezetimeout[i] < I_GetTime()) if (nodeingame[i] && freezetimeout[i] < I_GetTime())
Net_ConnectionTimeout(i); Net_ConnectionTimeout(i);
}
}
} }
// Keep the network alive while not advancing tics! // Keep the network alive while not advancing tics!
@@ -7152,11 +7172,13 @@ void NetUpdate(void)
} }
for (i = 0; i < MAXNETNODES; ++i) for (i = 0; i < MAXNETNODES; ++i)
{
if (resynch_inprogress[i]) if (resynch_inprogress[i])
{ {
SV_SendResynch(i); SV_SendResynch(i);
counts = -666; counts = -666;
} }
}
// Do not make tics while resynching // Do not make tics while resynching
if (counts != -666) if (counts != -666)
@@ -7183,6 +7205,8 @@ void NetUpdate(void)
Net_AckTicker(); Net_AckTicker();
HandleNodeTimeouts(); HandleNodeTimeouts();
nowtime /= NEWTICRATERATIO;
if (nowtime > resptime) if (nowtime > resptime)
{ {
resptime = nowtime; resptime = nowtime;
@@ -7208,9 +7232,15 @@ void NetUpdate(void)
INT32 D_NumPlayers(void) INT32 D_NumPlayers(void)
{ {
INT32 num = 0, ix; INT32 num = 0, ix;
for (ix = 0; ix < MAXPLAYERS; ix++) for (ix = 0; ix < MAXPLAYERS; ix++)
{
if (playeringame[ix]) if (playeringame[ix])
{
num++; num++;
}
}
return num; return num;
} }
+3 -1
View File
@@ -660,9 +660,11 @@ extern UINT8 hu_redownloadinggamestate;
#endif #endif
extern boolean hu_stopped; // kart, true when the game is stopped for players due to a disconnecting or connecting player extern boolean hu_stopped; // kart, true when the game is stopped for players due to a disconnecting or connecting player
#define SAVEGAMESIZE (768*1024)
typedef struct rewind_s typedef struct rewind_s
{ {
UINT8 savebuffer[(768*1024)]; UINT8 savebuffer[SAVEGAMESIZE];
tic_t leveltime; tic_t leveltime;
size_t demopos; size_t demopos;
+5
View File
@@ -697,6 +697,11 @@ void D_SRB2Loop(void)
for (;;) for (;;)
{ {
if (I_Interrupted())
{
I_Quit();
}
// capbudget is the minimum precise_t duration of a single loop iteration // capbudget is the minimum precise_t duration of a single loop iteration
precise_t capbudget; precise_t capbudget;
precise_t elapsed; precise_t elapsed;
+1 -5
View File
@@ -612,12 +612,8 @@ void Net_WaitAllAckReceived(UINT32 timeout)
static void InitNode(node_t *node) static void InitNode(node_t *node)
{ {
node->acktosend_head = node->acktosend_tail = 0; memset(node, 0, sizeof(node_t));
memset(node->acktosend, 0, sizeof(node->acktosend));
node->firstacktosend = 0;
node->nextacknum = 1; node->nextacknum = 1;
node->remotefirstack = 0;
node->flags = 0;
} }
static void InitAck(void) static void InitAck(void)
+137 -475
View File
@@ -1208,11 +1208,11 @@ static boolean AllowedPlayerNameChar(char ch)
static boolean EnsurePlayerNameIsGood(char *name, INT32 playernum) static boolean EnsurePlayerNameIsGood(char *name, INT32 playernum)
{ {
INT32 ix; size_t ix, len = strlen(name);
if (strlen(name) == 0 || strlen(name) > MAXPLAYERNAME) if (len == 0 || len > MAXPLAYERNAME)
return false; // Empty or too long. return false; // Empty or too long.
if (name[0] == ' ' || name[strlen(name)-1] == ' ') if (name[0] == ' ' || name[len-1] == ' ')
return false; // Starts or ends with a space. return false; // Starts or ends with a space.
if (isdigit(name[0])) if (isdigit(name[0]))
return false; // Starts with a digit. return false; // Starts with a digit.
@@ -1226,20 +1226,19 @@ static boolean EnsurePlayerNameIsGood(char *name, INT32 playernum)
// Also, anything over 0x80 is disallowed too, since compilers love to // Also, anything over 0x80 is disallowed too, since compilers love to
// differ on whether they're printable characters or not. // differ on whether they're printable characters or not.
for (ix = 0; name[ix] != '\0'; ix++) for (ix = 0; ix < len; ix++)
if (!AllowedPlayerNameChar(name[ix])) if (!AllowedPlayerNameChar(name[ix]))
return false; return false;
// Check if a player is currently using the name, case-insensitively. // Check if a player is currently using the name, case-insensitively.
for (ix = 0; ix < MAXPLAYERS; ix++) for (ix = 0; ix < MAXPLAYERS; ix++)
{ {
if (ix != playernum && playeringame[ix] if (ix != (size_t)playernum && playeringame[ix]
&& fasticmp(name, player_names[ix])) && fasticmp(name, player_names[ix]))
{ {
// We shouldn't kick people out just because // We shouldn't kick people out just because
// they joined the game with the same name // they joined the game with the same name
// as someone else -- modify the name instead. // as someone else -- modify the name instead.
size_t len = strlen(name);
// Recursion! // Recursion!
// Slowly strip characters off the end of the // Slowly strip characters off the end of the
@@ -1458,7 +1457,9 @@ UINT8 CanChangeSkin(INT32 playernum)
return true; return true;
} }
if (players[playernum].spectator || players[playernum].playerstate == PST_DEAD || players[playernum].playerstate == PST_REBORN) if (players[playernum].spectator ||
players[playernum].playerstate == PST_DEAD ||
players[playernum].playerstate == PST_REBORN)
return true; return true;
return false; return false;
@@ -1492,445 +1493,144 @@ static void ForceAllSkins(INT32 forcedskin)
} }
} }
static INT32 snacpending = 0, snac2pending = 0, snac3pending = 0, snac4pending = 0, chmappending = 0; static INT32 chmappending;
static INT32 snacpending[MAXSPLITSCREENPLAYERS];
// wonky compat, idk if anything uses this....
#define playerisbot (splitplayer == 1 && botingame)
// name, color, or skin has changed // name, color, or skin has changed
// //
static void SendNameAndColor(void) static void SendNameAndColor(UINT8 splitplayer)
{ {
char buf[MAXPLAYERNAME+2]; char buf[MAXPLAYERNAME+2];
char *p; char *p;
p = buf; p = buf;
// splitscreen
if (splitscreen < splitplayer && !playerisbot)
return;
const INT32 pnum = P_GetLocalPlayerNumForNum(splitplayer);
player_t *player = &players[pnum];
// TODO: make those cvars arrays
consvar_t *playercolor, *playername, *playerskin;
consvar_t *colorvars[] = {&cv_playercolor, &cv_playercolor2, &cv_playercolor3, &cv_playercolor4};
consvar_t *namevars[] = {&cv_playername, &cv_playername2, &cv_playername3, &cv_playername4};
consvar_t *skinvars[] = {&cv_skin, &cv_skin2, &cv_skin3, &cv_skin4};
playercolor = colorvars[splitplayer];
playername = namevars[splitplayer];
playerskin = skinvars[splitplayer];
// normal player colors // normal player colors
if (G_GametypeHasTeams()) if (G_GametypeHasTeams())
{ {
if (players[consoleplayer].ctfteam == 1 && cv_playercolor.value != skincolor_redteam) if (player->ctfteam == 1 && playercolor->value != skincolor_redteam)
CV_StealthSetValue(&cv_playercolor, skincolor_redteam); CV_StealthSetValue(playercolor, skincolor_redteam);
else if (players[consoleplayer].ctfteam == 2 && cv_playercolor.value != skincolor_blueteam) else if (player->ctfteam == 2 && playercolor->value != skincolor_blueteam)
CV_StealthSetValue(&cv_playercolor, skincolor_blueteam); CV_StealthSetValue(playercolor, skincolor_blueteam);
} }
// never allow the color "none" // never allow the color "none"
if (!cv_playercolor.value) if (!playercolor->value)
{ {
if (players[consoleplayer].skincolor) if (player->skincolor)
CV_StealthSetValue(&cv_playercolor, players[consoleplayer].skincolor); CV_StealthSetValue(playercolor, player->skincolor);
else if (skins[players[consoleplayer].skin].prefcolor) else if (skins[player->skin].prefcolor)
CV_StealthSetValue(&cv_playercolor, skins[players[consoleplayer].skin].prefcolor); CV_StealthSetValue(playercolor, skins[player->skin].prefcolor);
else else
CV_StealthSet(&cv_playercolor, cv_playercolor.defaultvalue); CV_StealthSet(playercolor, playercolor->defaultvalue);
} }
if (fastcmp(cv_playername.string, player_names[consoleplayer])
&& cv_playercolor.value == players[consoleplayer].skincolor
&& fastcmp(cv_skin.string, skins[players[consoleplayer].skin].name))
return;
// We'll handle it later if we're not playing. // We'll handle it later if we're not playing.
if (!Playing()) if (!Playing())
return; return;
if (fastcmp(playername->string, player_names[pnum])
&& playercolor->value == player->skincolor
&& fastcmp(playerskin->string, skins[player->skin].name))
return;
if (playerisbot)
{
players[pnum].skincolor = botcolor;
if (players[pnum].mo)
players[pnum].mo->color = players[pnum].skincolor;
SetPlayerSkinByNum(pnum, botskin-1);
return;
}
// If you're not in a netgame, merely update the skin, color, and name. // If you're not in a netgame, merely update the skin, color, and name.
if (!netgame) if (!netgame)
{ {
INT32 foundskin; INT32 foundskin;
CleanupPlayerName(consoleplayer, cv_playername.zstring); CleanupPlayerName(pnum, playername->zstring);
strcpy(player_names[consoleplayer], cv_playername.zstring); strcpy(player_names[pnum], playername->zstring);
players[consoleplayer].skincolor = cv_playercolor.value; player->skincolor = playercolor->value;
if (players[consoleplayer].mo) if (player->mo)
players[consoleplayer].mo->color = players[consoleplayer].skincolor; player->mo->color = player->skincolor;
if ((foundskin = R_SkinAvailable(cv_skin.string)) != -1) if ((foundskin = R_SkinAvailable(playerskin->string)) != -1)
{ {
cv_skin.value = foundskin; playerskin->value = foundskin;
SetPlayerSkin(consoleplayer, cv_skin.string); SetPlayerSkin(pnum, playerskin->string);
CV_StealthSet(&cv_skin, skins[cv_skin.value].name); CV_StealthSet(playerskin, skins[playerskin->value].name);
} }
else else
{ {
cv_skin.value = players[consoleplayer].skin; playerskin->value = player->skin;
CV_StealthSet(&cv_skin, skins[players[consoleplayer].skin].name); CV_StealthSet(playerskin, skins[player->skin].name);
// will always be same as current // will always be same as current
SetPlayerSkin(consoleplayer, cv_skin.string); SetPlayerSkin(pnum, playerskin->string);
} }
return; return;
} }
snacpending++; snacpending[splitplayer]++;
// Don't change name if muted // Don't change name if muted
if (player_name_changes[consoleplayer] >= MAXNAMECHANGES) if (player_name_changes[pnum] >= MAXNAMECHANGES)
{ {
CV_StealthSet(&cv_playername, player_names[consoleplayer]); CV_StealthSet(playername, player_names[pnum]);
HU_AddChatText("\x85*You must wait to change your name again", false); HU_AddChatText("\x85*You must wait to change your name again", false);
} }
else if (cv_mute.value && !(server || IsPlayerAdmin(consoleplayer))) else if (cv_mute.value && !(server || IsPlayerAdmin(pnum)))
CV_StealthSet(&cv_playername, player_names[consoleplayer]); CV_StealthSet(playername, player_names[pnum]);
else // Cleanup name if changing it else // Cleanup name if changing it
CleanupPlayerName(consoleplayer, cv_playername.zstring); CleanupPlayerName(pnum, playername->zstring);
// Don't change skin if the server doesn't want you to. // Don't change skin if the server doesn't want you to.
if (!CanChangeSkin(consoleplayer)) if (!CanChangeSkin(pnum))
CV_StealthSet(&cv_skin, skins[players[consoleplayer].skin].name); CV_StealthSet(playerskin, skins[player->skin].name);
// check if player has the skin loaded (cv_skin may have // check if player has the skin loaded (cv_skin may have
// the name of a skin that was available in the previous game) // the name of a skin that was available in the previous game)
cv_skin.value = R_SkinAvailable(cv_skin.string); playerskin->value = R_SkinAvailable(playerskin->string);
if (cv_skin.value < 0) if (playerskin->value < 0)
{ {
INT32 skinnum = players[consoleplayer].skin; INT32 skinnum = player->skin;
CV_StealthSet(&cv_skin, skins[skinnum].name); CV_StealthSet(playerskin, skins[skinnum].name);
cv_skin.value = skinnum; playerskin->value = skinnum;
} }
// Finally write out the complete packet and send it off. // Finally write out the complete packet and send it off.
WRITESTRINGN(p, cv_playername.zstring, MAXPLAYERNAME); WRITESTRINGN(p, playername->zstring, MAXPLAYERNAME);
WRITEUINT8(p, (UINT8)cv_playercolor.value); WRITEUINT8(p, (UINT8)playercolor->value);
WRITEUINT8(p, (UINT8)cv_skin.value); WRITEUINT8(p, (UINT8)playerskin->value);
SendNetXCmdForPlayer(0, XD_NAMEANDCOLOR, buf, p - buf); SendNetXCmdForPlayer(splitplayer, XD_NAMEANDCOLOR, buf, p - buf);
}
// splitscreen
static void SendNameAndColor2(void)
{
INT32 secondplaya = -1;
char buf[MAXPLAYERNAME+2];
char *p;
if (splitscreen < 1 && !botingame)
return; // can happen if skin2/color2/name2 changed
if (displayplayers[1] != consoleplayer)
secondplaya = displayplayers[1];
else if (!netgame) // HACK
secondplaya = 1;
if (secondplaya == -1)
return;
p = buf;
// normal player colors
if (G_GametypeHasTeams())
{
if (players[secondplaya].ctfteam == 1 && cv_playercolor2.value != skincolor_redteam)
CV_StealthSetValue(&cv_playercolor2, skincolor_redteam);
else if (players[secondplaya].ctfteam == 2 && cv_playercolor2.value != skincolor_blueteam)
CV_StealthSetValue(&cv_playercolor2, skincolor_blueteam);
}
// never allow the color "none"
if (!cv_playercolor2.value)
{
if (players[secondplaya].skincolor)
CV_StealthSetValue(&cv_playercolor2, players[secondplaya].skincolor);
else if (skins[players[secondplaya].skin].prefcolor)
CV_StealthSetValue(&cv_playercolor2, skins[players[secondplaya].skin].prefcolor);
else
CV_StealthSet(&cv_playercolor2, cv_playercolor2.defaultvalue);
}
// We'll handle it later if we're not playing.
if (!Playing())
return;
// If you're not in a netgame, merely update the skin, color, and name.
if (botingame)
{
players[secondplaya].skincolor = botcolor;
if (players[secondplaya].mo)
players[secondplaya].mo->color = players[secondplaya].skincolor;
SetPlayerSkinByNum(secondplaya, botskin-1);
return;
}
else if (!netgame)
{
INT32 foundskin;
CleanupPlayerName(secondplaya, cv_playername2.zstring);
strcpy(player_names[secondplaya], cv_playername2.zstring);
// don't use displayplayers[1]: the second player must be 1
players[secondplaya].skincolor = cv_playercolor2.value;
if (players[secondplaya].mo)
players[secondplaya].mo->color = players[secondplaya].skincolor;
if ((foundskin = R_SkinAvailable(cv_skin2.string)) != -1)
{
cv_skin2.value = foundskin;
SetPlayerSkin(secondplaya, cv_skin2.string);
}
else
{
cv_skin2.value = players[secondplaya].skin;
CV_StealthSet(&cv_skin2, skins[players[secondplaya].skin].name);
// will always be same as current
SetPlayerSkin(secondplaya, cv_skin2.string);
}
return;
}
snac2pending++;
// Don't change name if muted
if (player_name_changes[displayplayers[1]] >= MAXNAMECHANGES)
{
CV_StealthSet(&cv_playername2, player_names[displayplayers[1]]);
HU_AddChatText("\x85*You must wait to change your name again", false);
}
else if (cv_mute.value && !(server || IsPlayerAdmin(displayplayers[1])))
CV_StealthSet(&cv_playername2, player_names[displayplayers[1]]);
else // Cleanup name if changing it
CleanupPlayerName(displayplayers[1], cv_playername2.zstring);
// Don't change skin if the server doesn't want you to.
if (!CanChangeSkin(displayplayers[1]))
CV_StealthSet(&cv_skin2, skins[players[displayplayers[1]].skin].name);
// check if player has the skin loaded (cv_skin2 may have
// the name of a skin that was available in the previous game)
cv_skin2.value = R_SkinAvailable(cv_skin2.string);
if (cv_skin2.value < 0)
{
INT32 skinnum = players[displayplayers[1]].skin;
CV_StealthSet(&cv_skin2, skins[skinnum].name);
cv_skin2.value = skinnum;
}
// Finally write out the complete packet and send it off.
WRITESTRINGN(p, cv_playername2.zstring, MAXPLAYERNAME);
WRITEUINT8(p, (UINT8)cv_playercolor2.value);
WRITEUINT8(p, (UINT8)cv_skin2.value);
SendNetXCmdForPlayer(1, XD_NAMEANDCOLOR, buf, p - buf);
}
static void SendNameAndColor3(void)
{
INT32 thirdplaya = -1;
char buf[MAXPLAYERNAME+2];
char *p;
if (splitscreen < 2)
return; // can happen if skin3/color3/name3 changed
if (displayplayers[2] != consoleplayer)
thirdplaya = displayplayers[2];
else if (!netgame) // HACK
thirdplaya = 2;
if (thirdplaya == -1)
return;
p = buf;
// normal player colors
if (G_GametypeHasTeams())
{
if (players[thirdplaya].ctfteam == 1 && cv_playercolor3.value != skincolor_redteam)
CV_StealthSetValue(&cv_playercolor3, skincolor_redteam);
else if (players[thirdplaya].ctfteam == 2 && cv_playercolor3.value != skincolor_blueteam)
CV_StealthSetValue(&cv_playercolor3, skincolor_blueteam);
}
// never allow the color "none"
if (!cv_playercolor3.value)
{
if (players[thirdplaya].skincolor)
CV_StealthSetValue(&cv_playercolor3, players[thirdplaya].skincolor);
else if (skins[players[thirdplaya].skin].prefcolor)
CV_StealthSetValue(&cv_playercolor3, skins[players[thirdplaya].skin].prefcolor);
else
CV_StealthSet(&cv_playercolor3, cv_playercolor3.defaultvalue);
}
// We'll handle it later if we're not playing.
if (!Playing())
return;
// If you're not in a netgame, merely update the skin, color, and name.
if (!netgame)
{
INT32 foundskin;
CleanupPlayerName(thirdplaya, cv_playername3.zstring);
strcpy(player_names[thirdplaya], cv_playername3.zstring);
// don't use displayplayers[2]: the third player must be 2
players[thirdplaya].skincolor = cv_playercolor3.value;
if (players[thirdplaya].mo)
players[thirdplaya].mo->color = players[thirdplaya].skincolor;
if ((foundskin = R_SkinAvailable(cv_skin3.string)) != -1)
{
cv_skin3.value = foundskin;
SetPlayerSkin(thirdplaya, cv_skin3.string);
}
else
{
cv_skin3.value = players[thirdplaya].skin;
CV_StealthSet(&cv_skin3, skins[players[thirdplaya].skin].name);
// will always be same as current
SetPlayerSkin(thirdplaya, cv_skin3.string);
}
return;
}
snac3pending++;
// Don't change name if muted
if (player_name_changes[displayplayers[2]] >= MAXNAMECHANGES)
{
CV_StealthSet(&cv_playername3, player_names[displayplayers[2]]);
HU_AddChatText("\x85*You must wait to change your name again", false);
}
else if (cv_mute.value && !(server || IsPlayerAdmin(displayplayers[2])))
CV_StealthSet(&cv_playername3, player_names[displayplayers[2]]);
else // Cleanup name if changing it
CleanupPlayerName(displayplayers[2], cv_playername3.zstring);
// Don't change skin if the server doesn't want you to.
if (!CanChangeSkin(displayplayers[2]))
CV_StealthSet(&cv_skin3, skins[players[displayplayers[2]].skin].name);
// check if player has the skin loaded (cv_skin3 may have
// the name of a skin that was available in the previous game)
cv_skin3.value = R_SkinAvailable(cv_skin3.string);
if (cv_skin3.value < 0)
{
INT32 skinnum = players[displayplayers[2]].skin;
CV_StealthSet(&cv_skin3, skins[skinnum].name);
cv_skin3.value = skinnum;
}
// Finally write out the complete packet and send it off.
WRITESTRINGN(p, cv_playername3.zstring, MAXPLAYERNAME);
WRITEUINT8(p, (UINT8)cv_playercolor3.value);
WRITEUINT8(p, (UINT8)cv_skin3.value);
SendNetXCmdForPlayer(2, XD_NAMEANDCOLOR, buf, p - buf);
}
static void SendNameAndColor4(void)
{
INT32 fourthplaya = -1;
char buf[MAXPLAYERNAME+2];
char *p;
if (splitscreen < 3)
return; // can happen if skin4/color4/name4 changed
if (displayplayers[3] != consoleplayer)
fourthplaya = displayplayers[3];
else if (!netgame) // HACK
fourthplaya = 3;
if (fourthplaya == -1)
return;
p = buf;
// normal player colors
if (G_GametypeHasTeams())
{
if (players[fourthplaya].ctfteam == 1 && cv_playercolor4.value != skincolor_redteam)
CV_StealthSetValue(&cv_playercolor4, skincolor_redteam);
else if (players[fourthplaya].ctfteam == 2 && cv_playercolor4.value != skincolor_blueteam)
CV_StealthSetValue(&cv_playercolor4, skincolor_blueteam);
}
// never allow the color "none"
if (!cv_playercolor4.value)
{
if (players[fourthplaya].skincolor)
CV_StealthSetValue(&cv_playercolor4, players[fourthplaya].skincolor);
else if (skins[players[fourthplaya].skin].prefcolor)
CV_StealthSetValue(&cv_playercolor4, skins[players[fourthplaya].skin].prefcolor);
else
CV_StealthSet(&cv_playercolor4, cv_playercolor4.defaultvalue);
}
// We'll handle it later if we're not playing.
if (!Playing())
return;
// If you're not in a netgame, merely update the skin, color, and name.
if (botingame)
{
players[fourthplaya].skincolor = botcolor;
if (players[fourthplaya].mo)
players[fourthplaya].mo->color = players[fourthplaya].skincolor;
SetPlayerSkinByNum(fourthplaya, botskin-1);
return;
}
else if (!netgame)
{
INT32 foundskin;
CleanupPlayerName(fourthplaya, cv_playername4.zstring);
strcpy(player_names[fourthplaya], cv_playername4.zstring);
// don't use displayplayers[3]: the second player must be 4
players[fourthplaya].skincolor = cv_playercolor4.value;
if (players[fourthplaya].mo)
players[fourthplaya].mo->color = players[fourthplaya].skincolor;
if ((foundskin = R_SkinAvailable(cv_skin4.string)) != -1)
{
cv_skin4.value = foundskin;
SetPlayerSkin(fourthplaya, cv_skin4.string);
}
else
{
cv_skin4.value = players[fourthplaya].skin;
CV_StealthSet(&cv_skin4, skins[players[fourthplaya].skin].name);
// will always be same as current
SetPlayerSkin(fourthplaya, cv_skin4.string);
}
return;
}
snac4pending++;
// Don't change name if muted
if (player_name_changes[displayplayers[3]] >= MAXNAMECHANGES)
{
CV_StealthSet(&cv_playername4, player_names[displayplayers[3]]);
HU_AddChatText("\x85*You must wait to change your name again", false);
}
else if (cv_mute.value && !(server || IsPlayerAdmin(displayplayers[3])))
CV_StealthSet(&cv_playername4, player_names[displayplayers[3]]);
else // Cleanup name if changing it
CleanupPlayerName(displayplayers[3], cv_playername4.zstring);
// Don't change skin if the server doesn't want you to.
if (!CanChangeSkin(displayplayers[3]))
CV_StealthSet(&cv_skin4, skins[players[displayplayers[3]].skin].name);
// check if player has the skin loaded (cv_skin4 may have
// the name of a skin that was available in the previous game)
cv_skin4.value = R_SkinAvailable(cv_skin4.string);
if (cv_skin4.value < 0)
{
INT32 skinnum = players[displayplayers[3]].skin;
CV_StealthSet(&cv_skin4, skins[skinnum].name);
cv_skin4.value = skinnum;
}
// Finally write out the complete packet and send it off.
WRITESTRINGN(p, cv_playername4.zstring, MAXPLAYERNAME);
WRITEUINT8(p, (UINT8)cv_playercolor4.value);
WRITEUINT8(p, (UINT8)cv_skin4.value);
SendNetXCmdForPlayer(3, XD_NAMEANDCOLOR, buf, p - buf);
} }
static void Got_NameAndColor(const UINT8 **cp, INT32 playernum) static void Got_NameAndColor(const UINT8 **cp, INT32 playernum)
{ {
player_t *p = &players[playernum]; player_t *player = &players[playernum];
char name[MAXPLAYERNAME+1]; char name[MAXPLAYERNAME+1];
UINT8 color, skin; UINT8 color, skin;
@@ -1939,19 +1639,14 @@ static void Got_NameAndColor(const UINT8 **cp, INT32 playernum)
I_Error("There is no player %d!", playernum); I_Error("There is no player %d!", playernum);
#endif #endif
if (playernum == consoleplayer) if (P_IsLocalPlayer(player))
snacpending--; // TODO: make snacpending an array instead of 4 separate vars? {
else if (playernum == displayplayers[1]) snacpending[playernum]--;
snac2pending--;
else if (playernum == displayplayers[2])
snac3pending--;
else if (playernum == displayplayers[3])
snac4pending--;
#ifdef PARANOIA #ifdef PARANOIA
if (snacpending < 0 || snac2pending < 0 || snac3pending < 0 || snac4pending < 0) if (snacpending[playernum] < 0)
I_Error("snacpending negative!"); I_Error("snacpending negative!");
#endif #endif
}
READSTRINGN(*cp, name, MAXPLAYERNAME); READSTRINGN(*cp, name, MAXPLAYERNAME);
color = READUINT8(*cp); color = READUINT8(*cp);
@@ -1965,33 +1660,32 @@ static void Got_NameAndColor(const UINT8 **cp, INT32 playernum)
} }
// set color // set color
p->skincolor = color % MAXSKINCOLORS; player->skincolor = color % MAXSKINCOLORS;
if (p->mo) if (player->mo)
p->mo->color = (UINT8)p->skincolor; player->mo->color = (UINT8)player->skincolor;
demo_extradata[playernum] |= DXD_COLOR; demo_extradata[playernum] |= DXD_COLOR;
// normal player colors // normal player colors
if (server && (p != &players[consoleplayer] && p != &players[displayplayers[1]] if (server && !P_IsLocalPlayer(player))
&& p != &players[displayplayers[2]] && p != &players[displayplayers[3]]))
{ {
boolean kick = false; boolean kick = false;
// team colors // team colors
if (G_GametypeHasTeams()) if (G_GametypeHasTeams())
{ {
if (p->ctfteam == 1 && p->skincolor != skincolor_redteam) if (player->ctfteam == 1 && player->skincolor != skincolor_redteam)
kick = true; kick = true;
else if (p->ctfteam == 2 && p->skincolor != skincolor_blueteam) else if (player->ctfteam == 2 && player->skincolor != skincolor_blueteam)
kick = true; kick = true;
} }
// don't allow color "none" // don't allow color "none"
if (!p->skincolor) if (!player->skincolor)
kick = true; kick = true;
if (kick) if (kick)
{ {
CONS_Alert(CONS_WARNING, M_GetText("Illegal color change received from %s (team: %d), color: %d)\n"), player_names[playernum], p->ctfteam, p->skincolor); CONS_Alert(CONS_WARNING, M_GetText("Illegal color change received from %s (team: %d), color: %d)\n"), player_names[playernum], player->ctfteam, player->skincolor);
SendKick(playernum, KICK_MSG_CON_FAIL); SendKick(playernum, KICK_MSG_CON_FAIL);
return; return;
} }
@@ -2003,6 +1697,7 @@ static void Got_NameAndColor(const UINT8 **cp, INT32 playernum)
const INT32 forcedskin = cv_forceskin.value; const INT32 forcedskin = cv_forceskin.value;
SetPlayerSkinByNum(playernum, forcedskin); SetPlayerSkinByNum(playernum, forcedskin);
// TODO: make cv_skin an array
if (playernum == consoleplayer) if (playernum == consoleplayer)
CV_StealthSet(&cv_skin, skins[forcedskin].name); CV_StealthSet(&cv_skin, skins[forcedskin].name);
else if (playernum == displayplayers[1]) else if (playernum == displayplayers[1])
@@ -2016,44 +1711,16 @@ static void Got_NameAndColor(const UINT8 **cp, INT32 playernum)
SetPlayerSkinByNum(playernum, skin); SetPlayerSkinByNum(playernum, skin);
} }
void SendWeaponPref(void) void SendWeaponPref(UINT8 splitplayer)
{ {
UINT8 buf[1]; UINT8 buf[1];
buf[0] = 0; buf[0] = 0;
if (cv_flipcam[0].value)
if (cv_flipcam[splitplayer].value)
buf[0] |= 1; buf[0] |= 1;
SendNetXCmdForPlayer(0, XD_WEAPONPREF, buf, 1);
}
void SendWeaponPref2(void) SendNetXCmdForPlayer(splitplayer, XD_WEAPONPREF, buf, 1);
{
UINT8 buf[1];
buf[0] = 0;
if (cv_flipcam[1].value)
buf[0] |= 1;
SendNetXCmdForPlayer(1, XD_WEAPONPREF, buf, 1);
}
void SendWeaponPref3(void)
{
UINT8 buf[1];
buf[0] = 0;
if (cv_flipcam[2].value)
buf[0] |= 1;
SendNetXCmdForPlayer(2, XD_WEAPONPREF, buf, 1);
}
void SendWeaponPref4(void)
{
UINT8 buf[1];
buf[0] = 0;
if (cv_flipcam[3].value)
buf[0] |= 1;
SendNetXCmdForPlayer(3, XD_WEAPONPREF, buf, 1);
} }
static void Got_WeaponPref(const UINT8 **cp, INT32 playernum) static void Got_WeaponPref(const UINT8 **cp, INT32 playernum)
@@ -2069,23 +1736,10 @@ static void Got_WeaponPref(const UINT8 **cp, INT32 playernum)
player->pflags |= PF_ANALOGMODE; player->pflags |= PF_ANALOGMODE;
} }
void D_SendPlayerConfig(void) void D_SendPlayerConfig(UINT8 splitplayer)
{ {
SendNameAndColor(); SendNameAndColor(splitplayer);
if (splitscreen || botingame) SendWeaponPref(splitplayer);
SendNameAndColor2();
if (splitscreen > 1)
SendNameAndColor3();
if (splitscreen > 2)
SendNameAndColor4();
SendWeaponPref();
if (splitscreen)
SendWeaponPref2();
if (splitscreen > 1)
SendWeaponPref3();
if (splitscreen > 2)
SendWeaponPref4();
} }
// Only works for displayplayer, sorry! // Only works for displayplayer, sorry!
@@ -2108,10 +1762,12 @@ INT32 D_LookupPlayer(const char *s)
return playernum; return playernum;
} }
const size_t len = strlen(s);
for (playernum = 0; playernum < MAXPLAYERS; ++playernum) for (playernum = 0; playernum < MAXPLAYERS; ++playernum)
{ {
/* Match name case-insensitively: fully, or partially the start. */ /* Match name case-insensitively: fully, or partially the start. */
if (playeringame[playernum] && (strnicmp(player_names[playernum], s, strlen(s)) == 0)) if (playeringame[playernum] && (strnicmp(player_names[playernum], s, len) == 0))
{ {
return playernum; return playernum;
} }
@@ -2151,6 +1807,7 @@ static void GetViewablePlayerPlaceRange(INT32 *first, INT32 *last)
(*last) = 0; (*last) = 0;
for (i = 0; i < MAXPLAYERS; ++i) for (i = 0; i < MAXPLAYERS; ++i)
{
if (G_CouldView(i)) if (G_CouldView(i))
{ {
place = players[i].kartstuff[k_position]; place = players[i].kartstuff[k_position];
@@ -2159,6 +1816,7 @@ static void GetViewablePlayerPlaceRange(INT32 *first, INT32 *last)
if (place > (*last)) if (place > (*last))
(*last) = place; (*last) = place;
} }
}
} }
#define PRINTVIEWPOINT( pre,suf ) \ #define PRINTVIEWPOINT( pre,suf ) \
@@ -2491,7 +2149,7 @@ void D_MapChange(INT32 mapnum, INT32 newgametype, boolean pencoremode, boolean r
displayplayers[1] = 1; displayplayers[1] = 1;
playeringame[1] = true; playeringame[1] = true;
players[1].bot = 1; players[1].bot = 1;
SendNameAndColor2(); SendNameAndColor(1);
} }
} }
@@ -5768,50 +5426,54 @@ static void ForceSkin_OnChange(void)
} }
} }
//Allows the player's name to be changed if cv_mute is off. // Allows the player's name to be changed if cv_mute is off.
static void Name_OnChange(void) static void Name_OnChange(void)
{ {
if (cv_mute.value && !(server || IsPlayerAdmin(consoleplayer))) if (cv_mute.value && !(server || IsPlayerAdmin(consoleplayer)))
{ {
CONS_Alert(CONS_NOTICE, M_GetText("You may not change your name when chat is muted.\n")); CONS_Alert(CONS_NOTICE, M_GetText("You may not change your name when chat is muted.\n"));
CV_StealthSet(&cv_playername, player_names[consoleplayer]); CV_StealthSet(&cv_playername, player_names[consoleplayer]);
return;
} }
else
SendNameAndColor(); SendNameAndColor(0);
} }
static void Name2_OnChange(void) static void Name2_OnChange(void)
{ {
if (cv_mute.value) //Secondary player can't be admin. if (cv_mute.value) // Secondary player can't be admin.
{ {
CONS_Alert(CONS_NOTICE, M_GetText("You may not change your name when chat is muted.\n")); CONS_Alert(CONS_NOTICE, M_GetText("You may not change your name when chat is muted.\n"));
CV_StealthSet(&cv_playername2, player_names[displayplayers[1]]); CV_StealthSet(&cv_playername2, player_names[displayplayers[1]]);
return;
} }
else
SendNameAndColor2(); SendNameAndColor(1);
} }
static void Name3_OnChange(void) static void Name3_OnChange(void)
{ {
if (cv_mute.value) //Third player can't be admin. if (cv_mute.value) // Third player can't be admin.
{ {
CONS_Alert(CONS_NOTICE, M_GetText("You may not change your name when chat is muted.\n")); CONS_Alert(CONS_NOTICE, M_GetText("You may not change your name when chat is muted.\n"));
CV_StealthSet(&cv_playername3, player_names[displayplayers[2]]); CV_StealthSet(&cv_playername3, player_names[displayplayers[2]]);
return;
} }
else
SendNameAndColor3(); SendNameAndColor(2);
} }
static void Name4_OnChange(void) static void Name4_OnChange(void)
{ {
if (cv_mute.value) //Secondary player can't be admin. if (cv_mute.value) // Secondary player can't be admin.
{ {
CONS_Alert(CONS_NOTICE, M_GetText("You may not change your name when chat is muted.\n")); CONS_Alert(CONS_NOTICE, M_GetText("You may not change your name when chat is muted.\n"));
CV_StealthSet(&cv_playername4, player_names[displayplayers[3]]); CV_StealthSet(&cv_playername4, player_names[displayplayers[3]]);
return;
} }
else
SendNameAndColor4(); SendNameAndColor(3);
} }
/** Sends a skin change for the console player, unless that player is moving. /** Sends a skin change for the console player, unless that player is moving.
@@ -5833,7 +5495,7 @@ static void Skin_OnChange(void)
} }
if (CanChangeSkin(consoleplayer) && !P_PlayerMoving(consoleplayer)) if (CanChangeSkin(consoleplayer) && !P_PlayerMoving(consoleplayer))
SendNameAndColor(); SendNameAndColor(0);
else else
{ {
CONS_Alert(CONS_NOTICE, M_GetText("You can't change your skin at the moment.\n")); CONS_Alert(CONS_NOTICE, M_GetText("You can't change your skin at the moment.\n"));
@@ -5854,7 +5516,7 @@ static void Skin2_OnChange(void)
return; // do whatever you want return; // do whatever you want
if (CanChangeSkin(displayplayers[1]) && !P_PlayerMoving(displayplayers[1])) if (CanChangeSkin(displayplayers[1]) && !P_PlayerMoving(displayplayers[1]))
SendNameAndColor2(); SendNameAndColor(1);
else else
{ {
CONS_Alert(CONS_NOTICE, M_GetText("You can't change your skin at the moment.\n")); CONS_Alert(CONS_NOTICE, M_GetText("You can't change your skin at the moment.\n"));
@@ -5870,7 +5532,7 @@ static void Skin3_OnChange(void)
return; // do whatever you want return; // do whatever you want
if (CanChangeSkin(displayplayers[2]) && !P_PlayerMoving(displayplayers[2])) if (CanChangeSkin(displayplayers[2]) && !P_PlayerMoving(displayplayers[2]))
SendNameAndColor3(); SendNameAndColor(2);
else else
{ {
CONS_Alert(CONS_NOTICE, M_GetText("You can't change your skin at the moment.\n")); CONS_Alert(CONS_NOTICE, M_GetText("You can't change your skin at the moment.\n"));
@@ -5886,7 +5548,7 @@ static void Skin4_OnChange(void)
return; // do whatever you want return; // do whatever you want
if (CanChangeSkin(displayplayers[3]) && !P_PlayerMoving(displayplayers[3])) if (CanChangeSkin(displayplayers[3]) && !P_PlayerMoving(displayplayers[3]))
SendNameAndColor4(); SendNameAndColor(3);
else else
{ {
CONS_Alert(CONS_NOTICE, M_GetText("You can't change your skin at the moment.\n")); CONS_Alert(CONS_NOTICE, M_GetText("You can't change your skin at the moment.\n"));
@@ -5999,7 +5661,7 @@ static void Color_OnChange(void)
if (!P_PlayerMoving(consoleplayer)) if (!P_PlayerMoving(consoleplayer))
{ {
// Color change menu scrolling fix is no longer necessary // Color change menu scrolling fix is no longer necessary
SendNameAndColor(); SendNameAndColor(0);
} }
else else
{ {
@@ -6021,7 +5683,7 @@ static void Color2_OnChange(void)
if (!P_PlayerMoving(displayplayers[1])) if (!P_PlayerMoving(displayplayers[1]))
{ {
// Color change menu scrolling fix is no longer necessary // Color change menu scrolling fix is no longer necessary
SendNameAndColor2(); SendNameAndColor(1);
} }
else else
{ {
@@ -6038,7 +5700,7 @@ static void Color3_OnChange(void)
if (!P_PlayerMoving(displayplayers[2])) if (!P_PlayerMoving(displayplayers[2]))
{ {
// Color change menu scrolling fix is no longer necessary // Color change menu scrolling fix is no longer necessary
SendNameAndColor3(); SendNameAndColor(2);
} }
else else
{ {
@@ -6055,7 +5717,7 @@ static void Color4_OnChange(void)
if (!P_PlayerMoving(displayplayers[3])) if (!P_PlayerMoving(displayplayers[3]))
{ {
// Color change menu scrolling fix is no longer necessary // Color change menu scrolling fix is no longer necessary
SendNameAndColor4(); SendNameAndColor(3);
} }
else else
{ {
+2 -5
View File
@@ -21,10 +21,7 @@ extern "C" {
#include "command.h" #include "command.h"
void SendWeaponPref(void); void SendWeaponPref(UINT8 splitplayer);
void SendWeaponPref2(void);
void SendWeaponPref3(void);
void SendWeaponPref4(void);
// console vars // console vars
extern consvar_t cv_playername; extern consvar_t cv_playername;
@@ -295,7 +292,7 @@ typedef union {
// add game commands, needs cleanup // add game commands, needs cleanup
void D_RegisterServerCommands(void); void D_RegisterServerCommands(void);
void D_RegisterClientCommands(void); void D_RegisterClientCommands(void);
void D_SendPlayerConfig(void); void D_SendPlayerConfig(UINT8 splitplayer);
void Command_ExitGame_f(void); void Command_ExitGame_f(void);
void Command_Retry_f(void); void Command_Retry_f(void);
void D_GameTypeChanged(INT32 lastgametype); // not a real _OnChange function anymore void D_GameTypeChanged(INT32 lastgametype); // not a real _OnChange function anymore
+1 -1
View File
@@ -960,7 +960,7 @@ void Got_Filetxpak(void)
|| fastcmp(filename, "music.kart") || fastcmp(filename, "music.kart")
|| fastcmp(filename, "patch.kart") || fastcmp(filename, "patch.kart")
)) ))
I_Error("Tried to download \"%s\"", filename); I_Error("Tried to download base-game file: \"%s\"", filename);
if (filenum >= fileneedednum) if (filenum >= fileneedednum)
{ {
+16 -5
View File
@@ -984,7 +984,7 @@ void I_SleepDuration(precise_t duration)
#endif #endif
} }
boolean g_in_exiting_signal_handler = false; static volatile sig_atomic_t g_in_exiting_signal_handler = false;
static void I_PrintSignal(INT32 signal_num, boolean core_dumped, char *signal_msg) static void I_PrintSignal(INT32 signal_num, boolean core_dumped, char *signal_msg)
{ {
@@ -1048,6 +1048,11 @@ static void I_ReportSignal(int num, int coredumped)
I_OutputMsg("\nProcess killed by signal: %s\n\n", sigmsg); I_OutputMsg("\nProcess killed by signal: %s\n\n", sigmsg);
} }
boolean I_In_Exiting_Signal_Handler(void)
{
return g_in_exiting_signal_handler;
}
#ifndef NEWSIGNALHANDLER #ifndef NEWSIGNALHANDLER
FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num)
{ {
@@ -1067,11 +1072,17 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num)
} }
#endif #endif
FUNCNORETURN static ATTRNORETURN void quit_handler(int num) static volatile sig_atomic_t interrupted = 0;
boolean I_Interrupted(void)
{ {
signal(num, SIG_DFL); //default signal action return interrupted;
raise(num); }
I_Quit();
static void quit_handler(int num)
{
(void)num;
interrupted = 1;
} }
#ifdef HAVE_LIBBACKTRACE #ifdef HAVE_LIBBACKTRACE
+2 -2
View File
@@ -173,7 +173,7 @@ FUNCPRINTF static void deh_warning(const char *first, ...)
vsnprintf(buf, 1000, first, argptr); // sizeof only returned 4 here. it didn't like that pointer. vsnprintf(buf, 1000, first, argptr); // sizeof only returned 4 here. it didn't like that pointer.
va_end(argptr); va_end(argptr);
if(dbg_line == -1) // Not in a SOC, line number unknown. if (dbg_line == -1) // Not in a SOC, line number unknown.
CONS_Alert(CONS_WARNING, "%s\n", buf); CONS_Alert(CONS_WARNING, "%s\n", buf);
else else
CONS_Alert(CONS_WARNING, "Line %u: %s\n", dbg_line, buf); CONS_Alert(CONS_WARNING, "Line %u: %s\n", dbg_line, buf);
@@ -8545,7 +8545,7 @@ static inline int lib_action(lua_State *L)
// Hardcoded A_Action name to call for super() or NULL if super() would be invalid. // Hardcoded A_Action name to call for super() or NULL if super() would be invalid.
// Set in lua_infolib. // Set in lua_infolib.
const char *superactions[MAXRECURSION]; const char *superactions[MAXRECURSION] = {};
UINT8 superstack = 0; UINT8 superstack = 0;
static int lib_dummysuper(lua_State *L) static int lib_dummysuper(lua_State *L)
+1 -4
View File
@@ -69,9 +69,6 @@ UINT8 botcolor = 0;
JoyType_t Joystick[MAXSPLITSCREENPLAYERS] = {}; JoyType_t Joystick[MAXSPLITSCREENPLAYERS] = {};
// 1024 bytes is plenty for a savegame
#define SAVEGAMESIZE (1024)
// SRB2kart // SRB2kart
char gamedatafilename[64] = "kartdata.dat"; char gamedatafilename[64] = "kartdata.dat";
char timeattackfolder[64] = "kart"; char timeattackfolder[64] = "kart";
@@ -3902,7 +3899,7 @@ void G_SaveGame(UINT32 savegameslot)
char name[VERSIONSIZE]; char name[VERSIONSIZE];
size_t length; size_t length;
save.p = save.buffer = (UINT8 *)Z_Malloc(SAVEGAMESIZE, PU_STATIC, NULL); save.p = save.buffer = (UINT8 *)Z_Malloc(1024, PU_STATIC, NULL); // 1024 bytes is plenty for a savegame
if (!save.p) if (!save.p)
{ {
CONS_Alert(CONS_ERROR, M_GetText("No more free memory for saving game data\n")); CONS_Alert(CONS_ERROR, M_GetText("No more free memory for saving game data\n"));
+1
View File
@@ -318,6 +318,7 @@ static void
HMS_end (struct HMS_buffer *buffer) HMS_end (struct HMS_buffer *buffer)
{ {
curl_easy_cleanup(buffer->curl); curl_easy_cleanup(buffer->curl);
free(buffer->errbuf);
free(buffer->buffer); free(buffer->buffer);
free(buffer); free(buffer);
} }
+5 -1
View File
@@ -43,7 +43,7 @@ extern UINT8 graphics_started;
extern UINT8 keyboard_started; extern UINT8 keyboard_started;
/** \brief Set to true when inside a signal handler that will exit the program. */ /** \brief Set to true when inside a signal handler that will exit the program. */
extern boolean g_in_exiting_signal_handler; boolean I_In_Exiting_Signal_Handler(void);
/** \brief The I_GetFreeMem function /** \brief The I_GetFreeMem function
@@ -195,6 +195,10 @@ INT32 I_StartupSystem(void);
*/ */
void I_ShutdownSystem(void); void I_ShutdownSystem(void);
/** \brief To check if a Interrupt or Terminate Signal was fired
*/
boolean I_Interrupted(void);
/** \brief The I_GetDiskFreeSpace function /** \brief The I_GetDiskFreeSpace function
\param freespace a INT64 pointer to hold the free space amount \param freespace a INT64 pointer to hold the free space amount
+9 -7
View File
@@ -496,8 +496,10 @@ static void cleanupnodes(void)
// Why can't I start at zero? // Why can't I start at zero?
for (j = 1; j < MAXNETNODES; j++) for (j = 1; j < MAXNETNODES; j++)
{
if (!(nodeingame[j] || SV_SendingFile(j))) if (!(nodeingame[j] || SV_SendingFile(j)))
nodeconnected[j] = false; nodeconnected[j] = false;
}
} }
static SINT8 getfreenode(void) static SINT8 getfreenode(void)
@@ -507,11 +509,13 @@ static SINT8 getfreenode(void)
cleanupnodes(); cleanupnodes();
for (j = 0; j < MAXNETNODES; j++) for (j = 0; j < MAXNETNODES; j++)
{
if (!nodeconnected[j]) if (!nodeconnected[j])
{ {
nodeconnected[j] = true; nodeconnected[j] = true;
return j; return j;
} }
}
/** \warning No free node? Just in case a node might not have been freed properly, /** \warning No free node? Just in case a node might not have been freed properly,
* look if there are connected nodes that aren't in game, and forget them. * look if there are connected nodes that aren't in game, and forget them.
@@ -812,7 +816,7 @@ static void SOCK_Send(void)
static void SOCK_FreeNodenum(INT32 numnode) static void SOCK_FreeNodenum(INT32 numnode)
{ {
// can't disconnect from self :) // can't disconnect from self :)
if (!numnode || numnode > MAXNETNODES) if (numnode <= 0 || numnode > MAXNETNODES)
return; return;
DEBFILE(va("Free node %d (%s)\n", numnode, SOCK_GetNodeAddress(numnode))); DEBFILE(va("Free node %d (%s)\n", numnode, SOCK_GetNodeAddress(numnode)));
@@ -1432,14 +1436,12 @@ static void SOCK_RegisterHolePunch(void)
static boolean SOCK_OpenSocket(void) static boolean SOCK_OpenSocket(void)
{ {
size_t i; memset(clientaddress, 0, sizeof(clientaddress));
memset(clientaddress, 0, sizeof (clientaddress));
memset(nodeconnected, false, sizeof(nodeconnected));
nodeconnected[0] = true; // always connected to self nodeconnected[0] = true; // always connected to self
for (i = 1; i < MAXNETNODES; i++)
nodeconnected[i] = false;
nodeconnected[BROADCASTADDR] = true; nodeconnected[BROADCASTADDR] = true;
I_NetSend = SOCK_Send; I_NetSend = SOCK_Send;
I_NetGet = SOCK_Get; I_NetGet = SOCK_Get;
I_NetCloseSocket = SOCK_CloseSocket; I_NetCloseSocket = SOCK_CloseSocket;
@@ -1479,7 +1481,7 @@ static boolean SOCK_Ban(INT32 node)
{ {
INT32 ban; INT32 ban;
if (node > MAXNETNODES) if (node < 0 || node > MAXNETNODES)
return false; return false;
ban = numbans; ban = numbans;
+31 -14
View File
@@ -931,21 +931,21 @@ const char *K_GetItemPatch(UINT8 item, boolean tiny)
//} //}
INT32 ITEM_X, ITEM_Y; // Item Window static INT32 ITEM_X, ITEM_Y; // Item Window
INT32 TIME_X, TIME_Y; // Time Sticker static INT32 TIME_X, TIME_Y; // Time Sticker
INT32 LAPS_X, LAPS_Y; // Lap Sticker static INT32 LAPS_X, LAPS_Y; // Lap Sticker
INT32 SPDM_X, SPDM_Y; // Speedometer static INT32 SPDM_X, SPDM_Y; // Speedometer
INT32 POSI_X, POSI_Y; // Position Number static INT32 POSI_X, POSI_Y; // Position Number
INT32 FACE_X, FACE_Y; // Top-four Faces static INT32 FACE_X, FACE_Y; // Top-four Faces
INT32 STCD_X, STCD_Y; // Starting countdown static INT32 STCD_X, STCD_Y; // Starting countdown
INT32 CHEK_Y; // CHECK graphic static INT32 CHEK_Y; // CHECK graphic
INT32 MINI_X, MINI_Y; // Minimap static INT32 MINI_X, MINI_Y; // Minimap
INT32 WANT_X, WANT_Y; // Battle WANTED poster static INT32 WANT_X, WANT_Y; // Battle WANTED poster
// This is for the P2 and P4 side of splitscreen. Then we'll flip P1's and P2's to the bottom with V_SPLITSCREEN. // This is for the P2 and P4 side of splitscreen. Then we'll flip P1's and P2's to the bottom with V_SPLITSCREEN.
INT32 ITEM2_X, ITEM2_Y; static INT32 ITEM2_X, ITEM2_Y;
INT32 LAPS2_X, LAPS2_Y; static INT32 LAPS2_X, LAPS2_Y;
INT32 POSI2_X, POSI2_Y; static INT32 POSI2_X, POSI2_Y;
static void K_initKartHUD(void) static void K_initKartHUD(void)
{ {
@@ -3816,7 +3816,7 @@ static void K_drawKartMinimap(void)
if (cv_showminimapangle.value && (minidoticon || minilighticon) && !playertimedout) if (cv_showminimapangle.value && (minidoticon || minilighticon) && !playertimedout)
{ {
UINT8 *colormap; UINT8 *colormap = NULL;
drawinfo_t dims; drawinfo_t dims;
fixed_t interpx, interpy; fixed_t interpx, interpy;
fixed_t xoff = 0, yoff = 0; fixed_t xoff = 0, yoff = 0;
@@ -3827,10 +3827,27 @@ static void K_drawKartMinimap(void)
if (encoremode) if (encoremode)
ang = ANGLE_180 - ang; ang = ANGLE_180 - ang;
if (mobj->color)
{
if (mobj->colorized) if (mobj->colorized)
{
colormap = R_GetTranslationColormap(TC_RAINBOW, mobj->color, GTC_CACHE); colormap = R_GetTranslationColormap(TC_RAINBOW, mobj->color, GTC_CACHE);
}
else else
{
const INT32 skinnum = K_GetMobjLocalSkinNum(mobj->skin, mobj->localskin, mobj->skinlocal);
// special case if startcolor is not the default (160 / Green)
if (skinnum && skins[skinnum].starttranscolor != skins[0].starttranscolor)
{
colormap = R_GetTranslationColormap(TC_DEFAULT, mobj->color, GTC_CACHE);
}
else
{
colormap = R_GetLocalTranslationColormap(mobj->skin, mobj->localskin, mobj->color, GTC_CACHE, mobj->skinlocal); colormap = R_GetLocalTranslationColormap(mobj->skin, mobj->localskin, mobj->color, GTC_CACHE, mobj->skinlocal);
}
}
}
interpx = lerp(mobj->old_x, mobj->x); interpx = lerp(mobj->old_x, mobj->x);
interpy = lerp(mobj->old_y, mobj->y); interpy = lerp(mobj->old_y, mobj->y);
+10 -1
View File
@@ -660,13 +660,22 @@ INT32 K_GetSkinNum(player_t *player)
// //
// returns the mobj skinnumber // returns the mobj skinnumber
// accounts for localskins // accounts for localskins ?
// //
INT32 K_GetMobjSkinNum(const skin_t *skin, boolean local) INT32 K_GetMobjSkinNum(const skin_t *skin, boolean local)
{ {
return skin - K_GetSkinArray(local); return skin - K_GetSkinArray(local);
} }
//
// returns the mobj skinnumber
// accounts for localskins
//
INT32 K_GetMobjLocalSkinNum(const skin_t *skin, const skin_t *localskin, boolean local)
{
return localskin ? (localskin - K_GetSkinArray(local)) : (skin - skins);
}
// //
// returns the players skinnumber // returns the players skinnumber
// accounts for localskins // accounts for localskins
+5 -5
View File
@@ -4016,16 +4016,16 @@ boolean replaynamesloaded = false;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_mutex replayquerymutex; I_mutex replayquerymutex;
// g_in_exiting_signal_handler is an evil hack // I_In_Exiting_Signal_Handler is an evil hack
// to avoid infinite SIGABRT recursion in the signal handler // to avoid infinite SIGABRT recursion in the signal handler
// due to poisoned locks or mach-o kernel not supporting locks in signals // due to poisoned locks or mach-o kernel not supporting locks in signals
// or something like that. idk // or something like that. idk
# define Lock_search_state() if (!g_in_exiting_signal_handler) { I_lock_mutex(&replayquerymutex); } # define Lock_search_state() if (!I_In_Exiting_Signal_Handler()) { I_LockMutex(&replayquerymutex); }
# define Unlock_search_state() if (!g_in_exiting_signal_handler) { I_unlock_mutex(replayquerymutex); } # define Unlock_search_state() if (!I_In_Exiting_Signal_Handler()) { I_UnlockMutex(replayquerymutex); }
#else/*HAVE_THREADS*/ #else /*HAVE_THREADS*/
# define Lock_search_state() # define Lock_search_state()
# define Unlock_search_state() # define Unlock_search_state()
#endif/*HAVE_THREADS*/ #endif /*HAVE_THREADS*/
#define MAXREPLAYQUERY 37 #define MAXREPLAYQUERY 37
+1
View File
@@ -262,6 +262,7 @@ Finish_registration (void)
{ {
CONS_Printf("\n"); CONS_Printf("\n");
CONS_Alert(CONS_NOTICE, "%s\n", rules); CONS_Alert(CONS_NOTICE, "%s\n", rules);
free(rules);
} }
if (registered) if (registered)
+2 -2
View File
@@ -831,7 +831,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck)
{ {
S_StartSound(toucher, special->info->seesound); S_StartSound(toucher, special->info->seesound);
if (player->pflags & PF_NIGHTSMODE) if (UNLIKELY(player->pflags & PF_NIGHTSMODE))
{ {
player->bumpertime = TICRATE/2; player->bumpertime = TICRATE/2;
if (special->threshold > 0) if (special->threshold > 0)
@@ -1131,7 +1131,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck)
S_StartSound(toucher, special->info->painsound); S_StartSound(toucher, special->info->painsound);
return; return;
} }
else if (((player->pflags & PF_NIGHTSMODE) && (player->pflags & PF_DRILLING)) || (player->pflags & (PF_JUMPED|PF_SPINNING|PF_GLIDING)) else if (UNLIKELY((player->pflags & PF_NIGHTSMODE) && (player->pflags & PF_DRILLING)) || (player->pflags & (PF_JUMPED|PF_SPINNING|PF_GLIDING))
|| player->powers[pw_invulnerability] || player->powers[pw_super]) // Do you possess the ability to subdue the object? || player->powers[pw_invulnerability] || player->powers[pw_super]) // Do you possess the ability to subdue the object?
{ {
// Shatter the shield! // Shatter the shield!
-6
View File
@@ -30,8 +30,6 @@ extern "C" {
#define FLOATSPEED (FRACUNIT*4) #define FLOATSPEED (FRACUNIT*4)
//#define VIEWHEIGHTS "41"
// Maximum player score. // Maximum player score.
#define MAXSCORE 999999990 #define MAXSCORE 999999990
@@ -239,14 +237,10 @@ void P_InstaThrustEvenIn2D(mobj_t *mo, angle_t angle, fixed_t move);
boolean P_LookForEnemies(player_t *player); boolean P_LookForEnemies(player_t *player);
void P_NukeEnemies(mobj_t *inflictor, mobj_t *source, fixed_t radius); void P_NukeEnemies(mobj_t *inflictor, mobj_t *source, fixed_t radius);
void P_HomingAttack(mobj_t *source, mobj_t *enemy); /// \todo doesn't belong in p_user void P_HomingAttack(mobj_t *source, mobj_t *enemy); /// \todo doesn't belong in p_user
//boolean P_SuperReady(player_t *player);
boolean P_AnalogMove(player_t *player); boolean P_AnalogMove(player_t *player);
/*boolean P_TransferToNextMare(player_t *player);
UINT8 P_FindLowestMare(void);*/
UINT8 P_FindLowestLap(void); UINT8 P_FindLowestLap(void);
UINT8 P_FindHighestLap(void); UINT8 P_FindHighestLap(void);
void P_FindEmerald(void); void P_FindEmerald(void);
//void P_TransferToAxis(player_t *player, INT32 axisnum);
boolean P_PlayerMoving(INT32 pnum); boolean P_PlayerMoving(INT32 pnum);
void P_Telekinesis(player_t *player, fixed_t thrust, fixed_t range); void P_Telekinesis(player_t *player, fixed_t thrust, fixed_t range);
+9 -9
View File
@@ -919,12 +919,7 @@ static void P_PlayerFlip(mobj_t *mo)
G_GhostAddFlip((INT32) (mo->player - players)); G_GhostAddFlip((INT32) (mo->player - players));
// Flip aiming to match! // Flip aiming to match!
if (UNLIKELY(mo->player->pflags & PF_NIGHTSMODE)) // NiGHTS doesn't use flipcam if (mo->player->pflags & PF_FLIPCAM)
{
if (mo->tracer)
mo->tracer->eflags ^= MFE_VERTICALFLIP;
}
else if (mo->player->pflags & PF_FLIPCAM)
{ {
UINT8 i; UINT8 i;
@@ -946,6 +941,11 @@ static void P_PlayerFlip(mobj_t *mo)
camera[i].z += FixedMul(20*FRACUNIT, mo->scale); camera[i].z += FixedMul(20*FRACUNIT, mo->scale);
} }
} }
else if (UNLIKELY(mo->player->pflags & PF_NIGHTSMODE)) // NiGHTS doesn't use flipcam
{
if (mo->tracer)
mo->tracer->eflags ^= MFE_VERTICALFLIP;
}
} }
// //
@@ -3252,7 +3252,7 @@ void P_CalcChasePostImg(player_t *player, camera_t *thiscam)
player_flipcam = cv_flipcam[pnum].value; player_flipcam = cv_flipcam[pnum].value;
} }
const boolean flipcam = (player_flipcam && !(player->pflags & PF_NIGHTSMODE) && player->mo->eflags & MFE_VERTICALFLIP); const boolean flipcam = (player_flipcam && player->mo->eflags & MFE_VERTICALFLIP && LIKELY(!(player->pflags & PF_NIGHTSMODE)));
UINT8 postimgtype = 0; UINT8 postimgtype = 0;
if (encoremode) if (encoremode)
@@ -8553,7 +8553,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj)
if (mobj->tracer && mobj->tracer->player) if (mobj->tracer && mobj->tracer->player)
{ {
if (!(mobj->tracer->player->pflags & PF_NIGHTSMODE)) if (LIKELY(!(mobj->tracer->player->pflags & PF_NIGHTSMODE)))
{ {
mobj->flags &= ~MF_NOGRAVITY; mobj->flags &= ~MF_NOGRAVITY;
mobj->flags2 &= ~MF2_DONTDRAW; mobj->flags2 &= ~MF2_DONTDRAW;
@@ -8577,7 +8577,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj)
P_SetTarget(&mobj->target, NULL); P_SetTarget(&mobj->target, NULL);
} }
if (mobj->tracer->player->pflags & PF_NIGHTSMODE) if (UNLIKELY(mobj->tracer->player->pflags & PF_NIGHTSMODE))
{ {
if (mobj->tracer->player->bonustime) if (mobj->tracer->player->bonustime)
{ {
+3 -3
View File
@@ -4399,7 +4399,7 @@ static void P_RunSpecialSectorCheck(player_t *player, sector_t *sector)
// The list of specials that activate without floor touch // The list of specials that activate without floor touch
// Check Section 1 // Check Section 1
switch(GETSECSPECIAL(sector->special, 1)) switch (GETSECSPECIAL(sector->special, 1))
{ {
//case 2: // Damage (water) //case 2: // Damage (water)
case 8: // Instant kill case 8: // Instant kill
@@ -4410,7 +4410,7 @@ static void P_RunSpecialSectorCheck(player_t *player, sector_t *sector)
} }
// Check Section 2 // Check Section 2
switch(GETSECSPECIAL(sector->special, 2)) switch (GETSECSPECIAL(sector->special, 2))
{ {
case 2: // Linedef executor (All players needed) case 2: // Linedef executor (All players needed)
case 4: // Linedef executor case 4: // Linedef executor
@@ -4421,7 +4421,7 @@ static void P_RunSpecialSectorCheck(player_t *player, sector_t *sector)
} }
// Check Section 4 // Check Section 4
switch(GETSECSPECIAL(sector->special, 4)) switch (GETSECSPECIAL(sector->special, 4))
{ {
case 2: // Level Exit / GOAL Sector / Flag Return case 2: // Level Exit / GOAL Sector / Flag Return
case 1: // Starpost activator case 1: // Starpost activator
+1 -1
View File
@@ -4109,7 +4109,7 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall
angle -= (angle - thiscam->pitch)/2; angle -= (angle - thiscam->pitch)/2;
} }
if (player->playerstate != PST_DEAD && !((player->pflags & PF_NIGHTSMODE) && player->exiting)) if (player->playerstate != PST_DEAD && LIKELY(!((player->pflags & PF_NIGHTSMODE) && player->exiting)))
angle += (focusaiming < ANGLE_180 ? focusaiming/2 : InvAngle(InvAngle(focusaiming)/2)); // overcomplicated version of '((signed)focusaiming)/2;' angle += (focusaiming < ANGLE_180 ? focusaiming/2 : InvAngle(InvAngle(focusaiming)/2)); // overcomplicated version of '((signed)focusaiming)/2;'
if (!camstill && !timeover) // Keep the view still... if (!camstill && !timeover) // Keep the view still...
+1 -2
View File
@@ -437,8 +437,7 @@ UINT8* R_GetTranslationColormap(INT32 skinnum, skincolors_t color, UINT8 flags)
UINT8* R_GetLocalTranslationColormap(skin_t *skin, skin_t *localskin, skincolors_t color, UINT8 flags, boolean local) UINT8* R_GetLocalTranslationColormap(skin_t *skin, skin_t *localskin, skincolors_t color, UINT8 flags, boolean local)
{ {
const INT32 skinnum = localskin ? (localskin - K_GetSkinArray(local)) : (skin - skins); return RGetTranslationColormap(K_GetMobjLocalSkinNum(skin, localskin, local), color, flags, (localskin && local));
return RGetTranslationColormap(skinnum, color, flags, (localskin && local));
} }
patch_t* R_GetSkinFaceRank(player_t* ply) patch_t* R_GetSkinFaceRank(player_t* ply)
+4 -4
View File
@@ -280,22 +280,22 @@ static void Fov_OnChange(void)
static void FlipCam_OnChange(void) static void FlipCam_OnChange(void)
{ {
SendWeaponPref(); SendWeaponPref(0);
} }
static void FlipCam2_OnChange(void) static void FlipCam2_OnChange(void)
{ {
SendWeaponPref2(); SendWeaponPref(1);
} }
static void FlipCam3_OnChange(void) static void FlipCam3_OnChange(void)
{ {
SendWeaponPref3(); SendWeaponPref(2);
} }
static void FlipCam4_OnChange(void) static void FlipCam4_OnChange(void)
{ {
SendWeaponPref4(); SendWeaponPref(3);
} }
static void Precipstuff_OnChange(void) static void Precipstuff_OnChange(void)
+1
View File
@@ -92,6 +92,7 @@ INT32 R_LocalSkinAvailable(const char *name, boolean local);
// had to move those here Zzz... // had to move those here Zzz...
INT32 K_GetSkinNum(player_t *player); INT32 K_GetSkinNum(player_t *player);
INT32 K_GetMobjSkinNum(const skin_t *skin, boolean local); INT32 K_GetMobjSkinNum(const skin_t *skin, boolean local);
INT32 K_GetMobjLocalSkinNum(const skin_t *skin, const skin_t *localskin, boolean local);
skin_t *K_GetPlayerSkin(player_t *player); skin_t *K_GetPlayerSkin(player_t *player);
skin_t *K_GetMobjSkin(const mobj_t *mobj); skin_t *K_GetMobjSkin(const mobj_t *mobj);
patch_t *K_GetFacePrefix(player_t *player, INT32 skinnum); patch_t *K_GetFacePrefix(player_t *player, INT32 skinnum);
+16 -15
View File
@@ -1577,7 +1577,7 @@ static void write_backtrace(bt_crash_reason_t reason)
static std::thread::id g_main_thread_id; static std::thread::id g_main_thread_id;
#endif #endif
boolean g_in_exiting_signal_handler = false; static volatile sig_atomic_t g_in_exiting_signal_handler = false;
static void I_PrintSignal(INT32 signal_num, boolean core_dumped, char *signal_msg, char *signal_name) static void I_PrintSignal(INT32 signal_num, boolean core_dumped, char *signal_msg, char *signal_name)
{ {
@@ -1712,6 +1712,11 @@ static void I_ReportSignal(int num, int coredumped)
I_ShowErrorBox(sigttl, sigmsg); I_ShowErrorBox(sigttl, sigmsg);
} }
boolean I_In_Exiting_Signal_Handler(void)
{
return g_in_exiting_signal_handler;
}
#ifndef NEWSIGNALHANDLER #ifndef NEWSIGNALHANDLER
FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num)
{ {
@@ -1741,21 +1746,17 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num)
} }
#endif #endif
FUNCNORETURN static ATTRNORETURN void quit_handler(int num) static volatile sig_atomic_t interrupted = false;
{
#ifdef HAVE_THREADS
if (g_main_thread_id != std::this_thread::get_id())
{
// Do not attempt any sort of recovery if this signal triggers off the main thread
signal(num, SIG_DFL);
raise(num);
exit(-2);
}
#endif
signal(num, SIG_DFL); //default signal action boolean I_Interrupted(void)
raise(num); {
I_Quit(); return interrupted;
}
static void quit_handler(int num)
{
(void)num;
interrupted = true;
} }
static void I_RegisterSignals(void) static void I_RegisterSignals(void)
+1
View File
@@ -2027,6 +2027,7 @@ void I_ShutdownGraphics(void)
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
window = NULL; window = NULL;
if (SDL_WasInit(SDL_INIT_VIDEO) == SDL_INIT_VIDEO)
SDL_QuitSubSystem(SDL_INIT_VIDEO); SDL_QuitSubSystem(SDL_INIT_VIDEO);
framebuffer = SDL_FALSE; framebuffer = SDL_FALSE;
} }
+1
View File
@@ -237,6 +237,7 @@ void I_ShutdownSound(void)
Mix_Quit(); Mix_Quit();
#endif #endif
if (SDL_WasInit(SDL_INIT_AUDIO) == SDL_INIT_AUDIO)
SDL_QuitSubSystem(SDL_INIT_AUDIO); SDL_QuitSubSystem(SDL_INIT_AUDIO);
#ifdef HAVE_LIBGME #ifdef HAVE_LIBGME