Beispiel #1
0
void IGFManager :: OpenThread(int threadID, int startPost, int requestedCount, MULTISTRING &output)
{
	IGFThread *thread = GetPagedThreadPtr(threadID);
	if(thread == NULL)
		return;

	startPost = Util::ClipInt(startPost, 0, thread->mPostList.size() - 1);

	STRINGLIST row;

	//We retrieve the time offset since the first session since the client uses
	//4 byte integers which theoretically may not be large enough to hold the time data.
	unsigned long timeOffset = g_PlatformTime.getAbsoluteMinutes();

	//Prepare the header
	row.push_back(ConvertInteger(threadID));  //[0]
	row.push_back(thread->mTitle);   //[1]
	row.push_back(ConvertInteger(startPost));  //[2]
	row.push_back(ConvertInteger(thread->mPostList.size()));  //[3]
	row.push_back(ConvertInteger(timeOffset - thread->mLastUpdateTime));  //[4]
	output.push_back(row);
	row.clear();

	//Append the post data.
	int count = 0;
	for(size_t i = startPost; i < thread->mPostList.size(); i++)
	{
		IGFPost *post = GetPagedPostPtr(thread->mPostList[i]);
		if(post == NULL)
		{
			g_Logs.data->error("OpenThread: unable to find post: %v", thread->mPostList[i]);
			continue;
		}

		row.push_back(ConvertInteger(post->mID));  //[0]
		row.push_back(post->mCreatorName.c_str());  //[1]
		row.push_back(post->mCreationTime.c_str());  //[2]
		row.push_back(ConvertInteger(timeOffset - post->mPostedTime)); //[3]
		row.push_back(post->mBodyText.c_str());  //[4]
		row.push_back(ConvertInteger(post->mEditCount)); //[5]
		row.push_back(ConvertInteger(timeOffset - post->mLastUpdateTime)); //[6]

		output.push_back(row);
		row.clear();

		if(++count >= requestedCount)
			break;
	}
}
Beispiel #2
0
void IGFManager :: EnumCategoryList(int parentID, MULTISTRING &output)
{
	STRINGLIST entry;
	CATEGORYPAGE::iterator it;
	IGFCategoryPage::CATEGORYENTRY::iterator eit;
	for(it = mCategoryPages.begin(); it != mCategoryPages.end(); ++it)
	{
		for(eit = it->second.mEntries.begin(); eit != it->second.mEntries.end(); ++eit)
		{
			if(eit->second.mParentCategory == parentID)
			{
				entry.push_back(ConvertInteger(TYPE_CATEGORY));
				entry.push_back(ConvertInteger(eit->second.mID));
				entry.push_back(ConvertInteger(eit->second.mLocked));
				entry.push_back(ConvertInteger(0)); //Stickied.  Categories don't have this.
				entry.push_back(eit->second.mTitle);
				entry.push_back(ConvertInteger(eit->second.mThreadList.size()));
				entry.push_back(ConvertInteger(GetTimeOffset(eit->second.mLastUpdateTime)));

				output.push_back(entry);
				entry.clear();
			}
		}
	}
}
Beispiel #3
0
void IGFManager :: EnumThreadList(int parentID, MULTISTRING &output)
{
	IGFCategory* category = GetPagedCategoryPtr(parentID);
	if(category == NULL)
		return;

	//Pregenerate a list of threads
	std::vector<IGFThread*> results;
	for(size_t i = 0; i < category->mThreadList.size(); i++)
	{
		IGFThread* thread = GetPagedThreadPtr(category->mThreadList[i]);
		if(thread != NULL)
			results.push_back(thread);
	}

	if(category->mFlags.hasFlag(IGFFlags::FLAG_SORTALPHABETICAL))
		std::sort(results.begin(), results.end(), ThreadSortAlphabetical);

	STRINGLIST entry;
	for(size_t i = 0; i < results.size(); i++)
	{
		IGFThread* thread = results[i];
		entry.push_back(ConvertInteger(TYPE_THREAD));
		entry.push_back(ConvertInteger(thread->mID));
		entry.push_back(ConvertInteger(thread->mLocked));
		entry.push_back(ConvertInteger(thread->mStickied));
		entry.push_back(thread->mTitle);
		entry.push_back(ConvertInteger(thread->mPostList.size()));
		entry.push_back(ConvertInteger(GetTimeOffset(thread->mLastUpdateTime)));

		output.push_back(entry);
		entry.clear();
	}
}
Beispiel #4
0
// Tokenize a string using whitespace as separators, but including string quotations.
void TokenizeByWhitespace(const std::string &input, STRINGLIST &output)
{
	std::string str = input;
	output.clear();
	size_t len = str.size();
	int first = -1;
	int last = -1;
	bool quote = false;
	bool terminate = false;
	for(size_t i = 0; i < len; i++)
	{
		switch(input[i])
		{
		case '"':
			terminate = true;  //Treat opening quote as a block start
			quote = !quote;
			break;

		case ' ':
		case '\t':
		case '\n':
		case '\r':
			if(quote == false)
				terminate = true;
			break;
		default:
			if(first == -1)
				first = i;
			last = i;
		}
		if(terminate == true)
		{
			if(first >= 0 && last >= 0)
			{
				std::string t = str.substr(first, last - first + 1);
				output.push_back(str.substr(first, last - first + 1));
				first = -1;
				last = -1;
			}
			terminate = false;
		}
	}
	if(first != -1 && first < (int)len)
		output.push_back(str.substr(first, len - first + 1));
}