Skip to content

Commit a8111c0

Browse files
Merge pull request #183 from FS-Online/spectator-password
spectator password authentication
2 parents d7996be + 96a2ebc commit a8111c0

File tree

10 files changed

+65
-23
lines changed

10 files changed

+65
-23
lines changed

AirSim/AirLib/include/common/AirSimSettings.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,10 @@ struct AirSimSettings {
312312
std::string api_server_address = "";
313313
int api_port = RpcLibPort;
314314

315+
// If the current game is running as a listen server, and a spectator connects,
316+
// it must proide this password to be allowed to enter.
317+
std::string spectator_server_password = "password";
318+
315319
std::string clock_type = "";
316320
float clock_speed = 1.0f;
317321
bool log_messages_visible = true;
@@ -890,6 +894,7 @@ struct AirSimSettings {
890894
speed_unit_factor = settings_json.getFloat("SpeedUnitFactor", 1.0f);
891895
speed_unit_label = settings_json.getString("SpeedUnitLabel", "m\\s");
892896
log_messages_visible = settings_json.getBool("LogMessagesVisible", true);
897+
spectator_server_password = settings_json.getString("SpectatorServerPassword", "password");
893898

894899
{ //load origin geopoint
895900
Settings origin_geopoint_json;

UE4Project/Config/DefaultEngine.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ TransitionMap=
55
bUseSplitscreen=True
66
TwoPlayerSplitscreenLayout=Horizontal
77
ThreePlayerSplitscreenLayout=FavorTop
8-
GameInstanceClass=/AirSim/DisconnectGameInstance.DisconnectGameInstance_C
8+
GameInstanceClass=/AirSim/Blueprints/AirsimGameInstance.AirsimGameInstance_C
99
GameDefaultMap=/AirSim/MainMenuLevel.MainMenuLevel
1010
ServerDefaultMap=/Engine/Maps/Entry
11-
GlobalDefaultGameMode=/Script/AirSim.AirSimGameMode
11+
GlobalDefaultGameMode=/Script/Engine.GameMode
1212
GlobalDefaultServerGameMode=None
1313

1414

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:a0826818588a47990b665e799521de19c018115102deb8297c12e99645e6dd47
3-
size 47030
2+
oid sha256:c31b478880f4ff7ea8c615044cf7c6bf573b0d60f6ae3f74824f00fc36e5e45c
3+
size 30362
-745 Bytes
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:477bdb6f5cbf5a455c4af679c842b7e54f0259b776e7158883f842166dae0b79
3-
size 117840
2+
oid sha256:d5f8844ce66a309214de7ffa46a44270f6ea37b8df5086aca542712cca785efd
3+
size 118348

UE4Project/Plugins/AirSim/Source/AirBlueprintLib.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "CoreMinimal.h"
77
#include "GameFramework/Actor.h"
8+
#include "Misc/MessageDialog.h"
89
#include "Components/InputComponent.h"
910
#include "GameFramework/PlayerInput.h"
1011
#include "IImageWrapperModule.h"
@@ -47,6 +48,12 @@ class UAirBlueprintLib : public UBlueprintFunctionLibrary
4748
static void LogMessage(const FString &prefix, const FString &suffix, LogDebugLevel level, float persist_sec = 60);
4849
static float GetWorldToMetersScale(const AActor* context);
4950

51+
UFUNCTION(BlueprintCallable, Category = "Utils")
52+
static void showMessageAlertDialog(const FText& message, const FText& title)
53+
{
54+
FMessageDialog::Open(EAppMsgType::Ok, message, & title);
55+
}
56+
5057
template<typename T>
5158
static T* GetActorComponent(AActor* actor, FString name);
5259

UE4Project/Plugins/AirSim/Source/AirSimGameMode.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,17 @@ AAirSimGameMode::AAirSimGameMode(const FObjectInitializer& ObjectInitializer)
5454
static IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(TEXT("ImageWrapper"));
5555
}
5656

57+
void AAirSimGameMode::InitGame(const FString & MapName, const FString & Options, FString & ErrorMessage)
58+
{
59+
AGameModeBase::InitGame(MapName, Options, ErrorMessage);
60+
initializeSettings();
61+
}
62+
5763
void AAirSimGameMode::BeginPlay()
5864
{
5965
try
6066
{
6167
UAirBlueprintLib::OnBeginPlay();
62-
initializeSettings();
6368
setUnrealEngineSettings();
6469
}
6570
catch (std::exception &ex)
@@ -78,6 +83,16 @@ void AAirSimGameMode::EndPlay(const EEndPlayReason::Type EndPlayReason)
7883
Super::EndPlay(EndPlayReason);
7984
}
8085

86+
void AAirSimGameMode::PreLogin(const FString& Options, const FString& Address, const FUniqueNetIdRepl& UniqueId, FString& ErrorMessage)
87+
{
88+
FString clientPassword = UGameplayStatics::ParseOption(Options, TEXT("password"));
89+
std::string serverPassword = msr::airlib::AirSimSettings::singleton().spectator_server_password;
90+
if(clientPassword != FString(serverPassword.c_str())) {
91+
// login attamed is blocked if ErrorMessage is set to non-null string
92+
ErrorMessage = FString(TEXT("Incorrect password"));
93+
}
94+
}
95+
8196
void AAirSimGameMode::PostLogin(APlayerController * newPlayer) {
8297
newPlayer->StartSpectatingOnly();
8398
}

UE4Project/Plugins/AirSim/Source/AirSimGameMode.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ class AIRSIM_API AAirSimGameMode : public AGameModeBase
1717
public:
1818
GENERATED_BODY()
1919

20+
virtual void InitGame(const FString & MapName, const FString & Options, FString & ErrorMessage) override;
2021
virtual void BeginPlay() override;
2122
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
23+
virtual void PreLogin(const FString& Options, const FString& Address, const FUniqueNetIdRepl& UniqueId, FString& ErrorMessage) override;
2224
virtual void PostLogin(APlayerController * NewPlayer) override;
2325

2426

docs/spectator.md

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,48 @@
22
The spectator provides an eye into the virtual world from an external computer.
33
Through a network connection the virtual world state is replicated and shown on the screen.
44
The user can operate the camera with its mouse and keyboard.
5+
Spectators are not able to interact with the world
56

6-
## Launching the spectator
7+
## Launching the server
78

89
A simulator launched as 'server' will accept external viewers (spectators) to join the game.
9-
The spectators are not able to interact with the world.
10-
Spectators can enter the ip of the server in the main menu to connect to a running simulator.
11-
Multiple simultaneous spectators in a single world should work as well.
10+
You can launch the simulation as a server in the main menu by pressing the 'TODO' button.
1211

13-
> If a spectator loses connection to the server it will go back to the main menu.
14-
15-
If you want to give access to clients from external computers you must ensure the specified port is accessible.
16-
In most cases you will have to add a firewall rule to allow the traffic.
12+
The server will run on port 7777 port, make sure spectators can connect to it.
13+
In most cases you will need to add a firewall rule to allow TCP and UDP traffic.
1714
When behind a router you might need to do some port forwarding.
18-
Both TCP and UDP traffic must be able to travel from client to server on port 7777.
1915

20-
To skip the menu and launch the game as server or spectator directly, you can use the following commandline options:
16+
To skip the menu and launch the game as server directly, you can use the following command:
17+
18+
```
19+
FSDS.exe /Game/TrainingMap?listen
20+
```
21+
This opens the TrainingMap and allows external clients (spectators) to connect.
22+
23+
Within the `settings.json` you can configure the server password.
24+
Using the password is usefull to prevent trolls and curious people from connecting to the simulator and breaking the simulator.
2125

22-
**Run the game as a server**
2326
```
24-
FSDS.exe /Game/TrainingMap?listen -log
27+
{
28+
"SpectatorPassword": "password",
29+
...
2530
```
26-
This runs the simulator like normal but now external clients (spectators) are welcome to connect.
31+
If the password is not configured in the settings.json, the password is set to `password`.
32+
At this moment it is not possible to start a server without password.
33+
34+
## Launching the spectator
35+
Spectators can enter the ip of the server in the main menu to connect to a running simulator.
36+
Multiple simultaneous spectators in a single world should work as well.
37+
If a spectator loses connection to the server it will go back to the main menu.
2738

39+
To skip the menu and launch the spectator directly, you can use the following command:
2840

29-
**Running the spectator**
3041
```
31-
FSDS.exe 0.0.0.0 -log
42+
FSDS.exe 0.0.0.0?password=123456
3243
```
33-
Where `0.0.0.0` is replaced by the external ip of the server.
44+
Where `0.0.0.0` is replaced by the external ip of the server and `123456` is replaced by the server password.
3445

46+
**If you enter a wrong password you are taken back to the main menu. No error will be shown.**
3547

3648
## Using the spectator
3749

settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"SettingsVersion": 1.2,
44
"ViewMode": "SpringArmChase",
55
"ClockSpeed": 1.0,
6+
"SpectatorServerPassword": "password",
67
"PawnPaths": {
78
"DefaultCar": { "PawnBP": "Class'/AirSim/VehicleAdv/Cars/TechnionCar/TechnionCarPawn.TechnionCarPawn_C'" }
89
},

0 commit comments

Comments
 (0)