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