- Added some hackery at the start of MouseRead_Win32() that prevents it from

yanking the mouse around if they keys haven't been read yet to combat the
  same situation that causes the keyboard to return DIERR_NOTACQUIRED in
  KeyRead(): The window is sort of in focus and sort of not. User.dll
  considers it to be focused and it's drawn as such, but another focused
  window is on top of it, and DirectInput doesn't see it as focused.
- Fixed: KeyRead() should handle DIERR_NOTACQUIRED errors the same way it
  handles DIERR_INPUTLOST errors. This can happen if our window had the
  focus stolen away from it before we tried to acquire the keyboard in
  DI_Init2(). Strangely, MouseRead_DI() already did this.
- When a stack overflow occurs, report.txt now only includes the first and
  last 16KB of the stack to make it more manageable.
- Limited StreamEditBinary() to the first 64KB of the file to keep it from
  taking too long on large dumps.
- And now I know why gathering crash information in the same process that
  crashed can be bad: Stack overflows. You get one spare page to play with
  when the stack overflows. MiniDumpWriteDump() needs more than that and
  causes an access violation when it runs out of leftover stack, silently
  terminating the application. Windows XP x64 offers SetThreadStackGuarantee()
  to increase this, but that isn't available on anything older, including
  32-bit XP. To get around this, a new thread is created to write the mini
  dump when the stack overflows.
- Changed A_Burnination() to be closer to Strife's.
- Fixed: When playing back demos, DoAddBot() can be called without an
  associated call to SpawnBot(). So if the bot can't spawn, botnum can
  go negative, which will cause problems later in DCajunMaster::Main()
  when it sees that wanted_botnum (0) is higher than botnum (-1).
- Fixed: Stopping demo recording in multiplayer games should not abruptly
  drop the recorder out of the game without notifying the other players.
  In fact, there's no reason why it should drop them out of multiplayer at
  all.
- Fixed: Earthquakes were unreliable in multiplayer games because
  P_PredictPlayer() did not preserve the player's xviewshift.
- Fixed: PlayerIsGone() needs to stop any scripts that belong to the player
  who left, in addition to executing disconnect scripts.
- Fixed: APlayerPawn::AddInventory() should also check for a NULL player->mo
  in case the player left but somebody still has a reference to their actor.
- Fixed: DDrawFB::PaintToWindow() should simulate proper unlocking behavior
  and set Buffer to NULL.
- Improved feedback for network game initialization with the console ticker.
- Moved i_net.cpp and i_net.h out of sdl/ and win32/ and into the main source
  directory. They are identical, so keeping two copies of them is bad.
- Fixed: (At least with Creative's driver's,) EAX settings are global and not
  per-application. So if you play a multiplayer ZDoom game on one computer
  (or even another EAX-using application), ZDoom needs to restore the
  environment when it regains focus.
- Maybe fixed: (See http://forum.zdoom.org/potato.php?t=10689) Apparently,
  PacketGet can receive ECONNRESET from nodes that aren't in the game. It
  should be safe to just ignore these packets.
- Fixed: PlayerIsGone() should set the gone player's camera to NULL in case
  the player who left was player 0. This is because if a remaining player
  receives a "recoverable" error, they will become player 0. Once that happens,
  they game will try to update sounds through their camera and crash in
  FMODSoundRenderer::UpdateListener() because the zones array is now NULL.
  G_NewInit() should also clear all the player structures.


SVN r233 (trunk)
This commit is contained in:
Randy Heit 2006-06-30 02:13:26 +00:00
parent 38b0230253
commit 9fdcb553aa
27 changed files with 390 additions and 1085 deletions

View file

@ -1,3 +1,60 @@
June 29, 2006
- Added some hackery at the start of MouseRead_Win32() that prevents it from
yanking the mouse around if they keys haven't been read yet to combat the
same situation that causes the keyboard to return DIERR_NOTACQUIRED in
KeyRead(): The window is sort of in focus and sort of not. User.dll
considers it to be focused and it's drawn as such, but another focused
window is on top of it, and DirectInput doesn't see it as focused.
- Fixed: KeyRead() should handle DIERR_NOTACQUIRED errors the same way it
handles DIERR_INPUTLOST errors. This can happen if our window had the
focus stolen away from it before we tried to acquire the keyboard in
DI_Init2(). Strangely, MouseRead_DI() already did this.
- When a stack overflow occurs, report.txt now only includes the first and
last 16KB of the stack to make it more manageable.
- Limited StreamEditBinary() to the first 64KB of the file to keep it from
taking too long on large dumps.
- And now I know why gathering crash information in the same process that
crashed can be bad: Stack overflows. You get one spare page to play with
when the stack overflows. MiniDumpWriteDump() needs more than that and
causes an access violation when it runs out of leftover stack, silently
terminating the application. Windows XP x64 offers SetThreadStackGuarantee()
to increase this, but that isn't available on anything older, including
32-bit XP. To get around this, a new thread is created to write the mini
dump when the stack overflows.
- Changed A_Burnination() to be closer to Strife's.
- Fixed: When playing back demos, DoAddBot() can be called without an
associated call to SpawnBot(). So if the bot can't spawn, botnum can
go negative, which will cause problems later in DCajunMaster::Main()
when it sees that wanted_botnum (0) is higher than botnum (-1).
- Fixed: Stopping demo recording in multiplayer games should not abruptly
drop the recorder out of the game without notifying the other players.
In fact, there's no reason why it should drop them out of multiplayer at
all.
- Fixed: Earthquakes were unreliable in multiplayer games because
P_PredictPlayer() did not preserve the player's xviewshift.
- Fixed: PlayerIsGone() needs to stop any scripts that belong to the player
who left, in addition to executing disconnect scripts.
- Fixed: APlayerPawn::AddInventory() should also check for a NULL player->mo
in case the player left but somebody still has a reference to their actor.
- Fixed: DDrawFB::PaintToWindow() should simulate proper unlocking behavior
and set Buffer to NULL.
- Improved feedback for network game initialization with the console ticker.
- Moved i_net.cpp and i_net.h out of sdl/ and win32/ and into the main source
directory. They are identical, so keeping two copies of them is bad.
- Fixed: (At least with Creative's driver's,) EAX settings are global and not
per-application. So if you play a multiplayer ZDoom game on one computer
(or even another EAX-using application), ZDoom needs to restore the
environment when it regains focus.
- Maybe fixed: (See http://forum.zdoom.org/potato.php?t=10689) Apparently,
PacketGet can receive ECONNRESET from nodes that aren't in the game. It
should be safe to just ignore these packets.
- Fixed: PlayerIsGone() should set the gone player's camera to NULL in case
the player who left was player 0. This is because if a remaining player
receives a "recoverable" error, they will become player 0. Once that happens,
they game will try to update sounds through their camera and crash in
FMODSoundRenderer::UpdateListener() because the zones array is now NULL.
G_NewInit() should also clear all the player structures.
June 29, 2006 (Changes by Graf Zahl) June 29, 2006 (Changes by Graf Zahl)
- Added a 'default' setting to all color selection menu items that leaves - Added a 'default' setting to all color selection menu items that leaves
the font untranslated. the font untranslated.

View file

@ -361,7 +361,10 @@ void DCajunMaster::DoAddBot (int bnum, char *info)
Printf ("%s tried to join, but there was no player %d start\n", Printf ("%s tried to join, but there was no player %d start\n",
players[bnum].userinfo.netname, bnum+1); players[bnum].userinfo.netname, bnum+1);
ClearPlayer (bnum, false); // Make the bot inactive again ClearPlayer (bnum, false); // Make the bot inactive again
botnum--; if (botnum > 0)
{
botnum--;
}
} }
else else
{ {

View file

@ -121,6 +121,7 @@ static GameAtExit *ExitCmdList;
EXTERN_CVAR (Bool, show_messages) EXTERN_CVAR (Bool, show_messages)
static unsigned int TickerAt, TickerMax; static unsigned int TickerAt, TickerMax;
static bool TickerPercent;
static const char *TickerLabel; static const char *TickerLabel;
static bool TickerVisible; static bool TickerVisible;
@ -1079,8 +1080,9 @@ static void C_DrawNotifyText ()
} }
} }
void C_InitTicker (const char *label, unsigned int max) void C_InitTicker (const char *label, unsigned int max, bool showpercent)
{ {
TickerPercent = showpercent;
TickerMax = max; TickerMax = max;
TickerLabel = label; TickerLabel = label;
TickerAt = 0; TickerAt = 0;
@ -1170,7 +1172,14 @@ void C_DrawConsole ()
memset (tickstr + tickbegin + 1, 0x11, tickend - tickbegin); memset (tickstr + tickbegin + 1, 0x11, tickend - tickbegin);
tickstr[tickend + 1] = 0x12; tickstr[tickend + 1] = 0x12;
tickstr[tickend + 2] = ' '; tickstr[tickend + 2] = ' ';
sprintf (tickstr + tickend + 3, "%lu%%", Scale (TickerAt, 100, TickerMax)); if (TickerPercent)
{
sprintf (tickstr + tickend + 3, "%lu%%", Scale (TickerAt, 100, TickerMax));
}
else
{
tickstr[tickend+3] = 0;
}
screen->DrawText (CR_BROWN, LEFTMARGIN, tickerY, tickstr, TAG_DONE); screen->DrawText (CR_BROWN, LEFTMARGIN, tickerY, tickstr, TAG_DONE);
// Draw the marker // Draw the marker
@ -1268,6 +1277,7 @@ void C_FullConsole ()
{ {
if (demoplayback) if (demoplayback)
G_CheckDemoStatus (); G_CheckDemoStatus ();
D_QuitNetGame ();
advancedemo = false; advancedemo = false;
ConsoleState = c_down; ConsoleState = c_down;
HistPos = NULL; HistPos = NULL;

View file

@ -69,7 +69,7 @@ void C_HideConsole (void);
void C_AdjustBottom (void); void C_AdjustBottom (void);
void C_FlushDisplay (void); void C_FlushDisplay (void);
void C_InitTicker (const char *label, unsigned int max); void C_InitTicker (const char *label, unsigned int max, bool showpercent=true);
void C_SetTicker (unsigned int at, bool forceUpdate=false); void C_SetTicker (unsigned int at, bool forceUpdate=false);
void C_MidPrint (const char *message); void C_MidPrint (const char *message);

View file

@ -633,16 +633,16 @@ void D_ErrorCleanup ()
screen->Unlock (); screen->Unlock ();
bglobal.RemoveAllBots (true); bglobal.RemoveAllBots (true);
D_QuitNetGame (); D_QuitNetGame ();
if (demorecording || demoplayback)
G_CheckDemoStatus ();
Net_ClearBuffers (); Net_ClearBuffers ();
G_NewInit (); G_NewInit ();
singletics = false; singletics = false;
if (demorecording || demoplayback)
G_CheckDemoStatus ();
playeringame[0] = 1; playeringame[0] = 1;
players[0].playerstate = PST_LIVE; players[0].playerstate = PST_LIVE;
gameaction = ga_fullconsole; gameaction = ga_fullconsole;
menuactive = MENU_Off; menuactive = MENU_Off;
insave=false; insave = false;
} }
//========================================================================== //==========================================================================

View file

@ -621,11 +621,13 @@ void PlayerIsGone (int netnode, int netconsole)
} }
// [RH] Make the player disappear // [RH] Make the player disappear
FBehavior::StaticStopMyScripts (players[netconsole].mo);
if (players[netconsole].mo != NULL) if (players[netconsole].mo != NULL)
{ {
P_DisconnectEffect (players[netconsole].mo); P_DisconnectEffect (players[netconsole].mo);
players[netconsole].mo->Destroy (); players[netconsole].mo->Destroy ();
players[netconsole].mo = NULL; players[netconsole].mo = NULL;
players[netconsole].camera = NULL;
} }
// [RH] Let the scripts know the player left // [RH] Let the scripts know the player left
FBehavior::StaticStartTypedScripts (SCRIPT_Disconnect, NULL, true, netconsole); FBehavior::StaticStartTypedScripts (SCRIPT_Disconnect, NULL, true, netconsole);

