int main(void) { int ID = 0; // ID associated with the person. starts at invalid value char email[100]; // email address of user char *roomSize; // Size of the desired room int month = 0; // month from 1-12. starts at invalid value int day = 0; // day from 1-31. starts at invalid value. int year = 0; // month from 2014 up. starts at invalid value. int useTime[2] = {-1, -1}; // start and end time in 24 hour format. starts at invalid value. int loggedIn = 0; // Whether the user has entered their ID, username bool sub = false; // wilingness to substitute char output[MAX_STRING*10]; // final output of the Request // Enter details to proceed printf("Please log in to proceed. Enter your 6 digit ID: "); while (loggedIn == 0) { ID = getID(); buf[0] = '\0'; // reset buffer getEmail(email); buf[0] = '\0'; // reset buffer loggedIn = logIn(); buf[0] = '\0'; // reset buffer } // Get the year the user would like to book for. printf("Would you like to book for this calendar year? (Y/N): "); while (year == 0) { year = getYear(); buf[0] = '\0'; // reset buffer } // Get the month the user would like to book for. printf("Would you like to book for this month in %i? (Y/N): ", year); while ((month < 1) || (month > 12)) { month = getMonth(year); buf[0] = '\0'; // reset buffer } // Get the day the user would like to book for. Dynamicly change valid days in getDay printf("What day would you like to book for? "); while (day == 0) { day = getDay(month, year); buf[0] = '\0'; // reset buffer } // Get the time the user will use the room. printf("What time would you like to start using the room? (24 hour): "); while (useTime[0] == -1) { getTime(useTime, day, month, year); buf[0] = '\0'; // reset buffer } // Get the room size the user would like to book printf("What is the size of the room you are looking to reserve? (\"small\", \"standard\", or \"very large\"): "); roomSize = getRoomSize(); strcat (roomSize, "\0"); // add end of string character buf[0] = '\0'; // reset buffer printf("Would you be willing to take a larger room if there is no %s room available? (Y/N): ", roomSize); buf[0] = '\0'; // reset buffer fgets(buf, MAX_STRING, stdin); strcat (buf, "\0"); // add end of string character // willingness to substitute if ((buf[0] == 'y') || (buf[0] == 'Y')) { sub = true; } else { while ((buf[0] != 'n') || (buf[0] == 'N')) { printf("\nIncorrect input. Please answer with \'Y\' or \'N\': "); buf[0] = '\0'; // reset buffer fgets(buf, MAX_STRING, stdin); strcat (buf, "\0"); // add end of string character } } printf("\n\nBooking %i (%s) for a %s room on %i/%i/%i from %i to %i...", ID, email, roomSize, month, day, year, useTime[0], useTime[1]); sprintf(output, "%i,%i,%i,%i,%i,%s,%d,%i,%i,%s", month, day, year, useTime[0], useTime[1], roomSize, sub, ID, loggedIn, email); FILE *f = fopen("file.txt", "w"); if (f == NULL) { printf("Error opening file!\n"); exit(1); } // write to file where handler can process it fprintf(f, "%s\n", output); printf("Press enter to continue...\n"); getchar(); return 0; }
void startClient(int sockFd) { /** Start the client side operations. **/ //printf("In startClient.\n"); char sendMsg[MAXLINE], recvMsg[MAXLINE]; int n, retVal; int logout = 0, retry = 0; while(1) { //printf("In startClient\n"); bzero(&recvMsg, MAXLINE); bzero(&sendMsg, MAXLINE); // message from the server if((n = read(sockFd, recvMsg, MAXLINE)) < 0) printError('r'); if(n == 0) printError('t'); printf("\nServer : \n%s\n", recvMsg); //printf("sending response to server\n"); printf("\nClient : \n"); // sending response to server fgets(sendMsg, MAXLINE, stdin); if((n = write(sockFd, sendMsg, MAXLINE)) < 0) printError('w'); if(n == 0) printError('t'); // register if(strcmp("register", sendMsg) == EQUAL) { regis(sockFd); //printf("returned to start client\n"); logout = logIn(sockFd); if(logout) { fputs("\nWrite ./client 127.0.0.1 9876 to reconnect.\n\n", stdout); return; } } else // log in if(strcmp("log in", sendMsg) == EQUAL || strcmp("login", sendMsg) == EQUAL) { logout = logIn(sockFd); if(logout == 1) { fputs("\nWrite ./client 127.0.0.1 9876 to reconnect.\n\n", stdout); return; } } if(logout == -1) { fputs("Something went wrong.\n", stdout); } } }
///============================================================================= void* sm2obj::window::exportThreadFunc(void* Data){ // General settings //bool exportMaterials = (radioUvMapsAtlas->getValue() || radioUvMapsTiles->getValue()); //bool exportAtlas = radioUvMapsAtlas->getValue(); //bool exportObject = true; //bool exportTextures = true; std::string mtlOutputPath = outputFolder + "\\" + blueprintName + ".mtl"; std::string objOutputPath = outputFolder + "\\" + blueprintName + ".obj"; std::string blueprintFolder = starMadeFolder + "\\Blueprints\\" + blueprintName; std::string blockTypesPath = starMadeFolder + "\\data\\config\\BlockTypes.properties"; std::string blockConfigPath = starMadeFolder + "\\data\\config\\BlockConfig.xml"; std::string tempFolder = outputFolder + "\\" + blueprintName + "_TEMP_DELETE_THIS"; std::string textureFolder = starMadeFolder + "\\data\\textures\\block\\Default\\"; int textureSize = 0; int numOfThreads = comboNumOfThreads->getSelected() +1; bool exportAttachments = checkboxExportAttachments->getValue(); bool exportDiffuse = checkboxMatDiffuse->getValue(); bool exportAlpha = checkboxMatAlpha->getValue(); bool exportNormals = (radioMatBumps->getValue() || radioMatNormals->getValue()); bool exportEmissive = checkboxMatEmissive->getValue(); warningMessageFlag = false; // extern in config exportFinished = false; std::vector<threadInfoStruct*> threads; std::string textureExtension; progressStruct guiProgress; switch(comboTextureFormat->getSelected()){ case 0: textureExtension = "png"; break; case 1: textureExtension = "tga"; break; case 2: textureExtension = "bmp"; break; case 3: textureExtension = "tiff"; break; } switch(comboTextureSize->getSelected()){ case 0: textureFolder += "64"; textureSize = 64; break; case 1: textureFolder += "128"; textureSize = 128; break; case 2: textureFolder += "256"; textureSize = 256; break; } ffw::logDebug() << "Exporting object? -> " << (exportObject ? "true" : "False"); ffw::logDebug() << "Exporting textures? -> " << (exportTextures ? "true" : "False"); ffw::logDebug() << "Exporting materials? -> " << (exportMaterials ? "true" : "False"); // Edit GUI labels & progressbars if(exportObject){ labelReadingMeta->setColor(ffw::rgb(0x000000)); labelLoadingChunks->setColor(ffw::rgb(0x000000)); labelGeneratingBlocks->setColor(ffw::rgb(0x000000)); labelCreatingPolys->setColor(ffw::rgb(0x000000)); labelMergingVertices->setColor(ffw::rgb(0x000000)); labelReadingMeta->setValue(L"Reading meta: ..."); labelLoadingChunks->setValue(L"Loading chunks: ..."); labelGeneratingBlocks->setValue(L"Generating blocks: ..."); labelCreatingPolys->setValue(L"Creating polygons: ..."); labelMergingVertices->setValue(L"Merging vertices: ..."); } else { labelReadingMeta->setColor(ffw::rgb(0x777777)); labelLoadingChunks->setColor(ffw::rgb(0x777777)); labelGeneratingBlocks->setColor(ffw::rgb(0x777777)); labelCreatingPolys->setColor(ffw::rgb(0x777777)); labelMergingVertices->setColor(ffw::rgb(0x777777)); labelReadingMeta->setValue(L"Reading meta: X"); labelLoadingChunks->setValue(L"Loading chunks: X"); labelGeneratingBlocks->setValue(L"Generating blocks: X"); labelCreatingPolys->setValue(L"Creating polygons: X"); labelMergingVertices->setValue(L"Merging vertices: X"); } if(exportTextures){ labelExportingTextures->setColor(ffw::rgb(0x000000)); labelExportingTextures->setValue(L"Exporting textures: ..."); } else { labelExportingTextures->setColor(ffw::rgb(0x777777)); labelExportingTextures->setValue(L"Exporting textures: X"); } labelBlockConfig->setColor(ffw::rgb(0x000000)); labelBlockConfig->setValue(L"Block config: ..."); // Output files ffw::file objOutput; ffw::file mtlOutput; // Block config data std::vector<blockTypeStruct> blockTypes; std::vector<blockInfoStruct> blockInfo; // Blueprint output data entityInfoStruct entityRoot; if(exportObject){ // Open MTL file if(exportObject && exportMaterials){ if(!mtlOutput.open(mtlOutputPath, std::ios::out | std::ios::trunc)){ ffw::showModalError(this, L"Error!", L"Can not open output file for writing: " + ffw::utf8ToWstr(mtlOutputPath)); buttonCancel->setLabel(L"Close"); exportFinished = true; return NULL; } else { ffw::logSuccess() << "MTL destination path: " << objOutputPath; } } // Open OBJ file if(exportObject){ if(!objOutput.open(objOutputPath, std::ios::out | std::ios::trunc)){ ffw::showModalError(this, L"Error!", L"Can not open output file for writing: " + ffw::utf8ToWstr(objOutputPath)); buttonCancel->setLabel(L"Close"); exportFinished = true; return NULL; } else { ffw::logSuccess() << "OBJ destination path: " << objOutputPath; } } } labelBlockConfig->setValue(L"Block config: 0/2"); progressBlockConfig->setValue(0); std::cout << "checking... " << exportThreadStop << std::endl; // Check for cancelation if(exportThreadStop){ return NULL; } std::cout << "loading..." << std::endl; // Load block types if(!loadBlockTypes(blockTypes, blockTypesPath)){ ffw::showModalError(this, L"Error!", L"Failed to open block type properties: " + ffw::utf8ToWstr(blockTypesPath)); buttonCancel->setLabel(L"Close"); exportFinished = true; return NULL; } ffw::logSuccess() << "Loaded: " << blockTypes.size() << " block types"; labelBlockConfig->setValue(L"Block config: 1/2"); progressBlockConfig->setValue(50); // Check for cancelation if(exportThreadStop){ return NULL; } // Load block config if(!loadBlockConfig(blockTypes, blockInfo, blockConfigPath)){ ffw::showModalError(this, L"Error!", L"Failed to open block config: " + ffw::utf8ToWstr(blockConfigPath)); buttonCancel->setLabel(L"Close"); exportFinished = true; return NULL; } // Check for cancelation if(exportThreadStop){ return NULL; } ffw::logSuccess() << "Loaded: " << blockInfo.size() << " blocks from config"; labelBlockConfig->setValue(L"Block config: 2/2"); progressBlockConfig->setValue(100); if(exportObject){ labelReadingMeta->setValue(L"Reading meta: 0/1"); progressReadingMeta->setValue(0); // Load meta files if exporting attachments if(exportAttachments){ ffw::logDebug() << "Loading attached ships and turrets..."; if(!recursiveMetaLoader(&entityRoot, blueprintFolder, blueprintName, "")){ ffw::showModalError(this, L"Error!", L"Failed to load meta data! Try to export the ship without attached turrets and ships!"); buttonCancel->setLabel(L"Close"); exportFinished = true; return NULL; } } labelReadingMeta->setValue(L"Reading meta: 1/1"); progressReadingMeta->setValue(100); // Check for cancelation if(exportThreadStop){ return NULL; } // Dump information about ship recursiveMetaDump(&entityRoot, 0); // Create temp folder ffw::createDirectory(tempFolder); // Export chunks to temp folder int fileIndex = 0; guiProgress.label = labelLoadingChunks; guiProgress.progressbar = progressLoadingChunks; guiProgress.total = getTotalEntities(&entityRoot); guiProgress.status = 0; guiProgress.setProgress("Loading chunks"); if(!recursiveChunkLoader(&entityRoot, blueprintFolder, tempFolder, fileIndex, guiProgress, exportThreadStop)){ ffw::showModalError(this, L"Error!", L"Failed to export chunks to temporary folder! The ship might be corrupted or program has no privileges to create temporary files"); buttonCancel->setLabel(L"Close"); exportFinished = true; return NULL; } // Check for cancelation if(exportThreadStop){ return NULL; } // Create thread data for(int i = 0; i < numOfThreads; i++){ threads.push_back(new threadInfoStruct(blockInfo)); threads[i]->thread.bindFunction(&processChunk); } // Export chunks guiProgress.label = labelGeneratingBlocks; guiProgress.progressbar = progressGeneratingBlocks; guiProgress.total = fileIndex; guiProgress.status = 0; guiProgress.setProgress("Generating blocks"); recursiveChunkExport(&entityRoot, tempFolder, threads, guiProgress, blockInfo, exportThreadStop); // Delete threads for(int i = 0; i < numOfThreads; i++){ delete threads[i]; } threads.clear(); // Check for cancelation if(exportThreadStop){ return NULL; } // Generate queue std::vector<entityInfoStruct*> entityQueue; generateEntityQueue(&entityRoot, &entityQueue); // Export vertices //progress = 0; uint64_t indicesOffset = 0; uint64_t texPosOffset = 0; chunkBufferStruct* chunkRawBuffer = new chunkBufferStruct; guiProgress.label = labelCreatingPolys; guiProgress.progressbar = progressCreatingPolys; guiProgress.total = entityQueue.size(); guiProgress.status = 0; guiProgress.setProgress("Creating polygons"); for(auto& entity : entityQueue){ chunkRawBuffer->extractedMaterialsList.clear(); for(auto& chunk : entity->chunks){ //progress++; //ffw::logDebug() << "Generating vertices: " << progress << " out of: " << progressTotal; //Args.callbackProgress(progress, progressTotal); // Load a temp block to memory sm2obj::loadRawBlocks(tempFolder, chunkRawBuffer, chunk.fileIndex); // Export block to temp as indices and vertices sm2obj::extractBlocks(tempFolder, chunkRawBuffer, chunk.fileIndex, &indicesOffset, &texPosOffset, exportAtlas, exportMaterials, exportUV, blockInfo); } if(!exportAtlas)texPosOffset += 4; else texPosOffset += chunkRawBuffer->extractedMaterialsList.size()*4; if(exportAtlas){ for(auto i : chunkRawBuffer->extractedMaterialsList)entity->extractedTiles.push_back(i.x); } else { for(auto i : chunkRawBuffer->extractedMaterialsList)entity->extractedMaterials.push_back(i); } guiProgress.status++; guiProgress.setProgress("Creating polygons"); } delete chunkRawBuffer; // Check for cancelation if(exportThreadStop){ return NULL; } // Merge files guiProgress.label = labelMergingVertices; guiProgress.progressbar = progressMergingVertices; guiProgress.total = entityQueue.size(); guiProgress.status = 0; guiProgress.setProgress("Merging vertices"); ffw::logSuccess() << "Merging vertices and indices into a single file..."; objOutput.writeLine("# SM2OBJ"); if(exportMaterials)objOutput.writeLine("mtllib " + blueprintName + ".mtl"); //recursiveVerticesMerge(&entityRoot, tempFolder, &objOutput, !Args.useAtlas, Args.exportUV); for(auto& entity : entityQueue){ mergeVertices(entity, tempFolder, &objOutput, !exportAtlas, exportUV); guiProgress.status++; guiProgress.setProgress("Merging vertices"); } ffw::logSuccess() << "Creating material file..."; // Check for cancelation if(exportThreadStop){ return NULL; } // Export materials if(exportMaterials && exportAtlas){ ffw::logDebug() << "Exporting altas materials"; ffw::logDebug() << "Creating 3 materials..."; createMaterialAtlas(&mtlOutput, true, exportDiffuse, exportAlpha, exportNormals, exportEmissive, textureExtension); } else if(exportMaterials){ ffw::logDebug() << "Exporting block materials"; std::vector<ffw::vec2i> materialList; for(auto& entity : entityQueue){ for(auto& mat :entity->extractedMaterials){ // Find if material is already added bool found = false; for(auto& item : materialList){ if(item == mat){ found = true; break; } } if(found)continue; // Add to list materialList.push_back(mat); } } ffw::logDebug() << "Creating " << materialList.size() << " materials..."; mtlOutput.writeLine("# SM2OBJ\n"); for(auto& mat : materialList){ const blockInfoStruct* block = findBlock(blockInfo, mat.x); if(block == NULL)continue; createMaterialTile(&mtlOutput, block, mat.y, true, exportDiffuse, exportAlpha, exportNormals, exportEmissive, textureExtension); } } // Check for cancelation if(exportThreadStop){ return NULL; } } // Export textures if(exportTextures){ guiProgress.label = labelExportingTextures; guiProgress.progressbar = progressExportingTextures; guiProgress.total = 0; if(exportDiffuse)guiProgress.total++; if(exportAlpha)guiProgress.total++; if(exportEmissive && exportAtlas)guiProgress.total++; if(exportNormals)guiProgress.total++; guiProgress.status = 0; guiProgress.setProgress("Exporting textures"); std::string textureOutputFolder = outputFolder + "\\textures"; ffw::createDirectory(textureOutputFolder); if(exportAtlas){ if(exportDiffuse){ exportDiffuseAtlas(textureFolder + "\\t000.png", textureSize, textureOutputFolder + "\\Atlas_0_diff." + textureExtension); exportDiffuseAtlas(textureFolder + "\\t001.png", textureSize, textureOutputFolder + "\\Atlas_1_diff." + textureExtension); exportDiffuseAtlas(textureFolder + "\\t002.png", textureSize, textureOutputFolder + "\\Atlas_2_diff." + textureExtension); guiProgress.status++; guiProgress.setProgress("Exporting textures"); } // Check for cancelation if(exportThreadStop){ return NULL; } if(exportAlpha){ exportAlphaAtlas(textureFolder + "\\t000.png", textureSize, textureOutputFolder + "\\Atlas_0_alpha." + textureExtension); exportAlphaAtlas(textureFolder + "\\t001.png", textureSize, textureOutputFolder + "\\Atlas_1_alpha." + textureExtension); exportAlphaAtlas(textureFolder + "\\t002.png", textureSize, textureOutputFolder + "\\Atlas_2_alpha." + textureExtension); guiProgress.status++; guiProgress.setProgress("Exporting textures"); } // Check for cancelation if(exportThreadStop){ return NULL; } if(exportEmissive){ exportEmissiveAtlas(blockInfo, textureSize, 0, textureOutputFolder + "\\Atlas_0_emissive." + textureExtension); exportEmissiveAtlas(blockInfo, textureSize, 1, textureOutputFolder + "\\Atlas_1_emissive." + textureExtension); exportEmissiveAtlas(blockInfo, textureSize, 2, textureOutputFolder + "\\Atlas_2_emissive." + textureExtension); guiProgress.status++; guiProgress.setProgress("Exporting textures"); } // Check for cancelation if(exportThreadStop){ return NULL; } if(exportNormals && useBumps){ exportBumpAtlas(textureFolder + "\\t000_NRM.png", textureSize, textureOutputFolder + "\\Atlas_0_bump." + textureExtension); exportBumpAtlas(textureFolder + "\\t001_NRM.png", textureSize, textureOutputFolder + "\\Atlas_1_bump." + textureExtension); exportBumpAtlas(textureFolder + "\\t002_NRM.png", textureSize, textureOutputFolder + "\\Atlas_2_bump." + textureExtension); guiProgress.status++; guiProgress.setProgress("Exporting textures"); } else if(exportNormals){ exportNormalAtlas(textureFolder + "\\t000_NRM.png", textureSize, textureOutputFolder + "\\Atlas_0_bump." + textureExtension); exportNormalAtlas(textureFolder + "\\t001_NRM.png", textureSize, textureOutputFolder + "\\Atlas_1_bump." + textureExtension); exportNormalAtlas(textureFolder + "\\t002_NRM.png", textureSize, textureOutputFolder + "\\Atlas_2_bump." + textureExtension); guiProgress.status++; guiProgress.setProgress("Exporting textures"); } } else { if(exportDiffuse){ exportTileDiffuse(blockInfo, textureFolder, textureSize, textureOutputFolder, textureExtension); guiProgress.status++; guiProgress.setProgress("Exporting textures"); } // Check for cancelation if(exportThreadStop){ return NULL; } if(exportAlpha){ exportTileAlpha(blockInfo, textureFolder, textureSize, textureOutputFolder, textureExtension); guiProgress.status++; guiProgress.setProgress("Exporting textures"); } // Check for cancelation if(exportThreadStop){ return NULL; } if(exportNormals && useBumps){ exportTileBump(blockInfo, textureFolder, textureSize, textureOutputFolder, textureExtension); guiProgress.status++; guiProgress.setProgress("Exporting textures"); } else if(exportNormals){ exportTileNormals(blockInfo, textureFolder, textureSize, textureOutputFolder, textureExtension); guiProgress.status++; guiProgress.setProgress("Exporting textures"); } } } std::fstream logIn(ffw::getExecutablePath() + "\\log.txt", std::ios::in); std::fstream logOut(outputFolder + "\\" + blueprintName + "_log.txt", std::ios::out | std::ios::trunc); if(logIn && logOut){ logOut << logIn.rdbuf(); logIn.close(); logOut.close(); } if(warningMessageFlag) ffw::showModalWarning(this, L"Warning!", L"Blueprint might not be correctly exported! There were some minor errors! Check log file located in exported folder for warning and errors messages!"); else ffw::showModalInfo(this, L"Success!", L"Blueprint exported without any errors nor warnings! Destination folder: " + ffw::utf8ToWstr(outputFolder)); buttonCancel->setLabel(L"Close"); exportFinished = true; return NULL; }