Skip to content

Commit

Permalink
server/conf.go: Replace join/quit messages with bool to enable/disabl…
Browse files Browse the repository at this point in the history
…e default join/quit messages.
  • Loading branch information
Sandertv committed Dec 21, 2024
1 parent b41abec commit 16cdb23
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 40 deletions.
16 changes: 6 additions & 10 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@
# The message shown to players when the server is shutting down. The message may be left empty to direct
# players to the server list directly.
ShutdownMessage = "Server closed."
# AuthEnabled controls whether or not players must be connected to Xbox Live in order to join the server.
# AuthEnabled controls whether players must be connected to Xbox Live in order to join the server.
AuthEnabled = true
# JoinMessage is the message that appears when a player joins the server. Leave this empty to disable it.
# %v is the placeholder for the username of the player. Set this to "" to disable.
JoinMessage = "%v has joined the game"
# QuitMessage is the message that appears when a player leaves the server. Leave this empty to disable it.
# %v is the placeholder for the username of the player. Set this to "" to disable.
QuitMessage = "%v has left the game"
# DisableJoinQuitMessages specifies if join/quit messages should be broadcast when players join the server.
DisableJoinQuitMessages = false

[World]
# The folder that the world files (will) reside in, relative to the working directory. If not currently
# present, the folder will be made.
Folder = "world"
# Whether or not the worlds' data will be saved and loaded. If true, the server will use the
# Whether the worlds' data will be saved and loaded. If true, the server will use the
# default LevelDB data provider and if false, an empty provider will be used. To use your
# own provider, turn this value to false, as you will still be able to pass your own provider.
SaveData = true
Expand All @@ -36,7 +32,7 @@
# The maximum chunk radius that players may set in their settings. If they try to set it above this number,
# it will be capped and set to the max.
MaximumChunkRadius = 32
# Whether or not a player's data will be saved and loaded. If true, the server will use the
# Whether a player's data will be saved and loaded. If true, the server will use the
# default LevelDB data provider and if false, an empty provider will be used. To use your
# own provider, turn this value to false, as you will still be able to pass your own provider.
SaveData = true
Expand All @@ -49,5 +45,5 @@
AutoBuildPack = true
# Folder configures the directory used by the server to load resource packs.
Folder = "resources"
# Required configures whether or not the server will require players to have a resource pack to join.
# Required configures whether the server will require players to have a resource pack to join.
Required = true
28 changes: 10 additions & 18 deletions server/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ type Config struct {
// MaxChunkRadius is the maximum view distance that each player may have,
// measured in chunks. A chunk radius generally leads to more memory usage.
MaxChunkRadius int
// JoinMessage, QuitMessage and ShutdownMessage are the messages to send for
// when a player joins or quits the server and when the server shuts down,
// kicking all online players. JoinMessage and QuitMessage may have a '%v'
// argument, which will be replaced with the name of the player joining or
// quitting.
JoinMessage, QuitMessage, ShutdownMessage string
// DisableJoinQuitMessages specifies if join/quit messages should be
// broadcast when players join the server.
DisableJoinQuitMessages bool
// ShutdownMessage is the message sent when the server shuts down, kicking
// all online players.
ShutdownMessage string
// StatusProvider provides the server status shown to players in the server
// list. By default, StatusProvider will show the server name from the Name
// field and the current player count and maximum players.
Expand Down Expand Up @@ -191,14 +191,9 @@ type UserConfig struct {
// AuthEnabled controls whether players must be connected to Xbox Live
// in order to join the server.
AuthEnabled bool
// JoinMessage is the message that appears when a player joins the
// server. Leave this empty to disable it. %v is the placeholder for the
// username of the player
JoinMessage string
// QuitMessage is the message that appears when a player leaves the
// server. Leave this empty to disable it. %v is the placeholder for the
// username of the player
QuitMessage string
// DisableJoinQuitMessages specifies if the default join/quit messages
// should be broadcast when players join/quit the server.
DisableJoinQuitMessages bool
}
World struct {
// SaveData controls whether a world's data will be saved and loaded.
Expand Down Expand Up @@ -254,8 +249,7 @@ func (uc UserConfig) Config(log *slog.Logger) (Config, error) {
AuthDisabled: !uc.Server.AuthEnabled,
MaxPlayers: uc.Players.MaxCount,
MaxChunkRadius: uc.Players.MaximumChunkRadius,
JoinMessage: uc.Server.JoinMessage,
QuitMessage: uc.Server.QuitMessage,
DisableJoinQuitMessages: uc.Server.DisableJoinQuitMessages,
ShutdownMessage: uc.Server.ShutdownMessage,
DisableResourceBuilding: !uc.Resources.AutoBuildPack,
}
Expand Down Expand Up @@ -319,8 +313,6 @@ func DefaultConfig() UserConfig {
c.Server.Name = "Dragonfly Server"
c.Server.ShutdownMessage = "Server closed."
c.Server.AuthEnabled = true
c.Server.JoinMessage = "%v has joined the game"
c.Server.QuitMessage = "%v has left the game"
c.World.SaveData = true
c.World.Folder = "world"
c.Players.MaximumChunkRadius = 32
Expand Down
9 changes: 4 additions & 5 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,11 +523,10 @@ func (srv *Server) createPlayer(id uuid.UUID, conn session.Conn, conf player.Con
srv.pwg.Add(1)

s := session.Config{
Log: srv.conf.Log,
MaxChunkRadius: srv.conf.MaxChunkRadius,
JoinMessage: srv.conf.JoinMessage,
QuitMessage: srv.conf.QuitMessage,
HandleStop: srv.handleSessionClose,
Log: srv.conf.Log,
MaxChunkRadius: srv.conf.MaxChunkRadius,
DisableJoinQuitMessages: srv.conf.DisableJoinQuitMessages,
HandleStop: srv.handleSessionClose,
}.New(conn)

conf.Name = conn.IdentityData().DisplayName
Expand Down
10 changes: 3 additions & 7 deletions server/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ type Session struct {
openChunkTransactions []map[uint64]struct{}
invOpened bool

joinMessage, quitMessage string

closeBackground chan struct{}
}

Expand Down Expand Up @@ -132,7 +130,7 @@ type Config struct {

MaxChunkRadius int

JoinMessage, QuitMessage string
DisableJoinQuitMessages bool

HandleStop func(*world.Tx, Controllable)
}
Expand Down Expand Up @@ -162,8 +160,6 @@ func (conf Config) New(conn Conn) *Session {
conn: conn,
currentEntityRuntimeID: 1,
heldSlot: new(uint32),
joinMessage: conf.JoinMessage,
quitMessage: conf.QuitMessage,
recipes: make(map[uint32]recipe.Recipe),
conf: conf,
}
Expand Down Expand Up @@ -223,7 +219,7 @@ func (s *Session) Spawn(c Controllable, tx *world.Tx) {
s.sendInv(s.armour.Inventory(), protocol.WindowIDArmour)

chat.Global.Subscribe(c)
if s.joinMessage != "" {
if !s.conf.DisableJoinQuitMessages {
chat.Global.Writet(chat.MessageJoin, s.conn.IdentityData().DisplayName)
}

Expand Down Expand Up @@ -254,7 +250,7 @@ func (s *Session) close(tx *world.Tx, c Controllable) {

s.chunkLoader.Close(tx)

if s.quitMessage != "" {
if !s.conf.DisableJoinQuitMessages {
chat.Global.Writet(chat.MessageQuit, s.conn.IdentityData().DisplayName)
}
chat.Global.Unsubscribe(c)
Expand Down

0 comments on commit 16cdb23

Please sign in to comment.