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
b99ca4e0
Commit
b99ca4e0
authored
Apr 20, 2022
by
Melledy
Browse files
Refactor PacketSceneTransToPointRsp and add a null check when getting ScenePointEntries
parent
12501944
Changes
4
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/command/commands/ChangeSceneCommand.java
View file @
b99ca4e0
...
@@ -23,11 +23,17 @@ public final class ChangeSceneCommand implements CommandHandler {
...
@@ -23,11 +23,17 @@ public final class ChangeSceneCommand implements CommandHandler {
try
{
try
{
int
sceneId
=
Integer
.
parseInt
(
args
.
get
(
0
));
int
sceneId
=
Integer
.
parseInt
(
args
.
get
(
0
));
boolean
result
=
sender
.
getWorld
().
transferPlayerToScene
(
sender
,
sceneId
,
sender
.
getPos
());
if
(
sceneId
==
sender
.
getSceneId
())
{
CommandHandler
.
sendMessage
(
sender
,
"You are already in that scene"
);
return
;
}
boolean
result
=
sender
.
getWorld
().
transferPlayerToScene
(
sender
,
sceneId
,
sender
.
getPos
());
CommandHandler
.
sendMessage
(
sender
,
"Changed to scene "
+
sceneId
);
CommandHandler
.
sendMessage
(
sender
,
"Changed to scene "
+
sceneId
);
if
(!
result
)
{
if
(!
result
)
{
CommandHandler
.
sendMessage
(
sender
,
"Scene does not exist
or you are already in it
"
);
CommandHandler
.
sendMessage
(
sender
,
"Scene does not exist"
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
CommandHandler
.
sendMessage
(
sender
,
"Usage: changescene <scene id>"
);
CommandHandler
.
sendMessage
(
sender
,
"Usage: changescene <scene id>"
);
...
...
src/main/java/emu/grasscutter/game/World.java
View file @
b99ca4e0
...
@@ -207,27 +207,8 @@ public class World implements Iterable<GenshinPlayer> {
...
@@ -207,27 +207,8 @@ public class World implements Iterable<GenshinPlayer> {
this
.
getScenes
().
remove
(
scene
.
getId
());
this
.
getScenes
().
remove
(
scene
.
getId
());
}
}
public
boolean
forceTransferPlayerToScene
(
GenshinPlayer
player
,
int
sceneId
,
Position
pos
)
{
// Forces the client to reload the scene map to prevent the player from falling off the map.
if
(
GenshinData
.
getSceneDataMap
().
get
(
sceneId
)
==
null
)
{
return
false
;
}
if
(
player
.
getScene
()
!=
null
)
{
player
.
getScene
().
removePlayer
(
player
);
}
GenshinScene
scene
=
this
.
getSceneById
(
sceneId
);
scene
.
addPlayer
(
player
);
player
.
getPos
().
set
(
pos
);
// Teleport packet
player
.
sendPacket
(
new
PacketPlayerEnterSceneNotify
(
player
,
EnterType
.
EnterSelf
,
EnterReason
.
TransPoint
,
sceneId
,
pos
));
return
true
;
}
public
boolean
transferPlayerToScene
(
GenshinPlayer
player
,
int
sceneId
,
Position
pos
)
{
public
boolean
transferPlayerToScene
(
GenshinPlayer
player
,
int
sceneId
,
Position
pos
)
{
if
(
player
.
getScene
().
getId
()
==
sceneId
||
GenshinData
.
getSceneDataMap
().
get
(
sceneId
)
==
null
)
{
if
(
GenshinData
.
getSceneDataMap
().
get
(
sceneId
)
==
null
)
{
return
false
;
return
false
;
}
}
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneTransToPointReq.java
View file @
b99ca4e0
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
);
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
()));
session
.
send
(
new
PacketSceneTransToPointRsp
(
session
.
getPlayer
(),
req
.
getPointId
(),
req
.
getSceneId
()));
}
else
{
session
.
send
(
new
PacketSceneTransToPointRsp
());
}
}
}
}
}
src/main/java/emu/grasscutter/server/packet/send/PacketSceneTransToPointRsp.java
View file @
b99ca4e0
...
@@ -13,17 +13,6 @@ public class PacketSceneTransToPointRsp extends GenshinPacket {
...
@@ -13,17 +13,6 @@ public class PacketSceneTransToPointRsp extends GenshinPacket {
public
PacketSceneTransToPointRsp
(
GenshinPlayer
player
,
int
pointId
,
int
sceneId
)
{
public
PacketSceneTransToPointRsp
(
GenshinPlayer
player
,
int
pointId
,
int
sceneId
)
{
super
(
PacketOpcodes
.
SceneTransToPointRsp
);
super
(
PacketOpcodes
.
SceneTransToPointRsp
);
String
code
=
sceneId
+
"_"
+
pointId
;
ScenePointEntry
scenePointEntry
=
GenshinData
.
getScenePointEntries
().
get
(
code
);
float
x
=
scenePointEntry
.
getPointData
().
getTranPos
().
getX
();
float
y
=
scenePointEntry
.
getPointData
().
getTranPos
().
getY
();
float
z
=
scenePointEntry
.
getPointData
().
getTranPos
().
getZ
();
player
.
getPos
().
set
(
new
Position
(
x
,
y
,
z
));
player
.
getWorld
().
forceTransferPlayerToScene
(
player
,
sceneId
,
player
.
getPos
());
SceneTransToPointRsp
proto
=
SceneTransToPointRsp
.
newBuilder
()
SceneTransToPointRsp
proto
=
SceneTransToPointRsp
.
newBuilder
()
.
setRetcode
(
0
)
.
setRetcode
(
0
)
.
setPointId
(
pointId
)
.
setPointId
(
pointId
)
...
@@ -32,4 +21,14 @@ public class PacketSceneTransToPointRsp extends GenshinPacket {
...
@@ -32,4 +21,14 @@ public class PacketSceneTransToPointRsp extends GenshinPacket {
this
.
setData
(
proto
);
this
.
setData
(
proto
);
}
}
public
PacketSceneTransToPointRsp
()
{
super
(
PacketOpcodes
.
SceneTransToPointRsp
);
SceneTransToPointRsp
proto
=
SceneTransToPointRsp
.
newBuilder
()
.
setRetcode
(
1
)
// Internal server error
.
build
();
this
.
setData
(
proto
);
}
}
}
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