Skip to content

Commit

Permalink
Fixed client connecting to a server with a very long greeting message…
Browse files Browse the repository at this point in the history
…. Previously the client would get confused as the first TCP message received from the server would not contain the end marker "END\n", and the client would just stop reading the response.

Network message reception was fixed (broken by revision 4170).

Network debugging messages.
  • Loading branch information
skyjake committed Dec 22, 2006
1 parent 5e8706d commit 61eb35d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
9 changes: 7 additions & 2 deletions doomsday/engine/portable/src/cl_main.c
Expand Up @@ -127,14 +127,19 @@ void Cl_CleanUp()
*/
void Cl_SendHello(void)
{
char buf[16];
char buf[256];

Msg_Begin(PCL_HELLO2);
Msg_WriteLong(clientID);

// The game mode is included in the hello packet.
memset(buf, 0, sizeof(buf));
strncpy(buf, (char *) gx.GetVariable(DD_GAME_MODE), sizeof(buf));
strncpy(buf, (char *) gx.GetVariable(DD_GAME_MODE), sizeof(buf) - 1);

#ifdef _DEBUG
Con_Message("Cl_SendHello: game mode = %s\n", buf);
#endif

Msg_Write(buf, 16);

Net_SendBuffer(0, SPF_ORDERED);
Expand Down
16 changes: 5 additions & 11 deletions doomsday/engine/portable/src/net_buf.c
Expand Up @@ -178,7 +178,7 @@ netmessage_t *N_GetMessage(void)
{
// This is the message we'll return.
netmessage_t *msg = NULL;

N_LockQueue(true);
if(msgHead != NULL)
{
Expand Down Expand Up @@ -347,10 +347,8 @@ uint N_IdentifyPlayer(nodeid_t id)
netmessage_t *N_GetNextMessage(void)
{
netmessage_t *msg;
boolean found;

found = false;
while((msg = N_GetMessage()) != NULL && !found)
while((msg = N_GetMessage()) != NULL)
{
if(msg->player < 0)
{
Expand All @@ -372,14 +370,10 @@ Con_Printf("N_GetNextMessage: Unknown sender, skipped...\n");
N_ReturnBuffer(msg->handle);
msg->handle = NULL;

found = true;
return msg;
}
}

if(found)
return msg;
else
return NULL; // There are no more messages.
return NULL; // There are no more messages.
}

/**
Expand All @@ -405,7 +399,7 @@ boolean N_GetPacket(void)
// No messages at this time.
return false;
}

// There was a packet!
/*
#if _DEBUG
Expand Down
6 changes: 4 additions & 2 deletions doomsday/engine/portable/src/s_main.c
Expand Up @@ -363,11 +363,13 @@ int S_StartSound(int soundId, mobj_t *origin)

/**
* Play a world sound. The sound is sent to all players except the one who
* owns the origin mobj. It is assumed at the owner of the origin has already
* played the sound locally.
* owns the origin mobj. The server assumes that the owner of the origin plays
* the sound locally, which is done here, in the end of S_StartSoundEx().
*
* @param soundId Id of the sound.
* @param origin Origin mobj for the sound.
*
* @return Nonzero if a sound was successfully started.
*/
int S_StartSoundEx(int soundId, mobj_t *origin)
{
Expand Down
7 changes: 5 additions & 2 deletions doomsday/engine/portable/src/sv_main.c
Expand Up @@ -340,15 +340,18 @@ void Sv_HandlePacket(void)
int msgfrom;
char *msg;
char buf[17];

#ifdef _DEBUG
Con_Message("Sv_HandlePacket: type=%i\n", netBuffer.msg.type);
#endif

switch(netBuffer.msg.type)
{
case PCL_HELLO:
case PCL_HELLO2:
// Get the ID of the client.
id = Msg_ReadLong();
Con_Printf("Sv_HandlePacket: Hello from client %i (%08X).\n", from,
id);
Con_Printf("Sv_HandlePacket: Hello from client %i (%08X).\n", from, id);

// Check for duplicate IDs.
if(!pl->ingame && !sender->handshake)
Expand Down
11 changes: 8 additions & 3 deletions doomsday/engine/portable/src/sys_network.c
Expand Up @@ -331,7 +331,7 @@ static int C_DECL N_UDPReceiver(void *parm)
{
SDLNet_SocketSet set;
UDPpacket *packet = NULL;

// Put the UDP socket in our socket set so we can wait for it.
set = SDLNet_AllocSocketSet(1);
SDLNet_UDP_AddSocket(set, inSock);
Expand Down Expand Up @@ -430,7 +430,7 @@ boolean N_ReceiveReliably(nodeid_t from)
UDPpacket *packet = NULL;
int bytes = 0;
boolean error, read;

// TODO: What if we get one byte? How come we are here if there's nothing
// to receive?
if((bytes = SDLNet_TCP_Recv(sock, &size, 2)) != 2)
Expand Down Expand Up @@ -474,6 +474,10 @@ boolean N_ReceiveReliably(nodeid_t from)
msg->data = packet->data;
msg->size = size;
msg->handle = packet;

#ifdef _DEBUG
VERBOSE2(Con_Message("N_ReceiveReliably: Posting message, from=%i, size=%i\n", from, size));
#endif

// The message queue will handle the message from now on.
N_PostMessage(msg);
Expand Down Expand Up @@ -1207,8 +1211,9 @@ boolean N_LookForHosts(const char *address, int port)
{
int result;

if(strstr(Str_Text(response), "END\n"))
if(!strstr(Str_Text(response), "END\n"))
{
memset(buf, 0, sizeof(buf));
result = SDLNet_TCP_Recv(sock, buf, sizeof(buf) - 1);

if(result > 0)
Expand Down

0 comments on commit 61eb35d

Please sign in to comment.