I am trying to get a basic client/server game/demo going. I am using the older GDK from before Nov 2008 and the latest Raknet library. Whenever I try to access the packet data, the program crashes. Oddly, it works if I don't call any other function. It almost like the stack or something is getting corrupted.
#include "DarkGDK.h"
#include <stdio.h>
#include "RakNetworkFactory.h"
#include "RakPeerInterface.h"
#include "MessageIdentifiers.h"
#define MAX_CLIENTS 10
#define SERVER_PORT 60000
RakPeerInterface *peer;
Packet *packet;
void log(char *s1)
{
FILE *fp = fopen("log.txt", "at");
if (fp)
{
fprintf(fp, "%s\n", s1);
fclose(fp);
}
}
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 30 );
dbRandomize ( dbTimer ( ) );
peer = RakNetworkFactory::GetRakPeerInterface();
peer->Startup(MAX_CLIENTS, 30, &SocketDescriptor(SERVER_PORT,0), 1);
peer->SetMaximumIncomingConnections(MAX_CLIENTS);
//long dummy;
while (LoopGDK())
{
packet = peer->Receive();
while (packet)
{
switch (packet->data[0]) /// ****** CRASHES HERE *****
{
case ID_REMOTE_DISCONNECTION_NOTIFICATION:
log("Another client has disconnected.");
break;
case ID_REMOTE_CONNECTION_LOST:
log("Another client has lost the connection.");
break;
case ID_REMOTE_NEW_INCOMING_CONNECTION:
log("Another client has connected.");
break;
case ID_CONNECTION_REQUEST_ACCEPTED:
log("Our connection request has been accepted.");
break;
case ID_NEW_INCOMING_CONNECTION:
log("A connection is incoming...");
break;
case ID_NO_FREE_INCOMING_CONNECTIONS:
log("The server is full.");
break;
case ID_DISCONNECTION_NOTIFICATION:
log("A client has disconnected.");
break;
case ID_CONNECTION_LOST:
log("A client lost the connection.");
break;
default:
log("Message with identifier X has arrived.");
break;
}
peer->DeallocatePacket(packet);
packet = peer->Receive();
}
dbSync();
}
RakNetworkFactory::DestroyRakPeerInterface(peer);
}
Keep in mind I simplified the code to make it easier to read and track down the bug. If I comment out all the log() function calls then it works fine. Any function call screws it up so I know it not my log() or any other packet processing code.
This code works fine if I take Dark GDK out and make the program a console mode exe.
Thanks for the help.
<a href=www.rpgwo.com>RPG World Online</a>