Exemple #1
0
void MsgHandler::SendClientData()
{
	if(this->mNet->GetBall(this->mNet->GetIndex())->GetNumCommands() > 0)
	{
		char identifier = (char)6;
		char bufW[BUFFER_SIZE] = {0};
		int offset = 0;
		this->AddToBuffer(bufW, offset, identifier);

		Command* command = this->mNet->GetBall(this->mNet->GetIndex())->GetNextCommand();
		while(command != NULL)
		{
			this->AddToBuffer(bufW, offset, (char)command->GetNumInputs());
			for(int i = 0; i < command->GetNumInputs(); i++)
			{
				this->AddToBuffer(bufW, offset, command->GetInput(i));
			}
			this->AddToBuffer(bufW, offset, command->GetDuration());
			this->AddToBuffer(bufW, offset, command->GetForward());

			this->mNet->GetBall(this->mNet->GetIndex())->PopCommand();
			command = this->mNet->GetBall(this->mNet->GetIndex())->GetNextCommand();
		}
		if(offset > 1)
		{
			this->AddToBuffer(bufW, offset, SEGMENT_END);
			this->AddToBuffer(bufW, offset, this->mNet->GetBall(this->mNet->GetIndex())->GetExecTime());
			//this->mConn->SetWriteBuffer(bufW, offset, 0);
			this->mConn->Send(bufW, offset, 0);
		}
	}
}
Exemple #2
0
void GameMode::HandleClientKeyInputs(const int clientIndex, float diff)
{
	//keep reading client inputs until the sum of all DT has exceeded server DT (->not allowed to move any more)
	Command* command = this->mNet->GetBall(clientIndex)->GetNextCommand();
	float duration = 0.0f;
	if(command != NULL)
	{
		duration = command->GetDuration();
		while(duration <=  diff && command != NULL)
		{
			this->mBalls[clientIndex]->SetForwardVector(command->GetForward());
			for(int c = 0; c < command->GetNumInputs(); c++)
			{
				this->ClientKeyPress(command->GetDuration(), clientIndex, command->GetInput(c));
			}
			this->mNet->GetBall(clientIndex)->SetExecTime(this->mNet->GetBall(clientIndex)->GetExecTime() + command->GetDuration());
			this->mNet->GetBall(clientIndex)->PopCommand();


			command = this->mNet->GetBall(clientIndex)->GetNextCommand();
			if(command != NULL)
				duration += command->GetDuration();
								
		}
		if(duration > diff && command != NULL)
		{
			this->mBalls[clientIndex]->SetForwardVector(command->GetForward());
			duration -= command->GetDuration();
									
			for(int c = 0; c < command->GetNumInputs(); c++)
			{
				//ADD A CHECK HERE SO THAT THE SAME KEY CANT APPEAR MORE THAN ONCE IN THE ARRAY (COULD CHEAT THE SYSTEM THIS WAY)
				
				this->ClientKeyPress((diff - duration), clientIndex, command->GetInput(c));
			}

			command->ModifyDuration(-(diff - duration));
								
			this->mNet->GetBall(clientIndex)->SetExecTime(this->mNet->GetBall(clientIndex)->GetExecTime() + (diff - duration));
		}
	}
}