Calling function on dedicated server not working

I feel like I’m getting close with sending data up to my dedicated server, but I think I’m missing something important.

I have a dedicated server
I launch the client, and click my widgetblueprint which connects me to the dedicated server
[ do I need to do something special here to communicate upstream from myCharacterController? ]
The client switches maps to myLoginLevel which presents the user with a login form.
clicking this form calls my C++ code below.

The result is that on the client I see Not Authority, and on the server I see nothing.

bool AMyPlayerController::AuthorizePlayer(FString PlatformID, FString MatchKey)
{

	if (Role == ROLE_Authority)
	{
		UE_LOG(LogTemp, Log, TEXT("Authority"));
	}
	else {
		UE_LOG(LogTemp, Log, TEXT("NOT Authority"));
	}
	UE_LOG(LogTemp, Log, TEXT("PlatformID: %s"), *PlatformID);
	UE_LOG(LogTemp, Log, TEXT("MatchKey: %s"), *MatchKey);

	doStuff(32);
	return true;

}



void AMyPlayerController::doStuff_Implementation(int32 stuff)
{
	GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Green,
		FString::Printf(TEXT("Stuff %i"), stuff));
	UE_LOG(LogTemp, Log, TEXT("DID STUFFs"));
}

void AMyPlayerController::doStuffNetwork_Implementation(int32 stuff)
{
	doStuff(stuff);
}

bool AMyPlayerController::doStuffNetwork_Validate(int32 stuff)
{
	return true;
}

And the header file?

UCLASS()
class MMDEMO1_API AMyPlayerController : public APlayerController
{
GENERATED_BODY()

public:
	UFUNCTION(BlueprintCallable, Category = "LEET")
		bool AuthorizePlayer(FString PlatformID, FString MatchKey);

	UFUNCTION(BlueprintNativeEvent, Category = "LEET")
		void doStuff(int32 stuff);
	virtual void doStuff_Implementation(int32 stuff);

	UFUNCTION(Server, Reliable, WithValidation)
		void doStuffNetwork(int32 stuff);
};

So, you’re calling AuthorizePlayer on the client… and you expect the server to run this function and print out Authority?

My objective is to get the platformID and matchKey stored on the server. I’m totally new to unreal, so I’m sure I’m missing something.

A method marked as server isn’t “server only”, it means it’s called remotely on the server by the client. So if you want to get info from the server, you should called a method like “GetAuthorizationInfo” which is marked as server. This then calls a function marked Client, which will be run remotely on the client.

Something like:

UPROPERTY(Server, WithValidation)
void GetAuthorizationInfo();
// valid/imp methods

UPROPERTY(Client)
void SendAuthorizationInfo( const FString& PlatformID, const FString& MatchKey );
// imp method

void MyClass::GetAuthorizationInfo_Implementation()
{
  SendAuthorizationInfo( some string, some other string );
}

void MyClass::SendAuthorizationInfo_Implementation( const FString& PlatformID, const FString& MatchKey )
{
  // do stuff on client here
}

Or just add these values are variables which are marked as replicated (and don’t forget the replication override method.)

1 Like

Thank you!

Can I send you some bitcoin as a tip?

I was able to get it working with the following:

.h

UFUNCTION(BlueprintCallable, Category = "LEET", Server, Reliable, WithValidation)
		void GetAuthorizationInfo(const FString& PlatformID, const FString& MatchKey);
	// valid/imp methods

	UFUNCTION(BlueprintCallable, Category = "LEET", Client, Reliable)
		void SendAuthorizationInfo(const FString& PlatformID, const FString& MatchKey);
	// imp method

.cpp

void AMyPlayerController::GetAuthorizationInfo_Implementation(const FString& PlatformID, const FString& MatchKey)
{
	UE_LOG(LogTemp, Log, TEXT("PlatformID: %s"), *PlatformID);
	UE_LOG(LogTemp, Log, TEXT("MatchKey: %s"), *MatchKey); 
	SendAuthorizationInfo(PlatformID, MatchKey);
	UE_LOG(LogTemp, Log, TEXT("do stuff on server here"));
}

bool AMyPlayerController::GetAuthorizationInfo_Validate(const FString& PlatformID, const FString& MatchKey)
{
	UE_LOG(LogTemp, Log, TEXT("Validate"));
	return true;
}

void AMyPlayerController::SendAuthorizationInfo_Implementation(const FString& PlatformID, const FString& MatchKey)
{
	// do stuff on client here
	UE_LOG(LogTemp, Log, TEXT("do stuff on client here"));
}
1 Like

Thanks for the offer, but I don’t have a bitcoin wallet. :slight_smile:

1 Like