bool MEmblemMgr::CreateCache() { TCHAR szEmblemPath[MAX_PATH]=""; TCHAR szPath[MAX_PATH]=""; if(GetMyDocumentsPath(szPath)) { strcpy_safe(szEmblemPath, szPath); strcat_safe(szEmblemPath, GUNZ_FOLDER); CreatePath(szEmblemPath); strcat_safe(szEmblemPath, MPATH_EMBLEMFOLDER); CreatePath(szEmblemPath); strcat_safe(szEmblemPath, MPATH_EMBLEMFILE); } else { return false; } MXmlDocument xmlDoc; xmlDoc.Create(); bool bResult = xmlDoc.SaveToFile(szEmblemPath); xmlDoc.Destroy(); return bResult; }
/************************************************************************ * int room_index Identifies the room to add connection(s) to. * char* rooms[] Array of room names, each to correspond to a file. * int connections Total number of connections the room * identified by room_index should have. ***********************************************************************/ void initRoom(int room_index, char* rooms[], int connections, char* directory ) { char *room_name = rooms[room_index]; FILE *file_p = NULL; // need to open in directory, so craft the string here char room_dir[100] = ""; strcat_safe( room_dir, 100, directory ); strcat_safe( room_dir, 100, "/" ); strcat_safe( room_dir, 100, rooms[room_index] ); file_p = fopen( room_dir, "a+" ); // Check for successful file opening. if ( ! file_p ) { printf( "Error opening file in function initRoom!\n" ); exit( 1 ); } int connections_in_file = countConnections( file_p ); int connections_to_make = connections - connections_in_file; while ( connections_to_make > 0 ) { int rand_index = randInRange( 0, 6 ); if ( makeConnection( room_index, rand_index, rooms, directory, file_p ) ) { connections_to_make--; } } fclose(file_p); }
/************************************************************* * Call this function at the very end, but we can still use * the files because we know room type by rooms array position ************************************************************/ void addRoomTypes( char* rooms[], char* directory ) { char room_dir[100] = ""; FILE *file_p = NULL; int i; for ( i = 0; i < 7; ++i ) { // prepare directory string strcat_safe( room_dir, 100, directory ); strcat_safe( room_dir, 100, "/" ); strcat_safe( room_dir, 100, rooms[i] ); // do final writes to file file_p = fopen( room_dir, "a+" ); if (i == 0) { fprintf( file_p, "ROOM TYPE: START_ROOM\n" ); } else if (i < 6) { fprintf( file_p, "ROOM TYPE: MID_ROOM\n" ); } else { fprintf( file_p, "ROOM TYPE: END_ROOM\n" ); } fclose( file_p ); memset( &room_dir[0], 0, sizeof(room_dir) ); } }
void listLocations( char *room, char *directory ) { char other_1[100] = ""; char other_1a[100] = ""; char name[100] = ""; char path[100] = ""; // prepare directory string strcat_safe( path, 100, directory ); strcat_safe( path, 100, "/" ); strcat_safe( path, 100, room ); FILE *file = fopen( path, "a+" ); int connections = countConnections( file ) - 1; // countConnections actually counts the number of lines in file - 1 fseek( file, 0, SEEK_SET ); int count = 0; printf( "POSSIBLE CONNECTIONS: " ); while( fscanf( file, "%s %s %s\n", other_1, other_1a, name ) == 3 ) { if ( ! strcmp( other_1, "CONNECTION" ) ) { printf( "%s", name ); if (count + 1 < connections) printf( ", " ); count++; } } printf( ".\n" ); fclose( file ); }
bool MEmblemMgr::InitDefaut() { if(GetMyDocumentsPath(m_szEmblemBaseDir)) { // EmblemBaseFolder strcat_safe(m_szEmblemBaseDir, GUNZ_FOLDER); strcat_safe(m_szEmblemBaseDir, MPATH_EMBLEMFOLDER); // EmblemDataFile strcpy_safe(m_szEmblemDataFile, m_szEmblemBaseDir); strcat_safe(m_szEmblemDataFile, MPATH_EMBLEMFILE); return true; } else { return false; } }
bool RWFile::open(const char* path, ExistingFileAction efa) { if (efa.Value == Nonexistent.Value && Exists(path)) { state.error = true; return false; } char mode_string[8]; auto base_string = [&] { switch (efa.Value) { case Nonexistent.Value: case Clear.Value: return "w+"; case Append.Value: return "a+"; case Prepend.Value: // "r+" will fail if the file doesn't exist. return Exists(path) ? "r+" : "w+"; } assert(false); return "r+"; }(); strcpy_safe(mode_string, base_string); if (!efa.Text) strcat_safe(mode_string, "b"); return open_impl(path, mode_string); }
/****************************************************************************** * Checks to see whether the two rooms identified by index are the same, * and returns 0 if they are (avoiding a room making a connection to itself). * * If the two rooms identified are different, a connection will be made * between them unless the connection already exists. *****************************************************************************/ int makeConnection( int first, int second, char* rooms[], char* directory, FILE* first_room_file ) { if ( first == second ) return 0; // get room names char *first_room = rooms[first]; char *second_room = rooms[second]; // reserve room for file path strings char second_dir[100] = ""; strcat_safe( second_dir, 100, directory ); strcat_safe( second_dir, 100, "/" ); strcat_safe( second_dir, 100, second_room ); // Open room files for reading and writing FILE *second_room_file = fopen( second_dir, "a+" ); if ( ! ( first_room_file && second_room_file ) ) { printf( "in makeConnection: second_dir: %s\n", second_dir ); printf( "Error opening file in function makeConnection\n" ); exit( 1 ); } if ( connectionExists( first_room_file, second_room_file, first_room, second_room ) ) { return 1; } int c1 = countConnections( first_room_file ) + 1; int c2 = countConnections( second_room_file ) + 1; fprintf( first_room_file, "CONNECTION %d: %s\n", c1, second_room ); fprintf( second_room_file,"CONNECTION %d: %s\n", c2, first_room ); // Close only the file this function opened fclose( second_room_file ); return 1; }
void AddStr(const char* pFormat,...) { va_list args; char temp[1024]; va_start(args, pFormat); vsprintf_safe(temp, pFormat, args); strcat_safe(log_buffer, temp); va_end(args); }
/****************************************************** * Call this function at the beginning to create all * room files and add the first line to each file. *****************************************************/ void makeRoomFiles( char* rooms[], char* directory ) { char room_dir[100] = ""; FILE *file_p = NULL; int i; for ( i = 0; i < 7; ++i ) { // prepare directory string strcat_safe( room_dir, 100, directory ); strcat_safe( room_dir, 100, "/" ); strcat_safe( room_dir, 100, rooms[i] ); // do initial writes to file file_p = fopen( room_dir, "a+" ); fprintf( file_p, "ROOM NAME: %s\n", rooms[i] ); fclose( file_p ); memset( &room_dir[0], 0, sizeof(room_dir) ); } }
char* EagleDbTuple_toString(EagleDbTuple *tuple) { char *desc = (char *) EagleMemory_Allocate("EagleDbTuple_toString.1", 1024); int i; if (!desc) return NULL; desc[0] = 0; strcat_safe(desc, "("); for (i = 0; i < EagleDbTable_countColumns(tuple->table); ++i) { if (i > 0) strcat_safe(desc, ","); strcat_safe(desc, EagleDbTable_getColumn(tuple->table, i)->name); strcat_safe(desc, "="); switch (EagleDbTable_getColumn(tuple->table, i)->type) { case EagleDataTypeUnknown: sprintf(desc, "%s?", desc); break; case EagleDataTypeInteger: sprintf(desc, "%s%d", desc, *(((EagleDataTypeIntegerType**) tuple->data)[i])); break; case EagleDataTypeVarchar: sprintf(desc, "%s\"%s\"", desc, ((EagleDataTypeVarcharType*) tuple->data)[i]); break; case EagleDataTypeFloat: sprintf(desc, "%s%g", desc, *(((EagleDataTypeFloatType**) tuple->data)[i])); break; } } strcat_safe(desc, ")"); return desc; }
void ZRoomListBox::OnDraw( MDrawContext* pDC ) { MBitmap* pBitmap; MRECT rect; map<string, MBitmap*>::iterator iter; map<MMATCH_GAMETYPE, MBitmap*>::iterator iterIcon; int pressed_reposition = 0; int index = 0; for( int i = 0; i < NUM_DISPLAY_ROOM; ++i ) { bool bRoomFull = false; if( m_Selection == i ) pressed_reposition = 1; else pressed_reposition = 0; const char* mapName = MGetBannerName( m_pMapInfo[i].map_name); if( m_pMapInfo[i].IsEmpty ) { continue; } rect = GetInitialClientRect(); int width = (int)( m_iGapWidth + ( m_RoomWidth + m_iGapWidth*2 + m_iGapCenter ) * ( index%2 ) ); int height = (int)( m_iGapHeight + ( m_RoomHeight + m_iGapHeight ) * (int)(index*0.5f)); if( m_pMapInfo[i].nPeople >= m_pMapInfo[i].nMaxPeople ) { bRoomFull = true; } iter = find_if( m_pMapImage.begin(), m_pMapImage.end(), string_key_equal<string, MBitmap*>(mapName)); if( iter != m_pMapImage.end() ) { pBitmap = iter->second; if( pBitmap != 0 ) { if( ( m_pMapInfo[i].roomState == GMAE_CLOSED ) || bRoomFull ) pDC->SetBitmapColor(125,125,125,255); else pDC->SetBitmapColor(255,255,255,255); pDC->SetBitmap( pBitmap ); pDC->Draw( width + pressed_reposition, height + pressed_reposition, m_RoomWidth, m_RoomHeight ); } if(m_pRoomFrame!=0) { pDC->SetBitmap(m_pRoomFrame); pDC->Draw(width + pressed_reposition, height + pressed_reposition, m_RoomWidth * 0.75, m_RoomHeight, 0, 0, 512, 32 ); } } char szBuf[128]; MRECT r; r.x = width + m_RoomWidth*0.01f + pressed_reposition; r.y = height + m_RoomHeight*0.1f + pressed_reposition; r.w = m_RoomWidth*0.1; r.h = m_RoomHeight *0.5; sprintf_safe(szBuf,"%03d", m_pMapInfo[i].RoomNumber); pDC->SetFont( MFontManager::Get("FONTc8b") ); pDC->SetColor( 0,0,0); pDC->Text( MRECT( r.x+1, r.y+1, r.w, r.h), szBuf); if( m_pMapInfo[i].roomState == GMAE_CLOSED || bRoomFull ) pDC->SetColor( 115,146,173 ); else pDC->SetColor( 181, 247, 66 ); pDC->Text( r, szBuf ); r.x = width + m_RoomWidth*0.01f + pressed_reposition; r.y = height + m_RoomHeight*0.5f + pressed_reposition; r.w = m_RoomWidth*0.1f; r.h = m_RoomHeight*0.5f; sprintf_safe(szBuf,"%d/%d", m_pMapInfo[i].nPeople, m_pMapInfo[i].nMaxPeople ); pDC->SetColor( 0,0,0); pDC->Text( MRECT( r.x+1, r.y+1, r.w, r.h), szBuf); if( m_pMapInfo[i].roomState == GMAE_CLOSED || bRoomFull ) pDC->SetColor( 115,146,173 ); else pDC->SetColor( 181, 247, 66 ); pDC->Text( r, szBuf ); pDC->SetFont( MFontManager::Get("FONTc8b") ); r.x = width + m_RoomWidth*0.12 + pressed_reposition; r.y = height + pressed_reposition; r.w = m_RoomWidth*0.75; r.h = m_RoomHeight; MFont * pFont = pDC->GetFont(); char szBufTemp[SMI_MAPNAME_LENGTH]; int strLength = 0; int RoomWidth = pFont->GetWidth(m_pMapInfo[i].room_name); if( RoomWidth > m_RoomWidth*0.7 ) { while( strLength < 29 ) { if( m_pMapInfo[i].map_name[strLength] == '0' ) strcpy_safe( szBufTemp, m_pMapInfo[i].room_name ); if( ((unsigned char)m_pMapInfo[i].room_name[strLength]) > 127 ) strLength += 2; else ++strLength; } strncpy_safe( szBufTemp, m_pMapInfo[i].room_name, strLength*sizeof(char) ); szBufTemp[strLength] = '\0'; strcat_safe( szBufTemp, "..." ); pDC->SetColor( 0,0,0); pDC->Text( MRECT( r.x+1, r.y+1, r.w, r.h), szBufTemp, MAM_LEFT); if( m_pMapInfo[i].roomState == GMAE_CLOSED || bRoomFull ) pDC->SetColor( 115,146,173 ); else pDC->SetColor( 255, 255, 255 ); pDC->Text(r, szBufTemp, MAM_LEFT ); } else { pDC->SetColor( 0,0,0); pDC->Text( MRECT( r.x+1, r.y+1, r.w, r.h), m_pMapInfo[i].room_name, MAM_LEFT); if( m_pMapInfo[i].roomState == GMAE_CLOSED || bRoomFull ) pDC->SetColor( 115,146,173 ); else pDC->SetColor( 255, 255, 255 ); pDC->Text(r, m_pMapInfo[i].room_name, MAM_LEFT ); } r.x = width + m_RoomWidth*0.75f + pressed_reposition; r.y = height + pressed_reposition; r.w = m_RoomWidth * 0.2f ; r.h = m_RoomHeight; if( m_pMapInfo[i].bLimitLevel ) { char szBufTemp[64]; sprintf_safe( szBufTemp, "%d~%d", max(m_pMapInfo[i].nMasterLevel - m_pMapInfo[i].nLimitLevel,1), m_pMapInfo[i].nMasterLevel + m_pMapInfo[i].nLimitLevel); pDC->SetColor( 0,0,0); pDC->Text( MRECT( r.x+1, r.y+1, r.w, r.h), szBufTemp); if( m_pMapInfo[i].roomState == GMAE_CLOSED || bRoomFull ) pDC->SetColor( 100, 100, 100 ); else pDC->SetColor( 181, 247, 66 ); pDC->Text( r, szBufTemp ); } if (m_pMapInfo[i].bPrivate) { // 비밀방이면 게임모드 아이콘대신 열쇠아이콘이 나온다. // 열쇠아이콘은 하드코드됨. 나중에 일반화해서 xml로 빼놔야할 듯.. #define FN_ROOMLIST_PRIVATE_KEY "in_key.png" pBitmap = MBitmapManager::Get(FN_ROOMLIST_PRIVATE_KEY); if (pBitmap != NULL) { float x, y; x = width + m_RoomWidth*0.9 + pressed_reposition; y = height + pressed_reposition + ((m_RoomHeight-pBitmap->GetHeight())/2); pDC->SetBitmap( pBitmap ); pDC->Draw(x, y, pBitmap->GetWidth(), pBitmap->GetHeight()); } } else { iterIcon = m_pIconImage.find( m_pMapInfo[i].nGame_Type ); if( iterIcon != m_pIconImage.end() ) { pBitmap = iterIcon->second; if( pBitmap != 0) { r.x = width + m_RoomWidth*0.9 + pressed_reposition; r.y = height + m_RoomHeight/4.7 + pressed_reposition; // 아이콘 if( m_pMapInfo[i].roomState == GMAE_CLOSED || bRoomFull ) { pDC->SetBitmapColor(100,100,100,100); } else { pDC->SetBitmapColor(255,255,255,255); } pDC->SetBitmap( pBitmap ); pDC->Draw(r.x, height + pressed_reposition, m_RoomHeight, m_RoomHeight); } } } // 플레이 중이면 플레이 아이콘을 표시한다. if ( m_pMapInfo[i].roomState == GAME_PLAYING) { // 역시 플레이 아이콘도 하드코딩... -_-; #define FN_ROOMLIST_PLAYICON "icon_play.tga" pBitmap = MBitmapManager::Get( FN_ROOMLIST_PLAYICON); if (pBitmap != NULL) { float x, y; x = width + (m_RoomWidth * 0.955) + pressed_reposition; y = height + (m_RoomHeight * 0.54) + pressed_reposition; pDC->SetBitmap( pBitmap ); pDC->Draw(x, y, (m_RoomHeight * 0.5), (m_RoomHeight * 0.5)); } } //왓구(테두리) if( i == m_Selection) { if( m_pMapInfo[i].roomState == GMAE_CLOSED || bRoomFull) pDC->SetColor(115,146,173); else pDC->SetColor( 181, 247, 66 ); } else pDC->SetColor(128,128,128,255); pDC->Rectangle(width+pressed_reposition, height+pressed_reposition, m_RoomWidth, m_RoomHeight ); ++index; } pDC->SetOpacity( 255 ); pDC->SetBitmapColor(255,255,255,255); }