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
5d7edc38
Commit
5d7edc38
authored
May 14, 2022
by
KingRainbow44
Browse files
Implement PR #657
parent
0dcf0862
Changes
3
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/Configuration.java
View file @
5d7edc38
package
emu.grasscutter
;
import
emu.grasscutter.utils.ConfigContainer
;
import
emu.grasscutter.utils.ConfigContainer.*
;
import
java.util.Locale
;
...
...
@@ -40,6 +41,7 @@ public final class Configuration extends ConfigContainer {
public
static
final
Encryption
HTTP_ENCRYPTION
=
config
.
server
.
http
.
encryption
;
public
static
final
Policies
HTTP_POLICIES
=
config
.
server
.
http
.
policies
;
public
static
final
Files
HTTP_STATIC_FILES
=
config
.
server
.
http
.
files
;
public
static
final
GameOptions
GAME_OPTIONS
=
config
.
server
.
game
.
gameOptions
;
public
static
final
GameOptions
.
InventoryLimits
INVENTORY_LIMITS
=
config
.
server
.
game
.
gameOptions
.
inventoryLimits
;
...
...
src/main/java/emu/grasscutter/server/http/HttpServer.java
View file @
5d7edc38
...
...
@@ -2,13 +2,16 @@ package emu.grasscutter.server.http;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter.ServerDebugMode
;
import
emu.grasscutter.utils.FileUtils
;
import
express.Express
;
import
express.http.MediaType
;
import
io.javalin.Javalin
;
import
org.eclipse.jetty.server.Server
;
import
org.eclipse.jetty.server.ServerConnector
;
import
org.eclipse.jetty.util.ssl.SslContextFactory
;
import
java.io.File
;
import
java.io.IOException
;
import
static
emu
.
grasscutter
.
Configuration
.*;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
...
...
@@ -62,7 +65,7 @@ public final class HttpServer {
var
sslContextFactory
=
new
SslContextFactory
.
Server
();
var
keystoreFile
=
new
File
(
HTTP_ENCRYPTION
.
keystore
);
if
(!
keystoreFile
.
exists
())
{
;
if
(!
keystoreFile
.
exists
())
{
HTTP_ENCRYPTION
.
useEncryption
=
false
;
HTTP_ENCRYPTION
.
useInRouting
=
false
;
...
...
@@ -137,7 +140,10 @@ public final class HttpServer {
*/
public
static
class
DefaultRequestRouter
implements
Router
{
@Override
public
void
applyRoutes
(
Express
express
,
Javalin
handle
)
{
express
.
get
(
"/"
,
(
req
,
res
)
->
res
.
send
(
"""
express
.
get
(
"/"
,
(
request
,
response
)
->
{
File
file
=
new
File
(
HTTP_STATIC_FILES
.
errorFile
);
if
(!
file
.
exists
())
response
.
send
(
"""
<!DOCTYPE html>
<html>
<head>
...
...
@@ -145,7 +151,14 @@ public final class HttpServer {
</head>
<body>%s</body>
</html>
"""
.
formatted
(
translate
(
"messages.status.welcome"
))));
"""
.
formatted
(
translate
(
"messages.status.welcome"
)));
else
{
final
var
filePath
=
file
.
getPath
();
final
MediaType
fromExtension
=
MediaType
.
getByExtension
(
filePath
.
substring
(
filePath
.
lastIndexOf
(
"."
)
+
1
));
response
.
type
((
fromExtension
!=
null
)
?
fromExtension
.
getMIME
()
:
"text/plain"
)
.
send
(
FileUtils
.
read
(
filePath
));
}
});
}
}
...
...
@@ -158,6 +171,9 @@ public final class HttpServer {
if
(
SERVER
.
debugLevel
==
ServerDebugMode
.
MISSING
)
Grasscutter
.
getLogger
().
info
(
translate
(
"messages.dispatch.unhandled_request_error"
,
context
.
method
(),
context
.
url
()));
context
.
contentType
(
"text/html"
);
File
file
=
new
File
(
HTTP_STATIC_FILES
.
errorFile
);
if
(!
file
.
exists
())
context
.
result
(
"""
<!DOCTYPE html>
<html>
...
...
@@ -170,6 +186,12 @@ public final class HttpServer {
</
body
>
</
html
>
""");
else {
final var filePath = file.getPath();
final MediaType fromExtension = MediaType.getByExtension(filePath.substring(filePath.lastIndexOf("
.
") + 1));
context.contentType((fromExtension != null) ? fromExtension.getMIME() : "
text
/
plain
"
)
.
result
(
FileUtils
.
read
(
filePath
));
}
});
}
}
...
...
src/main/java/emu/grasscutter/utils/ConfigContainer.java
View file @
5d7edc38
...
...
@@ -17,7 +17,7 @@ import static emu.grasscutter.Grasscutter.config;
*/
public
class
ConfigContainer
{
private
static
int
version
()
{
return
2
;
return
3
;
}
/**
...
...
@@ -125,6 +125,7 @@ public class ConfigContainer {
public
Encryption
encryption
=
new
Encryption
();
public
Policies
policies
=
new
Policies
();
public
Files
files
=
new
Files
();
}
public
static
class
Game
{
...
...
@@ -228,6 +229,11 @@ public class ConfigContainer {
public String signature = "
Welcome
to
Grasscutter
!
";
}
public static class Files {
public String indexFile = "
./
index
.
html
";
public String errorFile = "
./
404
.
html
";
}
/* Objects. */
public static class Region {
...
...
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