While programming our game, there seems to be a pattern emerging concern a server’s authority. Most, if not all of our server methods require at least 4 method.
-
The initial call
MyMethod()
, which is pretty much the public API to be called in the code. This includes client-side logic whether the method should do certain things. -
The same logic, but now replicated on the server:
Server_MyMethod_Implementation()
. The server is an authority and decides whether the client was right. -
Network verification:
Server_MyMethod_Validate()
. Pretty trivial. -
Method that actually does what is requested when the client and server give the go-ahead:
DoMyMethod()
.
My question is, is whether this is an acceptable pattern, and what do other people use for server side authorive RPCs? It seems rather complex and a bit too much for just simple functionality. I’ve put a small snippet of our game code below to give an impression of how this are structured.
// --------------------------------------------------------------\
// CHARGE START |
// --------------------------------------------------------------/
void AWeapon::ChargeStart()
{
if (MayShootOrCharge())
{
if (Role < ROLE_Authority)
Server_ChargeStart();
else
DoChargeStart();
}
}
void AWeapon::Server_ChargeStart_Implementation()
{
if (MayShootOrCharge())
DoChargeStart();
}
bool AWeapon::Server_ChargeStart_Validate()
{
return true;
}
void AWeapon::DoChargeStart()
{
SetCharging(true);
}