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
4e5d72a9
Commit
4e5d72a9
authored
Apr 25, 2022
by
Asnxthaony
Committed by
Melledy
Apr 25, 2022
Browse files
sanity check
parent
122568ad
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/GenshinPlayer.java
View file @
4e5d72a9
This diff is collapsed.
Click to expand it.
src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBirthdayReq.java
View file @
4e5d72a9
...
...
@@ -11,23 +11,57 @@ import emu.grasscutter.server.packet.send.PacketSetPlayerBirthdayRsp;
@Opcodes
(
PacketOpcodes
.
SetPlayerBirthdayReq
)
public
class
HandlerSetPlayerBirthdayReq
extends
PacketHandler
{
@Override
public
void
handle
(
GameSession
session
,
byte
[]
header
,
byte
[]
payload
)
throws
Exception
{
SetPlayerBirthdayReq
req
=
SetPlayerBirthdayReq
.
parseFrom
(
payload
);
@Override
public
void
handle
(
GameSession
session
,
byte
[]
header
,
byte
[]
payload
)
throws
Exception
{
SetPlayerBirthdayReq
req
=
SetPlayerBirthdayReq
.
parseFrom
(
payload
);
if
(
req
.
getBirthday
().
getDay
()
>
0
&&
req
.
getBirthday
().
getMonth
()
>
0
)
{
int
day
=
req
.
getBirthday
().
getDay
();
int
month
=
req
.
getBirthday
().
getMonth
();
// RET_BIRTHDAY_CANNOT_BE_SET_TWICE = 7009
if
(
session
.
getPlayer
().
hasBirthday
())
{
session
.
send
(
new
PacketSetPlayerBirthdayRsp
(
7009
));
return
;
}
// Update birthday value
session
.
getPlayer
().
s
etBirthday
(
day
,
month
);
int
month
=
req
.
getBirthday
().
getMonth
();
int
day
=
req
.
g
etBirthday
(
).
getDay
(
);
// Save birthday month and day
session
.
getPlayer
().
save
();
SocialDetail
.
Builder
detail
=
session
.
getPlayer
().
getSocialDetail
();
// RET_BIRTHDAY_FORMAT_ERROR = 7022
if
(!
isValidBirthday
(
month
,
day
))
{
session
.
send
(
new
PacketSetPlayerBirthdayRsp
(
7022
));
return
;
}
// Update birthday value
session
.
getPlayer
().
setBirthday
(
day
,
month
);
// Save birthday month and day
session
.
getPlayer
().
save
();
SocialDetail
.
Builder
detail
=
session
.
getPlayer
().
getSocialDetail
();
session
.
send
(
new
PacketSetPlayerBirthdayRsp
(
session
.
getPlayer
()));
session
.
send
(
new
PacketGetPlayerSocialDetailRsp
(
detail
));
}
private
boolean
isValidBirthday
(
int
month
,
int
day
)
{
switch
(
month
)
{
case
1
:
case
3
:
case
5
:
case
7
:
case
8
:
case
10
:
case
12
:
return
day
>
0
&
day
<=
31
;
case
4
:
case
6
:
case
9
:
case
11
:
return
day
>
0
&&
day
<=
30
;
case
2
:
return
day
>
0
&
day
<=
29
;
}
return
false
;
}
session
.
send
(
new
PacketSetPlayerBirthdayRsp
(
session
.
getPlayer
()));
session
.
send
(
new
PacketGetPlayerSocialDetailRsp
(
detail
));
}
}
}
src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerBirthdayRsp.java
View file @
4e5d72a9
...
...
@@ -6,13 +6,24 @@ import emu.grasscutter.net.packet.PacketOpcodes;
import
emu.grasscutter.net.proto.SetPlayerBirthdayRspOuterClass.SetPlayerBirthdayRsp
;
public
class
PacketSetPlayerBirthdayRsp
extends
GenshinPacket
{
public
PacketSetPlayerBirthdayRsp
(
GenshinPlayer
player
)
{
super
(
PacketOpcodes
.
SetPlayerBirthdayRsp
);
SetPlayerBirthdayRsp
proto
=
SetPlayerBirthdayRsp
.
newBuilder
()
.
setBirthday
(
player
.
getBirthday
().
toProto
())
.
build
();
public
PacketSetPlayerBirthdayRsp
(
int
retCode
)
{
super
(
PacketOpcodes
.
SetPlayerBirthdayRsp
);
this
.
setData
(
proto
);
}
SetPlayerBirthdayRsp
proto
=
SetPlayerBirthdayRsp
.
newBuilder
()
.
setRetcode
(
retCode
)
.
build
();
this
.
setData
(
proto
);
}
public
PacketSetPlayerBirthdayRsp
(
GenshinPlayer
player
)
{
super
(
PacketOpcodes
.
SetPlayerBirthdayRsp
);
SetPlayerBirthdayRsp
proto
=
SetPlayerBirthdayRsp
.
newBuilder
()
.
setBirthday
(
player
.
getBirthday
().
toProto
())
.
build
();
this
.
setData
(
proto
);
}
}
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