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
d59799ce
Commit
d59799ce
authored
Apr 20, 2022
by
Benjamin Elsdon
Browse files
Update gradle + Work gacha reload (gs broken atm)
parent
86694158
Changes
6
Hide whitespace changes
Inline
Side-by-side
build.gradle
View file @
d59799ce
...
...
@@ -23,19 +23,21 @@ repositories {
}
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'
co
mp
i
le
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'
co
mp
i
le
group:
'io.netty'
,
name:
'netty-all'
,
version:
'4.1.69.Final'
i
mple
mentation
group:
'org.slf4j'
,
name:
'slf4j-api'
,
version:
'1.7.32'
i
mple
mentation
group:
'ch.qos.logback'
,
name:
'logback-core'
,
version:
'1.2.6'
i
mple
mentation
group:
'ch.qos.logback'
,
name:
'logback-classic'
,
version:
'1.2.6'
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'
co
mp
i
le
group:
'com.google.protobuf'
,
name:
'protobuf-java'
,
version:
'3.18.1'
i
mple
mentation
group:
'com.google.code.gson'
,
name:
'gson'
,
version:
'2.8.8'
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
{
...
...
@@ -51,9 +53,11 @@ jar {
jar
.
baseName
=
'grasscutter'
from
{
configurations
.
compile
.
collect
{
it
.
isDirectory
()
?
it
:
zipTree
(
it
)
}
configurations
.
runtimeClasspath
.
collect
{
it
.
isDirectory
()
?
it
:
zipTree
(
it
)
}
}
duplicatesStrategy
=
DuplicatesStrategy
.
INCLUDE
from
(
'src/main/java'
)
{
include
'*.xml'
}
...
...
gradle/wrapper/gradle-wrapper.properties
View file @
d59799ce
distributionBase
=
GRADLE_USER_HOME
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
zipStorePath
=
wrapper/dists
src/main/java/emu/grasscutter/Config.java
View file @
d59799ce
...
...
@@ -24,7 +24,7 @@ public final class Config {
public
String
DUMPS_FOLDER
=
"./dumps/"
;
public
String
KEY_FOLDER
=
"./keys/"
;
public
boolean
LOG_PACKETS
=
false
;
public
GameRates
Game
=
new
GameRates
();
public
ServerOptions
ServerOptions
=
new
ServerOptions
();
...
...
@@ -51,6 +51,7 @@ public final class Config {
public
int
MaxAvatarsInTeam
=
4
;
public
int
MaxAvatarsInTeamMultiplayer
=
4
;
public
int
MaxEntityLimit
=
1000
;
// Max entity limit per world. // TODO: Enforce later.
public
boolean
WatchGacha
=
false
;
public
int
[]
WelcomeEmotes
=
{
2007
,
1002
,
4010
};
public
String
WelcomeMotd
=
"Welcome to Grasscutter emu"
;
}
...
...
src/main/java/emu/grasscutter/game/gacha/GachaManager.java
View file @
d59799ce
package
emu.grasscutter.game.gacha
;
import
java.io.File
;
import
java.io.FileReader
;
import
java.nio.file.*
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
...
...
@@ -21,17 +23,23 @@ import emu.grasscutter.net.proto.GachaTransferItemOuterClass.GachaTransferItem;
import
emu.grasscutter.net.proto.GetGachaInfoRspOuterClass.GetGachaInfoRsp
;
import
emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam
;
import
emu.grasscutter.server.game.GameServer
;
import
emu.grasscutter.server.game.GameServerTickEvent
;
import
emu.grasscutter.server.packet.send.PacketDoGachaRsp
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectMap
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
;
import
it.unimi.dsi.fastutil.ints.IntArrayList
;
import
it.unimi.dsi.fastutil.ints.IntList
;
import
org.greenrobot.eventbus.Subscribe
;
import
static
java
.
nio
.
file
.
StandardWatchEventKinds
.
ENTRY_MODIFY
;
public
class
GachaManager
{
private
final
GameServer
server
;
private
final
Int2ObjectMap
<
GachaBanner
>
gachaBanners
;
private
GetGachaInfoRsp
cachedProto
;
WatchService
watchService
;
WatchKey
watchKey
;
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
[]
purpleAvatars
=
new
int
[]
{
1006
,
1014
,
1015
,
1020
,
1021
,
1023
,
1024
,
1025
,
1027
,
1031
,
1032
,
1034
,
1036
,
1039
,
1043
,
1044
,
1045
,
1048
,
1053
,
1055
,
1056
,
1064
};
...
...
@@ -40,11 +48,12 @@ public class GachaManager {
private
static
int
starglitterId
=
221
;
private
static
int
stardustId
=
222
;
public
GachaManager
(
GameServer
server
)
{
this
.
server
=
server
;
this
.
gachaBanners
=
new
Int2ObjectOpenHashMap
<>();
this
.
load
();
this
.
startWatcher
(
server
);
}
public
GameServer
getServer
()
{
...
...
@@ -266,6 +275,39 @@ public class GachaManager {
// Packets
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
,
ENTRY_MODIFY
);
watchKey
=
watchService
.
take
();
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
)
{
try
{
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
();
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
private
synchronized
GetGachaInfoRsp
createProto
()
{
GetGachaInfoRsp
.
Builder
proto
=
GetGachaInfoRsp
.
newBuilder
().
setGachaRandom
(
12345
);
...
...
src/main/java/emu/grasscutter/server/game/GameServer.java
View file @
d59799ce
...
...
@@ -3,6 +3,7 @@ package emu.grasscutter.server.game;
import
java.net.InetSocketAddress
;
import
java.util.*
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.CountDownLatch
;
import
emu.grasscutter.GenshinConstants
;
import
emu.grasscutter.Grasscutter
;
...
...
@@ -19,6 +20,8 @@ import emu.grasscutter.game.shop.ShopManager;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail
;
import
emu.grasscutter.netty.MihoyoKcpServer
;
import
jdk.internal.event.Event
;
import
org.greenrobot.eventbus.EventBus
;
public
final
class
GameServer
extends
MihoyoKcpServer
{
private
final
InetSocketAddress
address
;
...
...
@@ -33,9 +36,14 @@ public final class GameServer extends MihoyoKcpServer {
private
final
MultiplayerManager
multiplayerManager
;
private
final
DungeonManager
dungeonManager
;
private
final
CommandMap
commandMap
;
public
EventBus
OnGameServerTick
;
public
EventBus
OnGameServerStop
;
// TODO
public
GameServer
(
InetSocketAddress
address
)
{
super
(
address
);
OnGameServerTick
=
EventBus
.
builder
().
throwSubscriberException
(
true
).
build
();
this
.
setServerInitializer
(
new
GameServerInitializer
(
this
));
this
.
address
=
address
;
...
...
@@ -155,6 +163,8 @@ public final class GameServer extends MihoyoKcpServer {
for
(
GenshinPlayer
player
:
this
.
getPlayers
().
values
())
{
player
.
onTick
();
}
OnGameServerTick
.
post
(
new
GameServerTickEvent
());
}
@Override
...
...
src/main/java/emu/grasscutter/server/game/GameServerTickEvent.java
0 → 100644
View file @
d59799ce
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