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
52ee229e
Commit
52ee229e
authored
Jul 20, 2022
by
Melledy
Browse files
Split config `debugLevel` into `logPackets` (Game) and `logRequests` (Dispatch)
parent
408fa907
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/config/ConfigContainer.java
View file @
52ee229e
...
@@ -93,9 +93,8 @@ public class ConfigContainer {
...
@@ -93,9 +93,8 @@ public class ConfigContainer {
}
}
public
static
class
Server
{
public
static
class
Server
{
public
ServerDebugMode
debugLevel
=
ServerDebugMode
.
NONE
;
public
Set
<
Integer
>
debugWhitelist
=
Set
.
of
();
public
Set
<
Integer
>
DebugWhitelist
=
Set
.
of
();
public
Set
<
Integer
>
debugBlacklist
=
Set
.
of
();
public
Set
<
Integer
>
DebugBlacklist
=
Set
.
of
();
public
ServerRunMode
runMode
=
ServerRunMode
.
HYBRID
;
public
ServerRunMode
runMode
=
ServerRunMode
.
HYBRID
;
public
HTTP
http
=
new
HTTP
();
public
HTTP
http
=
new
HTTP
();
...
@@ -135,16 +134,21 @@ public class ConfigContainer {
...
@@ -135,16 +134,21 @@ public class ConfigContainer {
public
static
class
Game
{
public
static
class
Game
{
public
String
bindAddress
=
"0.0.0.0"
;
public
String
bindAddress
=
"0.0.0.0"
;
public
int
bindPort
=
22102
;
/* This is the address used in the default region. */
/* This is the address used in the default region. */
public
String
accessAddress
=
"127.0.0.1"
;
public
String
accessAddress
=
"127.0.0.1"
;
public
int
bindPort
=
22102
;
/* This is the port used in the default region. */
/* This is the port used in the default region. */
public
int
accessPort
=
0
;
public
int
accessPort
=
0
;
/* Entities within a certain range will be loaded for the player */
/* Entities within a certain range will be loaded for the player */
public
int
loadEntitiesForPlayerRange
=
100
;
public
int
loadEntitiesForPlayerRange
=
100
;
public
boolean
enableScriptInBigWorld
=
false
;
public
boolean
enableScriptInBigWorld
=
false
;
public
boolean
enableConsole
=
true
;
public
boolean
enableConsole
=
true
;
/* Controls whether packets should be logged in console or not */
public
ServerDebugMode
logPackets
=
ServerDebugMode
.
NONE
;
public
GameOptions
gameOptions
=
new
GameOptions
();
public
GameOptions
gameOptions
=
new
GameOptions
();
public
JoinOptions
joinOptions
=
new
JoinOptions
();
public
JoinOptions
joinOptions
=
new
JoinOptions
();
public
ConsoleAccount
serverAccount
=
new
ConsoleAccount
();
public
ConsoleAccount
serverAccount
=
new
ConsoleAccount
();
...
@@ -156,6 +160,8 @@ public class ConfigContainer {
...
@@ -156,6 +160,8 @@ public class ConfigContainer {
public
Region
[]
regions
=
{};
public
Region
[]
regions
=
{};
public
String
defaultName
=
"Grasscutter"
;
public
String
defaultName
=
"Grasscutter"
;
public
ServerDebugMode
logRequests
=
ServerDebugMode
.
NONE
;
}
}
public
static
class
Encryption
{
public
static
class
Encryption
{
...
...
src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java
View file @
52ee229e
...
@@ -94,7 +94,7 @@ public class GameServerPacketHandler {
...
@@ -94,7 +94,7 @@ public class GameServerPacketHandler {
}
}
// Log unhandled packets
// Log unhandled packets
if
(
SERVER
.
debugLevel
==
ServerDebugMode
.
MISSING
)
{
if
(
GAME_INFO
.
logPackets
==
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
));
}
}
}
}
...
...
src/main/java/emu/grasscutter/server/game/GameSession.java
View file @
52ee229e
...
@@ -148,18 +148,23 @@ public class GameSession implements GameSessionManager.KcpChannel {
...
@@ -148,18 +148,23 @@ public class GameSession implements GameSessionManager.KcpChannel {
}
}
// Log
// Log
if
(
SERVER
.
debugLevel
==
ServerDebugMode
.
ALL
)
{
switch
(
GAME_INFO
.
logPackets
)
{
if
(!
loopPacket
.
contains
(
packet
.
getOpcode
()))
{
case
ALL
->
{
logPacket
(
"SEND"
,
packet
.
getOpcode
(),
packet
.
getData
());
if
(!
loopPacket
.
contains
(
packet
.
getOpcode
()))
{
}
logPacket
(
"SEND"
,
packet
.
getOpcode
(),
packet
.
getData
());
}
}
}
if
(
SERVER
.
debugLevel
==
ServerDebugMode
.
WHITELIST
&&
SERVER
.
DebugWhitelist
.
contains
(
packet
.
getOpcode
()))
{
case
WHITELIST
->
{
logPacket
(
"SEND"
,
packet
.
getOpcode
(),
packet
.
getData
());
if
(
SERVER
.
debugWhitelist
.
contains
(
packet
.
getOpcode
()))
{
}
logPacket
(
"SEND"
,
packet
.
getOpcode
(),
packet
.
getData
());
}
if
(
SERVER
.
debugLevel
==
ServerDebugMode
.
BLACKLIST
&&
!(
SERVER
.
DebugBlacklist
.
contains
(
packet
.
getOpcode
())))
{
}
logPacket
(
"SEND"
,
packet
.
getOpcode
(),
packet
.
getData
());
case
BLACKLIST
->
{
if
(!
SERVER
.
debugBlacklist
.
contains
(
packet
.
getOpcode
()))
{
logPacket
(
"SEND"
,
packet
.
getOpcode
(),
packet
.
getData
());
}
}
default
->
{}
}
}
// Invoke event.
// Invoke event.
...
@@ -194,7 +199,7 @@ public class GameSession implements GameSessionManager.KcpChannel {
...
@@ -194,7 +199,7 @@ public class GameSession implements GameSessionManager.KcpChannel {
//logPacket(packet);
//logPacket(packet);
// Handle
// Handle
try
{
try
{
boolean
allDebug
=
SERVER
.
debugLevel
==
ServerDebugMode
.
ALL
;
boolean
allDebug
=
GAME_INFO
.
logPackets
==
ServerDebugMode
.
ALL
;
while
(
packet
.
readableBytes
()
>
0
)
{
while
(
packet
.
readableBytes
()
>
0
)
{
// Length
// Length
if
(
packet
.
readableBytes
()
<
12
)
{
if
(
packet
.
readableBytes
()
<
12
)
{
...
@@ -225,20 +230,26 @@ public class GameSession implements GameSessionManager.KcpChannel {
...
@@ -225,20 +230,26 @@ public class GameSession implements GameSessionManager.KcpChannel {
}
}
return
;
// Bad packet
return
;
// Bad packet
}
}
// Log packet
// Log packet
if
(
allDebug
)
{
switch
(
GAME_INFO
.
logPackets
)
{
if
(!
loopPacket
.
contains
(
opcode
))
{
case
ALL
->
{
logPacket
(
"RECV"
,
opcode
,
payload
);
if
(!
loopPacket
.
contains
(
opcode
))
{
}
logPacket
(
"RECV"
,
opcode
,
payload
);
}
}
}
if
(
SERVER
.
debugLevel
==
ServerDebugMode
.
WHITELIST
&&
SERVER
.
DebugWhitelist
.
contains
(
opcode
))
{
case
WHITELIST
->
{
logPacket
(
"RECV"
,
opcode
,
payload
);
if
(
SERVER
.
debugWhitelist
.
contains
(
opcode
))
{
}
logPacket
(
"RECV"
,
opcode
,
payload
);
}
if
(
SERVER
.
debugLevel
==
ServerDebugMode
.
BLACKLIST
&&
!(
SERVER
.
DebugBlacklist
.
contains
(
opcode
)))
{
}
logPacket
(
"RECV"
,
opcode
,
payload
);
case
BLACKLIST
->
{
}
if
(!(
SERVER
.
debugBlacklist
.
contains
(
opcode
)))
{
logPacket
(
"RECV"
,
opcode
,
payload
);
}
}
default
->
{}
}
// Handle
// Handle
getServer
().
getPacketHandler
().
handle
(
this
,
opcode
,
header
,
payload
);
getServer
().
getPacketHandler
().
handle
(
this
,
opcode
,
header
,
payload
);
...
...
src/main/java/emu/grasscutter/server/http/HttpServer.java
View file @
52ee229e
...
@@ -43,7 +43,7 @@ public final class HttpServer {
...
@@ -43,7 +43,7 @@ public final class HttpServer {
}
}
// Configure debug logging.
// Configure debug logging.
if
(
SERVER
.
debugLevel
==
ServerDebugMode
.
ALL
)
if
(
DISPATCH_INFO
.
logRequests
==
ServerDebugMode
.
ALL
)
config
.
enableDevLogging
();
config
.
enableDevLogging
();
// Disable compression on static files.
// Disable compression on static files.
...
@@ -173,7 +173,7 @@ public final class HttpServer {
...
@@ -173,7 +173,7 @@ public final class HttpServer {
public
static
class
UnhandledRequestRouter
implements
Router
{
public
static
class
UnhandledRequestRouter
implements
Router
{
@Override
public
void
applyRoutes
(
Express
express
,
Javalin
handle
)
{
@Override
public
void
applyRoutes
(
Express
express
,
Javalin
handle
)
{
handle
.
error
(
404
,
context
->
{
handle
.
error
(
404
,
context
->
{
if
(
SERVER
.
debugLevel
==
ServerDebugMode
.
MISSING
)
if
(
DISPATCH_INFO
.
logRequests
==
ServerDebugMode
.
MISSING
)
Grasscutter
.
getLogger
().
info
(
translate
(
"messages.dispatch.unhandled_request_error"
,
context
.
method
(),
context
.
url
()));
Grasscutter
.
getLogger
().
info
(
translate
(
"messages.dispatch.unhandled_request_error"
,
context
.
method
(),
context
.
url
()));
context
.
contentType
(
"text/html"
);
context
.
contentType
(
"text/html"
);
...
...
src/main/java/emu/grasscutter/server/http/objects/HttpJsonResponse.java
View file @
52ee229e
...
@@ -35,8 +35,8 @@ public final class HttpJsonResponse implements HttpContextHandler {
...
@@ -35,8 +35,8 @@ public final class HttpJsonResponse implements HttpContextHandler {
@Override
@Override
public
void
handle
(
Request
req
,
Response
res
)
throws
IOException
{
public
void
handle
(
Request
req
,
Response
res
)
throws
IOException
{
// Checking for ALL here isn't required as when ALL is enabled enableDevLogging() gets enabled
// Checking for ALL here isn't required as when ALL is enabled enableDevLogging() gets enabled
if
(
SERVER
.
debugLevel
==
ServerDebugMode
.
MISSING
&&
Arrays
.
stream
(
missingRoutes
).
anyMatch
(
x
->
Objects
.
equals
(
x
,
req
.
baseUrl
())))
{
if
(
DISPATCH_INFO
.
logRequests
==
ServerDebugMode
.
MISSING
&&
Arrays
.
stream
(
missingRoutes
).
anyMatch
(
x
->
Objects
.
equals
(
x
,
req
.
baseUrl
())))
{
Grasscutter
.
getLogger
().
info
(
translate
(
"messages.dispatch.request"
,
req
.
ip
(),
req
.
method
(),
req
.
baseUrl
())
+
(
SERVER
.
debugLevel
==
ServerDebugMode
.
MISSING
?
"(MISSING)"
:
""
));
Grasscutter
.
getLogger
().
info
(
translate
(
"messages.dispatch.request"
,
req
.
ip
(),
req
.
method
(),
req
.
baseUrl
())
+
(
DISPATCH_INFO
.
logRequests
==
ServerDebugMode
.
MISSING
?
"(MISSING)"
:
""
));
}
}
res
.
send
(
response
);
res
.
send
(
response
);
}
}
...
...
src/main/java/emu/grasscutter/server/http/objects/WebStaticVersionResponse.java
View file @
52ee229e
...
@@ -11,6 +11,7 @@ import express.http.Response;
...
@@ -11,6 +11,7 @@ import express.http.Response;
import
io.javalin.core.util.FileUtil
;
import
io.javalin.core.util.FileUtil
;
import
static
emu
.
grasscutter
.
config
.
Configuration
.
DATA
;
import
static
emu
.
grasscutter
.
config
.
Configuration
.
DATA
;
import
static
emu
.
grasscutter
.
config
.
Configuration
.
DISPATCH_INFO
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
...
@@ -32,7 +33,7 @@ public class WebStaticVersionResponse implements HttpContextHandler {
...
@@ -32,7 +33,7 @@ public class WebStaticVersionResponse implements HttpContextHandler {
response
.
type
((
fromExtension
!=
null
)
?
fromExtension
.
getMIME
()
:
"application/octet-stream"
);
response
.
type
((
fromExtension
!=
null
)
?
fromExtension
.
getMIME
()
:
"application/octet-stream"
);
response
.
send
(
filestream
.
readAllBytes
());
response
.
send
(
filestream
.
readAllBytes
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
if
(
Grasscutter
.
getConfig
().
server
.
debugLevel
.
equals
(
Grasscutter
.
ServerDebugMode
.
MISSING
)
)
{
if
(
DISPATCH_INFO
.
logRequests
==
Grasscutter
.
ServerDebugMode
.
MISSING
)
{
Grasscutter
.
getLogger
().
warn
(
"Webstatic File Missing: "
+
path
);
Grasscutter
.
getLogger
().
warn
(
"Webstatic File Missing: "
+
path
);
}
}
response
.
status
(
404
);
response
.
status
(
404
);
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerUnionCmdNotify.java
View file @
52ee229e
package
emu.grasscutter.server.packet.recv
;
package
emu.grasscutter.server.packet.recv
;
import
static
emu
.
grasscutter
.
config
.
Configuration
.
GAME_INFO
;
import
static
emu
.
grasscutter
.
config
.
Configuration
.
SERVER
;
import
static
emu
.
grasscutter
.
config
.
Configuration
.
SERVER
;
import
emu.grasscutter.Grasscutter
;
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.UnionCmdNotifyOuterClass.UnionCmdNotify
;
import
emu.grasscutter.net.proto.UnionCmdNotifyOuterClass.UnionCmdNotify
;
...
@@ -19,9 +19,9 @@ public class HandlerUnionCmdNotify extends PacketHandler {
...
@@ -19,9 +19,9 @@ public class HandlerUnionCmdNotify extends PacketHandler {
for
(
UnionCmd
cmd
:
req
.
getCmdListList
())
{
for
(
UnionCmd
cmd
:
req
.
getCmdListList
())
{
int
cmdOpcode
=
cmd
.
getMessageId
();
int
cmdOpcode
=
cmd
.
getMessageId
();
byte
[]
cmdPayload
=
cmd
.
getBody
().
toByteArray
();
byte
[]
cmdPayload
=
cmd
.
getBody
().
toByteArray
();
if
(
G
rasscutter
.
config
.
server
.
debugLevel
==
ServerDebugMode
.
WHITELIST
&&
SERVER
.
D
ebugWhitelist
.
contains
(
cmd
.
getMessageId
()))
{
if
(
G
AME_INFO
.
logPackets
==
ServerDebugMode
.
WHITELIST
&&
SERVER
.
d
ebugWhitelist
.
contains
(
cmd
.
getMessageId
()))
{
session
.
logPacket
(
"RECV in Union"
,
cmdOpcode
,
cmdPayload
);
session
.
logPacket
(
"RECV in Union"
,
cmdOpcode
,
cmdPayload
);
}
else
if
(
G
rasscutter
.
config
.
server
.
debugLevel
==
ServerDebugMode
.
BLACKLIST
&&
!
SERVER
.
D
ebugBlacklist
.
contains
(
cmd
.
getMessageId
()))
{
}
else
if
(
G
AME_INFO
.
logPackets
==
ServerDebugMode
.
BLACKLIST
&&
!
SERVER
.
d
ebugBlacklist
.
contains
(
cmd
.
getMessageId
()))
{
session
.
logPacket
(
"RECV in Union"
,
cmdOpcode
,
cmdPayload
);
session
.
logPacket
(
"RECV in Union"
,
cmdOpcode
,
cmdPayload
);
}
}
//debugLevel ALL ignores UnionCmdNotify, so we will also ignore the contained opcodes
//debugLevel ALL ignores UnionCmdNotify, so we will also ignore the contained opcodes
...
...
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