- switch (m_eState)
- {
- case EBeginStep:
- // timeout: if we don't get an incoming connection fast enough, go back to idle
- if ( g_timer_elapsed( m_pTimer, NULL ) > g_PrefsDlg.m_iTimeout )
- {
- gtk_MessageBox(g_pParentWnd->m_pWidget, "The connection timed out, assuming the BSP process failed\nMake sure you are using a networked version of Q3Map?\nOtherwise you need to disable BSP Monitoring in prefs.", "BSP process monitoring", MB_OK );
- Reset();
- if (m_bBSPPlugin)
- {
- // status == 1 : didn't get the connection
- g_BSPFrontendTable.m_pfnEndListen(1);
- }
- return;
- }
-#ifdef _DEBUG
- // some debug checks
- if (!m_pListenSocket)
- {
- Sys_Printf("ERROR: m_pListenSocket == NULL in CWatchBSP::RoutineProcessing EBeginStep state\n");
- return;
- }
-#endif
- // we are not connected yet, accept any incoming connection
- m_pInSocket = Net_Accept(m_pListenSocket);
- if (m_pInSocket)
- {
- Sys_Printf("Connected.\n");
- // prepare the message info struct for diving in
- memset (&m_message_info, 0, sizeof(message_info_s));
- // a dumb flag to make sure we init the push parser context when first getting a msg
- m_bNeedCtxtInit = true;
- m_eState = EWatching;
- }
- break;
- case EWatching:
-#ifdef _DEBUG
- // some debug checks
- if (!m_pInSocket)
- {
- Sys_Printf("ERROR: m_pInSocket == NULL in CWatchBSP::RoutineProcessing EWatching state\n");
- return;
- }
-#endif
- // select() will identify if the socket needs an update
- // if the socket is identified that means there's either a message or the connection has been closed/reset/terminated
- fd_set readfds;
- int ret;
- FD_ZERO(&readfds);
- FD_SET(((unsigned int)m_pInSocket->socket), &readfds);
- // from select man page:
- // n is the highest-numbered descriptor in any of the three sets, plus 1
- // (no use on windows)
- ret = select( m_pInSocket->socket + 1, &readfds, NULL, NULL, &tout );
- if (ret == SOCKET_ERROR)
- {
- Sys_Printf("WARNING: SOCKET_ERROR in CWatchBSP::RoutineProcessing\n");
- Sys_Printf("Terminating the connection.\n");
- Reset();
- return;
- }
-#ifdef _DEBUG
- if (ret == -1)
- {
- // we are non-blocking?? we should never get timeout errors
- Sys_Printf("WARNING: unexpected timeout expired in CWatchBSP::Processing\n");
- Sys_Printf("Terminating the connection.\n");
- Reset();
- return;
- }
-#endif
- if (ret == 1)
- {
- // the socket has been identified, there's something (message or disconnection)
- // see if there's anything in input
- ret = Net_Receive( m_pInSocket, &msg );
- if (ret > 0)
- {
- // unsigned int size = msg.size; //++timo just a check
- strcpy (m_xmlBuf, NMSG_ReadString (&msg));
- if (m_bNeedCtxtInit)
- {
- m_xmlParserCtxt = NULL;
- m_xmlParserCtxt = xmlCreatePushParserCtxt (&saxParser, &m_message_info, m_xmlBuf, strlen(m_xmlBuf), NULL);
- if (m_xmlParserCtxt == NULL)
- {
- Sys_FPrintf (SYS_ERR, "Failed to create the XML parser (incoming stream began with: %s)\n", m_xmlBuf);
- Reset();
- }
- m_bNeedCtxtInit = false;
- }
- else
- {
- xmlParseChunk (m_xmlParserCtxt, m_xmlBuf, strlen(m_xmlBuf), 0);
- }
- }
- else
- {
- // error or connection closed/reset
- // NOTE: if we get an error down the XML stream we don't reach here
- Net_Disconnect( m_pInSocket );
- m_pInSocket = NULL;
- Sys_Printf("Connection closed.\n");
- if (m_bBSPPlugin)
- {
- Reset();
- // let the BSP plugin know that the job is done
- g_BSPFrontendTable.m_pfnEndListen(0);
- return;
- }
- // move to next step or finish
- m_iCurrentStep++;
- if (m_iCurrentStep < m_pCmd->len )
- {
- DoEBeginStep();
- }
- else
- {
- // release the GPtrArray and the strings
- if (m_pCmd != NULL)
- {
- for (m_iCurrentStep=0; m_iCurrentStep < m_pCmd->len; m_iCurrentStep++ )
- {
- delete[] (char *)g_ptr_array_index( m_pCmd, m_iCurrentStep );
- }
- g_ptr_array_free( m_pCmd, false );
- }
- m_pCmd = NULL;
- // launch the engine .. OMG
- if (g_PrefsDlg.m_bRunQuake)
- {
- // do we enter sleep mode before?
- if (g_PrefsDlg.m_bDoSleep)
- {
- Sys_Printf("Going into sleep mode..\n");
- g_pParentWnd->OnSleep();
- }
- Sys_Printf("Running engine...\n");
- Str cmd;
- // build the command line
- cmd = g_pGameDescription->mEnginePath.GetBuffer();
- // this is game dependant
- //!\todo Read the engine binary name from a config file.
- if (g_pGameDescription->mGameFile == "wolf.game")
- {
- if (!strcmp(ValueForKey(g_qeglobals.d_project_entity, "gamemode"),"mp"))
- {
- // MP
-#if defined(WIN32)
- cmd += "WolfMP.exe";
-#elif defined(__linux__)
- cmd += "wolfmp";
-#elif defined(__APPLE__)
- cmd += "wolfmp.app";
-#else
-#error "WTF are you compiling on"
-#endif
- }
- else
- {
- // SP
-#if defined(WIN32)
- cmd += "WolfSP.exe";
-#elif defined(__linux__)
- cmd += "wolfsp";
-#elif defined(__APPLE__)
- cmd += "wolfsp.app";
-#else
-#error "WTF are you compiling on"
-#endif
- }
- } else if (g_pGameDescription->mGameFile == "et.game")
- {
-#if defined(WIN32)
- cmd += "et.exe";
-#elif defined(__linux__)
- cmd += "et";
-#elif defined(__APPLE__)
- cmd += "et.app";
-#else
-#error "WTF are you compiling on"
-#endif
- }
- // RIANT
- // JK2 HACK
- else if (g_pGameDescription->mGameFile == "jk2.game")
- {
- if (!strcmp(ValueForKey(g_qeglobals.d_project_entity, "gamemode"),"mp"))
- {
- // MP
-#if defined(WIN32)
- cmd += "jk2MP.exe";
-#elif defined(__linux__)
- cmd += "jk2mp";
-#elif defined(__APPLE__)
- cmd += "jk2mp.app";
-#else
-#error "WTF are you compiling on"
-#endif
- }
- else
- {
- // SP
-#if defined(WIN32)
- cmd += "jk2SP.exe";
-#elif defined(__linux__)
- cmd += "jk2sp";
-#elif defined(__APPLE__)
- cmd += "jk2sp.app";