VuMainThread::~VuMainThread() { // KCK Added. Probably a good idea JoinGame(vuPlayerPoolGroup); // must do this prior to destruction of database (below) messageQueue_->DispatchMessages(-1, TRUE); // flush queue delete messageQueue_; messageQueue_ = 0; vuGameList->Unregister(); delete vuGameList; vuGameList = 0; vuTargetList->Unregister(); delete vuTargetList; vuTargetList = 0; VuReferenceEntity(vuGlobalGroup); VuReferenceEntity(vuPlayerPoolGroup); vuDatabase->Purge(); delete vuDatabase; vuDatabase = 0; VuDeReferenceEntity(vuGlobalGroup); VuDeReferenceEntity(vuPlayerPoolGroup); vuGlobalGroup = 0; vuPlayerPoolGroup = 0; delete vuCollectionManager; vuCollectionManager = 0; vuLocalSessionEntity.reset(); vuMainThread = 0; }
void HumanClientApp::HandleMessage(Message& msg) { if (INSTRUMENT_MESSAGE_HANDLING) std::cerr << "HumanClientApp::HandleMessage(" << msg.Type() << ")\n"; switch (msg.Type()) { case Message::ERROR_MSG: m_fsm->process_event(Error(msg)); break; case Message::HOST_MP_GAME: m_fsm->process_event(HostMPGame(msg)); break; case Message::HOST_SP_GAME: m_fsm->process_event(HostSPGame(msg)); break; case Message::JOIN_GAME: m_fsm->process_event(JoinGame(msg)); break; case Message::HOST_ID: m_fsm->process_event(HostID(msg)); break; case Message::LOBBY_UPDATE: m_fsm->process_event(LobbyUpdate(msg)); break; case Message::LOBBY_CHAT: m_fsm->process_event(LobbyChat(msg)); break; case Message::SAVE_GAME_DATA_REQUEST: m_fsm->process_event(SaveGameDataRequest(msg)); break; case Message::GAME_START: m_fsm->process_event(GameStart(msg)); break; case Message::TURN_UPDATE: m_fsm->process_event(TurnUpdate(msg)); break; case Message::TURN_PARTIAL_UPDATE: m_fsm->process_event(TurnPartialUpdate(msg)); break; case Message::TURN_PROGRESS: m_fsm->process_event(TurnProgress(msg)); break; case Message::PLAYER_STATUS: m_fsm->process_event(::PlayerStatus(msg)); break; case Message::PLAYER_CHAT: m_fsm->process_event(PlayerChat(msg)); break; case Message::DIPLOMACY: m_fsm->process_event(Diplomacy(msg)); break; case Message::DIPLOMATIC_STATUS: m_fsm->process_event(DiplomaticStatusUpdate(msg)); break; case Message::END_GAME: m_fsm->process_event(::EndGame(msg)); break; default: ErrorLogger() << "HumanClientApp::HandleMessage : Received an unknown message type \"" << msg.Type() << "\"."; } }
/** ** Parse JOINGAME */ static void ParseJoinGame(Session *session, char *buf) { char *id; char *password; int ret; if (Parse1or2Args(buf, &id, &password)) { Send(session, "ERR_BADPARAMETER\n"); return; } ret = JoinGame(session, atoi(id), password); if (ret == -1) { Send(session, "ERR_ALREADYINGAME\n"); return; } else if (ret == -2) { // ID not found Send(session, "ERR_BADPARAMETER\n"); return; } else if (ret == -3) { if (!password) { Send(session, "ERR_NEEDPASSWORD\n"); } else { Send(session, "ERR_BADPASSWORD\n"); } return; } else if (ret == -4) { Send(session, "ERR_GAMEFULL\n"); return; } DebugPrint("%s joined game %d\n" _C_ session->UserData.Name _C_ atoi(id)); Send(session, "JOINGAME_OK\n"); }
// // I_InitNetwork // // Returns true if packet server mode might be a good idea. // bool I_InitNetwork (void) { int i; const char *v; memset (&doomcom, 0, sizeof(doomcom)); // set up for network v = Args->CheckValue ("-dup"); if (v) { doomcom.ticdup = clamp (atoi (v), 1, MAXTICDUP); } else { doomcom.ticdup = 1; } if (Args->CheckParm ("-extratic")) doomcom.extratics = 1; else doomcom.extratics = 0; v = Args->CheckValue ("-port"); if (v) { DOOMPORT = atoi (v); Printf ("using alternate port %i\n", DOOMPORT); } // parse network game options, // player 1: -host <numplayers> // player x: -join <player 1's address> if ( (i = Args->CheckParm ("-host")) ) { HostGame (i); } else if ( (i = Args->CheckParm ("-join")) ) { JoinGame (i); } else { // single player game netgame = false; multiplayer = false; doomcom.id = DOOMCOM_ID; doomcom.numplayers = doomcom.numnodes = 1; doomcom.consoleplayer = 0; return false; } if (doomcom.numnodes < 3) { // Packet server mode with only two players is effectively the same as // peer-to-peer but with some slightly larger packets. return false; } return doomcom.numnodes > 3 || !NodesOnSameNetwork(); }
void ShowHeroScene::CreateMenu() { auto strings = FileUtils::getInstance()->getValueMapFromFile("fonts/menu.xml"); std::string strBeginGame = strings["BeginGame"].asString(); std::string strCreateGame = strings["CreateGame"].asString(); std::string strJoinGame = strings["JoinGame"].asString(); std::string strExitGame = strings["ExitGame"].asString(); if (/*GameLogic::GetInstance()->IsSingleGame()*/GameLogic::GetInstance()->GetGameType() == SINGLE_GAME_TYPE) { MenuItemLabel* beginGameItem = MenuItemLabel::create(LabelTTF::create(strBeginGame, "Arial", 40), [&](Ref* sender) { BeginGame(); } ); beginGameItem->setPosition(Point(500,100)); auto menu = Menu::create(beginGameItem,NULL); menu->setPosition(Point(0, 0)); addChild(menu); } else { if (/*GameLogic::GetInstance()->IsCreator()*/GameLogic::GetInstance()->GetGameType() == CREATE_GAME_TYPE) { MenuItemLabel* createGameItem = MenuItemLabel::create(LabelTTF::create(strCreateGame, "Arial", 40), [&](Ref* sender) { CreateGame(); } ); createGameItem->setPosition(Point(500,100)); auto menu = Menu::create(createGameItem,NULL); menu->setPosition(Point(0, 0)); addChild(menu); } else { MenuItemLabel* joinGameItem = MenuItemLabel::create(LabelTTF::create(strJoinGame, "Arial", 40), [&](Ref* sender) { JoinGame(); } ); joinGameItem->setPosition(Point(500,100)); auto menu = Menu::create(joinGameItem,NULL); menu->setPosition(Point(0, 0)); addChild(menu); } } }
virtual void PerformAction(const EFriendActionType::Type ActionType) override { switch(ActionType) { case EFriendActionType::AcceptFriendRequest : { AcceptFriend(); break; } case EFriendActionType::RemoveFriend : case EFriendActionType::IgnoreFriendRequest : case EFriendActionType::BlockFriend : case EFriendActionType::RejectFriendRequest: case EFriendActionType::CancelFriendRequest: { RemoveFriend(EFriendActionType::ToText(ActionType).ToString()); break; } case EFriendActionType::SendFriendRequest : { SendFriendRequest(); break; } case EFriendActionType::InviteToGame : { InviteToGame(); break; } case EFriendActionType::JoinGame : { JoinGame(); break; } case EFriendActionType::RejectGame: { RejectGame(); break; } case EFriendActionType::Chat: { StartChat(); break; } } SetPendingAction(EFriendActionType::MAX_None); }
bool CSakiServerEngine::OnAccepted(CAsyncSocket* pVisitor) { auto player = JoinGame(pVisitor); if (player != nullptr) { // Send Hello message to new player { auto msg = SakiSnakeCommon::Msg<SakiSnakeCommon::msgHello, SakiSnakeCommon::HelloMsg>(); msg._data._playerId = player->PlayerId(); msg._data._height = m_board.Height(); msg._data._width = m_board.Width(); msg._data._r = player->Color().r; msg._data._g = player->Color().g; msg._data._b = player->Color().b; player->Send(&msg); } // Send Joined message to everybody for (auto x : m_players) { for (auto y : m_players) { if (y.first != x.second->PlayerId()) { auto msg = SakiSnakeCommon::Msg<SakiSnakeCommon::msgJoined, SakiSnakeCommon::JoinedMsg>(); msg._data._playerId = y.second->PlayerId(); msg._data._r = y.second->Color().r; msg._data._g = y.second->Color().g; msg._data._b = y.second->Color().b; x.second->Send(&msg); } } } BroadcastBoard(); } return (player != nullptr); }
VU_ERRCODE VuMainThread::InitComms ( ComAPIHandle handle, int bufSize, int packSize, ComAPIHandle relhandle, int relBufSize, int relPackSize, int resendQueueSize ) { if ((vuGlobalGroup->GetCommsHandle() != NULL) || (vuPlayerPoolGroup != NULL) || (handle == NULL)){ return VU_ERROR; } if (!relhandle) { relhandle = handle; relBufSize = bufSize; relPackSize = packSize; } // create player pool group(game) vuPlayerPoolGroup = new VuPlayerPoolGame(vuxLocalDomain); vuPlayerPoolGroup->SetSendCreate(VuEntity::VU_SC_DONT_SEND); vuDatabase->Insert(vuPlayerPoolGroup); sendQueue_ = new VuPendingSendQueue(resendQueueSize); //vuLowSendQueue = new VuPendingSendQueue(resendQueueSize); vuGlobalGroup->SetCommsHandle(handle, bufSize, packSize); vuGlobalGroup->SetCommsStatus(VU_CONN_ACTIVE); vuGlobalGroup->SetReliableCommsHandle(relhandle, relBufSize, relPackSize); vuGlobalGroup->SetReliableCommsStatus(VU_CONN_ACTIVE); vuGlobalGroup->SetConnected(TRUE); vuLocalSessionEntity->OpenSession(); return JoinGame(vuPlayerPoolGroup); }
BOOL CALLBACK DlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: { SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER1), TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(4, 10)); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER2), TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(1, 2)); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER3), TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(0, 6)); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER4), TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(0, 6)); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER5), TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(0, 6)); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER6), TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(1, 6)); int nValue; nValue = GetPrivateProfileInt("MoonbaseConsole", "SizeValue", 4, szMoonbaseIniFileG); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER1), TBM_SETPOS, TRUE, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "SizeRandom", FALSE, szMoonbaseIniFileG); CheckDlgButton(hwndDlg, IDC_CHECK1, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "GeneratorValue", 1, szMoonbaseIniFileG); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER2), TBM_SETPOS, TRUE, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "GeneratorRandom", TRUE, szMoonbaseIniFileG); CheckDlgButton(hwndDlg, IDC_CHECK2, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "EnergyValue", 3, szMoonbaseIniFileG); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER3), TBM_SETPOS, TRUE, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "EnergyRandom", TRUE, szMoonbaseIniFileG); CheckDlgButton(hwndDlg, IDC_CHECK3, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "TerrainValue", 3, szMoonbaseIniFileG); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER4), TBM_SETPOS, TRUE, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "TerrainRandom", TRUE, szMoonbaseIniFileG); CheckDlgButton(hwndDlg, IDC_CHECK4, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "WaterValue", 3, szMoonbaseIniFileG); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER5), TBM_SETPOS, TRUE, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "WaterRandom", TRUE, szMoonbaseIniFileG); CheckDlgButton(hwndDlg, IDC_CHECK5, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "TilesetValue", 5, szMoonbaseIniFileG); SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER6), TBM_SETPOS, TRUE, nValue); nValue = GetPrivateProfileInt("MoonbaseConsole", "TilesetRandom", TRUE, szMoonbaseIniFileG); CheckDlgButton(hwndDlg, IDC_CHECK6, nValue); SendMessage(hwndDlg, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIconG); EnableDialog(hwndDlg, true); return TRUE; } case WM_VSCROLL: { if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER1)) CheckDlgButton(hwndDlg, IDC_CHECK1, BST_UNCHECKED); else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER2)) CheckDlgButton(hwndDlg, IDC_CHECK2, BST_UNCHECKED); else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER3)) CheckDlgButton(hwndDlg, IDC_CHECK3, BST_UNCHECKED); else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER4)) CheckDlgButton(hwndDlg, IDC_CHECK4, BST_UNCHECKED); else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER5)) CheckDlgButton(hwndDlg, IDC_CHECK5, BST_UNCHECKED); else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER6)) CheckDlgButton(hwndDlg, IDC_CHECK6, BST_UNCHECKED); return TRUE; } case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_BUTTON1: // Help { HRSRC hrsrc = FindResource(NULL, MAKEINTRESOURCE(IDR_TXT1), "TXT"); HGLOBAL hgbl = LoadResource(NULL, hrsrc); BYTE *pReadme = (BYTE *)LockResource(hgbl); char sz[MAX_PATH]; strcpy(sz, szMoonbasePathG); strcat(sz, "\\MC_README.TXT"); FILE *pf; pf = fopen(sz, "wb"); fwrite(pReadme, 1, SizeofResource(NULL, hrsrc), pf); fclose(pf); ShellExecute(hwndDlg, "open", "MC_README.TXT", NULL, szMoonbasePathG, SW_SHOWNORMAL); return TRUE; } case IDC_BUTTON3: // Credits MessageBox(hwndDlg, "A lot of people helped in one way or the other. Here are the main contributors (in alphabetical order).\n" "\n" "Katton designed and coded the Katton map generation algorithm. He decoded a lot of the tiles and published what he learned. He also coded the algorithm that puts the \"craters\" on the map and wrote the code that generates the map preview showing the options.\n" "\n" "MYCROFT wrote the tools to rip apart the MAP files so they could be deciphered, decoded the rest of the tiles, defined the format that allows the generators to describe the map without caring about tiles, wrote the code to translate the generator output to a useable map, and did the Windows coding.\n" "\n" "SpacemanSpiff designed and coded the Spiff map generation algorithm. He also contributed to deciphering the map file format.\n" "\n" "Special thanks to Bwappo for his contest-winning thumbnail image.\n" "\n" "A number of other people on the Moonbase Commander forums also contributed to map decoding or beta testing including Bwappo, Covak, florent28, Kamolas, llangford, and YorkdinK.\n", "Moonbase Console Credits", MB_OK); return TRUE; case IDC_BTN_HOST_GAME: if (!DialogBoxParam(hInstanceG, MAKEINTRESOURCE(IDD_DIALOG3), hwndDlg, HostDlgProc, 0)) return TRUE; // bail if they cancel // fall through case IDC_SINGLE_GENERATE: { CGameInfo gi; gi.nVersion = GAMENUM_VERSION; if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_CHECK1)) gi.nMapSize = ((rand() % 5) + 4) * 8; // Don't randomly pick nonstandard map sizes. else gi.nMapSize = SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER1), TBM_GETPOS, 0, 0) * 8; if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_CHECK2)) gi.nGenerator = (rand() % 2) + 1; else gi.nGenerator = SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER2), TBM_GETPOS, 0, 0); if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_CHECK6)) gi.nTileset = (rand() % 6) + 1; else gi.nTileset = 7 - SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER6), TBM_GETPOS, 0, 0);; gi.nIP1 = (unsigned char) FIRST_IPADDRESS(dwIPAddressG); gi.nIP2 = (unsigned char) SECOND_IPADDRESS(dwIPAddressG); gi.nIP3 = (unsigned char) THIRD_IPADDRESS(dwIPAddressG); gi.nIP4 = (unsigned char) FOURTH_IPADDRESS(dwIPAddressG); MBCMIF mif; if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_CHECK3)) gi.nEnergy = (rand() % 3) + 2; // Only use [2, 3, 4] of the legal [0, 1, 2, 3, 4, 5, 6] else gi.nEnergy = 6 - SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER3), TBM_GETPOS, 0, 0); if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_CHECK4)) gi.nTerrain = (rand() % 3) + 2; // Only use [2, 3, 4] of the legal [0, 1, 2, 3, 4, 5, 6] else gi.nTerrain = 6 - SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER4), TBM_GETPOS, 0, 0); if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_CHECK5)) gi.nWater = (rand() % 3) + 2; // Only use [2, 3, 4] of the legal [0, 1, 2, 3, 4, 5, 6] else gi.nWater = 6 - SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER5), TBM_GETPOS, 0, 0); gi.nSeed = rand(); // It is critical that the seed get set right before the generate. srand(gi.nSeed); switch (gi.nGenerator) { case SPIFF_GEN: SpiffGenerate(gi, mif); break; case KATTON_GEN: KattonGenerate(gi, mif); break; } try { BackupSystemMapFile();// TODO: Do single player differently. makewiz(gi.nEnergy, gi.nTerrain, gi.nWater); MakeMap(mif, gi); if (LOWORD(wParam) == IDC_SINGLE_GENERATE) { gi.nIP1 = 192; gi.nIP2 = 168; gi.nIP3 = 1; gi.nIP4 = 1; } else { PublishGameNumber(gi, hwndDlg); // Prompt the user, tell them about the game number, and give them a chance to bail. if (IDCANCEL == MessageBox(hwndDlg, "Your random map has been generated.\n\nThe game number for this map needs to be given to the people that you will be playing with.\nThis number is already on the clipboard, paste it into a message to them.\n\nOnce you have done this, press Ok to start Moonbase Commander or Cancel to abort.", "Moonbase Console Message", MB_OKCANCEL)) { RestoreSystemMapFile(); return TRUE; } } HostGame(hwndDlg, gi); } catch (CMapError e) { RestoreSystemMapFile(); char szErrorHeader[80]; char szError[512]; sprintf(szErrorHeader, "Map Generation Error: Please Report This Information"); sprintf(szError, "%s\n\n" "Generator:\t%s\n" "Seed:\t\t%04X\n" "Size:\t\t%d\n" "nEnergy:\t\t%d\n" "nTerrain:\t\t%d\n" "nWater:\t\t%d\n" "\n(%d, %d)\n" "%d %d %d %d\n" " %c %c %c\n" "%d %d %d %d\n" " %c %c %c\n" "%d %d %d %d\n" " %c %c %c\n" "%d %d %d %d\n", e.m_szErrorDescription, (gi.nGenerator == SPIFF_GEN) ? "SpacemanSpiff" : "Katton", (int)gi.nSeed, (int)gi.nMapSize, gi.nEnergy, gi.nTerrain, gi.nWater, e.m_nX, e.m_nY, mif.TTLLCorner(e.m_nX,e.m_nY), mif.TTLCorner(e.m_nX,e.m_nY), mif.TTRCorner(e.m_nX,e.m_nY), mif.TTRRCorner(e.m_nX,e.m_nY), mif.TLCenter(e.m_nX,e.m_nY), mif.TCenter(e.m_nX,e.m_nY), mif.TRCenter(e.m_nX,e.m_nY), mif.TLLCorner(e.m_nX,e.m_nY), mif.TLCorner(e.m_nX,e.m_nY), mif.TRCorner(e.m_nX,e.m_nY), mif.TRRCorner(e.m_nX,e.m_nY), mif.LCenter(e.m_nX,e.m_nY), mif.aaCenterMap[e.m_nX][e.m_nY], mif.RCenter(e.m_nX,e.m_nY), mif.BLLCorner(e.m_nX,e.m_nY), mif.BLCorner(e.m_nX,e.m_nY), mif.BRCorner(e.m_nX,e.m_nY), mif.BRRCorner(e.m_nX,e.m_nY), mif.BLCenter(e.m_nX,e.m_nY), mif.BCenter(e.m_nX,e.m_nY), mif.BRCenter(e.m_nX,e.m_nY), mif.BBLLCorner(e.m_nX,e.m_nY), mif.BBLCorner(e.m_nX,e.m_nY), mif.BBRCorner(e.m_nX,e.m_nY), mif.BBRRCorner(e.m_nX,e.m_nY)); MessageBox(NULL, szError, szErrorHeader, MB_OK); } catch (CGenericError e) { MessageBox(NULL, e.m_szErrorDescription, "Moonbase Console Error", MB_OK); } return TRUE; } case IDC_BUTTON2: { if (!DialogBoxParam(hInstanceG, MAKEINTRESOURCE(IDD_DIALOG2), hwndDlg, JoinDlgProc, 0)) return TRUE; // bail if they cancel MBCMIF mif; // seed the generator srand(giG.nSeed); switch(giG.nGenerator) { case SPIFF_GEN: SpiffGenerate(giG, mif); break; case KATTON_GEN: KattonGenerate(giG, mif); break; } try { BackupSystemMapFile(); makewiz(giG.nEnergy, giG.nTerrain, giG.nWater); MakeMap(mif, giG); } catch (CGenericError e) { RestoreSystemMapFile(); MessageBox(NULL, e.m_szErrorDescription, "Moonbase Console Error", MB_OK); } catch (...) { // Shouldn't get map generation errors here, only valid keys should be coming in. } JoinGame(hwndDlg, giG); return TRUE; } default: return FALSE; } case WM_CLOSE: { char sz[80]; wsprintf(sz, "%d", SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER1), TBM_GETPOS, 0, 0)); WritePrivateProfileString("MoonbaseConsole", "SizeValue", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", IsDlgButtonChecked(hwndDlg, IDC_CHECK1)); WritePrivateProfileString("MoonbaseConsole", "SizeRandom", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER2), TBM_GETPOS, 0, 0)); WritePrivateProfileString("MoonbaseConsole", "GeneratorValue", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", IsDlgButtonChecked(hwndDlg, IDC_CHECK2)); WritePrivateProfileString("MoonbaseConsole", "GeneratorRandom", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER3), TBM_GETPOS, 0, 0)); WritePrivateProfileString("MoonbaseConsole", "EnergyValue", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", IsDlgButtonChecked(hwndDlg, IDC_CHECK3)); WritePrivateProfileString("MoonbaseConsole", "EnergyRandom", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER4), TBM_GETPOS, 0, 0)); WritePrivateProfileString("MoonbaseConsole", "TerrainValue", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", IsDlgButtonChecked(hwndDlg, IDC_CHECK4)); WritePrivateProfileString("MoonbaseConsole", "TerrainRandom", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER5), TBM_GETPOS, 0, 0)); WritePrivateProfileString("MoonbaseConsole", "WaterValue", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", IsDlgButtonChecked(hwndDlg, IDC_CHECK5)); WritePrivateProfileString("MoonbaseConsole", "WaterRandom", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", SendMessage(GetDlgItem(hwndDlg, IDC_SLIDER6), TBM_GETPOS, 0, 0)); WritePrivateProfileString("MoonbaseConsole", "TilesetValue", sz, szMoonbaseIniFileG); wsprintf(sz, "%d", IsDlgButtonChecked(hwndDlg, IDC_CHECK6)); WritePrivateProfileString("MoonbaseConsole", "TilesetRandom", sz, szMoonbaseIniFileG); DestroyWindow(hwndDlg); return TRUE; } case WM_DESTROY: CleanUpMoonbaseINI(); PostQuitMessage(0); return TRUE; } return FALSE; }
int main( int pArgc, const char** pArgs ) { const char* lQueryPtr; int lLock; int lMemId; char lQuery[4096]; char lOp[12]; BOOL lPrintTitle; #ifndef _NO_IPC_ union semun lNULL; #endif #ifdef _NO_IPC_ gGlobalState.Clear(); if( InitLogFile() ) { fprintf( gLogFile, "IMR Init version 0.13.13b %s\n", GetTime( time(NULL)) ); } #endif #ifdef _FAST_CGI_ while( FCGI_Accept() >= 0 ) { #endif lPrintTitle = TRUE; /* Send the header required by the server */ printf("Content-type: text/plain%c%c", 10, 10); lQueryPtr = getenv( "QUERY_STRING" ); if( lQueryPtr == NULL ) { printf( "No parameters\n" ); } else { StrMaxCopy( lQuery, lQueryPtr, 4096 ); UnpadQuery( lQuery ); if( sscanf( lQuery, "=%11s", lOp ) == 1 ) { #ifndef _FAST_CGI_ /* Change the local directory */ char* lPathEnd = strrchr( pArgs[0], '/' ); if( lPathEnd != NULL ) { *lPathEnd = 0; chdir( pArgs[0] ); } #endif if( !strcmp( lOp, "RESET" ) ) { printf( "RESET OK\n\n" ); #ifdef _NO_IPC_ /* // gGlobalState.Clear(); // sleep( 2 ); // return 0; // break; */ #else lLock = semget( IR_SEM_KEY, 1, 0777 ); lMemId = shmget( IR_SHMEM_KEY, sizeof( IRState ), 0666 ); if( lLock != -1 ) { semctl( lLock, 0, IPC_RMID, lNULL ); } if( lMemId != -1 ) { shmctl( lMemId, IPC_RMID, NULL ); } #endif if( InitLogFile() ) { fprintf( gLogFile, "IMR Reset %s\n", GetTime( time(NULL)) ); } #ifdef _FAST_CGI_ break; #endif } else if( !strcmp( lOp, "SET_MESSAGE" ) ) { } /* else if( !strcmp( lOp, "STICK" ) ) { // Fork and leave a child running for 1 hour int lCode = fork(); if( lCode == 0 ) { if( InitLogFile() ) { fprintf( gLogFile, "STICK Start %s\n", GetTime( time(NULL)) ); CloseLogFile(); } close( 0 ); close( 1 ); close( 2 ); sleep( 3600 ); if( InitLogFile() ) { fprintf( gLogFile, "STICK End %s\n", GetTime( time(NULL)) ); CloseLogFile(); } } else if( lCode == -1 ) { printf( "ERROR\n" ); } else { printf( "SUCCESS\n" ); } } */ else { IRState* lState = NULL; #ifdef _NO_IPC_ lState = &gGlobalState; #else int lLock; /* Semaphore */ int lMemId; /* Shared memory */ struct sembuf lSemOp; lSemOp.sem_flg = 0; /*Avoid corruption but must not core-dump SEM_UNDO; // Risky but prevents dead-lock */ lSemOp.sem_num = 0; /* First try to create the structure for the first time */ /* Lock the data struct */ lLock = semget( IR_SEM_KEY, 1, 0777|IPC_CREAT|IPC_EXCL ); if( lLock != -1 ) { union semun lArg; /* Initialize the newly created semaphore */ lArg.val = 1; semctl( lLock, 0, SETVAL, lArg ); } else { lLock = semget( IR_SEM_KEY, 1, 0777 ); } if( lLock == -1 ) { printf( "Unable to get semaphore\n" ); } else { lSemOp.sem_op = -1; if( semop( lLock, &lSemOp, 1 ) == -1 ) { printf( "Unable to decrement semaphore\n" ); lLock = -1; } else { /* From here we can work safely */ lMemId = shmget( IR_SHMEM_KEY, sizeof( IRState ), 0666|IPC_CREAT|IPC_EXCL ); if( lMemId != -1 ) { lState = (IRState*)shmat( lMemId, NULL, 0 ); if( (int)lState == -1 ) { lState = NULL; } if( lState == NULL ) { printf( "Unable to attach shmem\n" ); } else { Clear( lState ); if( InitLogFile() ) { fprintf( gLogFile, "IMR Init %s\n", GetTime( time(NULL)) ); } } } else { lMemId = shmget( IR_SHMEM_KEY, sizeof( IRState ), 0666 ); if( lMemId == -1 ) { printf( "Unable to get shmem\n" ); } else { lState = (IRState*)shmat( lMemId, NULL, 0 ); if( (int)lState == -1 ) { lState = NULL; } if( lState == NULL ) { printf( "Unable to attach shmem\n" ); } } } } } #endif if( lState != NULL ) { lPrintTitle = FALSE; VerifyExpirations( lState ); if( !strcmp( lOp, "REFRESH" ) ) { int lUserIndex; int lUserId; int lTimeStamp; if( sscanf( lQuery, "%*s %d-%u %d", &lUserIndex, &lUserId, &lTimeStamp )==3 ) { PrintStateChange( lState, lUserIndex, lUserId, lTimeStamp ); } } else if( !strcmp( lOp, "ADD_CHAT" ) ) { int lUserIndex; int lUserId; char lChatMessage[200]; if( sscanf( lQuery, "%*s %d-%u %200s", &lUserIndex, &lUserId, lChatMessage )==3 ) { Unpad( lChatMessage ); AddChatMessage( lState, lUserIndex, lUserId, lChatMessage ); } } /* URL?=ADD_USER MAJOR-MINORID VERSION KEY2 KEY3 ALIAS */ else if( !strcmp( lOp, "ADD_USER" ) ) { int lMajorID; int lMinorID; int lVersion; unsigned int lKey2; unsigned int lKey3; char lUserName[40]; #ifdef _EXPIRED_ AddUser( lState, "User", 1,-1, -1, 0, 0 ); #else if( sscanf( lQuery, "%*s %d-%d %d %d %d %40s", &lMajorID, &lMinorID, &lVersion, &lKey2, &lKey3, lUserName )==6 ) { Unpad( lUserName ); AddUser( lState, lUserName, lVersion,lMajorID, lMinorID, lKey2, lKey3 ); } #endif } /* URL?=ADD_GAME USER_ID GAME_NAME TRACK_NAME NBLAP WEAPON PORT */ else if( !strcmp( lOp, "ADD_GAME" ) ) { int lUserIndex; int lUserId; int lNbLap; char lGameName[40]; char lTrackName[40]; int lWeapon; unsigned lPort; if( sscanf( lQuery, "%*s %d-%u %40s %40s %d %d %u", &lUserIndex, &lUserId, lGameName, lTrackName, &lNbLap, &lWeapon, &lPort )==7 ) { const char* lRemoteAddr = getenv( "REMOTE_ADDR" ); if( (lRemoteAddr != NULL)&&(strlen(lRemoteAddr) != 0) ) { Unpad( lTrackName ); Unpad( lGameName ); AddGame( lState, lGameName, lTrackName, lNbLap, lUserIndex, lUserId, lRemoteAddr, lPort, lWeapon ); } } } else if( !strcmp( lOp, "JOIN_GAME" ) ) { int lUserIndex; int lUserId; int lGameIndex; int lGameId; if( sscanf( lQuery, "%*s %d-%u %d-%u", &lGameIndex, &lGameId, &lUserIndex, &lUserId )==4 ) { JoinGame( lState, lGameIndex, lGameId, lUserIndex, lUserId ); } } else if( !strcmp( lOp, "DEL_GAME" ) ) { int lUserIndex; int lUserId; int lGameIndex; int lGameId; if( sscanf( lQuery, "%*s %d-%u %d-%u", &lGameIndex, &lGameId, &lUserIndex, &lUserId )==4 ) { DeleteGame( lState, lGameIndex, lGameId, lUserIndex, lUserId ); } } else if( !strcmp( lOp, "LEAVE_GAME" ) ) { int lUserIndex; int lUserId; int lGameIndex; int lGameId; if( sscanf( lQuery, "%*s %d-%u %d-%u", &lGameIndex, &lGameId, &lUserIndex, &lUserId )==4 ) { LeaveGame( lState, lGameIndex, lGameId, lUserIndex, lUserId ); } } else if( !strcmp( lOp, "DEL_USER" ) ) { int lUserIndex; int lUserId; if( sscanf( lQuery, "%*s %d-%u", &lUserIndex, &lUserId )==2 ) { DeleteUser( lState, lUserIndex, lUserId ); } } else if( !strcmp( lOp, "START_GAME" ) ) { int lUserIndex; int lUserId; int lGameIndex; int lGameId; if( sscanf( lQuery, "%*s %d-%u %d-%u", &lGameIndex, &lGameId, &lUserIndex, &lUserId )==4 ) { StartGame( lState, lGameIndex, lGameId, lUserIndex, lUserId ); } } else { lPrintTitle = TRUE; } } #ifdef _NO_IPC_ lState = NULL; #else /* Release lock */ if( lLock != -1 ) { lSemOp.sem_op = 1; semop( lLock, &lSemOp, 1 ); /* Release memory */ if( lState != NULL ) { shmdt( (char*)lState ); } } #endif } } } CloseLogFile(); if( lPrintTitle ) { printf( "Internet Meeting Room (c)1996,97 GrokkSoft inc.\n" ); } #ifdef _FAST_CGI_ } #endif return 0; }