sprintf( (char*)temp, "region_%s.bbi", FindCharBySerial(calcserial(msg2Post[4], msg2Post[5], msg2Post[6], msg2Post[7]))->region.latin1() );
;
int MsgBoardGetMaxMsgSN( int msgType, int autoPost=0 ){	FILE        *pFile            = NULL;		// 50 chars for prefix and 4 for the extension plus the ending NULL	char        fileName[256]     = "";	unsigned char        msgbbiSegment[20] = "\x00\x00\x00\x00\x0e\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";	char        maxMsgSN[5]       = "";		int         maxSN             = 0;		struct tm   timeOfPost;	time_t      now;	// If a MSBBOARDPATH has been define in the SERVER.SCP file, then use it	if (!SrvParams->msgboardPath().isEmpty())		strcpy( fileName, SrvParams->msgboardPath().latin1() );		switch ( msgType )	{		// LOCAL post	case LOCALPOST:		// Get Message Board serial number from message buffer		sprintf( (char*)temp, "%02x%02x%02x%02x.bbi", msg2Post[4], msg2Post[5], msg2Post[6], msg2Post[7]);		break;				// REGIONAL post	case REGIONALPOST:		// set the Message Board fileName to the proper region number		if ( autoPost )		{			sprintf( (char*)temp, "region_%s.bbi", FindCharBySerial(calcserial(msg2Post[4], msg2Post[5], msg2Post[6], msg2Post[7]))->region.latin1() );		}		else		{			P_ITEM msgBoard = FindItemBySerial(calcserial(msg2Post[4], msg2Post[5], msg2Post[6], msg2Post[7]));			if( msgBoard == NULL )				break;			cTerritory* Region = cAllTerritories::getInstance()->region( msgBoard->pos.x, msgBoard->pos.y );			if( Region != NULL )				sprintf( (char*)temp, "region_%s.bbi", Region->name().latin1() );		}		break;				// GLOBAL POST	case GLOBALPOST:		strcpy( (char*)temp, "global.bbi" );		break;				// Invalid post type	default:		clConsole.send("WOLFPACK: MsgBoardGetMaxMsgSN() Invalid post type, aborting post\n");		return 0;	}		// Append file name to path	strcat( fileName, (char*)temp );		// Get the current maximum message s/n from the bbi file	pFile = fopen( fileName, "rb" );	if ( pFile == NULL )	{		clConsole.send("WOLFPACK: MsgBoardGetMaxMsgSN() bbi not found. Creating file %s\n", fileName );				// Default to serial number 0		maxSN = 0;	}	else // bbi file exists so read in first 4 bytes to get current maximum serial number	{		// Get the first 4 bytes from each message index segment in the bbi file		if ( fread(maxMsgSN, sizeof(char), 4, pFile) != 4 )		{			clConsole.send("WOLFPACK: MsgBoardGetMaxMsgSN() Could not get MaxSN from %s\n", fileName );						fclose( pFile );			pFile = NULL;			return 0;		}				// Calculate the maxSN in decimal		maxSN = (maxMsgSN[0]<<24) + (maxMsgSN[1]<<16) + (maxMsgSN[2]<<8) + maxMsgSN[3];				// Increment maxSN to new value		maxSN++;	}		// Done retrieving maxMsgSN so close bbi file	if ( pFile )	{		fclose( pFile );		pFile = NULL;	}		// If the maxSN == 0 then the file does not exist yet so create the file	if ( maxSN == 0 )	{		pFile = fopen( fileName, "ab+" );				if ( pFile == NULL )		{			clConsole.send("WOLFPACK: MsgBoardGetMaxMsgSN() Error creating bbi file, aborting post\n");			return 0;		}		else		{			// GLOBAL   Posts start at 01 00 00 00 -> 01 FF FF FF			// REGIONAL Posts start at 02 00 00 00 -> 02 FF FF FF			// LOCAL    Posts start at 03 00 00 00 -> 03 FF FF FF			switch ( msgType )			{				// LOCAL post			case LOCALPOST:				// Write out the serial number as 4 bytes				// Write 03 00 00 00 to bbi file (can't start at 00 00 00 00 because client crashes if this is true)				if ( fwrite("\x03\x00\x00\x00", sizeof(char), 4, pFile) != 4 )				{					clConsole.send("WOLFPACK: MsgBoardGetMaxMsgSN() Error writing to bbi file, aborting post\n");					fclose( pFile );					pFile = NULL;					return 0;				}				// Set maxSN to its startup default				maxSN = 0x3000000;				break;								// REGIONAL post			case REGIONALPOST:				// Write 02 00 00 00 to bbi file (can't start at 00 00 00 00 because client crashes if this is true)				if ( fwrite("\x02\x00\x00\x00", sizeof(char), 4, pFile) != 4 )				{					clConsole.send("WOLFPACK: MsgBoardGetMaxMsgSN() Error writing to bbi file, aborting post\n");					fclose( pFile );					pFile = NULL;					return 0;				}				// Set maxSN to its startup default				maxSN = 0x2000000;				break;								// GLOBAL POST (any other value)			case GLOBALPOST:				// Write 01 00 00 00 to bbi file (can't start at 00 00 00 00 because client crashes if this is true)				if ( fwrite("\x01\x00\x00\x00", sizeof(char), 4, pFile) != 4 )				{					clConsole.send("WOLFPACK: MsgBoardGetMaxMsgSN() Error writing to bbi file, aborting post\n");					fclose( pFile );					pFile = NULL;					return 0;				}								// Set maxSN to its startup default				maxSN = 0x1000000;				break;								// Invalid post type			default:				clConsole.send("WOLFPACK: MsgBoardGetMaxMsgSN() Invalid post type, aborting post\n");				fclose( pFile );				pFile = NULL;				return 0;			}		}	}	else	{		// File must have existed already if maxSN > 0 so open the file as read/write		pFile = fopen( fileName, "rb+" );				if ( pFile == NULL )		{			clConsole.send("WOLFPACK: MsgBoardGetMaxMsgSN() Failed to create bbi file, aborting post\n");			return 0;		}		else		{			// Set file pointer to BOF			if ( fseek(pFile, 0, SEEK_SET) )			{				clConsole.send("WOLFPACK: MsgBoardGetMaxMsgSN() Failed to set pFile to BOF in bbi file\n");				fclose( pFile );				pFile = NULL;				return 0;			}			else			{				// Convert maxSN to an char array				maxMsgSN[0] = maxSN>>24;				maxMsgSN[1] = maxSN>>16;				maxMsgSN[2] = maxSN>>8;				maxMsgSN[3] = maxSN%256;								// Write out new maxSN for this post				if ( fwrite( maxMsgSN, sizeof(char), 4, pFile) != 4 )				{					clConsole.send("WOLFPACK: MsgBoardGetMaxMsgSN() Error writing to bbi file, aborting post\n");					fclose( pFile );					pFile = NULL;					return 0;				}								// Now jump to EOF to write next msgbbiSegment info				if ( fseek(pFile, 0, SEEK_END) )				{					clConsole.send("WOLFPACK: MsgBoardGetMaxMsgSN() Failed to set pFile to EOF in bbi file\n");					fclose( pFile );					pFile = NULL;					return 0;				}			}		}	}		// Set bytes to proper values in bbi message array	msgbbiSegment[0]  = maxSN>>24;  // Message ID 1	msgbbiSegment[1]  = maxSN>>16;     // Message ID 2	msgbbiSegment[2]  = maxSN>>8;       // Message ID 3	msgbbiSegment[3]  = maxSN%256;       // Message ID 4	msgbbiSegment[6]  = msg2Post[3];     // 05 = user posted message, 0xFF and lower  is a quest post (0xFF is escort quest)		// Calculate current time and date ( for later bulletin board maintenance routine )	time( &now );	timeOfPost = *localtime( &now );		msgbbiSegment[7]  = (timeOfPost.tm_yday+1)/256;	msgbbiSegment[8]  = (timeOfPost.tm_yday+1)%256;		// If this is an autoPost then set the CHAR or ITEM serial number in order to mark it for deletion	// after the quest is done.	if ( autoPost )	{		msgbbiSegment[13]  = msg2Post[4];  // CHAR or ITEM SN1		msgbbiSegment[14]  = msg2Post[5];  // CHAR or ITEM SN2		msgbbiSegment[15]  = msg2Post[6];  // CHAR or ITEM SN3		msgbbiSegment[16]  = msg2Post[7];  // CHAR or ITEM SN4	}		// GLOBAL   Posts start at 01 00 00 00 -> 01 FF FF FF	// REGIONAL Posts start at 02 00 00 00 -> 02 FF FF FF	// LOCAL    Posts start at 03 00 00 00 -> 03 FF FF FF	switch ( msgType )	{		// LOCAL post	case LOCALPOST:		// Check to see if Maximum number of posts have been reached		//if ( ((maxSN-0x03000000) >= MAXPOSTS) || (maxSN >= 0xFFFFFFFF) )		if ( maxSN >= 0x03FFFFFF )		{			clConsole.send("WOLFPACK: MsgBoardGetMaxMsgSN() Max posts reached in %s\n", fileName );			fclose( pFile );			pFile = NULL;			return 0;		}		break;				// REGIONAL post	case REGIONALPOST:		// Check to see if Maximum number of posts have been reached		//if ( ((maxSN-0x02000000) >= MAXPOSTS) || (maxSN >= 0x02FFFFFF) )		if ( maxSN >= 0x02FFFFFF )		{			clConsole.send("WOLFPACK: MsgBoardGetMaxMsgSN() Max posts reached in %s\n", fileName );			fclose( pFile );			pFile = NULL;			return 0;		}		break;				// GLOBAL POST (any other value)	case GLOBALPOST:		// Check to see if Maximum number of posts have been reached		//if ( ((maxSN-0x01000000) >= MAXPOSTS) || (maxSN >= 0x01FFFFFF) )		if ( maxSN >= 0x01FFFFFF )		{			clConsole.send("WOLFPACK: MsgBoardGetMaxMsgSN() Max posts reached in %s\n", fileName );			fclose( pFile );			pFile = NULL;			return 0;		}		break;				// Invalid post type	default:		clConsole.send("WOLFPACK: MsgBoardGetMaxMsgSN() Invalid post type, aborting post\n");		fclose( pFile );		pFile = NULL;		return 0;	}		// Write out bbi message array to file	if ( fwrite(msgbbiSegment, sizeof(char), (sizeof(msgbbiSegment)-1), pFile) != (sizeof(msgbbiSegment)-1) )	{		clConsole.send("WOLFPACK: MsgBoardGetMaxMsgSN() Error writing to bbi file, aborting post\n");		fclose( pFile );		pFile = NULL;		return 0;	}		// Close bbi file for the final time	fclose( pFile );	pFile = NULL;		// Return int value of new posts serial number	return maxSN;}