commit 39dbaf6651e2b1940d2e4c5ea8c4c08e97c9c19c
parent 61364ab27bfbfe66995c941f97b3277b39316ee3
Author: anon <anon@example.com>
Date: Thu, 5 Nov 2026 05:26:22 +0000
Return to automatic weather after temporary admin changes
Diffstat:
9 files changed, 61 insertions(+), 48 deletions(-)
diff --git a/docs/admin.md b/docs/admin.md
@@ -64,20 +64,21 @@ before destructive queries.
## Weather
-Automatic leaves the client's ordinary environment behavior alone. Clear, Rain,
-Clouds, and Fog and clouds send the original `WeatherControlIIR_t` message to
-connected 14.9.1 clients. The selection is stored in `admin_settings` and restored
-on startup. The movement loop refreshes an override every five seconds. Each
-spatial effect fades in for one second, holds for four, and fades out for one;
-switching or returning to Automatic settles within six seconds. Joining or zoning
-clients receive the override at the next refresh.
+Weather always returns to the client's ordinary environment behavior. Selecting
+Clear, Rain, Clouds, or Fog and clouds starts a five-minute event using the original
+`WeatherControlIIR_t` message. The event is kept in memory and is not restored
+after a server restart. The movement loop refreshes it every five seconds until
+its deadline. Each spatial effect fades in for one second, holds for four, and
+fades out for one. Switching settles within six seconds; ordinary weather resumes
+within six seconds of the deadline. Joining or zoning clients receive the event
+at the next refresh, without extending its deadline.
These are explicit preview presets, not recovered historical weather schedules:
70% intensity, neutral white ambient light, temperature 20, no wind/earthquake,
and fog RGB 160/170/180 with 25% density only in the fog preset. The radius is
1,000,000 units around each recipient's global position. Short effects avoid
-accumulating permanent weather events. Automatic restores the original behavior
-when the last short effect expires.
+accumulating permanent weather events. The normal client weather cycle continues
+underneath; this control does not move its internal schedule to another phase.
Protocol evidence is original `kkr.dll` SHA-256
`a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`:
diff --git a/server/admin_browser_test.go b/server/admin_browser_test.go
@@ -60,6 +60,7 @@ func TestAdminBrowser(t *testing.T) {
t.Fatal(err)
}
+ world.advancePlayerMovement(time.Now().Add(5 * time.Minute))
world.mutex.Lock()
defer world.mutex.Unlock()
if world.weather != 0 {
diff --git a/server/admin_pages.go b/server/admin_pages.go
@@ -68,15 +68,19 @@ func (server *server) controlPage(w http.ResponseWriter, r *http.Request) {
}
fmt.Fprint(w, "<div>Database queries / second<strong id='query-rate'>-</strong></div></div><section><h2>Game time</h2>")
fmt.Fprintf(w, "<p>Game time: %02d:%02d</p><form method='post' action='admin/time'><label>Hour (0-26)<input type='number' name='hour' min='0' max='26' value='%d' required></label><label>Minute<input type='number' name='minute' min='0' max='59' value='%d' required></label><button>Set time</button></form></section>", seconds/3600, seconds/60%60, seconds/3600, seconds/60%60)
- fmt.Fprint(w, "<section><h2>Weather</h2><form method='post' action='admin/weather'><label>Conditions<select name='weather' aria-label='Conditions'>")
- for value, name := range []string{"Automatic", "Clear", "Rain", "Clouds", "Fog and clouds"} {
+ fmt.Fprint(w, "<section><h2>Weather</h2><form method='post' action='admin/weather'><label>Conditions<select name='weather' aria-label='Conditions' required>")
+ if weather == 0 {
+ fmt.Fprint(w, "<option value='' disabled selected>Choose weather</option>")
+ }
+ for index, name := range []string{"Clear", "Rain", "Clouds", "Fog and clouds"} {
+ value := index + 1
selected := ""
if value == weather {
selected = " selected"
}
fmt.Fprintf(w, "<option value='%d'%s>%s</option>", value, selected, name)
}
- fmt.Fprint(w, "</select></label><button>Set weather</button></form><small class='muted'>Transitions take up to 6 seconds.</small></section><script>let sample;async function stats(){try{if(!document.hidden){const response=await fetch('admin/stats');if(!response.ok)throw new Error();const next=await response.json();if(sample)document.querySelector('#query-rate').textContent=((next.queries-sample.queries)/(next.time-sample.time)).toFixed(1);sample=next;}}catch{document.querySelector('#query-rate').textContent='Unavailable';}setTimeout(stats,2000)}stats();</script></main></body></html>")
+ fmt.Fprint(w, "</select></label><button>Set weather</button></form><small class='muted'>5 minutes, then automatic weather resumes.</small></section><script>let sample;async function stats(){try{if(!document.hidden){const response=await fetch('admin/stats');if(!response.ok)throw new Error();const next=await response.json();if(sample)document.querySelector('#query-rate').textContent=((next.queries-sample.queries)/(next.time-sample.time)).toFixed(1);sample=next;}}catch{document.querySelector('#query-rate').textContent='Unavailable';}setTimeout(stats,2000)}stats();</script></main></body></html>")
}
diff --git a/server/admin_weather.go b/server/admin_weather.go
@@ -34,23 +34,15 @@ func weatherPacket(player *character, weather int) []byte {
func (server *server) setWeather(w http.ResponseWriter, r *http.Request) {
weather, err := strconv.Atoi(r.FormValue("weather"))
- if err != nil || weather < 0 || weather > 4 {
+ if err != nil || weather < 1 || weather > 4 {
http.Error(w, "Invalid weather", 400)
return
}
server.updateMutex.Lock()
defer server.updateMutex.Unlock()
server.mutex.Lock()
- db, err := server.database()
- if err == nil {
- _, err = db.Exec("UPDATE admin_settings SET weather=? WHERE id=1", weather)
- }
- if err != nil {
- server.mutex.Unlock()
- http.Error(w, err.Error(), 500)
- return
- }
server.weather = weather
+ server.weatherUntil = time.Now().Add(5 * time.Minute)
server.nextWeather = time.Time{}
updates := make(map[*worldClient][][]byte)
server.weatherUpdates_locked(time.Now(), updates)
@@ -60,6 +52,10 @@ func (server *server) setWeather(w http.ResponseWriter, r *http.Request) {
}
func (server *server) weatherUpdates_locked(now time.Time, updates map[*worldClient][][]byte) {
+ // Let the client's ordinary weather resume when this event ends.
+ if !now.Before(server.weatherUntil) {
+ server.weather = 0
+ }
if server.weather == 0 || now.Before(server.nextWeather) {
return
}
diff --git a/server/admin_weather_test.go b/server/admin_weather_test.go
@@ -5,9 +5,10 @@ import (
"net/url"
"strings"
"testing"
+ "time"
)
-func TestAdminWeatherPersistsAndSendsOriginalTargetPacket(t *testing.T) {
+func TestAdminWeatherSendsOriginalTargetPacket(t *testing.T) {
world := newAdminTestServer(t)
player := &character{id: 1, playfield: 705, position: [3]float32{960, 16.5, 510}, health: 100}
world.characters[1] = player
@@ -18,16 +19,11 @@ func TestAdminWeatherPersistsAndSendsOriginalTargetPacket(t *testing.T) {
cookie := setup.Result().Cookies()[0]
selected := adminRequest(handler, "POST", "/admin/weather", url.Values{"weather": {"2"}}.Encode(), cookie)
- var weather int
- if err := world.db.QueryRow("SELECT weather FROM admin_settings").Scan(&weather); err != nil {
- t.Fatal(err)
- }
invalid := adminRequest(handler, "POST", "/admin/weather", "weather=8", cookie)
- automatic := adminRequest(handler, "POST", "/admin/weather", "weather=0", cookie)
page := adminRequest(handler, "GET", "/admin", "", cookie)
- if selected.Code != 303 || weather != 2 || invalid.Code != 400 || automatic.Code != 303 || world.weather != 0 || len(connection.packets) != 1 {
- t.Fatal("weather state", selected.Code, weather, invalid.Code, len(connection.packets))
+ if selected.Code != 303 || world.weather != 2 || invalid.Code != 400 || len(connection.packets) != 1 {
+ t.Fatal("weather state", selected.Code, world.weather, invalid.Code, len(connection.packets))
}
packet := connection.packets[0]
if len(packet) != 72 || binary.BigEndian.Uint32(packet[16:20]) != 0x0c5a5d6d || packet[41] != 0 || packet[42] != 70 || packet[49] != 255 || packet[50] != 255 || packet[51] != 255 {
@@ -36,12 +32,39 @@ func TestAdminWeatherPersistsAndSendsOriginalTargetPacket(t *testing.T) {
if binary.BigEndian.Uint16(packet[29:31]) != 1 || binary.BigEndian.Uint32(packet[31:35]) != 4 || binary.BigEndian.Uint16(packet[35:37]) != 1 {
t.Fatalf("weather lifetime %x", packet)
}
- if !strings.Contains(page.Body.String(), "value='0' selected>Automatic") {
+ if !strings.Contains(page.Body.String(), "value='2' selected>Rain") || strings.Contains(page.Body.String(), ">Automatic</option>") {
t.Fatal("weather setting not reflected")
}
}
-func TestAdminWeatherRestoresAfterRestart(t *testing.T) {
+func TestAdminWeatherReturnsToAutomatic(t *testing.T) {
+ world := newAdminTestServer(t)
+ world.characters[1] = &character{id: 1, playfield: 705}
+ connection := &combatTestConn{}
+ world.clients[1] = &worldClient{id: 1, ready: true, target: true, conn: connection}
+ handler := world.httpHandler()
+ setup := adminRequest(handler, "POST", "/admin/login", "username=Operator&password=", nil)
+ cookie := setup.Result().Cookies()[0]
+ started := time.Now()
+ selected := adminRequest(handler, "POST", "/admin/weather", "weather=2", cookie)
+ if selected.Code != 303 || world.weatherUntil.Before(started.Add(5*time.Minute)) || world.weatherUntil.After(time.Now().Add(5*time.Minute)) {
+ t.Fatal("weather event duration", selected.Code, world.weatherUntil)
+ }
+
+ // Simulation time, rather than a real wait, crosses the event deadline.
+ world.advancePlayerMovement(world.weatherUntil.Add(-time.Second))
+ if world.weather != 2 || len(connection.packets) != 2 {
+ t.Fatal("weather event ended early", world.weather, len(connection.packets))
+ }
+ world.advancePlayerMovement(world.weatherUntil)
+ world.advancePlayerMovement(world.weatherUntil.Add(time.Hour))
+ page := adminRequest(handler, "GET", "/admin", "", cookie)
+ if world.weather != 0 || len(connection.packets) != 2 || !strings.Contains(page.Body.String(), ">Choose weather</option>") {
+ t.Fatal("weather kept renewing", world.weather, len(connection.packets))
+ }
+}
+
+func TestAdminWeatherDoesNotRestoreAfterRestart(t *testing.T) {
useNPCData(t, testNPCData())
world := newTestServer(t)
handler := world.httpHandler()
@@ -51,7 +74,7 @@ func TestAdminWeatherRestoresAfterRestart(t *testing.T) {
response := adminRequest(handler, "POST", "/admin/weather", "weather=4", cookie)
restarted := newServerForTest(t)
- if response.Code != 303 || restarted.weather != 4 {
- t.Fatal("weather not restored", response.Code, restarted.weather)
+ if response.Code != 303 || restarted.weather != 0 {
+ t.Fatal("temporary weather restored", response.Code, restarted.weather)
}
}
diff --git a/server/state.go b/server/state.go
@@ -153,6 +153,7 @@ type server struct {
chatLogMutex sync.Mutex
browserStreams map[string]*browserStream
weather int
+ weatherUntil time.Time
nextWeather time.Time
gameSeconds float64
clockStarted time.Time
diff --git a/server/world.sql b/server/world.sql
@@ -312,8 +312,3 @@ CREATE TABLE IF NOT EXISTS admin_sessions (
admin_id INTEGER NOT NULL REFERENCES admin_users(id) ON DELETE CASCADE,
expires_at INTEGER NOT NULL
);
-CREATE TABLE IF NOT EXISTS admin_settings (
- id INTEGER PRIMARY KEY CHECK (id = 1),
- weather INTEGER NOT NULL DEFAULT 0 CHECK (weather BETWEEN 0 AND 4)
-);
-INSERT OR IGNORE INTO admin_settings (id) VALUES (1);
diff --git a/server/world_store.go b/server/world_store.go
@@ -170,9 +170,6 @@ func (server *server) loadNPCs() (bool, error) {
if err != nil {
return false, err
}
- if err := db.QueryRow("SELECT weather FROM admin_settings WHERE id=1").Scan(&server.weather); err != nil {
- return false, err
- }
var initialized bool
var started string
if err := db.QueryRow("SELECT npcs_initialized, last_item_id, last_character_id, last_npc_id, game_seconds, clock_started FROM world WHERE id = 1").Scan(
diff --git a/tools/client/test_admin.mjs b/tools/client/test_admin.mjs
@@ -90,12 +90,7 @@ try {
await game.wait('weather frames ' + name, state => state.frame > frame + 150);
await client.screenshot({path: output + '/weather-' + name + '.png'});
}
- await page.getByLabel('Conditions', {exact: true}).selectOption('0');
- await page.getByRole('button', {name: 'Set weather', exact: true}).click();
- const automaticAt = Date.now(), automaticSequence = game.sequence;
- await game.wait('automatic weather resumes', () => Date.now() - automaticAt >= 6500);
- assert(!game.events.some(event => event.sequence > automaticSequence && event.opcode === '0c5a5d6d' && event.direction === 'framereceived'));
- await client.screenshot({path: output + '/weather-automatic.png'});
+ assert.equal(await page.getByLabel('Conditions', {exact: true}).locator('option', {hasText: 'Automatic'}).count(), 0);
await game.save(output + '/game');
assert(mapResponses.every(response => response.npcs.length <= 500 && response.warps.length <= 500));