Ejemplo n.º 1
0
//Sends the actual message
bool Server::SendString(int ID, std::string & _string)
{
	if(_string.find("InitChess") != std::string::npos)
	{
		if (!SendPacketType(ID, P_GameStateChange)) 
		return false; 
	}
	else if(_string.find("MOVE:") != std::string::npos)
	{
		if (!SendPacketType(ID, P_ChessMove))
		return false;
	}
	else
	{
		if (!SendPacketType(ID, P_ChatMessage)) 
			return false; 
	}
	int bufferlength = _string.size(); 
	if (!SendInt(ID, bufferlength)) 
		return false; 
	int RetnCheck = send(players[FindClient(ID)].connection, _string.c_str(), bufferlength, NULL); 
	if (RetnCheck == SOCKET_ERROR) 
		return false; 
	return true; 
}
bool Server::SendString(int ID, std::string & _string)
{
	if (!SendPacketType(ID, P_ChatMessage)) //Send packet type: Chat Message, If sending packet type fails...
		return false; //Return false: Failed to send string
	int bufferlength = _string.size(); //Find string buffer length
	if (!SendInt(ID, bufferlength)) //Send length of string buffer, If sending buffer length fails...
		return false; //Return false: Failed to send string buffer length
	if (!sendall(ID, (char*)_string.c_str(), bufferlength)) //Try to send string buffer... If buffer fails to send,
		return false; //Return false: Failed to send string buffer
	return true; //Return true: string successfully sent
}