Name:
Allard Ankone
Date of birth:
01-08-1985
Nationality:
Dutch
Gender:
Male
Email:
allard@icebox.nl
Phone:
+31(0)6-40628406
Skype:
aankone
Linkedin:
linkedin.com/aankone
BitBucket:
bitbucket.org/aankone
#include "Precompiled.h" #include "../Main/Main.h" #include#include #include "tech5/engine/sys/sys_lobby.h" bool useTech5Packets = true; #if 1 struct networkitem { int source; int size; char buffer[256*64]; }; std::queue< networkitem > networkstacks[4]; //sockaddr_in sockaddrs[4]; int DoomLibRecv( char* buff, DWORD *numRecv ) { //int player = DoomInterface::CurrentPlayer(); int player = ::g->consoleplayer; if (networkstacks[player].empty()) return -1; networkitem item = networkstacks[player].front(); memcpy( buff, item.buffer, item.size ); *numRecv = item.size; //*source = sockaddrs[item.source]; networkstacks[player].pop(); return 1; } void I_Printf(char *error, ...); int DoomLibSend( const char* buff, DWORD size, sockaddr_in *target, int toNode ) { int i; i = DoomLib::RemoteNodeToPlayerIndex( toNode ); //I_Printf( "DoomLibSend %d --> %d: %d\n", ::g->consoleplayer, i, size ); networkitem item; item.source = DoomInterface::CurrentPlayer(); item.size = size; memcpy( item.buffer, buff, size ); networkstacks[i].push( item ); return 1; } int DoomLibSendRemote() { if ( gameLocal == NULL ) { return 0; } int curPlayer = DoomLib::GetPlayer(); for (int player = 0; player < gameLocal->Interface.GetNumPlayers(); ++player) { DoomLib::SetPlayer( player ); for( int i = 0; i < 4; i++ ) { //Check if it is remote int node = DoomLib::PlayerIndexToRemoteNode( i ); if ( ::g->sendaddress[node].sin_addr.s_addr == ::g->sendaddress[0].sin_addr.s_addr ) { continue; } while(!networkstacks[i].empty()) { networkitem item = networkstacks[i].front(); int c; //WSABUF buffer; //DWORD num_sent; //buffer.buf = (char*)&item.buffer; //buffer.len = item.size; if ( useTech5Packets ) { idLobby & lobby = static_cast< idLobby & >( session->GetGameLobbyBase() ); lobbyUser_t * user = lobby.GetLobbyUser( i ); if ( user != NULL ) { lobby.SendConnectionLess( user->address, idLobby::OOB_GENERIC_GAME_DATA, (const byte *)(&item.buffer[0] ), item.size ); } } else { c = sendto( ::g->sendsocket, &item.buffer, item.size, MSG_DONTWAIT, (sockaddr*)&::g->sendaddress[node], sizeof(::g->sendaddress[node]) ); //c = WSASendTo(::g->sendsocket, &buffer, 1, &num_sent, 0, (sockaddr*)&::g->sendaddress[node], sizeof(::g->sendaddress[node]), 0, 0); } networkstacks[i].pop(); } } } DoomLib::SetPlayer(curPlayer); return 1; } void DL_InitNetworking( DoomInterface *pdi ) { // DHM - Nerve :: Clear out any old splitscreen packets that may be lingering. for ( int i = 0; i<4; i++ ) { while ( !networkstacks[i].empty() ) { networkstacks[i].pop(); } } /*sockaddrs[0].sin_addr.s_addr = inet_addr("0.0.0.1" ); sockaddrs[1].sin_addr.s_addr = inet_addr("0.0.0.2" ); sockaddrs[2].sin_addr.s_addr = inet_addr("0.0.0.3" ); sockaddrs[3].sin_addr.s_addr = inet_addr("0.0.0.4" );*/ pdi->SetNetworking( DoomLibRecv, DoomLibSend, DoomLibSendRemote ); } #else void DL_InitNetworking( DoomInterface *pdi ) { } #endif
lumpinfo_t* lumpinfo = NULL;
int numlumps;
void** lumpcache;
int filelength (FILE* handle)
{
// DHM - not used :: development tool (loading single lump not in a WAD file)
return 0;
}
void
ExtractFileBase
( const char* path,
char* dest )
{
const char* src;
int length;
src = path + strlen(path) - 1;
// back up until a \ or the start
while (src != path
&& *(src-1) != '\\'
&& *(src-1) != '/')
{
src--;
}
// copy up to eight characters
memset (dest,0,8);
length = 0;
while (*src && *src != '.')
{
if (++length == 9)
I_Error ("Filename base of %s >8 chars",path);
*dest++ = toupper((int)*src++);
}
}
//
// LUMP BASED ROUTINES.
//
//
// W_AddFile
// All files are optional, but at least one file must be
// found (PWAD, if all required lumps are present).
// Files with a .wad extension are wadlink files
// with multiple lumps.
// Other files are single lumps with the base filename
// for the lump name.
//
// If filename starts with a tilde, the file is handled
// specially to allow map reloads.
// But: the reload feature is a fragile hack...
const char* reloadname;
void W_AddFile ( const char *filename)
{
wadinfo_t header;
lumpinfo_t* lump_p;
int i;
idFile * handle;
int length;
int startlump;
std::vector fileinfo( 1 );
// open the file and add to directory
if ( (handle = fileSystem->OpenFileRead(filename)) == 0)
{
I_Printf (" couldn't open %s\n",filename);
return;
}
I_Printf (" adding %s\n",filename);
startlump = numlumps;
if ( idStr::Icmp( filename+strlen(filename)-3 , "wad" ) )
{
// single lump file
fileinfo[0].filepos = 0;
fileinfo[0].size = 0;
ExtractFileBase (filename, fileinfo[0].name);
numlumps++;
}
else
{
// WAD file
handle->Read( &header, sizeof( header ) );
if ( idStr::Cmpn( header.identification,"IWAD",4 ) )
{
// Homebrew levels?
if ( idStr::Cmpn( header.identification, "PWAD", 4 ) )
{
I_Error ("Wad file %s doesn't have IWAD "
"or PWAD id\n", filename);
}
// ???modifiedgame = true;
}
header.numlumps = LONG(header.numlumps);
header.infotableofs = LONG(header.infotableofs);
length = header.numlumps*sizeof(filelump_t);
fileinfo.resize(header.numlumps);
handle->Seek( header.infotableofs, FS_SEEK_SET );
handle->Read( &fileinfo[0], length );
numlumps += header.numlumps;
}
// Fill in lumpinfo
if (lumpinfo == NULL) {
lumpinfo = (lumpinfo_t*)malloc( numlumps*sizeof(lumpinfo_t) );
} else {
lumpinfo = (lumpinfo_t*)realloc( lumpinfo, numlumps*sizeof(lumpinfo_t) );
}
if (!lumpinfo)
I_Error ("Couldn't realloc lumpinfo");
lump_p = &lumpinfo[startlump];
::g->wadFileHandles[ ::g->numWadFiles++ ] = handle;
filelump_t * filelumpPointer = &fileinfo[0];
for (i=startlump ; ihandle = handle;
lump_p->position = LONG(filelumpPointer->filepos);
lump_p->size = LONG(filelumpPointer->size);
strncpy (lump_p->name, filelumpPointer->name, 8);
}
}
//
// W_Reload
// Flushes any of the reloadable lumps in memory
// and reloads the directory.
//
void W_Reload (void)
{
// DHM - unused development tool
}
//
// W_FreeLumps
// Frees all lump data
//
void W_FreeLumps() {
if ( lumpcache != NULL ) {
for ( int i = 0; i < numlumps; i++ ) {
if ( lumpcache[i] ) {
Z_Free( lumpcache[i] );
}
}
Z_Free( lumpcache );
lumpcache = NULL;
}
if ( lumpinfo != NULL ) {
free( lumpinfo );
lumpinfo = NULL;
numlumps = 0;
}
}
//
// W_FreeWadFiles
// Free this list of wad files so that a new list can be created
//
void W_FreeWadFiles() {
for (int i = 0 ; i < MAXWADFILES ; i++) {
wadfiles[i] = NULL;
if ( ::g->wadFileHandles[i] ) {
delete ::g->wadFileHandles[i];
}
::g->wadFileHandles[i] = NULL;
}
::g->numWadFiles = 0;
extraWad = 0;
}
//
// W_InitMultipleFiles
// Pass a null terminated list of files to use.
// All files are optional, but at least one file
// must be found.
// Files with a .wad extension are idlink files
// with multiple lumps.
// Other files are single lumps with the base filename
// for the lump name.
// Lump names can appear multiple times.
// The name searcher looks backwards, so a later file
// does override all earlier ones.
//
void W_InitMultipleFiles (const char** filenames)
{
int size;
if (lumpinfo == NULL)
{
// open all the files, load headers, and count lumps
numlumps = 0;
// will be realloced as lumps are added
lumpinfo = NULL;
for ( ; *filenames ; filenames++)
{
W_AddFile (*filenames);
}
if (!numlumps)
I_Error ("W_InitMultipleFiles: no files found");
// set up caching
size = numlumps * sizeof(*lumpcache);
lumpcache = (void**)DoomLib::Z_Malloc(size, PU_STATIC_SHARED, 0 );
if (!lumpcache)
I_Error ("Couldn't allocate lumpcache");
memset (lumpcache,0, size);
} else {
// set up caching
size = numlumps * sizeof(*lumpcache);
lumpcache = (void**)DoomLib::Z_Malloc(size, PU_STATIC_SHARED, 0 );
if (!lumpcache)
I_Error ("Couldn't allocate lumpcache");
memset (lumpcache,0, size);
}
}
void W_Shutdown( void ) {
/*
for (int i = 0 ; i < MAXWADFILES ; i++) {
if ( ::g->wadFileHandles[i] ) {
doomFiles->FClose( ::g->wadFileHandles[i] );
}
}
if ( lumpinfo != NULL ) {
free( lumpinfo );
lumpinfo = NULL;
}
*/
W_FreeLumps();
W_FreeWadFiles();
}
//
// W_NumLumps
//
int W_NumLumps (void)
{
return numlumps;
}
//
// W_CheckNumForName
// Returns -1 if name not found.
//
int W_CheckNumForName (const char* name)
{
const int NameLength = 9;
union {
char s[NameLength];
int x[2];
} name8;
int v1;
int v2;
lumpinfo_t* lump_p;
// make the name into two integers for easy compares
strncpy (name8.s,name, NameLength - 1);
// in case the name was a fill 8 chars
name8.s[NameLength - 1] = 0;
// case insensitive
for ( int i = 0; i < NameLength; ++i ) {
name8.s[i] = toupper( name8.s[i] );
}
v1 = name8.x[0];
v2 = name8.x[1];
// scan backwards so patch lump files take precedence
lump_p = lumpinfo + numlumps;
while (lump_p-- != lumpinfo)
{
if ( *(int *)lump_p->name == v1
&& *(int *)&lump_p->name[4] == v2)
{
return lump_p - lumpinfo;
}
}
// TFB. Not found.
return -1;
}
//
// W_GetNumForName
// Calls W_CheckNumForName, but bombs out if not found.
//
int W_GetNumForName ( const char* name)
{
int i;
i = W_CheckNumForName ( name);
if (i == -1)
I_Error ("W_GetNumForName: %s not found!", name);
return i;
}
//
// W_LumpLength
// Returns the buffer size needed to load the given lump.
//
int W_LumpLength (int lump)
{
if (lump >= numlumps)
I_Error ("W_LumpLength: %i >= numlumps",lump);
return lumpinfo[lump].size;
}
//
// W_ReadLump
// Loads the lump into the given buffer,
// which must be >= W_LumpLength().
//
void
W_ReadLump
( int lump,
void* dest )
{
int c;
lumpinfo_t* l;
idFile * handle;
if (lump >= numlumps)
I_Error ("W_ReadLump: %i >= numlumps",lump);
l = lumpinfo+lump;
handle = l->handle;
handle->Seek( l->position, FS_SEEK_SET );
c = handle->Read( dest, l->size );
if (c < l->size)
I_Error ("W_ReadLump: only read %i of %i on lump %i", c,l->size,lump);
}
//
// W_CacheLumpNum
//
void*
W_CacheLumpNum
( int lump,
int tag )
{
#ifdef RANGECHECK
if (lump >= numlumps)
I_Error ("W_CacheLumpNum: %i >= numlumps",lump);
#endif
if (!lumpcache[lump])
{
byte* ptr;
// read the lump in
//I_Printf ("cache miss on lump %i\n",lump);
ptr = (byte*)DoomLib::Z_Malloc(W_LumpLength (lump), tag, &lumpcache[lump]);
W_ReadLump (lump, lumpcache[lump]);
}
return lumpcache[lump];
}
//
// W_CacheLumpName
//
void*
W_CacheLumpName
( const char* name,
int tag )
{
return W_CacheLumpNum (W_GetNumForName(name), tag);
}
void W_Profile (void)
{
}