This repository was archived by the owner on Nov 28, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDockyardServer.kt
More file actions
162 lines (138 loc) · 7.09 KB
/
DockyardServer.kt
File metadata and controls
162 lines (138 loc) · 7.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package io.github.dockyardmc
import io.github.dockyardmc.utils.InstrumentationUtils
import cz.lukynka.prettylog.LogType
import cz.lukynka.prettylog.log
import io.github.dockyardmc.config.Config
import io.github.dockyardmc.config.ConfigManager
import io.github.dockyardmc.events.Events
import io.github.dockyardmc.events.ServerFinishLoadEvent
import io.github.dockyardmc.events.WorldFinishLoadingEvent
import io.github.dockyardmc.implementations.block.DefaultBlockHandlers
import io.github.dockyardmc.implementations.commands.DefaultCommands
import io.github.dockyardmc.npc.NpcCommand
import io.github.dockyardmc.profiler.profiler
import io.github.dockyardmc.protocol.NetworkCompression
import io.github.dockyardmc.protocol.packets.registry.ClientPacketRegistry
import io.github.dockyardmc.protocol.packets.registry.ServerPacketRegistry
import io.github.dockyardmc.registry.MinecraftVersions
import io.github.dockyardmc.registry.RegistryManager
import io.github.dockyardmc.registry.registries.*
import io.github.dockyardmc.registry.registries.tags.*
import io.github.dockyardmc.scheduler.GlobalScheduler
import io.github.dockyardmc.server.NettyServer
import io.github.dockyardmc.server.PlayerKeepAliveTimer
import io.github.dockyardmc.server.ServerTickManager
import io.github.dockyardmc.spark.SparkDockyardIntegration
import io.github.dockyardmc.utils.Resources
import io.github.dockyardmc.utils.UpdateChecker
import io.github.dockyardmc.world.WorldManager
class DockyardServer(configBuilder: Config.() -> Unit) {
val config: Config = Config()
val nettyServer: NettyServer = NettyServer(this)
val serverTickManager: ServerTickManager = ServerTickManager()
val playerKeepAliveTimer: PlayerKeepAliveTimer = PlayerKeepAliveTimer()
init {
profiler("Server Load") {
instance = this
configBuilder.invoke(config)
profiler("Register packets") {
ServerPacketRegistry.load()
ClientPacketRegistry.load()
}
profiler("Load Registries") {
SoundRegistry.initialize(RegistryManager.getStreamFromPath("registry/sound_registry.json.gz"))
RegistryManager.register(AttributeRegistry)
RegistryManager.register(BlockRegistry)
RegistryManager.register(EntityTypeRegistry)
RegistryManager.register(DimensionTypeRegistry)
RegistryManager.register(BannerPatternRegistry)
RegistryManager.register(DamageTypeRegistry)
RegistryManager.register(JukeboxSongRegistry)
RegistryManager.register(TrimMaterialRegistry)
RegistryManager.register(TrimPatternRegistry)
RegistryManager.register(ChatTypeRegistry)
RegistryManager.register(ParticleRegistry)
RegistryManager.register(PaintingVariantRegistry)
RegistryManager.register(PotionEffectRegistry)
RegistryManager.register(BiomeRegistry)
RegistryManager.register(ItemRegistry)
RegistryManager.register(FluidRegistry)
RegistryManager.register(PotionTypeRegistry)
RegistryManager.register(WolfVariantRegistry)
RegistryManager.register(WolfSoundVariantRegistry)
RegistryManager.register(CatVariantRegistry)
RegistryManager.register(CowVariantRegistry)
RegistryManager.register(PigVariantRegistry)
RegistryManager.register(FrogVariantRegistry)
RegistryManager.register(ChickenVariantRegistry)
RegistryManager.register(ItemTagRegistry)
RegistryManager.register(BlockTagRegistry)
RegistryManager.register(EntityTypeTagRegistry)
RegistryManager.register(FluidTagRegistry)
RegistryManager.register(ItemTagRegistry)
RegistryManager.register(BiomeTagRegistry)
RegistryManager.register(DialogTypeRegistry)
RegistryManager.register(DialogBodyTypeRegistry)
RegistryManager.register(DialogRegistry)
RegistryManager.register(DialogInputTypeRegistry)
RegistryManager.register(DialogActionTypeRegistry)
}
profiler("Default Implementations") {
if (ConfigManager.config.implementationConfig.defaultCommands) DefaultCommands().register()
if (ConfigManager.config.implementationConfig.npcCommand) NpcCommand()
if (ConfigManager.config.implementationConfig.spark) SparkDockyardIntegration().initialize()
if (ConfigManager.config.implementationConfig.applyBlockPlacementRules) DefaultBlockHandlers().register()
}
NetworkCompression.COMPRESSION_THRESHOLD = ConfigManager.config.networkCompressionThreshold
WorldManager.loadDefaultWorld()
Events.dispatch(ServerFinishLoadEvent(this))
if (ConfigManager.config.updateChecker) UpdateChecker()
if (InstrumentationUtils.isDebuggerAttached()) {
profiler("Setup hot reload detection") {
InstrumentationUtils.setupHotReloadDetection()
}
}
}
}
val ip get() = config.ip
val port get() = config.port
fun start() {
versionInfo = Resources.getDockyardVersion()
log("Starting DockyardMC Version ${versionInfo.dockyardVersion} (${versionInfo.gitCommit}@${versionInfo.gitBranch} for MC ${minecraftVersion.versionName})", LogType.RUNTIME)
log("DockyardMC is still under heavy development. Things will break (I warned you)", LogType.WARNING)
profiler("Start TCP socket") {
serverTickManager.start()
playerKeepAliveTimer.start()
nettyServer.start()
}
Events.dispatch(WorldFinishLoadingEvent(WorldManager.mainWorld))
}
companion object {
lateinit var versionInfo: Resources.DockyardVersionInfo
lateinit var instance: DockyardServer
val minecraftVersion = MinecraftVersions.v1_21_6
var allowAnyVersion: Boolean = false
val scheduler = GlobalScheduler("main_scheduler")
var tickRate: Int = 20
val debug get() = ConfigManager.config.debug
var mutePacketLogs = mutableListOf(
"ClientboundSystemChatMessagePacket",
"ServerboundSetPlayerPositionPacket",
"ServerboundSetPlayerPositionAndRotationPacket",
"ServerboundSetPlayerRotationPacket",
"ClientboundKeepAlivePacket",
"ServerboundKeepAlivePacket",
"ClientboundUpdateEntityPositionPacket",
"ClientboundUpdateEntityPositionAndRotationPacket",
"ClientboundUpdateEntityRotationPacket",
"ClientboundSetHeadYawPacket",
"ClientboundSendParticlePacket",
"ClientboundUpdateScorePacket",
"ClientboundChunkDataPacket",
"ServerboundClientTickEndPacket",
"ClientboundEntityTeleportPacket",
"ClientboundUnloadChunkPacket",
"ClientboundTrackedWaypointPacket"
)
}
}