Commit 716380a0 authored by Melledy's avatar Melledy
Browse files

Merge branch 'development' into java-16

parents 09c8ed34 627d3dda
...@@ -7,7 +7,7 @@ public class ComboTokenReqJson { ...@@ -7,7 +7,7 @@ public class ComboTokenReqJson {
public String device; public String device;
public String sign; public String sign;
public class LoginTokenData { public static class LoginTokenData {
public String uid; public String uid;
public String token; public String token;
public boolean guest; public boolean guest;
......
...@@ -5,7 +5,7 @@ public class ComboTokenResJson { ...@@ -5,7 +5,7 @@ public class ComboTokenResJson {
public int retcode; public int retcode;
public LoginData data = new LoginData(); public LoginData data = new LoginData();
public class LoginData { public static class LoginData {
public int account_type = 1; public int account_type = 1;
public boolean heartbeat; public boolean heartbeat;
public String combo_id; public String combo_id;
......
...@@ -5,7 +5,7 @@ public class LoginResultJson { ...@@ -5,7 +5,7 @@ public class LoginResultJson {
public int retcode; public int retcode;
public VerifyData data = new VerifyData(); public VerifyData data = new VerifyData();
public class VerifyData { public static class VerifyData {
public VerifyAccountData account = new VerifyAccountData(); public VerifyAccountData account = new VerifyAccountData();
public boolean device_grant_required = false; public boolean device_grant_required = false;
public String realname_operation = "NONE"; public String realname_operation = "NONE";
...@@ -13,7 +13,7 @@ public class LoginResultJson { ...@@ -13,7 +13,7 @@ public class LoginResultJson {
public boolean safe_mobile_required = false; public boolean safe_mobile_required = false;
} }
public class VerifyAccountData { public static class VerifyAccountData {
public String uid; public String uid;
public String name = ""; public String name = "";
public String email; public String email;
......
...@@ -87,7 +87,7 @@ public class GameServerPacketHandler { ...@@ -87,7 +87,7 @@ public class GameServerPacketHandler {
} }
// Log unhandled packets // Log unhandled packets
if (Grasscutter.getConfig().LOG_PACKETS) { if (Grasscutter.getConfig().getGameServerOptions().LOG_PACKETS) {
//Grasscutter.getLogger().info("Unhandled packet (" + opcode + "): " + PacketOpcodesUtil.getOpcodeName(opcode)); //Grasscutter.getLogger().info("Unhandled packet (" + opcode + "): " + PacketOpcodesUtil.getOpcodeName(opcode));
} }
} }
......
...@@ -165,7 +165,7 @@ public class GameSession extends MihoyoKcpChannel { ...@@ -165,7 +165,7 @@ public class GameSession extends MihoyoKcpChannel {
byte[] data = genshinPacket.build(); byte[] data = genshinPacket.build();
// Log // Log
if (Grasscutter.getConfig().LOG_PACKETS) { if (Grasscutter.getConfig().getGameServerOptions().LOG_PACKETS) {
logPacket(genshinPacket); logPacket(genshinPacket);
} }
...@@ -225,7 +225,7 @@ public class GameSession extends MihoyoKcpChannel { ...@@ -225,7 +225,7 @@ public class GameSession extends MihoyoKcpChannel {
} }
// Log packet // Log packet
if (Grasscutter.getConfig().LOG_PACKETS) { if (Grasscutter.getConfig().getGameServerOptions().LOG_PACKETS) {
Grasscutter.getLogger().info("RECV: " + PacketOpcodesUtil.getOpcodeName(opcode) + " (" + opcode + ")"); Grasscutter.getLogger().info("RECV: " + PacketOpcodesUtil.getOpcodeName(opcode) + " (" + opcode + ")");
System.out.println(Utils.bytesToHex(payload)); System.out.println(Utils.bytesToHex(payload));
} }
......
...@@ -31,8 +31,11 @@ public class HandlerEnterSceneDoneReq extends PacketHandler { ...@@ -31,8 +31,11 @@ public class HandlerEnterSceneDoneReq extends PacketHandler {
// Locations // Locations
session.send(new PacketWorldPlayerLocationNotify(session.getPlayer().getWorld())); session.send(new PacketWorldPlayerLocationNotify(session.getPlayer().getWorld()));
session.send(new PacketScenePlayerLocationNotify(session.getPlayer())); session.send(new PacketScenePlayerLocationNotify(session.getPlayer().getScene()));
session.send(new PacketWorldPlayerRTTNotify(session.getPlayer().getWorld())); session.send(new PacketWorldPlayerRTTNotify(session.getPlayer().getWorld()));
// Reset timer for sending player locations
session.getPlayer().resetSendPlayerLocTime();
} }
} }
...@@ -35,15 +35,15 @@ public class HandlerGetPlayerTokenReq extends PacketHandler { ...@@ -35,15 +35,15 @@ public class HandlerGetPlayerTokenReq extends PacketHandler {
// Has character // Has character
boolean doesPlayerExist = false; boolean doesPlayerExist = false;
if (account.getPlayerId() > 0) { if (account.getPlayerUid() > 0) {
// Set flag for player existing // Set flag for player existing
doesPlayerExist = DatabaseHelper.checkPlayerExists(account.getPlayerId()); doesPlayerExist = DatabaseHelper.checkPlayerExists(account.getPlayerUid());
} }
// Set reserve player id if account doesnt exist // Set reserve player id if account doesnt exist
if (!doesPlayerExist) { if (!doesPlayerExist) {
int id = DatabaseHelper.getNextPlayerId(session.getAccount().getPlayerId()); int id = DatabaseHelper.getNextPlayerId(session.getAccount().getPlayerUid());
if (id != session.getAccount().getPlayerId()) { if (id != session.getAccount().getPlayerUid()) {
session.getAccount().setPlayerId(id); session.getAccount().setPlayerId(id);
session.getAccount().save(); session.getAccount().save();
} }
......
...@@ -30,7 +30,7 @@ public class HandlerPlayerLoginReq extends PacketHandler { ...@@ -30,7 +30,7 @@ public class HandlerPlayerLoginReq extends PacketHandler {
} }
// Load character from db // Load character from db
GenshinPlayer player = DatabaseHelper.getPlayerById(session.getAccount().getPlayerId()); GenshinPlayer player = DatabaseHelper.getPlayerById(session.getAccount().getPlayerUid());
if (player == null) { if (player == null) {
// Send packets // Send packets
......
package emu.grasscutter.server.packet.recv; package emu.grasscutter.server.packet.recv;
import emu.grasscutter.data.GenshinData;
import emu.grasscutter.data.custom.ScenePointEntry;
import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SceneTransToPointReqOuterClass.SceneTransToPointReq; import emu.grasscutter.net.proto.SceneTransToPointReqOuterClass.SceneTransToPointReq;
import emu.grasscutter.net.proto.SceneTransToPointRspOuterClass.SceneTransToPointRsp;
import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketSceneTransToPointRsp; import emu.grasscutter.server.packet.send.PacketSceneTransToPointRsp;
import emu.grasscutter.utils.Position;
@Opcodes(PacketOpcodes.SceneTransToPointReq) @Opcodes(PacketOpcodes.SceneTransToPointReq)
public class HandlerSceneTransToPointReq extends PacketHandler { public class HandlerSceneTransToPointReq extends PacketHandler {
...@@ -13,7 +17,20 @@ public class HandlerSceneTransToPointReq extends PacketHandler { ...@@ -13,7 +17,20 @@ public class HandlerSceneTransToPointReq extends PacketHandler {
@Override @Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
SceneTransToPointReq req = SceneTransToPointReq.parseFrom(payload); SceneTransToPointReq req = SceneTransToPointReq.parseFrom(payload);
session.send(new PacketSceneTransToPointRsp(session.getPlayer(), req.getPointId(), req.getSceneId()));
String code = req.getSceneId() + "_" + req.getPointId();
ScenePointEntry scenePointEntry = GenshinData.getScenePointEntries().get(code);
if (scenePointEntry != null) {
float x = scenePointEntry.getPointData().getTranPos().getX();
float y = scenePointEntry.getPointData().getTranPos().getY();
float z = scenePointEntry.getPointData().getTranPos().getZ();
session.getPlayer().getWorld().transferPlayerToScene(session.getPlayer(), req.getSceneId(), new Position(x, y, z));
session.send(new PacketSceneTransToPointRsp(session.getPlayer(), req.getPointId(), req.getSceneId()));
} else {
session.send(new PacketSceneTransToPointRsp());
}
} }
} }
...@@ -3,6 +3,7 @@ package emu.grasscutter.server.packet.recv; ...@@ -3,6 +3,7 @@ package emu.grasscutter.server.packet.recv;
import emu.grasscutter.net.packet.GenshinPacket; import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SetEntityClientDataNotifyOuterClass.SetEntityClientDataNotify;
import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.game.GameSession;
...@@ -16,8 +17,11 @@ public class HandlerSetEntityClientDataNotify extends PacketHandler { ...@@ -16,8 +17,11 @@ public class HandlerSetEntityClientDataNotify extends PacketHandler {
return; return;
} }
// Make sure packet is a valid proto before replaying it to the other players
SetEntityClientDataNotify notif = SetEntityClientDataNotify.parseFrom(payload);
GenshinPacket packet = new GenshinPacket(PacketOpcodes.SetEntityClientDataNotify, true); GenshinPacket packet = new GenshinPacket(PacketOpcodes.SetEntityClientDataNotify, true);
packet.setData(payload); packet.setData(notif);
session.getPlayer().getScene().broadcastPacketToOthers(session.getPlayer(), packet); session.getPlayer().getScene().broadcastPacketToOthers(session.getPlayer(), packet);
} }
......
...@@ -43,7 +43,7 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler { ...@@ -43,7 +43,7 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler {
try { try {
// Save to db // Save to db
DatabaseHelper.createPlayer(player, session.getAccount().getPlayerId()); DatabaseHelper.createPlayer(player, session.getAccount().getPlayerUid());
// Create avatar // Create avatar
if (player.getAvatars().getAvatarCount() == 0) { if (player.getAvatars().getAvatarCount() == 0) {
......
...@@ -8,8 +8,8 @@ import emu.grasscutter.net.proto.AbilityChangeNotifyOuterClass.AbilityChangeNoti ...@@ -8,8 +8,8 @@ import emu.grasscutter.net.proto.AbilityChangeNotifyOuterClass.AbilityChangeNoti
public class PacketAbilityChangeNotify extends GenshinPacket { public class PacketAbilityChangeNotify extends GenshinPacket {
public PacketAbilityChangeNotify(EntityAvatar entity) { public PacketAbilityChangeNotify(EntityAvatar entity) {
super(PacketOpcodes.AbilityChangeNotify); super(PacketOpcodes.AbilityChangeNotify, true);
AbilityChangeNotify proto = AbilityChangeNotify.newBuilder() AbilityChangeNotify proto = AbilityChangeNotify.newBuilder()
.setEntityId(entity.getId()) .setEntityId(entity.getId())
.setAbilityControlBlock(entity.getAbilityControlBlock()) .setAbilityControlBlock(entity.getAbilityControlBlock())
......
...@@ -23,7 +23,6 @@ public class PacketGetPlayerFriendListRsp extends GenshinPacket { ...@@ -23,7 +23,6 @@ public class PacketGetPlayerFriendListRsp extends GenshinPacket {
.setWorldLevel(0) .setWorldLevel(0)
.setSignature("") .setSignature("")
.setLastActiveTime((int) (System.currentTimeMillis() / 1000f)) .setLastActiveTime((int) (System.currentTimeMillis() / 1000f))
.setIsMpModeAvailable(true)
.setNameCardId(210001) .setNameCardId(210001)
.setOnlineState(FriendOnlineState.FRIEND_ONLINE) .setOnlineState(FriendOnlineState.FRIEND_ONLINE)
.setParam(1) .setParam(1)
......
...@@ -16,7 +16,7 @@ public class PacketGetPlayerTokenRsp extends GenshinPacket { ...@@ -16,7 +16,7 @@ public class PacketGetPlayerTokenRsp extends GenshinPacket {
this.setUseDispatchKey(true); this.setUseDispatchKey(true);
GetPlayerTokenRsp p = GetPlayerTokenRsp.newBuilder() GetPlayerTokenRsp p = GetPlayerTokenRsp.newBuilder()
.setPlayerUid(session.getAccount().getPlayerId()) .setPlayerUid(session.getAccount().getPlayerUid())
.setAccountToken(session.getAccount().getToken()) .setAccountToken(session.getAccount().getToken())
.setAccountType(1) .setAccountType(1)
.setIsProficientPlayer(doesPlayerExist) // Not sure where this goes .setIsProficientPlayer(doesPlayerExist) // Not sure where this goes
......
...@@ -52,7 +52,7 @@ public class PacketPlayerEnterSceneNotify extends GenshinPacket { ...@@ -52,7 +52,7 @@ public class PacketPlayerEnterSceneNotify extends GenshinPacket {
.setSceneId(newScene) .setSceneId(newScene)
.setPos(newPos.toProto()) .setPos(newPos.toProto())
.setSceneBeginTime(System.currentTimeMillis()) .setSceneBeginTime(System.currentTimeMillis())
.setType(EnterType.EnterSelf) .setType(type)
.setTargetUid(target.getUid()) .setTargetUid(target.getUid())
.setEnterSceneToken(player.getEnterSceneToken()) .setEnterSceneToken(player.getEnterSceneToken())
.setWorldLevel(target.getWorld().getWorldLevel()) .setWorldLevel(target.getWorld().getWorldLevel())
......
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import com.google.protobuf.ByteString;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.net.packet.GenshinPacket; import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.PlayerLoginRspOuterClass.PlayerLoginRsp; import emu.grasscutter.net.proto.PlayerLoginRspOuterClass.PlayerLoginRsp;
import emu.grasscutter.net.proto.QueryCurrRegionHttpRspOuterClass;
import emu.grasscutter.net.proto.RegionInfoOuterClass.RegionInfo; import emu.grasscutter.net.proto.RegionInfoOuterClass.RegionInfo;
import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.utils.FileUtils;
import java.io.File;
import java.net.URL;
import java.util.Base64;
public class PacketPlayerLoginRsp extends GenshinPacket { public class PacketPlayerLoginRsp extends GenshinPacket {
private static QueryCurrRegionHttpRspOuterClass.QueryCurrRegionHttpRsp regionCache;
public PacketPlayerLoginRsp(GameSession session) { public PacketPlayerLoginRsp(GameSession session) {
super(PacketOpcodes.PlayerLoginRsp, 1); super(PacketOpcodes.PlayerLoginRsp, 1);
this.setUseDispatchKey(true); this.setUseDispatchKey(true);
RegionInfo info = Grasscutter.getDispatchServer().getCurrRegion().getRegionInfo(); RegionInfo info;
if(Grasscutter.getConfig().RunMode.equalsIgnoreCase("GAME_ONLY")) {
if (regionCache == null) {
try {
File file = new File(Grasscutter.getConfig().DATA_FOLDER + "query_cur_region.txt");
String query_cur_region = "";
if (file.exists()) {
query_cur_region = new String(FileUtils.read(file));
} else {
Grasscutter.getLogger().warn("query_cur_region not found! Using default current region.");
}
byte[] decodedCurRegion = Base64.getDecoder().decode(query_cur_region);
QueryCurrRegionHttpRspOuterClass.QueryCurrRegionHttpRsp regionQuery = QueryCurrRegionHttpRspOuterClass.QueryCurrRegionHttpRsp.parseFrom(decodedCurRegion);
RegionInfo serverRegion = regionQuery.getRegionInfo().toBuilder()
.setIp((Grasscutter.getConfig().getGameServerOptions().PublicIp.isEmpty() ? Grasscutter.getConfig().getGameServerOptions().Ip : Grasscutter.getConfig().getGameServerOptions().PublicIp))
.setPort(Grasscutter.getConfig().getGameServerOptions().PublicPort != 0 ? Grasscutter.getConfig().getGameServerOptions().PublicPort : Grasscutter.getConfig().getGameServerOptions().Port)
.setSecretKey(ByteString.copyFrom(FileUtils.read(Grasscutter.getConfig().KEY_FOLDER + "dispatchSeed.bin")))
.build();
regionCache = regionQuery.toBuilder().setRegionInfo(serverRegion).build();
} catch (Exception e) {
Grasscutter.getLogger().error("Error while initializing region cache!", e);
}
}
info = regionCache.getRegionInfo();
} else {
info = Grasscutter.getDispatchServer().getCurrRegion().getRegionInfo();
}
PlayerLoginRsp p = PlayerLoginRsp.newBuilder() PlayerLoginRsp p = PlayerLoginRsp.newBuilder()
.setIsUseAbilityHash(true) // true .setIsUseAbilityHash(true) // true
.setAbilityHashCode(1844674) // 1844674 .setAbilityHashCode(1844674) // 1844674
......
...@@ -19,7 +19,7 @@ public class PacketPlayerStoreNotify extends GenshinPacket { ...@@ -19,7 +19,7 @@ public class PacketPlayerStoreNotify extends GenshinPacket {
PlayerStoreNotify.Builder p = PlayerStoreNotify.newBuilder() PlayerStoreNotify.Builder p = PlayerStoreNotify.newBuilder()
.setStoreType(StoreType.StorePack) .setStoreType(StoreType.StorePack)
.setWeightLimit(Grasscutter.getConfig().getServerOptions().InventoryLimitAll); .setWeightLimit(Grasscutter.getConfig().getGameServerOptions().InventoryLimitAll);
for (GenshinItem item : player.getInventory()) { for (GenshinItem item : player.getInventory()) {
Item itemProto = item.toProto(); Item itemProto = item.toProto();
......
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import emu.grasscutter.Config.ServerOptions; import emu.grasscutter.Config.GameServerOptions;
import emu.grasscutter.GenshinConstants; import emu.grasscutter.GenshinConstants;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.GenshinPlayer;
...@@ -14,7 +14,7 @@ public class PacketPullRecentChatRsp extends GenshinPacket { ...@@ -14,7 +14,7 @@ public class PacketPullRecentChatRsp extends GenshinPacket {
public PacketPullRecentChatRsp(GenshinPlayer player) { public PacketPullRecentChatRsp(GenshinPlayer player) {
super(PacketOpcodes.PullRecentChatRsp); super(PacketOpcodes.PullRecentChatRsp);
ServerOptions serverOptions = Grasscutter.getConfig().getServerOptions(); GameServerOptions serverOptions = Grasscutter.getConfig().getGameServerOptions();
PullRecentChatRsp.Builder proto = PullRecentChatRsp.newBuilder(); PullRecentChatRsp.Builder proto = PullRecentChatRsp.newBuilder();
if (serverOptions.WelcomeEmotes != null && serverOptions.WelcomeEmotes.length > 0) { if (serverOptions.WelcomeEmotes != null && serverOptions.WelcomeEmotes.length > 0) {
...@@ -33,7 +33,7 @@ public class PacketPullRecentChatRsp extends GenshinPacket { ...@@ -33,7 +33,7 @@ public class PacketPullRecentChatRsp extends GenshinPacket {
.setTime((int) (System.currentTimeMillis() / 1000)) .setTime((int) (System.currentTimeMillis() / 1000))
.setUid(GenshinConstants.SERVER_CONSOLE_UID) .setUid(GenshinConstants.SERVER_CONSOLE_UID)
.setToUid(player.getUid()) .setToUid(player.getUid())
.setText(Grasscutter.getConfig().getServerOptions().WelcomeMotd) .setText(Grasscutter.getConfig().getGameServerOptions().WelcomeMotd)
.build(); .build();
proto.addChatInfo(welcomeMotd); proto.addChatInfo(welcomeMotd);
......
...@@ -12,7 +12,7 @@ public class PacketSceneAreaWeatherNotify extends GenshinPacket { ...@@ -12,7 +12,7 @@ public class PacketSceneAreaWeatherNotify extends GenshinPacket {
super(PacketOpcodes.SceneAreaWeatherNotify); super(PacketOpcodes.SceneAreaWeatherNotify);
SceneAreaWeatherNotify proto = SceneAreaWeatherNotify.newBuilder() SceneAreaWeatherNotify proto = SceneAreaWeatherNotify.newBuilder()
.setWeatherAreaId(1) .setWeatherAreaId(player.getScene().getWeather())
.setClimateType(player.getScene().getClimate().getValue()) .setClimateType(player.getScene().getClimate().getValue())
.build(); .build();
......
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.GenshinScene;
import emu.grasscutter.net.packet.GenshinPacket; import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.ScenePlayerLocationNotifyOuterClass.ScenePlayerLocationNotify; import emu.grasscutter.net.proto.ScenePlayerLocationNotifyOuterClass.ScenePlayerLocationNotify;
public class PacketScenePlayerLocationNotify extends GenshinPacket { public class PacketScenePlayerLocationNotify extends GenshinPacket {
public PacketScenePlayerLocationNotify(GenshinPlayer player) { public PacketScenePlayerLocationNotify(GenshinScene scene) {
super(PacketOpcodes.ScenePlayerLocationNotify); super(PacketOpcodes.ScenePlayerLocationNotify);
ScenePlayerLocationNotify.Builder proto = ScenePlayerLocationNotify.newBuilder() ScenePlayerLocationNotify.Builder proto = ScenePlayerLocationNotify.newBuilder()
.setSceneId(player.getSceneId()); .setSceneId(scene.getId());
for (GenshinPlayer p : player.getWorld().getPlayers()) { for (GenshinPlayer p : scene.getPlayers()) {
proto.addPlayerLocList(p.getPlayerLocationInfo()); proto.addPlayerLocList(p.getPlayerLocationInfo());
} }
......
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