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
0e7976f9
Commit
0e7976f9
authored
Apr 21, 2022
by
Melledy
Committed by
GitHub
Apr 21, 2022
Browse files
Merge pull request #78 from MlgmXyysd/dispatch-refactor
Refact dispatch server
parents
dccee2df
54856147
Changes
7
Show whitespace changes
Inline
Side-by-side
proxy.py
View file @
0e7976f9
...
@@ -16,12 +16,14 @@
...
@@ -16,12 +16,14 @@
# - mitmdump from mitmproxy
# - mitmdump from mitmproxy
#
#
# @author MlgmXyysd
# @author MlgmXyysd
# @version 1.
0
# @version 1.
1
#
#
##
##
from
mitmproxy
import
http
from
mitmproxy
import
http
from
proxy_config
import
USE_SSL
from
proxy_config
import
REMOTE_HOST
from
proxy_config
import
REMOTE_HOST
from
proxy_config
import
REMOTE_PORT
class
MlgmXyysd_Genshin_Impact_Proxy
:
class
MlgmXyysd_Genshin_Impact_Proxy
:
...
@@ -60,7 +62,12 @@ class MlgmXyysd_Genshin_Impact_Proxy:
...
@@ -60,7 +62,12 @@ class MlgmXyysd_Genshin_Impact_Proxy:
def
request
(
self
,
flow
:
http
.
HTTPFlow
)
->
None
:
def
request
(
self
,
flow
:
http
.
HTTPFlow
)
->
None
:
if
flow
.
request
.
host
in
self
.
LIST_DOMAINS
:
if
flow
.
request
.
host
in
self
.
LIST_DOMAINS
:
if
USE_SSL
:
flow
.
request
.
scheme
=
"https"
else
:
flow
.
request
.
scheme
=
"http"
flow
.
request
.
host
=
REMOTE_HOST
flow
.
request
.
host
=
REMOTE_HOST
flow
.
request
.
port
=
REMOTE_PORT
addons
=
[
addons
=
[
MlgmXyysd_Genshin_Impact_Proxy
()
MlgmXyysd_Genshin_Impact_Proxy
()
...
...
proxy_config.py
View file @
0e7976f9
# This can also be replaced with another IP address.
# This can also be replaced with another IP address.
REMOTE_HOST
=
"localhost"
USE_SSL
=
True
\ No newline at end of file
REMOTE_HOST
=
"127.0.0.1"
REMOTE_PORT
=
443
\ No newline at end of file
src/main/java/emu/grasscutter/Config.java
View file @
0e7976f9
package
emu.grasscutter
;
package
emu.grasscutter
;
public
final
class
Config
{
public
final
class
Config
{
public
String
DispatchServerIp
=
"
127
.0.0.
1
"
;
public
String
DispatchServerIp
=
"
0
.0.0.
0
"
;
public
String
DispatchServerPublicIp
=
""
;
public
String
DispatchServerPublicIp
=
"
127.0.0.1
"
;
public
int
DispatchServerPort
=
443
;
public
int
DispatchServerPort
=
443
;
public
String
DispatchServerKeystorePath
=
"./keystore.p12"
;
public
String
DispatchServerKeystorePath
=
"./keystore.p12"
;
public
String
DispatchServerKeystorePassword
=
""
;
public
String
DispatchServerKeystorePassword
=
""
;
public
Boolean
UseSSL
=
true
;
public
Boolean
UseSSL
=
true
;
public
String
GameServerName
=
"Test"
;
public
String
GameServerName
=
"Test"
;
public
String
GameServerIp
=
"
127
.0.0.
1
"
;
public
String
GameServerIp
=
"
0
.0.0.
0
"
;
public
String
GameServerPublicIp
=
""
;
public
String
GameServerPublicIp
=
"
127.0.0.1
"
;
public
int
GameServerPort
=
22102
;
public
int
GameServerPort
=
22102
;
public
int
OverseaLogPort
=
8888
;
public
int
UploadLogPort
=
80
;
public
String
DatabaseUrl
=
"mongodb://localhost:27017"
;
public
String
DatabaseUrl
=
"mongodb://localhost:27017"
;
public
String
DatabaseCollection
=
"grasscutter"
;
public
String
DatabaseCollection
=
"grasscutter"
;
...
...
src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java
View file @
0e7976f9
package
emu.grasscutter.server.dispatch
;
package
emu.grasscutter.server.dispatch
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.net.InetSocketAddress
;
import
java.net.URI
;
import
java.net.URLDecoder
;
import
java.security.KeyStore
;
import
java.util.Base64
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Map
;
import
javax.net.ssl.KeyManagerFactory
;
import
javax.net.ssl.SSLContext
;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.google.gson.GsonBuilder
;
import
com.google.protobuf.ByteString
;
import
com.google.protobuf.ByteString
;
import
com.sun.net.httpserver.HttpExchange
;
import
com.sun.net.httpserver.HttpExchange
;
import
com.sun.net.httpserver.Http
Handl
er
;
import
com.sun.net.httpserver.Http
Serv
er
;
import
com.sun.net.httpserver.HttpsConfigurator
;
import
com.sun.net.httpserver.HttpsConfigurator
;
import
com.sun.net.httpserver.HttpsServer
;
import
com.sun.net.httpserver.HttpsServer
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.database.DatabaseHelper
;
import
emu.grasscutter.database.DatabaseHelper
;
import
emu.grasscutter.game.Account
;
import
emu.grasscutter.game.Account
;
...
@@ -32,27 +14,31 @@ import emu.grasscutter.net.proto.QueryCurrRegionHttpRspOuterClass.QueryCurrRegio
...
@@ -32,27 +14,31 @@ import emu.grasscutter.net.proto.QueryCurrRegionHttpRspOuterClass.QueryCurrRegio
import
emu.grasscutter.net.proto.QueryRegionListHttpRspOuterClass.QueryRegionListHttpRsp
;
import
emu.grasscutter.net.proto.QueryRegionListHttpRspOuterClass.QueryRegionListHttpRsp
;
import
emu.grasscutter.net.proto.RegionInfoOuterClass.RegionInfo
;
import
emu.grasscutter.net.proto.RegionInfoOuterClass.RegionInfo
;
import
emu.grasscutter.net.proto.RegionSimpleInfoOuterClass.RegionSimpleInfo
;
import
emu.grasscutter.net.proto.RegionSimpleInfoOuterClass.RegionSimpleInfo
;
import
emu.grasscutter.server.dispatch.json.ComboTokenReqJson
;
import
emu.grasscutter.server.dispatch.json.*
;
import
emu.grasscutter.server.dispatch.json.ComboTokenResJson
;
import
emu.grasscutter.server.dispatch.json.LoginAccountRequestJson
;
import
emu.grasscutter.server.dispatch.json.LoginResultJson
;
import
emu.grasscutter.server.dispatch.json.LoginTokenRequestJson
;
import
emu.grasscutter.server.dispatch.json.ComboTokenReqJson.LoginTokenData
;
import
emu.grasscutter.server.dispatch.json.ComboTokenReqJson.LoginTokenData
;
import
emu.grasscutter.utils.FileUtils
;
import
emu.grasscutter.utils.FileUtils
;
import
emu.grasscutter.utils.Utils
;
import
emu.grasscutter.utils.Utils
;
import
com.sun.net.httpserver.HttpServer
;
import
javax.net.ssl.KeyManagerFactory
;
import
javax.net.ssl.SSLContext
;
import
java.io.*
;
import
java.net.InetSocketAddress
;
import
java.net.URI
;
import
java.net.URLDecoder
;
import
java.security.KeyStore
;
import
java.util.Base64
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Map
;
public
final
class
DispatchServer
{
public
final
class
DispatchServer
{
public
static
String
query_region_list
=
""
;
public
static
String
query_cur_region
=
""
;
private
final
InetSocketAddress
address
;
private
final
InetSocketAddress
address
;
private
final
Gson
gson
;
private
final
Gson
gson
;
private
QueryCurrRegionHttpRsp
currRegion
;
public
String
regionListBase64
;
public
String
regionListBase64
;
public
String
regionCurrentBase64
;
public
String
regionCurrentBase64
;
private
QueryCurrRegionHttpRsp
currRegion
;
public
static
String
query_region_list
=
""
;
public
static
String
query_cur_region
=
""
;
public
DispatchServer
()
{
public
DispatchServer
()
{
this
.
address
=
new
InetSocketAddress
(
Grasscutter
.
getConfig
().
DispatchServerIp
,
Grasscutter
.
getConfig
().
DispatchServerPort
);
this
.
address
=
new
InetSocketAddress
(
Grasscutter
.
getConfig
().
DispatchServerIp
,
Grasscutter
.
getConfig
().
DispatchServerPort
);
...
@@ -81,14 +67,14 @@ public final class DispatchServer {
...
@@ -81,14 +67,14 @@ public final class DispatchServer {
if
(
file
.
exists
())
{
if
(
file
.
exists
())
{
query_region_list
=
new
String
(
FileUtils
.
read
(
file
));
query_region_list
=
new
String
(
FileUtils
.
read
(
file
));
}
else
{
}
else
{
Grasscutter
.
getLogger
().
warn
(
"query_region_list not found! Using default region list."
);
Grasscutter
.
getLogger
().
warn
(
"
[Dispatch]
query_region_list not found! Using default region list."
);
}
}
file
=
new
File
(
Grasscutter
.
getConfig
().
DATA_FOLDER
+
"query_cur_region.txt"
);
file
=
new
File
(
Grasscutter
.
getConfig
().
DATA_FOLDER
+
"query_cur_region.txt"
);
if
(
file
.
exists
())
{
if
(
file
.
exists
())
{
query_cur_region
=
new
String
(
FileUtils
.
read
(
file
));
query_cur_region
=
new
String
(
FileUtils
.
read
(
file
));
}
else
{
}
else
{
Grasscutter
.
getLogger
().
warn
(
"query_cur_region not found! Using default current region."
);
Grasscutter
.
getLogger
().
warn
(
"
[Dispatch]
query_cur_region not found! Using default current region."
);
}
}
}
}
...
@@ -134,13 +120,13 @@ public final class DispatchServer {
...
@@ -134,13 +120,13 @@ public final class DispatchServer {
this
.
regionCurrentBase64
=
Base64
.
getEncoder
().
encodeToString
(
parsedRegionQuery
.
toByteString
().
toByteArray
());
this
.
regionCurrentBase64
=
Base64
.
getEncoder
().
encodeToString
(
parsedRegionQuery
.
toByteString
().
toByteArray
());
this
.
currRegion
=
parsedRegionQuery
;
this
.
currRegion
=
parsedRegionQuery
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Grasscutter
.
getLogger
().
error
(
"Error while initializing region info!"
,
e
);
Grasscutter
.
getLogger
().
error
(
"
[Dispatch]
Error while initializing region info!"
,
e
);
}
}
}
}
public
void
start
()
throws
Exception
{
public
void
start
()
throws
Exception
{
HttpServer
server
;
HttpServer
server
;
if
(
Grasscutter
.
getConfig
().
UseSSL
)
{
if
(
Grasscutter
.
getConfig
().
UseSSL
)
{
HttpsServer
httpsServer
;
HttpsServer
httpsServer
;
httpsServer
=
HttpsServer
.
create
(
getAddress
(),
0
);
httpsServer
=
HttpsServer
.
create
(
getAddress
(),
0
);
SSLContext
sslContext
=
SSLContext
.
getInstance
(
"TLS"
);
SSLContext
sslContext
=
SSLContext
.
getInstance
(
"TLS"
);
...
@@ -156,55 +142,34 @@ public final class DispatchServer {
...
@@ -156,55 +142,34 @@ public final class DispatchServer {
httpsServer
.
setHttpsConfigurator
(
new
HttpsConfigurator
(
sslContext
));
httpsServer
.
setHttpsConfigurator
(
new
HttpsConfigurator
(
sslContext
));
server
=
httpsServer
;
server
=
httpsServer
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Grasscutter
.
getLogger
().
error
(
"No SSL cert found!"
);
Grasscutter
.
getLogger
().
warn
(
"[Dispatch] No SSL cert found! Falling back to HTTP server."
);
return
;
Grasscutter
.
getConfig
().
UseSSL
=
false
;
server
=
HttpServer
.
create
(
getAddress
(),
0
);
}
}
}
else
{
}
else
{
server
=
HttpServer
.
create
(
getAddress
(),
0
);
server
=
HttpServer
.
create
(
getAddress
(),
0
);
}
}
server
.
createContext
(
"/"
,
t
->
{
server
.
createContext
(
"/"
,
t
->
responseHTML
(
t
,
"Hello"
));
//Create a response form the request query parameters
String
response
=
"Hello"
;
//Set the response header status and length
t
.
getResponseHeaders
().
put
(
"Content-Type"
,
Collections
.
singletonList
(
"text/html; charset=UTF-8"
));
t
.
sendResponseHeaders
(
200
,
response
.
getBytes
().
length
);
//Write the response string
OutputStream
os
=
t
.
getResponseBody
();
os
.
write
(
response
.
getBytes
());
os
.
close
();
});
// Dispatch
// Dispatch
server
.
createContext
(
"/query_region_list"
,
t
->
{
server
.
createContext
(
"/query_region_list"
,
t
->
{
// Log
// Log
Grasscutter
.
getLogger
().
info
(
"Client request: query_region_list"
);
Grasscutter
.
getLogger
().
info
(
String
.
format
(
"[Dispatch] Client %s request: query_region_list"
,
t
.
getRemoteAddress
()));
// Create a response form the request query parameters
String
response
=
regionListBase64
;
responseHTML
(
t
,
regionListBase64
);
// Set the response header status and length
t
.
getResponseHeaders
().
put
(
"Content-Type"
,
Collections
.
singletonList
(
"text/html; charset=UTF-8"
));
t
.
sendResponseHeaders
(
200
,
response
.
getBytes
().
length
);
// Write the response string
OutputStream
os
=
t
.
getResponseBody
();
os
.
write
(
response
.
getBytes
());
os
.
close
();
});
});
server
.
createContext
(
"/query_cur_region"
,
t
->
{
server
.
createContext
(
"/query_cur_region"
,
t
->
{
// Log
// Log
Grasscutter
.
getLogger
().
info
(
"
Client request: query_cur_region"
);
Grasscutter
.
getLogger
().
info
(
String
.
format
(
"[Dispatch]
Client
%s
request: query_cur_region"
,
t
.
getRemoteAddress
())
);
// Create a response form the request query parameters
// Create a response form the request query parameters
URI
uri
=
t
.
getRequestURI
();
URI
uri
=
t
.
getRequestURI
();
String
response
=
"CAESGE5vdCBGb3VuZCB2ZXJzaW9uIGNvbmZpZw=="
;
String
response
=
"CAESGE5vdCBGb3VuZCB2ZXJzaW9uIGNvbmZpZw=="
;
if
(
uri
.
getQuery
()
!=
null
&&
uri
.
getQuery
().
length
()
>
0
)
{
if
(
uri
.
getQuery
()
!=
null
&&
uri
.
getQuery
().
length
()
>
0
)
{
response
=
regionCurrentBase64
;
response
=
regionCurrentBase64
;
}
}
// Set the response header status and length
t
.
getResponseHeaders
().
put
(
"Content-Type"
,
Collections
.
singletonList
(
"text/html; charset=UTF-8"
));
responseHTML
(
t
,
response
);
t
.
sendResponseHeaders
(
200
,
response
.
getBytes
().
length
);
// Write the response string
OutputStream
os
=
t
.
getResponseBody
();
os
.
write
(
response
.
getBytes
());
os
.
close
();
});
});
// Login via account
// Login via account
server
.
createContext
(
"/hk4e_global/mdk/shield/api/login"
,
t
->
{
server
.
createContext
(
"/hk4e_global/mdk/shield/api/login"
,
t
->
{
...
@@ -213,8 +178,7 @@ public final class DispatchServer {
...
@@ -213,8 +178,7 @@ public final class DispatchServer {
try
{
try
{
String
body
=
Utils
.
toString
(
t
.
getRequestBody
());
String
body
=
Utils
.
toString
(
t
.
getRequestBody
());
requestData
=
getGsonFactory
().
fromJson
(
body
,
LoginAccountRequestJson
.
class
);
requestData
=
getGsonFactory
().
fromJson
(
body
,
LoginAccountRequestJson
.
class
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
ignored
)
{
}
}
// Create response json
// Create response json
if
(
requestData
==
null
)
{
if
(
requestData
==
null
)
{
...
@@ -222,6 +186,8 @@ public final class DispatchServer {
...
@@ -222,6 +186,8 @@ public final class DispatchServer {
}
}
LoginResultJson
responseData
=
new
LoginResultJson
();
LoginResultJson
responseData
=
new
LoginResultJson
();
Grasscutter
.
getLogger
().
info
(
String
.
format
(
"[Dispatch] Client %s is trying to log in"
,
t
.
getRemoteAddress
()));
// Login
// Login
Account
account
=
DatabaseHelper
.
getAccountByName
(
requestData
.
account
);
Account
account
=
DatabaseHelper
.
getAccountByName
(
requestData
.
account
);
...
@@ -232,13 +198,24 @@ public final class DispatchServer {
...
@@ -232,13 +198,24 @@ public final class DispatchServer {
// This account has been created AUTOMATICALLY. There will be no permissions added.
// This account has been created AUTOMATICALLY. There will be no permissions added.
account
=
DatabaseHelper
.
createAccountWithId
(
requestData
.
account
,
0
);
account
=
DatabaseHelper
.
createAccountWithId
(
requestData
.
account
,
0
);
if
(
account
!=
null
)
{
responseData
.
message
=
"OK"
;
responseData
.
message
=
"OK"
;
responseData
.
data
.
account
.
uid
=
account
.
getId
();
responseData
.
data
.
account
.
uid
=
account
.
getId
();
responseData
.
data
.
account
.
token
=
account
.
generateSessionKey
();
responseData
.
data
.
account
.
token
=
account
.
generateSessionKey
();
responseData
.
data
.
account
.
email
=
account
.
getEmail
();
responseData
.
data
.
account
.
email
=
account
.
getEmail
();
Grasscutter
.
getLogger
().
info
(
String
.
format
(
"[Dispatch] Client %s failed to log in: Account %s created"
,
t
.
getRemoteAddress
(),
responseData
.
data
.
account
.
uid
));
}
else
{
responseData
.
retcode
=
-
201
;
responseData
.
message
=
"Username not found, create failed."
;
Grasscutter
.
getLogger
().
info
(
String
.
format
(
"[Dispatch] Client %s failed to log in: Account create failed"
,
t
.
getRemoteAddress
()));
}
}
else
{
}
else
{
responseData
.
retcode
=
-
201
;
responseData
.
retcode
=
-
201
;
responseData
.
message
=
"Username not found."
;
responseData
.
message
=
"Username not found."
;
Grasscutter
.
getLogger
().
info
(
String
.
format
(
"[Dispatch] Client %s failed to log in: Account no found"
,
t
.
getRemoteAddress
()));
}
}
}
else
{
}
else
{
// Account was found, log the player in
// Account was found, log the player in
...
@@ -246,18 +223,13 @@ public final class DispatchServer {
...
@@ -246,18 +223,13 @@ public final class DispatchServer {
responseData
.
data
.
account
.
uid
=
account
.
getId
();
responseData
.
data
.
account
.
uid
=
account
.
getId
();
responseData
.
data
.
account
.
token
=
account
.
generateSessionKey
();
responseData
.
data
.
account
.
token
=
account
.
generateSessionKey
();
responseData
.
data
.
account
.
email
=
account
.
getEmail
();
responseData
.
data
.
account
.
email
=
account
.
getEmail
();
Grasscutter
.
getLogger
().
info
(
String
.
format
(
"[Dispatch] Client %s logged in as %s"
,
t
.
getRemoteAddress
(),
responseData
.
data
.
account
.
uid
));
}
}
// Create a response
responseJSON
(
t
,
responseData
);
String
response
=
getGsonFactory
().
toJson
(
responseData
);
// 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
();
});
});
// Login via token
// Login via token
server
.
createContext
(
"/hk4e_global/mdk/shield/api/verify"
,
t
->
{
server
.
createContext
(
"/hk4e_global/mdk/shield/api/verify"
,
t
->
{
// Get post data
// Get post data
...
@@ -265,14 +237,14 @@ public final class DispatchServer {
...
@@ -265,14 +237,14 @@ public final class DispatchServer {
try
{
try
{
String
body
=
Utils
.
toString
(
t
.
getRequestBody
());
String
body
=
Utils
.
toString
(
t
.
getRequestBody
());
requestData
=
getGsonFactory
().
fromJson
(
body
,
LoginTokenRequestJson
.
class
);
requestData
=
getGsonFactory
().
fromJson
(
body
,
LoginTokenRequestJson
.
class
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
ignored
)
{
}
}
// Create response json
// Create response json
if
(
requestData
==
null
)
{
if
(
requestData
==
null
)
{
return
;
return
;
}
}
LoginResultJson
responseData
=
new
LoginResultJson
();
LoginResultJson
responseData
=
new
LoginResultJson
();
Grasscutter
.
getLogger
().
info
(
String
.
format
(
"[Dispatch] Client %s is trying to log in via token"
,
t
.
getRemoteAddress
()));
// Login
// Login
Account
account
=
DatabaseHelper
.
getAccountById
(
requestData
.
uid
);
Account
account
=
DatabaseHelper
.
getAccountById
(
requestData
.
uid
);
...
@@ -281,22 +253,18 @@ public final class DispatchServer {
...
@@ -281,22 +253,18 @@ public final class DispatchServer {
if
(
account
==
null
||
!
account
.
getSessionKey
().
equals
(
requestData
.
token
))
{
if
(
account
==
null
||
!
account
.
getSessionKey
().
equals
(
requestData
.
token
))
{
responseData
.
retcode
=
-
111
;
responseData
.
retcode
=
-
111
;
responseData
.
message
=
"Game account cache information error"
;
responseData
.
message
=
"Game account cache information error"
;
Grasscutter
.
getLogger
().
info
(
String
.
format
(
"[Dispatch] Client %s failed to log in via token"
,
t
.
getRemoteAddress
()));
}
else
{
}
else
{
responseData
.
message
=
"OK"
;
responseData
.
message
=
"OK"
;
responseData
.
data
.
account
.
uid
=
requestData
.
uid
;
responseData
.
data
.
account
.
uid
=
requestData
.
uid
;
responseData
.
data
.
account
.
token
=
requestData
.
token
;
responseData
.
data
.
account
.
token
=
requestData
.
token
;
responseData
.
data
.
account
.
email
=
account
.
getEmail
();
responseData
.
data
.
account
.
email
=
account
.
getEmail
();
Grasscutter
.
getLogger
().
info
(
String
.
format
(
"[Dispatch] Client %s logged in via token as %s"
,
t
.
getRemoteAddress
(),
responseData
.
data
.
account
.
uid
));
}
}
// Create a response
responseJSON
(
t
,
responseData
);
String
response
=
getGsonFactory
().
toJson
(
responseData
);
// 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
();
});
});
// Exchange for combo token
// Exchange for combo token
server
.
createContext
(
"/hk4e_global/combo/granter/login/v2/login"
,
t
->
{
server
.
createContext
(
"/hk4e_global/combo/granter/login/v2/login"
,
t
->
{
...
@@ -305,8 +273,7 @@ public final class DispatchServer {
...
@@ -305,8 +273,7 @@ public final class DispatchServer {
try
{
try
{
String
body
=
Utils
.
toString
(
t
.
getRequestBody
());
String
body
=
Utils
.
toString
(
t
.
getRequestBody
());
requestData
=
getGsonFactory
().
fromJson
(
body
,
ComboTokenReqJson
.
class
);
requestData
=
getGsonFactory
().
fromJson
(
body
,
ComboTokenReqJson
.
class
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
ignored
)
{
}
}
// Create response json
// Create response json
if
(
requestData
==
null
||
requestData
.
data
==
null
)
{
if
(
requestData
==
null
||
requestData
.
data
==
null
)
{
...
@@ -322,22 +289,18 @@ public final class DispatchServer {
...
@@ -322,22 +289,18 @@ public final class DispatchServer {
if
(
account
==
null
||
!
account
.
getSessionKey
().
equals
(
loginData
.
token
))
{
if
(
account
==
null
||
!
account
.
getSessionKey
().
equals
(
loginData
.
token
))
{
responseData
.
retcode
=
-
201
;
responseData
.
retcode
=
-
201
;
responseData
.
message
=
"Wrong session key."
;
responseData
.
message
=
"Wrong session key."
;
Grasscutter
.
getLogger
().
info
(
String
.
format
(
"[Dispatch] Client %s failed to exchange combo token"
,
t
.
getRemoteAddress
()));
}
else
{
}
else
{
responseData
.
message
=
"OK"
;
responseData
.
message
=
"OK"
;
responseData
.
data
.
open_id
=
loginData
.
uid
;
responseData
.
data
.
open_id
=
loginData
.
uid
;
responseData
.
data
.
combo_id
=
"157795300"
;
responseData
.
data
.
combo_id
=
"157795300"
;
responseData
.
data
.
combo_token
=
account
.
generateLoginToken
();
responseData
.
data
.
combo_token
=
account
.
generateLoginToken
();
Grasscutter
.
getLogger
().
info
(
String
.
format
(
"[Dispatch] Client %s succeed to exchange combo token"
,
t
.
getRemoteAddress
()));
}
}
// Create a response
responseJSON
(
t
,
responseData
);
String
response
=
getGsonFactory
().
toJson
(
responseData
);
// 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
();
});
});
// Agreement and Protocol
// Agreement and Protocol
server
.
createContext
(
// hk4e-sdk-os.hoyoverse.com
server
.
createContext
(
// hk4e-sdk-os.hoyoverse.com
...
@@ -405,57 +368,66 @@ public final class DispatchServer {
...
@@ -405,57 +368,66 @@ public final class DispatchServer {
"/perf/config/verify"
,
"/perf/config/verify"
,
new
DispatchHttpJsonHandler
(
"{\"code\":0}"
)
new
DispatchHttpJsonHandler
(
"{\"code\":0}"
)
);
);
// Start server
server
.
start
();
Grasscutter
.
getLogger
().
info
(
"Dispatch server started on port "
+
getAddress
().
getPort
());
// Logging servers
// Logging servers
HttpServer
overseaLogServer
=
HttpServer
.
create
(
new
InetSocketAddress
(
Grasscutter
.
getConfig
().
DispatchServerIp
,
Grasscutter
.
getConfig
().
OverseaLogPort
),
0
);
server
.
createContext
(
// overseauspider.yuanshen.com
overseaLogServer
.
createContext
(
// overseauspider.yuanshen.com
"/log"
,
"/log"
,
new
DispatchHttpJsonHandler
(
"{\"code\":0}"
)
new
DispatchHttpJsonHandler
(
"{\"code\":0}"
)
);
);
overseaLogServer
.
start
();
Grasscutter
.
getLogger
().
info
(
"Log server (overseauspider) started on port "
+
8888
);
HttpServer
uploadLogServer
=
HttpServer
.
create
(
new
InetSocketAddress
(
Grasscutter
.
getConfig
().
DispatchServerIp
,
Grasscutter
.
getConfig
().
UploadLogPort
),
0
);
server
.
createContext
(
// log-upload-os.mihoyo.com
uploadLogServer
.
createContext
(
// log-upload-os.mihoyo.com
"/crash/dataUpload"
,
"/crash/dataUpload"
,
new
DispatchHttpJsonHandler
(
"{\"code\":0}"
)
new
DispatchHttpJsonHandler
(
"{\"code\":0}"
)
);
);
uploadLogServer
.
createContext
(
"/gacha"
,
t
->
{
server
.
createContext
(
"/gacha"
,
t
->
responseHTML
(
t
,
"<!doctype html><html lang=\"en\"><head><title>Gacha</title></head><body></body></html>"
));
//Create a response form the request query parameters
// Start server
String
response
=
"<!doctype html><html lang=\"en\"><head><title>Gacha</title></head><body></body></html>"
;
server
.
start
();
//Set the response header status and length
Grasscutter
.
getLogger
().
info
(
"[Dispatch] Dispatch server started on port "
+
getAddress
().
getPort
());
}
private
void
responseJSON
(
HttpExchange
t
,
Object
data
)
throws
IOException
{
// Create a response
String
response
=
getGsonFactory
().
toJson
(
data
);
// 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
();
}
private
void
responseHTML
(
HttpExchange
t
,
String
response
)
throws
IOException
{
// Set the response header status and length
t
.
getResponseHeaders
().
put
(
"Content-Type"
,
Collections
.
singletonList
(
"text/html; charset=UTF-8"
));
t
.
getResponseHeaders
().
put
(
"Content-Type"
,
Collections
.
singletonList
(
"text/html; charset=UTF-8"
));
t
.
sendResponseHeaders
(
200
,
response
.
getBytes
().
length
);
t
.
sendResponseHeaders
(
200
,
response
.
getBytes
().
length
);
//Write the response string
//Write the response string
OutputStream
os
=
t
.
getResponseBody
();
OutputStream
os
=
t
.
getResponseBody
();
os
.
write
(
response
.
getBytes
());
os
.
write
(
response
.
getBytes
());
os
.
close
();
os
.
close
();
});
uploadLogServer
.
start
();
Grasscutter
.
getLogger
().
info
(
"Log server (log-upload-os) started on port "
+
Grasscutter
.
getConfig
().
UploadLogPort
);
}
}
private
Map
<
String
,
String
>
parseQueryString
(
String
qs
)
{
private
Map
<
String
,
String
>
parseQueryString
(
String
qs
)
{
Map
<
String
,
String
>
result
=
new
HashMap
<>();
Map
<
String
,
String
>
result
=
new
HashMap
<>();
if
(
qs
==
null
)
if
(
qs
==
null
)
{
return
result
;
return
result
;
}
int
last
=
0
,
next
,
l
=
qs
.
length
();
int
last
=
0
,
next
,
l
=
qs
.
length
();
while
(
last
<
l
)
{
while
(
last
<
l
)
{
next
=
qs
.
indexOf
(
'&'
,
last
);
next
=
qs
.
indexOf
(
'&'
,
last
);
if
(
next
==
-
1
)
if
(
next
==
-
1
)
{
next
=
l
;
next
=
l
;
}
if
(
next
>
last
)
{
if
(
next
>
last
)
{
int
eqPos
=
qs
.
indexOf
(
'='
,
last
);
int
eqPos
=
qs
.
indexOf
(
'='
,
last
);
try
{
try
{
if
(
eqPos
<
0
||
eqPos
>
next
)
if
(
eqPos
<
0
||
eqPos
>
next
)
{
result
.
put
(
URLDecoder
.
decode
(
qs
.
substring
(
last
,
next
),
"utf-8"
),
""
);
result
.
put
(
URLDecoder
.
decode
(
qs
.
substring
(
last
,
next
),
"utf-8"
),
""
);
else
}
else
{
result
.
put
(
URLDecoder
.
decode
(
qs
.
substring
(
last
,
eqPos
),
"utf-8"
),
URLDecoder
.
decode
(
qs
.
substring
(
eqPos
+
1
,
next
),
"utf-8"
));
result
.
put
(
URLDecoder
.
decode
(
qs
.
substring
(
last
,
eqPos
),
"utf-8"
),
URLDecoder
.
decode
(
qs
.
substring
(
eqPos
+
1
,
next
),
"utf-8"
));
}
}
catch
(
UnsupportedEncodingException
e
)
{
}
catch
(
UnsupportedEncodingException
e
)
{
throw
new
RuntimeException
(
e
);
// will never happen, utf-8 support is mandatory for java
throw
new
RuntimeException
(
e
);
// will never happen, utf-8 support is mandatory for java
}
}
...
...
src/main/java/emu/grasscutter/server/dispatch/json/ComboTokenReqJson.java
View file @
0e7976f9
...
@@ -7,7 +7,7 @@ public class ComboTokenReqJson {
...
@@ -7,7 +7,7 @@ public class ComboTokenReqJson {
public
String
device
;
public
String
device
;
public
String
sign
;
public
String
sign
;
public
class
LoginTokenData
{
public
static
class
LoginTokenData
{
public
String
uid
;
public
String
uid
;
public
String
token
;
public
String
token
;
public
boolean
guest
;
public
boolean
guest
;
...
...
src/main/java/emu/grasscutter/server/dispatch/json/ComboTokenResJson.java
View file @
0e7976f9
...
@@ -5,7 +5,7 @@ public class ComboTokenResJson {
...
@@ -5,7 +5,7 @@ public class ComboTokenResJson {
public
int
retcode
;
public
int
retcode
;
public
LoginData
data
=
new
LoginData
();
public
LoginData
data
=
new
LoginData
();
public
class
LoginData
{
public
static
class
LoginData
{
public
int
account_type
=
1
;
public
int
account_type
=
1
;
public
boolean
heartbeat
;
public
boolean
heartbeat
;
public
String
combo_id
;
public
String
combo_id
;
...
...
src/main/java/emu/grasscutter/server/dispatch/json/LoginResultJson.java
View file @
0e7976f9
...
@@ -5,7 +5,7 @@ public class LoginResultJson {
...
@@ -5,7 +5,7 @@ public class LoginResultJson {
public
int
retcode
;
public
int
retcode
;
public
VerifyData
data
=
new
VerifyData
();
public
VerifyData
data
=
new
VerifyData
();
public
class
VerifyData
{
public
static
class
VerifyData
{
public
VerifyAccountData
account
=
new
VerifyAccountData
();
public
VerifyAccountData
account
=
new
VerifyAccountData
();
public
boolean
device_grant_required
=
false
;
public
boolean
device_grant_required
=
false
;
public
String
realname_operation
=
"NONE"
;
public
String
realname_operation
=
"NONE"
;
...
@@ -13,7 +13,7 @@ public class LoginResultJson {
...
@@ -13,7 +13,7 @@ public class LoginResultJson {
public
boolean
safe_mobile_required
=
false
;
public
boolean
safe_mobile_required
=
false
;
}
}
public
class
VerifyAccountData
{
public
static
class
VerifyAccountData
{
public
String
uid
;
public
String
uid
;
public
String
name
=
""
;
public
String
name
=
""
;
public
String
email
;
public
String
email
;
...
...
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