Commit 1c36f078 authored by Melledy's avatar Melledy
Browse files

Renamed all references to a certain game

parent 6b8902be
......@@ -8,7 +8,7 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
public abstract class MihoyoKcpChannel extends ChannelInboundHandlerAdapter {
public abstract class KcpChannel extends ChannelInboundHandlerAdapter {
private UkcpChannel kcpChannel;
private ChannelHandlerContext ctx;
private boolean isActive;
......
......@@ -10,9 +10,9 @@ import io.netty.channel.ChannelMetadata;
import io.netty.channel.ChannelOutboundBuffer;
import io.netty.channel.nio.AbstractNioMessageChannel;
public class MihoyoKcpHandshaker extends AbstractNioMessageChannel {
public class KcpHandshaker extends AbstractNioMessageChannel {
protected MihoyoKcpHandshaker(Channel parent, SelectableChannel ch, int readInterestOp) {
protected KcpHandshaker(Channel parent, SelectableChannel ch, int readInterestOp) {
super(parent, ch, readInterestOp);
}
......
......@@ -13,14 +13,14 @@ import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
@SuppressWarnings("rawtypes")
public class MihoyoKcpServer extends Thread {
public class KcpServer extends Thread {
private EventLoopGroup group;
private UkcpServerBootstrap bootstrap;
private ChannelInitializer serverInitializer;
private InetSocketAddress address;
public MihoyoKcpServer(InetSocketAddress address) {
public KcpServer(InetSocketAddress address) {
this.address = address;
this.setName("Netty Server Thread");
}
......@@ -40,7 +40,7 @@ public class MihoyoKcpServer extends Thread {
@Override
public void run() {
if (getServerInitializer() == null) {
this.setServerInitializer(new MihoyoKcpServerInitializer());
this.setServerInitializer(new KcpServerInitializer());
}
try {
......
......@@ -5,7 +5,7 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
@SuppressWarnings("unused")
public class MihoyoKcpServerInitializer extends ChannelInitializer<UkcpChannel> {
public class KcpServerInitializer extends ChannelInitializer<UkcpChannel> {
@Override
protected void initChannel(UkcpChannel ch) throws Exception {
......
package emu.grasscutter.plugin.api;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.avatar.GenshinAvatar;
import emu.grasscutter.game.Player;
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.props.EnterReason;
import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType;
import emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify;
import emu.grasscutter.server.packet.send.PacketAvatarLifeStateChangeNotify;
......@@ -13,16 +13,16 @@ import emu.grasscutter.server.packet.send.PacketPlayerEnterSceneNotify;
import emu.grasscutter.utils.Position;
/**
* Hooks into the {@link GenshinPlayer} class, adding convenient ways to do certain things.
* Hooks into the {@link Player} class, adding convenient ways to do certain things.
*/
public final class PlayerHook {
private final GenshinPlayer player;
private final Player player;
/**
* Hooks into the player.
* @param player The player to hook into.
*/
public PlayerHook(GenshinPlayer player) {
public PlayerHook(Player player) {
this.player = player;
}
......@@ -53,7 +53,7 @@ public final class PlayerHook {
* Broadcasts the packet sent to all world players.
* @param packet The packet to send.
*/
public void broadcastPacketToWorld(GenshinPacket packet) {
public void broadcastPacketToWorld(BasePacket packet) {
this.player.getWorld().broadcastPacket(packet);
}
......@@ -70,7 +70,7 @@ public final class PlayerHook {
* Revives the specified avatar.
* @param avatar The avatar to revive.
*/
public void reviveAvatar(GenshinAvatar avatar) {
public void reviveAvatar(Avatar avatar) {
this.broadcastPacketToWorld(new PacketAvatarLifeStateChangeNotify(avatar));
}
......@@ -105,9 +105,9 @@ public final class PlayerHook {
/**
* Gets the currently selected avatar.
* @return The avatar as an {@link GenshinAvatar}.
* @return The avatar as an {@link Avatar}.
*/
public GenshinAvatar getCurrentAvatar() {
public Avatar getCurrentAvatar() {
return this.getCurrentAvatarEntity().getAvatar();
}
}
\ No newline at end of file
package emu.grasscutter.plugin.api;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.Player;
import emu.grasscutter.server.game.GameServer;
import java.util.LinkedList;
......@@ -35,7 +35,7 @@ public final class ServerHook {
* Gets all online players.
* @return Players connected to the server.
*/
public List<GenshinPlayer> getOnlinePlayers() {
public List<Player> getOnlinePlayers() {
return new LinkedList<>(this.server.getPlayers().values());
}
}
\ No newline at end of file
......@@ -55,6 +55,7 @@ public final class DispatchServer {
this.initRegion();
}
@Deprecated
public HttpServer getServer() {
return server;
}
......
package emu.grasscutter.server.event.game;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.server.event.Cancellable;
import emu.grasscutter.server.event.ServerEvent;
import emu.grasscutter.server.game.GameSession;
public final class SendPacketEvent extends ServerEvent implements Cancellable {
private final GameSession gameSession;
private GenshinPacket packet;
private BasePacket packet;
public SendPacketEvent(GameSession gameSession, GenshinPacket packet) {
public SendPacketEvent(GameSession gameSession, BasePacket packet) {
super(Type.GAME);
this.gameSession = gameSession;
......@@ -20,11 +20,11 @@ public final class SendPacketEvent extends ServerEvent implements Cancellable {
return this.gameSession;
}
public void setPacket(GenshinPacket packet) {
public void setPacket(BasePacket packet) {
this.packet = packet;
}
public GenshinPacket getPacket() {
public BasePacket getPacket() {
return this.packet;
}
}
......@@ -5,12 +5,12 @@ import java.time.OffsetDateTime;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import emu.grasscutter.GenshinConstants;
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.GenshinPlayer;
import emu.grasscutter.game.Player;
import emu.grasscutter.game.World;
import emu.grasscutter.game.dungeons.DungeonManager;
import emu.grasscutter.game.gacha.GachaManager;
......@@ -20,18 +20,18 @@ import emu.grasscutter.game.managers.MultiplayerManager;
import emu.grasscutter.game.shop.ShopManager;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail;
import emu.grasscutter.netty.MihoyoKcpServer;
import emu.grasscutter.netty.KcpServer;
import emu.grasscutter.server.event.ServerEvent;
import emu.grasscutter.server.event.game.ServerTickEvent;
import emu.grasscutter.server.event.internal.ServerStartEvent;
import emu.grasscutter.server.event.internal.ServerStopEvent;
import emu.grasscutter.task.TaskMap;
public final class GameServer extends MihoyoKcpServer {
public final class GameServer extends KcpServer {
private final InetSocketAddress address;
private final GameServerPacketHandler packetHandler;
private final Map<Integer, GenshinPlayer> players;
private final Map<Integer, Player> players;
private final Set<World> worlds;
private final ChatManager chatManager;
......@@ -82,7 +82,7 @@ public final class GameServer extends MihoyoKcpServer {
return packetHandler;
}
public Map<Integer, GenshinPlayer> getPlayers() {
public Map<Integer, Player> getPlayers() {
return players;
}
......@@ -122,22 +122,22 @@ public final class GameServer extends MihoyoKcpServer {
return this.taskMap;
}
public void registerPlayer(GenshinPlayer player) {
public void registerPlayer(Player player) {
getPlayers().put(player.getUid(), player);
}
public GenshinPlayer getPlayerByUid(int id) {
public Player getPlayerByUid(int id) {
return this.getPlayerByUid(id, false);
}
public GenshinPlayer getPlayerByUid(int id, boolean allowOfflinePlayers) {
public Player getPlayerByUid(int id, boolean allowOfflinePlayers) {
// Console check
if (id == GenshinConstants.SERVER_CONSOLE_UID) {
if (id == GameConstants.SERVER_CONSOLE_UID) {
return null;
}
// Get from online players
GenshinPlayer player = this.getPlayers().get(id);
Player player = this.getPlayers().get(id);
if (!allowOfflinePlayers) {
return player;
......@@ -153,7 +153,7 @@ public final class GameServer extends MihoyoKcpServer {
public SocialDetail.Builder getSocialDetailByUid(int id) {
// Get from online players
GenshinPlayer player = this.getPlayerByUid(id, true);
Player player = this.getPlayerByUid(id, true);
if (player == null) {
return null;
......@@ -163,7 +163,7 @@ public final class GameServer extends MihoyoKcpServer {
}
public Account getAccountByName(String username) {
Optional<GenshinPlayer> playerOpt = getPlayers().values().stream().filter(player -> player.getAccount().getUsername().equals(username)).findFirst();
Optional<Player> playerOpt = getPlayers().values().stream().filter(player -> player.getAccount().getUsername().equals(username)).findFirst();
if (playerOpt.isPresent()) {
return playerOpt.get().getAccount();
}
......@@ -204,10 +204,10 @@ public final class GameServer extends MihoyoKcpServer {
ServerStopEvent event = new ServerStopEvent(ServerEvent.Type.GAME, OffsetDateTime.now()); event.call();
// Kick and save all players
List<GenshinPlayer> list = new ArrayList<>(this.getPlayers().size());
List<Player> list = new ArrayList<>(this.getPlayers().size());
list.addAll(this.getPlayers().values());
for (GenshinPlayer player : list) {
for (Player player : list) {
player.getSession().close();
}
}
......
package emu.grasscutter.server.game;
import emu.grasscutter.netty.MihoyoKcpServerInitializer;
import emu.grasscutter.netty.KcpServerInitializer;
import io.jpower.kcp.netty.UkcpChannel;
import io.netty.channel.ChannelPipeline;
public class GameServerInitializer extends MihoyoKcpServerInitializer {
public class GameServerInitializer extends KcpServerInitializer {
private GameServer server;
public GameServerInitializer(GameServer server) {
......
......@@ -8,11 +8,11 @@ import java.util.Set;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.Account;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.game.Player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.packet.PacketOpcodesUtil;
import emu.grasscutter.netty.MihoyoKcpChannel;
import emu.grasscutter.netty.KcpChannel;
import emu.grasscutter.server.event.game.SendPacketEvent;
import emu.grasscutter.utils.Crypto;
import emu.grasscutter.utils.FileUtils;
......@@ -21,11 +21,11 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
public class GameSession extends MihoyoKcpChannel {
public class GameSession extends KcpChannel {
private GameServer server;
private Account account;
private GenshinPlayer player;
private Player player;
private boolean useSecretKey;
private SessionState state;
......@@ -67,11 +67,11 @@ public class GameSession extends MihoyoKcpChannel {
return this.getAccount().getId();
}
public GenshinPlayer getPlayer() {
public Player getPlayer() {
return player;
}
public synchronized void setPlayer(GenshinPlayer player) {
public synchronized void setPlayer(Player player) {
this.player = player;
this.player.setSession(this);
this.player.setAccount(this.getAccount());
......@@ -144,43 +144,35 @@ public class GameSession extends MihoyoKcpChannel {
byte[] packet = FileUtils.read(p);
GenshinPacket genshinPacket = new GenshinPacket(opcode);
genshinPacket.setData(packet);
BasePacket basePacket = new BasePacket(opcode);
basePacket.setData(packet);
// Log
logPacket(genshinPacket.getOpcode());
send(genshinPacket);
send(basePacket);
}
public void send(GenshinPacket genshinPacket) {
public void send(BasePacket packet) {
// Test
if (genshinPacket.getOpcode() <= 0) {
if (packet.getOpcode() <= 0) {
Grasscutter.getLogger().warn("Tried to send packet with missing cmd id!");
return;
}
// Header
if (genshinPacket.shouldBuildHeader()) {
genshinPacket.buildHeader(this.getNextClientSequence());
if (packet.shouldBuildHeader()) {
packet.buildHeader(this.getNextClientSequence());
}
// Log
if (Grasscutter.getConfig().getGameServerOptions().LOG_PACKETS) {
logPacket(genshinPacket);
logPacket(packet);
}
// Invoke event.
SendPacketEvent event = new SendPacketEvent(this, genshinPacket); event.call();
SendPacketEvent event = new SendPacketEvent(this, packet); event.call();
if(!event.isCanceled()) // If event is not cancelled, continue.
this.send(event.getPacket().build());
}
private void logPacket(int opcode) {
//Grasscutter.getLogger().info("SEND: " + PacketOpcodesUtil.getOpcodeName(opcode));
//System.out.println(Utils.bytesToHex(genshinPacket.getData()));
}
private static final Set<Integer> loopPacket = Set.of(
PacketOpcodes.PingReq,
PacketOpcodes.PingRsp,
......@@ -189,10 +181,10 @@ public class GameSession extends MihoyoKcpChannel {
PacketOpcodes.QueryPathReq
);
private void logPacket(GenshinPacket genshinPacket) {
if (!loopPacket.contains(genshinPacket.getOpcode())) {
Grasscutter.getLogger().info("SEND: " + PacketOpcodesUtil.getOpcodeName(genshinPacket.getOpcode()) + " (" + genshinPacket.getOpcode() + ")");
System.out.println(Utils.bytesToHex(genshinPacket.getData()));
private void logPacket(BasePacket packet) {
if (!loopPacket.contains(packet.getOpcode())) {
Grasscutter.getLogger().info("SEND: " + PacketOpcodesUtil.getOpcodeName(packet.getOpcode()) + " (" + packet.getOpcode() + ")");
System.out.println(Utils.bytesToHex(packet.getData()));
}
}
......
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.data.GenshinData;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.def.RewardData;
import emu.grasscutter.game.avatar.GenshinAvatar;
import emu.grasscutter.game.inventory.GenshinItem;
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketOpcodes;
......@@ -27,14 +27,14 @@ public class HandlerAvatarFetterLevelRewardReq extends PacketHandler {
} else {
long avatarGuid = req.getAvatarGuid();
GenshinAvatar avatar = session
Avatar avatar = session
.getPlayer()
.getAvatars()
.getAvatarByGuid(avatarGuid);
int rewardId = avatar.getNameCardRewardId();
RewardData card = GenshinData.getRewardDataMap().get(rewardId);
RewardData card = GameData.getRewardDataMap().get(rewardId);
int cardId = card.getRewardItemList().get(0).getItemId();
if (session.getPlayer().getNameCardList().contains(cardId)) {
......@@ -43,7 +43,7 @@ public class HandlerAvatarFetterLevelRewardReq extends PacketHandler {
return;
}
GenshinItem item = new GenshinItem(cardId);
GameItem item = new GameItem(cardId);
session.getPlayer().getInventory().addItem(item, ActionReason.FetterLevelReward);
session.getPlayer().sendPacket(new PacketUnlockNameCardNotify(cardId));
session.send(new PacketAvatarFetterDataNotify(avatar));
......
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.game.entity.GenshinEntity;
import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.CombatInvocationsNotifyOuterClass.CombatInvocationsNotify;
......@@ -27,7 +27,7 @@ public class HandlerCombatInvocationsNotify extends PacketHandler {
case ENTITY_MOVE:
// Handle movement
EntityMoveInfo moveInfo = EntityMoveInfo.parseFrom(entry.getCombatData());
GenshinEntity entity = session.getPlayer().getScene().getEntityById(moveInfo.getEntityId());
GameEntity entity = session.getPlayer().getScene().getEntityById(moveInfo.getEntityId());
if (entity != null) {
entity.getPosition().set(moveInfo.getMotionInfo().getPos());
entity.getRotation().set(moveInfo.getMotionInfo().getRot());
......
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.game.GenshinPlayer.SceneLoadState;
import emu.grasscutter.game.Player.SceneLoadState;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.packet.PacketHandler;
......
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.packet.PacketHandler;
......@@ -11,7 +11,7 @@ public class HandlerGetPlayerBlacklistReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
session.send(new GenshinPacket(PacketOpcodes.GetPlayerBlacklistRsp).buildHeader(3));
session.send(new BasePacket(PacketOpcodes.GetPlayerBlacklistRsp).buildHeader(3));
}
}
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.game.inventory.GenshinItem;
import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.NpcTalkReqOuterClass.NpcTalkReq;
......
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.game.Player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.PlayerLoginReqOuterClass.PlayerLoginReq;
......@@ -30,12 +30,12 @@ public class HandlerPlayerLoginReq extends PacketHandler {
}
// Load character from db
GenshinPlayer player = DatabaseHelper.getPlayerById(session.getAccount().getPlayerUid());
Player player = DatabaseHelper.getPlayerById(session.getAccount().getPlayerUid());
if (player == null) {
// Send packets
session.setState(SessionState.PICKING_CHARACTER);
session.send(new GenshinPacket(PacketOpcodes.DoSetPlayerBornDataNotify));
session.send(new BasePacket(PacketOpcodes.DoSetPlayerBornDataNotify));
} else {
// Set character
session.setPlayer(player);
......
......@@ -19,8 +19,6 @@ public class HandlerPrivateChatReq extends PacketHandler {
} else if (content == PrivateChatReq.ContentCase.ICON) {
session.getServer().getChatManager().sendPrivateMessage(session.getPlayer(), req.getTargetUid(), req.getIcon());
}
//session.send(new GenshinPacket(PacketOpcodes.PrivateChatRsp)); // Unused by server
}
}
......@@ -2,7 +2,7 @@ package emu.grasscutter.server.packet.recv;
import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.entity.EntityMonster;
import emu.grasscutter.game.entity.GenshinEntity;
import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.game.props.LifeState;
import emu.grasscutter.net.packet.Opcodes;
......@@ -19,7 +19,7 @@ public class HandlerSceneEntityDrownReq extends PacketHandler {
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
SceneEntityDrownReq req = SceneEntityDrownReq.parseFrom(payload);
GenshinEntity entity = session.getPlayer().getScene().getEntityById(req.getEntityId());
GameEntity entity = session.getPlayer().getScene().getEntityById(req.getEntityId());
if (entity == null || !(entity instanceof EntityMonster || entity instanceof EntityAvatar)) {
return;
......
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.game.GenshinPlayer.SceneLoadState;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.game.Player.SceneLoadState;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.packet.PacketHandler;
......@@ -31,7 +31,7 @@ public class HandlerSceneInitFinishReq extends PacketHandler {
session.send(new PacketWorldPlayerInfoNotify(session.getPlayer().getWorld()));
session.send(new PacketWorldDataNotify(session.getPlayer().getWorld()));
session.send(new PacketSceneUnlockInfoNotify());
session.send(new GenshinPacket(PacketOpcodes.SceneForceUnlockNotify));
session.send(new BasePacket(PacketOpcodes.SceneForceUnlockNotify));
session.send(new PacketHostPlayerNotify(session.getPlayer().getWorld()));
session.send(new PacketSceneTimeNotify(session.getPlayer()));
......
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