// ----------------------------------------------------------------------------------------------------------- void write_key_text(FILE *my_file) { int i; int red_count, blue_count, gold_count; int red_count2, blue_count2, gold_count2; int blue_segnum=-1, blue_sidenum=-1, red_segnum=-1, red_sidenum=-1, gold_segnum=-1, gold_sidenum=-1; int connect_side; fprintf(my_file, "-----------------------------------------------------------------------------\n"); fprintf(my_file, "Key stuff:\n"); red_count = 0; blue_count = 0; gold_count = 0; for (i=0; i<Num_walls; i++) { if (Walls[i].keys & KEY_BLUE) { fprintf(my_file, "Wall %i (seg=%i, side=%i) is keyed to the blue key.\n", i, Walls[i].segnum, Walls[i].sidenum); if (blue_segnum == -1) { blue_segnum = Walls[i].segnum; blue_sidenum = Walls[i].sidenum; blue_count++; } else { connect_side = find_connect_side(&Segments[Walls[i].segnum], &Segments[blue_segnum]); if (connect_side != blue_sidenum) { warning_printf(my_file, "Warning: This blue door at seg %i, is different than the one at seg %i, side %i\n", Walls[i].segnum, blue_segnum, blue_sidenum); blue_count++; } } } if (Walls[i].keys & KEY_RED) { fprintf(my_file, "Wall %i (seg=%i, side=%i) is keyed to the red key.\n", i, Walls[i].segnum, Walls[i].sidenum); if (red_segnum == -1) { red_segnum = Walls[i].segnum; red_sidenum = Walls[i].sidenum; red_count++; } else { connect_side = find_connect_side(&Segments[Walls[i].segnum], &Segments[red_segnum]); if (connect_side != red_sidenum) { warning_printf(my_file, "Warning: This red door at seg %i, is different than the one at seg %i, side %i\n", Walls[i].segnum, red_segnum, red_sidenum); red_count++; } } } if (Walls[i].keys & KEY_GOLD) { fprintf(my_file, "Wall %i (seg=%i, side=%i) is keyed to the gold key.\n", i, Walls[i].segnum, Walls[i].sidenum); if (gold_segnum == -1) { gold_segnum = Walls[i].segnum; gold_sidenum = Walls[i].sidenum; gold_count++; } else { connect_side = find_connect_side(&Segments[Walls[i].segnum], &Segments[gold_segnum]); if (connect_side != gold_sidenum) { warning_printf(my_file, "Warning: This gold door at seg %i, is different than the one at seg %i, side %i\n", Walls[i].segnum, gold_segnum, gold_sidenum); gold_count++; } } } } if (blue_count > 1) warning_printf(my_file, "Warning: %i doors are keyed to the blue key.\n", blue_count); if (red_count > 1) warning_printf(my_file, "Warning: %i doors are keyed to the red key.\n", red_count); if (gold_count > 1) warning_printf(my_file, "Warning: %i doors are keyed to the gold key.\n", gold_count); red_count2 = 0; blue_count2 = 0; gold_count2 = 0; for (i=0; i<=Highest_object_index; i++) { if (Objects[i].type == OBJ_POWERUP) if (Objects[i].id == POW_KEY_BLUE) { fprintf(my_file, "The BLUE key is object %i in segment %i\n", i, Objects[i].segnum); blue_count2++; } if (Objects[i].type == OBJ_POWERUP) if (Objects[i].id == POW_KEY_RED) { fprintf(my_file, "The RED key is object %i in segment %i\n", i, Objects[i].segnum); red_count2++; } if (Objects[i].type == OBJ_POWERUP) if (Objects[i].id == POW_KEY_GOLD) { fprintf(my_file, "The GOLD key is object %i in segment %i\n", i, Objects[i].segnum); gold_count2++; } if (Objects[i].contains_count) { if (Objects[i].contains_type == OBJ_POWERUP) { switch (Objects[i].contains_id) { case POW_KEY_BLUE: fprintf(my_file, "The BLUE key is contained in object %i (a %s %s) in segment %i\n", i, Object_type_names[Objects[i].type], Robot_names[Objects[i].id], Objects[i].segnum); blue_count2 += Objects[i].contains_count; break; case POW_KEY_GOLD: fprintf(my_file, "The GOLD key is contained in object %i (a %s %s) in segment %i\n", i, Object_type_names[Objects[i].type], Robot_names[Objects[i].id], Objects[i].segnum); gold_count2 += Objects[i].contains_count; break; case POW_KEY_RED: fprintf(my_file, "The RED key is contained in object %i (a %s %s) in segment %i\n", i, Object_type_names[Objects[i].type], Robot_names[Objects[i].id], Objects[i].segnum); red_count2 += Objects[i].contains_count; break; default: break; } } } } if (blue_count) if (blue_count2 == 0) err_printf(my_file, "Error: There is a door keyed to the blue key, but no blue key!\n"); if (red_count) if (red_count2 == 0) err_printf(my_file, "Error: There is a door keyed to the red key, but no red key!\n"); if (gold_count) if (gold_count2 == 0) err_printf(my_file, "Error: There is a door keyed to the gold key, but no gold key!\n"); if (blue_count2 > 1) err_printf(my_file, "Error: There are %i blue keys!\n", blue_count2); if (red_count2 > 1) err_printf(my_file, "Error: There are %i red keys!\n", red_count2); if (gold_count2 > 1) err_printf(my_file, "Error: There are %i gold keys!\n", gold_count2); }
// // FUNCTION: ServiceStart // // PURPOSE: Actual code of the service // that does the work. // // PARAMETERS: // dwArgc - number of command line arguments // lpszArgv - array of command line arguments // // RETURN VALUE: // none // VOID ServiceStart (DWORD dwArgc, LPTSTR *lpszArgv) { int run_retval = RUN_EXIT; HANDLE stdin_thread = NULL; int iter; // report the status to the service control manager. if (!ReportStatusToSCMgr(SERVICE_START_PENDING, NO_ERROR, 3000)) return; // Load the path to the service executable char szExe[1024]; HMODULE hModule = GetModuleHandle(NULL); if (!GetModuleFileName(hModule, szExe, 1024)) strcpy(szExe, "mpd.exe"); WriteMPDRegistry("path", szExe); // Initialize dbs_init(); ContextInit(); if (!bDebug) { #ifndef _DEBUG // If we are not running in debug mode and this is the release // build then set the error mode to prevent popup message boxes. #ifdef USE_SET_ERROR_MODE SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); #endif #endif easy_socket_init(); ParseRegistry(false); } // report the status to the service control manager. if (!ReportStatusToSCMgr(SERVICE_START_PENDING, NO_ERROR, 3000)) { easy_socket_finalize(); dbs_finalize(); ContextFinalize(); return; } g_hProcessStructMutex = CreateMutex(NULL, FALSE, NULL); g_hForwarderMutex = CreateMutex(NULL, FALSE, NULL); g_hLaunchMutex = CreateMutex(NULL, FALSE, NULL); g_hBarrierStructMutex = CreateMutex(NULL, FALSE, NULL); InitMPDUser(); do { // report the status to the service control manager. if (!ReportStatusToSCMgr(SERVICE_RUNNING, NO_ERROR, 0)) { easy_socket_finalize(); dbs_finalize(); ContextFinalize(); return; } //////////////////////////////////////////////////////// // // Service is now running, perform work until shutdown // AddInfoToMessageLog("MPICH_MPD Daemon service started."); if (stdin_thread == NULL && bDebug) { for (iter=0; iter<CREATE_THREAD_RETRIES; iter++) { stdin_thread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)StdinThread, NULL, 0, NULL); if (stdin_thread != NULL) break; Sleep(CREATE_THREAD_SLEEP_TIME); } if (stdin_thread == NULL) { err_printf("ServiceStart:CreateThread(stdin_thread) failed, error %d\n", GetLastError()); } } __try { run_retval = RUN_RESTART; run_retval = Run(); if (run_retval == RUN_RESTART) { warning_printf("Run returned RUN_RESTART, restarting mpd."); } } __except ( EvalException(GetExceptionInformation()) ) {} RemoveAllContexts(); } while (run_retval == RUN_RESTART); CloseHandle(g_hProcessStructMutex); CloseHandle(g_hForwarderMutex); CloseHandle(g_hLaunchMutex); CloseHandle(g_hBarrierStructMutex); if (stdin_thread != NULL) { TerminateThread(stdin_thread, 0); CloseHandle(stdin_thread); } easy_socket_finalize(); dbs_finalize(); ContextFinalize(); AddInfoToMessageLog("MPICH_MPD Daemon service stopped."); SetEvent(g_hBombDiffuseEvent); if (g_hBombThread != NULL) { if (WaitForSingleObject(g_hBombThread, 5000) == WAIT_TIMEOUT) { TerminateThread(g_hBombThread, 0); } CloseHandle(g_hBombThread); } CloseHandle(g_hBombDiffuseEvent); dbg_printf("ServiceStart: exiting.\n"); }
// ---------------------------------------------------------------------------- void write_key_text(FILE *my_file) { int i; int redCount, blueCount, goldCount; int redCount2, blueCount2, goldCount2; int blue_segnum=-1, blue_sidenum=-1, red_segnum=-1, red_sidenum=-1, gold_segnum=-1, gold_sidenum=-1; int connect_side; fprintf(my_file, "-----------------------------------------------------------------------------\n"); fprintf(my_file, "Key stuff:\n"); redCount = 0; blueCount = 0; goldCount = 0; for (i=0; i<gameData.walls.nWalls; i++) { if (gameData.walls.walls[i].keys & KEY_BLUE) { fprintf(my_file, "Wall %i (seg=%i, tSide=%i) is keyed to the blue key.\n", i, gameData.walls.walls[i].nSegment, gameData.walls.walls[i].nSide); if (blue_segnum == -1) { blue_segnum = gameData.walls.walls[i].nSegment; blue_sidenum = gameData.walls.walls[i].nSide; blueCount++; } else { connect_side = FindConnectedSide(&gameData.segs.segments[gameData.walls.walls[i].nSegment], &gameData.segs.segments[blue_segnum]); if (connect_side != blue_sidenum) { warning_printf(my_file, "Warning: This blue door at seg %i, is different than the one at seg %i, tSide %i\n", gameData.walls.walls[i].nSegment, blue_segnum, blue_sidenum); blueCount++; } } } if (gameData.walls.walls[i].keys & KEY_RED) { fprintf(my_file, "Wall %i (seg=%i, tSide=%i) is keyed to the red key.\n", i, gameData.walls.walls[i].nSegment, gameData.walls.walls[i].nSide); if (red_segnum == -1) { red_segnum = gameData.walls.walls[i].nSegment; red_sidenum = gameData.walls.walls[i].nSide; redCount++; } else { connect_side = FindConnectedSide(&gameData.segs.segments[gameData.walls.walls[i].nSegment], &gameData.segs.segments[red_segnum]); if (connect_side != red_sidenum) { warning_printf(my_file, "Warning: This red door at seg %i, is different than the one at seg %i, tSide %i\n", gameData.walls.walls[i].nSegment, red_segnum, red_sidenum); redCount++; } } } if (gameData.walls.walls[i].keys & KEY_GOLD) { fprintf(my_file, "Wall %i (seg=%i, tSide=%i) is keyed to the gold key.\n", i, gameData.walls.walls[i].nSegment, gameData.walls.walls[i].nSide); if (gold_segnum == -1) { gold_segnum = gameData.walls.walls[i].nSegment; gold_sidenum = gameData.walls.walls[i].nSide; goldCount++; } else { connect_side = FindConnectedSide(&gameData.segs.segments[gameData.walls.walls[i].nSegment], &gameData.segs.segments[gold_segnum]); if (connect_side != gold_sidenum) { warning_printf(my_file, "Warning: This gold door at seg %i, is different than the one at seg %i, tSide %i\n", gameData.walls.walls[i].nSegment, gold_segnum, gold_sidenum); goldCount++; } } } } if (blueCount > 1) warning_printf(my_file, "Warning: %i doors are keyed to the blue key.\n", blueCount); if (redCount > 1) warning_printf(my_file, "Warning: %i doors are keyed to the red key.\n", redCount); if (goldCount > 1) warning_printf(my_file, "Warning: %i doors are keyed to the gold key.\n", goldCount); redCount2 = 0; blueCount2 = 0; goldCount2 = 0; for (i=0; i<=gameData.objs.nLastObject; i++) { if (gameData.objs.objects[i].nType == OBJ_POWERUP) if (gameData.objs.objects[i].id == POW_KEY_BLUE) { fprintf(my_file, "The BLUE key is tObject %i in tSegment %i\n", i, gameData.objs.objects[i].nSegment); blueCount2++; } if (gameData.objs.objects[i].nType == OBJ_POWERUP) if (gameData.objs.objects[i].id == POW_KEY_RED) { fprintf(my_file, "The RED key is tObject %i in tSegment %i\n", i, gameData.objs.objects[i].nSegment); redCount2++; } if (gameData.objs.objects[i].nType == OBJ_POWERUP) if (gameData.objs.objects[i].id == POW_KEY_GOLD) { fprintf(my_file, "The GOLD key is tObject %i in tSegment %i\n", i, gameData.objs.objects[i].nSegment); goldCount2++; } if (gameData.objs.objects[i].containsCount) { if (gameData.objs.objects[i].containsType == OBJ_POWERUP) { switch (gameData.objs.objects[i].containsId) { case POW_KEY_BLUE: fprintf(my_file, "The BLUE key is contained in tObject %i (a %s %s) in tSegment %i\n", i, szObjectTypeNames[gameData.objs.objects[i].nType], gameData.bots.names[gameData.objs.objects[i].id], gameData.objs.objects[i].nSegment); blueCount2 += gameData.objs.objects[i].containsCount; break; case POW_KEY_GOLD: fprintf(my_file, "The GOLD key is contained in tObject %i (a %s %s) in tSegment %i\n", i, szObjectTypeNames[gameData.objs.objects[i].nType], gameData.bots.names[gameData.objs.objects[i].id], gameData.objs.objects[i].nSegment); goldCount2 += gameData.objs.objects[i].containsCount; break; case POW_KEY_RED: fprintf(my_file, "The RED key is contained in tObject %i (a %s %s) in tSegment %i\n", i, szObjectTypeNames[gameData.objs.objects[i].nType], gameData.bots.names[gameData.objs.objects[i].id], gameData.objs.objects[i].nSegment); redCount2 += gameData.objs.objects[i].containsCount; break; default: break; } } } } if (blueCount) if (blueCount2 == 0) err_printf(my_file, "Error: There is a door keyed to the blue key, but no blue key!\n"); if (redCount) if (redCount2 == 0) err_printf(my_file, "Error: There is a door keyed to the red key, but no red key!\n"); if (goldCount) if (goldCount2 == 0) err_printf(my_file, "Error: There is a door keyed to the gold key, but no gold key!\n"); if (blueCount2 > 1) err_printf(my_file, "Error: There are %i blue keys!\n", blueCount2); if (redCount2 > 1) err_printf(my_file, "Error: There are %i red keys!\n", redCount2); if (goldCount2 > 1) err_printf(my_file, "Error: There are %i gold keys!\n", goldCount2); }