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
243ad3ab
Commit
243ad3ab
authored
May 27, 2022
by
Melledy
Browse files
Refactor accounts to not use a player uid
parent
880d1770
Changes
12
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/command/commands/AccountCommand.java
View file @
243ad3ab
...
...
@@ -52,7 +52,7 @@ public final class AccountCommand implements CommandHandler {
account
.
addPermission
(
"*"
);
account
.
save
();
// Save account to database.
CommandHandler
.
sendMessage
(
null
,
translate
(
sender
,
"commands.account.create"
,
Integer
.
toString
(
account
.
getPlayerUid
())));
CommandHandler
.
sendMessage
(
null
,
translate
(
sender
,
"commands.account.create"
,
Integer
.
toString
(
account
.
get
Reserved
PlayerUid
())));
}
return
;
case
"delete"
:
...
...
@@ -63,10 +63,10 @@ public final class AccountCommand implements CommandHandler {
CommandHandler
.
sendMessage
(
null
,
translate
(
sender
,
"commands.account.no_account"
));
return
;
}
// Get the player for the account.
// If that player is currently online, we kick them before proceeding with the deletion.
Player
player
=
Grasscutter
.
getGameServer
().
getPlayerBy
Ui
d
(
toDelete
.
get
PlayerUi
d
());
Player
player
=
Grasscutter
.
getGameServer
().
getPlayerBy
AccountI
d
(
toDelete
.
get
I
d
());
if
(
player
!=
null
)
{
player
.
getSession
().
close
();
}
...
...
src/main/java/emu/grasscutter/command/commands/KickCommand.java
View file @
243ad3ab
...
...
@@ -15,7 +15,7 @@ public final class KickCommand implements CommandHandler {
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
sender
!=
null
)
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.kick.player_kick_player"
,
Integer
.
toString
(
sender
.
get
Account
().
getPlayer
Uid
()),
sender
.
getAccount
().
getUsername
(),
Integer
.
toString
(
sender
.
getUid
()),
sender
.
getAccount
().
getUsername
(),
Integer
.
toString
(
targetPlayer
.
getUid
()),
targetPlayer
.
getAccount
().
getUsername
()));
}
else
{
CommandHandler
.
sendMessage
(
null
,
translate
(
sender
,
"commands.kick.server_kick_player"
,
Integer
.
toString
(
targetPlayer
.
getUid
()),
targetPlayer
.
getAccount
().
getUsername
()));
...
...
src/main/java/emu/grasscutter/command/commands/SendMailCommand.java
View file @
243ad3ab
...
...
@@ -44,7 +44,7 @@ public final class SendMailCommand implements CommandHandler {
}
case
"all"
->
mailBuilder
=
new
MailBuilder
(
true
,
new
Mail
());
default
->
{
if
(
DatabaseHelper
.
getPlayerBy
I
d
(
Integer
.
parseInt
(
args
.
get
(
0
)))
!=
null
)
{
if
(
DatabaseHelper
.
getPlayerBy
Ui
d
(
Integer
.
parseInt
(
args
.
get
(
0
)))
!=
null
)
{
mailBuilder
=
new
MailBuilder
(
Integer
.
parseInt
(
args
.
get
(
0
)),
new
Mail
());
}
else
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.sendMail.user_not_exist"
,
args
.
get
(
0
)));
...
...
src/main/java/emu/grasscutter/database/DatabaseHelper.java
View file @
243ad3ab
...
...
@@ -8,6 +8,7 @@ import dev.morphia.query.FindOptions;
import
dev.morphia.query.Sort
;
import
dev.morphia.query.experimental.filters.Filters
;
import
emu.grasscutter.GameConstants
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.game.Account
;
import
emu.grasscutter.game.avatar.Avatar
;
import
emu.grasscutter.game.friends.Friendship
;
...
...
@@ -49,7 +50,7 @@ public final class DatabaseHelper {
account
.
setId
(
Integer
.
toString
(
DatabaseManager
.
getNextId
(
account
)));
if
(
reservedId
>
0
)
{
account
.
setPlayer
I
d
(
reservedId
);
account
.
set
Reserved
Player
Ui
d
(
reservedId
);
}
DatabaseHelper
.
saveAccount
(
account
);
...
...
@@ -104,25 +105,28 @@ public final class DatabaseHelper {
// This should optimally be wrapped inside a transaction, to make sure an error thrown mid-way does not leave the
// database in an inconsistent state, but unfortunately Mongo only supports that when we have a replica set ...
// Delete Mail.class data
DatabaseManager
.
getGameDatabase
().
getCollection
(
"mail"
).
deleteMany
(
eq
(
"ownerUid"
,
target
.
getPlayerUid
()));
// Delete Avatar.class data
DatabaseManager
.
getGameDatabase
().
getCollection
(
"avatars"
).
deleteMany
(
eq
(
"ownerId"
,
target
.
getPlayerUid
()));
// Delete GachaRecord.class data
DatabaseManager
.
getGameDatabase
().
getCollection
(
"gachas"
).
deleteMany
(
eq
(
"ownerId"
,
target
.
getPlayerUid
()));
// Delete GameItem.class data
DatabaseManager
.
getGameDatabase
().
getCollection
(
"items"
).
deleteMany
(
eq
(
"ownerId"
,
target
.
getPlayerUid
()));
// Delete GameMainQuest.class data
DatabaseManager
.
getGameDatabase
().
getCollection
(
"quests"
).
deleteMany
(
eq
(
"ownerUid"
,
target
.
getPlayerUid
()));
// Delete friendships.
// Here, we need to make sure to not only delete the deleted account's friendships,
// but also all friendship entries for that account's friends.
DatabaseManager
.
getGameDatabase
().
getCollection
(
"friendships"
).
deleteMany
(
eq
(
"ownerId"
,
target
.
getPlayerUid
()));
DatabaseManager
.
getGameDatabase
().
getCollection
(
"friendships"
).
deleteMany
(
eq
(
"friendId"
,
target
.
getPlayerUid
()));
// Delete the player.
DatabaseManager
.
getGameDatastore
().
find
(
Player
.
class
).
filter
(
Filters
.
eq
(
"id"
,
target
.
getPlayerUid
())).
delete
();
Player
player
=
Grasscutter
.
getGameServer
().
getPlayerByAccountId
(
target
.
getId
());
if
(
player
!=
null
)
{
// Close session first
player
.
getSession
().
close
();
// Delete data from collections
DatabaseManager
.
getGameDatabase
().
getCollection
(
"mail"
).
deleteMany
(
eq
(
"ownerUid"
,
player
.
getUid
()));
DatabaseManager
.
getGameDatabase
().
getCollection
(
"avatars"
).
deleteMany
(
eq
(
"ownerId"
,
player
.
getUid
()));
DatabaseManager
.
getGameDatabase
().
getCollection
(
"gachas"
).
deleteMany
(
eq
(
"ownerId"
,
player
.
getUid
()));
DatabaseManager
.
getGameDatabase
().
getCollection
(
"items"
).
deleteMany
(
eq
(
"ownerId"
,
player
.
getUid
()));
DatabaseManager
.
getGameDatabase
().
getCollection
(
"quests"
).
deleteMany
(
eq
(
"ownerUid"
,
player
.
getUid
()));
// Delete friendships.
// Here, we need to make sure to not only delete the deleted account's friendships,
// but also all friendship entries for that account's friends.
DatabaseManager
.
getGameDatabase
().
getCollection
(
"friendships"
).
deleteMany
(
eq
(
"ownerId"
,
player
.
getUid
()));
DatabaseManager
.
getGameDatabase
().
getCollection
(
"friendships"
).
deleteMany
(
eq
(
"friendId"
,
player
.
getUid
()));
// Delete the player last.
DatabaseManager
.
getGameDatastore
().
find
(
Player
.
class
).
filter
(
Filters
.
eq
(
"id"
,
player
.
getUid
())).
delete
();
}
// Finally, delete the account itself.
DatabaseManager
.
getGameDatastore
().
find
(
Account
.
class
).
filter
(
Filters
.
eq
(
"id"
,
target
.
getId
())).
delete
();
...
...
@@ -132,15 +136,19 @@ public final class DatabaseHelper {
return
DatabaseManager
.
getGameDatastore
().
find
(
Player
.
class
).
stream
().
toList
();
}
public
static
Player
getPlayerBy
I
d
(
int
id
)
{
public
static
Player
getPlayerBy
Ui
d
(
int
id
)
{
return
DatabaseManager
.
getGameDatastore
().
find
(
Player
.
class
).
filter
(
Filters
.
eq
(
"_id"
,
id
)).
first
();
}
public
static
boolean
checkPlayerExists
(
int
id
)
{
return
DatabaseManager
.
getGameDatastore
().
find
(
Player
.
class
).
filter
(
Filters
.
eq
(
"_id"
,
id
)).
first
()
!=
null
;
public
static
Player
getPlayerByAccount
(
Account
account
)
{
return
DatabaseManager
.
getGameDatastore
().
find
(
Player
.
class
).
filter
(
Filters
.
eq
(
"accountId"
,
account
.
getId
())).
first
();
}
public
static
boolean
checkPlayerExists
(
int
uid
)
{
return
DatabaseManager
.
getGameDatastore
().
find
(
Player
.
class
).
filter
(
Filters
.
eq
(
"_id"
,
uid
)).
count
()
>
0
;
}
public
static
synchronized
Player
cre
atePlayer
(
Player
character
,
int
reservedId
)
{
public
static
synchronized
Player
gener
atePlayer
Uid
(
Player
character
,
int
reservedId
)
{
// Check if reserved id
int
id
;
if
(
reservedId
>
0
&&
!
checkPlayerExists
(
reservedId
))
{
...
...
src/main/java/emu/grasscutter/game/Account.java
View file @
243ad3ab
...
...
@@ -21,7 +21,7 @@ public class Account {
private
String
username
;
private
String
password
;
// Unused for now
@AlsoLoad
(
"playerUid"
)
private
int
p
layerId
;
private
int
reservedP
layerId
;
private
String
email
;
private
String
token
;
...
...
@@ -67,12 +67,12 @@ public class Account {
this
.
token
=
token
;
}
public
int
getPlayerUid
()
{
return
this
.
p
layerId
;
public
int
get
Reserved
PlayerUid
()
{
return
this
.
reservedP
layerId
;
}
public
void
setPlayer
I
d
(
int
playerId
)
{
this
.
p
layerId
=
playerId
;
public
void
set
Reserved
Player
Ui
d
(
int
playerId
)
{
this
.
reservedP
layerId
=
playerId
;
}
public
String
getEmail
()
{
...
...
src/main/java/emu/grasscutter/game/player/Player.java
View file @
243ad3ab
...
...
@@ -50,6 +50,7 @@ import emu.grasscutter.server.event.player.PlayerJoinEvent;
import
emu.grasscutter.server.event.player.PlayerQuitEvent
;
import
emu.grasscutter.server.game.GameServer
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.game.GameSession.SessionState
;
import
emu.grasscutter.server.packet.send.*
;
import
emu.grasscutter.utils.DateHelper
;
import
emu.grasscutter.utils.Position
;
...
...
@@ -247,7 +248,6 @@ public class Player {
public
void
setAccount
(
Account
account
)
{
this
.
account
=
account
;
this
.
account
.
setPlayerId
(
getUid
());
}
public
GameSession
getSession
()
{
...
...
@@ -1017,8 +1017,8 @@ public class Player {
}
}
}
else
{
List
<
Integer
>
showAvatarList
=
DatabaseHelper
.
getPlayerBy
I
d
(
id
).
getShowAvatarList
();
AvatarStorage
avatars
=
DatabaseHelper
.
getPlayerBy
I
d
(
id
).
getAvatars
();
List
<
Integer
>
showAvatarList
=
DatabaseHelper
.
getPlayerBy
Ui
d
(
id
).
getShowAvatarList
();
AvatarStorage
avatars
=
DatabaseHelper
.
getPlayerBy
Ui
d
(
id
).
getAvatars
();
avatars
.
loadFromDatabase
();
if
(
showAvatarList
!=
null
)
{
for
(
int
avatarId
:
showAvatarList
)
{
...
...
@@ -1058,7 +1058,7 @@ public class Player {
player
=
this
;
shouldRecalc
=
false
;
}
else
{
player
=
DatabaseHelper
.
getPlayerBy
I
d
(
id
);
player
=
DatabaseHelper
.
getPlayerBy
Ui
d
(
id
);
player
.
getAvatars
().
loadFromDatabase
();
player
.
getInventory
().
loadFromDatabase
();
shouldRecalc
=
true
;
...
...
@@ -1176,8 +1176,9 @@ public class Player {
public
void
save
()
{
DatabaseHelper
.
savePlayer
(
this
);
}
public
void
onLogin
()
{
// Called from tokenrsp
public
void
loadFromDatabase
()
{
// Make sure these exist
if
(
this
.
getTeamManager
()
==
null
)
{
this
.
teamManager
=
new
TeamManager
(
this
);
...
...
@@ -1205,6 +1206,14 @@ public class Player {
this
.
getMailHandler
().
loadFromDatabase
();
this
.
getQuestManager
().
loadFromDatabase
();
// Add to gameserver (Always handle last)
if
(
getSession
().
isActive
())
{
getServer
().
registerPlayer
(
this
);
getProfile
().
setPlayer
(
this
);
// Set online
}
}
public
void
onLogin
()
{
// Quest - Commented out because a problem is caused if you log out while this quest is active
/*
if (getQuestManager().getMainQuestById(351) == null) {
...
...
@@ -1224,12 +1233,6 @@ public class Player {
World
world
=
new
World
(
this
);
world
.
addPlayer
(
this
);
// Add to gameserver
if
(
getSession
().
isActive
())
{
getServer
().
registerPlayer
(
this
);
getProfile
().
setPlayer
(
this
);
// Set online
}
// Multiplayer setting
this
.
setProperty
(
PlayerProperty
.
PROP_PLAYER_MP_SETTING_TYPE
,
this
.
getMpSetting
().
getNumber
());
this
.
setProperty
(
PlayerProperty
.
PROP_IS_MP_MODE_AVAILABLE
,
1
);
...
...
@@ -1255,6 +1258,9 @@ public class Player {
// First notify packets sent
this
.
setHasSentAvatarDataNotify
(
true
);
// Set session state
session
.
setState
(
SessionState
.
ACTIVE
);
// Call join event.
PlayerJoinEvent
event
=
new
PlayerJoinEvent
(
this
);
event
.
call
();
...
...
src/main/java/emu/grasscutter/server/game/GameServer.java
View file @
243ad3ab
...
...
@@ -118,6 +118,7 @@ public final class GameServer extends KcpServer {
public
ChatManagerHandler
getChatManager
()
{
return
chatManager
;
}
public
void
setChatManager
(
ChatManagerHandler
chatManager
)
{
this
.
chatManager
=
chatManager
;
}
...
...
@@ -189,12 +190,17 @@ public final class GameServer extends KcpServer {
// Check database if character isnt here
if
(
player
==
null
)
{
player
=
DatabaseHelper
.
getPlayerBy
I
d
(
id
);
player
=
DatabaseHelper
.
getPlayerBy
Ui
d
(
id
);
}
return
player
;
}
public
Player
getPlayerByAccountId
(
String
accountId
)
{
Optional
<
Player
>
playerOpt
=
getPlayers
().
values
().
stream
().
filter
(
player
->
player
.
getAccount
().
getId
().
equals
(
accountId
)).
findFirst
();
return
playerOpt
.
orElse
(
null
);
}
public
SocialDetail
.
Builder
getSocialDetailByUid
(
int
id
)
{
// Get from online players
Player
player
=
this
.
getPlayerByUid
(
id
,
true
);
...
...
src/main/java/emu/grasscutter/server/http/handlers/GachaHandler.java
View file @
243ad3ab
...
...
@@ -52,7 +52,7 @@ public final class GachaHandler implements Router {
response
.
status
(
403
).
send
(
"Requested account was not found"
);
return
;
}
Player
player
=
Grasscutter
.
getGameServer
().
getPlayerBy
Ui
d
(
account
.
get
PlayerUi
d
());
Player
player
=
Grasscutter
.
getGameServer
().
getPlayerBy
AccountI
d
(
account
.
get
I
d
());
if
(
player
==
null
)
{
response
.
status
(
403
).
send
(
"No player associated with requested account"
);
return
;
...
...
@@ -88,7 +88,7 @@ public final class GachaHandler implements Router {
response
.
status
(
403
).
send
(
"Requested account was not found"
);
return
;
}
Player
player
=
Grasscutter
.
getGameServer
().
getPlayerBy
Ui
d
(
account
.
get
PlayerUi
d
());
Player
player
=
Grasscutter
.
getGameServer
().
getPlayerBy
AccountI
d
(
account
.
get
I
d
());
if
(
player
==
null
)
{
response
.
status
(
403
).
send
(
"No player associated with requested account"
);
return
;
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerTokenReq.java
View file @
243ad3ab
package
emu.grasscutter.server.packet.recv
;
import
static
emu
.
grasscutter
.
Configuration
.
ACCOUNT
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.database.DatabaseHelper
;
import
emu.grasscutter.game.Account
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.net.packet.Opcodes
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.GetPlayerTokenReqOuterClass.GetPlayerTokenReq
;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.server.event.game.PlayerCreationEvent
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.game.GameSession.SessionState
;
import
emu.grasscutter.server.packet.send.PacketGetPlayerTokenRsp
;
...
...
@@ -15,6 +20,12 @@ public class HandlerGetPlayerTokenReq extends PacketHandler {
@Override
public
void
handle
(
GameSession
session
,
byte
[]
header
,
byte
[]
payload
)
throws
Exception
{
// Max players limit
if
(
ACCOUNT
.
maxPlayer
>
-
1
&&
Grasscutter
.
getGameServer
().
getPlayers
().
size
()
>=
ACCOUNT
.
maxPlayer
)
{
session
.
close
();
return
;
}
GetPlayerTokenReq
req
=
GetPlayerTokenReq
.
parseFrom
(
payload
);
// Authenticate
...
...
@@ -30,27 +41,35 @@ public class HandlerGetPlayerTokenReq extends PacketHandler {
// Set account
session
.
setAccount
(
account
);
session
.
setUseSecretKey
(
true
);
session
.
setState
(
SessionState
.
WAITING_FOR_LOGIN
);
// Has character
boolean
doesPlayerExist
=
false
;
if
(
account
.
getPlayerUid
()
>
0
)
{
// Set flag for player existing
doesPlayerExist
=
DatabaseHelper
.
checkPlayerExists
(
account
.
getPlayerUid
());
// Get player
Player
player
=
DatabaseHelper
.
getPlayerByAccount
(
account
);
if
(
player
==
null
)
{
int
nextPlayerUid
=
DatabaseHelper
.
getNextPlayerId
(
session
.
getAccount
().
getReservedPlayerUid
());
// Call creation event.
PlayerCreationEvent
event
=
new
PlayerCreationEvent
(
session
,
Player
.
class
);
event
.
call
();
// Create player instance from event.
player
=
event
.
getPlayerClass
().
getDeclaredConstructor
(
GameSession
.
class
).
newInstance
(
session
);
// Save to db
DatabaseHelper
.
generatePlayerUid
(
player
,
nextPlayerUid
);
}
// Set reserve player id if account doesnt exist
if
(!
doesPlayerExist
)
{
int
id
=
DatabaseHelper
.
getNextPlayerId
(
session
.
getAccount
().
getPlayerUid
());
if
(
id
!=
session
.
getAccount
().
getPlayerUid
())
{
session
.
getAccount
().
setPlayerId
(
id
);
session
.
getAccount
().
save
();
}
}
// Set player object for session
session
.
setPlayer
(
player
);
// Load player from database
player
.
loadFromDatabase
();
// Set session state
session
.
setUseSecretKey
(
true
);
session
.
setState
(
SessionState
.
WAITING_FOR_LOGIN
);
// Send packet
session
.
send
(
new
PacketGetPlayerTokenRsp
(
session
,
doesPlayerExist
));
session
.
send
(
new
PacketGetPlayerTokenRsp
(
session
));
}
}
src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerLoginReq.java
View file @
243ad3ab
...
...
@@ -22,11 +22,7 @@ public class HandlerPlayerLoginReq extends PacketHandler {
public
void
handle
(
GameSession
session
,
byte
[]
header
,
byte
[]
payload
)
throws
Exception
{
// Check
if
(
session
.
getAccount
()
==
null
)
{
return
;
}
// Max players limit
if
(
ACCOUNT
.
maxPlayer
>
-
1
&&
Grasscutter
.
getGameServer
().
getPlayers
().
size
()
>=
ACCOUNT
.
maxPlayer
)
{
session
.
close
();
return
;
}
...
...
@@ -35,23 +31,21 @@ public class HandlerPlayerLoginReq extends PacketHandler {
// Authenticate session
if
(!
req
.
getToken
().
equals
(
session
.
getAccount
().
getToken
()))
{
session
.
close
();
return
;
}
// Load character from db
Player
player
=
DatabaseHelper
.
getPlayerById
(
session
.
getAccount
()
.
getPlayer
Uid
()
);
Player
player
=
session
.
getPlayer
(
);
if
(
player
==
null
)
{
// Send packets
// Show opening cutscene if player has no avatars
if
(
player
.
getAvatars
().
getAvatarCount
()
==
0
)
{
// Pick character
session
.
setState
(
SessionState
.
PICKING_CHARACTER
);
session
.
send
(
new
BasePacket
(
PacketOpcodes
.
DoSetPlayerBornDataNotify
));
}
else
{
// Set character
session
.
setPlayer
(
player
);
// Login done
session
.
getPlayer
().
onLogin
();
session
.
setState
(
SessionState
.
ACTIVE
);
}
// Final packet to tell client logging in is done
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBornDataReq.java
View file @
243ad3ab
...
...
@@ -46,60 +46,38 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler {
return
;
}
String
nickname
=
req
.
getNickName
();
if
(
nickname
==
null
)
{
nickname
=
"Traveler"
;
// Get player object
Player
player
=
session
.
getPlayer
();
// Create avatar
if
(
player
.
getAvatars
().
getAvatarCount
()
==
0
)
{
Avatar
mainCharacter
=
new
Avatar
(
avatarId
);
mainCharacter
.
setSkillDepotData
(
GameData
.
getAvatarSkillDepotDataMap
().
get
(
startingSkillDepot
));
// Manually handle adding to team
player
.
addAvatar
(
mainCharacter
,
false
);
player
.
setMainCharacterId
(
avatarId
);
player
.
setHeadImage
(
avatarId
);
player
.
getTeamManager
().
getCurrentSinglePlayerTeamInfo
().
getAvatars
().
add
(
mainCharacter
.
getAvatarId
());
player
.
save
();
// TODO save player team in different object
}
else
{
return
;
}
// Call creation event.
PlayerCreationEvent
event
=
new
PlayerCreationEvent
(
session
,
Player
.
class
);
event
.
call
();
// Create player instance from event.
Player
player
=
event
.
getPlayerClass
().
getDeclaredConstructor
(
GameSession
.
class
).
newInstance
(
session
);
player
.
setNickname
(
nickname
);
// Login done
session
.
getPlayer
().
onLogin
();
try
{
// Save to db
DatabaseHelper
.
createPlayer
(
player
,
session
.
getAccount
().
getPlayerUid
());
// Create avatar
if
(
player
.
getAvatars
().
getAvatarCount
()
==
0
)
{
Avatar
mainCharacter
=
new
Avatar
(
avatarId
);
mainCharacter
.
setSkillDepotData
(
GameData
.
getAvatarSkillDepotDataMap
().
get
(
startingSkillDepot
));
// Manually handle adding to team
player
.
addAvatar
(
mainCharacter
,
false
);
player
.
setMainCharacterId
(
avatarId
);
player
.
setHeadImage
(
avatarId
);
player
.
getTeamManager
().
getCurrentSinglePlayerTeamInfo
().
getAvatars
().
add
(
mainCharacter
.
getAvatarId
());
player
.
save
();
// TODO save player team in different object
}
// Save account
session
.
getAccount
().
setPlayerId
(
player
.
getUid
());
session
.
getAccount
().
save
();
// Set character
session
.
setPlayer
(
player
);
// Login done
session
.
getPlayer
().
onLogin
();
session
.
setState
(
SessionState
.
ACTIVE
);
// Born resp packet
session
.
send
(
new
BasePacket
(
PacketOpcodes
.
SetPlayerBornDataRsp
));
// Born resp packet
session
.
send
(
new
BasePacket
(
PacketOpcodes
.
SetPlayerBornDataRsp
));
// Default mail
var
welcomeMail
=
GAME_INFO
.
joinOptions
.
welcomeMail
;
MailBuilder
mailBuilder
=
new
MailBuilder
(
player
.
getUid
(),
new
Mail
());
mailBuilder
.
mail
.
mailContent
.
title
=
welcomeMail
.
title
;
mailBuilder
.
mail
.
mailContent
.
sender
=
welcomeMail
.
sender
;
// Please credit Grasscutter if changing something here. We don't condone commercial use of the project.
mailBuilder
.
mail
.
mailContent
.
content
=
welcomeMail
.
content
+
"\n<type=\"browser\" text=\"GitHub\" href=\"https://github.com/Melledy/Grasscutter\"/>"
;
mailBuilder
.
mail
.
itemList
.
addAll
(
Arrays
.
asList
(
welcomeMail
.
items
));
mailBuilder
.
mail
.
importance
=
1
;
player
.
sendMail
(
mailBuilder
.
mail
);
}
catch
(
Exception
e
)
{
Grasscutter
.
getLogger
().
error
(
"Error creating player object: "
,
e
);
session
.
close
();
}
// Default mail
var
welcomeMail
=
GAME_INFO
.
joinOptions
.
welcomeMail
;
MailBuilder
mailBuilder
=
new
MailBuilder
(
player
.
getUid
(),
new
Mail
());
mailBuilder
.
mail
.
mailContent
.
title
=
welcomeMail
.
title
;
mailBuilder
.
mail
.
mailContent
.
sender
=
welcomeMail
.
sender
;
// Please credit Grasscutter if changing something here. We don't condone commercial use of the project.
mailBuilder
.
mail
.
mailContent
.
content
=
welcomeMail
.
content
+
"\n<type=\"browser\" text=\"GitHub\" href=\"https://github.com/Melledy/Grasscutter\"/>"
;
mailBuilder
.
mail
.
itemList
.
addAll
(
Arrays
.
asList
(
welcomeMail
.
items
));
mailBuilder
.
mail
.
importance
=
1
;
player
.
sendMail
(
mailBuilder
.
mail
);
}
}
src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerTokenRsp.java
View file @
243ad3ab
...
...
@@ -10,16 +10,16 @@ import emu.grasscutter.utils.Crypto;
public
class
PacketGetPlayerTokenRsp
extends
BasePacket
{
public
PacketGetPlayerTokenRsp
(
GameSession
session
,
boolean
doesPlayerExist
)
{
public
PacketGetPlayerTokenRsp
(
GameSession
session
)
{
super
(
PacketOpcodes
.
GetPlayerTokenRsp
,
true
);
this
.
setUseDispatchKey
(
true
);
GetPlayerTokenRsp
p
=
GetPlayerTokenRsp
.
newBuilder
()
.
setUid
(
session
.
get
Account
().
get
PlayerUid
())
.
setUid
(
session
.
getPlayer
().
get
Uid
())
.
setToken
(
session
.
getAccount
().
getToken
())
.
setAccountType
(
1
)
.
setIsProficientPlayer
(
doesPlayerExist
)
// Not sure where this goes
.
setIsProficientPlayer
(
session
.
getPlayer
().
getAvatars
().
getAvatarCount
()
>
0
)
// Not sure where this goes
.
setSecretKeySeed
(
Crypto
.
ENCRYPT_SEED
)
.
setSecurityCmdBuffer
(
ByteString
.
copyFrom
(
Crypto
.
ENCRYPT_SEED_BUFFER
))
.
setPlatformType
(
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