Exemple #1
0
void CGameContext::ConPrivMsg(IConsole::IResult *pResult, void *pUserData)
{
	CGameContext *pSelf = (CGameContext *) pUserData;
    
	int to = pResult->GetVictim();
    
	if(!CheckClientID(to))
		return;
	if(CheckClientID(pResult->m_ClientID) && pSelf->ProcessSpamProtection(pResult->m_ClientID))
		return;
    
	char message[512];
	str_format(message, sizeof(message), "PM -> %s: ", pSelf->Server()->ClientName(to));
	str_append(message, pResult->GetString(0), sizeof(message));
    
	CNetMsg_Sv_Chat Msg;
	Msg.m_Team = 1;
	Msg.m_ClientID = CheckClientID(pResult->m_ClientID) ? pResult->m_ClientID : -1;
	Msg.m_pMessage = message;
	pSelf->Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, to);
	
	if(CheckClientID(pResult->m_ClientID))
	{
		pSelf->Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, pResult->m_ClientID);
		str_format(message, sizeof(message), "\"%s\" -> \"%s\" : %s", 
			   pSelf->Server()->ClientName(pResult->m_ClientID),
			   pSelf->Server()->ClientName(to),
			   pResult->GetString(0));

	}
	else
	{
		str_format(message, sizeof(message), "%d -> \"%s\" : %s", 
			   pResult->m_ClientID,
			   pSelf->Server()->ClientName(to),
			   pResult->GetString(0));
	}
	pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "pmchat", message);
}
Exemple #2
0
void CGameContext::ConSwap(IConsole::IResult *pResult, void *pUserData)
{
	CGameContext *pSelf = (CGameContext *) pUserData;
	const int ClientID = pResult->m_ClientID;

	if(!g_Config.m_SvSwap)
	{
		pSelf->SendChatTarget(ClientID, "Swap is not activated");
		return;
	}
	
	int ToSwap = pResult->GetVictim();
	if(!CheckClientID(ToSwap) || ClientID == ToSwap)
		ToSwap = -1;

	if(!CheckClientID(ClientID))
		return;
	
	pSelf->m_aSwapRequest[ClientID] = ToSwap;
	if(ToSwap == -1)
		return;
	
	if(pSelf->ProcessSpamProtection(ClientID)) // dont flood
		return;
	
	// check if ToSwap agrees
	char aBuf[128];
	if(pSelf->m_aSwapRequest[ToSwap] != ClientID)
	{
		// send  notification to ToSwap
		str_format(aBuf, sizeof(aBuf), "%s wants to swap places with you. Type \'/swap %d\' to accept.",
			   pSelf->Server()->ClientName(ClientID), ClientID);
		pSelf->SendChatTarget(ToSwap, aBuf);
		
		str_format(aBuf, sizeof(aBuf), "Requst sent to %s.",
			   pSelf->Server()->ClientName(ToSwap));
		pSelf->SendChatTarget(ClientID, aBuf);
	}
	else
	{
		// ToSwap agreed
		CCharacter * pChar1 = pSelf->GetPlayerChar(ClientID);
		CCharacter * pChar2 = pSelf->GetPlayerChar(ToSwap);
		if(!pChar1 || !pChar2 || pChar1->Team() != pChar2->Team())
		{
			// one is not alive or not in the same team
			const char * pStr = "Can\'t swap!";
			pSelf->SendChatTarget(ToSwap, pStr);
			pSelf->SendChatTarget(ClientID, pStr);
			return;
		}

		CPlayerRescueState state1 = GetPlayerState(pChar1),
			state2 = GetPlayerState(pChar2);
		
		// swap
		ApplyPlayerState(state2, pChar1);
		ApplyPlayerState(state1, pChar2);
		
		str_format(aBuf, sizeof(aBuf), "%s swapped with %s.",
			   pSelf->Server()->ClientName(ToSwap),
			   pSelf->Server()->ClientName(ClientID));
		pSelf->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
		// reset swap requests
		pSelf->m_aSwapRequest[ToSwap] = -1;
		pSelf->m_aSwapRequest[ClientID] = -1;
	}
}