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
3a216bf1
Commit
3a216bf1
authored
May 15, 2022
by
Hotaru
Committed by
Melledy
May 14, 2022
Browse files
Move gacha files to separate directory and refactor file serving
parent
159feb40
Changes
7
Show whitespace changes
Inline
Side-by-side
data/gacha
_
details.html
→
data/gacha
/
details.html
View file @
3a216bf1
...
@@ -84,7 +84,7 @@
...
@@ -84,7 +84,7 @@
var
fiveStarItems
=
{{
FIVE_STARS
}};
var
fiveStarItems
=
{{
FIVE_STARS
}};
var
fourStarItems
=
{{
FOUR_STARS
}};
var
fourStarItems
=
{{
FOUR_STARS
}};
var
threeStarItems
=
{{
THREE_STARS
}};
var
threeStarItems
=
{{
THREE_STARS
}};
var
lang
=
"
{{LANGUAGE}}
"
;
var
lang
=
"
{{LANGUAGE}}
"
.
toLowerCase
()
;
function
getNameForId
(
itemId
)
{
function
getNameForId
(
itemId
)
{
if
(
mappings
[
lang
]
!=
null
&&
mappings
[
lang
][
itemId
]
!=
null
)
{
if
(
mappings
[
lang
]
!=
null
&&
mappings
[
lang
][
itemId
]
!=
null
)
{
...
...
data/gacha
_
records.html
→
data/gacha
/
records.html
View file @
3a216bf1
...
@@ -58,7 +58,7 @@
...
@@ -58,7 +58,7 @@
<!-- Otherwise you may onle see number IDs in the gacha record -->
<!-- Otherwise you may onle see number IDs in the gacha record -->
<script
type=
"text/javascript"
src=
"/gacha/mappings"
></script>
<script
type=
"text/javascript"
src=
"/gacha/mappings"
></script>
<script>
<script>
record
=
{{
REPLACE_RECORD
}};
record
s
=
{{
REPLACE_RECORD
S
}};
maxPage
=
{{
REPLACE_MAXPAGE
}};
maxPage
=
{{
REPLACE_MAXPAGE
}};
mappings
[
'
default
'
]
=
mappings
[
'
en-us
'
];
// make en-us as default/fallback option
mappings
[
'
default
'
]
=
mappings
[
'
en-us
'
];
// make en-us as default/fallback option
...
@@ -111,7 +111,8 @@
...
@@ -111,7 +111,8 @@
</footer>
</footer>
<script>
<script>
var
lang
=
new
window
.
URLSearchParams
(
window
.
location
.
search
).
get
(
"
lang
"
);
var
lang
=
"
{{LANGUAGE}}
"
.
toLowerCase
();
function
itemMapper
(
itemID
)
{
function
itemMapper
(
itemID
)
{
if
(
mappings
[
lang
]
!=
null
&&
mappings
[
lang
][
itemID
]
!=
null
)
{
if
(
mappings
[
lang
]
!=
null
&&
mappings
[
lang
][
itemID
]
!=
null
)
{
var
entry
=
mappings
[
lang
][
itemID
];
var
entry
=
mappings
[
lang
][
itemID
];
...
@@ -128,17 +129,19 @@
...
@@ -128,17 +129,19 @@
}
}
return
"
<span class='blue'>
"
+
itemID
+
"
</span>
"
;
return
"
<span class='blue'>
"
+
itemID
+
"
</span>
"
;
}
}
(
function
(){
(
function
(){
var
container
=
document
.
getElementById
(
"
container
"
);
var
container
=
document
.
getElementById
(
"
container
"
);
record
.
forEach
(
element
=>
{
record
s
.
forEach
(
element
=>
{
var
e
=
document
.
createElement
(
"
tr
"
);
var
e
=
document
.
createElement
(
"
tr
"
);
e
.
innerHTML
=
"
<td>
"
+
(
new
Date
(
element
.
time
).
toLocaleString
(
lang
))
+
"
</td><td>
"
+
itemMapper
(
element
.
item
)
+
"
</td>
"
;
e
.
innerHTML
=
"
<td>
"
+
(
new
Date
(
element
.
time
).
toLocaleString
(
lang
))
+
"
</td><td>
"
+
itemMapper
(
element
.
item
)
+
"
</td>
"
;
container
.
appendChild
(
e
);
container
.
appendChild
(
e
);
});
});
// setup pagenation buttons
// setup pagenation buttons
var
page
=
parseInt
(
new
window
.
URLSearchParams
(
window
.
location
.
search
).
get
(
"
p
"
));
var
page
=
parseInt
(
new
window
.
URLSearchParams
(
window
.
location
.
search
).
get
(
"
p
"
));
if
(
!
page
){
if
(
!
page
)
{
page
=
0
;
page
=
0
;
}
}
document
.
getElementById
(
"
curpage
"
).
innerText
=
page
+
1
;
document
.
getElementById
(
"
curpage
"
).
innerText
=
page
+
1
;
...
@@ -147,7 +150,6 @@
...
@@ -147,7 +150,6 @@
document
.
getElementById
(
"
prev
"
).
href
=
href
.
toString
();
document
.
getElementById
(
"
prev
"
).
href
=
href
.
toString
();
href
.
searchParams
.
set
(
"
p
"
,
page
+
1
);
href
.
searchParams
.
set
(
"
p
"
,
page
+
1
);
document
.
getElementById
(
"
next
"
).
href
=
href
.
toString
();
document
.
getElementById
(
"
next
"
).
href
=
href
.
toString
();
if
(
page
<=
0
)
{
if
(
page
<=
0
)
{
document
.
getElementById
(
"
prev
"
).
style
.
display
=
"
none
"
;
document
.
getElementById
(
"
prev
"
).
style
.
display
=
"
none
"
;
}
}
...
@@ -157,11 +159,10 @@
...
@@ -157,11 +159,10 @@
// setup gacha type info
// setup gacha type info
var
gachaType
=
new
window
.
URLSearchParams
(
window
.
location
.
search
).
get
(
"
gachaType
"
);
var
gachaType
=
new
window
.
URLSearchParams
(
window
.
location
.
search
).
get
(
"
gachaType
"
);
var
gachaString
;
if
(
mappings
[
lang
]
!=
null
&&
mappings
[
lang
][
gachaType
]
!=
null
)
{
if
(
mappings
[
lang
]
!=
null
&&
mappings
[
lang
][
gachaType
]
!=
null
)
{
gachaString
=
mappings
[
lang
][
gachaType
];
var
gachaString
=
mappings
[
lang
][
gachaType
];
}
else
{
}
else
{
gachaString
=
mappings
[
'
default
'
][
gachaType
];
var
gachaString
=
mappings
[
'
default
'
][
gachaType
];
if
(
gachaString
==
null
)
{
if
(
gachaString
==
null
)
{
gachaString
=
gachaType
;
gachaString
=
gachaType
;
}
}
...
...
src/main/java/emu/grasscutter/server/http/handlers/GachaHandler.java
View file @
3a216bf1
...
@@ -17,6 +17,7 @@ import io.javalin.Javalin;
...
@@ -17,6 +17,7 @@ import io.javalin.Javalin;
import
io.javalin.http.staticfiles.Location
;
import
io.javalin.http.staticfiles.Location
;
import
java.io.File
;
import
java.io.File
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.LinkedHashSet
;
import
java.util.LinkedHashSet
;
import
java.util.Set
;
import
java.util.Set
;
...
@@ -30,11 +31,8 @@ import static emu.grasscutter.utils.Language.translate;
...
@@ -30,11 +31,8 @@ import static emu.grasscutter.utils.Language.translate;
public
final
class
GachaHandler
implements
Router
{
public
final
class
GachaHandler
implements
Router
{
private
final
String
gachaMappings
;
private
final
String
gachaMappings
;
private
static
String
recordsTemplate
=
""
;
private
static
String
detailsTemplate
=
""
;
public
GachaHandler
()
{
public
GachaHandler
()
{
this
.
gachaMappings
=
Utils
.
toFilePath
(
DATA
(
"/gacha
_
mappings.js"
));
this
.
gachaMappings
=
Utils
.
toFilePath
(
DATA
(
"/gacha
/
mappings.js"
));
if
(!(
new
File
(
this
.
gachaMappings
).
exists
()))
{
if
(!(
new
File
(
this
.
gachaMappings
).
exists
()))
{
try
{
try
{
Tools
.
createGachaMapping
(
this
.
gachaMappings
);
Tools
.
createGachaMapping
(
this
.
gachaMappings
);
...
@@ -42,12 +40,6 @@ public final class GachaHandler implements Router {
...
@@ -42,12 +40,6 @@ public final class GachaHandler implements Router {
Grasscutter
.
getLogger
().
warn
(
"Failed to create gacha mappings."
,
exception
);
Grasscutter
.
getLogger
().
warn
(
"Failed to create gacha mappings."
,
exception
);
}
}
}
}
var
templateFile
=
new
File
(
DATA
(
"/gacha_records.html"
));
recordsTemplate
=
templateFile
.
exists
()
?
new
String
(
FileUtils
.
read
(
templateFile
))
:
"{{REPLACE_RECORD}}"
;
templateFile
=
new
File
(
Utils
.
toFilePath
(
DATA
(
"/gacha_details.html"
)));
detailsTemplate
=
templateFile
.
exists
()
?
new
String
(
FileUtils
.
read
(
templateFile
))
:
null
;
}
}
@Override
public
void
applyRoutes
(
Express
express
,
Javalin
handle
)
{
@Override
public
void
applyRoutes
(
Express
express
,
Javalin
handle
)
{
...
@@ -58,7 +50,24 @@ public final class GachaHandler implements Router {
...
@@ -58,7 +50,24 @@ public final class GachaHandler implements Router {
}
}
private
static
void
gachaRecords
(
Request
request
,
Response
response
)
{
private
static
void
gachaRecords
(
Request
request
,
Response
response
)
{
var
sessionKey
=
request
.
query
(
"s"
);
File
recordsTemplate
=
new
File
(
Utils
.
toFilePath
(
DATA
(
"gacha/records.html"
)));
if
(!
recordsTemplate
.
exists
())
{
Grasscutter
.
getLogger
().
warn
(
"File does not exist: "
+
recordsTemplate
);
response
.
status
(
500
);
return
;
}
String
sessionKey
=
request
.
query
(
"s"
);
Account
account
=
DatabaseHelper
.
getAccountBySessionKey
(
sessionKey
);
if
(
account
==
null
)
{
response
.
status
(
403
).
send
(
"Requested account was not found"
);
return
;
}
Player
player
=
Grasscutter
.
getGameServer
().
getPlayerByUid
(
account
.
getPlayerUid
());
if
(
player
==
null
)
{
response
.
status
(
403
).
send
(
"No player associated with requested account"
);
return
;
}
int
page
=
0
,
gachaType
=
0
;
int
page
=
0
,
gachaType
=
0
;
if
(
request
.
query
(
"p"
)
!=
null
)
if
(
request
.
query
(
"p"
)
!=
null
)
...
@@ -66,35 +75,38 @@ public final class GachaHandler implements Router {
...
@@ -66,35 +75,38 @@ public final class GachaHandler implements Router {
if
(
request
.
query
(
"gachaType"
)
!=
null
)
if
(
request
.
query
(
"gachaType"
)
!=
null
)
gachaType
=
Integer
.
parseInt
(
request
.
query
(
"gachaType"
));
gachaType
=
Integer
.
parseInt
(
request
.
query
(
"gachaType"
));
// Get account from session key.
String
records
=
DatabaseHelper
.
getGachaRecords
(
player
.
getUid
(),
page
,
gachaType
).
toString
();
var
account
=
DatabaseHelper
.
getAccountBySessionKey
(
sessionKey
);
long
maxPage
=
DatabaseHelper
.
getGachaRecordsMaxPage
(
player
.
getUid
(),
page
,
gachaType
);
if
(
account
==
null
)
// Send response.
response
.
status
(
404
).
send
(
"Unable to find account."
);
else
{
String
records
=
DatabaseHelper
.
getGachaRecords
(
account
.
getPlayerUid
(),
gachaType
,
page
).
toString
();
long
maxPage
=
DatabaseHelper
.
getGachaRecordsMaxPage
(
account
.
getPlayerUid
(),
page
,
gachaType
);
response
.
send
(
recordsTemplate
String
template
=
new
String
(
FileUtils
.
read
(
recordsTemplate
),
StandardCharsets
.
UTF_8
)
.
replace
(
"{{REPLACE_RECORD}}"
,
records
)
.
replace
(
"{{REPLACE_RECORDS}}"
,
records
)
.
replace
(
"{{REPLACE_MAXPAGE}}"
,
String
.
valueOf
(
maxPage
)));
.
replace
(
"{{REPLACE_MAXPAGE}}"
,
String
.
valueOf
(
maxPage
))
}
.
replace
(
"{{LANGUAGE}}"
,
Utils
.
getLanguageCode
(
account
.
getLocale
()));
response
.
send
(
template
);
}
}
private
static
void
gachaDetails
(
Request
request
,
Response
response
)
{
private
static
void
gachaDetails
(
Request
request
,
Response
response
)
{
String
template
=
detailsTemplate
;
File
detailsTemplate
=
new
File
(
Utils
.
toFilePath
(
DATA
(
"gacha/details.html"
)));
if
(!
detailsTemplate
.
exists
())
{
Grasscutter
.
getLogger
().
warn
(
"File does not exist: "
+
detailsTemplate
);
response
.
status
(
500
);
return
;
}
// Get player info (for langauge).
String
sessionKey
=
request
.
query
(
"s"
);
String
sessionKey
=
request
.
query
(
"s"
);
Account
account
=
DatabaseHelper
.
getAccountBySessionKey
(
sessionKey
);
Account
account
=
DatabaseHelper
.
getAccountBySessionKey
(
sessionKey
);
if
(
account
==
null
)
{
response
.
status
(
403
).
send
(
"Requested account was not found"
);
return
;
}
Player
player
=
Grasscutter
.
getGameServer
().
getPlayerByUid
(
account
.
getPlayerUid
());
Player
player
=
Grasscutter
.
getGameServer
().
getPlayerByUid
(
account
.
getPlayerUid
());
if
(
player
==
null
)
{
// If the template was not loaded, return an error.
response
.
status
(
403
).
send
(
"No player associated with requested account"
);
if
(
detailsTemplate
==
null
)
{
response
.
send
(
translate
(
player
,
"gacha.details.template_missing"
));
return
;
return
;
}
}
String
template
=
new
String
(
FileUtils
.
read
(
detailsTemplate
),
StandardCharsets
.
UTF_8
);
// Add translated title etc. to the page.
// Add translated title etc. to the page.
template
=
template
.
replace
(
"{{TITLE}}"
,
translate
(
player
,
"gacha.details.title"
))
template
=
template
.
replace
(
"{{TITLE}}"
,
translate
(
player
,
"gacha.details.title"
))
.
replace
(
"{{AVAILABLE_FIVE_STARS}}"
,
translate
(
player
,
"gacha.details.available_five_stars"
))
.
replace
(
"{{AVAILABLE_FIVE_STARS}}"
,
translate
(
player
,
"gacha.details.available_five_stars"
))
...
...
src/main/resources/languages/en-US.json
View file @
3a216bf1
...
@@ -380,8 +380,7 @@
...
@@ -380,8 +380,7 @@
"title"
:
"Banner Details"
,
"title"
:
"Banner Details"
,
"available_five_stars"
:
"Available 5-star Items"
,
"available_five_stars"
:
"Available 5-star Items"
,
"available_four_stars"
:
"Available 4-star Items"
,
"available_four_stars"
:
"Available 4-star Items"
,
"available_three_stars"
:
"Available 3-star Items"
,
"available_three_stars"
:
"Available 3-star Items"
"template_missing"
:
"data/gacha_details.html is missing."
}
}
}
}
}
}
src/main/resources/languages/pl-PL.json
View file @
3a216bf1
...
@@ -308,8 +308,7 @@
...
@@ -308,8 +308,7 @@
"title"
:
"Banner Details"
,
"title"
:
"Banner Details"
,
"available_five_stars"
:
"Available 5-star Items"
,
"available_five_stars"
:
"Available 5-star Items"
,
"available_four_stars"
:
"Available 4-star Items"
,
"available_four_stars"
:
"Available 4-star Items"
,
"available_three_stars"
:
"Available 3-star Items"
,
"available_three_stars"
:
"Available 3-star Items"
"template_missing"
:
"data/gacha_details.html is missing."
}
}
}
}
}
}
\ No newline at end of file
src/main/resources/languages/zh-CN.json
View file @
3a216bf1
...
@@ -379,8 +379,7 @@
...
@@ -379,8 +379,7 @@
"title"
:
"祈愿详情"
,
"title"
:
"祈愿详情"
,
"available_five_stars"
:
"可获得的5星物品"
,
"available_five_stars"
:
"可获得的5星物品"
,
"available_four_stars"
:
"可获得的4星物品"
,
"available_four_stars"
:
"可获得的4星物品"
,
"available_three_stars"
:
"可获得的3星物品"
,
"available_three_stars"
:
"可获得的3星物品"
"template_missing"
:
"缺失文件:data/gacha_details.html"
}
}
}
}
}
}
src/main/resources/languages/zh-TW.json
View file @
3a216bf1
...
@@ -371,8 +371,7 @@
...
@@ -371,8 +371,7 @@
"title"
:
"祈願詳情"
,
"title"
:
"祈願詳情"
,
"available_five_stars"
:
"可獲得的5星物品"
,
"available_five_stars"
:
"可獲得的5星物品"
,
"available_four_stars"
:
"可獲得的4星物品"
,
"available_four_stars"
:
"可獲得的4星物品"
,
"available_three_stars"
:
"可獲得的3星物品"
,
"available_three_stars"
:
"可獲得的3星物品"
"template_missing"
:
"data/gacha_details.html 不存在。"
}
}
}
}
}
}
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