2008-11-17 00:38:26 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 1997, 2005 - 3D Realms Entertainment
|
|
|
|
|
|
|
|
This file is part of Shadow Warrior version 1.2
|
|
|
|
|
|
|
|
Shadow Warrior is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
Original Source: 1997 - Frank Maddin and Jim Norwood
|
|
|
|
Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
int g_numSyncBytes = 1;
|
|
|
|
char g_szfirstSyncMsg[MAXSYNCBYTES][60];
|
|
|
|
int g_foundSyncError = 0;
|
2008-11-17 00:38:26 +00:00
|
|
|
|
|
|
|
static int crctable[256];
|
|
|
|
#define updatecrc(dcrc,xz) (dcrc = (crctable[((dcrc)>>8)^((xz)&255)]^((dcrc)<<8)))
|
|
|
|
|
|
|
|
void initsynccrc(void)
|
|
|
|
{
|
|
|
|
int i, j, k, a;
|
|
|
|
|
|
|
|
for (j=0;j<256;j++) //Calculate CRC table
|
|
|
|
{
|
|
|
|
k = (j<<8); a = 0;
|
|
|
|
for (i=7;i>=0;i--)
|
|
|
|
{
|
|
|
|
if (((k^a)&0x8000) > 0)
|
|
|
|
a = ((a<<1)&65535) ^ 0x1021; //0x1021 = genpoly
|
|
|
|
else
|
|
|
|
a = ((a<<1)&65535);
|
|
|
|
k = ((k<<1)&65535);
|
|
|
|
}
|
|
|
|
crctable[j] = (a&65535);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
char Net_PlayerSync(void)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
short i;
|
|
|
|
unsigned short crc = 0;
|
2008-11-20 14:06:36 +00:00
|
|
|
DukePlayer_t *pp;
|
2008-11-17 00:38:26 +00:00
|
|
|
|
2008-11-20 14:06:36 +00:00
|
|
|
TRAVERSE_CONNECT(i)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
pp = g_player[i].ps;
|
|
|
|
updatecrc(crc, pp->posx & 255);
|
|
|
|
updatecrc(crc, pp->posy & 255);
|
|
|
|
updatecrc(crc, pp->posz & 255);
|
|
|
|
updatecrc(crc, pp->ang & 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((char) crc & 255);
|
|
|
|
}
|
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
char Net_PlayerSync2(void)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
2008-11-20 14:06:36 +00:00
|
|
|
int i;
|
|
|
|
int j, nextj;
|
2008-11-17 00:38:26 +00:00
|
|
|
unsigned short crc = 0;
|
2008-11-20 14:06:36 +00:00
|
|
|
DukePlayer_t *pp;
|
|
|
|
spritetype *spr;
|
2008-11-17 00:38:26 +00:00
|
|
|
|
2008-11-20 14:06:36 +00:00
|
|
|
TRAVERSE_CONNECT(i)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
pp = g_player[i].ps;
|
|
|
|
|
|
|
|
updatecrc(crc, pp->horiz & 255);
|
|
|
|
updatecrc(crc, sprite[pp->i].extra & 255);
|
|
|
|
updatecrc(crc, pp->bobcounter & 255);
|
|
|
|
}
|
|
|
|
|
2008-11-20 14:06:36 +00:00
|
|
|
TRAVERSE_SPRITE_STAT(headspritestat[STAT_PLAYER], j, nextj)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
spr = &sprite[j];
|
|
|
|
updatecrc(crc, (spr->x) & 255);
|
|
|
|
updatecrc(crc, (spr->y) & 255);
|
|
|
|
updatecrc(crc, (spr->z) & 255);
|
|
|
|
updatecrc(crc, (spr->ang) & 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((char) crc & 255);
|
|
|
|
}
|
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
char Net_ActorSync(void)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
unsigned short crc = 0;
|
2008-11-20 14:06:36 +00:00
|
|
|
int j, nextj;
|
2008-11-17 00:38:26 +00:00
|
|
|
spritetype *spr;
|
|
|
|
|
2008-11-20 14:06:36 +00:00
|
|
|
TRAVERSE_SPRITE_STAT(headspritestat[STAT_ACTOR], j, nextj)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
spr = &sprite[j];
|
|
|
|
updatecrc(crc, (spr->x) & 255);
|
|
|
|
updatecrc(crc, (spr->y) & 255);
|
|
|
|
updatecrc(crc, (spr->z) & 255);
|
2008-11-20 14:06:36 +00:00
|
|
|
updatecrc(crc, (spr->lotag) & 255);
|
|
|
|
updatecrc(crc, (spr->hitag) & 255);
|
2008-11-17 00:38:26 +00:00
|
|
|
updatecrc(crc, (spr->ang) & 255);
|
|
|
|
}
|
|
|
|
|
2008-11-20 14:06:36 +00:00
|
|
|
TRAVERSE_SPRITE_STAT(headspritestat[STAT_ZOMBIEACTOR], j, nextj)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
spr = &sprite[j];
|
|
|
|
updatecrc(crc, (spr->x) & 255);
|
|
|
|
updatecrc(crc, (spr->y) & 255);
|
|
|
|
updatecrc(crc, (spr->z) & 255);
|
2008-11-20 14:06:36 +00:00
|
|
|
updatecrc(crc, (spr->lotag) & 255);
|
|
|
|
updatecrc(crc, (spr->hitag) & 255);
|
2008-11-17 00:38:26 +00:00
|
|
|
updatecrc(crc, (spr->ang) & 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((char) crc & 255);
|
|
|
|
}
|
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
char Net_WeaponSync(void)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
unsigned short crc = 0;
|
2008-11-20 14:06:36 +00:00
|
|
|
int j, nextj;
|
2008-11-17 00:38:26 +00:00
|
|
|
spritetype *spr;
|
|
|
|
|
2008-11-20 14:06:36 +00:00
|
|
|
TRAVERSE_SPRITE_STAT(headspritestat[STAT_PROJECTILE], j, nextj)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
spr = &sprite[j];
|
|
|
|
updatecrc(crc, (spr->x) & 255);
|
|
|
|
updatecrc(crc, (spr->y) & 255);
|
|
|
|
updatecrc(crc, (spr->z) & 255);
|
|
|
|
updatecrc(crc, (spr->ang) & 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((char) crc & 255);
|
|
|
|
}
|
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
char Net_MapSync(void)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
unsigned short crc = 0;
|
2008-11-20 14:06:36 +00:00
|
|
|
int j, nextj;
|
2008-11-17 00:38:26 +00:00
|
|
|
spritetype *spr;
|
2008-11-20 14:06:36 +00:00
|
|
|
walltype *wal;
|
|
|
|
sectortype *sect;
|
2008-11-17 00:38:26 +00:00
|
|
|
|
2008-11-20 14:06:36 +00:00
|
|
|
TRAVERSE_SPRITE_STAT(headspritestat[STAT_EFFECTOR], j, nextj)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
spr = &sprite[j];
|
|
|
|
updatecrc(crc, (spr->x) & 255);
|
|
|
|
updatecrc(crc, (spr->y) & 255);
|
|
|
|
updatecrc(crc, (spr->z) & 255);
|
|
|
|
updatecrc(crc, (spr->ang) & 255);
|
2008-11-20 14:06:36 +00:00
|
|
|
updatecrc(crc, (spr->lotag) & 255);
|
|
|
|
updatecrc(crc, (spr->hitag) & 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j=numwalls;j>=0;j--)
|
|
|
|
{
|
|
|
|
wal = &wall[j];
|
|
|
|
updatecrc(crc, (wal->x) & 255);
|
|
|
|
updatecrc(crc, (wal->y) & 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j=numsectors;j>=0;j--)
|
|
|
|
{
|
|
|
|
sect = §or[j];
|
|
|
|
updatecrc(crc, (sect->floorz) & 255);
|
|
|
|
updatecrc(crc, (sect->ceilingz) & 255);
|
2008-11-17 00:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ((char) crc & 255);
|
|
|
|
}
|
2008-11-20 14:06:36 +00:00
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
char Net_RandomSync(void)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
unsigned short crc = 0;
|
|
|
|
|
|
|
|
updatecrc(crc, randomseed & 255);
|
|
|
|
updatecrc(crc, (randomseed >> 8) & 255);
|
2008-11-20 14:06:36 +00:00
|
|
|
updatecrc(crc, g_globalRandom & 255);
|
|
|
|
updatecrc(crc, (g_globalRandom >> 8) & 255);
|
2008-11-17 00:38:26 +00:00
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
if (g_numSyncBytes == 1)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
2008-11-21 12:14:05 +00:00
|
|
|
updatecrc(crc,Net_PlayerSync() & 255);
|
|
|
|
updatecrc(crc,Net_PlayerSync2() & 255);
|
|
|
|
updatecrc(crc,Net_WeaponSync() & 255);
|
|
|
|
updatecrc(crc,Net_ActorSync() & 255);
|
2008-11-17 00:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ((char) crc & 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *SyncNames[] =
|
|
|
|
{
|
2008-11-20 14:06:36 +00:00
|
|
|
"Net_CheckRandomSync",
|
|
|
|
"Net_CheckPlayerSync",
|
|
|
|
"Net_CheckPlayerSync2",
|
|
|
|
"Net_CheckWeaponSync",
|
|
|
|
"Net_CheckActorSync",
|
|
|
|
"Net_CheckMapSync",
|
2008-11-17 00:38:26 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static char(*SyncFunc[MAXSYNCBYTES + 1])(void) =
|
|
|
|
{
|
2008-11-21 12:14:05 +00:00
|
|
|
Net_RandomSync,
|
|
|
|
Net_PlayerSync,
|
|
|
|
Net_PlayerSync2,
|
|
|
|
Net_WeaponSync,
|
|
|
|
Net_ActorSync,
|
|
|
|
Net_MapSync,
|
2008-11-17 00:38:26 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
void Net_GetSyncStat(void)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
playerdata_t *pp = &g_player[myconnectindex];
|
|
|
|
unsigned int val;
|
|
|
|
static unsigned int count;
|
|
|
|
|
|
|
|
if (numplayers < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; SyncFunc[i]; i++)
|
|
|
|
{
|
|
|
|
pp->syncval[pp->syncvalhead & (SYNCFIFOSIZ - 1)][i] = (*SyncFunc[i])();
|
|
|
|
}
|
|
|
|
|
|
|
|
val = pp->syncval[pp->syncvalhead & (SYNCFIFOSIZ - 1)][0];
|
|
|
|
count += val;
|
|
|
|
|
|
|
|
pp->syncvalhead++;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Sync Message print
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
void Net_DisplaySyncMsg(void)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
2008-11-21 12:14:05 +00:00
|
|
|
static unsigned int moveCount = 0;
|
2008-11-20 14:06:36 +00:00
|
|
|
extern unsigned int g_moveThingsCount;
|
2008-11-17 00:38:26 +00:00
|
|
|
|
|
|
|
// if (!SyncPrintMode)
|
|
|
|
// return;
|
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
if (numplayers < 2)
|
2008-11-17 00:38:26 +00:00
|
|
|
return;
|
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
for (i = 0; i < g_numSyncBytes; i++)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
// syncstat is NON 0 - out of sync
|
|
|
|
if (syncstat[i] != 0)
|
|
|
|
{
|
2008-11-21 12:14:05 +00:00
|
|
|
if (g_numSyncBytes > 1)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
2008-11-20 14:06:36 +00:00
|
|
|
sprintf(tempbuf, "Out Of Sync - %s", SyncNames[i]);
|
|
|
|
printext256(4L, 100L + (i * 8), 31, 1, tempbuf, 0);
|
2008-11-17 00:38:26 +00:00
|
|
|
}
|
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
if (!g_foundSyncError && g_szfirstSyncMsg[i][0] == '\0')
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
2008-11-21 12:14:05 +00:00
|
|
|
// g_foundSyncError one so test all of them and then never test again
|
|
|
|
g_foundSyncError = TRUE;
|
2008-11-17 00:38:26 +00:00
|
|
|
|
|
|
|
// save off loop count
|
2008-11-21 12:14:05 +00:00
|
|
|
moveCount = g_moveThingsCount;
|
2008-11-17 00:38:26 +00:00
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
for (j = 0; j < g_numSyncBytes; j++)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
2008-11-21 12:14:05 +00:00
|
|
|
if (syncstat[j] != 0 && g_szfirstSyncMsg[j][0] == '\0')
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
2008-11-20 14:06:36 +00:00
|
|
|
sprintf(tempbuf, "Out Of Sync - %s", SyncNames[j]);
|
2008-11-21 12:14:05 +00:00
|
|
|
strcpy(g_szfirstSyncMsg[j], tempbuf);
|
2008-11-17 00:38:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
// print out the g_szfirstSyncMsg message you got
|
|
|
|
for (i = 0; i < g_numSyncBytes; i++)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
2008-11-21 12:14:05 +00:00
|
|
|
if (g_szfirstSyncMsg[i][0] != '\0')
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
2008-11-21 12:14:05 +00:00
|
|
|
if (g_numSyncBytes > 1)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
2008-11-21 12:14:05 +00:00
|
|
|
sprintf(tempbuf, "FIRST %s", g_szfirstSyncMsg[i]);
|
2008-11-20 14:06:36 +00:00
|
|
|
printext256(4L, 44L + (i * 8), 31, 1, tempbuf, 0);
|
2008-11-21 12:14:05 +00:00
|
|
|
sprintf(tempbuf, "moveCount %d",moveCount);
|
2008-11-20 14:06:36 +00:00
|
|
|
printext256(4L, 52L + (i * 8), 31, 1, tempbuf, 0);
|
2008-11-17 00:38:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-20 14:06:36 +00:00
|
|
|
printext256(4L,100L,31,0,"Out Of Sync - Please restart game",0);
|
2008-11-17 00:38:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if (syncstate != 0)
|
|
|
|
// printext256(68L, 92L, 1, 31, "Missed Network packet!", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
void Net_AddSyncInfoToPacket(int *j)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
int sb;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
// sync testing
|
|
|
|
while (g_player[myconnectindex].syncvalhead != syncvaltail && count++ < 4)
|
|
|
|
{
|
2008-11-21 12:14:05 +00:00
|
|
|
for (sb = 0; sb < g_numSyncBytes; sb++)
|
2008-11-17 00:38:26 +00:00
|
|
|
packbuf[(*j)++] = g_player[myconnectindex].syncval[syncvaltail & (SYNCFIFOSIZ - 1)][sb];
|
|
|
|
|
|
|
|
syncvaltail++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
void Net_GetSyncInfoFromPacket(char *packbuf, int packbufleng, int *j, int otherconnectindex)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
int sb, i;
|
|
|
|
extern int syncvaltail, syncvaltottail;
|
|
|
|
playerdata_t *ppo = &g_player[otherconnectindex];
|
|
|
|
char found = 0;
|
|
|
|
|
|
|
|
// have had problems with this routine crashing when players quit
|
|
|
|
// games.
|
|
|
|
|
|
|
|
// if ready2send is not set then don't try to get sync info
|
|
|
|
|
|
|
|
if (!ready2send)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Suspect that its trying to traverse the connect list
|
|
|
|
// for a player that does not exist. This tries to take care of that
|
|
|
|
|
2008-11-20 14:06:36 +00:00
|
|
|
TRAVERSE_CONNECT(i)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
if (otherconnectindex == i)
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// sync testing
|
|
|
|
//while ((*j) != packbufleng) // changed this on Kens suggestion
|
|
|
|
while ((*j) < packbufleng)
|
|
|
|
{
|
2008-11-21 12:14:05 +00:00
|
|
|
for (sb = 0; sb < g_numSyncBytes; sb++)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
ppo->syncval[ppo->syncvalhead & (SYNCFIFOSIZ - 1)][sb] = packbuf[(*j)++];
|
|
|
|
}
|
|
|
|
ppo->syncvalhead++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update syncstat
|
|
|
|
// if any of the syncstat vars is non-0 then there is a problem
|
2008-11-20 14:06:36 +00:00
|
|
|
TRAVERSE_CONNECT(i)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
if (g_player[i].syncvalhead == syncvaltottail)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-21 12:14:05 +00:00
|
|
|
//for (sb = 0; sb < g_numSyncBytes; sb++)
|
2008-11-17 00:38:26 +00:00
|
|
|
// syncstat[sb] = 0;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
for (i = connectpoint2[connecthead]; i >= 0; i = connectpoint2[i])
|
|
|
|
{
|
2008-11-21 12:14:05 +00:00
|
|
|
for (sb = 0; sb < g_numSyncBytes; sb++)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
if (g_player[i].syncval[syncvaltottail & (SYNCFIFOSIZ - 1)][sb] != g_player[connecthead].syncval[syncvaltottail & (SYNCFIFOSIZ - 1)][sb])
|
|
|
|
{
|
|
|
|
syncstat[sb] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
syncvaltottail++;
|
|
|
|
|
2008-11-20 14:06:36 +00:00
|
|
|
TRAVERSE_CONNECT(i)
|
2008-11-17 00:38:26 +00:00
|
|
|
{
|
|
|
|
if (g_player[i].syncvalhead == syncvaltottail)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|