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
f35f76f3
Commit
f35f76f3
authored
Apr 20, 2022
by
Magix
Committed by
GitHub
Apr 20, 2022
Browse files
Events, Gradle Update, and Gacha Reload
Update gradle, Implemented live gacha reloading, and game server event buses
parents
757b9c9d
482c174e
Changes
9
Show whitespace changes
Inline
Side-by-side
build.gradle
View file @
f35f76f3
...
@@ -23,19 +23,21 @@ repositories {
...
@@ -23,19 +23,21 @@ repositories {
}
}
dependencies
{
dependencies
{
co
mp
i
le
fileTree
(
dir:
'lib'
,
include:
'*.jar'
)
i
mple
mentation
fileTree
(
dir:
'lib'
,
include:
[
'*.jar'
]
)
co
mp
i
le
group:
'org.slf4j'
,
name:
'slf4j-api'
,
version:
'1.7.32'
i
mple
mentation
group:
'org.slf4j'
,
name:
'slf4j-api'
,
version:
'1.7.32'
co
mp
i
le
group:
'ch.qos.logback'
,
name:
'logback-core'
,
version:
'1.2.6'
i
mple
mentation
group:
'ch.qos.logback'
,
name:
'logback-core'
,
version:
'1.2.6'
co
mp
i
le
group:
'ch.qos.logback'
,
name:
'logback-classic'
,
version:
'1.2.6'
i
mple
mentation
group:
'ch.qos.logback'
,
name:
'logback-classic'
,
version:
'1.2.6'
co
mp
i
le
group:
'io.netty'
,
name:
'netty-all'
,
version:
'4.1.69.Final'
i
mple
mentation
group:
'io.netty'
,
name:
'netty-all'
,
version:
'4.1.69.Final'
co
mp
i
le
group:
'com.google.code.gson'
,
name:
'gson'
,
version:
'2.8.8'
i
mple
mentation
group:
'com.google.code.gson'
,
name:
'gson'
,
version:
'2.8.8'
co
mp
i
le
group:
'com.google.protobuf'
,
name:
'protobuf-java'
,
version:
'3.18.1'
i
mple
mentation
group:
'com.google.protobuf'
,
name:
'protobuf-java'
,
version:
'3.18.1'
co
mp
i
le
group:
'org.reflections'
,
name:
'reflections'
,
version:
'0.9.12'
i
mple
mentation
group:
'org.reflections'
,
name:
'reflections'
,
version:
'0.9.12'
compile
group:
'dev.morphia.morphia'
,
name:
'core'
,
version:
'1.6.1'
implementation
group:
'dev.morphia.morphia'
,
name:
'core'
,
version:
'1.6.1'
implementation
group:
'org.greenrobot'
,
name:
'eventbus-java'
,
version:
'3.3.1'
}
}
application
{
application
{
...
@@ -51,9 +53,11 @@ jar {
...
@@ -51,9 +53,11 @@ jar {
jar
.
baseName
=
'grasscutter'
jar
.
baseName
=
'grasscutter'
from
{
from
{
configurations
.
compile
.
collect
{
it
.
isDirectory
()
?
it
:
zipTree
(
it
)
}
configurations
.
runtimeClasspath
.
collect
{
it
.
isDirectory
()
?
it
:
zipTree
(
it
)
}
}
}
duplicatesStrategy
=
DuplicatesStrategy
.
INCLUDE
from
(
'src/main/java'
)
{
from
(
'src/main/java'
)
{
include
'*.xml'
include
'*.xml'
}
}
...
...
gradle/wrapper/gradle-wrapper.properties
View file @
f35f76f3
distributionBase
=
GRADLE_USER_HOME
distributionBase
=
GRADLE_USER_HOME
distributionPath
=
wrapper/dists
distributionPath
=
wrapper/dists
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-
5.6.3
-bin.zip
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-
7.4.2
-bin.zip
zipStoreBase
=
GRADLE_USER_HOME
zipStoreBase
=
GRADLE_USER_HOME
zipStorePath
=
wrapper/dists
zipStorePath
=
wrapper/dists
src/main/java/emu/grasscutter/Config.java
View file @
f35f76f3
...
@@ -51,6 +51,7 @@ public final class Config {
...
@@ -51,6 +51,7 @@ public final class Config {
public
int
MaxAvatarsInTeam
=
4
;
public
int
MaxAvatarsInTeam
=
4
;
public
int
MaxAvatarsInTeamMultiplayer
=
4
;
public
int
MaxAvatarsInTeamMultiplayer
=
4
;
public
int
MaxEntityLimit
=
1000
;
// Max entity limit per world. // TODO: Enforce later.
public
int
MaxEntityLimit
=
1000
;
// Max entity limit per world. // TODO: Enforce later.
public
boolean
WatchGacha
=
false
;
public
int
[]
WelcomeEmotes
=
{
2007
,
1002
,
4010
};
public
int
[]
WelcomeEmotes
=
{
2007
,
1002
,
4010
};
public
String
WelcomeMotd
=
"Welcome to Grasscutter emu"
;
public
String
WelcomeMotd
=
"Welcome to Grasscutter emu"
;
public
boolean
AutomaticallyCreateAccounts
=
false
;
public
boolean
AutomaticallyCreateAccounts
=
false
;
...
...
src/main/java/emu/grasscutter/command/commands/Reload.java
View file @
f35f76f3
...
@@ -15,6 +15,7 @@ public class Reload implements CommandHandler {
...
@@ -15,6 +15,7 @@ public class Reload implements CommandHandler {
public
void
execute
(
GenshinPlayer
sender
,
List
<
String
>
args
)
{
public
void
execute
(
GenshinPlayer
sender
,
List
<
String
>
args
)
{
CommandHandler
.
sendMessage
(
sender
,
"Reloading config."
);
CommandHandler
.
sendMessage
(
sender
,
"Reloading config."
);
Grasscutter
.
loadConfig
();
Grasscutter
.
loadConfig
();
Grasscutter
.
getGameServer
().
getGachaManager
().
load
();
Grasscutter
.
getDispatchServer
().
loadQueries
();
Grasscutter
.
getDispatchServer
().
loadQueries
();
CommandHandler
.
sendMessage
(
sender
,
"Reload complete."
);
CommandHandler
.
sendMessage
(
sender
,
"Reload complete."
);
}
}
...
...
src/main/java/emu/grasscutter/game/gacha/GachaManager.java
View file @
f35f76f3
package
emu.grasscutter.game.gacha
;
package
emu.grasscutter.game.gacha
;
import
java.io.File
;
import
java.io.FileReader
;
import
java.io.FileReader
;
import
java.nio.file.*
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.List
;
...
@@ -8,6 +10,7 @@ import java.util.concurrent.ThreadLocalRandom;
...
@@ -8,6 +10,7 @@ import java.util.concurrent.ThreadLocalRandom;
import
com.google.gson.reflect.TypeToken
;
import
com.google.gson.reflect.TypeToken
;
import
com.sun.nio.file.SensitivityWatchEventModifier
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.GenshinData
;
import
emu.grasscutter.data.GenshinData
;
import
emu.grasscutter.data.def.ItemData
;
import
emu.grasscutter.data.def.ItemData
;
...
@@ -21,16 +24,19 @@ import emu.grasscutter.net.proto.GachaTransferItemOuterClass.GachaTransferItem;
...
@@ -21,16 +24,19 @@ import emu.grasscutter.net.proto.GachaTransferItemOuterClass.GachaTransferItem;
import
emu.grasscutter.net.proto.GetGachaInfoRspOuterClass.GetGachaInfoRsp
;
import
emu.grasscutter.net.proto.GetGachaInfoRspOuterClass.GetGachaInfoRsp
;
import
emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam
;
import
emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam
;
import
emu.grasscutter.server.game.GameServer
;
import
emu.grasscutter.server.game.GameServer
;
import
emu.grasscutter.server.game.GameServerTickEvent
;
import
emu.grasscutter.server.packet.send.PacketDoGachaRsp
;
import
emu.grasscutter.server.packet.send.PacketDoGachaRsp
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectMap
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectMap
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
;
import
it.unimi.dsi.fastutil.ints.IntArrayList
;
import
it.unimi.dsi.fastutil.ints.IntArrayList
;
import
it.unimi.dsi.fastutil.ints.IntList
;
import
it.unimi.dsi.fastutil.ints.IntList
;
import
org.greenrobot.eventbus.Subscribe
;
public
class
GachaManager
{
public
class
GachaManager
{
private
final
GameServer
server
;
private
final
GameServer
server
;
private
final
Int2ObjectMap
<
GachaBanner
>
gachaBanners
;
private
final
Int2ObjectMap
<
GachaBanner
>
gachaBanners
;
private
GetGachaInfoRsp
cachedProto
;
private
GetGachaInfoRsp
cachedProto
;
WatchService
watchService
;
private
int
[]
yellowAvatars
=
new
int
[]
{
1003
,
1016
,
1042
,
1035
,
1041
};
private
int
[]
yellowAvatars
=
new
int
[]
{
1003
,
1016
,
1042
,
1035
,
1041
};
private
int
[]
yellowWeapons
=
new
int
[]
{
11501
,
11502
,
12501
,
12502
,
13502
,
13505
,
14501
,
14502
,
15501
,
15502
};
private
int
[]
yellowWeapons
=
new
int
[]
{
11501
,
11502
,
12501
,
12502
,
13502
,
13505
,
14501
,
14502
,
15501
,
15502
};
...
@@ -45,6 +51,7 @@ public class GachaManager {
...
@@ -45,6 +51,7 @@ public class GachaManager {
this
.
server
=
server
;
this
.
server
=
server
;
this
.
gachaBanners
=
new
Int2ObjectOpenHashMap
<>();
this
.
gachaBanners
=
new
Int2ObjectOpenHashMap
<>();
this
.
load
();
this
.
load
();
this
.
startWatcher
(
server
);
}
}
public
GameServer
getServer
()
{
public
GameServer
getServer
()
{
...
@@ -65,10 +72,17 @@ public class GachaManager {
...
@@ -65,10 +72,17 @@ public class GachaManager {
public
synchronized
void
load
()
{
public
synchronized
void
load
()
{
try
(
FileReader
fileReader
=
new
FileReader
(
Grasscutter
.
getConfig
().
DATA_FOLDER
+
"Banners.json"
))
{
try
(
FileReader
fileReader
=
new
FileReader
(
Grasscutter
.
getConfig
().
DATA_FOLDER
+
"Banners.json"
))
{
getGachaBanners
().
clear
();
List
<
GachaBanner
>
banners
=
Grasscutter
.
getGsonFactory
().
fromJson
(
fileReader
,
TypeToken
.
getParameterized
(
Collection
.
class
,
GachaBanner
.
class
).
getType
());
List
<
GachaBanner
>
banners
=
Grasscutter
.
getGsonFactory
().
fromJson
(
fileReader
,
TypeToken
.
getParameterized
(
Collection
.
class
,
GachaBanner
.
class
).
getType
());
if
(
banners
.
size
()
>
0
)
{
for
(
GachaBanner
banner
:
banners
)
{
for
(
GachaBanner
banner
:
banners
)
{
getGachaBanners
().
put
(
banner
.
getGachaType
(),
banner
);
getGachaBanners
().
put
(
banner
.
getGachaType
(),
banner
);
}
}
Grasscutter
.
getLogger
().
info
(
"Banners successfully loaded."
);
this
.
cachedProto
=
createProto
();
}
else
{
Grasscutter
.
getLogger
().
error
(
"Unable to load banners. Banners size is 0."
);
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// TODO Auto-generated catch block
// TODO Auto-generated catch block
e
.
printStackTrace
();
e
.
printStackTrace
();
...
@@ -267,6 +281,48 @@ public class GachaManager {
...
@@ -267,6 +281,48 @@ public class GachaManager {
player
.
sendPacket
(
new
PacketDoGachaRsp
(
banner
,
list
));
player
.
sendPacket
(
new
PacketDoGachaRsp
(
banner
,
list
));
}
}
private
synchronized
void
startWatcher
(
GameServer
server
)
{
if
(
this
.
watchService
==
null
)
{
try
{
this
.
watchService
=
FileSystems
.
getDefault
().
newWatchService
();
Path
path
=
new
File
(
Grasscutter
.
getConfig
().
DATA_FOLDER
).
toPath
();
path
.
register
(
watchService
,
new
WatchEvent
.
Kind
[]{
StandardWatchEventKinds
.
ENTRY_MODIFY
},
SensitivityWatchEventModifier
.
HIGH
);
server
.
OnGameServerTick
.
register
(
this
);
}
catch
(
Exception
e
)
{
Grasscutter
.
getLogger
().
error
(
"Unable to load the Gacha Manager Watch Service. If ServerOptions.watchGacha is true it will not auto-reload"
);
e
.
printStackTrace
();
}
}
else
{
Grasscutter
.
getLogger
().
error
(
"Cannot reinitialise watcher "
);
}
}
@Subscribe
public
synchronized
void
watchBannerJson
(
GameServerTickEvent
tickEvent
)
{
if
(
Grasscutter
.
getConfig
().
getServerOptions
().
WatchGacha
)
{
try
{
WatchKey
watchKey
=
watchService
.
take
();
for
(
WatchEvent
<?>
event
:
watchKey
.
pollEvents
())
{
final
Path
changed
=
(
Path
)
event
.
context
();
if
(
changed
.
endsWith
(
"Banners.json"
))
{
Grasscutter
.
getLogger
().
info
(
"Change detected with banners.json. Reloading gacha config"
);
this
.
load
();
}
}
boolean
valid
=
watchKey
.
reset
();
if
(!
valid
)
{
Grasscutter
.
getLogger
().
error
(
"Unable to reset Gacha Manager Watch Key. Auto-reload of banners.json will no longer work."
);
return
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
private
synchronized
GetGachaInfoRsp
createProto
()
{
private
synchronized
GetGachaInfoRsp
createProto
()
{
GetGachaInfoRsp
.
Builder
proto
=
GetGachaInfoRsp
.
newBuilder
().
setGachaRandom
(
12345
);
GetGachaInfoRsp
.
Builder
proto
=
GetGachaInfoRsp
.
newBuilder
().
setGachaRandom
(
12345
);
...
...
src/main/java/emu/grasscutter/server/game/GameServer.java
View file @
f35f76f3
...
@@ -19,6 +19,7 @@ import emu.grasscutter.game.shop.ShopManager;
...
@@ -19,6 +19,7 @@ import emu.grasscutter.game.shop.ShopManager;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail
;
import
emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail
;
import
emu.grasscutter.netty.MihoyoKcpServer
;
import
emu.grasscutter.netty.MihoyoKcpServer
;
import
org.greenrobot.eventbus.EventBus
;
public
final
class
GameServer
extends
MihoyoKcpServer
{
public
final
class
GameServer
extends
MihoyoKcpServer
{
private
final
InetSocketAddress
address
;
private
final
InetSocketAddress
address
;
...
@@ -34,9 +35,17 @@ public final class GameServer extends MihoyoKcpServer {
...
@@ -34,9 +35,17 @@ public final class GameServer extends MihoyoKcpServer {
private
final
DungeonManager
dungeonManager
;
private
final
DungeonManager
dungeonManager
;
private
final
CommandMap
commandMap
;
private
final
CommandMap
commandMap
;
public
EventBus
OnGameServerStartFinish
;
public
EventBus
OnGameServerTick
;
public
EventBus
OnGameServerStop
;
public
GameServer
(
InetSocketAddress
address
)
{
public
GameServer
(
InetSocketAddress
address
)
{
super
(
address
);
super
(
address
);
OnGameServerStartFinish
=
EventBus
.
builder
().
throwSubscriberException
(
true
).
logNoSubscriberMessages
(
false
).
build
();
OnGameServerTick
=
EventBus
.
builder
().
throwSubscriberException
(
true
).
logNoSubscriberMessages
(
false
).
build
();
OnGameServerStop
=
EventBus
.
builder
().
throwSubscriberException
(
true
).
logNoSubscriberMessages
(
false
).
build
();
this
.
setServerInitializer
(
new
GameServerInitializer
(
this
));
this
.
setServerInitializer
(
new
GameServerInitializer
(
this
));
this
.
address
=
address
;
this
.
address
=
address
;
this
.
packetHandler
=
new
GameServerPacketHandler
(
PacketHandler
.
class
);
this
.
packetHandler
=
new
GameServerPacketHandler
(
PacketHandler
.
class
);
...
@@ -155,14 +164,20 @@ public final class GameServer extends MihoyoKcpServer {
...
@@ -155,14 +164,20 @@ public final class GameServer extends MihoyoKcpServer {
for
(
GenshinPlayer
player
:
this
.
getPlayers
().
values
())
{
for
(
GenshinPlayer
player
:
this
.
getPlayers
().
values
())
{
player
.
onTick
();
player
.
onTick
();
}
}
OnGameServerTick
.
post
(
new
GameServerTickEvent
());
}
}
@Override
@Override
public
void
onStartFinish
()
{
public
void
onStartFinish
()
{
Grasscutter
.
getLogger
().
info
(
"Game Server started on port "
+
address
.
getPort
());
Grasscutter
.
getLogger
().
info
(
"Game Server started on port "
+
address
.
getPort
());
OnGameServerStartFinish
.
post
(
new
GameServerStartFinishEvent
());
}
}
public
void
onServerShutdown
()
{
public
void
onServerShutdown
()
{
OnGameServerStop
.
post
(
new
GameServerStopEvent
());
// Kick and save all players
// Kick and save all players
List
<
GenshinPlayer
>
list
=
new
ArrayList
<>(
this
.
getPlayers
().
size
());
List
<
GenshinPlayer
>
list
=
new
ArrayList
<>(
this
.
getPlayers
().
size
());
list
.
addAll
(
this
.
getPlayers
().
values
());
list
.
addAll
(
this
.
getPlayers
().
values
());
...
...
src/main/java/emu/grasscutter/server/game/GameServerStartFinishEvent.java
0 → 100644
View file @
f35f76f3
package
emu.grasscutter.server.game
;
public
class
GameServerStartFinishEvent
{
// Placeholder class for now, probably will get used later
}
src/main/java/emu/grasscutter/server/game/GameServerStopEvent.java
0 → 100644
View file @
f35f76f3
package
emu.grasscutter.server.game
;
public
class
GameServerStopEvent
{
// Placeholder class for now, probably will get used later
}
src/main/java/emu/grasscutter/server/game/GameServerTickEvent.java
0 → 100644
View file @
f35f76f3
package
emu.grasscutter.server.game
;
public
class
GameServerTickEvent
{
// Placeholder class for now, probably will get used later
}
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