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
359e8359
Commit
359e8359
authored
Jun 16, 2022
by
Melledy
Browse files
Refactor gacha banner proto creation to not do a lookup on the database
parent
2624f48a
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/gacha/GachaBanner.java
View file @
359e8359
...
...
@@ -138,13 +138,11 @@ public class GachaBanner {
default
->
(
eventChance
>
-
1
)
?
eventChance
:
eventChance5
;
};
}
@Deprecated
public
GachaInfo
toProto
()
{
return
toProto
(
""
);
}
public
GachaInfo
toProto
(
String
sessionKey
)
{
public
GachaInfo
toProto
(
Player
player
)
{
// TODO: use other Nonce/key insteadof session key to ensure the overall security for the player
String
sessionKey
=
player
.
getAccount
().
getSessionKey
();
String
record
=
"http"
+
(
HTTP_ENCRYPTION
.
useInRouting
?
"s"
:
""
)
+
"://"
+
lr
(
HTTP_INFO
.
accessAddress
,
HTTP_INFO
.
bindAddress
)
+
":"
+
lr
(
HTTP_INFO
.
accessPort
,
HTTP_INFO
.
bindPort
)
...
...
@@ -176,9 +174,7 @@ public class GachaBanner {
.
setGachaTimesLimit
(
Integer
.
MAX_VALUE
)
.
setGachaSortId
(
this
.
getSortId
());
if
(
hasEpitomized
()
&&
!
sessionKey
.
isEmpty
())
{
Account
account
=
DatabaseHelper
.
getAccountBySessionKey
(
sessionKey
);
Player
player
=
Grasscutter
.
getGameServer
().
getPlayerByAccountId
(
account
.
getId
());
if
(
hasEpitomized
())
{
PlayerGachaBannerInfo
gachaInfo
=
player
.
getGachaInfo
().
getBannerInfo
(
this
);
info
.
setWishItemId
(
gachaInfo
.
getWishItemId
())
...
...
src/main/java/emu/grasscutter/game/gacha/GachaManager.java
View file @
359e8359
...
...
@@ -48,8 +48,7 @@ import static emu.grasscutter.Configuration.*;
public
class
GachaManager
{
private
final
GameServer
server
;
private
final
Int2ObjectMap
<
GachaBanner
>
gachaBanners
;
private
GetGachaInfoRsp
cachedProto
;
WatchService
watchService
;
private
WatchService
watchService
;
private
static
final
int
starglitterId
=
221
;
private
static
final
int
stardustId
=
222
;
...
...
@@ -88,9 +87,6 @@ public class GachaManager {
getGachaBanners
().
put
(
banner
.
getScheduleId
(),
banner
);
}
Grasscutter
.
getLogger
().
info
(
"Banners successfully loaded."
);
this
.
cachedProto
=
createProto
();
}
else
{
Grasscutter
.
getLogger
().
error
(
"Unable to load banners. Banners size is 0."
);
}
...
...
@@ -421,18 +417,7 @@ public class GachaManager {
}
}
@Deprecated
private
synchronized
GetGachaInfoRsp
createProto
()
{
GetGachaInfoRsp
.
Builder
proto
=
GetGachaInfoRsp
.
newBuilder
().
setGachaRandom
(
12345
);
for
(
GachaBanner
banner
:
getGachaBanners
().
values
())
{
proto
.
addGachaInfoList
(
banner
.
toProto
());
}
return
proto
.
build
();
}
private
synchronized
GetGachaInfoRsp
createProto
(
String
sessionKey
)
{
private
synchronized
GetGachaInfoRsp
createProto
(
Player
player
)
{
GetGachaInfoRsp
.
Builder
proto
=
GetGachaInfoRsp
.
newBuilder
().
setGachaRandom
(
12345
);
long
currentTime
=
System
.
currentTimeMillis
()
/
1000L
;
...
...
@@ -440,22 +425,14 @@ public class GachaManager {
for
(
GachaBanner
banner
:
getGachaBanners
().
values
())
{
if
((
banner
.
getEndTime
()
>=
currentTime
&&
banner
.
getBeginTime
()
<=
currentTime
)
||
(
banner
.
getBannerType
()
==
BannerType
.
STANDARD
))
{
proto
.
addGachaInfoList
(
banner
.
toProto
(
sessionKey
));
proto
.
addGachaInfoList
(
banner
.
toProto
(
player
));
}
}
return
proto
.
build
();
}
@Deprecated
public
GetGachaInfoRsp
toProto
()
{
if
(
this
.
cachedProto
==
null
)
{
this
.
cachedProto
=
createProto
();
}
return
this
.
cachedProto
;
}
public
GetGachaInfoRsp
toProto
(
String
sessionKey
)
{
return
createProto
(
sessionKey
);
public
GetGachaInfoRsp
toProto
(
Player
player
)
{
return
createProto
(
player
);
}
}
src/main/java/emu/grasscutter/server/packet/recv/HandlerGetGachaInfoReq.java
View file @
359e8359
...
...
@@ -14,10 +14,7 @@ public class HandlerGetGachaInfoReq extends PacketHandler {
@Override
public
void
handle
(
GameSession
session
,
byte
[]
header
,
byte
[]
payload
)
throws
Exception
{
session
.
send
(
new
PacketGetGachaInfoRsp
(
session
.
getServer
().
getGachaManager
(),
// TODO: use other Nonce/key insteadof session key to ensure the overall security for the player
session
.
getPlayer
().
getAccount
().
getSessionKey
())
);
session
.
send
(
new
PacketGetGachaInfoRsp
(
session
.
getServer
().
getGachaManager
(),
session
.
getPlayer
()));
}
}
src/main/java/emu/grasscutter/server/packet/send/PacketGetGachaInfoRsp.java
View file @
359e8359
package
emu.grasscutter.server.packet.send
;
import
emu.grasscutter.game.gacha.GachaManager
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.net.packet.BasePacket
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
public
class
PacketGetGachaInfoRsp
extends
BasePacket
{
@Deprecated
public
PacketGetGachaInfoRsp
(
GachaManager
manager
)
{
public
PacketGetGachaInfoRsp
(
GachaManager
manager
,
Player
player
)
{
super
(
PacketOpcodes
.
GetGachaInfoRsp
);
this
.
setData
(
manager
.
toProto
());
}
public
PacketGetGachaInfoRsp
(
GachaManager
manager
,
String
sessionKey
)
{
super
(
PacketOpcodes
.
GetGachaInfoRsp
);
this
.
setData
(
manager
.
toProto
(
sessionKey
));
this
.
setData
(
manager
.
toProto
(
player
));
}
}
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