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
947d3e57
Commit
947d3e57
authored
May 01, 2022
by
Benjamin Elsdon
Browse files
Complete rework of Dispatch, Added DebugMode
parent
4db1724d
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
947d3e57
...
...
@@ -54,12 +54,14 @@ tmp/
# Grasscutter
resources/*
logs/*
plugins/*
data/AbilityEmbryos.json
data/OpenConfig.json
GM Handbook.txt
config.json
mitmdump.exe
*.jar
!lib/*.jar
mongod.exe
/src/generated/
/*.sh
\ No newline at end of file
/*.sh
build.gradle
View file @
947d3e57
...
...
@@ -16,18 +16,22 @@ buildscript {
}
plugins
{
// Apply the application plugin to add support for building a CLI application
id
'application'
// Apply the java plugin to add support for Java
id
'java'
// Apply the protobuf auto generator
id
'com.google.protobuf'
version
"0.8.18"
id
'idea'
// Eclipse Support
id
'eclipse'
//
Apply the application plugin to add support for building a CLI application
id
'
application
'
//
Intelij Support
id
'
idea
'
// Maven
id
'maven-publish'
id
'signing'
}
...
...
lib/java-express-1.1.3.jar
0 → 100644
View file @
947d3e57
File added
src/main/java/emu/grasscutter/Config.java
View file @
947d3e57
...
...
@@ -13,6 +13,7 @@ public final class Config {
public
String
SCRIPTS_FOLDER
=
"./resources/Scripts/"
;
public
String
PLUGINS_FOLDER
=
"./plugins/"
;
public
String
DebugMode
=
"NONE"
;
// ALL, MISSING, NONE
public
String
RunMode
=
"HYBRID"
;
// HYBRID, DISPATCH_ONLY, GAME_ONLY
public
GameServerOptions
GameServer
=
new
GameServerOptions
();
public
DispatchServerOptions
DispatchServer
=
new
DispatchServerOptions
();
...
...
@@ -60,8 +61,6 @@ public final class Config {
public
String
DispatchServerDatabaseUrl
=
"mongodb://localhost:27017"
;
public
String
DispatchServerDatabaseCollection
=
"grasscutter"
;
public
boolean
LOG_PACKETS
=
false
;
public
int
InventoryLimitWeapon
=
2000
;
public
int
InventoryLimitRelic
=
2000
;
public
int
InventoryLimitMaterial
=
2000
;
...
...
src/main/java/emu/grasscutter/server/dispatch/DispatchHttpJsonHandler.java
View file @
947d3e57
...
...
@@ -2,26 +2,41 @@ package emu.grasscutter.server.dispatch;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
com.sun.net.httpserver.HttpExchange
;
import
com.sun.net.httpserver.HttpHandler
;
import
emu.grasscutter.Grasscutter
;
import
express.http.HttpContextHandler
;
import
express.http.Request
;
import
express.http.Response
;
public
final
class
DispatchHttpJsonHandler
implements
HttpHandler
{
public
final
class
DispatchHttpJsonHandler
implements
Http
Context
Handler
{
private
final
String
response
;
private
final
String
[]
missingRoutes
=
{
// TODO: When http requests for theses routes are found please remove it from this list and update the route request type in the DispatchServer
"/common/hk4e_global/announcement/api/getAlertPic"
,
"/common/hk4e_global/announcement/api/getAlertAnn"
,
"/common/hk4e_global/announcement/api/getAnnList"
,
"/common/hk4e_global/announcement/api/getAnnContent"
,
"/hk4e_global/mdk/shopwindow/shopwindow/listPriceTier"
,
"/log/sdk/upload"
,
"/sdk/upload"
,
"/perf/config/verify"
,
"/log"
,
"/crash/dataUpload"
};
public
DispatchHttpJsonHandler
(
String
response
)
{
this
.
response
=
response
;
}
@Override
public
void
handle
(
HttpExchange
t
)
throws
IOException
{
// Set the response header status and length
t
.
getResponseHeaders
().
put
(
"Content-Type"
,
Collections
.
singletonList
(
"application/json"
));
t
.
sendResponseHeaders
(
200
,
response
.
getBytes
().
length
);
// Write the response string
OutputStream
os
=
t
.
getResponseBody
();
os
.
write
(
response
.
getBytes
());
os
.
close
();
public
void
handle
(
Request
req
,
Response
res
)
throws
IOException
{
// Checking for ALL here isn't required as when ALL is enabled enableDevLogging() gets enabled
if
(
Grasscutter
.
getConfig
().
DebugMode
.
equalsIgnoreCase
(
"MISSING"
)
&&
Arrays
.
stream
(
missingRoutes
).
anyMatch
(
x
->
x
==
req
.
baseUrl
()))
{
Grasscutter
.
getLogger
().
info
(
String
.
format
(
"[Dispatch] Client %s %s request: "
,
req
.
ip
(),
req
.
method
(),
req
.
baseUrl
())
+
(
Grasscutter
.
getConfig
().
DebugMode
.
equalsIgnoreCase
(
"MISSING"
)
?
"(MISSING)"
:
""
));
res
.
send
(
response
.
getBytes
());
}
}
}
src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java
View file @
947d3e57
This diff is collapsed.
Click to expand it.
src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java
View file @
947d3e57
...
...
@@ -88,7 +88,7 @@ public class GameServerPacketHandler {
}
// Log unhandled packets
if
(
Grasscutter
.
getConfig
().
getGameServerOptions
().
LOG_PACKETS
)
{
if
(
Grasscutter
.
getConfig
().
DebugMode
.
equalsIgnoreCase
(
"MISSING"
)
)
{
Grasscutter
.
getLogger
().
info
(
"Unhandled packet ("
+
opcode
+
"): "
+
emu
.
grasscutter
.
net
.
packet
.
PacketOpcodesUtil
.
getOpcodeName
(
opcode
));
}
}
...
...
src/main/java/emu/grasscutter/server/game/GameSession.java
View file @
947d3e57
...
...
@@ -163,7 +163,7 @@ public class GameSession extends KcpChannel {
}
// Log
if
(
Grasscutter
.
getConfig
().
getGameServerOptions
().
LOG_PACKETS
)
{
if
(
Grasscutter
.
getConfig
().
DebugMode
.
equalsIgnoreCase
(
"ALL"
)
)
{
logPacket
(
packet
);
}
...
...
@@ -230,7 +230,7 @@ public class GameSession extends KcpChannel {
}
// Log packet
if
(
Grasscutter
.
getConfig
().
getGameServerOptions
().
LOG_PACKETS
)
{
if
(
Grasscutter
.
getConfig
().
DebugMode
.
equalsIgnoreCase
(
"ALL"
)
)
{
if
(!
loopPacket
.
contains
(
opcode
))
{
Grasscutter
.
getLogger
().
info
(
"RECV: "
+
PacketOpcodesUtil
.
getOpcodeName
(
opcode
)
+
" ("
+
opcode
+
")"
);
System
.
out
.
println
(
Utils
.
bytesToHex
(
payload
));
...
...
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