Commit b9f7c657 authored by Benjamin Elsdon's avatar Benjamin Elsdon
Browse files

Merge remote-tracking branch 'upstream/development' into dev-mail

parents eb495807 782618cd
......@@ -103,8 +103,8 @@ public final class DispatchServer {
byte[] decoded2 = Base64.getDecoder().decode(query_cur_region);
QueryCurrRegionHttpRsp regionQuery = QueryCurrRegionHttpRsp.parseFrom(decoded2);
List<RegionSimpleInfo> servers = new ArrayList<RegionSimpleInfo>();
List<String> usedNames = new ArrayList<String>(); // List to check for potential naming conflicts
List<RegionSimpleInfo> servers = new ArrayList<>();
List<String> usedNames = new ArrayList<>(); // List to check for potential naming conflicts
if (Grasscutter.getConfig().RunMode.equalsIgnoreCase("HYBRID")) { // Automatically add the game server if in
// hybrid mode
RegionSimpleInfo server = RegionSimpleInfo.newBuilder()
......@@ -126,10 +126,10 @@ public final class DispatchServer {
servers.add(server);
RegionInfo serverRegion = regionQuery.getRegionInfo().toBuilder()
.setIp((Grasscutter.getConfig().getGameServerOptions().PublicIp.isEmpty()
.setGateserverIp((Grasscutter.getConfig().getGameServerOptions().PublicIp.isEmpty()
? Grasscutter.getConfig().getGameServerOptions().Ip
: Grasscutter.getConfig().getGameServerOptions().PublicIp))
.setPort(Grasscutter.getConfig().getGameServerOptions().PublicPort != 0
.setGateserverPort(Grasscutter.getConfig().getGameServerOptions().PublicPort != 0
? Grasscutter.getConfig().getGameServerOptions().PublicPort
: Grasscutter.getConfig().getGameServerOptions().Port)
.setSecretKey(ByteString
......@@ -169,8 +169,8 @@ public final class DispatchServer {
servers.add(server);
RegionInfo serverRegion = regionQuery.getRegionInfo().toBuilder()
.setIp(regionInfo.Ip)
.setPort(regionInfo.Port)
.setGateserverIp(regionInfo.Ip)
.setGateserverPort(regionInfo.Port)
.setSecretKey(ByteString
.copyFrom(FileUtils.read(Grasscutter.getConfig().KEY_FOLDER + "dispatchSeed.bin")))
.build();
......@@ -181,7 +181,7 @@ public final class DispatchServer {
}
QueryRegionListHttpRsp regionList = QueryRegionListHttpRsp.newBuilder()
.addAllServers(servers)
.addAllRegionList(servers)
.setClientSecretKey(rl.getClientSecretKey())
.setClientCustomConfigEncrypted(rl.getClientCustomConfigEncrypted())
.setEnableLoginPc(true)
......@@ -268,7 +268,10 @@ public final class DispatchServer {
Grasscutter.getLogger()
.info(String.format("[Dispatch] Client %s request: query_region_list", t.getRemoteAddress()));
responseHTML(t, regionListBase64);
// Invoke event.
QueryAllRegionsEvent event = new QueryAllRegionsEvent(regionListBase64); event.call();
// Respond with event result.
responseHTML(t, event.getRegionList());
});
for (String regionName : regions.keySet()) {
......
......@@ -10,6 +10,10 @@ public abstract class ServerEvent extends Event {
this.type = type;
}
public Type getServerType() {
return this.type;
}
public enum Type {
DISPATCH,
GAME
......
package emu.grasscutter.server.event.game;
import emu.grasscutter.server.event.ServerEvent;
public final class ServerTickEvent extends ServerEvent {
public ServerTickEvent() {
super(Type.GAME);
}
}
package emu.grasscutter.server.event.internal;
import emu.grasscutter.server.event.ServerEvent;
import java.time.OffsetDateTime;
public final class ServerStartEvent extends ServerEvent {
private final OffsetDateTime startTime;
public ServerStartEvent(Type type, OffsetDateTime startTime) {
super(type);
this.startTime = startTime;
}
public OffsetDateTime getStartTime() {
return this.startTime;
}
}
package emu.grasscutter.server.event.internal;
import emu.grasscutter.server.event.ServerEvent;
import java.time.OffsetDateTime;
public final class ServerStopEvent extends ServerEvent {
private final OffsetDateTime stopTime;
public ServerStopEvent(Type type, OffsetDateTime stopTime) {
super(type);
this.stopTime = stopTime;
}
public OffsetDateTime getStopTime() {
return this.stopTime;
}
}
package emu.grasscutter.server.game;
import java.net.InetSocketAddress;
import java.time.OffsetDateTime;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
......@@ -20,7 +21,10 @@ 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 org.greenrobot.eventbus.EventBus;
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;
public final class GameServer extends MihoyoKcpServer {
private final InetSocketAddress address;
......@@ -37,17 +41,9 @@ public final class GameServer extends MihoyoKcpServer {
private final DungeonManager dungeonManager;
private final CommandMap commandMap;
public EventBus OnGameServerStartFinish;
public EventBus OnGameServerTick;
public EventBus OnGameServerStop;
public GameServer(InetSocketAddress address) {
super(address);
OnGameServerStartFinish = EventBus.builder().throwSubscriberException(true).logNoSubscriberMessages(false).build();
OnGameServerTick = EventBus.builder().throwSubscriberException(true).logNoSubscriberMessages(false).build();
OnGameServerStop = EventBus.builder().throwSubscriberException(true).logNoSubscriberMessages(false).build();
this.setServerInitializer(new GameServerInitializer(this));
this.address = address;
this.packetHandler = new GameServerPacketHandler(PacketHandler.class);
......@@ -179,11 +175,7 @@ public final class GameServer extends MihoyoKcpServer {
world.onTick();
}
for (GenshinPlayer player : this.getPlayers().values()) {
player.onTick();
}
OnGameServerTick.post(new GameServerTickEvent());
ServerTickEvent event = new ServerTickEvent(); event.call();
}
public void registerWorld(World world) {
......@@ -198,12 +190,11 @@ public final class GameServer extends MihoyoKcpServer {
@Override
public void onStartFinish() {
Grasscutter.getLogger().info("Game Server started on port " + address.getPort());
OnGameServerStartFinish.post(new GameServerStartFinishEvent());
ServerStartEvent event = new ServerStartEvent(ServerEvent.Type.GAME, OffsetDateTime.now()); event.call();
}
public void onServerShutdown() {
OnGameServerStop.post(new GameServerStopEvent());
ServerStopEvent event = new ServerStopEvent(ServerEvent.Type.GAME, OffsetDateTime.now()); event.call();
// Kick and save all players
List<GenshinPlayer> list = new ArrayList<>(this.getPlayers().size());
......
......@@ -89,7 +89,7 @@ public class GameServerPacketHandler {
// Log unhandled packets
if (Grasscutter.getConfig().getGameServerOptions().LOG_PACKETS) {
//Grasscutter.getLogger().info("Unhandled packet (" + opcode + "): " + PacketOpcodesUtil.getOpcodeName(opcode));
Grasscutter.getLogger().info("Unhandled packet (" + opcode + "): " + emu.grasscutter.net.packet.PacketOpcodesUtil.getOpcodeName(opcode));
}
}
}
......@@ -3,11 +3,14 @@ package emu.grasscutter.server.game;
import java.io.File;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.HashSet;
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.net.packet.PacketOpcodes;
import emu.grasscutter.net.packet.PacketOpcodesUtil;
import emu.grasscutter.netty.MihoyoKcpChannel;
import emu.grasscutter.server.event.game.SendPacketEvent;
......@@ -178,10 +181,20 @@ public class GameSession extends MihoyoKcpChannel {
//System.out.println(Utils.bytesToHex(genshinPacket.getData()));
}
private static final Set<Integer> loopPacket = Set.of(
PacketOpcodes.PingReq,
PacketOpcodes.PingRsp,
PacketOpcodes.WorldPlayerRTTNotify,
PacketOpcodes.UnionCmdNotify,
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()));
}
}
@Override
public void onMessage(ChannelHandlerContext ctx, ByteBuf data) {
......@@ -226,9 +239,11 @@ public class GameSession extends MihoyoKcpChannel {
// Log packet
if (Grasscutter.getConfig().getGameServerOptions().LOG_PACKETS) {
if (!loopPacket.contains(opcode)) {
Grasscutter.getLogger().info("RECV: " + PacketOpcodesUtil.getOpcodeName(opcode) + " (" + opcode + ")");
System.out.println(Utils.bytesToHex(payload));
}
}
// Handle
getServer().getPacketHandler().handle(this, opcode, header, payload);
......
......@@ -19,12 +19,12 @@ public class HandlerCombatInvocationsNotify extends PacketHandler {
for (CombatInvokeEntry entry : notif.getInvokeListList()) {
switch (entry.getArgumentType()) {
case CombatEvtBeingHit:
case COMBAT_EVT_BEING_HIT:
// Handle damage
EvtBeingHitInfo hitInfo = EvtBeingHitInfo.parseFrom(entry.getCombatData());
session.getPlayer().getScene().handleAttack(hitInfo.getAttackResult());
break;
case EntityMove:
case ENTITY_MOVE:
// Handle movement
EntityMoveInfo moveInfo = EntityMoveInfo.parseFrom(entry.getCombatData());
GenshinEntity entity = session.getPlayer().getScene().getEntityById(moveInfo.getEntityId());
......
......@@ -3,22 +3,18 @@ package emu.grasscutter.server.packet.recv;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SitReqOuterClass;
import emu.grasscutter.net.proto.CombineReqOuterClass;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketSitRsp;
import emu.grasscutter.utils.Position;
@Opcodes(PacketOpcodes.SitReq)
public class HandleSitReq extends PacketHandler {
@Opcodes(PacketOpcodes.CombineReq)
public class HandlerCombineReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
SitReqOuterClass.SitReq req = SitReqOuterClass.SitReq.parseFrom(payload);
float x = req.getPosition().getX();
float y = req.getPosition().getY();
float z = req.getPosition().getZ();
CombineReqOuterClass.CombineReq req = CombineReqOuterClass.CombineReq.parseFrom(payload);
session.send(new PacketSitRsp(req.getChairId(), new Position(x, y, z), session.getPlayer().getTeamManager().getCurrentAvatarEntity().getId()));
}
}
......@@ -32,7 +32,7 @@ public class HandlerMarkMapReq extends PacketHandler {
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
MarkMapReq req = MarkMapReq.parseFrom(payload);
if (req.getOp() != Operation.Add) {
if (req.getOp() != MarkMapReq.Operation.ADD) {
return;
}
......
......@@ -3,6 +3,7 @@ package emu.grasscutter.server.packet.recv;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.proto.RetcodeOuterClass;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketPlayerGetForceQuitBanInfoRsp;
......@@ -14,10 +15,10 @@ public class HandlerPlayerGetForceQuitBanInfoReq extends PacketHandler {
if (session.getServer().getMultiplayerManager().leaveCoop(session.getPlayer())) {
// Success
session.send(new PacketPlayerGetForceQuitBanInfoRsp(0));
session.send(new PacketPlayerGetForceQuitBanInfoRsp(RetcodeOuterClass.Retcode.RET_SUCC_VALUE));
} else {
// Fail
session.send(new PacketPlayerGetForceQuitBanInfoRsp(1));
session.send(new PacketPlayerGetForceQuitBanInfoRsp(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE));
}
}
......
......@@ -11,7 +11,7 @@ public class PacketAvatarChangeCostumeNotify extends GenshinPacket {
super(PacketOpcodes.AvatarChangeCostumeNotify);
AvatarChangeCostumeNotify proto = AvatarChangeCostumeNotify.newBuilder()
.setEntity(entity.toProto())
.setEntityInfo(entity.toProto())
.build();
this.setData(proto);
......
......@@ -3,6 +3,7 @@ package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.AvatarChangeCostumeRspOuterClass.AvatarChangeCostumeRsp;
import emu.grasscutter.net.proto.RetcodeOuterClass;
public class PacketAvatarChangeCostumeRsp extends GenshinPacket {
......@@ -21,7 +22,7 @@ public class PacketAvatarChangeCostumeRsp extends GenshinPacket {
super(PacketOpcodes.AvatarChangeCostumeRsp);
AvatarChangeCostumeRsp proto = AvatarChangeCostumeRsp.newBuilder()
.setRetcode(1)
.setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE)
.build();
this.setData(proto);
......
......@@ -3,6 +3,7 @@ package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.AvatarWearFlycloakRspOuterClass.AvatarWearFlycloakRsp;
import emu.grasscutter.net.proto.RetcodeOuterClass;
public class PacketAvatarWearFlycloakRsp extends GenshinPacket {
public PacketAvatarWearFlycloakRsp(long avatarGuid, int costumeId) {
......@@ -20,7 +21,7 @@ public class PacketAvatarWearFlycloakRsp extends GenshinPacket {
super(PacketOpcodes.AvatarWearFlycloakRsp);
AvatarWearFlycloakRsp proto = AvatarWearFlycloakRsp.newBuilder()
.setRetcode(1)
.setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE)
.build();
this.setData(proto);
......
......@@ -4,9 +4,9 @@ import java.util.List;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.packet.Retcode;
import emu.grasscutter.net.proto.CalcWeaponUpgradeReturnItemsRspOuterClass.CalcWeaponUpgradeReturnItemsRsp;
import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam;
import emu.grasscutter.net.proto.RetcodeOuterClass;
public class PacketCalcWeaponUpgradeReturnItemsRsp extends GenshinPacket {
......@@ -25,7 +25,7 @@ public class PacketCalcWeaponUpgradeReturnItemsRsp extends GenshinPacket {
super(PacketOpcodes.CalcWeaponUpgradeReturnItemsRsp);
CalcWeaponUpgradeReturnItemsRsp proto = CalcWeaponUpgradeReturnItemsRsp.newBuilder()
.setRetcode(Retcode.FAIL)
.setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE)
.build();
this.setData(proto);
......
......@@ -3,6 +3,7 @@ package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.ChangeAvatarRspOuterClass.ChangeAvatarRsp;
import emu.grasscutter.net.proto.RetcodeOuterClass;
public class PacketChangeAvatarRsp extends GenshinPacket {
......@@ -10,8 +11,8 @@ public class PacketChangeAvatarRsp extends GenshinPacket {
super(PacketOpcodes.ChangeAvatarRsp);
ChangeAvatarRsp p = ChangeAvatarRsp.newBuilder()
.setRetcode(0)
.setCurrGuid(guid)
.setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE)
.setCurGuid(guid)
.build();
this.setData(p);
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.CombineReqOuterClass;
import emu.grasscutter.net.proto.CombineRspOuterClass;
import emu.grasscutter.net.proto.ItemParamOuterClass;
import emu.grasscutter.net.proto.RetcodeOuterClass;
public class PacketCombineRsp extends GenshinPacket {
public PacketCombineRsp() {
super(PacketOpcodes.CombineRsp);
CombineRspOuterClass.CombineRsp proto = CombineRspOuterClass.CombineRsp.newBuilder()
.setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE).build();
this.setData(proto);
}
public PacketCombineRsp(int retcode) {
super(PacketOpcodes.CombineRsp);
CombineRspOuterClass.CombineRsp proto = CombineRspOuterClass.CombineRsp.newBuilder()
.setRetcode(retcode).build();
this.setData(proto);
}
public PacketCombineRsp(CombineReqOuterClass.CombineReq combineReq,
Iterable<ItemParamOuterClass.ItemParam> costItemList,
Iterable<ItemParamOuterClass.ItemParam> resultItemList,
Iterable<ItemParamOuterClass.ItemParam> totalRandomItemList,
Iterable<ItemParamOuterClass.ItemParam> totalReturnItemList,
Iterable<ItemParamOuterClass.ItemParam> totalExtraItemList) {
super(PacketOpcodes.CombineRsp);
CombineRspOuterClass.CombineRsp proto = CombineRspOuterClass.CombineRsp.newBuilder()
.setRetcode(RetcodeOuterClass.Retcode.RET_SUCC_VALUE)
.setCombineId(combineReq.getCombineId())
.setCombineCount(combineReq.getCombineCount())
.setAvatarGuid(combineReq.getAvatarGuid())
.addAllCostItemList(costItemList)
.addAllResultItemList(resultItemList)
.addAllTotalRandomItemList(totalRandomItemList)
.addAllTotalReturnItemList(totalReturnItemList)
.addAllTotalExtraItemList(totalExtraItemList)
.build();
this.setData(proto);
}
}
......@@ -7,6 +7,7 @@ import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.DoGachaRspOuterClass.DoGachaRsp;
import emu.grasscutter.net.proto.GachaItemOuterClass.GachaItem;
import emu.grasscutter.net.proto.RetcodeOuterClass;
public class PacketDoGachaRsp extends GenshinPacket {
......@@ -33,7 +34,7 @@ public class PacketDoGachaRsp extends GenshinPacket {
super(PacketOpcodes.DoGachaRsp);
DoGachaRsp p = DoGachaRsp.newBuilder()
.setRetcode(1)
.setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE)
.build();
this.setData(p);
......
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