Announcement

Collapse
No announcement yet.

Expose to BP: get server port and IP address

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Expose to BP: get server port and IP address

    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


    PHP Code:
    UCLASS()
    class 
    TWITCH_WWII_API UGetServerIPAndPort : public UBlueprintFunctionLibrary
    {
        
    GENERATED_BODY()
        
    UFUNCTION(BlueprintPuremeta = (DisplayName "Get Server IP Address"CompactNodeTitle "GetServerIP"Keywords "Server IP Address"), Category Game)
        static 
    FString ServerIPAndPort();
    }; 
    And now this part bothers me

    GetServerIPAndPort.cpp

    PHP Code:
    #include "Engine/World.h"
    #include "GetServerIPAndPort.h"

    FString UGetServerIPAndPort::ServerIPAndPort()
    {
        
    //if ( GetWorld() ) return GetWorld()->URL.Port;
        
    return "";

    Currently it returns empty string. But how to get server IP and port so it will look something like this:
    Click image for larger version

Name:	bp.jpg
Views:	1
Size:	22.8 KB
ID:	1499908

    #2
    Ok, I tried this:

    Code:
    int32 UGetServerIPAndPort::ServerIPAndPort()
    {
        UWorld* wworld = GEngine->GameViewport->GetWorld();
    
            if (wworld->IsServer())
            {
                return wworld->URL.Port;
            }
            return 0;
    
    }
    But UE4 crash after calling it.
    Could not find anywhere something related to this.
    Little help here?

    Comment

    Working...
    X