View file

@ -2101,7 +2101,10 @@ void G_WriteDemoTiccmd (ticcmd_t *cmd, int player, int buf)
if (stoprecording) if (stoprecording)
{ // use "stop" console command to end demo recording { // use "stop" console command to end demo recording
G_CheckDemoStatus (); G_CheckDemoStatus ();
gameaction = ga_fullconsole; if (!netgame)
{
gameaction = ga_fullconsole;
}
return; return;
} }

View file

@ -1369,10 +1369,13 @@ void G_NewInit ()
demoplayback = false; demoplayback = false;
D_SetupUserInfo (); D_SetupUserInfo ();
} }
memset (playeringame, 0, sizeof(playeringame));
for (i = 0; i < MAXPLAYERS; ++i) for (i = 0; i < MAXPLAYERS; ++i)
{ {
player_t *p = &players[i];
p->~player_t();
::new(p) player_t;
players[i].playerstate = PST_DEAD; players[i].playerstate = PST_DEAD;
playeringame[i] = 0;
} }
BackupSaveName = ""; BackupSaveName = "";
consoleplayer = 0; consoleplayer = 0;

View file

@ -142,7 +142,10 @@ DHUDMessage::~DHUDMessage ()
{ {
V_FreeBrokenLines (Lines); V_FreeBrokenLines (Lines);
Lines = NULL; Lines = NULL;
BorderNeedRefresh = screen->GetPageCount (); if (screen != NULL)
{
BorderNeedRefresh = screen->GetPageCount ();
}
} }
if (SourceText != NULL) if (SourceText != NULL)
{ {

View file

@ -1598,27 +1598,20 @@ void A_Burnination (AActor *self)
// x + (((pr_phburn() + 12) & 31) << FRACBITS); // x + (((pr_phburn() + 12) & 31) << FRACBITS);
// //
// But that creates a lop-sided burn because it won't use negative offsets. // But that creates a lop-sided burn because it won't use negative offsets.
int xofs = pr_phburn(); int xofs, xrand = pr_phburn();
int yofs = pr_phburn(); int yofs, yrand = pr_phburn();
xofs = (xofs - 128); // Adding 12 is pointless if you're going to mask it afterward.
if (xofs < 0) xofs = xrand & 31;
if (xrand & 128)
{ {
xofs = clamp (xofs, -31, -12); xofs = -xofs;
}
else
{
xofs = clamp (xofs, 12, 31);
} }
yofs = (yofs - 128); yofs = yrand & 31;
if (yofs < 0) if (yrand & 128)
{ {
yofs = clamp (yofs, -31, -12); yofs = -yofs;
}
else
{
yofs = clamp (yofs, 12, 31);
} }
fixed_t x = self->x + (xofs << FRACBITS); fixed_t x = self->x + (xofs << FRACBITS);

View file

@ -57,6 +57,7 @@
#include "m_crc32.h" #include "m_crc32.h"
#include "d_player.h" #include "d_player.h"
#include "templates.h" #include "templates.h"
#include "c_console.h"
#include "doomstat.h" #include "doomstat.h"
@ -215,11 +216,11 @@ void PacketGet (void)
, (sockaddr *)&fromaddress, &fromlen); , (sockaddr *)&fromaddress, &fromlen);
node = FindNode (&fromaddress); node = FindNode (&fromaddress);
if (c == SOCKET_ERROR) if (node >= 0 && c == SOCKET_ERROR)
{ {
int err = WSAGetLastError(); int err = WSAGetLastError();
if (err == WSAECONNRESET && node >= 0) if (err == WSAECONNRESET)
{ // The remote node aborted unexpectedly, so pretend it sent an exit packet { // The remote node aborted unexpectedly, so pretend it sent an exit packet
Printf (PRINT_BOLD, "The connection from %s was dropped\n", Printf (PRINT_BOLD, "The connection from %s was dropped\n",
@ -435,11 +436,15 @@ void HostGame (int i)
atterm (SendAbort); atterm (SendAbort);
C_InitTicker ("Waiting for players", numplayers);
C_SetTicker (1, true);
// Wait for numplayers-1 different connections // Wait for numplayers-1 different connections
while (doomcom.numnodes < numplayers) while (doomcom.numnodes < numplayers)
{ {
while (doomcom.numnodes < numplayers) while (doomcom.numnodes < numplayers)
{ {
C_SetTicker (doomcom.numnodes, true);
if (CheckAbort ()) if (CheckAbort ())
{ {
SendAbort (); SendAbort ();
@ -510,6 +515,8 @@ void HostGame (int i)
ackcount = 0; ackcount = 0;
memset (gotack, 0, sizeof(gotack)); memset (gotack, 0, sizeof(gotack));
Printf ("Sending all here\n"); Printf ("Sending all here\n");
C_InitTicker ("Done waiting", 1);
C_SetTicker (1, true);
while (ackcount < doomcom.numnodes - 1) while (ackcount < doomcom.numnodes - 1)
{ {
packet.fake = PRE_FAKE; packet.fake = PRE_FAKE;
@ -585,13 +592,32 @@ void HostGame (int i)
{ {
sendplayer[i] = i; sendplayer[i] = i;
} }
C_SetTicker (1, true);
C_InitTicker (NULL, 0);
} }
void SendToHost (BYTE message, BYTE ackmess, bool abortable) // This routine is used by a guest to notify the host of its presence.
// Once that host acknowledges receipt of the notification, this routine
// is never called again.
static const int bouncerfps = 10;
static const int bouncerdelay = 1000 / bouncerfps;
static const int updateperiod = 300 / bouncerdelay;
int SendToHost (BYTE message, BYTE ackmess, bool abortable)
{ {
sockaddr_in *from; sockaddr_in *from;
bool waiting = true; bool waiting = true;
PreGamePacket packet; PreGamePacket packet;
int bouncer = 0;
C_InitTicker ("Waiting for host", 8, false);
C_SetTicker (0, true);
// Let host know we are here
packet.fake = PRE_FAKE;
packet.message = message;
PreSend (&packet, 2, &sendaddress[1]);
while (waiting) while (waiting)
{ {
@ -601,25 +627,41 @@ void SendToHost (BYTE message, BYTE ackmess, bool abortable)
I_FatalError ("Network game synchronization aborted."); I_FatalError ("Network game synchronization aborted.");
} }
// Let host know we are here Sleep (bouncerdelay);
packet.fake = PRE_FAKE;
packet.message = message;
PreSend (&packet, 2, &sendaddress[1]);
Sleep (300);
// Listen for acknowledgement // Listen for acknowledgement
while ( (from = PreGet (&packet, sizeof(packet), true)) ) if (bouncer % updateperiod == 0)
{ {
if (packet.fake == PRE_FAKE && packet.message == ackmess) while ( (from = PreGet (&packet, sizeof(packet), true)) )
{ {
waiting = false; if (packet.fake == PRE_FAKE && packet.message == ackmess)
{
waiting = false;
doomcom.consoleplayer = packet.consolenum; doomcom.consoleplayer = packet.consolenum;
sendplayer[0] = packet.consolenum; sendplayer[0] = packet.consolenum;
Printf ("Console player number: %d\n", doomcom.consoleplayer); Printf ("Console player number: %d\n", doomcom.consoleplayer);
}
}
if (waiting)
{
// Let host know we are here
packet.fake = PRE_FAKE;
packet.message = message;
PreSend (&packet, 2, &sendaddress[1]);
} }
} }
if (waiting)
{
int tickpos = ++bouncer & 15;
if (tickpos > 8)
{
tickpos = 16 - tickpos;
}
C_SetTicker (tickpos, true);
}
} }
return bouncer;
} }
void JoinGame (int i) void JoinGame (int i)
@ -627,6 +669,7 @@ void JoinGame (int i)
sockaddr_in *from; sockaddr_in *from;
bool waiting; bool waiting;
PreGamePacket packet; PreGamePacket packet;
int bouncer;
if ((i == Args.NumArgs() - 1) || if ((i == Args.NumArgs() - 1) ||
(Args.GetArg(i+1)[0] == '-') || (Args.GetArg(i+1)[0] == '-') ||
@ -640,9 +683,10 @@ void JoinGame (int i)
sendplayer[1] = 0; sendplayer[1] = 0;
// Let host know we are here // Let host know we are here
SendToHost (PRE_CONNECT, PRE_CONACK, true); bouncer = SendToHost (PRE_CONNECT, PRE_CONACK, true);
// Wait for everyone else to connect // Wait for everyone else to connect
C_InitTicker ("Waiting for players", 8, false);
waiting = true; waiting = true;
//doomcom.numnodes = 2; //doomcom.numnodes = 2;
atterm (SendAbort); atterm (SendAbort);
@ -655,54 +699,68 @@ void JoinGame (int i)
I_FatalError ("Network game synchronization aborted."); I_FatalError ("Network game synchronization aborted.");
} }
Sleep (300); Sleep (bouncerdelay);
while (waiting && (from = PreGet (&packet, sizeof(packet), false)) )
if (bouncer % updateperiod == 0)
{ {
if (packet.fake != PRE_FAKE) while (waiting && (from = PreGet (&packet, sizeof(packet), false)) )
{ {
continue; if (packet.fake != PRE_FAKE)
}
switch (packet.message)
{
case PRE_ALLHERE:
if (doomcom.numnodes == 0)
{ {
int node; continue;
packet.numnodes = packet.numnodes;
doomcom.numnodes = packet.numnodes + 2;
for (node = 0; node < packet.numnodes; node++)
{
sendaddress[node+2].sin_addr.s_addr = packet.machines[node].address;
sendaddress[node+2].sin_port = packet.machines[node].port;
sendplayer[node+2] = packet.machines[node].player;
// [JC] - fixes problem of games not starting due to
// no address family being assigned to nodes stored in
// sendaddress[] from the All Here packet.
sendaddress[node+2].sin_family = AF_INET;
}
} }
switch (packet.message)
{
case PRE_ALLHERE:
if (doomcom.numnodes == 0)
{
int node;
Printf ("Received All Here, sending ACK\n"); packet.numnodes = packet.numnodes;
packet.fake = PRE_FAKE; doomcom.numnodes = packet.numnodes + 2;
packet.message = PRE_ALLHEREACK; for (node = 0; node < packet.numnodes; node++)
PreSend (&packet, 2, &sendaddress[1]); {
break; sendaddress[node+2].sin_addr.s_addr = packet.machines[node].address;
case PRE_GO: sendaddress[node+2].sin_port = packet.machines[node].port;
Printf ("Go\n"); sendplayer[node+2] = packet.machines[node].player;
waiting = false;
break; // [JC] - fixes problem of games not starting due to
case PRE_DISCONNECT: // no address family being assigned to nodes stored in
I_FatalError ("Host cancelled the game"); // sendaddress[] from the All Here packet.
break; sendaddress[node+2].sin_family = AF_INET;
}
}
Printf ("Received All Here, sending ACK\n");
packet.fake = PRE_FAKE;
packet.message = PRE_ALLHEREACK;
PreSend (&packet, 2, &sendaddress[1]);
break;
case PRE_GO:
Printf ("Go\n");
waiting = false;
break;
case PRE_DISCONNECT:
I_FatalError ("Host cancelled the game");
break;
}
} }
} }
if (waiting)
{
int tickpos = ++bouncer & 15;
if (tickpos > 8)
{
tickpos = 16 - tickpos;
}
C_SetTicker (tickpos, true);
}
} }
popterm (); popterm ();
Printf ("Total players: %d\n", doomcom.numnodes); Printf ("Total players: %d\n", doomcom.numnodes);
C_InitTicker (NULL, 0);
doomcom.id = DOOMCOM_ID; doomcom.id = DOOMCOM_ID;
doomcom.numplayers = doomcom.numnodes; doomcom.numplayers = doomcom.numnodes;

View file

@ -753,7 +753,7 @@ static value_t TextColors[] =
{ 7.0, "blue" }, { 7.0, "blue" },
{ 8.0, "orange" }, { 8.0, "orange" },
{ 9.0, "white" }, { 9.0, "white" },
{ 10.0, "yellow" } { 10.0, "yellow" },
{ 11.0, "default" } { 11.0, "default" }
}; };

View file

@ -1434,6 +1434,22 @@ void FBehavior::StartTypedScripts (WORD type, AActor *activator, bool always, in
} }
} }
// FBehavior :: StaticStopMyScripts
//
// Stops any scripts started by the specified actor. Used by the net code
// when a player disconnects. Should this be used in general whenever an
// actor is destroyed?
void FBehavior::StaticStopMyScripts (AActor *actor)
{
DACSThinker *controller = DACSThinker::ActiveThinker;
if (controller != NULL)
{
controller->StopScriptsFor (actor);
}
}
//---- The ACS Interpreter ----// //---- The ACS Interpreter ----//
void strbin (char *str); void strbin (char *str);
@ -1512,6 +1528,21 @@ void DACSThinker::Tick ()
} }
} }
void DACSThinker::StopScriptsFor (AActor *actor)
{
DLevelScript *script = Scripts;
while (script != NULL)
{
DLevelScript *next = script->next;
if (script->activator == actor)
{
script->SetState (DLevelScript::SCRIPT_PleaseRemove);
}
script = next;
}
}
IMPLEMENT_POINTY_CLASS (DLevelScript) IMPLEMENT_POINTY_CLASS (DLevelScript)
DECLARE_POINTER (activator) DECLARE_POINTER (activator)
END_POINTERS END_POINTERS

