This commit is contained in:
LJ Sonic 2023-01-14 20:02:06 +01:00
parent 8df0debd54
commit a54155e2cc
10 changed files with 132 additions and 226 deletions

View file

@ -60,7 +60,7 @@ static inline void CL_DrawConnectionStatus(void)
if (cl_mode != CL_DOWNLOADFILES && cl_mode != CL_LOADFILES)
{
INT32 i, animtime = ((ccstime / 4) & 15) + 16;
INT32 animtime = ((ccstime / 4) & 15) + 16;
UINT8 palstart;
const char *cltext;
@ -75,7 +75,7 @@ static inline void CL_DrawConnectionStatus(void)
palstart = 96; // Green
if (!(cl_mode == CL_DOWNLOADSAVEGAME && lastfilenum != -1))
for (i = 0; i < 16; ++i) // 15 pal entries total.
for (INT32 i = 0; i < 16; ++i) // 15 pal entries total.
V_DrawFill((BASEVIDWIDTH/2-128) + (i * 16), BASEVIDHEIGHT-16, 16, 8, palstart + ((animtime - i) & 15));
switch (cl_mode)
@ -134,14 +134,13 @@ static inline void CL_DrawConnectionStatus(void)
{
INT32 totalfileslength;
INT32 loadcompletednum = 0;
INT32 i;
V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT-16-16, V_YELLOWMAP, "Press ESC to abort");
//ima just count files here
if (fileneeded)
{
for (i = 0; i < fileneedednum; i++)
for (INT32 i = 0; i < fileneedednum; i++)
if (fileneeded[i].status == FS_OPEN)
loadcompletednum++;
}
@ -277,9 +276,7 @@ UINT32 serverlistcount = 0;
static void SL_ClearServerList(INT32 connectedserver)
{
UINT32 i;
for (i = 0; i < serverlistcount; i++)
for (UINT32 i = 0; i < serverlistcount; i++)
if (connectedserver != serverlist[i].node)
{
Net_CloseConnection(serverlist[i].node|FORCECLOSE);
@ -290,8 +287,7 @@ static void SL_ClearServerList(INT32 connectedserver)
static UINT32 SL_SearchServer(INT32 node)
{
UINT32 i;
for (i = 0; i < serverlistcount; i++)
for (UINT32 i = 0; i < serverlistcount; i++)
if (serverlist[i].node == node)
return i;
@ -388,9 +384,7 @@ Fetch_servers_thread (struct Fetch_servers_ctx *ctx)
void CL_QueryServerList (msg_server_t *server_list)
{
INT32 i;
for (i = 0; server_list[i].header.buffer[0]; i++)
for (INT32 i = 0; server_list[i].header.buffer[0]; i++)
{
// Make sure MS version matches our own, to
// thwart nefarious servers who lie to the MS.
@ -781,7 +775,6 @@ static boolean CL_ServerConnectionSearchTicker(tic_t *asksent)
static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic_t *asksent)
{
boolean waitmore;
INT32 i;
switch (cl_mode)
{
@ -808,7 +801,7 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic
break;
case CL_DOWNLOADFILES:
waitmore = false;
for (i = 0; i < fileneedednum; i++)
for (INT32 i = 0; i < fileneedednum; i++)
if (fileneeded[i].status == FS_DOWNLOADING
|| fileneeded[i].status == FS_REQUESTED)
{

View file

@ -79,7 +79,6 @@ static void Ban_Clear(void)
void Ban_Load_File(boolean warning)
{
FILE *f;
size_t i;
const char *address, *mask;
char buffer[MAX_WADPATH];
@ -97,7 +96,7 @@ void Ban_Load_File(boolean warning)
Ban_Clear();
for (i=0; fgets(buffer, (int)sizeof(buffer), f); i++)
for (size_t i=0; fgets(buffer, (int)sizeof(buffer), f); i++)
{
address = strtok(buffer, " \t\r\n");
mask = strtok(NULL, " \t\r\n");
@ -113,7 +112,6 @@ void Ban_Load_File(boolean warning)
void D_SaveBan(void)
{
FILE *f;
size_t i;
banreason_t *reasonlist = reasonhead;
const char *address, *mask;
const char *path = va("%s"PATHSEP"%s", srb2home, "ban.txt");
@ -132,7 +130,7 @@ void D_SaveBan(void)
return;
}
for (i = 0;(address = I_GetBanAddress(i)) != NULL;i++)
for (size_t i = 0;(address = I_GetBanAddress(i)) != NULL;i++)
{
if (!I_GetBanMask || (mask = I_GetBanMask(i)) == NULL)
fprintf(f, "%s 0", address);
@ -236,12 +234,12 @@ void Command_Ban(void)
}
else
{
size_t i, j = COM_Argc();
size_t j = COM_Argc();
char message[MAX_REASONLENGTH];
//Steal from the motd code so you don't have to put the reason in quotes.
strlcpy(message, COM_Argv(2), sizeof message);
for (i = 3; i < j; i++)
for (size_t i = 3; i < j; i++)
{
strlcat(message, " ", sizeof message);
strlcat(message, COM_Argv(i), sizeof message);
@ -340,12 +338,12 @@ void Command_Kick(void)
}
else
{
size_t i, j = COM_Argc();
size_t j = COM_Argc();
char message[MAX_REASONLENGTH];
//Steal from the motd code so you don't have to put the reason in quotes.
strlcpy(message, COM_Argv(2), sizeof message);
for (i = 3; i < j; i++)
for (size_t i = 3; i < j; i++)
{
strlcat(message, " ", sizeof message);
strlcat(message, COM_Argv(i), sizeof message);
@ -435,9 +433,7 @@ void Command_connect(void)
void Command_GetPlayerNum(void)
{
INT32 i;
for (i = 0; i < MAXPLAYERS; i++)
for (INT32 i = 0; i < MAXPLAYERS; i++)
if (playeringame[i])
{
if (serverplayer == i)
@ -453,18 +449,17 @@ void Command_GetPlayerNum(void)
*/
void Command_Nodes(void)
{
INT32 i;
size_t maxlen = 0;
const char *address;
for (i = 0; i < MAXPLAYERS; i++)
for (INT32 i = 0; i < MAXPLAYERS; i++)
{
const size_t plen = strlen(player_names[i]);
if (playeringame[i] && plen > maxlen)
maxlen = plen;
}
for (i = 0; i < MAXPLAYERS; i++)
for (INT32 i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i])
{

View file

@ -440,11 +440,9 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum)
if (M_CheckParm("-consisdump")) // Helps debugging some problems
{
INT32 i;
CONS_Printf(M_GetText("Player kicked is #%d, dumping consistency...\n"), pnum);
for (i = 0; i < MAXPLAYERS; i++)
for (INT32 i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i])
continue;
@ -545,8 +543,8 @@ static void RedistributeSpecialStageSpheres(INT32 playernum)
INT32 sincrement = max(spheres / count, 1);
INT32 rincrement = max(rings / count, 1);
INT32 i, n;
for (i = 0; i < MAXPLAYERS; i++)
INT32 n;
for (INT32 i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i] || i == playernum)
continue;
@ -644,10 +642,8 @@ void D_QuitNetGame(void)
if (server)
{
INT32 i;
netbuffer->packettype = PT_SERVERSHUTDOWN;
for (i = 0; i < MAXNETNODES; i++)
for (INT32 i = 0; i < MAXNETNODES; i++)
if (netnodes[i].ingame)
HSendPacket(i, true, 0, 0);
#ifdef MASTERSERVER
@ -701,8 +697,6 @@ void CL_RemoveSplitscreenPlayer(void)
void SV_ResetServer(void)
{
INT32 i;
// +1 because this command will be executed in com_executebuffer in
// tryruntic so gametic will be incremented, anyway maketic > gametic
// is not an issue
@ -713,10 +707,10 @@ void SV_ResetServer(void)
joindelay = 0;
for (i = 0; i < MAXNETNODES; i++)
for (INT32 i = 0; i < MAXNETNODES; i++)
ResetNode(i);
for (i = 0; i < MAXPLAYERS; i++)
for (INT32 i = 0; i < MAXPLAYERS; i++)
{
LUA_InvalidatePlayer(&players[i]);
playeringame[i] = false;
@ -755,10 +749,9 @@ void SV_ResetServer(void)
static inline void SV_GenContext(void)
{
UINT8 i;
// generate server_context, as exactly 8 bytes of randomly mixed A-Z and a-z
// (hopefully M_Random is initialized!! if not this will be awfully silly!)
for (i = 0; i < 8; i++)
for (UINT8 i = 0; i < 8; i++)
{
const char a = M_RandomKey(26*2);
if (a < 26) // uppercase
@ -814,8 +807,6 @@ void SV_StartSinglePlayerServer(void)
void SV_StopServer(void)
{
tic_t i;
if (gamestate == GS_INTERMISSION)
Y_EndIntermission();
gamestate = wipegamestate = GS_NULL;
@ -823,7 +814,7 @@ void SV_StopServer(void)
localtextcmd[0] = 0;
localtextcmd2[0] = 0;
for (i = firstticstosend; i < firstticstosend + BACKUPTICS; i++)
for (tic_t i = firstticstosend; i < firstticstosend + BACKUPTICS; i++)
D_Clearticcmd(i);
consoleplayer = 0;
@ -913,7 +904,6 @@ If they're not lagging, decrement the timer by 1. Of course, reset all of this i
static inline void PingUpdate(void)
{
INT32 i;
boolean laggers[MAXPLAYERS];
UINT8 numlaggers = 0;
memset(laggers, 0, sizeof(boolean) * MAXPLAYERS);
@ -923,7 +913,7 @@ static inline void PingUpdate(void)
//check for ping limit breakage.
if (cv_maxping.value)
{
for (i = 1; i < MAXPLAYERS; i++)
for (INT32 i = 1; i < MAXPLAYERS; i++)
{
if (playeringame[i] && !players[i].quittime
&& (realpingtable[i] / pingmeasurecount > (unsigned)cv_maxping.value))
@ -940,7 +930,7 @@ static inline void PingUpdate(void)
//in that case, it is probably the server's fault.
if (numlaggers < D_NumPlayers() - 1)
{
for (i = 1; i < MAXPLAYERS; i++)
for (INT32 i = 1; i < MAXPLAYERS; i++)
{
if (playeringame[i] && laggers[i])
{
@ -965,7 +955,7 @@ static inline void PingUpdate(void)
}
//make the ping packet and clear server data for next one
for (i = 0; i < MAXPLAYERS; i++)
for (INT32 i = 0; i < MAXPLAYERS; i++)
{
netbuffer->u.pingtable[i] = realpingtable[i] / pingmeasurecount;
//server takes a snapshot of the real ping for display.
@ -978,7 +968,7 @@ static inline void PingUpdate(void)
netbuffer->u.pingtable[MAXPLAYERS] = cv_maxping.value;
//send out our ping packets
for (i = 0; i < MAXNETNODES; i++)
for (INT32 i = 0; i < MAXNETNODES; i++)
if (netnodes[i].ingame)
HSendPacket(i, true, 0, sizeof(INT32) * (MAXPLAYERS+1));
@ -999,8 +989,7 @@ static void PT_Ping(SINT8 node, INT32 netconsole)
//Update client ping table from the server.
if (client)
{
UINT8 i;
for (i = 0; i < MAXPLAYERS; i++)
for (INT32 i = 0; i < MAXPLAYERS; i++)
if (playeringame[i])
playerpingtable[i] = (tic_t)netbuffer->u.pingtable[i];
@ -1225,7 +1214,6 @@ void NetUpdate(void)
static tic_t gametime = 0;
static tic_t resptime = 0;
tic_t nowtime;
INT32 i;
INT32 realtics;
nowtime = I_GetTime();
@ -1248,7 +1236,7 @@ void NetUpdate(void)
if (netgame && !(gametime % 35)) // update once per second.
PingUpdate();
// update node latency values so we can take an average later.
for (i = 0; i < MAXPLAYERS; i++)
for (INT32 i = 0; i < MAXPLAYERS; i++)
if (playeringame[i] && playernode[i] != UINT8_MAX)
realpingtable[i] += G_TicsToMilliseconds(GetLag(playernode[i]));
pingmeasurecount++;
@ -1287,7 +1275,7 @@ void NetUpdate(void)
hu_redownloadinggamestate = false;
firstticstosend = gametic;
for (i = 0; i < MAXNETNODES; i++)
for (INT32 i = 0; i < MAXNETNODES; i++)
if (netnodes[i].ingame && netnodes[i].tic < firstticstosend)
{
firstticstosend = netnodes[i].tic;
@ -1301,7 +1289,7 @@ void NetUpdate(void)
if (maketic + counts >= firstticstosend + BACKUPTICS)
counts = firstticstosend+BACKUPTICS-maketic-1;
for (i = 0; i < counts; i++)
for (INT32 i = 0; i < counts; i++)
SV_Maketic(); // Create missed tics and increment maketic
for (; tictoclear < firstticstosend; tictoclear++) // Clear only when acknowledged
@ -1318,7 +1306,7 @@ void NetUpdate(void)
// Handle timeouts to prevent definitive freezes from happenning
if (server)
{
for (i = 1; i < MAXNETNODES; i++)
for (INT32 i = 1; i < MAXNETNODES; i++)
if (netnodes[i].ingame && netnodes[i].freezetimeout < I_GetTime())
Net_ConnectionTimeout(i);
@ -1387,7 +1375,7 @@ void D_ClientServerInit(void)
SINT8 nametonum(const char *name)
{
INT32 playernum, i;
INT32 playernum;
if (!strcmp(name, "0"))
return 0;
@ -1405,7 +1393,7 @@ SINT8 nametonum(const char *name)
return -1;
}
for (i = 0; i < MAXPLAYERS; i++)
for (INT32 i = 0; i < MAXPLAYERS; i++)
if (playeringame[i] && !stricmp(player_names[i], name))
return (SINT8)i;
@ -1427,8 +1415,8 @@ boolean Playing(void)
*/
INT32 D_NumPlayers(void)
{
INT32 num = 0, ix;
for (ix = 0; ix < MAXPLAYERS; ix++)
INT32 num = 0;
for (INT32 ix = 0; ix < MAXPLAYERS; ix++)
if (playeringame[ix])
num++;
return num;
@ -1444,7 +1432,6 @@ INT32 D_NumPlayers(void)
//
INT16 Consistancy(void)
{
INT32 i;
UINT32 ret = 0;
#ifdef MOBJCONSISTANCY
thinker_t *th;
@ -1453,7 +1440,7 @@ INT16 Consistancy(void)
DEBFILE(va("TIC %u ", gametic));
for (i = 0; i < MAXPLAYERS; i++)
for (INT32 i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i])
ret ^= 0xCCCC;

View file

@ -211,7 +211,7 @@ FUNCMATH static INT32 cmpack(UINT8 a, UINT8 b)
static boolean GetFreeAcknum(UINT8 *freeack, boolean lowtimer)
{
node_t *node = &nodes[doomcom->remotenode];
INT32 i, numfreeslot = 0;
INT32 numfreeslot = 0;
if (cmpack((UINT8)((node->remotefirstack + MAXACKTOSEND) % 256), node->nextacknum) < 0)
{
@ -219,7 +219,7 @@ static boolean GetFreeAcknum(UINT8 *freeack, boolean lowtimer)
return false;
}
for (i = 0; i < MAXACKPACKETS; i++)
for (INT32 i = 0; i < MAXACKPACKETS; i++)
if (!ackpak[i].acknum)
{
// For low priority packets, make sure to let freeslots so urgent packets can be sent
@ -276,10 +276,10 @@ static boolean GetFreeAcknum(UINT8 *freeack, boolean lowtimer)
*/
INT32 Net_GetFreeAcks(boolean urgent)
{
INT32 i, numfreeslot = 0;
INT32 numfreeslot = 0;
INT32 n = 0; // Number of free acks found
for (i = 0; i < MAXACKPACKETS; i++)
for (INT32 i = 0; i < MAXACKPACKETS; i++)
if (!ackpak[i].acknum)
{
// For low priority packets, make sure to let freeslots so urgent packets can be sent
@ -315,7 +315,6 @@ static void RemoveAck(INT32 i)
// We have got a packet, proceed the ack request and ack return
static boolean Processackpak(void)
{
INT32 i;
boolean goodpacket = true;
node_t *node = &nodes[doomcom->remotenode];
@ -324,7 +323,7 @@ static boolean Processackpak(void)
{
node->remotefirstack = netbuffer->ackreturn;
// Search the ackbuffer and free it
for (i = 0; i < MAXACKPACKETS; i++)
for (INT32 i = 0; i < MAXACKPACKETS; i++)
if (ackpak[i].acknum && ackpak[i].destinationnode == node - nodes
&& cmpack(ackpak[i].acknum, netbuffer->ackreturn) <= 0)
{
@ -346,7 +345,7 @@ static boolean Processackpak(void)
else
{
// Check if it is not already in the queue
for (i = node->acktosend_tail; i != node->acktosend_head; i = (i+1) % MAXACKTOSEND)
for (INT32 i = node->acktosend_tail; i != node->acktosend_head; i = (i+1) % MAXACKTOSEND)
if (node->acktosend[i] == ack)
{
DEBFILE(va("Discard(2) ack %d (duplicated)\n", ack));
@ -374,7 +373,7 @@ static boolean Processackpak(void)
while (change)
{
change = false;
for (i = node->acktosend_tail; i != node->acktosend_head;
for (INT32 i = node->acktosend_tail; i != node->acktosend_head;
i = (i+1) % MAXACKTOSEND)
{
if (cmpack(node->acktosend[i], nextfirstack) <= 0)
@ -434,11 +433,9 @@ void Net_SendAcks(INT32 node)
static void GotAcks(void)
{
INT32 i, j;
for (j = 0; j < MAXACKTOSEND; j++)
for (INT32 j = 0; j < MAXACKTOSEND; j++)
if (netbuffer->u.textcmd[j])
for (i = 0; i < MAXACKPACKETS; i++)
for (INT32 i = 0; i < MAXACKPACKETS; i++)
if (ackpak[i].acknum && ackpak[i].destinationnode == doomcom->remotenode)
{
if (ackpak[i].acknum == netbuffer->u.textcmd[j])
@ -475,9 +472,8 @@ void Net_ConnectionTimeout(INT32 node)
// Resend the data if needed
void Net_AckTicker(void)
{
INT32 i;
for (i = 0; i < MAXACKPACKETS; i++)
for (INT32 i = 0; i < MAXACKPACKETS; i++)
{
const INT32 nodei = ackpak[i].destinationnode;
node_t *node = &nodes[nodei];
@ -504,7 +500,7 @@ void Net_AckTicker(void)
}
}
for (i = 1; i < MAXNETNODES; i++)
for (INT32 i = 1; i < MAXNETNODES; i++)
{
// This is something like node open flag
if (nodes[i].firstacktosend)
@ -567,9 +563,7 @@ void Net_UnAcknowledgePacket(INT32 node)
*/
static boolean Net_AllAcksReceived(void)
{
INT32 i;
for (i = 0; i < MAXACKPACKETS; i++)
for (INT32 i = 0; i < MAXACKPACKETS; i++)
if (ackpak[i].acknum)
return false;
@ -611,12 +605,10 @@ static void InitNode(node_t *node)
static void InitAck(void)
{
INT32 i;
for (i = 0; i < MAXACKPACKETS; i++)
for (INT32 i = 0; i < MAXACKPACKETS; i++)
ackpak[i].acknum = 0;
for (i = 0; i < MAXNETNODES; i++)
for (INT32 i = 0; i < MAXNETNODES; i++)
InitNode(&nodes[i]);
}
@ -627,8 +619,7 @@ static void InitAck(void)
*/
void Net_AbortPacketType(UINT8 packettype)
{
INT32 i;
for (i = 0; i < MAXACKPACKETS; i++)
for (INT32 i = 0; i < MAXACKPACKETS; i++)
if (ackpak[i].acknum && (ackpak[i].pak.data.packettype == packettype
|| packettype == UINT8_MAX))
{
@ -643,7 +634,6 @@ void Net_AbortPacketType(UINT8 packettype)
// remove a node, clear all ack from this node and reset askret
void Net_CloseConnection(INT32 node)
{
INT32 i;
boolean forceclose = (node & FORCECLOSE) != 0;
if (node == -1)
@ -673,7 +663,7 @@ void Net_CloseConnection(INT32 node)
}
// check if we are waiting for an ack from this node
for (i = 0; i < MAXACKPACKETS; i++)
for (INT32 i = 0; i < MAXACKPACKETS; i++)
if (ackpak[i].acknum && ackpak[i].destinationnode == node)
{
if (!forceclose)
@ -697,9 +687,8 @@ static UINT32 NetbufferChecksum(void)
UINT32 c = 0x1234567;
const INT32 l = doomcom->datalength - 4;
const UINT8 *buf = (UINT8 *)netbuffer + 4;
INT32 i;
for (i = 0; i < l; i++, buf++)
for (INT32 i = 0; i < l; i++, buf++)
c += (*buf) * (i+1);
return LONG(c);
@ -710,9 +699,8 @@ static UINT32 NetbufferChecksum(void)
static void fprintfstring(char *s, size_t len)
{
INT32 mode = 0;
size_t i;
for (i = 0; i < len; i++)
for (size_t i = 0; i < len; i++)
if (s[i] < 32)
{
if (!mode)
@ -879,7 +867,6 @@ void Command_Drop(void)
{
INT32 packetquantity;
const char *packetname;
size_t i;
if (COM_Argc() < 2)
{
@ -909,11 +896,11 @@ void Command_Drop(void)
packetname = COM_Argv(1);
if (!(stricmp(packetname, "all") && stricmp(packetname, "any")))
for (i = 0; i < NUMPACKETTYPE; i++)
for (size_t i = 0; i < NUMPACKETTYPE; i++)
packetdropquantity[i] = packetquantity;
else
{
for (i = 0; i < NUMPACKETTYPE; i++)
for (size_t i = 0; i < NUMPACKETTYPE; i++)
if (!stricmp(packetname, packettypename[i]))
{
packetdropquantity[i] = packetquantity;
@ -1336,13 +1323,12 @@ void Command_Ping_f(void)
int name_width = 0;
int ms_width = 0;
int n;
INT32 i;
pingc = 0;
for (i = 1; i < MAXPLAYERS; ++i)
for (INT32 i = 1; i < MAXPLAYERS; ++i)
if (playeringame[i])
{
int n;
n = strlen(player_names[i]);
if (n > name_width)
name_width = n;
@ -1362,7 +1348,7 @@ void Command_Ping_f(void)
qsort(pingv, pingc, sizeof (struct pingcell), &pingcellcmp);
for (i = 0; i < pingc; ++i)
for (INT32 i = 0; i < pingc; ++i)
{
CONS_Printf("%02d : %-*s %*d ms\n",
pingv[i].num,
@ -1378,15 +1364,13 @@ void Command_Ping_f(void)
void D_CloseConnection(void)
{
INT32 i;
if (netgame)
{
// wait the ackreturn with timout of 5 Sec
Net_WaitAllAckReceived(5);
// close all connection
for (i = 0; i < MAXNETNODES; i++)
for (INT32 i = 0; i < MAXNETNODES; i++)
Net_CloseConnection(i|FORCECLOSE);
InitAck();

View file

@ -128,9 +128,7 @@ consvar_t cv_downloadspeed = CVAR_INIT ("downloadspeed", "16", CV_SAVE|CV_NETVAR
static UINT16 GetWadNumFromFileNeededId(UINT8 id)
{
UINT16 wadnum;
for (wadnum = mainwads; wadnum < numwadfiles; wadnum++)
for (UINT16 wadnum = mainwads; wadnum < numwadfiles; wadnum++)
{
if (!wadfiles[wadnum]->important)
continue;
@ -150,14 +148,13 @@ static UINT16 GetWadNumFromFileNeededId(UINT8 id)
*/
UINT8 *PutFileNeeded(UINT16 firstfile)
{
size_t i;
UINT8 count = 0;
UINT8 *p_start = netbuffer->packettype == PT_MOREFILESNEEDED ? netbuffer->u.filesneededcfg.files : netbuffer->u.serverinfo.fileneeded;
UINT8 *p = p_start;
char wadfilename[MAX_WADPATH] = "";
UINT8 filestatus, folder;
for (i = mainwads; i < numwadfiles; i++) //mainwads, otherwise we start on the first mainwad
for (size_t i = mainwads; i < numwadfiles; i++) //mainwads, otherwise we start on the first mainwad
{
// If it has only music/sound lumps, don't put it in the list
if (!wadfiles[i]->important)
@ -232,7 +229,6 @@ void FreeFileNeeded(void)
*/
void D_ParseFileneeded(INT32 fileneedednum_parm, UINT8 *fileneededstr, UINT16 firstfile)
{
INT32 i;
UINT8 *p;
UINT8 filestatus;
@ -241,7 +237,7 @@ void D_ParseFileneeded(INT32 fileneedednum_parm, UINT8 *fileneededstr, UINT16 fi
AllocFileNeeded(fileneedednum);
for (i = firstfile; i < fileneedednum; i++)
for (INT32 i = firstfile; i < fileneedednum; i++)
{
fileneeded[i].type = FILENEEDED_WAD;
fileneeded[i].status = FS_NOTCHECKED; // We haven't even started looking for the file yet
@ -281,9 +277,9 @@ void CL_PrepareDownloadSaveGame(const char *tmpsave)
*/
boolean CL_CheckDownloadable(void)
{
UINT8 i,dlstatus = 0;
UINT8 dlstatus = 0;
for (i = 0; i < fileneedednum; i++)
for (UINT8 i = 0; i < fileneedednum; i++)
if (fileneeded[i].status != FS_FOUND && fileneeded[i].status != FS_OPEN)
{
if (fileneeded[i].willsend == 1)
@ -304,7 +300,7 @@ boolean CL_CheckDownloadable(void)
// not downloadable, put reason in console
CONS_Alert(CONS_NOTICE, M_GetText("You need additional files to connect to this server:\n"));
for (i = 0; i < fileneedednum; i++)
for (UINT8 i = 0; i < fileneedednum; i++)
if (fileneeded[i].status != FS_FOUND && fileneeded[i].status != FS_OPEN)
{
CONS_Printf(" * \"%s\" (%dK)", fileneeded[i].filename, fileneeded[i].totalsize >> 10);
@ -374,14 +370,13 @@ void CL_AbortDownloadResume(void)
boolean CL_SendFileRequest(void)
{
char *p;
INT32 i;
INT64 totalfreespaceneeded = 0, availablefreespace;
#ifdef PARANOIA
if (M_CheckParm("-nodownload"))
I_Error("Attempted to download files in -nodownload mode");
for (i = 0; i < fileneedednum; i++)
for (INT32 i = 0; i < fileneedednum; i++)
if (fileneeded[i].status != FS_FOUND && fileneeded[i].status != FS_OPEN
&& (fileneeded[i].willsend == 0 || fileneeded[i].willsend == 2))
{
@ -391,7 +386,7 @@ boolean CL_SendFileRequest(void)
netbuffer->packettype = PT_REQUESTFILE;
p = (char *)netbuffer->u.textcmd;
for (i = 0; i < fileneedednum; i++)
for (INT32 i = 0; i < fileneedednum; i++)
if ((fileneeded[i].status == FS_NOTFOUND || fileneeded[i].status == FS_MD5SUMBAD))
{
totalfreespaceneeded += fileneeded[i].totalsize;
@ -422,7 +417,6 @@ boolean CL_SendFileRequest(void)
void PT_RequestFile(SINT8 node)
{
UINT8 *p = netbuffer->u.textcmd;
UINT8 id;
if (client || !cv_downloading.value)
{
@ -432,7 +426,7 @@ void PT_RequestFile(SINT8 node)
while (p < netbuffer->u.textcmd + MAXTEXTCMD-1) // Don't allow hacked client to overflow
{
id = READUINT8(p);
UINT8 id = READUINT8(p);
if (id == 0xFF)
break;
@ -543,9 +537,7 @@ INT32 CL_CheckFiles(void)
// Load it now
boolean CL_LoadServerFiles(void)
{
INT32 i;
for (i = 0; i < fileneedednum; i++)
for (INT32 i = 0; i < fileneedednum; i++)
{
if (fileneeded[i].status == FS_OPEN)
continue; // Already loaded
@ -641,11 +633,10 @@ void AddLuaFileTransfer(const char *filename, const char *mode)
static void SV_PrepareSendLuaFileToNextNode(void)
{
INT32 i;
UINT8 success = 1;
// Find a client to send the file to
for (i = 1; i < MAXNETNODES; i++)
for (INT32 i = 1; i < MAXNETNODES; i++)
if (luafiletransfers->nodestatus[i] == LFTNS_WAITING) // Node waiting
{
// Tell the client we're about to send them the file
@ -667,12 +658,11 @@ static void SV_PrepareSendLuaFileToNextNode(void)
void SV_PrepareSendLuaFile(void)
{
char *binfilename;
INT32 i;
luafiletransfers->ongoing = true;
// Set status to "waiting" for everyone
for (i = 0; i < MAXNETNODES; i++)
for (INT32 i = 0; i < MAXNETNODES; i++)
luafiletransfers->nodestatus[i] = (netnodes[i].ingame ? LFTNS_WAITING : LFTNS_NONE);
if (FIL_ReadFileOK(luafiletransfers->realfilename))
@ -1153,7 +1143,6 @@ void PT_FileAck(SINT8 node)
{
fileack_pak *packet = &netbuffer->u.fileack;
filetran_t *trans = &transfer[node];
INT32 i, j;
if (client)
return;
@ -1175,11 +1164,11 @@ void PT_FileAck(SINT8 node)
trans->dontsenduntil = 0;
}
for (i = 0; i < packet->numsegments; i++)
for (INT32 i = 0; i < packet->numsegments; i++)
{
fileacksegment_t *segment = &packet->segments[i];
for (j = 0; j < 32; j++)
for (INT32 j = 0; j < 32; j++)
if (LONG(segment->acks) & (1 << j))
{
if (LONG(segment->start) * FILEFRAGMENTSIZE >= trans->txlist->size)
@ -1215,13 +1204,12 @@ void PT_FileReceived(SINT8 node)
static void SendAckPacket(fileack_pak *packet, UINT8 fileid)
{
size_t packetsize;
INT32 i;
packetsize = sizeof(*packet) + packet->numsegments * sizeof(*packet->segments);
// Finalise the packet
packet->fileid = fileid;
for (i = 0; i < packet->numsegments; i++)
for (INT32 i = 0; i < packet->numsegments; i++)
{
packet->segments[i].start = LONG(packet->segments[i].start);
packet->segments[i].acks = LONG(packet->segments[i].acks);
@ -1261,9 +1249,7 @@ static void AddFragmentToAckPacket(fileack_pak *packet, UINT8 iteration, UINT32
void FileReceiveTicker(void)
{
INT32 i;
for (i = 0; i < fileneedednum; i++)
for (INT32 i = 0; i < fileneedednum; i++)
{
fileneeded_t *file = &fileneeded[i];
@ -1277,8 +1263,7 @@ void FileReceiveTicker(void)
if (file->ackresendposition != UINT32_MAX && file->status == FS_DOWNLOADING)
{
// Acknowledge ~70 MB/s, whichs means the client sends ~18 KB/s
INT32 j;
for (j = 0; j < 2048; j++)
for (INT32 j = 0; j < 2048; j++)
{
if (file->receivedfragments[file->ackresendposition])
AddFragmentToAckPacket(file->ackpacket, file->iteration, file->ackresendposition, i);
@ -1500,15 +1485,14 @@ void SV_AbortSendFiles(INT32 node)
void CloseNetFile(void)
{
INT32 i;
// Is sending?
for (i = 0; i < MAXNETNODES; i++)
for (INT32 i = 0; i < MAXNETNODES; i++)
SV_AbortSendFiles(i);
// Receiving a file?
if (fileneeded)
{
for (i = 0; i < fileneedednum; i++)
for (INT32 i = 0; i < fileneedednum; i++)
if (fileneeded[i].status == FS_DOWNLOADING && fileneeded[i].file)
{
fclose(fileneeded[i].file);
@ -1541,9 +1525,7 @@ void CloseNetFile(void)
void Command_Downloads_f(void)
{
INT32 node;
for (node = 0; node < MAXNETNODES; node++)
for (INT32 node = 0; node < MAXNETNODES; node++)
if (transfer[node].txlist
&& transfer[node].txlist->ram == SF_FILE) // Node is downloading a file?
{
@ -1577,14 +1559,11 @@ void Command_Downloads_f(void)
void nameonly(char *s)
{
size_t j, len;
void *ns;
for (j = strlen(s); j != (size_t)-1; j--)
for (size_t j = strlen(s); j != (size_t)-1; j--)
if ((s[j] == '\\') || (s[j] == ':') || (s[j] == '/'))
{
ns = &(s[j+1]);
len = strlen(ns);
void *ns = &(s[j+1]);
size_t len = strlen(ns);
#if 0
M_Memcpy(s, ns, len+1);
#else
@ -1597,9 +1576,9 @@ void nameonly(char *s)
// Returns the length in characters of the last element of a path.
size_t nameonlylength(const char *s)
{
size_t j, len = strlen(s);
size_t len = strlen(s);
for (j = len; j != (size_t)-1; j--)
for (size_t j = len; j != (size_t)-1; j--)
if ((s[j] == '\\') || (s[j] == ':') || (s[j] == '/'))
return len - j - 1;

View file

@ -43,9 +43,7 @@ boolean cl_redownloadinggamestate = false;
boolean SV_ResendingSavegameToAnyone(void)
{
INT32 i;
for (i = 0; i < MAXNETNODES; i++)
for (INT32 i = 0; i < MAXNETNODES; i++)
if (netnodes[i].resendingsavegame)
return true;
return false;
@ -236,9 +234,7 @@ void CL_LoadReceivedSavegame(boolean reloading)
void CL_ReloadReceivedSavegame(void)
{
INT32 i;
for (i = 0; i < MAXPLAYERS; i++)
for (INT32 i = 0; i < MAXPLAYERS; i++)
{
LUA_InvalidatePlayer(&players[i]);
sprintf(player_names[i], "Player %d", i + 1);

View file

@ -416,24 +416,20 @@ static boolean SOCK_cmpaddr(mysockaddr_t *a, mysockaddr_t *b, UINT8 mask)
*/
static void cleanupnodes(void)
{
SINT8 j;
if (!Playing())
return;
// Why can't I start at zero?
for (j = 1; j < MAXNETNODES; j++)
for (SINT8 j = 1; j < MAXNETNODES; j++)
if (!(netnodes[j].ingame || SendingFile(j)))
nodeconnected[j] = false;
}
static SINT8 getfreenode(void)
{
SINT8 j;
cleanupnodes();
for (j = 0; j < MAXNETNODES; j++)
for (SINT8 j = 0; j < MAXNETNODES; j++)
if (!nodeconnected[j])
{
nodeconnected[j] = true;
@ -446,7 +442,7 @@ static SINT8 getfreenode(void)
* downloading a needed wad, but it's better than not letting anyone join...
*/
/*I_Error("No more free nodes!!1!11!11!!1111\n");
for (j = 1; j < MAXNETNODES; j++)
for (SINT8 j = 1; j < MAXNETNODES; j++)
if (!netnodes[j].ingame)
return j;*/
@ -458,9 +454,8 @@ void Command_Numnodes(void)
{
INT32 connected = 0;
INT32 ingame = 0;
INT32 i;
for (i = 1; i < MAXNETNODES; i++)
for (INT32 i = 1; i < MAXNETNODES; i++)
{
if (!(nodeconnected[i] || netnodes[i].ingame))
continue;
@ -496,13 +491,13 @@ void Command_Numnodes(void)
// Returns true if a packet was received from a new node, false in all other cases
static boolean SOCK_Get(void)
{
size_t i, n;
size_t i;
int j;
ssize_t c;
mysockaddr_t fromaddress;
socklen_t fromlen;
for (n = 0; n < mysocketses; n++)
for (size_t n = 0; n < mysocketses; n++)
{
fromlen = (socklen_t)sizeof(fromaddress);
c = recvfrom(mysockets[n], (char *)&doomcom->data, MAXPACKETLENGTH, 0,
@ -563,10 +558,9 @@ static fd_set masterset;
#ifdef SELECTTEST
static boolean FD_CPY(fd_set *src, fd_set *dst, SOCKET_TYPE *fd, size_t len)
{
size_t i;
boolean testset = false;
FD_ZERO(dst);
for (i = 0; i < len;i++)
for (size_t i = 0; i < len;i++)
{
if(fd[i] != (SOCKET_TYPE)ERRSOCKET &&
FD_ISSET(fd[i], src) && !FD_ISSET(fd[i], dst)) // no checking for dups
@ -630,16 +624,15 @@ static inline ssize_t SOCK_SendToAddr(SOCKET_TYPE socket, mysockaddr_t *sockaddr
static void SOCK_Send(void)
{
ssize_t c = ERRSOCKET;
size_t i, j;
if (!nodeconnected[doomcom->remotenode])
return;
if (doomcom->remotenode == BROADCASTADDR)
{
for (i = 0; i < mysocketses; i++)
for (size_t i = 0; i < mysocketses; i++)
{
for (j = 0; j < broadcastaddresses; j++)
for (size_t j = 0; j < broadcastaddresses; j++)
{
if (myfamily[i] == broadcastaddress[j].any.sa_family)
SOCK_SendToAddr(mysockets[i], &broadcastaddress[j]);
@ -649,7 +642,7 @@ static void SOCK_Send(void)
}
else if (nodesocket[doomcom->remotenode] == (SOCKET_TYPE)ERRSOCKET)
{
for (i = 0; i < mysocketses; i++)
for (size_t i = 0; i < mysocketses; i++)
{
if (myfamily[i] == clientaddress[doomcom->remotenode].any.sa_family)
SOCK_SendToAddr(mysockets[i], &clientaddress[doomcom->remotenode]);
@ -1082,8 +1075,7 @@ boolean I_InitTcpDriver(void)
static void SOCK_CloseSocket(void)
{
size_t i;
for (i=0; i < MAXNETNODES+1; i++)
for (size_t i=0; i < MAXNETNODES+1; i++)
{
if (mysockets[i] != (SOCKET_TYPE)ERRSOCKET
&& FD_ISSET(mysockets[i], &masterset))
@ -1154,12 +1146,10 @@ static SINT8 SOCK_NetMakeNodewPort(const char *address, const char *port)
static boolean SOCK_OpenSocket(void)
{
size_t i;
memset(clientaddress, 0, sizeof (clientaddress));
nodeconnected[0] = true; // always connected to self
for (i = 1; i < MAXNETNODES; i++)
for (size_t i = 1; i < MAXNETNODES; i++)
nodeconnected[i] = false;
nodeconnected[BROADCASTADDR] = true;
I_NetSend = SOCK_Send;

View file

@ -90,13 +90,11 @@ void D_FreeTextcmd(tic_t tic)
if (textcmdtic)
{
INT32 i;
// Remove this tic from the list.
*tctprev = textcmdtic->next;
// Free all players.
for (i = 0; i < TEXTCMD_HASH_SIZE; i++)
for (INT32 i = 0; i < TEXTCMD_HASH_SIZE; i++)
{
textcmdplayer_t *textcmdplayer = textcmdtic->playercmds[i];
@ -174,9 +172,7 @@ UINT8* D_GetTextcmd(tic_t tic, INT32 playernum)
void ExtraDataTicker(void)
{
INT32 i;
for (i = 0; i < MAXPLAYERS; i++)
for (INT32 i = 0; i < MAXPLAYERS; i++)
if (playeringame[i] || i == 0)
{
UINT8 *bufferstart = D_GetExistingTextcmd(gametic, i);
@ -221,10 +217,9 @@ void ExtraDataTicker(void)
// used at txtcmds received to check packetsize bound
size_t TotalTextCmdPerTic(tic_t tic)
{
INT32 i;
size_t total = 1; // num of textcmds in the tic (ntextcmd byte)
for (i = 0; i < MAXPLAYERS; i++)
for (INT32 i = 0; i < MAXPLAYERS; i++)
{
UINT8 *textcmd = D_GetExistingTextcmd(tic, i);
if ((!i || playeringame[i]) && textcmd)

View file

@ -55,7 +55,6 @@ static INT32 FindRejoinerNum(SINT8 node)
char strippednodeaddress[64];
const char *nodeaddress;
char *port;
INT32 i;
// Make sure there is no dead dress before proceeding to the stripping
if (!I_GetNodeAddress)
@ -71,7 +70,7 @@ static INT32 FindRejoinerNum(SINT8 node)
*port = '\0';
// Check if any player matches the stripped address
for (i = 0; i < MAXPLAYERS; i++)
for (INT32 i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i] && playeraddress[i][0] && playernode[i] == UINT8_MAX
&& !strcmp(playeraddress[i], strippednodeaddress))
@ -162,10 +161,9 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime)
static void SV_SendPlayerInfo(INT32 node)
{
UINT8 i;
netbuffer->packettype = PT_PLAYERINFO;
for (i = 0; i < MAXPLAYERS; i++)
for (UINT8 i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i])
{
@ -425,7 +423,6 @@ void PT_ClientJoin(SINT8 node)
char names[MAXSPLITSCREENPLAYERS][MAXPLAYERNAME + 1];
INT32 numplayers = netbuffer->u.clientcfg.localplayers;
INT32 rejoinernum;
INT32 i;
// Ignore duplicate packets
if (client || netnodes[node].ingame)
@ -440,7 +437,7 @@ void PT_ClientJoin(SINT8 node)
return;
}
for (i = 0; i < numplayers; i++)
for (INT32 i = 0; i < numplayers; i++)
{
strlcpy(names[i], netbuffer->u.clientcfg.names[i], MAXPLAYERNAME + 1);
if (!EnsurePlayerNameIsGood(names[i], rejoinernum))
@ -469,7 +466,7 @@ void PT_ClientJoin(SINT8 node)
}
// Splitscreen can allow 2 players in one node
for (i = 0; i < numplayers; i++)
for (INT32 i = 0; i < numplayers; i++)
SV_AddPlayer(node, names[i]);
joindelay += cv_joindelay.value * TICRATE;

View file

@ -80,11 +80,9 @@ tic_t ExpandTics(INT32 low, INT32 node)
void D_Clearticcmd(tic_t tic)
{
INT32 i;
D_FreeTextcmd(tic);
for (i = 0; i < MAXPLAYERS; i++)
for (INT32 i = 0; i < MAXPLAYERS; i++)
netcmds[tic%BACKUPTICS][i].angleturn = 0;
DEBFILE(va("clear tic %5u (%2u)\n", tic, tic%BACKUPTICS));
@ -92,13 +90,11 @@ void D_Clearticcmd(tic_t tic)
void D_ResetTiccmds(void)
{
INT32 i;
memset(&localcmds, 0, sizeof(ticcmd_t));
memset(&localcmds2, 0, sizeof(ticcmd_t));
// Reset the net command list
for (i = 0; i < TEXTCMD_HASH_SIZE; i++)
for (INT32 i = 0; i < TEXTCMD_HASH_SIZE; i++)
while (textcmds[i])
D_Clearticcmd(textcmds[i]->tic);
}
@ -229,8 +225,7 @@ void PT_ServerTics(SINT8 node, INT32 netconsole)
realstart = netbuffer->u.serverpak.starttic;
realend = realstart + netbuffer->u.serverpak.numtics;
if (realend > gametic + CLIENTBACKUPTICS)
realend = gametic + CLIENTBACKUPTICS;
realend = min(realend, gametic + CLIENTBACKUPTICS);
cl_packetmissed = realstart > neededtic;
if (realstart <= neededtic && realend > neededtic)
@ -304,9 +299,8 @@ void CL_SendClientCmd(void)
static tic_t SV_CalculateNumTicsForPacket(SINT8 nodenum, tic_t firsttic, tic_t lasttic)
{
size_t size = BASESERVERTICSSIZE;
tic_t tic;
for (tic = firsttic; tic < lasttic; tic++)
for (tic_t tic = firsttic; tic < lasttic; tic++)
{
size += sizeof (ticcmd_t) * doomcom->numslots;
size += TotalTextCmdPerTic(tic);
@ -344,15 +338,12 @@ static tic_t SV_CalculateNumTicsForPacket(SINT8 nodenum, tic_t firsttic, tic_t l
// send tic from firstticstosend to maketic-1
void SV_SendTics(void)
{
tic_t realfirsttic, lasttictosend, i;
UINT32 n;
size_t packsize;
UINT8 *bufpos;
tic_t realfirsttic, lasttictosend;
// send to all client but not to me
// for each node create a packet with x tics and send it
// x is computed using netnodes[n].supposedtic, max packet size and maketic
for (n = 1; n < MAXNETNODES; n++)
for (INT32 n = 1; n < MAXNETNODES; n++)
if (netnodes[n].ingame)
{
// assert netnodes[n].supposedtic>=netnodes[n].tic
@ -367,42 +358,42 @@ void SV_SendTics(void)
// (getpacket servertics case)
DEBFILE(va("Nothing to send node %u mak=%u sup=%u net=%u \n",
n, maketic, netnodes[n].supposedtic, netnodes[n].tic));
realfirsttic = netnodes[n].tic;
if (realfirsttic >= lasttictosend || (I_GetTime() + n)&3)
// all tic are ok
continue;
DEBFILE(va("Sent %d anyway\n", realfirsttic));
}
if (realfirsttic < firstticstosend)
realfirsttic = firstticstosend;
realfirsttic = max(realfirsttic, firstticstosend);
lasttictosend = realfirsttic + SV_CalculateNumTicsForPacket(n, realfirsttic, lasttictosend);
// Send the tics
// Prepare the packet header
netbuffer->packettype = PT_SERVERTICS;
netbuffer->u.serverpak.starttic = realfirsttic;
netbuffer->u.serverpak.numtics = (UINT8)(lasttictosend - realfirsttic);
netbuffer->u.serverpak.numslots = (UINT8)SHORT(doomcom->numslots);
bufpos = (UINT8 *)&netbuffer->u.serverpak.cmds;
for (i = realfirsttic; i < lasttictosend; i++)
{
// Fill and send the packet
UINT8 *bufpos = (UINT8 *)&netbuffer->u.serverpak.cmds;
for (tic_t i = realfirsttic; i < lasttictosend; i++)
bufpos = G_DcpyTiccmd(bufpos, netcmds[i%BACKUPTICS], doomcom->numslots * sizeof (ticcmd_t));
}
// add textcmds
for (i = realfirsttic; i < lasttictosend; i++)
SV_WriteNetCommandsForTic();
packsize = bufpos - (UINT8 *)&(netbuffer->u);
for (tic_t i = realfirsttic; i < lasttictosend; i++)
SV_WriteNetCommandsForTic(i, &bufpos);
size_t packsize = bufpos - (UINT8 *)&(netbuffer->u);
HSendPacket(n, false, 0, packsize);
// when tic are too large, only one tic is sent so don't go backward!
if (lasttictosend-doomcom->extratics > realfirsttic)
netnodes[n].supposedtic = lasttictosend-doomcom->extratics;
else
netnodes[n].supposedtic = lasttictosend;
if (netnodes[n].supposedtic < netnodes[n].tic) netnodes[n].supposedtic = netnodes[n].tic;
netnodes[n].supposedtic = max(netnodes[n].supposedtic, netnodes[n].tic);
}
// node 0 is me!
netnodes[0].supposedtic = maketic;
}
@ -413,7 +404,8 @@ void Local_Maketic(INT32 realtics)
D_ProcessEvents(); // menu responder, cons responder,
// game responder calls HU_Responder, AM_Responder,
// and G_MapEventsToControls
if (!dedicated) rendergametic = gametic;
if (!dedicated)
rendergametic = gametic;
// translate inputs (keyboard/mouse/gamepad) into game controls
G_BuildTiccmd(&localcmds, realtics, 1);
if (splitscreen || botingame)
@ -426,9 +418,7 @@ void Local_Maketic(INT32 realtics)
// create missed tic
void SV_Maketic(void)
{
INT32 i;
for (i = 0; i < MAXPLAYERS; i++)
for (INT32 i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i])
continue;