mirror of
https://github.com/glest/glest-source.git
synced 2025-08-12 11:24:00 +02:00
- more thread guards to avoid crashes
This commit is contained in:
@@ -302,14 +302,16 @@ MenuStateCustomGame::~MenuStateCustomGame() {
|
|||||||
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
needToBroadcastServerSettings = false;
|
needToBroadcastServerSettings = false;
|
||||||
needToRepublishToMasterserver = false;
|
needToRepublishToMasterserver = false;
|
||||||
safeMutex.ReleaseLock();
|
|
||||||
|
|
||||||
BaseThread::shutdownAndWait(publishToMasterserverThread);
|
BaseThread::shutdownAndWait(publishToMasterserverThread);
|
||||||
|
safeMutex.ReleaseLock(true);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
safeMutex.Lock();
|
||||||
delete publishToMasterserverThread;
|
delete publishToMasterserverThread;
|
||||||
publishToMasterserverThread = NULL;
|
publishToMasterserverThread = NULL;
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
@@ -318,10 +320,13 @@ void MenuStateCustomGame::returnToParentMenu(){
|
|||||||
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
needToBroadcastServerSettings = false;
|
needToBroadcastServerSettings = false;
|
||||||
needToRepublishToMasterserver = false;
|
needToRepublishToMasterserver = false;
|
||||||
safeMutex.ReleaseLock();
|
|
||||||
|
|
||||||
BaseThread::shutdownAndWait(publishToMasterserverThread);
|
BaseThread::shutdownAndWait(publishToMasterserverThread);
|
||||||
if(parentMenuIsMs) {
|
|
||||||
|
bool returnToMasterServerMenu = parentMenuIsMs;
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
|
if(returnToMasterServerMenu) {
|
||||||
mainMenu->setState(new MenuStateMasterserver(program, mainMenu));
|
mainMenu->setState(new MenuStateMasterserver(program, mainMenu));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -380,7 +385,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
GameSettings gameSettings;
|
GameSettings gameSettings;
|
||||||
loadGameSettings(&gameSettings);
|
loadGameSettings(&gameSettings);
|
||||||
|
|
||||||
@@ -397,11 +402,13 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
needToSetChangedGameSettings = false;
|
needToSetChangedGameSettings = false;
|
||||||
lastSetChangedGameSettings = time(NULL);
|
lastSetChangedGameSettings = time(NULL);
|
||||||
}
|
}
|
||||||
|
safeMutex.ReleaseLock(true);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
bool bOkToStart = serverInterface->launchGame(&gameSettings);
|
bool bOkToStart = serverInterface->launchGame(&gameSettings);
|
||||||
if(bOkToStart == true)
|
if(bOkToStart == true)
|
||||||
{
|
{
|
||||||
|
safeMutex.Lock();
|
||||||
if( listBoxPublishServer.getEditable() &&
|
if( listBoxPublishServer.getEditable() &&
|
||||||
listBoxPublishServer.getSelectedItemIndex() == 0) {
|
listBoxPublishServer.getSelectedItemIndex() == 0) {
|
||||||
|
|
||||||
@@ -419,18 +426,20 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
|
|
||||||
BaseThread::shutdownAndWait(publishToMasterserverThread);
|
BaseThread::shutdownAndWait(publishToMasterserverThread);
|
||||||
|
|
||||||
|
safeMutex.ReleaseLock(true);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
safeMutex.Lock();
|
||||||
delete publishToMasterserverThread;
|
delete publishToMasterserverThread;
|
||||||
publishToMasterserverThread = NULL;
|
publishToMasterserverThread = NULL;
|
||||||
|
safeMutex.ReleaseLock(true);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
assert(program != NULL);
|
assert(program != NULL);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
safeMutex.ReleaseLock();
|
|
||||||
program->setState(new Game(program, &gameSettings));
|
program->setState(new Game(program, &gameSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -600,6 +609,8 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateCustomGame::mouseMove(int x, int y, const MouseState *ms){
|
void MenuStateCustomGame::mouseMove(int x, int y, const MouseState *ms){
|
||||||
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
|
|
||||||
if (mainMessageBox.getEnabled()) {
|
if (mainMessageBox.getEnabled()) {
|
||||||
mainMessageBox.mouseMove(x, y);
|
mainMessageBox.mouseMove(x, y);
|
||||||
}
|
}
|
||||||
@@ -628,12 +639,13 @@ void MenuStateCustomGame::render(){
|
|||||||
try {
|
try {
|
||||||
Renderer &renderer= Renderer::getInstance();
|
Renderer &renderer= Renderer::getInstance();
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
|
|
||||||
if(mainMessageBox.getEnabled()){
|
if(mainMessageBox.getEnabled()){
|
||||||
renderer.renderMessageBox(&mainMessageBox);
|
renderer.renderMessageBox(&mainMessageBox);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
|
||||||
int i;
|
int i;
|
||||||
renderer.renderButton(&buttonReturn);
|
renderer.renderButton(&buttonReturn);
|
||||||
renderer.renderButton(&buttonPlayNow);
|
renderer.renderButton(&buttonPlayNow);
|
||||||
@@ -700,7 +712,7 @@ void MenuStateCustomGame::update()
|
|||||||
|
|
||||||
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
bool masterServerErr = showMasterserverError;
|
bool masterServerErr = showMasterserverError;
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
if(masterServerErr)
|
if(masterServerErr)
|
||||||
{
|
{
|
||||||
safeMutex.Lock();
|
safeMutex.Lock();
|
||||||
@@ -712,7 +724,7 @@ void MenuStateCustomGame::update()
|
|||||||
listBoxPublishServer.setSelectedItemIndex(1);
|
listBoxPublishServer.setSelectedItemIndex(1);
|
||||||
mainMessageBoxState=1;
|
mainMessageBoxState=1;
|
||||||
showMessageBox( masterServererErrorToShow, lang.get("ErrorFromMasterserver"), false);
|
showMessageBox( masterServererErrorToShow, lang.get("ErrorFromMasterserver"), false);
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
@@ -769,7 +781,7 @@ void MenuStateCustomGame::update()
|
|||||||
switchSetupRequests[i]=NULL;
|
switchSetupRequests[i]=NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] mapInfo.players = %d\n",__FILE__,__FUNCTION__,__LINE__,mapInfo.players);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] mapInfo.players = %d\n",__FILE__,__FUNCTION__,__LINE__,mapInfo.players);
|
||||||
|
|
||||||
@@ -875,7 +887,7 @@ void MenuStateCustomGame::update()
|
|||||||
labelNetStatus[i].setText("");
|
labelNetStatus[i].setText("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
@@ -884,7 +896,7 @@ void MenuStateCustomGame::update()
|
|||||||
//haveAtLeastOneNetworkClientConnected == true &&
|
//haveAtLeastOneNetworkClientConnected == true &&
|
||||||
needToSetChangedGameSettings == true &&
|
needToSetChangedGameSettings == true &&
|
||||||
difftime(time(NULL),lastSetChangedGameSettings) >= 2);
|
difftime(time(NULL),lastSetChangedGameSettings) >= 2);
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
|
|
||||||
// Send the game settings to each client if we have at least one networked client
|
// Send the game settings to each client if we have at least one networked client
|
||||||
if(checkDataSynch == true)
|
if(checkDataSynch == true)
|
||||||
@@ -895,7 +907,7 @@ void MenuStateCustomGame::update()
|
|||||||
|
|
||||||
safeMutex.Lock();
|
safeMutex.Lock();
|
||||||
needToSetChangedGameSettings = false;
|
needToSetChangedGameSettings = false;
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
@@ -906,7 +918,7 @@ void MenuStateCustomGame::update()
|
|||||||
//listBoxPublishServer.setSelectedItemIndex(0);
|
//listBoxPublishServer.setSelectedItemIndex(0);
|
||||||
listBoxPublishServer.setEditable(true);
|
listBoxPublishServer.setEditable(true);
|
||||||
listBoxEnableServerControlledAI.setEditable(true);
|
listBoxEnableServerControlledAI.setEditable(true);
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -914,25 +926,25 @@ void MenuStateCustomGame::update()
|
|||||||
listBoxPublishServer.setSelectedItemIndex(1);
|
listBoxPublishServer.setSelectedItemIndex(1);
|
||||||
listBoxPublishServer.setEditable(false);
|
listBoxPublishServer.setEditable(false);
|
||||||
listBoxEnableServerControlledAI.setEditable(false);
|
listBoxEnableServerControlledAI.setEditable(false);
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
safeMutex.Lock();
|
safeMutex.Lock();
|
||||||
bool republishToMaster = (difftime(time(NULL),lastMasterserverPublishing) >= 5);
|
bool republishToMaster = (difftime(time(NULL),lastMasterserverPublishing) >= 5);
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
|
|
||||||
if(republishToMaster == true) {
|
if(republishToMaster == true) {
|
||||||
safeMutex.Lock();
|
safeMutex.Lock();
|
||||||
needToRepublishToMasterserver = true;
|
needToRepublishToMasterserver = true;
|
||||||
lastMasterserverPublishing = time(NULL);
|
lastMasterserverPublishing = time(NULL);
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
safeMutex.Lock();
|
safeMutex.Lock();
|
||||||
bool callPublishNow = (listBoxPublishServer.getEditable() &&
|
bool callPublishNow = (listBoxPublishServer.getEditable() &&
|
||||||
listBoxPublishServer.getSelectedItemIndex() == 0 &&
|
listBoxPublishServer.getSelectedItemIndex() == 0 &&
|
||||||
needToRepublishToMasterserver == true);
|
needToRepublishToMasterserver == true);
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
|
|
||||||
if(callPublishNow == true) {
|
if(callPublishNow == true) {
|
||||||
// give it to me baby, aha aha ...
|
// give it to me baby, aha aha ...
|
||||||
@@ -941,12 +953,12 @@ void MenuStateCustomGame::update()
|
|||||||
|
|
||||||
safeMutex.Lock();
|
safeMutex.Lock();
|
||||||
bool broadCastSettings = (difftime(time(NULL),lastSetChangedGameSettings) >= 2);
|
bool broadCastSettings = (difftime(time(NULL),lastSetChangedGameSettings) >= 2);
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
|
|
||||||
if(broadCastSettings == true) {
|
if(broadCastSettings == true) {
|
||||||
safeMutex.Lock();
|
safeMutex.Lock();
|
||||||
needToBroadcastServerSettings=true;
|
needToBroadcastServerSettings=true;
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//call the chat manager
|
//call the chat manager
|
||||||
@@ -957,13 +969,13 @@ void MenuStateCustomGame::update()
|
|||||||
|
|
||||||
safeMutex.Lock();
|
safeMutex.Lock();
|
||||||
broadCastSettings = (difftime(time(NULL),lastSetChangedGameSettings) >= 2);
|
broadCastSettings = (difftime(time(NULL),lastSetChangedGameSettings) >= 2);
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
|
|
||||||
if(broadCastSettings == true)
|
if(broadCastSettings == true)
|
||||||
{// reset timer here on bottom becasue used for different things
|
{// reset timer here on bottom becasue used for different things
|
||||||
safeMutex.Lock();
|
safeMutex.Lock();
|
||||||
lastSetChangedGameSettings = time(NULL);
|
lastSetChangedGameSettings = time(NULL);
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
}
|
}
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
@@ -1043,7 +1055,7 @@ void MenuStateCustomGame::simpleTask() {
|
|||||||
|
|
||||||
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
bool republish = (needToRepublishToMasterserver == true && publishToServerInfo != "");
|
bool republish = (needToRepublishToMasterserver == true && publishToServerInfo != "");
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
|
|
||||||
if(republish == true) {
|
if(republish == true) {
|
||||||
|
|
||||||
@@ -1051,13 +1063,13 @@ void MenuStateCustomGame::simpleTask() {
|
|||||||
|
|
||||||
safeMutex.Lock();
|
safeMutex.Lock();
|
||||||
needToRepublishToMasterserver = false;
|
needToRepublishToMasterserver = false;
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
|
|
||||||
string request = Config::getInstance().getString("Masterserver") + "addServerInfo.php?" + publishToServerInfo;
|
string request = Config::getInstance().getString("Masterserver") + "addServerInfo.php?" + publishToServerInfo;
|
||||||
|
|
||||||
safeMutex.Lock();
|
safeMutex.Lock();
|
||||||
publishToServerInfo = "";
|
publishToServerInfo = "";
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
|
|
||||||
//printf("the request is:\n%s\n",request.c_str());
|
//printf("the request is:\n%s\n",request.c_str());
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] the request is:\n%s\n",__FILE__,__FUNCTION__,__LINE__,request.c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] the request is:\n%s\n",__FILE__,__FUNCTION__,__LINE__,request.c_str());
|
||||||
@@ -1073,7 +1085,7 @@ void MenuStateCustomGame::simpleTask() {
|
|||||||
safeMutex.Lock();
|
safeMutex.Lock();
|
||||||
showMasterserverError=true;
|
showMasterserverError=true;
|
||||||
masterServererErrorToShow=serverInfo;
|
masterServererErrorToShow=serverInfo;
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1081,7 +1093,7 @@ void MenuStateCustomGame::simpleTask() {
|
|||||||
|
|
||||||
safeMutex.Lock();
|
safeMutex.Lock();
|
||||||
bool broadCastSettings = needToBroadcastServerSettings;
|
bool broadCastSettings = needToBroadcastServerSettings;
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
|
|
||||||
if(broadCastSettings)
|
if(broadCastSettings)
|
||||||
{
|
{
|
||||||
@@ -1089,7 +1101,7 @@ void MenuStateCustomGame::simpleTask() {
|
|||||||
|
|
||||||
safeMutex.Lock();
|
safeMutex.Lock();
|
||||||
needToBroadcastServerSettings=false;
|
needToBroadcastServerSettings=false;
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock(true);
|
||||||
|
|
||||||
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
|
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
|
||||||
if(serverInterface->hasClientConnection() == true) {
|
if(serverInterface->hasClientConnection() == true) {
|
||||||
@@ -1169,7 +1181,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
|
|||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getTech() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getTech().c_str());
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getTech() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getTech().c_str());
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getMap() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getMap().c_str());
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getMap() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getMap().c_str());
|
||||||
|
|
||||||
safeMutex.ReleaseLock(false);
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
@@ -179,11 +179,14 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
|
|||||||
}
|
}
|
||||||
|
|
||||||
MenuStateMasterserver::~MenuStateMasterserver() {
|
MenuStateMasterserver::~MenuStateMasterserver() {
|
||||||
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
clearServerLines();
|
clearServerLines();
|
||||||
|
|
||||||
BaseThread::shutdownAndWait(updateFromMasterserverThread);
|
BaseThread::shutdownAndWait(updateFromMasterserverThread);
|
||||||
delete updateFromMasterserverThread;
|
delete updateFromMasterserverThread;
|
||||||
updateFromMasterserverThread = NULL;
|
updateFromMasterserverThread = NULL;
|
||||||
|
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateMasterserver::clearServerLines(){
|
void MenuStateMasterserver::clearServerLines(){
|
||||||
@@ -210,31 +213,41 @@ void MenuStateMasterserver::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(buttonRefresh.mouseClick(x, y)){
|
else if(buttonRefresh.mouseClick(x, y)){
|
||||||
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
soundRenderer.playFx(coreData.getClickSoundB());
|
soundRenderer.playFx(coreData.getClickSoundB());
|
||||||
//updateServerInfo();
|
//updateServerInfo();
|
||||||
needUpdateFromServer = true;
|
needUpdateFromServer = true;
|
||||||
}
|
}
|
||||||
else if(buttonReturn.mouseClick(x, y)){
|
else if(buttonReturn.mouseClick(x, y)){
|
||||||
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
soundRenderer.playFx(coreData.getClickSoundB());
|
soundRenderer.playFx(coreData.getClickSoundB());
|
||||||
|
|
||||||
BaseThread::shutdownAndWait(updateFromMasterserverThread);
|
BaseThread::shutdownAndWait(updateFromMasterserverThread);
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
mainMenu->setState(new MenuStateRoot(program, mainMenu));
|
mainMenu->setState(new MenuStateRoot(program, mainMenu));
|
||||||
}
|
}
|
||||||
else if(buttonCreateGame.mouseClick(x, y)){
|
else if(buttonCreateGame.mouseClick(x, y)){
|
||||||
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
soundRenderer.playFx(coreData.getClickSoundB());
|
soundRenderer.playFx(coreData.getClickSoundB());
|
||||||
|
|
||||||
BaseThread::shutdownAndWait(updateFromMasterserverThread);
|
BaseThread::shutdownAndWait(updateFromMasterserverThread);
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
mainMenu->setState(new MenuStateCustomGame(program, mainMenu,true,true));
|
mainMenu->setState(new MenuStateCustomGame(program, mainMenu,true,true));
|
||||||
}
|
}
|
||||||
else if(listBoxAutoRefresh.mouseClick(x, y)){
|
else if(listBoxAutoRefresh.mouseClick(x, y)){
|
||||||
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
soundRenderer.playFx(coreData.getClickSoundA());
|
soundRenderer.playFx(coreData.getClickSoundA());
|
||||||
autoRefreshTime=10*listBoxAutoRefresh.getSelectedItemIndex();
|
autoRefreshTime=10*listBoxAutoRefresh.getSelectedItemIndex();
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
for(int i=0; i<serverLines.size(); ++i){
|
for(int i=0; i<serverLines.size(); ++i){
|
||||||
if(serverLines[i]->buttonMouseClick(x, y)){
|
if(serverLines[i]->buttonMouseClick(x, y)){
|
||||||
soundRenderer.playFx(coreData.getClickSoundB());
|
soundRenderer.playFx(coreData.getClickSoundB());
|
||||||
connectToServer(serverLines[i]->getMasterServerInfo()->getIpAddress());
|
string connectServerIP = serverLines[i]->getMasterServerInfo()->getIpAddress();
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
connectToServer(connectServerIP);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -242,6 +255,8 @@ void MenuStateMasterserver::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateMasterserver::mouseMove(int x, int y, const MouseState *ms){
|
void MenuStateMasterserver::mouseMove(int x, int y, const MouseState *ms){
|
||||||
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
|
|
||||||
if (mainMessageBox.getEnabled()) {
|
if (mainMessageBox.getEnabled()) {
|
||||||
mainMessageBox.mouseMove(x, y);
|
mainMessageBox.mouseMove(x, y);
|
||||||
}
|
}
|
||||||
@@ -258,6 +273,7 @@ void MenuStateMasterserver::mouseMove(int x, int y, const MouseState *ms){
|
|||||||
void MenuStateMasterserver::render(){
|
void MenuStateMasterserver::render(){
|
||||||
Renderer &renderer= Renderer::getInstance();
|
Renderer &renderer= Renderer::getInstance();
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
if(mainMessageBox.getEnabled()){
|
if(mainMessageBox.getEnabled()){
|
||||||
renderer.renderMessageBox(&mainMessageBox);
|
renderer.renderMessageBox(&mainMessageBox);
|
||||||
}
|
}
|
||||||
@@ -277,6 +293,7 @@ void MenuStateMasterserver::render(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateMasterserver::update(){
|
void MenuStateMasterserver::update(){
|
||||||
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
if(autoRefreshTime!=0 && difftime(time(NULL),lastRefreshTimer) >= autoRefreshTime ) {
|
if(autoRefreshTime!=0 && difftime(time(NULL),lastRefreshTimer) >= autoRefreshTime ) {
|
||||||
needUpdateFromServer = true;
|
needUpdateFromServer = true;
|
||||||
lastRefreshTimer= time(NULL);
|
lastRefreshTimer= time(NULL);
|
||||||
@@ -299,17 +316,19 @@ void MenuStateMasterserver::update(){
|
|||||||
throw runtime_error(sError.c_str());
|
throw runtime_error(sError.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateMasterserver::simpleTask() {
|
void MenuStateMasterserver::simpleTask() {
|
||||||
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
if(needUpdateFromServer == true) {
|
if(needUpdateFromServer == true) {
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
updateServerInfo();
|
updateServerInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateMasterserver::updateServerInfo() {
|
void MenuStateMasterserver::updateServerInfo() {
|
||||||
try {
|
try {
|
||||||
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
needUpdateFromServer = false;
|
needUpdateFromServer = false;
|
||||||
|
|
||||||
int numberOfOldServerLines=serverLines.size();
|
int numberOfOldServerLines=serverLines.size();
|
||||||
@@ -367,6 +386,7 @@ void MenuStateMasterserver::updateServerInfo() {
|
|||||||
catch(const exception &e){
|
catch(const exception &e){
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d, error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d, error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
threadedErrorMsg = e.what();
|
threadedErrorMsg = e.what();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -376,6 +396,8 @@ void MenuStateMasterserver::connectToServer(string ipString)
|
|||||||
{
|
{
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START ipString='%s'\n",__FILE__,__FUNCTION__,ipString.c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START ipString='%s'\n",__FILE__,__FUNCTION__,ipString.c_str());
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
|
|
||||||
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
||||||
Config& config= Config::getInstance();
|
Config& config= Config::getInstance();
|
||||||
Ip serverIp(ipString);
|
Ip serverIp(ipString);
|
||||||
@@ -404,6 +426,9 @@ void MenuStateMasterserver::connectToServer(string ipString)
|
|||||||
//config.save();
|
//config.save();
|
||||||
|
|
||||||
BaseThread::shutdownAndWait(updateFromMasterserverThread);
|
BaseThread::shutdownAndWait(updateFromMasterserverThread);
|
||||||
|
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
mainMenu->setState(new MenuStateConnectedGame(program, mainMenu,jmMasterserver));
|
mainMenu->setState(new MenuStateConnectedGame(program, mainMenu,jmMasterserver));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -86,6 +86,7 @@ private:
|
|||||||
|
|
||||||
static DisplayMessageFunction pCB_DisplayMessage;
|
static DisplayMessageFunction pCB_DisplayMessage;
|
||||||
std::string threadedErrorMsg;
|
std::string threadedErrorMsg;
|
||||||
|
Mutex masterServerThreadAccessor;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MenuStateMasterserver(Program *program, MainMenu *mainMenu);
|
MenuStateMasterserver(Program *program, MainMenu *mainMenu);
|
||||||
|
@@ -63,13 +63,16 @@ public:
|
|||||||
void clear() { memset(this, 0, sizeof(MouseState)); }
|
void clear() { memset(this, 0, sizeof(MouseState)); }
|
||||||
|
|
||||||
bool get(MouseButton b) const {
|
bool get(MouseButton b) const {
|
||||||
assert(b > 0 && b < mbCount);
|
if(b > 0 && b < mbCount) {
|
||||||
return states[b];
|
return states[b];
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set(MouseButton b, bool state) {
|
void set(MouseButton b, bool state) {
|
||||||
assert(b > 0 && b < mbCount);
|
if(b > 0 && b < mbCount) {
|
||||||
states[b] = state;
|
states[b] = state;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user