View file

@ -156,6 +156,7 @@ public:
static const ScriptPtr *StaticFindScript (int script, FBehavior *&module); static const ScriptPtr *StaticFindScript (int script, FBehavior *&module);
static const char *StaticLookupString (DWORD index); static const char *StaticLookupString (DWORD index);
static void StaticStartTypedScripts (WORD type, AActor *activator, bool always, int arg1=0, bool runNow=false); static void StaticStartTypedScripts (WORD type, AActor *activator, bool always, int arg1=0, bool runNow=false);
static void StaticStopMyScripts (AActor *actor);
private: private:
struct ArrayInfo; struct ArrayInfo;
@ -632,6 +633,7 @@ public:
static DACSThinker *ActiveThinker; static DACSThinker *ActiveThinker;
void DumpScriptStatus(); void DumpScriptStatus();
void StopScriptsFor (AActor *actor);
private: private:
DLevelScript *LastScript; DLevelScript *LastScript;

View file

@ -278,7 +278,7 @@ void APlayerPawn::Tick()
void APlayerPawn::AddInventory (AInventory *item) void APlayerPawn::AddInventory (AInventory *item)
{ {
// Adding inventory to a voodoo doll should add it to the real player instead. // Adding inventory to a voodoo doll should add it to the real player instead.
if (player != NULL && player->mo != this) if (player != NULL && player->mo != this && player->mo != NULL)
{ {
player->mo->AddInventory (item); player->mo->AddInventory (item);
return; return;
@ -1728,13 +1728,14 @@ void P_PredictPlayer (player_t *player)
} }
act->BlockNode = NULL; act->BlockNode = NULL;
int xviewshift = player->xviewshift;
for (int i = gametic; i < maxtic; ++i) for (int i = gametic; i < maxtic; ++i)
{ {
player->cmd = localcmds[i % LOCALCMDTICS]; player->cmd = localcmds[i % LOCALCMDTICS];
P_PlayerThink (player); P_PlayerThink (player);
player->mo->Tick (); player->mo->Tick ();
} }
player->xviewshift = xviewshift;
} }
extern msecnode_t *P_AddSecnode (sector_t *s, AActor *thing, msecnode_t *nextnode); extern msecnode_t *P_AddSecnode (sector_t *s, AActor *thing, msecnode_t *nextnode);

View file

@ -857,6 +857,11 @@ void FMODSoundRenderer::UpdateSoundParams3D (long handle, float pos[3], float ve
FSOUND_3D_SetAttributes (ChannelMap[handle].channelID, pos, vel); FSOUND_3D_SetAttributes (ChannelMap[handle].channelID, pos, vel);
} }
void FMODSoundRenderer::ResetEnvironment ()
{
PrevEnvironment = NULL;
}
void FMODSoundRenderer::UpdateListener (AActor *listener) void FMODSoundRenderer::UpdateListener (AActor *listener)
{ {
float angle; float angle;
@ -908,6 +913,7 @@ void FMODSoundRenderer::UpdateListener (AActor *listener)
else else
{ {
underwater = (listener->waterlevel == 3 && snd_waterreverb); underwater = (listener->waterlevel == 3 && snd_waterreverb);
assert (zones != NULL);
env = zones[listener->Sector->ZoneNumber].Environment; env = zones[listener->Sector->ZoneNumber].Environment;
if (env == NULL) if (env == NULL)
{ {

View file

@ -51,6 +51,7 @@ public:
void PrintStatus (); void PrintStatus ();
void PrintDriversList (); void PrintDriversList ();
void GatherStats (char *outstring); void GatherStats (char *outstring);
void ResetEnvironment ();
private: private:
// Maps sfx channels onto FMOD channels // Maps sfx channels onto FMOD channels

View file

@ -332,6 +332,10 @@ void SoundRenderer::GatherStats (char *outstring)
sprintf (outstring, "No stats for this sound renderer."); sprintf (outstring, "No stats for this sound renderer.");
} }
void SoundRenderer::ResetEnvironment ()
{
}
SoundStream::~SoundStream () SoundStream::~SoundStream ()
{ {
} }
@ -339,3 +343,4 @@ SoundStream::~SoundStream ()
SoundTrackerModule::~SoundTrackerModule () SoundTrackerModule::~SoundTrackerModule ()
{ {
} }

View file

@ -120,6 +120,7 @@ public:
virtual void PrintStatus () = 0; virtual void PrintStatus () = 0;
virtual void PrintDriversList () = 0; virtual void PrintDriversList () = 0;
virtual void GatherStats (char *outstring); virtual void GatherStats (char *outstring);
virtual void ResetEnvironment ();
bool Sound3D; bool Sound3D;
}; };

View file

@ -175,6 +175,13 @@ typedef BOOL (WINAPI *WRITEDUMP) (HANDLE, DWORD, HANDLE, MINIDUMP_TYPE,
PMINIDUMP_USER_STREAM_INFORMATION, PMINIDUMP_USER_STREAM_INFORMATION,
PMINIDUMP_CALLBACK_INFORMATION); PMINIDUMP_CALLBACK_INFORMATION);
struct MiniDumpThreadData
{
HANDLE File;
WRITEDUMP pMiniDumpWriteDump;
MINIDUMP_EXCEPTION_INFORMATION *Exceptor;
};
// EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
@ -188,11 +195,12 @@ static void AddZipFile (HANDLE ziphandle, TarFile *whichfile, short dosdate, sho
static HANDLE CreateTempFile (); static HANDLE CreateTempFile ();
static void DumpBytes (HANDLE file, BYTE *address); static void DumpBytes (HANDLE file, BYTE *address);
static void AddStackInfo (HANDLE file, void *dumpaddress); static void AddStackInfo (HANDLE file, void *dumpaddress, DWORD code);
static void StackWalk (HANDLE file, void *dumpaddress, DWORD *topOfStack); static void StackWalk (HANDLE file, void *dumpaddress, DWORD *topOfStack, DWORD *jump);
static void AddToolHelp (HANDLE file); static void AddToolHelp (HANDLE file);
static HANDLE WriteTextReport (); static HANDLE WriteTextReport ();
static DWORD WINAPI WriteMiniDumpInAnotherThread (LPVOID lpParam);
static INT_PTR CALLBACK DetailsDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); static INT_PTR CALLBACK DetailsDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
static void SetEditControl (HWND control, HWND sizedisplay, int filenum); static void SetEditControl (HWND control, HWND sizedisplay, int filenum);
@ -379,8 +387,23 @@ static HANDLE WriteMyMiniDump (void)
file = CreateTempFile (); file = CreateTempFile ();
if (file != INVALID_HANDLE_VALUE) if (file != INVALID_HANDLE_VALUE)
{ {
good = pMiniDumpWriteDump (DbgProcess, DbgProcessID, file, if (CrashPointers.ExceptionRecord->ExceptionCode != EXCEPTION_STACK_OVERFLOW)
MiniDumpNormal, &exceptor, NULL, NULL); {
good = pMiniDumpWriteDump (DbgProcess, DbgProcessID, file,
MiniDumpNormal, &exceptor, NULL, NULL);
}
else
{
MiniDumpThreadData dumpdata = { file, pMiniDumpWriteDump, &exceptor };
DWORD id;
HANDLE thread = CreateThread (NULL, 0, WriteMiniDumpInAnotherThread,
&dumpdata, 0, &id);
WaitForSingleObject (thread, INFINITE);
if (GetExitCodeThread (thread, &id))
{
good = id;
}
}
} }
} }
else else
@ -390,6 +413,23 @@ static HANDLE WriteMyMiniDump (void)
return good ? file : INVALID_HANDLE_VALUE; return good ? file : INVALID_HANDLE_VALUE;
} }
//==========================================================================
//
// WriteMiniDumpInAnotherThread
//
// When a stack overflow occurs, there isn't enough room left on the stack
// for MiniDumpWriteDump to do its thing, so we create a new thread with
// a new stack to do the work.
//
//==========================================================================
static DWORD WINAPI WriteMiniDumpInAnotherThread (LPVOID lpParam)
{
MiniDumpThreadData *dumpdata = (MiniDumpThreadData *)lpParam;
return dumpdata->pMiniDumpWriteDump (DbgProcess, DbgProcessID,
dumpdata->File, MiniDumpNormal, dumpdata->Exceptor, NULL, NULL);
}
//========================================================================== //==========================================================================
// //
// Writef // Writef
@ -634,7 +674,8 @@ HANDLE WriteTextReport ()
if (ctxt->ContextFlags & CONTEXT_CONTROL) if (ctxt->ContextFlags & CONTEXT_CONTROL)
{ {
AddStackInfo (file, (void *)(size_t)CrashPointers.ContextRecord->Esp); AddStackInfo (file, (void *)(size_t)CrashPointers.ContextRecord->Esp,
CrashPointers.ExceptionRecord->ExceptionCode);
} }
return file; return file;
@ -731,14 +772,24 @@ static void AddToolHelp (HANDLE file)
// //
//========================================================================== //==========================================================================
static void AddStackInfo (HANDLE file, void *dumpaddress) static void AddStackInfo (HANDLE file, void *dumpaddress, DWORD code)
{ {
DWORD *addr = (DWORD *)dumpaddress; DWORD *addr = (DWORD *)dumpaddress, *jump;
DWORD *topOfStack = GetTopOfStack (dumpaddress); DWORD *topOfStack = GetTopOfStack (dumpaddress);
BYTE peekb; BYTE peekb;
DWORD peekd; DWORD peekd;
StackWalk (file, dumpaddress, topOfStack); jump = topOfStack;
if (code == EXCEPTION_STACK_OVERFLOW)
{
// If the stack overflowed, only dump the first and last 16KB of it.
if (topOfStack - addr > 32768/4)
{
jump = addr + 16384/4;
}
}
StackWalk (file, dumpaddress, topOfStack, jump);
Writef (file, "\r\nStack Contents:\r\n"); Writef (file, "\r\nStack Contents:\r\n");
DWORD *scan; DWORD *scan;
@ -747,6 +798,12 @@ static void AddStackInfo (HANDLE file, void *dumpaddress)
int i; int i;
ptrdiff_t max; ptrdiff_t max;
if (scan == jump)
{
scan = topOfStack - 16384/4;
Writef (file, "\r\n . . . Snip . . .\r\n\r\n");
}
if (topOfStack - scan < 4) if (topOfStack - scan < 4)
{ {
max = topOfStack - scan; max = topOfStack - scan;
@ -792,7 +849,7 @@ static void AddStackInfo (HANDLE file, void *dumpaddress)
// //
//========================================================================== //==========================================================================
static void StackWalk (HANDLE file, void *dumpaddress, DWORD *topOfStack) static void StackWalk (HANDLE file, void *dumpaddress, DWORD *topOfStack, DWORD *jump)
{ {
DWORD *addr = (DWORD *)dumpaddress; DWORD *addr = (DWORD *)dumpaddress;
@ -809,6 +866,12 @@ static void StackWalk (HANDLE file, void *dumpaddress, DWORD *topOfStack)
{ {
DWORD_PTR code; DWORD_PTR code;
if (scan == jump)
{
scan = topOfStack - 16384/4;
Writef (file, "\r\n\r\n . . . . Snip . . . .\r\n");
}
if (SafeReadMemory (scan, &code, sizeof(code)) && if (SafeReadMemory (scan, &code, sizeof(code)) &&
code >= codeStart && code < codeEnd) code >= codeStart && code < codeEnd)
{ {
@ -1793,9 +1856,9 @@ repeat:
while (cb - ((LPBYTE)buff_p - buffer) > 150) while (cb - ((LPBYTE)buff_p - buffer) > 150)
{ {
ReadFile (info->File, buf16, 16, &read, NULL); ReadFile (info->File, buf16, 16, &read, NULL);
if (read == 0) if (read == 0 || info->Pointer >= 65536)
{ {
info->Stage++; info->Stage = read == 0 ? 2 : 3;
goto repeat; goto repeat;
} }
char *linestart = buff_p; char *linestart = buff_p;
@ -1833,10 +1896,15 @@ repeat:
case 2: // Write epilogue case 2: // Write epilogue
buff_p += sprintf (buff_p, "\\cf0 }"); buff_p += sprintf (buff_p, "\\cf0 }");
info->Stage++; info->Stage = 4;
break; break;
case 3: // We're done case 3: // Write epilogue for truncated file
buff_p += sprintf (buff_p, "--- Rest of file truncated ---\\cf0 }");
info->Stage = 4;
break;
case 4: // We're done
return TRUE; return TRUE;
} }

View file

@ -357,6 +357,7 @@ CUSTOM_CVAR (Int, in_mouse, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
static BYTE KeyState[256]; static BYTE KeyState[256];
static BYTE DIKState[2][NUM_KEYS]; static BYTE DIKState[2][NUM_KEYS];
static int KeysReadCount;
static int ActiveDIKState; static int ActiveDIKState;
static void SetSoundPaused (int state); static void SetSoundPaused (int state);
@ -744,6 +745,10 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if (wParam) if (wParam)
{ {
SetPriorityClass (GetCurrentProcess (), INGAME_PRIORITY_CLASS); SetPriorityClass (GetCurrentProcess (), INGAME_PRIORITY_CLASS);
if (GSnd != NULL)
{
GSnd->ResetEnvironment();
}
} }
else if (!noidle && !netgame) else if (!noidle && !netgame)
{ {
@ -1686,8 +1691,18 @@ static void MouseRead_Win32 ()
POINT pt; POINT pt;
int x, y; int x, y;
if (KeysReadCount == 0)
{
UngrabMouse_Win32();
}
else if (KeysReadCount == 1 && HaveFocus && !MakeMouseEvents)
{
GrabMouse_Win32();
}
if (!HaveFocus || !MakeMouseEvents || !GetCursorPos (&pt)) if (!HaveFocus || !MakeMouseEvents || !GetCursorPos (&pt))
{
return; return;
}
x = pt.x - PrevX; x = pt.x - PrevX;
y = PrevY - pt.y; y = PrevY - pt.y;
@ -1829,7 +1844,7 @@ static void KeyRead ()
toState = DIKState[ActiveDIKState ^ 1]; toState = DIKState[ActiveDIKState ^ 1];
hr = g_pKey->GetDeviceState (256, toState); hr = g_pKey->GetDeviceState (256, toState);
if (hr == DIERR_INPUTLOST) if (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED)
{ {
hr = g_pKey->Acquire (); hr = g_pKey->Acquire ();
if (hr != DI_OK) if (hr != DI_OK)
@ -1844,6 +1859,7 @@ static void KeyRead ()
} }
// Successfully got the buffer // Successfully got the buffer
KeysReadCount++;
ActiveDIKState ^= 1; ActiveDIKState ^= 1;
// Copy key states not handled here from the old to the new buffer // Copy key states not handled here from the old to the new buffer

View file

@ -519,6 +519,14 @@ LONG WINAPI CatchAllExceptions (LPEXCEPTION_POINTERS info)
return EXCEPTION_CONTINUE_EXECUTION; return EXCEPTION_CONTINUE_EXECUTION;
} }
static void infiniterecursion(int foo)
{
if (foo)
{
infiniterecursion(foo);
}
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE nothing, LPSTR cmdline, int nCmdShow) int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE nothing, LPSTR cmdline, int nCmdShow)
{ {
g_hInst = hInstance; g_hInst = hInstance;
@ -539,6 +547,19 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE nothing, LPSTR cmdline, int n
DisplayCrashLog (); DisplayCrashLog ();
exit (0); exit (0);
} }
if (__argc == 2 && strcmp (__argv[1], "TestStackCrash") == 0)
{
__try
{
infiniterecursion(1);
}
__except(CrashPointers = *GetExceptionInformation(),
CreateCrashLog (__argv[1], 14), EXCEPTION_EXECUTE_HANDLER)
{
}
DisplayCrashLog ();
exit (0);
}
#endif #endif
#ifdef REGEXEPEEK #ifdef REGEXEPEEK
@ -550,17 +571,12 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE nothing, LPSTR cmdline, int n
0, FALSE, DUPLICATE_SAME_ACCESS); 0, FALSE, DUPLICATE_SAME_ACCESS);
MainThreadID = GetCurrentThreadId(); MainThreadID = GetCurrentThreadId();
#ifndef _DEBUG
if (MainThread != INVALID_HANDLE_VALUE) if (MainThread != INVALID_HANDLE_VALUE)
{ {
// SetUnhandledExceptionFilter is not supposed to do anything if a debugger SetUnhandledExceptionFilter (CatchAllExceptions);
// is attached to the process, but one time I did see my exception filter
// used instead of breaking into the debugger. (Or maybe I just forgot to
// run it in the debugger. Whatever. It doesn't hurt to check for one.)
#ifdef _DEBUG
if (!IsDebuggerPresent ())
#endif
SetUnhandledExceptionFilter (CatchAllExceptions);
} }
#endif
#if defined(_DEBUG) && defined(_MSC_VER) #if defined(_DEBUG) && defined(_MSC_VER)
// Uncomment this line to make the Visual C++ CRT check the heap before // Uncomment this line to make the Visual C++ CRT check the heap before

View file

@ -1,837 +0,0 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id: i_net.c,v 1.2 1997/12/29 19:50:54 pekangas Exp $
//
// Copyright (C) 1993-1996 by id Software, Inc.
//
// This source is available for distribution and/or modification
// only under the terms of the DOOM Source Code License as
// published by id Software. All rights reserved.
//
// The source is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
// for more details.
//
// DESCRIPTION:
// Low-level networking code. Uses BSD sockets for UDP networking.
//
//-----------------------------------------------------------------------------
/* [Petteri] Check if compiling for Win32: */
#if defined(__WINDOWS__) || defined(__NT__) || defined(_MSC_VER) || defined(_WIN32)
#ifndef __WIN32__
# define __WIN32__
#endif
#endif
/* Follow #ifdef __WIN32__ marks */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/* [Petteri] Use Winsock for Win32: */
#ifdef __WIN32__
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# include <winsock.h>
#else
# include <sys/socket.h>
# include <netinet/in.h>
# include <arpa/inet.h>
# include <errno.h>
# include <unistd.h>
# include <netdb.h>
# include <sys/ioctl.h>
#endif
#include "doomtype.h"
#include "i_system.h"
#include "d_event.h"
#include "d_net.h"
#include "m_argv.h"
#include "m_alloc.h"
#include "m_swap.h"
#include "m_crc32.h"
#include "d_player.h"
#include "templates.h"
#include "doomstat.h"
#include "i_net.h"
/* [Petteri] Get more portable: */
#ifndef __WIN32__
typedef int SOCKET;
#define SOCKET_ERROR -1
#define INVALID_SOCKET -1
#define closesocket close
#define ioctlsocket ioctl
#define Sleep(x) usleep (x * 1000)
#define WSAEWOULDBLOCK EWOULDBLOCK
#define WSAECONNRESET ECONNRESET
#define WSAGetLastError() errno
#endif
#ifdef __WIN32__
#define IPPORT_USERRESERVED 5000
typedef int socklen_t;
#endif
extern BOOL CheckAbort (void);
//
// NETWORKING
//
static u_short DOOMPORT = (IPPORT_USERRESERVED + 29);
static SOCKET mysocket = INVALID_SOCKET;
static sockaddr_in sendaddress[MAXNETNODES];
static BYTE sendplayer[MAXNETNODES];
void (*netget) (void);
void (*netsend) (void);
#ifdef __WIN32__
char *neterror (void);
#else
#define neterror() strerror(errno)
#endif
enum
{
PRE_CONNECT,
PRE_DISCONNECT,
PRE_ALLHERE,
PRE_CONACK,
PRE_ALLHEREACK,
PRE_GO
};
// Set PreGamePacket.fake to this so that the game rejects any pregame packets
// after it starts. This translates to NCMD_SETUP|NCMD_MULTI.
#define PRE_FAKE 0x30
struct PreGamePacket
{
BYTE fake;
BYTE message;
BYTE numnodes;
BYTE consolenum;
struct
{
u_long address;
u_short port;
BYTE player;
BYTE pad;
} machines[MAXNETNODES];
};
//
// UDPsocket
//
SOCKET UDPsocket (void)
{
SOCKET s;
// allocate a socket
s = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (s == INVALID_SOCKET)
I_FatalError ("can't create socket: %s", neterror ());
return s;
}
//
// BindToLocalPort
//
void BindToLocalPort (SOCKET s, u_short port)
{
int v;
sockaddr_in address;
memset (&address, 0, sizeof(address));
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(port);
v = bind (s, (sockaddr *)&address, sizeof(address));
if (v == SOCKET_ERROR)
I_FatalError ("BindToPort: %s", neterror ());
}
int FindNode (sockaddr_in *address)
{
int i;
// find remote node number
for (i = 0; i<doomcom.numnodes; i++)
if (address->sin_addr.s_addr == sendaddress[i].sin_addr.s_addr
&& address->sin_port == sendaddress[i].sin_port)
break;
if (i == doomcom.numnodes)
{
// packet is not from one of the players (new game broadcast?)
i = -1;
}
return i;
}
//
// PacketSend
//
void PacketSend (void)
{
int c;
//printf ("sending %i\n",gametic);
c = sendto (mysocket , (const char*)doomcom.data, doomcom.datalength
,0,(sockaddr *)&sendaddress[doomcom.remotenode]
,sizeof(sendaddress[doomcom.remotenode]));
// if (c == -1)
// I_Error ("SendPacket error: %s",strerror(errno));
}
//
// PacketGet
//
void PacketGet (void)
{
int c;
socklen_t fromlen;
sockaddr_in fromaddress;
int node;
fromlen = sizeof(fromaddress);
c = recvfrom (mysocket, (char*)doomcom.data, MAX_MSGLEN, 0
, (sockaddr *)&fromaddress, &fromlen);
node = FindNode (&fromaddress);
if (c == SOCKET_ERROR)
{
int err = WSAGetLastError();
if (err == WSAECONNRESET && node >= 0)
{ // The remote node aborted unexpectedly, so pretend it sent an exit packet
Printf (PRINT_BOLD, "The connection from %s was dropped\n",
players[sendplayer[node]].userinfo.netname);
doomcom.data[0] = 0x80; // NCMD_EXIT
c = 1;
}
else if (err != WSAEWOULDBLOCK)
{
I_Error ("GetPacket: %s", neterror ());
}
else
{
doomcom.remotenode = -1; // no packet
return;
}
}
doomcom.remotenode = node;
doomcom.datalength = (short)c;
}
sockaddr_in *PreGet (void *buffer, int bufferlen, bool noabort)
{
static sockaddr_in fromaddress;
socklen_t fromlen;
int c;
fromlen = sizeof(fromaddress);
c = recvfrom (mysocket, (char *)buffer, bufferlen, 0,
(sockaddr *)&fromaddress, &fromlen);
if (c == SOCKET_ERROR)
{
int err = WSAGetLastError();
if (err == WSAEWOULDBLOCK || (noabort && err == WSAECONNRESET))
return NULL; // no packet
I_Error ("PreGet: %s", neterror ());
}
return &fromaddress;
}
void PreSend (const void *buffer, int bufferlen, sockaddr_in *to)
{
sendto (mysocket, (const char *)buffer, bufferlen, 0, (sockaddr *)to, sizeof(*to));
}
void BuildAddress (sockaddr_in *address, char *name)
{
hostent *hostentry; // host information entry
u_short port;
char *portpart;
bool isnamed = false;
int curchar;
char c;
address->sin_family = AF_INET;
if ( (portpart = strchr (name, ':')) )
{
*portpart = 0;
port = atoi (portpart + 1);
if (!port)
{
Printf ("Weird port: %s (using %d)\n", portpart + 1, DOOMPORT);
port = DOOMPORT;
}
}
else
{
port = DOOMPORT;
}
address->sin_port = htons(port);
for (curchar = 0; (c = name[curchar]) ; curchar++)
{
if ((c < '0' || c > '9') && c != '.')
{
isnamed = true;
break;
}
}
if (!isnamed)
{
address->sin_addr.s_addr = inet_addr (name);
Printf ("Node number %d address %s\n", doomcom.numnodes, name);
}
else
{
hostentry = gethostbyname (name);
if (!hostentry)
I_FatalError ("gethostbyname: couldn't find %s\n%s", name, neterror());
address->sin_addr.s_addr = *(int *)hostentry->h_addr_list[0];
Printf ("Node number %d hostname %s\n",
doomcom.numnodes, hostentry->h_name);
}
if (portpart)
*portpart = ':';
}
void CloseNetwork (void)
{
if (mysocket != INVALID_SOCKET)
{
closesocket (mysocket);
mysocket = INVALID_SOCKET;
}
#ifdef __WIN32__
WSACleanup ();
#endif
}
void StartNetwork (bool autoPort)
{
u_long trueval = 1;
#ifdef __WIN32__
WSADATA wsad;
if (WSAStartup (0x0101, &wsad))
{
I_FatalError ("Could not initialize Windows Sockets");
}
#endif
atterm (CloseNetwork);
netsend = PacketSend;
netget = PacketGet;
netgame = true;
multiplayer = true;
// create communication socket
mysocket = UDPsocket ();
BindToLocalPort (mysocket, autoPort ? 0 : DOOMPORT);
ioctlsocket (mysocket, FIONBIO, &trueval);
}
void WaitForPlayers (int i)
{
if (i == Args.NumArgs() - 1)
I_FatalError ("Not enough parameters after -net");
StartNetwork (false);
// parse player number and host list
doomcom.consoleplayer = (short)(Args.GetArg (i+1)[0]-'1');
Printf ("Console player number: %d\n", doomcom.consoleplayer);
doomcom.numnodes = 1; // this node for sure
i++;
while (++i < Args.NumArgs() && Args.GetArg (i)[0] != '-' && Args.GetArg (i)[0] != '+')
{
BuildAddress (&sendaddress[doomcom.numnodes], Args.GetArg (i));
doomcom.numnodes++;
}
Printf ("Total players: %d\n", doomcom.numnodes);
doomcom.id = DOOMCOM_ID;
doomcom.numplayers = doomcom.numnodes;
}
void SendAbort (void)
{
BYTE dis[2] = { PRE_FAKE, PRE_DISCONNECT };
while (--doomcom.numnodes > 0)
{
PreSend (dis, 2, &sendaddress[doomcom.numnodes]);
PreSend (dis, 2, &sendaddress[doomcom.numnodes]);
PreSend (dis, 2, &sendaddress[doomcom.numnodes]);
PreSend (dis, 2, &sendaddress[doomcom.numnodes]);
}
}
void HostGame (int i)
{
PreGamePacket packet;
int numplayers;
bool gotack[MAXNETNODES];
int ackcount;
sockaddr_in *from;
int node;
if ((i == Args.NumArgs() - 1) || !(numplayers = atoi (Args.GetArg(i+1))))
{ // No player count specified, assume 2
numplayers = 2;
}
if (numplayers == 1)
{ // Special case: Only 1 player, so don't bother starting the network
netgame = false;
multiplayer = true;
doomcom.id = DOOMCOM_ID;
doomcom.numplayers = doomcom.numnodes = 1;
doomcom.consoleplayer = 0;
return;
}
StartNetwork (false);
// [JC] - this computer is starting the game, therefore it should
// be the Net Arbitrator.
doomcom.consoleplayer = 0;
Printf ("Console player number: %d\n", doomcom.consoleplayer);
doomcom.numnodes = 1;
Printf ("Waiting for players...\n");
atterm (SendAbort);
// Wait for numplayers-1 different connections
while (doomcom.numnodes < numplayers)
{
while (doomcom.numnodes < numplayers)
{
if (CheckAbort ())
{
SendAbort ();
I_FatalError ("Network game synchronization aborted.");
}
while ( (from = PreGet (&packet, sizeof(packet), false)) )
{
if (packet.fake != PRE_FAKE)
{
continue;
}
switch (packet.message)
{
case PRE_CONNECT:
node = FindNode (from);
if (node == -1)
{
node = doomcom.numnodes++;
sendaddress[node] = *from;
}
Printf ("Got connect from node %d\n", node);
packet.message = PRE_CONACK;
packet.consolenum = node;
PreSend (&packet, 4, from);
break;
case PRE_DISCONNECT:
node = FindNode (from);
if (node >= 0)
{
Printf ("Got disconnect from node %d\n", node);
doomcom.numnodes--;
while (node < doomcom.numnodes)
{
sendaddress[node] = sendaddress[node+1];
node++;
}
}
break;
}
}
}
// It's possible somebody bailed out after all players were found.
// Unfortunately, this isn't guaranteed to catch all of them.
// Oh well. Better than nothing.
while ( (from = PreGet (&packet, sizeof(packet), false)) )
{
if (packet.fake == PRE_FAKE && packet.message == PRE_DISCONNECT)
{
node = FindNode (from);
if (node >= 0)
{
doomcom.numnodes--;
while (node < doomcom.numnodes)
{
sendaddress[node] = sendaddress[node+1];
node++;
}
}
break;
}
}
}
// Now inform everyone of all machines involved in the game
ackcount = 0;
memset (gotack, 0, sizeof(gotack));
Printf ("Sending all here\n");
while (ackcount < doomcom.numnodes - 1)
{
packet.fake = PRE_FAKE;
packet.message = PRE_ALLHERE;
packet.numnodes = doomcom.numnodes - 2;
for (node = 1; node < doomcom.numnodes; node++)
{
int machine, spot = 0;
if (!gotack[node])
{
for (spot = 0, machine = 1; machine < doomcom.numnodes; machine++)
{
if (node != machine)
{
packet.machines[spot].address = sendaddress[machine].sin_addr.s_addr;
packet.machines[spot].port = sendaddress[machine].sin_port;
packet.machines[spot].player = node;
spot++; // fixes problem of new address replacing existing address in
// array, it's supposed to increment the index before getting
// and storing in the packet the next address.
}
}
}
PreSend (&packet, 4 + spot*8, &sendaddress[node]);
}
if (CheckAbort ())
{
SendAbort ();
I_FatalError ("Network game synchronization aborted.");
}
while ( (from = PreGet (&packet, sizeof(packet), false)) )
{
if (packet.fake == PRE_FAKE && packet.message == PRE_ALLHEREACK)
{
node = FindNode (from);
if (node >= 0)
{
if (!gotack[node])
{
gotack[node] = true;
ackcount++;
}
}
PreSend (&packet, 2, from);
}
}
}
popterm ();
// Now go
Printf ("Go\n");
packet.fake = PRE_FAKE;
packet.message = PRE_GO;
for (node = 1; node < doomcom.numnodes; node++)
{
for (int i = 8; i != 0; --i)
{
PreSend (&packet, 2, &sendaddress[node]);
}
}
Printf ("Total players: %d\n", doomcom.numnodes);
doomcom.id = DOOMCOM_ID;
doomcom.numplayers = doomcom.numnodes;
// On the host, each player's number is the same as its node number
for (i = 0; i < doomcom.numnodes; ++i)
{
sendplayer[i] = i;
}
}
void SendToHost (BYTE message, BYTE ackmess, bool abortable)
{
sockaddr_in *from;
bool waiting = true;
PreGamePacket packet;
while (waiting)
{
if (abortable && CheckAbort ())
{
SendAbort ();
I_FatalError ("Network game synchronization aborted.");
}
// Let host know we are here
packet.fake = PRE_FAKE;
packet.message = message;
PreSend (&packet, 2, &sendaddress[1]);
Sleep (300);
// Listen for acknowledgement
while ( (from = PreGet (&packet, sizeof(packet), true)) )
{
if (packet.fake == PRE_FAKE && packet.message == ackmess)
{
waiting = false;
doomcom.consoleplayer = packet.consolenum;
sendplayer[0] = packet.consolenum;
Printf ("Console player number: %d\n", doomcom.consoleplayer);
}
}
}
}
void JoinGame (int i)
{
sockaddr_in *from;
bool waiting;
PreGamePacket packet;
if ((i == Args.NumArgs() - 1) ||
(Args.GetArg(i+1)[0] == '-') ||
(Args.GetArg(i+1)[0] == '+'))
I_FatalError ("You need to specify the host machine's address");
StartNetwork (true);
// Host is always node 1
BuildAddress (&sendaddress[1], Args.GetArg(i+1));
sendplayer[1] = 0;
// Let host know we are here
SendToHost (PRE_CONNECT, PRE_CONACK, true);
// Wait for everyone else to connect
waiting = true;
//doomcom.numnodes = 2;
atterm (SendAbort);
while (waiting)
{
if (CheckAbort ())
{
SendAbort ();
I_FatalError ("Network game synchronization aborted.");
}
Sleep (300);
while (waiting && (from = PreGet (&packet, sizeof(packet), false)) )
{
if (packet.fake != PRE_FAKE)
{
continue;
}
switch (packet.message)
{
case PRE_ALLHERE:
if (doomcom.numnodes == 0)
{
int node;
packet.numnodes = packet.numnodes;
doomcom.numnodes = packet.numnodes + 2;
for (node = 0; node < packet.numnodes; node++)
{
sendaddress[node+2].sin_addr.s_addr = packet.machines[node].address;
sendaddress[node+2].sin_port = packet.machines[node].port;
sendplayer[node+2] = packet.machines[node].player;
// [JC] - fixes problem of games not starting due to
// no address family being assigned to nodes stored in
// sendaddress[] from the All Here packet.
sendaddress[node+2].sin_family = AF_INET;
}
}
Printf ("Received All Here, sending ACK\n");
packet.fake = PRE_FAKE;
packet.message = PRE_ALLHEREACK;
PreSend (&packet, 2, &sendaddress[1]);
break;
case PRE_GO:
Printf ("Go\n");
waiting = false;
break;
case PRE_DISCONNECT:
I_FatalError ("Host cancelled the game");
break;
}
}
}
popterm ();
Printf ("Total players: %d\n", doomcom.numnodes);
doomcom.id = DOOMCOM_ID;
doomcom.numplayers = doomcom.numnodes;
}
//
// I_InitNetwork
//
void I_InitNetwork (void)
{
int i;
char *v;
memset (&doomcom, 0, sizeof(doomcom));
// set up for network
v = Args.CheckValue ("-dup");
if (v)
{
doomcom.ticdup = clamp (atoi (v), 1, MAXTICDUP);
}
else
{
doomcom.ticdup = 1;
}
if (Args.CheckParm ("-extratic"))
doomcom.extratics = 1;
else
doomcom.extratics = 0;
v = Args.CheckValue ("-port");
if (v)
{
DOOMPORT = atoi (v);
Printf ("using alternate port %i\n", DOOMPORT);
}
// parse network game options,
// -net <consoleplayer> <host> <host> ...
// -or-
// player 1: -host <numplayers>
// player x: -join <player 1's address>
if ( (i = Args.CheckParm ("-net")) )
WaitForPlayers (i);
else if ( (i = Args.CheckParm ("-host")) )
HostGame (i);
else if ( (i = Args.CheckParm ("-join")) )
JoinGame (i);
else
{
// single player game
netgame = false;
multiplayer = false;
doomcom.id = DOOMCOM_ID;
doomcom.numplayers = doomcom.numnodes = 1;
doomcom.consoleplayer = 0;
return;
}
}
void I_NetCmd (void)
{
if (doomcom.command == CMD_SEND)
{
netsend ();
}
else if (doomcom.command == CMD_GET)
{
netget ();
}
else
I_Error ("Bad net cmd: %i\n",doomcom.command);
}
#ifdef __WIN32__
char *neterror (void)
{
static char neterr[16];
int code;
switch (code = WSAGetLastError ()) {
case WSAEACCES: return "EACCES";
case WSAEADDRINUSE: return "EADDRINUSE";
case WSAEADDRNOTAVAIL: return "EADDRNOTAVAIL";
case WSAEAFNOSUPPORT: return "EAFNOSUPPORT";
case WSAEALREADY: return "EALREADY";
case WSAECONNABORTED: return "ECONNABORTED";
case WSAECONNREFUSED: return "ECONNREFUSED";
case WSAECONNRESET: return "ECONNRESET";
case WSAEDESTADDRREQ: return "EDESTADDRREQ";
case WSAEFAULT: return "EFAULT";
case WSAEHOSTDOWN: return "EHOSTDOWN";
case WSAEHOSTUNREACH: return "EHOSTUNREACH";
case WSAEINPROGRESS: return "EINPROGRESS";
case WSAEINTR: return "EINTR";
case WSAEINVAL: return "EINVAL";
case WSAEISCONN: return "EISCONN";
case WSAEMFILE: return "EMFILE";
case WSAEMSGSIZE: return "EMSGSIZE";
case WSAENETDOWN: return "ENETDOWN";
case WSAENETRESET: return "ENETRESET";
case WSAENETUNREACH: return "ENETUNREACH";
case WSAENOBUFS: return "ENOBUFS";
case WSAENOPROTOOPT: return "ENOPROTOOPT";
case WSAENOTCONN: return "ENOTCONN";
case WSAENOTSOCK: return "ENOTSOCK";
case WSAEOPNOTSUPP: return "EOPNOTSUPP";
case WSAEPFNOSUPPORT: return "EPFNOSUPPORT";
case WSAEPROCLIM: return "EPROCLIM";
case WSAEPROTONOSUPPORT: return "EPROTONOSUPPORT";
case WSAEPROTOTYPE: return "EPROTOTYPE";
case WSAESHUTDOWN: return "ESHUTDOWN";
case WSAESOCKTNOSUPPORT: return "ESOCKTNOSUPPORT";
case WSAETIMEDOUT: return "ETIMEDOUT";
case WSAEWOULDBLOCK: return "EWOULDBLOCK";
case WSAHOST_NOT_FOUND: return "HOST_NOT_FOUND";
case WSANOTINITIALISED: return "NOTINITIALISED";
case WSANO_DATA: return "NO_DATA";
case WSANO_RECOVERY: return "NO_RECOVERY";
case WSASYSNOTREADY: return "SYSNOTREADY";
case WSATRY_AGAIN: return "TRY_AGAIN";
case WSAVERNOTSUPPORTED: return "VERNOTSUPPORTED";
case WSAEDISCON: return "EDISCON";
default:
sprintf (neterr, "%d", code);
return neterr;
}
}
#endif

View file

@ -1,30 +0,0 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id: i_net.h,v 1.1.1.1 1997/12/28 12:59:02 pekangas Exp $
//
// Copyright (C) 1993-1996 by id Software, Inc.
//
// This source is available for distribution and/or modification
// only under the terms of the DOOM Source Code License as
// published by id Software. All rights reserved.
//
// The source is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
// for more details.
//
// DESCRIPTION:
// System specific network interface stuff.
//
//-----------------------------------------------------------------------------
#ifndef __I_NET_H__
#define __I_NET_H__
// Called by D_DoomMain.
void I_InitNetwork (void);
void I_NetCmd (void);
#endif

View file

@ -1599,6 +1599,7 @@ bool DDrawFB::PaintToWindow ()
PrimarySurf->Blt (&rect, BackSurf, NULL, DDBLT_WAIT, NULL); PrimarySurf->Blt (&rect, BackSurf, NULL, DDBLT_WAIT, NULL);
} }
} }
Buffer = NULL;
LOG ("Did paint to window\n"); LOG ("Did paint to window\n");
} }
return true; return true;

View file

@ -1847,6 +1847,10 @@
/> />
</FileConfiguration> </FileConfiguration>
</File> </File>
<File
RelativePath=".\src\i_net.cpp"
>
</File>
<File <File
RelativePath=".\src\info.cpp" RelativePath=".\src\info.cpp"
> >
@ -4526,6 +4530,10 @@
RelativePath=".\src\i_movie.h" RelativePath=".\src\i_movie.h"
> >
</File> </File>
<File
RelativePath=".\src\i_net.h"
>
</File>
<File <File
RelativePath=".\src\i_video.h" RelativePath=".\src\i_video.h"
> >
@ -5271,46 +5279,6 @@
/> />
</FileConfiguration> </FileConfiguration>
</File> </File>
<File
RelativePath=".\src\win32\i_net.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="&quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; "
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="&quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; "
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="&quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; "
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="&quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; &quot; /I /fmod/api/inc&quot; "
/>
</FileConfiguration>
</File>
<File
RelativePath=".\src\win32\i_net.h"
>
</File>
<File <File
RelativePath=".\src\win32\I_system.cpp" RelativePath=".\src\win32\I_system.cpp"
> >
@ -10080,82 +10048,6 @@
/> />
</FileConfiguration> </FileConfiguration>
</File> </File>
<File
RelativePath=".\src\sdl\i_net.cpp"
>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\src\sdl\i_net.h"
>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCustomBuildTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCustomBuildTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCustomBuildTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
ExcludedFromBuild="true"
>
<Tool
Name="VCCustomBuildTool"
/>
</FileConfiguration>
</File>
<File <File
RelativePath=".\src\sdl\i_system.cpp" RelativePath=".\src\sdl\i_system.cpp"
> >