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
34f7c6e7
Commit
34f7c6e7
authored
Jun 24, 2022
by
KingRainbow44
Browse files
Formatting changes
parent
95df9a31
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/server/event/game/CommandResponseEvent.java
View file @
34f7c6e7
...
@@ -7,7 +7,7 @@ import emu.grasscutter.server.event.types.ServerEvent;
...
@@ -7,7 +7,7 @@ import emu.grasscutter.server.event.types.ServerEvent;
* @deprecated Will be removed in 1.2.3-dev or 1.3.0.
* @deprecated Will be removed in 1.2.3-dev or 1.3.0.
*/
*/
@Deprecated
(
since
=
"1.2.2-dev"
,
forRemoval
=
true
)
@Deprecated
(
since
=
"1.2.2-dev"
,
forRemoval
=
true
)
public
class
CommandResponseEvent
extends
ServerEvent
{
public
final
class
CommandResponseEvent
extends
ServerEvent
{
private
String
message
;
private
String
message
;
private
Player
player
;
private
Player
player
;
...
...
src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java
View file @
34f7c6e7
...
@@ -19,10 +19,10 @@ import static emu.grasscutter.Configuration.*;
...
@@ -19,10 +19,10 @@ import static emu.grasscutter.Configuration.*;
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
public
class
GameServerPacketHandler
{
public
class
GameServerPacketHandler
{
private
final
Int2ObjectMap
<
PacketHandler
>
handlers
;
private
final
Int2ObjectMap
<
PacketHandler
>
handlers
;
public
GameServerPacketHandler
(
Class
<?
extends
PacketHandler
>
handlerClass
)
{
public
GameServerPacketHandler
(
Class
<?
extends
PacketHandler
>
handlerClass
)
{
this
.
handlers
=
new
Int2ObjectOpenHashMap
<>();
this
.
handlers
=
new
Int2ObjectOpenHashMap
<>();
this
.
registerHandlers
(
handlerClass
);
this
.
registerHandlers
(
handlerClass
);
}
}
...
@@ -34,7 +34,7 @@ public class GameServerPacketHandler {
...
@@ -34,7 +34,7 @@ public class GameServerPacketHandler {
return
;
return
;
}
}
PacketHandler
packetHandler
=
(
PacketHandler
)
handlerClass
.
newInstance
();
PacketHandler
packetHandler
=
handlerClass
.
getDeclaredConstructor
()
.
newInstance
();
this
.
handlers
.
put
(
opcode
.
value
(),
packetHandler
);
this
.
handlers
.
put
(
opcode
.
value
(),
packetHandler
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -45,23 +45,23 @@ public class GameServerPacketHandler {
...
@@ -45,23 +45,23 @@ public class GameServerPacketHandler {
public
void
registerHandlers
(
Class
<?
extends
PacketHandler
>
handlerClass
)
{
public
void
registerHandlers
(
Class
<?
extends
PacketHandler
>
handlerClass
)
{
Reflections
reflections
=
new
Reflections
(
"emu.grasscutter.server.packet"
);
Reflections
reflections
=
new
Reflections
(
"emu.grasscutter.server.packet"
);
Set
<?>
handlerClasses
=
reflections
.
getSubTypesOf
(
handlerClass
);
Set
<?>
handlerClasses
=
reflections
.
getSubTypesOf
(
handlerClass
);
for
(
Object
obj
:
handlerClasses
)
{
for
(
Object
obj
:
handlerClasses
)
{
this
.
registerPacketHandler
((
Class
<?
extends
PacketHandler
>)
obj
);
this
.
registerPacketHandler
((
Class
<?
extends
PacketHandler
>)
obj
);
}
}
// Debug
// Debug
Grasscutter
.
getLogger
().
info
(
"Registered "
+
this
.
handlers
.
size
()
+
" "
+
handlerClass
.
getSimpleName
()
+
"s"
);
Grasscutter
.
getLogger
().
info
(
"Registered "
+
this
.
handlers
.
size
()
+
" "
+
handlerClass
.
getSimpleName
()
+
"s"
);
}
}
public
void
handle
(
GameSession
session
,
int
opcode
,
byte
[]
header
,
byte
[]
payload
)
{
public
void
handle
(
GameSession
session
,
int
opcode
,
byte
[]
header
,
byte
[]
payload
)
{
PacketHandler
handler
=
this
.
handlers
.
get
(
opcode
);
PacketHandler
handler
=
this
.
handlers
.
get
(
opcode
);
if
(
handler
!=
null
)
{
if
(
handler
!=
null
)
{
try
{
try
{
// Make sure session is ready for packets
// Make sure session is ready for packets
SessionState
state
=
session
.
getState
();
SessionState
state
=
session
.
getState
();
if
(
opcode
==
PacketOpcodes
.
PingReq
)
{
if
(
opcode
==
PacketOpcodes
.
PingReq
)
{
// Always continue if packet is ping request
// Always continue if packet is ping request
}
else
if
(
opcode
==
PacketOpcodes
.
GetPlayerTokenReq
)
{
}
else
if
(
opcode
==
PacketOpcodes
.
GetPlayerTokenReq
)
{
...
@@ -81,18 +81,18 @@ public class GameServerPacketHandler {
...
@@ -81,18 +81,18 @@ public class GameServerPacketHandler {
return
;
return
;
}
}
}
}
// Invoke event.
// Invoke event.
ReceivePacketEvent
event
=
new
ReceivePacketEvent
(
session
,
opcode
,
payload
);
event
.
call
();
ReceivePacketEvent
event
=
new
ReceivePacketEvent
(
session
,
opcode
,
payload
);
event
.
call
();
if
(!
event
.
isCanceled
())
// If event is not canceled, continue.
if
(!
event
.
isCanceled
())
// If event is not canceled, continue.
handler
.
handle
(
session
,
header
,
event
.
getPacketData
());
handler
.
handle
(
session
,
header
,
event
.
getPacketData
());
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
// TODO Remove this when no more needed
// TODO Remove this when no more needed
ex
.
printStackTrace
();
ex
.
printStackTrace
();
}
}
return
;
// Packet successfully handled
return
;
// Packet successfully handled
}
}
// Log unhandled packets
// Log unhandled packets
if
(
SERVER
.
debugLevel
==
ServerDebugMode
.
MISSING
)
{
if
(
SERVER
.
debugLevel
==
ServerDebugMode
.
MISSING
)
{
Grasscutter
.
getLogger
().
info
(
"Unhandled packet ("
+
opcode
+
"): "
+
emu
.
grasscutter
.
net
.
packet
.
PacketOpcodesUtil
.
getOpcodeName
(
opcode
));
Grasscutter
.
getLogger
().
info
(
"Unhandled packet ("
+
opcode
+
"): "
+
emu
.
grasscutter
.
net
.
packet
.
PacketOpcodesUtil
.
getOpcodeName
(
opcode
));
...
...
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