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
10bfb697
Commit
10bfb697
authored
Apr 30, 2022
by
Melledy
Browse files
Change RunMode and DebugMode to enums
parent
eac82f3c
Changes
8
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/Config.java
View file @
10bfb697
package
emu.grasscutter
;
import
emu.grasscutter.Grasscutter.ServerDebugMode
;
import
emu.grasscutter.Grasscutter.ServerRunMode
;
import
emu.grasscutter.game.mail.Mail
;
public
final
class
Config
{
...
...
@@ -15,8 +17,8 @@ public final class Config {
public
String
SCRIPTS_FOLDER
=
"./resources/Scripts/"
;
public
String
PLUGINS_FOLDER
=
"./plugins/"
;
public
S
tring
DebugMode
=
"
NONE
"
;
// ALL, MISSING, NONE
public
S
tring
RunMode
=
"
HYBRID
"
;
// HYBRID, DISPATCH_ONLY, GAME_ONLY
public
S
erverDebugMode
DebugMode
=
ServerDebugMode
.
NONE
;
// ALL, MISSING, NONE
public
S
erverRunMode
RunMode
=
ServerRunMode
.
HYBRID
;
// HYBRID, DISPATCH_ONLY, GAME_ONLY
public
GameServerOptions
GameServer
=
new
GameServerOptions
();
public
DispatchServerOptions
DispatchServer
=
new
DispatchServerOptions
();
...
...
src/main/java/emu/grasscutter/Grasscutter.java
View file @
10bfb697
...
...
@@ -35,7 +35,6 @@ public final class Grasscutter {
private
static
int
day
;
// Current day of week
public
static
RunMode
MODE
=
RunMode
.
BOTH
;
private
static
DispatchServer
dispatchServer
;
private
static
GameServer
gameServer
;
private
static
PluginManager
pluginManager
;
...
...
@@ -58,8 +57,6 @@ public final class Grasscutter {
for
(
String
arg
:
args
)
{
switch
(
arg
.
toLowerCase
())
{
case
"-auth"
->
MODE
=
RunMode
.
AUTH
;
case
"-game"
->
MODE
=
RunMode
.
GAME
;
case
"-handbook"
->
{
Tools
.
createGmHandbook
();
return
;
}
...
...
@@ -85,12 +82,12 @@ public final class Grasscutter {
gameServer
=
new
GameServer
(
new
InetSocketAddress
(
getConfig
().
getGameServerOptions
().
Ip
,
getConfig
().
getGameServerOptions
().
Port
));
// Start servers.
if
(
getConfig
().
RunMode
.
equalsIgnoreCase
(
"
HYBRID
"
)
)
{
if
(
getConfig
().
RunMode
==
ServerRunMode
.
HYBRID
)
{
dispatchServer
.
start
();
gameServer
.
start
();
}
else
if
(
getConfig
().
RunMode
.
equalsIgnoreCase
(
"
DISPATCH_ONLY
"
)
)
{
}
else
if
(
getConfig
().
RunMode
==
ServerRunMode
.
DISPATCH_ONLY
)
{
dispatchServer
.
start
();
}
else
if
(
getConfig
().
RunMode
.
equalsIgnoreCase
(
"
GAME_ONLY
"
)
)
{
}
else
if
(
getConfig
().
RunMode
==
ServerRunMode
.
GAME_ONLY
)
{
gameServer
.
start
();
}
else
{
getLogger
().
error
(
"Invalid server run mode. "
+
getConfig
().
RunMode
);
...
...
@@ -140,7 +137,7 @@ public final class Grasscutter {
try
(
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
System
.
in
)))
{
while
((
input
=
br
.
readLine
())
!=
null
)
{
try
{
if
(
getConfig
().
RunMode
.
equalsIgnoreCase
(
"
DISPATCH_ONLY
"
)
)
{
if
(
getConfig
().
RunMode
==
ServerRunMode
.
DISPATCH_ONLY
)
{
getLogger
().
error
(
"Commands are not supported in dispatch only mode."
);
return
;
}
...
...
@@ -154,12 +151,6 @@ public final class Grasscutter {
Grasscutter
.
getLogger
().
error
(
"An error occurred."
,
e
);
}
}
public
enum
RunMode
{
BOTH
,
AUTH
,
GAME
}
public
static
Config
getConfig
()
{
return
config
;
...
...
@@ -193,4 +184,12 @@ public final class Grasscutter {
public
static
int
getCurrentDayOfWeek
()
{
return
day
;
}
public
enum
ServerRunMode
{
HYBRID
,
DISPATCH_ONLY
,
GAME_ONLY
}
public
enum
ServerDebugMode
{
ALL
,
MISSING
,
NONE
}
}
src/main/java/emu/grasscutter/database/DatabaseManager.java
View file @
10bfb697
...
...
@@ -12,6 +12,7 @@ import dev.morphia.Morphia;
import
dev.morphia.mapping.MapperOptions
;
import
dev.morphia.query.experimental.filters.Filters
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter.ServerRunMode
;
import
emu.grasscutter.game.Account
;
import
emu.grasscutter.game.avatar.Avatar
;
import
emu.grasscutter.game.friends.Friendship
;
...
...
@@ -41,7 +42,7 @@ public final class DatabaseManager {
// Yes. I very dislike this method. However, this will be good for now.
// TODO: Add dispatch routes for player account management
public
static
Datastore
getAccountDatastore
()
{
if
(
Grasscutter
.
getConfig
().
RunMode
.
equalsIgnoreCase
(
"
GAME_ONLY
"
)
)
{
if
(
Grasscutter
.
getConfig
().
RunMode
==
ServerRunMode
.
GAME_ONLY
)
{
return
dispatchDatastore
;
}
else
{
return
datastore
;
...
...
@@ -77,7 +78,7 @@ public final class DatabaseManager {
}
}
if
(
Grasscutter
.
getConfig
().
RunMode
.
equalsIgnoreCase
(
"
GAME_ONLY
"
)
)
{
if
(
Grasscutter
.
getConfig
().
RunMode
==
ServerRunMode
.
GAME_ONLY
)
{
dispatchMongoClient
=
MongoClients
.
create
(
Grasscutter
.
getConfig
().
getGameServerOptions
().
DispatchServerDatabaseUrl
);
dispatchDatastore
=
Morphia
.
createDatastore
(
dispatchMongoClient
,
Grasscutter
.
getConfig
().
getGameServerOptions
().
DispatchServerDatabaseCollection
);
...
...
src/main/java/emu/grasscutter/server/dispatch/DispatchHttpJsonHandler.java
View file @
10bfb697
...
...
@@ -8,6 +8,7 @@ import java.util.Collections;
import
com.sun.net.httpserver.HttpExchange
;
import
com.sun.net.httpserver.HttpHandler
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter.ServerDebugMode
;
import
express.http.HttpContextHandler
;
import
express.http.Request
;
import
express.http.Response
;
...
...
@@ -34,8 +35,8 @@ public final class DispatchHttpJsonHandler implements HttpContextHandler {
@Override
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)"
:
""
));
if
(
Grasscutter
.
getConfig
().
DebugMode
==
ServerDebugMode
.
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
==
ServerDebugMode
.
MISSING
?
"(MISSING)"
:
""
));
}
res
.
send
(
response
);
}
...
...
src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java
View file @
10bfb697
...
...
@@ -6,6 +6,8 @@ import com.google.protobuf.ByteString;
import
emu.grasscutter.Config
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter.ServerDebugMode
;
import
emu.grasscutter.Grasscutter.ServerRunMode
;
import
emu.grasscutter.database.DatabaseHelper
;
import
emu.grasscutter.game.Account
;
import
emu.grasscutter.net.proto.QueryCurrRegionHttpRspOuterClass.QueryCurrRegionHttpRsp
;
...
...
@@ -62,7 +64,7 @@ public final class DispatchServer {
public
QueryCurrRegionHttpRsp
getCurrRegion
()
{
// Needs to be fixed by having the game servers connect to the dispatch server.
if
(
Grasscutter
.
getConfig
().
RunMode
.
equalsIgnoreCase
(
"
HYBRID
"
)
)
{
if
(
Grasscutter
.
getConfig
().
RunMode
==
ServerRunMode
.
HYBRID
)
{
return
regions
.
get
(
defaultServerName
).
parsedRegionQuery
;
}
...
...
@@ -98,7 +100,7 @@ public final class DispatchServer {
List
<
RegionSimpleInfo
>
servers
=
new
ArrayList
<>();
List
<
String
>
usedNames
=
new
ArrayList
<>();
// List to check for potential naming conflicts
if
(
Grasscutter
.
getConfig
().
RunMode
.
equalsIgnoreCase
(
"
HYBRID
"
)
)
{
// Automatically add the game server if in
if
(
Grasscutter
.
getConfig
().
RunMode
==
ServerRunMode
.
HYBRID
)
{
// Automatically add the game server if in
// hybrid mode
RegionSimpleInfo
server
=
RegionSimpleInfo
.
newBuilder
()
.
setName
(
"os_usa"
)
...
...
@@ -233,7 +235,7 @@ public final class DispatchServer {
});
config
.
enforceSsl
=
Grasscutter
.
getConfig
().
getDispatchOptions
().
UseSSL
;
if
(
Grasscutter
.
getConfig
().
DebugMode
.
equalsIgnoreCase
(
"
ALL
"
)
)
{
if
(
Grasscutter
.
getConfig
().
DebugMode
==
ServerDebugMode
.
ALL
)
{
config
.
enableDevLogging
();
}
});
...
...
@@ -241,7 +243,7 @@ public final class DispatchServer {
httpServer
.
get
(
"/"
,
(
req
,
res
)
->
res
.
send
(
"Welcome to Grasscutter"
));
httpServer
.
raw
().
error
(
404
,
ctx
->
{
if
(
Grasscutter
.
getConfig
().
DebugMode
.
equalsIgnoreCase
(
"
MISSING
"
)
)
{
if
(
Grasscutter
.
getConfig
().
DebugMode
==
ServerDebugMode
.
MISSING
)
{
Grasscutter
.
getLogger
().
info
(
String
.
format
(
"[Dispatch] Potential unhandled %s request: %s"
,
ctx
.
method
(),
ctx
.
url
()));
}
ctx
.
contentType
(
"text/html"
);
...
...
src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java
View file @
10bfb697
...
...
@@ -6,6 +6,7 @@ import emu.grasscutter.server.event.game.ReceivePacketEvent;
import
org.reflections.Reflections
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter.ServerDebugMode
;
import
emu.grasscutter.net.packet.Opcodes
;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
...
...
@@ -88,7 +89,7 @@ public class GameServerPacketHandler {
}
// Log unhandled packets
if
(
Grasscutter
.
getConfig
().
DebugMode
.
equalsIgnoreCase
(
"
MISSING
"
)
)
{
if
(
Grasscutter
.
getConfig
().
DebugMode
==
ServerDebugMode
.
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 @
10bfb697
...
...
@@ -7,6 +7,7 @@ import java.util.HashSet;
import
java.util.Set
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter.ServerDebugMode
;
import
emu.grasscutter.game.Account
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.net.packet.BasePacket
;
...
...
@@ -163,7 +164,7 @@ public class GameSession extends KcpChannel {
}
// Log
if
(
Grasscutter
.
getConfig
().
DebugMode
.
equalsIgnoreCase
(
"
ALL
"
)
)
{
if
(
Grasscutter
.
getConfig
().
DebugMode
==
ServerDebugMode
.
ALL
)
{
logPacket
(
packet
);
}
...
...
@@ -230,7 +231,7 @@ public class GameSession extends KcpChannel {
}
// Log packet
if
(
Grasscutter
.
getConfig
().
DebugMode
.
equalsIgnoreCase
(
"
ALL
"
)
)
{
if
(
Grasscutter
.
getConfig
().
DebugMode
==
ServerDebugMode
.
ALL
)
{
if
(!
loopPacket
.
contains
(
opcode
))
{
Grasscutter
.
getLogger
().
info
(
"RECV: "
+
PacketOpcodesUtil
.
getOpcodeName
(
opcode
)
+
" ("
+
opcode
+
")"
);
System
.
out
.
println
(
Utils
.
bytesToHex
(
payload
));
...
...
src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLoginRsp.java
View file @
10bfb697
...
...
@@ -2,6 +2,8 @@ package emu.grasscutter.server.packet.send;
import
com.google.protobuf.ByteString
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter.ServerDebugMode
;
import
emu.grasscutter.Grasscutter.ServerRunMode
;
import
emu.grasscutter.net.packet.BasePacket
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.PlayerLoginRspOuterClass.PlayerLoginRsp
;
...
...
@@ -25,7 +27,7 @@ public class PacketPlayerLoginRsp extends BasePacket {
RegionInfo
info
;
if
(
Grasscutter
.
getConfig
().
RunMode
.
equalsIgnoreCase
(
"
GAME_ONLY
"
)
)
{
if
(
Grasscutter
.
getConfig
().
RunMode
==
ServerRunMode
.
GAME_ONLY
)
{
if
(
regionCache
==
null
)
{
try
{
File
file
=
new
File
(
Grasscutter
.
getConfig
().
DATA_FOLDER
+
"query_cur_region.txt"
);
...
...
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