File tree 8 files changed +51
-10
lines changed
game-service/Game.Application
maple-fighters/Assets/Maple Fighters
ScriptableObjects/Configurations 8 files changed +51
-10
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ services:
7
7
REACT_APP_ENV : Production
8
8
REMOVE_CF_IPS : " false"
9
9
ports :
10
- - 80:80
10
+ - 443:443
11
11
depends_on :
12
12
- game-service
13
13
game-service :
@@ -16,7 +16,7 @@ services:
16
16
expose :
17
17
- 50051
18
18
environment :
19
- URL : ws ://0.0.0.0:50051
19
+ URL : wss ://0.0.0.0:50051
20
20
FLECK_LOG : Info
21
21
IM_LOG : Debug
22
22
GAME_LOG : Debug
Original file line number Diff line number Diff line change @@ -16,10 +16,24 @@ http {
16
16
server game-service:50051;
17
17
}
18
18
19
- server {
19
+ server {
20
20
listen 80 ;
21
21
server_name _;
22
22
23
+ # Redirect all HTTP requests to HTTPS
24
+ return 301 https://$host$request_uri ;
25
+ }
26
+
27
+ server {
28
+ listen 443 ssl;
29
+ server_name _;
30
+
31
+ # SSL configuration
32
+ ssl_certificate /etc/nginx/ssl/server.crt;
33
+ ssl_certificate_key /etc/nginx/ssl/server.key;
34
+ ssl_protocols TLSv1.2 TLSv1.3;
35
+ ssl_ciphers HIGH:!aNULL:!MD5;
36
+
23
37
limit_req zone=req burst=10 delay=5;
24
38
limit_req_status 444;
25
39
limit_rate 5m ;
31
45
}
32
46
33
47
location /game {
34
- # Source: https://github.com/nicokaiser/nginx-websocket-proxy/blob/master/simple-ws.conf
35
- # redirect all HTTP traffic to game-service
36
- proxy_pass http://game/;
48
+ # Upgrade to WebSocket protocol over HTTPS
49
+ proxy_pass https://game/;
37
50
proxy_set_header X-Real-IP $remote_addr ;
38
51
proxy_set_header Host $host ;
39
52
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
Original file line number Diff line number Diff line change 1
1
using System ;
2
+ using System . Security . Cryptography . X509Certificates ;
2
3
using DotNetEnv ;
3
4
using Fleck ;
4
5
using Game . Application ;
23
24
GameLog . Level = ( GameLogLevel ) Enum . Parse ( typeof ( GameLogLevel ) , gameLog ) ;
24
25
25
26
var url = Env . GetString ( "URL" ) ;
26
- var server = new WebSocketServer ( url ) ;
27
+ var certificatePassword = Env . GetString ( "CERT_PASSWORD" ) ;
28
+ var serverUri = new Uri ( url ) ;
29
+ var server = new WebSocketServer ( $ "{ serverUri . Scheme } ://{ serverUri . Host } :{ serverUri . Port } ") ;
27
30
var serverComponents = new ComponentCollection ( new IComponent [ ]
28
31
{
29
32
new IdGenerator ( ) ,
41
44
serverComponents ? . Dispose ( ) ;
42
45
} ;
43
46
47
+ if ( string . IsNullOrEmpty ( certificatePassword ) == false )
48
+ {
49
+ server . Certificate = new X509Certificate2 ( "server.pfx" , certificatePassword ) ;
50
+ }
51
+
44
52
server . Start ( ( connection ) =>
45
53
{
46
54
var id = idGenerator . GenerateId ( ) ;
Original file line number Diff line number Diff line change 2
2
docker build -t game-service .
3
3
4
4
run :
5
- docker run -p 50051:50051 game-service -e URL=ws://0.0.0.0:50051 \
5
+ docker run -p 50051:50051 game-service -e \
6
+ URL=ws://0.0.0.0:50051 \
6
7
FLECK_LOG=Info \
7
8
IM_LOG=Debug \
8
- GAME_LOG=Debug
9
+ GAME_LOG=Debug \
10
+ CONFIG_SOURCE=v2.0 \
11
+ MAX_CONNECTIONS=100
Original file line number Diff line number Diff line change @@ -14,12 +14,15 @@ MonoBehaviour:
14
14
m_EditorClassIdentifier :
15
15
HostingData :
16
16
- Name : Editor
17
+ Protocol : ws
17
18
Host : localhost
18
19
Environment : 0
19
20
- Name : Development
21
+ Protocol : ws
20
22
Host : localhost
21
23
Environment : 1
22
24
- Name : Production
25
+ Protocol : wss
23
26
Host : maplefighters.io
24
27
Environment : 2
25
28
Environment : 0
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ public class HostingData
7
7
{
8
8
public string Name ;
9
9
10
+ public string Protocol ;
11
+
10
12
public string Host ;
11
13
12
14
public HostingEnvironment Environment ;
Original file line number Diff line number Diff line change @@ -14,6 +14,18 @@ public class NetworkConfiguration : ScriptableSingleton<NetworkConfiguration>
14
14
15
15
public HostingEnvironment Environment ;
16
16
17
+ public string GetProtocol ( )
18
+ {
19
+ var hostingData =
20
+ HostingData . FirstOrDefault ( ( x ) => x . Environment == Environment ) ;
21
+ if ( hostingData != null )
22
+ {
23
+ return hostingData . Protocol ;
24
+ }
25
+
26
+ return string . Empty ;
27
+ }
28
+
17
29
public string GetHost ( )
18
30
{
19
31
var hostingData =
Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ private void Start()
77
77
78
78
var uriBuilder = new UriBuilder ( )
79
79
{
80
- Scheme = "ws" ,
80
+ Scheme = networkConfiguration . GetProtocol ( ) ,
81
81
Host = networkConfiguration . GetHost ( ) ,
82
82
Path = "game"
83
83
} ;
You can’t perform that action at this time.
0 commit comments