I am trying to get server IP and port for current dedicated server (exposed to BP).
I successfully managed to show node in blueprints (but without function). I am new at this.
However this is code:
GetServerIPAndPort.h
UCLASS()
class TWITCH_WWII_API UGetServerIPAndPort : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
UFUNCTION(BlueprintPure, meta = (DisplayName = "Get Server IP Address", CompactNodeTitle = "GetServerIP", Keywords = "Server IP Address"), Category = Game)
static FString ServerIPAndPort();
};
Iām in the process of Exposing IP/Port to BP Function Library (C++ Plugin). Unfortunately, I hit a road block with ānonstatic member reference must be relative to a specific objectā. Curious if you found a solution to this issue?
You should make it static and use the WorldContextObject to call GetWorld since you canāt make the call directly from a static function. Optionally use BlueprintPure instead of BlueprintCallable:
*.h
UFUNCTION(BlueprintPure, meta = (WorldContext = "WorldContextObject"))
static const FString GetNetworkURL(UObject* WorldContextObject);
*.cpp
const FString UMyBlueprintFunctionLibrary::GetNetworkURL(UObject* WorldContextObject)
{
if (WorldContextObject)
{
if (UWorld* World = WorldContextObject->GetWorld())
{
return World->GetAddressURL();
}
}
return "";
}
Thank You @GarnerP57 . Youāre an amazing knowledgeable UE4 C++ Programmer. Iām a noob, embarrassed to admit Iām new to C++. Apparently, āWorld->GetAddressURL()ā function only works for Clients . Iām doing more research to locate the function I need to Server Ip Port. This put me on the right path.
Thank you for the kind words, I still have a lot to learn about this engine though. I am not familiar with any function that returns the server public IP from the server itself. As far as I know servers normally give their IP to another Master Server that the Clients can get a Server IP from. The public IP is only known by the router connecting the server to the internet and anyone the router/server is sending messages to.
That is the purpose of the exposing this info to blueprints is to acquire IP & Port to send to Master Server (HTTP) for Clients. It will be used in Online Subsystem for Wordpress Plugin .
Getting your private network IP is simple since you just have to call the router and it will be happy to respond with your designated Private IP.
I donāt know how you would ask the router connected to the internet for the Public IP without sending a packet to an external server and it will report back with your Public IP. I guess it is possible somehow and I would also like to know how.
According to Google it canāt be done and the only solution is to use an external server which doesnāt sound like a bad solution to be honest if you pick a reliable server.
Developing Online Services Plugin for Wordpress. The IP Port is needed for registering to Online Services Server for Server and Client Sessions, Presence, Match Making, Tournament Management, etc. I found a solution that sends API Request via HTTP that echos back the Public IP.
Seems like nice plugin.
Iām not sure how useful it would be in practice, especially when it comes to scalability.
I would use my own API instead of WordPress for this purpose and nothing else. And then I could always call API that will return data from the database and could be used anywhere (in Wordpress too).
However, I was working on a slightly different method. There is one master server and other servers send queries and requests via node.js or websockets (or HTTPS).
For example, a user click on Play button, it will send request to the server, server will ask master server if there are available servers to join.
If there are NO available servers, master server will spawn a new dedicated server instance with parameters (master server automatically handle ports and insert data into database). When dedicated server is up, it will send response that user can join and server is available.
If there are available servers, master server will return data about available server to user and user will join.
When match is over dedicated server will send info to master server and will shut down automatically.
Also, this could be used for player invites, creating virtual lobbies etc.
Basically, thereās nothing to write, servers will automatically spawn and shutdown on request by master server (and to do: routing users to specific server based on geoIP).
Working on webinterface to manually spawn servers, close server, get info from servers like all players and commands for them, set max. number of players for each server, set max port range (max number of server per IP) etc.