Download

[dedicated server]how to give server a notice when shutdown server?

I build dedicated server in shipping mode, when I start server program in CMD: MyServer.exe -log, server started successfully and my client can connect to, but it run in backstage, my question is how can I shutdown MyServer.exe normally? in my server, there are some logic(e.g. write player’s data from memory to database) need to be done when server exit, if I kill process MyServer.exe immediately, the data of players would rollback.

I write some logic in AMyGameMode::BeginDestroy() which override from AActor::BeginDestroy(), this function would be called when server started in UE4 Editor and click Stop button.

275f73b19b262246a8860146d5b3b485dd81ba2c.png

The dedicated server will have to close the game by its own accord, for example using the QuitGame function:



#include "Runtime/Engine/Classes/Kismet/KismetSystemLibrary.h"

void ASomeActor::SomeActorFunction()
{
	UKismetSystemLibrary::QuitGame(this, nullptr, EQuitPreference::Quit);
}


Does your server ever close manually? For example when all players leave, or after a time limit is reached? Or is this a game where the server runs indefinitely?

thx very much for your help! I got idea from your suggestion: use a special client which allow to send CloseServer message only to server.

You’re welcome! That should work. :slight_smile: