Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
3e7dc503
Commit
3e7dc503
authored
Apr 18, 2022
by
Melledy
Committed by
GitHub
Apr 18, 2022
Browse files
Merge pull request #16 from pedox/feat-dispatch-server
Added Config for using http server with non SSL
parents
efc9a4b3
0ff6ea42
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/Config.java
View file @
3e7dc503
...
@@ -6,12 +6,15 @@ public final class Config {
...
@@ -6,12 +6,15 @@ public final class Config {
public
int
DispatchServerPort
=
443
;
public
int
DispatchServerPort
=
443
;
public
String
DispatchServerKeystorePath
=
"./keystore.p12"
;
public
String
DispatchServerKeystorePath
=
"./keystore.p12"
;
public
String
DispatchServerKeystorePassword
=
""
;
public
String
DispatchServerKeystorePassword
=
""
;
public
Boolean
UseSSL
=
true
;
public
String
GameServerName
=
"Test"
;
public
String
GameServerName
=
"Test"
;
public
String
GameServerIp
=
"127.0.0.1"
;
public
String
GameServerIp
=
"127.0.0.1"
;
public
String
GameServerPublicIp
=
""
;
public
String
GameServerPublicIp
=
""
;
public
int
GameServerPort
=
22102
;
public
int
GameServerPort
=
22102
;
public
int
UploadLogPort
=
80
;
public
String
DatabaseUrl
=
"mongodb://localhost:27017"
;
public
String
DatabaseUrl
=
"mongodb://localhost:27017"
;
public
String
DatabaseCollection
=
"grasscutter"
;
public
String
DatabaseCollection
=
"grasscutter"
;
...
...
src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java
View file @
3e7dc503
...
@@ -139,22 +139,28 @@ public final class DispatchServer {
...
@@ -139,22 +139,28 @@ public final class DispatchServer {
}
}
public
void
start
()
throws
Exception
{
public
void
start
()
throws
Exception
{
HttpsServer
server
=
HttpsServer
.
create
(
getAddress
(),
0
);
HttpServer
server
;
SSLContext
sslContext
=
SSLContext
.
getInstance
(
"TLS"
);
if
(
Grasscutter
.
getConfig
().
UseSSL
)
{
HttpsServer
httpsServer
;
try
(
FileInputStream
fis
=
new
FileInputStream
(
Grasscutter
.
getConfig
().
DispatchServerKeystorePath
))
{
httpsServer
=
HttpsServer
.
create
(
getAddress
(),
0
);
char
[]
keystorePassword
=
Grasscutter
.
getConfig
().
DispatchServerKeystorePassword
.
toCharArray
();
SSLContext
sslContext
=
SSLContext
.
getInstance
(
"TLS"
);
KeyStore
ks
=
KeyStore
.
getInstance
(
"PKCS12"
);
try
(
FileInputStream
fis
=
new
FileInputStream
(
Grasscutter
.
getConfig
().
DispatchServerKeystorePath
))
{
ks
.
load
(
fis
,
keystorePassword
);
char
[]
keystorePassword
=
Grasscutter
.
getConfig
().
DispatchServerKeystorePassword
.
toCharArray
();
KeyManagerFactory
kmf
=
KeyManagerFactory
.
getInstance
(
"SunX509"
);
KeyStore
ks
=
KeyStore
.
getInstance
(
"PKCS12"
);
kmf
.
init
(
ks
,
keystorePassword
);
ks
.
load
(
fis
,
keystorePassword
);
KeyManagerFactory
kmf
=
KeyManagerFactory
.
getInstance
(
"SunX509"
);
sslContext
.
init
(
kmf
.
getKeyManagers
(),
null
,
null
);
kmf
.
init
(
ks
,
keystorePassword
);
server
.
setHttpsConfigurator
(
new
HttpsConfigurator
(
sslContext
));
sslContext
.
init
(
kmf
.
getKeyManagers
(),
null
,
null
);
}
catch
(
Exception
e
)
{
Grasscutter
.
getLogger
().
error
(
"No SSL cert found!"
);
httpsServer
.
setHttpsConfigurator
(
new
HttpsConfigurator
(
sslContext
));
return
;
server
=
httpsServer
;
}
catch
(
Exception
e
)
{
Grasscutter
.
getLogger
().
error
(
"No SSL cert found!"
);
return
;
}
}
else
{
server
=
HttpServer
.
create
(
getAddress
(),
0
);
}
}
server
.
createContext
(
"/"
,
t
->
{
server
.
createContext
(
"/"
,
t
->
{
...
@@ -396,7 +402,7 @@ public final class DispatchServer {
...
@@ -396,7 +402,7 @@ public final class DispatchServer {
overseaLogServer
.
start
();
overseaLogServer
.
start
();
Grasscutter
.
getLogger
().
info
(
"Log server (overseauspider) started on port "
+
8888
);
Grasscutter
.
getLogger
().
info
(
"Log server (overseauspider) started on port "
+
8888
);
HttpServer
uploadLogServer
=
HttpServer
.
create
(
new
InetSocketAddress
(
Grasscutter
.
getConfig
().
DispatchServerIp
,
80
),
0
);
HttpServer
uploadLogServer
=
HttpServer
.
create
(
new
InetSocketAddress
(
Grasscutter
.
getConfig
().
DispatchServerIp
,
Grasscutter
.
getConfig
().
UploadLogPort
),
0
);
uploadLogServer
.
createContext
(
// log-upload-os.mihoyo.com
uploadLogServer
.
createContext
(
// log-upload-os.mihoyo.com
"/crash/dataUpload"
,
"/crash/dataUpload"
,
new
DispatchHttpJsonHandler
(
"{\"code\":0}"
)
new
DispatchHttpJsonHandler
(
"{\"code\":0}"
)
...
@@ -413,7 +419,7 @@ public final class DispatchServer {
...
@@ -413,7 +419,7 @@ public final class DispatchServer {
os
.
close
();
os
.
close
();
});
});
uploadLogServer
.
start
();
uploadLogServer
.
start
();
Grasscutter
.
getLogger
().
info
(
"Log server (log-upload-os) started on port "
+
80
);
Grasscutter
.
getLogger
().
info
(
"Log server (log-upload-os) started on port "
+
Grasscutter
.
getConfig
().
UploadLogPort
);
}
}
private
Map
<
String
,
String
>
parseQueryString
(
String
qs
)
{
private
Map
<
String
,
String
>
parseQueryString
(
String
qs
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment