Announcement

Collapse
No announcement yet.

Launch a dedicated server during game?

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

    Launch a dedicated server during game?

    Hi, i recently succeed to learn how to launch a dedicated server and now i wonder How to launch a server during game instead of manually clicking Server.exe file.

    i found that some people just saying use 'Open' command but i want to launch Several dedicated server Automatically.

    i also read that put "MyGame.exe ExampleMap -server" or "MyGame.exe /Game/Maps/ExampleMap -server -game -log" like thing in command line. but when i tried this, it just don't work.

    whenever i tried that command, command log said "Command not recognized: Test_Server.exe TestLevel -server".

    is there any way to launch a dedicated server inside of game logic?

    #2
    From C++? Yes.
    From Blueprint, not that I am aware of.
    Rule#21: Be polite, be professional, but have a plan to kill everyone you meet.

    Comment


      #3
      well, currently, i am trying to using "FPlatformProcess::CreateProc" function to open '~Server.exe' file.
      Is this the C++ method you told? or is there a better way to do it?

      Comment


        #4
        Originally posted by Kris View Post
        From C++? Yes.
        From Blueprint, not that I am aware of.
        If the Open command works, it should be possible to do this automatically in BP through the execute console command node.

        Comment


          #5
          hhm1573 Yeah, sounds right.

          When I was looking into, I found UT4 used the same method, so rigged up a function based on that.

          Code:
          bool U<YOURPROJECT>GameInstance::CreateDedicatedServer(const FString CommandLine, bool bShowLog /* = false */)
          {
              FString ExecPath = FPaths::ProjectDir() + TEXT("Binaries/Win64/<YOURPROJECT>-Win64-Shipping.exe");
              FString Options = FString::Printf(TEXT("%s -log"), *CommandLine);
          
          #if WITH_EDITOR
              ExecPath = FPaths::EngineDir() + TEXT("/Binaries/Win64/UE4Editor.exe");
          
              FString ProjectFilePath = FPaths::ProjectDir() + TEXT("<YOURPROJECT>.uproject");
              ProjectFilePath = FPaths::ConvertRelativePathToFull(ProjectFilePath);
          
              Options = FString::Printf(TEXT("%s %s -log -server"), *ProjectFilePath, *CommandLine);
          #endif
          
              ExecPath = FPaths::ConvertRelativePathToFull(ExecPath);
          
              DedicatedServerProcessHandle = FPlatformProcess::CreateProc(*ExecPath, *(Options + FString::Printf(TEXT(" -ClientProcID=%u"), FPlatformProcess::GetCurrentProcessId())), true, !bShowLog, false, NULL, 0, NULL, NULL);
              return DedicatedServerProcessHandle.IsValid();
          }
          
          void U<YOURPROJECT>GameInstance::TerminateDedicatedServer()
          {
              // If we have a valid dedicated server process, terminate it.
              if (DedicatedServerProcessHandle.IsValid() && FPlatformProcess::IsProcRunning(DedicatedServerProcessHandle))
              {
                  FPlatformProcess::TerminateProc(DedicatedServerProcessHandle);
                  DedicatedServerProcessHandle.Reset();
              }
          }
          Rule#21: Be polite, be professional, but have a plan to kill everyone you meet.

          Comment

          Working...
          X