yojimbo: Problem with Unreal

Hi Glenn, I tried to integrate libyojimbo with unreal engine, after successfuly sending/receiving message with bare windows client to linux server, it’s failed doing excactling the same thing in Unreal Engine tutorial scene. I did some network sniffing with Wireshark, it’s weird the client side sends 10 UDP packets of 18 bytes payload to server, and server logged with “ignored encrypted packet, no read packet key for this address”, any ideas? Here’s my code (in Unreal).

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.

#include "physxClient.h"
#include "physxClientGameMode.h"
#include "physxClientHUD.h"
#include "physxClientCharacter.h"
#include "../ThirdParty/libyojimbo/include/yojimbo.h"
#include "../ThirdParty/libyojimbo/include/shared.h"
#include <signal.h>

using namespace yojimbo;

AphysxClientGameMode::AphysxClientGameMode()
	: Super()
{
	// set default pawn class to our Blueprinted character
	static ConstructorHelpers::FClassFinder<APawn> PlayerPawnClassFinder(TEXT("/Game/FirstPersonCPP/Blueprints/FirstPersonCharacter"));
	DefaultPawnClass = PlayerPawnClassFinder.Class;

	// use our custom HUD class
	HUDClass = AphysxClientHUD::StaticClass();
}
double ti = 100.0;

Client* client ;

void AphysxClientGameMode::StartPlay() {
	Super::StartPlay();
	InitializeYojimbo();
	OgameMessageFactory messageFactory(GetDefaultAllocator());
	uint64_t clientId = 1;

	Address clientAddress("0.0.0.0", 6667);
	Address serverAddress("192.168.0.8", 6666);
		 
	ClientServerConfig config;
	config.numChannels = 1;
	config.channel[0].type = CHANNEL_TYPE_UNRELIABLE_UNORDERED;

	client = new Client(GetDefaultAllocator(), clientAddress, config, adapter, ti);

	uint8_t privateKey[KeyBytes];
	memset(privateKey, 0, KeyBytes);
	client->InsecureConnect(privateKey, clientId, serverAddress);
	client->AdvanceTime(ti);
}

void AphysxClientGameMode::Tick(float f) {
	Super::Tick(f);
	
	const double deltaTime = 0.1;

	JoinMessage* message = (JoinMessage*)(client->CreateMessage(JOIN_MESSAGE));
	message->teamId = 1;
	client->SendMessage(0, message);
	client->SendPackets();
	client->ReceivePackets();
	ti += deltaTime;
	client->AdvanceTime(ti);
	//messageFactory.ReleaseMessage(message);

	yojimbo_sleep(deltaTime);

	return;
}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 41 (28 by maintainers)

Most upvoted comments

Works for me

#include "YojimboComponent.h"
#include <EngineGlobals.h>
#include <Runtime/Engine/Classes/Engine/Engine.h>
#include "C:/Users/Glenn Fiedler/Documents/Unreal Projects/YojimboTest/Yojimbo/yojimbo.h"
#include "C:/Users/Glenn Fiedler/Documents/Unreal Projects/YojimboTest/Yojimbo/shared.h"

using namespace yojimbo;

int yojimbo_printf_function( const char * format, ... )
{
    char buffer[4*1024];
    va_list args;
    va_start( args, format );
    vsprintf_s( buffer, format, args );
    va_end( args );
    int length = strlen( buffer );
    if ( buffer[length-1] == '\n' )
    {
        buffer[length-1] = '\0';
    }
    GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, UTF8_TO_TCHAR( buffer ) );
    return 0;
}

UYojimboComponent::UYojimboComponent()
{
    PrimaryComponentTick.bCanEverTick = true;
}

Client * client = NULL;
double clientTime = 0.0;

void UYojimboComponent::BeginPlay()
{
    Super::BeginPlay();
    yojimbo_log_level( YOJIMBO_LOG_LEVEL_DEBUG );
    yojimbo_set_printf_function( yojimbo_printf_function );
    InitializeYojimbo();
    yojimbo_printf( YOJIMBO_LOG_LEVEL_INFO, "connecting client (insecure)\n" );
    uint64_t clientId = 0;
    random_bytes( (uint8_t*) &clientId, 8 );
    ClientServerConfig config;
    client = new Client( GetDefaultAllocator(), Address("0.0.0.0"), config, adapter, clientTime );
    Address serverAddress( "127.0.0.1", ServerPort );
    uint8_t privateKey[KeyBytes];
    memset( privateKey, 0, KeyBytes );
    client->InsecureConnect( privateKey, clientId, serverAddress );
}

void UYojimboComponent::TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction * ThisTickFunction )
{
    Super::TickComponent( DeltaTime, TickType, ThisTickFunction );
    client->SendPackets();
    client->ReceivePackets();
    client->AdvanceTime( clientTime );
    clientTime += DeltaTime;
}