sprintf( (char*)temp, "region_%s.bbp", FindCharBySerial(calcserial(msg2Post[4], msg2Post[5], msg2Post[6], msg2Post[7]))->region.latin1());
;
int MsgBoardPost( int s, int msgType, int autoPost ){	// WRITE FILE OUT (POST MESSAGE)		// 50 chars for prefix and 4 for the extension plus the ending NULL	unsigned long loopexit3=0;	char        fileName[256] = "";	FILE        *pFile = NULL;		int         origMsgSize           = 0;//	int         tempMsgSize           = 0;	int         newMsgSize            = 0;	int         newMsgSN              = 0;	int         maxMsgSN              = 0;	int         isReply               = 0;	int         x, y, z, pos, offset;		char        msgHeader[17]         = "";	char        msgSubject[257]       = "";	char        msgBody[MAXBUFFER_ASYNCH]    = "";	char        msgAuthor[52]         = "";   // Maximum name size from char_st (Size + Name)	char        msgDate[17]           = "";   // Maximum date size based on Size + "Day ### @ hh:mm" format		struct tm   timeOfPost;	time_t      now;		// If this is a users post (done from the client) then copy the client buffer[s] into our buffer	if ( !autoPost )	{		memcpy( msg2Post, buffer[s], (buffer[s][1]*256 + buffer[s][2]) );				// Determine what type of post this is supposed to be and then set the proper file name		// Also, if this is a reply to a base post, then abort posting if the reply is to a		// GLOBAL or REGIONAL message.  No one can reply to GLOBAL or REGIONAL messages as they		// as for informational purposes only (discussions should be taken offline).  There is no		// reason to reply to a quest post execpt to fill up the message board.		isReply = (msg2Post[8]*16777216) + (msg2Post[9]*65536) + (msg2Post[10]*256) + msg2Post[11];				// If this is a reply to anything other than a LOCAL post, abort		if ( (isReply>0) && (isReply<0x03000000) )		{#ifdef DEBUG			clConsole.send("WOLFPACK: MsgBoardPost() Attempted reply to a global or regional post\n");#endif			sysmessage( s, "You can not reply to global or regional posts" );			return 0;		}	}		// If everything passed the check above then,	// Determine the new messages serial number for the type of post being done	maxMsgSN = MsgBoardGetMaxMsgSN( msgType, autoPost );		// If the value returned is zero, then abort the posting	if ( maxMsgSN == 0 )	{		clConsole.send("WOLFPACK: MsgBoardPost() Could not retrieve a valid message serial number\n");		sysmessage( s, "Post failed!" );		return 0;	}		// 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.bbp", 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.bbp", 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.bbp" );		break;				// Invalid post type	default:		clConsole.send("WOLFPACK: MsgBoardPost() Invalid post type, aborting post\n");		sysmessage( s, "Invalid post type!" );		return 0;	}		// Append file name to end of path	strcat( fileName, (char*)temp );		// Open the file for appending	pFile=fopen( fileName, "ab+");		// If we couldn't open the file, send an error message to client	if ( pFile == NULL )	{		clConsole.send("WOLFPACK: MsgBoardPost() Unable to open bbp file, aborting post\n");		return 0;	}		// Calculate original size of the message that the client sent to us  origMsgSize = ( (msg2Post[1]<<8) + msg2Post[2] );		// Get the messages header info (packet type, size, type, board S/N, parent msg S/N(replies only))	for ( x=0; x<12; x++ )		msgHeader[x] = msg2Post[x];			// Set new messages serial number to maxMsgSN from the bbi file	msgHeader[8]  = maxMsgSN>>24;	msgHeader[9]  = maxMsgSN>>16;	msgHeader[10] = maxMsgSN>>8;	msgHeader[11] = maxMsgSN%256;		// Get the new messages serial number (which is its post position on the board- anything other than 00 00 00 00 	// (base post) is a reply to a specific message ID )  newMsgSN = (msg2Post[8]<<24) + (msg2Post[9]<<16) + (msg2Post[10]<<8) + msg2Post[11];		// If the newMsgSN is 0 then it is a base post, other wise it is a reply to a previous post	if ( newMsgSN )	{		// Create the proper parent message ID segment for the new post		msgHeader[12] = msg2Post[8];		msgHeader[13] = msg2Post[9];		msgHeader[14] = msg2Post[10];		msgHeader[15] = msg2Post[11];	}	else	{		// If this isn't a reply post, the parent message SN fields should be 0x00		msgHeader[12] = 0;		msgHeader[13] = 0;		msgHeader[14] = 0;		msgHeader[15] = 0;	}		newMsgSize = origMsgSize + 4;  // added 4 bytes for parent msg ID		// This is the position within the msg2Post[] array	pos = x; // Should equal to 12 (pointing to size of Subject field)		// Get the messages subject info (size, subject)	y = msg2Post[pos];  // get the size of the subject		for ( x=0; x<=y; x++ )    // Do while we get all bytes		msgSubject[x] = msg2Post[pos+x];  // get the subject message (size and data)		pos += x;		// Get the messages body info (body section, body size, body data)	z = msg2Post[pos];     // Total number of NULL's in Body of message	offset = 0;		// Check if body of post is empty (NULL)	if ( z )	{		// Get the FIRST Body segment size + 2 for pre segment size bytes		y = msg2Post[pos+1] + 2;				// Loop until number of remaining NULLS equal zero		while (z && (++loopexit3 < MAXLOOPS) )  		{			// Store Body segment into msgBody ( continue until NULL reached )			for ( x=0; x<y; x++ )				msgBody[x+offset] = msg2Post[pos+x];						offset += x;			pos += x;						// Size of NEXT Body segment			y = msg2Post[pos] + 1;						// Decrement NULL count (processed one segment of the Body)			z--;		}	}	else  // Body is empty (NULL) so write out set msgBody[] = "\x00"	{		msgBody[0] = msg2Post[pos];		offset++;		//pos++;	}		// Get the Authors info and create msgAuthor packet	// if this was a user posting, get the characters name, other wise leave it blank	if ( !autoPost )		strncpy( &msgAuthor[1], currchar[s]->name.c_str(), (sizeof(msgAuthor)-1) );	msgAuthor[0] = strlen(&msgAuthor[1]) + 1;  // get the length of the name + 1 for null		newMsgSize += (msgAuthor[0]+1);   // Update the new total length of the message	// + 1 is for the byte giving the size of Author segment		// Calculate current time and date	time( &now );	timeOfPost = *localtime( &now );		// Create msgDate data packet	sprintf( &msgDate[1], "Day %i @ %i:%02i\0",		(timeOfPost.tm_yday+1),		timeOfPost.tm_hour,		timeOfPost.tm_min );		// get the length of the date + 1 for null	msgDate[0] = strlen(&msgDate[1]) + 1;       		// Update the new total length of the message (+ 1 is for the byte giving the size of Date segment)	newMsgSize += (msgDate[0]+1);		// Start writing information out to a file	// msgHeader + sizeof(msgAuthor) + msgAuthor		// Write out the msgHeader	msgHeader[1] = newMsgSize/256;	msgHeader[2] = newMsgSize%256;	fwrite( msgHeader, sizeof(char), (sizeof(msgHeader)-1), pFile );		// Write out the msgAuthor	fwrite( msgAuthor, sizeof(char), (msgAuthor[0]+1), pFile );		// Write out the msgSubject	fwrite( msgSubject, sizeof(char), (msgSubject[0]+1), pFile );		// Write out the msgDate	fwrite( msgDate, sizeof(char), (msgDate[0]+1), pFile );		// Write out the msgBody	fwrite( msgBody, sizeof(char), offset, pFile );		// Close the file	fclose( pFile );	pFile = NULL;		// if this was a user post, then immediately update the message board with the newly created message	if ( !autoPost )	{		// Add item   |s1|s2|s3|s4|m1|m2|??|#i|#i|x1|x2|y1|y2|b1|b2|b3|b4|c1|c2 		//[RECV:20] 25 40 2b 38 1a 0e b0 00 00 00 00 00 00 00 40 07 ba 3d 00 00 		char addItem[21] = "\x25\x00\x00\x00\x00\x0e\xb0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";				// Insert posts serial number into addItem[] packet		addItem[1]  = msgHeader[8];		addItem[2]  = msgHeader[9];		addItem[3]  = msgHeader[10];		addItem[4]  = msgHeader[11];				// Insert posts bulleting board serial number into addItem[] packet		addItem[14] = msgHeader[4];		addItem[15] = msgHeader[5];		addItem[16] = msgHeader[6];		addItem[17] = msgHeader[7];				// Setup buffer to expect to receive an ACK from the client for this posting		postCount[s]       = 1;		postAckCount[s]    = 0;		postAcked[s][0][0] = msgHeader[8];		postAcked[s][0][1] = msgHeader[9];		postAcked[s][0][2] = msgHeader[10];		postAcked[s][0][3] = msgHeader[11];				// Send "Add Item to Container" message to client		Xsend( s, addItem, 20);	}	// Return success (the new message serial number)	return maxMsgSN;}