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
12755927
Commit
12755927
authored
Apr 21, 2022
by
Benjamin Elsdon
Browse files
Fixed null pointer exception in hybrid mode.
parent
1500d2e8
Changes
2
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java
View file @
12755927
...
...
@@ -5,6 +5,7 @@ import java.io.FileInputStream;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.net.InetAddress
;
import
java.net.InetSocketAddress
;
import
java.net.URI
;
import
java.net.URLDecoder
;
...
...
@@ -44,18 +45,18 @@ import com.sun.net.httpserver.HttpServer;
public
final
class
DispatchServer
{
private
final
InetSocketAddress
address
;
private
final
Gson
gson
;
private
final
String
defaultServerName
=
"os_usa"
;
//private QueryCurrRegionHttpRsp currRegion;
public
String
regionListBase64
;
public
HashMap
<
String
,
RegionData
>
regions
;
public
HashMap
<
InetSocketAddress
,
String
>
usersIngame
;
public
HashMap
<
String
,
UserConnnectionData
>
usersConnected
;
public
static
String
query_region_list
=
""
;
public
static
String
query_cur_region
=
""
;
public
DispatchServer
()
{
this
.
regions
=
new
HashMap
<
String
,
RegionData
>();
this
.
usersIngame
=
new
HashMap
<
InetSocketAddress
,
String
>();
this
.
address
=
new
InetSocketAddress
(
Grasscutter
.
getConfig
().
getDispatchOptions
().
Ip
,
Grasscutter
.
getConfig
().
getDispatchOptions
().
Port
);
this
.
gson
=
new
GsonBuilder
().
create
();
...
...
@@ -71,12 +72,13 @@ public final class DispatchServer {
return
gson
;
}
public
QueryCurrRegionHttpRsp
getCurrRegion
(
InetSocketAddress
address
)
{
if
(
usersIngame
.
containsKey
(
address
))
{
return
regions
.
get
(
usersIngame
.
get
(
address
)).
parsedRegionQuery
;
public
QueryCurrRegionHttpRsp
getCurrRegion
()
{
// Needs to be fixed by having the game servers connect to the dispatch server.
if
(
Grasscutter
.
getConfig
().
RunMode
.
equalsIgnoreCase
(
"HYBRID"
))
{
return
regions
.
get
(
defaultServerName
).
parsedRegionQuery
;
}
Grasscutter
.
getLogger
().
error
(
"
User is not logged in to dispatch server. "
+
address
.
getAddress
()
+
":"
+
address
.
getPort
()
);
Grasscutter
.
getLogger
().
error
(
"
Ignore the error below"
);
return
null
;
}
...
...
@@ -109,7 +111,6 @@ public final class DispatchServer {
List
<
RegionSimpleInfo
>
servers
=
new
ArrayList
<
RegionSimpleInfo
>();
List
<
String
>
usedNames
=
new
ArrayList
<
String
>();
// List to check for potential naming conflicts
if
(
Grasscutter
.
getConfig
().
RunMode
.
equalsIgnoreCase
(
"HYBRID"
))
{
// Automatically add the game server if in hybrid mode
String
defaultServerName
=
"os_usa"
;
RegionSimpleInfo
server
=
RegionSimpleInfo
.
newBuilder
()
.
setName
(
"os_usa"
)
.
setTitle
(
Grasscutter
.
getConfig
().
getGameServerOptions
().
Name
)
...
...
@@ -222,16 +223,11 @@ public final class DispatchServer {
OutputStream
os
=
t
.
getResponseBody
();
os
.
write
(
response
.
getBytes
());
os
.
close
();
if
(
usersIngame
.
containsKey
(
t
.
getRemoteAddress
()))
{
usersIngame
.
remove
(
t
.
getRemoteAddress
());
}
});
for
(
String
regionName
:
regions
.
keySet
())
{
server
.
createContext
(
"/query_cur_region_"
+
regionName
,
t
->
{
String
regionCurrentBase64
=
regions
.
get
(
regionName
).
Base64
;
// Log
Grasscutter
.
getLogger
().
info
(
"Client request: query_cur_region_"
+
regionName
);
// Create a response form the request query parameters
...
...
@@ -247,8 +243,6 @@ public final class DispatchServer {
OutputStream
os
=
t
.
getResponseBody
();
os
.
write
(
response
.
getBytes
());
os
.
close
();
//Save region info to hashmap for user, this for getCurrRegion();
usersIngame
.
put
(
t
.
getRemoteAddress
(),
regionName
);
});
}
...
...
@@ -521,4 +515,9 @@ public final class DispatchServer {
this
.
Base64
=
b64
;
}
}
public
static
class
UserConnnectionData
{
public
InetAddress
dispatchConnectedAddress
;
public
String
connectedRegion
;
}
}
src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLoginRsp.java
View file @
12755927
...
...
@@ -14,7 +14,7 @@ public class PacketPlayerLoginRsp extends GenshinPacket {
this
.
setUseDispatchKey
(
true
);
RegionInfo
info
=
Grasscutter
.
getDispatchServer
().
getCurrRegion
(
session
.
getAddress
()
).
getRegionInfo
();
RegionInfo
info
=
Grasscutter
.
getDispatchServer
().
getCurrRegion
().
getRegionInfo
();
PlayerLoginRsp
p
=
PlayerLoginRsp
.
newBuilder
()
.
setIsUseAbilityHash
(
true
)
// true
...
...
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