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
dc153572
Commit
dc153572
authored
Aug 16, 2022
by
GanyusLeftHorn
Committed by
Luke H-W
Aug 17, 2022
Browse files
Fix chat welcome messages and some slight refactoring.
parent
97779fd3
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/
managers/
chat/Chat
Manager
.java
→
src/main/java/emu/grasscutter/game/chat/Chat
System
.java
View file @
dc153572
package
emu.grasscutter.game.
managers.
chat
;
package
emu.grasscutter.game.chat
;
import
emu.grasscutter.GameConstants
;
import
emu.grasscutter.GameConstants
;
import
emu.grasscutter.command.CommandMap
;
import
emu.grasscutter.command.CommandMap
;
...
@@ -20,7 +20,7 @@ import java.util.HashMap;
...
@@ -20,7 +20,7 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
public
class
Chat
Manager
implements
Chat
Manager
Handler
{
public
class
Chat
System
implements
Chat
System
Handler
{
static
final
String
PREFIXES
=
"[/!]"
;
static
final
String
PREFIXES
=
"[/!]"
;
static
final
Pattern
RE_PREFIXES
=
Pattern
.
compile
(
PREFIXES
);
static
final
Pattern
RE_PREFIXES
=
Pattern
.
compile
(
PREFIXES
);
static
final
Pattern
RE_COMMANDS
=
Pattern
.
compile
(
"\n"
+
PREFIXES
);
static
final
Pattern
RE_COMMANDS
=
Pattern
.
compile
(
"\n"
+
PREFIXES
);
...
@@ -31,7 +31,7 @@ public class ChatManager implements ChatManagerHandler {
...
@@ -31,7 +31,7 @@ public class ChatManager implements ChatManagerHandler {
private
final
GameServer
server
;
private
final
GameServer
server
;
public
Chat
Manager
(
GameServer
server
)
{
public
Chat
System
(
GameServer
server
)
{
this
.
server
=
server
;
this
.
server
=
server
;
}
}
...
@@ -50,15 +50,15 @@ public class ChatManager implements ChatManagerHandler {
...
@@ -50,15 +50,15 @@ public class ChatManager implements ChatManagerHandler {
/********************
/********************
* Chat history handling
* Chat history handling
********************/
********************/
private
void
putInHistory
(
int
uid
,
int
t
ar
get
Id
,
ChatInfo
info
)
{
private
void
putInHistory
(
int
uid
,
int
p
ar
tner
Id
,
ChatInfo
info
)
{
if
(!
this
.
history
.
containsKey
(
uid
))
{
if
(!
this
.
history
.
containsKey
(
uid
))
{
this
.
history
.
put
(
uid
,
new
HashMap
<>());
this
.
history
.
put
(
uid
,
new
HashMap
<>());
}
}
if
(!
this
.
history
.
get
(
uid
).
containsKey
(
t
ar
get
Id
))
{
if
(!
this
.
history
.
get
(
uid
).
containsKey
(
p
ar
tner
Id
))
{
this
.
history
.
get
(
uid
).
put
(
t
ar
get
Id
,
new
ArrayList
<>());
this
.
history
.
get
(
uid
).
put
(
p
ar
tner
Id
,
new
ArrayList
<>());
}
}
this
.
history
.
get
(
uid
).
get
(
t
ar
get
Id
).
add
(
info
);
this
.
history
.
get
(
uid
).
get
(
p
ar
tner
Id
).
add
(
info
);
}
}
public
void
clearHistoryOnLogout
(
Player
player
)
{
public
void
clearHistoryOnLogout
(
Player
player
)
{
...
@@ -67,9 +67,9 @@ public class ChatManager implements ChatManagerHandler {
...
@@ -67,9 +67,9 @@ public class ChatManager implements ChatManagerHandler {
}
}
}
}
public
void
handlePullPrivateChatReq
(
Player
player
,
int
t
ar
getUi
d
)
{
public
void
handlePullPrivateChatReq
(
Player
player
,
int
p
ar
tnerI
d
)
{
if
(
this
.
history
.
containsKey
(
player
.
getUid
()
)
&&
this
.
history
.
get
(
player
.
getUid
()).
containsKey
(
t
ar
getUi
d
))
{
if
(
this
.
history
.
getOrDefault
(
player
.
getUid
()
,
Map
.
of
()).
containsKey
(
p
ar
tnerI
d
))
{
player
.
sendPacket
(
new
PacketPullPrivateChatRsp
(
this
.
history
.
get
(
player
.
getUid
()).
get
(
t
ar
getUi
d
)));
player
.
sendPacket
(
new
PacketPullPrivateChatRsp
(
this
.
history
.
get
(
player
.
getUid
()).
get
(
p
ar
tnerI
d
)));
}
}
else
{
else
{
player
.
sendPacket
(
new
PacketPullPrivateChatRsp
(
List
.
of
()));
player
.
sendPacket
(
new
PacketPullPrivateChatRsp
(
List
.
of
()));
...
@@ -77,17 +77,17 @@ public class ChatManager implements ChatManagerHandler {
...
@@ -77,17 +77,17 @@ public class ChatManager implements ChatManagerHandler {
}
}
public
void
handlePullRecentChatReq
(
Player
player
)
{
public
void
handlePullRecentChatReq
(
Player
player
)
{
// If this user has no chat history yet, create it by sending the server welcome messages.
if
(!
this
.
history
.
getOrDefault
(
player
.
getUid
(),
Map
.
of
()).
containsKey
(
GameConstants
.
SERVER_CONSOLE_UID
))
{
this
.
sendServerWelcomeMessages
(
player
);
}
// For now, we send the list three messages from the server for the recent chat history.
// For now, we send the list three messages from the server for the recent chat history.
// This matches the previous behavior, but ultimately, we should probably keep track of the last chat partner
// This matches the previous behavior, but ultimately, we should probably keep track of the last chat partner
// for every given player and return the last messages exchanged with that partner.
// for every given player and return the last messages exchanged with that partner.
if
(
this
.
history
.
containsKey
(
player
.
getUid
())
&&
this
.
history
.
get
(
player
.
getUid
()).
containsKey
(
GameConstants
.
SERVER_CONSOLE_UID
))
{
int
historyLength
=
this
.
history
.
get
(
player
.
getUid
()).
get
(
GameConstants
.
SERVER_CONSOLE_UID
).
size
();
int
historyLength
=
this
.
history
.
get
(
player
.
getUid
()).
get
(
GameConstants
.
SERVER_CONSOLE_UID
).
size
();
var
messages
=
this
.
history
.
get
(
player
.
getUid
()).
get
(
GameConstants
.
SERVER_CONSOLE_UID
).
subList
(
Math
.
max
(
historyLength
-
3
,
0
),
historyLength
);
var
messages
=
this
.
history
.
get
(
player
.
getUid
()).
get
(
GameConstants
.
SERVER_CONSOLE_UID
).
subList
(
Math
.
max
(
historyLength
-
3
,
0
),
historyLength
);
player
.
sendPacket
(
new
PacketPullRecentChatRsp
(
messages
));
player
.
sendPacket
(
new
PacketPullRecentChatRsp
(
messages
));
}
else
{
player
.
sendPacket
(
new
PacketPullRecentChatRsp
(
List
.
of
()));
}
}
}
/********************
/********************
...
@@ -199,7 +199,7 @@ public class ChatManager implements ChatManagerHandler {
...
@@ -199,7 +199,7 @@ public class ChatManager implements ChatManagerHandler {
/********************
/********************
* Welcome messages
* Welcome messages
********************/
********************/
p
ublic
void
sendServerWelcomeMessages
(
Player
player
)
{
p
rivate
void
sendServerWelcomeMessages
(
Player
player
)
{
var
joinOptions
=
GAME_INFO
.
joinOptions
;
var
joinOptions
=
GAME_INFO
.
joinOptions
;
if
(
joinOptions
.
welcomeEmotes
!=
null
&&
joinOptions
.
welcomeEmotes
.
length
>
0
)
{
if
(
joinOptions
.
welcomeEmotes
!=
null
&&
joinOptions
.
welcomeEmotes
.
length
>
0
)
{
...
...
src/main/java/emu/grasscutter/game/
managers/
chat/Chat
Manager
Handler.java
→
src/main/java/emu/grasscutter/game/chat/Chat
System
Handler.java
View file @
dc153572
package
emu.grasscutter.game.
managers.
chat
;
package
emu.grasscutter.game.chat
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.server.game.GameServer
;
import
emu.grasscutter.server.game.GameServer
;
public
interface
Chat
Manager
Handler
{
public
interface
Chat
System
Handler
{
GameServer
getServer
();
GameServer
getServer
();
void
sendPrivateMessage
(
Player
player
,
int
targetUid
,
String
message
);
void
sendPrivateMessage
(
Player
player
,
int
targetUid
,
String
message
);
void
sendPrivateMessage
(
Player
player
,
int
targetUid
,
int
emote
);
void
sendPrivateMessage
(
Player
player
,
int
targetUid
,
int
emote
);
...
@@ -13,6 +13,5 @@ public interface ChatManagerHandler {
...
@@ -13,6 +13,5 @@ public interface ChatManagerHandler {
void
sendPrivateMessageFromServer
(
int
targetUid
,
int
emote
);
void
sendPrivateMessageFromServer
(
int
targetUid
,
int
emote
);
void
handlePullPrivateChatReq
(
Player
player
,
int
targetUid
);
void
handlePullPrivateChatReq
(
Player
player
,
int
targetUid
);
void
clearHistoryOnLogout
(
Player
player
);
void
clearHistoryOnLogout
(
Player
player
);
void
sendServerWelcomeMessages
(
Player
player
);
void
handlePullRecentChatReq
(
Player
player
);
void
handlePullRecentChatReq
(
Player
player
);
}
}
src/main/java/emu/grasscutter/game/player/Player.java
View file @
dc153572
...
@@ -51,14 +51,12 @@ import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry
...
@@ -51,14 +51,12 @@ import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry
import
emu.grasscutter.net.proto.AttackResultOuterClass.AttackResult
;
import
emu.grasscutter.net.proto.AttackResultOuterClass.AttackResult
;
import
emu.grasscutter.net.proto.CombatInvokeEntryOuterClass.CombatInvokeEntry
;
import
emu.grasscutter.net.proto.CombatInvokeEntryOuterClass.CombatInvokeEntry
;
import
emu.grasscutter.net.proto.GadgetInteractReqOuterClass.GadgetInteractReq
;
import
emu.grasscutter.net.proto.GadgetInteractReqOuterClass.GadgetInteractReq
;
import
emu.grasscutter.net.proto.InteractTypeOuterClass.InteractType
;
import
emu.grasscutter.net.proto.MpSettingTypeOuterClass.MpSettingType
;
import
emu.grasscutter.net.proto.MpSettingTypeOuterClass.MpSettingType
;
import
emu.grasscutter.net.proto.OnlinePlayerInfoOuterClass.OnlinePlayerInfo
;
import
emu.grasscutter.net.proto.OnlinePlayerInfoOuterClass.OnlinePlayerInfo
;
import
emu.grasscutter.net.proto.PlayerLocationInfoOuterClass.PlayerLocationInfo
;
import
emu.grasscutter.net.proto.PlayerLocationInfoOuterClass.PlayerLocationInfo
;
import
emu.grasscutter.net.proto.ProfilePictureOuterClass.ProfilePicture
;
import
emu.grasscutter.net.proto.ProfilePictureOuterClass.ProfilePicture
;
import
emu.grasscutter.net.proto.PropChangeReasonOuterClass.PropChangeReason
;
import
emu.grasscutter.net.proto.PropChangeReasonOuterClass.PropChangeReason
;
import
emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail
;
import
emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail
;
import
emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType
;
import
emu.grasscutter.scripts.data.SceneRegion
;
import
emu.grasscutter.scripts.data.SceneRegion
;
import
emu.grasscutter.server.event.player.PlayerJoinEvent
;
import
emu.grasscutter.server.event.player.PlayerJoinEvent
;
import
emu.grasscutter.server.event.player.PlayerQuitEvent
;
import
emu.grasscutter.server.event.player.PlayerQuitEvent
;
...
@@ -799,7 +797,6 @@ public class Player {
...
@@ -799,7 +797,6 @@ public class Player {
}
}
this
.
getServer
().
getChatSystem
().
sendPrivateMessageFromServer
(
getUid
(),
message
.
toString
());
this
.
getServer
().
getChatSystem
().
sendPrivateMessageFromServer
(
getUid
(),
message
.
toString
());
// this.sendPacket(new PacketPrivateChatNotify(GameConstants.SERVER_CONSOLE_UID, getUid(), message.toString()));
}
}
/**
/**
...
@@ -809,7 +806,6 @@ public class Player {
...
@@ -809,7 +806,6 @@ public class Player {
* @param message The message to send.
* @param message The message to send.
*/
*/
public
void
sendMessage
(
Player
sender
,
Object
message
)
{
public
void
sendMessage
(
Player
sender
,
Object
message
)
{
// this.sendPacket(new PacketPrivateChatNotify(sender.getUid(), this.getUid(), message.toString()));
this
.
getServer
().
getChatSystem
().
sendPrivateMessage
(
sender
,
this
.
getUid
(),
message
.
toString
());
this
.
getServer
().
getChatSystem
().
sendPrivateMessage
(
sender
,
this
.
getUid
(),
message
.
toString
());
}
}
...
@@ -1194,12 +1190,8 @@ public class Player {
...
@@ -1194,12 +1190,8 @@ public class Player {
session
.
send
(
new
PacketPlayerEnterSceneNotify
(
this
));
// Enter game world
session
.
send
(
new
PacketPlayerEnterSceneNotify
(
this
));
// Enter game world
session
.
send
(
new
PacketPlayerLevelRewardUpdateNotify
(
rewardedLevels
));
session
.
send
(
new
PacketPlayerLevelRewardUpdateNotify
(
rewardedLevels
));
// First notify packets sent
// First notify packets sent
this
.
hasSentLoginPackets
=
true
;
this
.
hasSentLoginPackets
=
true
;
// Send server welcome chat.
this
.
getServer
().
getChatSystem
().
sendServerWelcomeMessages
(
this
);
// Set session state
// Set session state
session
.
setState
(
SessionState
.
ACTIVE
);
session
.
setState
(
SessionState
.
ACTIVE
);
...
...
src/main/java/emu/grasscutter/server/game/GameServer.java
View file @
dc153572
...
@@ -2,10 +2,11 @@ package emu.grasscutter.server.game;
...
@@ -2,10 +2,11 @@ package emu.grasscutter.server.game;
import
emu.grasscutter.GameConstants
;
import
emu.grasscutter.GameConstants
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.command.CommandMap
;
import
emu.grasscutter.database.DatabaseHelper
;
import
emu.grasscutter.database.DatabaseHelper
;
import
emu.grasscutter.game.Account
;
import
emu.grasscutter.game.Account
;
import
emu.grasscutter.game.battlepass.BattlePassSystem
;
import
emu.grasscutter.game.battlepass.BattlePassSystem
;
import
emu.grasscutter.game.chat.ChatSystem
;
import
emu.grasscutter.game.chat.ChatSystemHandler
;
import
emu.grasscutter.game.combine.CombineManger
;
import
emu.grasscutter.game.combine.CombineManger
;
import
emu.grasscutter.game.drop.DropSystem
;
import
emu.grasscutter.game.drop.DropSystem
;
import
emu.grasscutter.game.dungeons.DungeonSystem
;
import
emu.grasscutter.game.dungeons.DungeonSystem
;
...
@@ -13,8 +14,6 @@ import emu.grasscutter.game.dungeons.challenge.DungeonChallenge;
...
@@ -13,8 +14,6 @@ import emu.grasscutter.game.dungeons.challenge.DungeonChallenge;
import
emu.grasscutter.game.expedition.ExpeditionSystem
;
import
emu.grasscutter.game.expedition.ExpeditionSystem
;
import
emu.grasscutter.game.gacha.GachaSystem
;
import
emu.grasscutter.game.gacha.GachaSystem
;
import
emu.grasscutter.game.managers.CookingManager
;
import
emu.grasscutter.game.managers.CookingManager
;
import
emu.grasscutter.game.managers.chat.ChatManager
;
import
emu.grasscutter.game.managers.chat.ChatManagerHandler
;
import
emu.grasscutter.game.managers.energy.EnergyManager
;
import
emu.grasscutter.game.managers.energy.EnergyManager
;
import
emu.grasscutter.game.managers.stamina.StaminaManager
;
import
emu.grasscutter.game.managers.stamina.StaminaManager
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.player.Player
;
...
@@ -74,7 +73,7 @@ public final class GameServer extends KcpServer {
...
@@ -74,7 +73,7 @@ public final class GameServer extends KcpServer {
private
final
ServerTaskScheduler
scheduler
;
private
final
ServerTaskScheduler
scheduler
;
private
final
TaskMap
taskMap
;
private
final
TaskMap
taskMap
;
private
Chat
Manager
Handler
chatManager
;
private
Chat
System
Handler
chatManager
;
public
GameServer
()
{
public
GameServer
()
{
this
(
getAdapterInetSocketAddress
());
this
(
getAdapterInetSocketAddress
());
...
@@ -124,27 +123,27 @@ public final class GameServer extends KcpServer {
...
@@ -124,27 +123,27 @@ public final class GameServer extends KcpServer {
this
.
questSystem
=
new
QuestSystem
(
this
);
this
.
questSystem
=
new
QuestSystem
(
this
);
// Chata manager
// Chata manager
this
.
chatManager
=
new
Chat
Manager
(
this
);
this
.
chatManager
=
new
Chat
System
(
this
);
// Hook into shutdown event.
// Hook into shutdown event.
Runtime
.
getRuntime
().
addShutdownHook
(
new
Thread
(
this
::
onServerShutdown
));
Runtime
.
getRuntime
().
addShutdownHook
(
new
Thread
(
this
::
onServerShutdown
));
}
}
@Deprecated
@Deprecated
public
Chat
Manager
Handler
getChatManager
()
{
public
Chat
System
Handler
getChatManager
()
{
return
chatManager
;
return
chatManager
;
}
}
@Deprecated
@Deprecated
public
void
setChatManager
(
Chat
Manager
Handler
chatManager
)
{
public
void
setChatManager
(
Chat
System
Handler
chatManager
)
{
this
.
chatManager
=
chatManager
;
this
.
chatManager
=
chatManager
;
}
}
public
Chat
Manager
Handler
getChatSystem
()
{
public
Chat
System
Handler
getChatSystem
()
{
return
chatManager
;
return
chatManager
;
}
}
public
void
setChatSystem
(
Chat
Manager
Handler
chatManager
)
{
public
void
setChatSystem
(
Chat
System
Handler
chatManager
)
{
this
.
chatManager
=
chatManager
;
this
.
chatManager
=
chatManager
;
}
}
...
...
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