C++ / Blueprint networking

Hello.

I have some question about the unreal engine networking system, i’m working on my own c++ server, i can send to it information and then the server give me some information back.

I made my login / character system working with a sql database, but now i would start to spawn into the world and play.

1) Do i have to use the ue4 replication system and no other choice ?

2) If not, is it possible to make a c++ server without any ue4 networking library or function, and send / receive data from UDP socket.

3) If it is, is it a way to :

example :

I ask to my server to spawn me, the server send me the X-Y-Z position and i can spawn my self, and also say to all other player connected,
“i’m here so spawn me into your game and update my position while i’m moving etc.” (client -> server -> client 2)

Once i’m spawn, spawn the other player who are already connected, spawn the monster, and update every data the server will send to me.

example of code i could use:


struct sData_Entity
{
	int          charId;
	char        Name[MAX_SIZE_CHAR_NAME + 1];
	int           byRace;
	int           byGender;
	int           byLevel;
	float        fPositionX;
	float        fPositionY;
	float        fPositionZ;
	int           _entityIdentifier; //use to know witch object have to be updated.
};

This struct could be use to send to the server the information to update for all already connected player and then send it to the client listening upd socket and update the information.

If anyone could enlighten me, it would be appreciated, thanks !

You can do basically anything you want since you have full access to the source, but I don’t see why you’d use some other system for gameplay related networking. For character info and logins, if these are global, it’s fairly easy to write your own networking code and communicate with your own servers. But for gameplay it doesn’t make much sense to ignore the networking features UE4 has in place.

Hi, first thanks for your quickly responding.

For the login and character info i made a custom server because i need to access to my database and check if my player account and character are create etc etc.

But for the “Game server”, as i understood the ue4 networking features is a player game as a server, but by this way can i spawn as i want my creature around the world ? and can i access to my database safety ?

Are you asking how to spawn your creature in the world given database info? You can use the FHttpModule, or you can implement your own TCP using Sockets, to query your database. Here’s an example of me querying a central server for info about my games:


void UUBGameInstance::RequestServerList(FServerListRetrievedDelegate OnRetrieveServerList) const
{

	FHttpModule* Http = &FHttpModule::Get();
	TSharedRef<IHttpRequest> Request = Http->CreateRequest();
	Request->SetURL("http://127.0.0.1");
	Request->SetVerb("GET");

	Request->OnProcessRequestComplete().BindLambda([OnRetrieveServerList](FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded)
	{
		if (bSucceeded)
		{
			StaticServerList.Empty();

			FString JsonStr = HttpResponse->GetContentAsString();
			TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(JsonStr);
			TSharedPtr< FJsonObject > JsonPtr;

			FJsonSerializer::Deserialize(Reader, JsonPtr);

			for (auto It = JsonPtr->Values.CreateConstIterator(); It; ++It)
			{
				const FString& ServerIP = It.Key();

				uint32 PlayerCount = 512;
				uint32 RemainingTime = 66011;
				uint32 MaxPlayers = 512;

				FString ServerName = TEXT("Error");

				const auto& Value = It.Value();
				const TSharedPtr<FJsonObject> *ServerInfoObj;
				if (Value->TryGetObject(ServerInfoObj))
				{
					(*ServerInfoObj)->TryGetNumberField(TEXT("playerCount"), PlayerCount);
					(*ServerInfoObj)->TryGetStringField(TEXT("serverName"), ServerName);
					(*ServerInfoObj)->TryGetNumberField(TEXT("playerMax"), MaxPlayers);
					(*ServerInfoObj)->TryGetNumberField(TEXT("time"), RemainingTime);
				}

				FServerInfo ServerInfo;
				ServerInfo.ServerName = ServerName;
				ServerInfo.ServerIP = ServerIP;
				ServerInfo.RemainingTime = RemainingTime;
				ServerInfo.PlayerCount = PlayerCount;
				ServerInfo.MaxPlayers = MaxPlayers;

				StaticServerList.Add(ServerInfo);

				UE_LOG(UBLog, Display, TEXT("Listing %s from %s with %d players."), *ServerName, *ServerIP, PlayerCount);
			}
		}
		if (OnRetrieveServerList.IsBound())
		{
			OnRetrieveServerList.Execute();
		}
	});

	if (!Request->ProcessRequest())
	{
		if (OnRetrieveServerList.IsBound())
		{
			OnRetrieveServerList.Execute();
		}
	}
}

Huum that is interesting, i’ll look if i can spawn a cube by this way, move the cube and check the sync.

also, i’ve seen a can run a dedicated server, so i’ll look it too.

Thank’s for the help :slight_smile: !