void C_ArchiveCVars (FConfigFile *f, uint32 filter) { FBaseCVar *cvar = CVars; while (cvar) { if ((cvar->Flags & (CVAR_GLOBALCONFIG|CVAR_ARCHIVE|CVAR_MOD|CVAR_AUTO|CVAR_USERINFO|CVAR_SERVERINFO|CVAR_NOSAVE)) == filter) { UCVarValue val; val = cvar->GetGenericRep (CVAR_String); // [BB] This is ancient code from Skulltag... if ( filter == (CVAR_ARCHIVE|CVAR_USERINFO) ) { char szString[64]; strncpy( szString, val.String, 63 ); szString[63] = 0; V_UnColorizeString( szString, 64 ); f->SetValueForKey (cvar->GetName (), szString); } else f->SetValueForKey (cvar->GetName (), val.String); } cvar = cvar->m_Next; } }
// [BB] Version of V_UnColorizeString that accepts a FString as argument and doesn't need ulMaxStringLength. void V_UnColorizeString( FString &String ) { const int length = static_cast<int> (String.Len()); // [BB] The temporary array is twice as big, because every converted color code // increases the length of the string by one. char *tempCharArray = new char[2*length+1]; // [BB] We only need to copy length chars, because that's length = String.Len(). strncpy( tempCharArray, String.GetChars(), length ); tempCharArray[length] = 0; V_UnColorizeString( tempCharArray, 2*length ); String = tempCharArray; delete[] tempCharArray; }
// [RC] Conforms names to meet standards. void V_CleanPlayerName( char *pszString ) { char *pszStart; char *p; char c; ULONG ulStringLength; ULONG ulTotalLength; ULONG ulNonWhitespace; char szColorlessName[256]; ulStringLength = static_cast<ULONG>(strlen( pszString )); ulTotalLength = 0; ulNonWhitespace = 0; // Start at the beginning of the string. p = pszString; pszStart = pszString; // The name must be longer than three characters. if ( ulStringLength < 3 ) { strcpy( pszString, "Player" ); return; } // Go through and remove the illegal characters. while ( (c = *p++) ) { if ( !v_IsCharAcceptableInNames(c) ) { ULONG ulPos; ulStringLength = static_cast<ULONG>(strlen( pszString )); // Shift the rest of the string back one. for ( ulPos = 0; ulPos < ulStringLength; ulPos++ ) pszString[ulPos] = pszString[ulPos + 1]; // Don't skip a character. p--; } else { pszString++; ulTotalLength++; } } // Cut the string at its new end. *pszString = 0; // [BB] Remove any trailing incomplete escaped color codes. Since we just removed // quite a bit from the string, it's possible that those are there now. // Note: We need to work on pszStart now, by now pszString only contains a pointer // to the end of the string. // [BB] I don't want to implement the trailing crap removement for escaped and // unescaped color codes, so I have to uncolorize, clean and colorize the name here. // Not so efficient, but V_CleanPlayerName is called seldom enough so that this // doesn't matter. FString tempString = pszStart; V_UnColorizeString ( tempString ); V_RemoveTrailingCrapFromFString ( tempString ); // [BB] If the name uses color codes, make sure that it is terminated with "\\c-". // V_RemoveTrailingCrapFromFString removes all trailing color codes including "\\c-". // This is necessary to catch incomplete color codes before the trailing "\\c-". // Hence, we have to re-add "\\c-" here. if ( ( tempString.IndexOf ( "\\c" ) != -1 ) ) { // [BB] In the uncolorized string, color codes need one additional char, take this // into account when checking whether the name is too long. FString tempColorizedString = tempString.GetChars(); V_ColorizeString ( tempColorizedString ); const unsigned int numColorCodes = tempString.Len() - tempColorizedString.Len(); if ( tempString.Len() > MAXPLAYERNAME - 3 + numColorCodes ) { tempString = tempString.Left ( MAXPLAYERNAME - 3 + numColorCodes ); V_RemoveTrailingCrapFromFString ( tempString ); } tempString += "\\c-"; } V_ColorizeString ( tempString ); sprintf ( pszStart, "%s", tempString.GetChars() ); // Determine the name's actual length. strncpy( szColorlessName, pszStart, 256 ); V_RemoveColorCodes( szColorlessName ); p = szColorlessName; ulNonWhitespace = 0; while ( (c = *p++) ) { if ( !v_IsCharacterWhitespace(c) ) ulNonWhitespace++; } // Check the length again, as characters were removed. if ( ulNonWhitespace < 3 ) strcpy( pszStart, "Player" ); }
//***************************************************************************** // BOOL CALLBACK settings_ServerTab_MOTDCallback( HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam ) { switch ( Message ) { case WM_CLOSE: EndDialog( hDlg, -1 ); break; case WM_INITDIALOG: { SendDlgItemMessage( hDlg, IDC_MOTD, EM_SETLIMITTEXT, 512, 0 ); // Initialize the MOTD. We have to turn "\n" into carriage returns. { char szBuffer[512]; char szInputString[512]; char *psz; char *pszString; char c; strncpy( szInputString, g_fsMOTD.GetChars( ), 512 ); szInputString[512-1] = 0; // Nifty little trick to turn "\n" into '\n', while maintaining the "\c" color codes. V_ColorizeString( szInputString ); V_UnColorizeString( szInputString, 256 ); pszString = szInputString; psz = szBuffer; while ( 1 ) { c = *pszString++; if ( c == '\0' ) { *psz = c; break; } if ( c == '\n' ) *psz++ = '\r'; *psz++ = c; } SetDlgItemText( hDlg, IDC_MOTD, szBuffer ); SendDlgItemMessage( hDlg, IDC_MOTD, EM_SETSEL, -1, 0 ); // [RC] Why doesn't this work? } } break; case WM_COMMAND: { switch ( LOWORD( wParam )) { case IDOK: { // MOTD. Zip up those linebreaks into \ns. char szBuffer[1024]; GetDlgItemText( hDlg, IDC_MOTD, szBuffer, 1024 ); { char szString[1024+64]; char *psz; char *pszString; char c; psz = szBuffer; pszString = szString; while ( 1 ) { c = *psz++; if ( c == 0 ) { *pszString = c; break; } else if ( c == '\r' ) { *pszString++ = '\\'; *pszString++ = 'n'; psz++; } else *pszString++ = c; } g_fsMOTD = szString; } } EndDialog( hDlg, -1 ); break; case IDCANCEL: EndDialog( hDlg, -1 ); break; } } break; default: return ( FALSE ); } return ( TRUE ); }