Bugfix for tracker#: 2985601
- Added checking for NULL pointer as well as clients now check connection state of the server during load.
This commit is contained in:
parent
f7df0fd3d4
commit
4e12d8dbcf
|
@ -190,7 +190,7 @@ void Game::load(){
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//throw runtime_error("Test!");
|
||||
|
||||
//tileset
|
||||
world.loadTileset(config.getPathListForType(ptTilesets,scenarioDir), tilesetName, &checksum);
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Martio Figueroa
|
||||
|
@ -58,9 +57,10 @@ public:
|
|||
}
|
||||
|
||||
static void handleRuntimeError(const char *msg) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,msg);
|
||||
|
||||
Program *program = Program::getInstance();
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] [%s] gameInitialized = %d, program = %p\n",__FILE__,__FUNCTION__,__LINE__,msg,gameInitialized,program);
|
||||
|
||||
if(program && gameInitialized == true) {
|
||||
//SystemFlags::Close();
|
||||
program->showMessage(msg);
|
||||
|
@ -68,6 +68,7 @@ public:
|
|||
else {
|
||||
message("#2 An error ocurred and Glest will close.\nError msg = [" + (msg != NULL ? string(msg) : string("?")) + "]\n\nPlease report this bug to "+mailString+", attaching the generated "+getCrashDumpFileName()+" file.");
|
||||
}
|
||||
showCursor(true);
|
||||
restoreVideoMode(true);
|
||||
//SystemFlags::Close();
|
||||
exit(0);
|
||||
|
@ -85,6 +86,7 @@ public:
|
|||
}
|
||||
|
||||
if(exitApp == true) {
|
||||
showCursor(true);
|
||||
restoreVideoMode(true);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",msg);
|
||||
//SystemFlags::Close();
|
||||
|
@ -306,12 +308,13 @@ int glestMain(int argc, char** argv){
|
|||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
gameInitialized = true;
|
||||
|
||||
// test
|
||||
//Shared::Platform::MessageBox(NULL,"Mark's test.","Test",0);
|
||||
//throw runtime_error("test!");
|
||||
//ExceptionHandler::DisplayMessage("test!", false);
|
||||
|
||||
gameInitialized = true;
|
||||
//main loop
|
||||
while(Window::handleEvent()){
|
||||
program->loop();
|
||||
|
|
|
@ -81,7 +81,8 @@ void Program::ShowMessageProgramState::render() {
|
|||
void Program::ShowMessageProgramState::mouseDownLeft(int x, int y) {
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
if(msgBox.mouseClick(x,y)) {
|
||||
int button= 1;
|
||||
if(msgBox.mouseClick(x,y,button)) {
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
program->exit();
|
||||
|
@ -235,29 +236,36 @@ void Program::resize(SizeState sizeState){
|
|||
|
||||
void Program::setState(ProgramState *programState, bool cleanupOldState)
|
||||
{
|
||||
try {
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
|
||||
if(cleanupOldState == true) {
|
||||
delete this->programState;
|
||||
}
|
||||
|
||||
if(cleanupOldState == true) {
|
||||
delete this->programState;
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
this->programState= programState;
|
||||
programState->load();
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
programState->init();
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
updateTimer.reset();
|
||||
updateCameraTimer.reset();
|
||||
fpsTimer.reset();
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
|
||||
}
|
||||
catch(const exception &e){
|
||||
//exceptionMessage(e);
|
||||
//throw runtime_error(e.what());
|
||||
this->showMessage(e.what());
|
||||
setState(new Intro(this));
|
||||
}
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
this->programState= programState;
|
||||
programState->load();
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
programState->init();
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
updateTimer.reset();
|
||||
updateCameraTimer.reset();
|
||||
fpsTimer.reset();
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
|
||||
}
|
||||
|
||||
void Program::exit() {
|
||||
|
@ -425,7 +433,8 @@ void Program::showMessage(const char *msg) {
|
|||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
showCursor(Config::getInstance().getBool("Windowed"));
|
||||
//showCursor(Config::getInstance().getBool("Windowed"));
|
||||
showCursor(false);
|
||||
|
||||
//MainWindow *mainWindow= new MainWindow(this);
|
||||
init(this->window,false);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Martiño Figueroa
|
||||
// Copyright (C) 2001-2008 Martio Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
|
|
|
@ -422,7 +422,7 @@ void ClientInterface::updateKeyframe(int frameCount)
|
|||
|
||||
void ClientInterface::waitUntilReady(Checksum* checksum)
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
Logger &logger= Logger::getInstance();
|
||||
|
||||
|
@ -436,16 +436,36 @@ void ClientInterface::waitUntilReady(Checksum* checksum)
|
|||
NetworkMessageReady networkMessageReady;
|
||||
sendMessage(&networkMessageReady);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
int64 lastMillisCheck = 0;
|
||||
//wait until we get a ready message from the server
|
||||
while(true)
|
||||
{
|
||||
NetworkMessageType networkMessageType = getNextMessageType(true);
|
||||
if(isConnected() == false) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
string sErr = "Error, Server has disconnected!";
|
||||
sendTextMessage(sErr,-1);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
DisplayErrorMessage(sErr);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
quit= true;
|
||||
close();
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
return;
|
||||
}
|
||||
NetworkMessageType networkMessageType = getNextMessageType(true);
|
||||
if(networkMessageType == nmtReady)
|
||||
{
|
||||
if(receiveMessage(&networkMessageReady))
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -453,12 +473,21 @@ void ClientInterface::waitUntilReady(Checksum* checksum)
|
|||
{
|
||||
if(chrono.getMillis() > readyWaitTimeout)
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//throw runtime_error("Timeout waiting for server");
|
||||
string sErr = "Timeout waiting for server";
|
||||
sendTextMessage(sErr,-1);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
DisplayErrorMessage(sErr);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
quit= true;
|
||||
close();
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
@ -475,11 +504,20 @@ void ClientInterface::waitUntilReady(Checksum* checksum)
|
|||
}
|
||||
else
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//throw runtime_error(string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected network message: " + intToStr(networkMessageType) );
|
||||
sendTextMessage("Unexpected network message: " + intToStr(networkMessageType),-1);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
DisplayErrorMessage(string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected network message: " + intToStr(networkMessageType));
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
quit= true;
|
||||
close();
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -487,19 +525,31 @@ void ClientInterface::waitUntilReady(Checksum* checksum)
|
|||
sleep(waitSleepTime);
|
||||
}
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
//check checksum
|
||||
if(networkMessageReady.getChecksum() != checksum->getSum())
|
||||
//if(1)
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
string sErr = "Checksum error, you don't have the same data as the server";
|
||||
//throw runtime_error("Checksum error, you don't have the same data as the server");
|
||||
sendTextMessage(sErr,-1);
|
||||
if(Config::getInstance().getBool("NetworkConsistencyChecks"))
|
||||
{// error message and disconnect only if checked
|
||||
DisplayErrorMessage(sErr);
|
||||
quit= true;
|
||||
close();
|
||||
}
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
if(Config::getInstance().getBool("NetworkConsistencyChecks")) {
|
||||
// error message and disconnect only if checked
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
DisplayErrorMessage(sErr);
|
||||
|
||||
quit= true;
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,67 +37,69 @@ namespace Glest{ namespace Game{
|
|||
|
||||
bool NetworkMessage::peek(Socket* socket, void* data, int dataSize)
|
||||
{
|
||||
int ipeekdatalen = socket->getDataToRead();
|
||||
|
||||
if(ipeekdatalen >= dataSize)
|
||||
{
|
||||
if(socket->peek(data, dataSize)!=dataSize)
|
||||
if(socket != NULL) {
|
||||
int ipeekdatalen = socket->getDataToRead();
|
||||
if(ipeekdatalen >= dataSize)
|
||||
{
|
||||
if(socket != NULL && socket->getSocketId() > 0)
|
||||
{
|
||||
throw runtime_error("Error peeking NetworkMessage");
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket has been disconnected\n",__FILE__,__FUNCTION__);
|
||||
}
|
||||
if(socket->peek(data, dataSize)!=dataSize)
|
||||
{
|
||||
if(socket != NULL && socket->getSocketId() > 0)
|
||||
{
|
||||
throw runtime_error("Error peeking NetworkMessage");
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d socket has been disconnected\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] dataSize = %d\n",__FILE__,__FUNCTION__,dataSize);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] dataSize = %d\n",__FILE__,__FUNCTION__,dataSize);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket->getDataToRead() returned %d\n",__FILE__,__FUNCTION__,ipeekdatalen);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket->getDataToRead() returned %d\n",__FILE__,__FUNCTION__,ipeekdatalen);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NetworkMessage::receive(Socket* socket, void* data, int dataSize)
|
||||
{
|
||||
int ipeekdatalen = socket->getDataToRead();
|
||||
|
||||
if(ipeekdatalen >= dataSize)
|
||||
{
|
||||
if(socket->receive(data, dataSize)!=dataSize)
|
||||
if(socket != NULL) {
|
||||
int ipeekdatalen = socket->getDataToRead();
|
||||
if(ipeekdatalen >= dataSize)
|
||||
{
|
||||
if(socket != NULL && socket->getSocketId() > 0)
|
||||
{
|
||||
throw runtime_error("Error receiving NetworkMessage");
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket has been disconnected\n",__FILE__,__FUNCTION__);
|
||||
}
|
||||
if(socket->receive(data, dataSize)!=dataSize)
|
||||
{
|
||||
if(socket != NULL && socket->getSocketId() > 0)
|
||||
{
|
||||
throw runtime_error("Error receiving NetworkMessage");
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket has been disconnected\n",__FILE__,__FUNCTION__);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] dataSize = %d\n",__FILE__,__FUNCTION__,dataSize);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] dataSize = %d\n",__FILE__,__FUNCTION__,dataSize);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket->getDataToRead() returned %d\n",__FILE__,__FUNCTION__,ipeekdatalen);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket->getDataToRead() returned %d\n",__FILE__,__FUNCTION__,ipeekdatalen);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void NetworkMessage::send(Socket* socket, const void* data, int dataSize) const
|
||||
{
|
||||
if(socket->send(data, dataSize)!=dataSize)
|
||||
if(socket != NULL && socket->send(data, dataSize)!=dataSize)
|
||||
{
|
||||
if(socket != NULL && socket->getSocketId() > 0)
|
||||
{
|
||||
|
@ -105,7 +107,7 @@ void NetworkMessage::send(Socket* socket, const void* data, int dataSize) const
|
|||
}
|
||||
else
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket has been disconnected\n",__FILE__,__FUNCTION__);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d socket has been disconnected\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue