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
600decbc
Commit
600decbc
authored
Apr 23, 2022
by
KingRainbow44
Browse files
Implement region events
parent
6056e962
Changes
3
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java
View file @
600decbc
...
@@ -18,6 +18,8 @@ import emu.grasscutter.net.proto.RegionInfoOuterClass.RegionInfo;
...
@@ -18,6 +18,8 @@ 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.*
;
import
emu.grasscutter.server.dispatch.json.*
;
import
emu.grasscutter.server.dispatch.json.ComboTokenReqJson.LoginTokenData
;
import
emu.grasscutter.server.dispatch.json.ComboTokenReqJson.LoginTokenData
;
import
emu.grasscutter.server.event.dispatch.QueryAllRegionsEvent
;
import
emu.grasscutter.server.event.dispatch.QueryCurrentRegionEvent
;
import
emu.grasscutter.utils.FileUtils
;
import
emu.grasscutter.utils.FileUtils
;
import
emu.grasscutter.utils.Utils
;
import
emu.grasscutter.utils.Utils
;
...
@@ -189,24 +191,32 @@ public final class DispatchServer {
...
@@ -189,24 +191,32 @@ public final class DispatchServer {
// Dispatch
// Dispatch
server
.
createContext
(
"/query_region_list"
,
t
->
{
server
.
createContext
(
"/query_region_list"
,
t
->
{
// Log
// Log
incoming request.
Grasscutter
.
getLogger
().
info
(
String
.
format
(
"[Dispatch] Client %s request: query_region_list"
,
t
.
getRemoteAddress
()));
Grasscutter
.
getLogger
().
info
(
String
.
format
(
"[Dispatch] Client %s request: query_region_list"
,
t
.
getRemoteAddress
()));
responseHTML
(
t
,
regionListBase64
);
// Invoke event.
QueryAllRegionsEvent
event
=
new
QueryAllRegionsEvent
(
this
.
regionListBase64
);
event
.
call
();
// Respond with event result.
responseHTML
(
t
,
event
.
getRegionList
());
});
});
for
(
String
regionName
:
regions
.
keySet
())
{
for
(
String
regionName
:
regions
.
keySet
())
{
server
.
createContext
(
"/query_cur_region_"
+
regionName
,
t
->
{
server
.
createContext
(
"/query_cur_region_"
+
regionName
,
t
->
{
String
regionCurrentBase64
=
regions
.
get
(
regionName
).
Base64
;
String
regionCurrentBase64
=
regions
.
get
(
regionName
).
Base64
;
// Log
// Log
incoming request.
Grasscutter
.
getLogger
().
info
(
String
.
format
(
"Client %s request: query_cur_region_%s"
,
t
.
getRemoteAddress
(),
regionName
));
Grasscutter
.
getLogger
().
info
(
String
.
format
(
"Client %s request: query_cur_region_%s"
,
t
.
getRemoteAddress
(),
regionName
));
// Create a response form the request query parameters
// Create a response from 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
;
}
}
responseHTML
(
t
,
response
);
// Invoke event.
QueryCurrentRegionEvent
event
=
new
QueryCurrentRegionEvent
(
response
);
event
.
call
();
// Respond with event result.
responseHTML
(
t
,
event
.
getRegionInfo
());
});
});
}
}
...
...
src/main/java/emu/grasscutter/server/event/dispatch/QueryAllRegionsEvent.java
0 → 100644
View file @
600decbc
package
emu.grasscutter.server.event.dispatch
;
import
emu.grasscutter.server.event.ServerEvent
;
public
final
class
QueryAllRegionsEvent
extends
ServerEvent
{
private
String
regionList
;
public
QueryAllRegionsEvent
(
String
regionList
)
{
super
(
Type
.
DISPATCH
);
this
.
regionList
=
regionList
;
}
public
void
setRegionList
(
String
regionList
)
{
this
.
regionList
=
regionList
;
}
public
String
getRegionList
()
{
return
this
.
regionList
;
}
}
src/main/java/emu/grasscutter/server/event/dispatch/QueryCurrentRegionEvent.java
0 → 100644
View file @
600decbc
package
emu.grasscutter.server.event.dispatch
;
import
emu.grasscutter.server.event.ServerEvent
;
public
final
class
QueryCurrentRegionEvent
extends
ServerEvent
{
private
String
regionInfo
;
public
QueryCurrentRegionEvent
(
String
regionInfo
)
{
super
(
Type
.
DISPATCH
);
this
.
regionInfo
=
regionInfo
;
}
public
void
setRegionInfo
(
String
regionInfo
)
{
this
.
regionInfo
=
regionInfo
;
}
public
String
getRegionInfo
()
{
return
this
.
regionInfo
;
}
}
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