Commit dc153572 authored by GanyusLeftHorn's avatar GanyusLeftHorn Committed by Luke H-W
Browse files

Fix chat welcome messages and some slight refactoring.

parent 97779fd3
package emu.grasscutter.game.managers.chat;
package emu.grasscutter.game.chat;
import emu.grasscutter.GameConstants;
import emu.grasscutter.command.CommandMap;
......@@ -20,7 +20,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ChatManager implements ChatManagerHandler {
public class ChatSystem implements ChatSystemHandler {
static final String PREFIXES = "[/!]";
static final Pattern RE_PREFIXES = Pattern.compile(PREFIXES);
static final Pattern RE_COMMANDS = Pattern.compile("\n" + PREFIXES);
......@@ -31,7 +31,7 @@ public class ChatManager implements ChatManagerHandler {
private final GameServer server;
public ChatManager(GameServer server) {
public ChatSystem(GameServer server) {
this.server = server;
}
......@@ -50,15 +50,15 @@ public class ChatManager implements ChatManagerHandler {
/********************
* Chat history handling
********************/
private void putInHistory(int uid, int targetId, ChatInfo info) {
private void putInHistory(int uid, int partnerId, ChatInfo info) {
if (!this.history.containsKey(uid)) {
this.history.put(uid, new HashMap<>());
}
if (!this.history.get(uid).containsKey(targetId)) {
this.history.get(uid).put(targetId, new ArrayList<>());
if (!this.history.get(uid).containsKey(partnerId)) {
this.history.get(uid).put(partnerId, new ArrayList<>());
}
this.history.get(uid).get(targetId).add(info);
this.history.get(uid).get(partnerId).add(info);
}
public void clearHistoryOnLogout(Player player) {
......@@ -67,9 +67,9 @@ public class ChatManager implements ChatManagerHandler {
}
}
public void handlePullPrivateChatReq(Player player, int targetUid) {
if (this.history.containsKey(player.getUid()) && this.history.get(player.getUid()).containsKey(targetUid)) {
player.sendPacket(new PacketPullPrivateChatRsp(this.history.get(player.getUid()).get(targetUid)));
public void handlePullPrivateChatReq(Player player, int partnerId) {
if (this.history.getOrDefault(player.getUid(), Map.of()).containsKey(partnerId)) {
player.sendPacket(new PacketPullPrivateChatRsp(this.history.get(player.getUid()).get(partnerId)));
}
else {
player.sendPacket(new PacketPullPrivateChatRsp(List.of()));
......@@ -77,18 +77,18 @@ public class ChatManager implements ChatManagerHandler {
}
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.
// 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.
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();
var messages = this.history.get(player.getUid()).get(GameConstants.SERVER_CONSOLE_UID).subList(Math.max(historyLength - 3, 0), historyLength);
player.sendPacket(new PacketPullRecentChatRsp(messages));
}
else {
player.sendPacket(new PacketPullRecentChatRsp(List.of()));
}
}
/********************
* Sending messages
......@@ -199,7 +199,7 @@ public class ChatManager implements ChatManagerHandler {
/********************
* Welcome messages
********************/
public void sendServerWelcomeMessages(Player player) {
private void sendServerWelcomeMessages(Player player) {
var joinOptions = GAME_INFO.joinOptions;
if (joinOptions.welcomeEmotes != null && joinOptions.welcomeEmotes.length > 0) {
......
package emu.grasscutter.game.managers.chat;
package emu.grasscutter.game.chat;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.game.GameServer;
public interface ChatManagerHandler {
public interface ChatSystemHandler {
GameServer getServer();
void sendPrivateMessage(Player player, int targetUid, String message);
void sendPrivateMessage(Player player, int targetUid, int emote);
......@@ -13,6 +13,5 @@ public interface ChatManagerHandler {
void sendPrivateMessageFromServer(int targetUid, int emote);
void handlePullPrivateChatReq(Player player, int targetUid);
void clearHistoryOnLogout(Player player);
void sendServerWelcomeMessages(Player player);
void handlePullRecentChatReq(Player player);
}
......@@ -51,14 +51,12 @@ import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry
import emu.grasscutter.net.proto.AttackResultOuterClass.AttackResult;
import emu.grasscutter.net.proto.CombatInvokeEntryOuterClass.CombatInvokeEntry;
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.OnlinePlayerInfoOuterClass.OnlinePlayerInfo;
import emu.grasscutter.net.proto.PlayerLocationInfoOuterClass.PlayerLocationInfo;
import emu.grasscutter.net.proto.ProfilePictureOuterClass.ProfilePicture;
import emu.grasscutter.net.proto.PropChangeReasonOuterClass.PropChangeReason;
import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail;
import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType;
import emu.grasscutter.scripts.data.SceneRegion;
import emu.grasscutter.server.event.player.PlayerJoinEvent;
import emu.grasscutter.server.event.player.PlayerQuitEvent;
......@@ -799,7 +797,6 @@ public class Player {
}
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 {
* @param message The message to send.
*/
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());
}
......@@ -1194,13 +1190,9 @@ public class Player {
session.send(new PacketPlayerEnterSceneNotify(this)); // Enter game world
session.send(new PacketPlayerLevelRewardUpdateNotify(rewardedLevels));
// First notify packets sent
this.hasSentLoginPackets = true;
// Send server welcome chat.
this.getServer().getChatSystem().sendServerWelcomeMessages(this);
// Set session state
session.setState(SessionState.ACTIVE);
......
......@@ -2,10 +2,11 @@ package emu.grasscutter.server.game;
import emu.grasscutter.GameConstants;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.CommandMap;
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.Account;
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.drop.DropSystem;
import emu.grasscutter.game.dungeons.DungeonSystem;
......@@ -13,8 +14,6 @@ import emu.grasscutter.game.dungeons.challenge.DungeonChallenge;
import emu.grasscutter.game.expedition.ExpeditionSystem;
import emu.grasscutter.game.gacha.GachaSystem;
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.stamina.StaminaManager;
import emu.grasscutter.game.player.Player;
......@@ -74,7 +73,7 @@ public final class GameServer extends KcpServer {
private final ServerTaskScheduler scheduler;
private final TaskMap taskMap;
private ChatManagerHandler chatManager;
private ChatSystemHandler chatManager;
public GameServer() {
this(getAdapterInetSocketAddress());
......@@ -124,27 +123,27 @@ public final class GameServer extends KcpServer {
this.questSystem = new QuestSystem(this);
// Chata manager
this.chatManager = new ChatManager(this);
this.chatManager = new ChatSystem(this);
// Hook into shutdown event.
Runtime.getRuntime().addShutdownHook(new Thread(this::onServerShutdown));
}
@Deprecated
public ChatManagerHandler getChatManager() {
public ChatSystemHandler getChatManager() {
return chatManager;
}
@Deprecated
public void setChatManager(ChatManagerHandler chatManager) {
public void setChatManager(ChatSystemHandler chatManager) {
this.chatManager = chatManager;
}
public ChatManagerHandler getChatSystem() {
public ChatSystemHandler getChatSystem() {
return chatManager;
}
public void setChatSystem(ChatManagerHandler chatManager) {
public void setChatSystem(ChatSystemHandler chatManager) {
this.chatManager = chatManager;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment