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
20e3b8ff
Commit
20e3b8ff
authored
May 14, 2022
by
ShiroSaki
Committed by
Melledy
May 13, 2022
Browse files
add support for announcement page
parent
82698d56
Changes
4
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
20e3b8ff
...
...
@@ -73,3 +73,4 @@ BuildConfig.java
# macOS
.DS_Store
data/hk4e/announcement/
data/GameAnnouncementList.json
View file @
20e3b8ff
...
...
@@ -57,5 +57,13 @@
"mi18n_name"
:
"Activity"
}
],
"timezone"
:
-5
"timezone"
:
-5
,
"alert"
:
false
,
"alert_id"
:
0
,
"pic_list"
:
[],
"pic_total"
:
0
,
"pic_type_list"
:
[],
"pic_alert"
:
false
,
"pic_alert_id"
:
0
,
"static_sign"
:
""
}
\ No newline at end of file
src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java
View file @
20e3b8ff
...
...
@@ -16,6 +16,7 @@ import emu.grasscutter.net.proto.RegionInfoOuterClass.RegionInfo;
import
emu.grasscutter.net.proto.RegionSimpleInfoOuterClass.RegionSimpleInfo
;
import
emu.grasscutter.server.dispatch.authentication.AuthenticationHandler
;
import
emu.grasscutter.server.dispatch.authentication.DefaultAuthenticationHandler
;
import
emu.grasscutter.server.dispatch.http.AnnouncementIndexHandler
;
import
emu.grasscutter.server.dispatch.http.GachaDetailsHandler
;
import
emu.grasscutter.server.dispatch.http.GachaRecordHandler
;
import
emu.grasscutter.server.dispatch.json.*
;
...
...
@@ -443,6 +444,11 @@ public final class DispatchServer {
// gacha details
httpServer
.
get
(
"/gacha/details"
,
new
GachaDetailsHandler
());
// announcement index
httpServer
.
get
(
"/hk4e/announcement/*"
,
new
AnnouncementIndexHandler
());
httpServer
.
get
(
"/sw.js"
,
new
AnnouncementIndexHandler
());
httpServer
.
get
(
"/dora/lib/vue/2.6.11/vue.min.js"
,
new
AnnouncementIndexHandler
());
// static file support for plugins
httpServer
.
raw
().
config
.
precompressStaticFiles
=
false
;
// If this isn't set to false, files such as images may appear corrupted when serving static files
...
...
src/main/java/emu/grasscutter/server/dispatch/http/AnnouncementIndexHandler.java
0 → 100644
View file @
20e3b8ff
package
emu.grasscutter.server.dispatch.http
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.database.DatabaseHelper
;
import
emu.grasscutter.game.Account
;
import
emu.grasscutter.utils.FileUtils
;
import
emu.grasscutter.utils.Utils
;
import
express.http.HttpContextHandler
;
import
express.http.Request
;
import
express.http.Response
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.Objects
;
import
static
emu
.
grasscutter
.
Configuration
.
DATA
;
public
class
AnnouncementIndexHandler
implements
HttpContextHandler
{
private
final
String
render_template
;
private
final
String
render_swjs
;
private
final
String
render_vueminjs
;
public
AnnouncementIndexHandler
()
{
File
template
=
new
File
(
Utils
.
toFilePath
(
DATA
(
"/hk4e/announcement/index.html"
)));
File
swjs
=
new
File
(
Utils
.
toFilePath
(
DATA
(
"/hk4e/announcement/sw.js"
)));
File
vueminjs
=
new
File
(
Utils
.
toFilePath
(
DATA
(
"/hk4e/announcement/vue.min.js"
)));
this
.
render_template
=
template
.
exists
()
?
new
String
(
FileUtils
.
read
(
template
))
:
null
;
this
.
render_swjs
=
swjs
.
exists
()
?
new
String
(
FileUtils
.
read
(
swjs
))
:
null
;
this
.
render_vueminjs
=
vueminjs
.
exists
()
?
new
String
(
FileUtils
.
read
(
vueminjs
))
:
null
;
}
@Override
public
void
handle
(
Request
req
,
Response
res
)
throws
IOException
{
if
(
Objects
.
equals
(
req
.
path
(),
"/sw.js"
))
{
res
.
send
(
render_swjs
);
}
else
if
(
Objects
.
equals
(
req
.
path
(),
"/hk4e/announcement/index.html"
))
{
res
.
send
(
render_template
);
}
else
if
(
Objects
.
equals
(
req
.
path
(),
"/dora/lib/vue/2.6.11/vue.min.js"
)){
res
.
send
(
render_vueminjs
);
}
else
{
File
renderFile
=
new
File
(
Utils
.
toFilePath
(
DATA
(
req
.
path
())));
if
(
renderFile
.
exists
()){
String
ext
=
req
.
path
().
substring
(
req
.
path
().
lastIndexOf
(
"."
)
+
1
);
switch
(
ext
){
case
"css"
:
res
.
type
(
"text/css"
);
res
.
send
(
FileUtils
.
read
(
renderFile
));
break
;
case
"js"
:
default
:
res
.
send
(
FileUtils
.
read
(
renderFile
));
break
;
}
}
else
{
Grasscutter
.
getLogger
().
info
(
"File not exist: "
+
req
.
path
());
}
}
}
}
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