All pastes #2106280 Raw Edit

Stuff

public text v1 · immutable
#2106280 ·published 2012-01-26 06:10 UTC
rendered paste body
void __stdcall Proc_PlayerJoin(nc_cPlayer *pData, nc_WideStringClass *pName)
{
	if (pName->Get_Length() > 20)
	{
		Console_Output(StrFormat("[JellyScripts] Notice: Nickname \"%ls\" is longer than 20 characters and has been truncated to 20 characters.\n",pName->m_Buffer).c_str());
		pName->Resize(21);
		pName->m_Buffer[20] = '\0';
		pData->PlayerName.Resize(21);
		pData->PlayerName.m_Buffer[20] = '\0';
	}
	bool noticeShown = false;

	// Check for invalid characters in nickname
	wchar_t *pNamePtr = pName->m_Buffer;
	while (*pName->m_Buffer)
	{
		switch (*pName->m_Buffer)
		{
			case ' ':
			case ';':
			case ':':
			case '"':
			case '\'':
				if (!noticeShown)
				{
					Console_Output(StrFormat("[JellyScripts] Notice: Nickname \"%ls\" contains disallowed character(s) and has been replaced with an underscore.\n",pNamePtr).c_str());
					Console_Input(StrFormat("ppage %d Your nickname contains disallowed character(s), therefore they have been replaced with an underscore.\n",pData->PlayerId).c_str());
					noticeShown = true;
				}
				*pName->m_Buffer = '_';
				break;

			default:
				break;
		}
		*pName->m_Buffer++;
	}

	// Duplicate nickname check after replaced
	pName->m_Buffer = pNamePtr;
	wchar_t *changedName = pNamePtr;
	for (nc_GenericSLNode<nc_cPlayer> *pList = nc_cPlayerManager::PlayerList->HeadNode; pList != NULL; pList = pList->NodeNext)
	{
		if (pList->NodeData->IsActive && pList->NodeData != pData && !wcsicmp(pNamePtr, pList->NodeData->PlayerName.m_Buffer))
		{
			for (int i = 1; i <= 128; i++)
			{
				pName->Format(L"%ls%d", changedName, i);
				if (!nc_cPlayerManager::Find_Player(*pName))
					break;
			}
		}
	}
	pData->PlayerName.Format(L"%ls", pNamePtr);
}