M2.6: server rules (PvP, raiding, locks and friends, death penalty, difficulty, wolf grace), chat, admin commands, server console
This commit is contained in:
@@ -32,7 +32,7 @@ signal clock(day: int, time: float) ## the server's time of day
|
||||
const Identity = preload("res://scripts/net/identity.gd")
|
||||
const ServerConfig = preload("res://scripts/net/server_config.gd")
|
||||
|
||||
const PROTOCOL := 5 ## 3: shared world (M2.3); 4: the server decides (M2.4); 5: wildlife (M2.5)
|
||||
const PROTOCOL := 6 ## 3: shared world; 4: the server decides; 5: wildlife; 6: rules and chat (M2.6)
|
||||
const DEFAULT_PORT := 24242
|
||||
const HANDSHAKE_TIMEOUT := 10.0
|
||||
const JOIN_TIMEOUT := 20.0 ## includes the server building its terrain on first join
|
||||
@@ -272,6 +272,45 @@ func _tick_clock(delta: float) -> void:
|
||||
for peer in players:
|
||||
_s2c_clock.rpc_id(peer, _world.day_night.day, _world.day_night.time)
|
||||
|
||||
# --- admin (chat.gd) ---------------------------------------------------------------
|
||||
|
||||
signal rules_changed ## clients: the server's rules changed (/set)
|
||||
|
||||
## The peer of the player online called `n` (any case), or 0.
|
||||
func peer_by_name(n: String) -> int:
|
||||
for peer in players:
|
||||
if String(players[peer].name).to_lower() == n.strip_edges().to_lower():
|
||||
return peer
|
||||
return 0
|
||||
|
||||
## Disconnects a player with a reason (their title screen shows it).
|
||||
func kick(peer: int, reason: String) -> void:
|
||||
if players.has(peer):
|
||||
_reject(peer, reason)
|
||||
|
||||
## Everyone gets the rules again (after /set) and the weather override.
|
||||
func broadcast_rules() -> void:
|
||||
_world.apply_rules()
|
||||
for peer in players:
|
||||
_s2c_rules.rpc_id(peer, config.public_info())
|
||||
|
||||
func set_weather(state: String) -> void:
|
||||
_world.weather.force(state)
|
||||
for peer in players:
|
||||
_s2c_weather.rpc_id(peer, state)
|
||||
|
||||
@rpc("authority", "call_remote", "reliable")
|
||||
func _s2c_rules(info: Dictionary) -> void:
|
||||
server_info = info
|
||||
rules_changed.emit()
|
||||
|
||||
@rpc("authority", "call_remote", "reliable")
|
||||
func _s2c_weather(state: String) -> void:
|
||||
world_info.weather = state
|
||||
weather_changed.emit(state)
|
||||
|
||||
signal weather_changed(state: String)
|
||||
|
||||
## Everyone gets the clock now (after a night's sleep, an admin's /time).
|
||||
func push_clock() -> void:
|
||||
_clock_left = CLOCK_INTERVAL
|
||||
@@ -454,7 +493,8 @@ func _c2s_proof(sig: PackedByteArray) -> void:
|
||||
players.size(), int(config.v("max_players"))])
|
||||
# (The world's own seed: an existing world keeps the seed it was made with.)
|
||||
var world := {"seed": int(_terrain.noise_seed), "worldlet": String(config.v("worldlet")), "spawn": start, "yaw": yaw,
|
||||
"island_spawn": _spawn, "day": _world.day_night.day, "time": _world.day_night.time, "server_time": server_time}
|
||||
"island_spawn": _spawn, "day": _world.day_night.day, "time": _world.day_night.time, "server_time": server_time,
|
||||
"weather": _world.weather.override}
|
||||
_s2c_welcome.rpc_id(peer, {"you": peer, "server": config.public_info(), "players": players, "world": world})
|
||||
for other in players:
|
||||
if other != peer:
|
||||
|
||||
Reference in New Issue
Block a user