Hi everyone,
I’ve played around with the Message Bus inspired by the McLarren demo from a while ago. Well I’ve used the GDC2016 plugin from Max from github as a starting point and got the client-server-discovery working quite quickly but then I got stuck at the RPC part.
So I initialize a RPC server on my server like this:
...
RpcServer = FModuleManager::LoadModuleChecked<IMessagingRpcModule>("MessagingRpc").CreateRpcServer();
RpcServer->RegisterHandler<FControllerCommand>(this, &AMessagingGameMode::HandleRequest);
...
The Handle Request looks like follows:
TAsyncResult<int32> AMessagingGameMode::HandleRequest(const FControllerCommandRequest& Message)
{
UE_LOG(LogTemp, Warning, TEXT("Something arrived from the client"))
switch (Message.Command)
{
case EControllerCommand::MoveForward:
UE_LOG(LogTemp, Warning, TEXT("Got a forward message with %f"), Message.Value)
break;
case EControllerCommand::MoveRight:
UE_LOG(LogTemp, Warning, TEXT("Got a right message with %f"), Message.Value)
break;
default:
break;
}
return 0;
}
Furthermore my message declarations to be complete:
USTRUCT()
struct FControllerPing
{
GENERATED_BODY()
};
USTRUCT()
struct FGamePong
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, Category = "Message")
FString GameAddress;
FGamePong() { }
FGamePong(const FString& InAddress)
: GameAddress(InAddress)
{ }
};
UENUM()
enum class EControllerCommand : uint8
{
MoveForward,
MoveRight
};
USTRUCT()
struct FControllerCommandRequest : public FRpcMessage
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, Category = "Message")
EControllerCommand Command;
UPROPERTY(EditAnywhere, Category = "Message")
float Value;
FControllerCommandRequest(EControllerCommand InCommand, float InValue)
: Command(InCommand),
Value(InValue)
{
}
FControllerCommandRequest()
{
};
};
USTRUCT()
struct FControllerCommandResponse : public FRpcMessage
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, Category = "Message")
int32 Result;
FControllerCommandResponse() : Result(INDEX_NONE)
{
}
FControllerCommandResponse(int32 InResult) : Result(InResult)
{
}
};
DECLARE_RPC(FControllerCommand, int32)
The rpc client on the client side is created like this:
RpcClient = FModuleManager::LoadModuleChecked<IMessagingRpcModule>("MessagingRpc").CreateRpcClient();
...
// later in the server address is extracted from the 'pong' message from the server
void AFFTControllerGameMode::HandleGamePongMessage(const FGamePong& Message,
const TSharedRef<IMessageContext, ESPMode::ThreadSafe>& Context)
{
FMessageAddress NewGameAddress;
if (FMessageAddress::Parse(Message.GameAddress, NewGameAddress) && NewGameAddress != GameAddress)
{
GameAddress = NewGameAddress;
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red,
FString::Printf(TEXT("Got new adresse %s"), *NewGameAddress.ToString()));
RpcClient->Connect(NewGameAddress);
OnGameFound.Broadcast();
}
LastGameResponse = FDateTime::UtcNow();
}
And finally an RPC call is issued like this:
void AFFTControllerGameMode::SendCommand(const EControllerCommand Command, const float Value) const
{
if (Value == 0)
{
return;
}
if (RpcClient->IsConnected())
{
RpcClient->Call<FControllerCommand>(Command, Value);
}
else
{
UE_LOG(LogTemp, Error, TEXT("Command was not send because rpc client is not connected"))
}
}
This function is just a simple abstraction.
On the surface everything is similar or the same as in the gdc2016 plugin. But the issued rpc requests don’t reach the server.
Does someone has an idea what I’m missing?