commit 2d2525eb5285b5da9dc13e52066ceb99f550bb9b
parent 1ac76cb99e9f03187ee856ccc36a3313edc30547
Author: anon <anon@example.com>
Date: Wed, 21 Oct 2026 05:40:45 +0000
Keep protocol and movement traces out of the console
Diffstat:
7 files changed, 48 insertions(+), 12 deletions(-)
diff --git a/DEVELOPERS.md b/DEVELOPERS.md
@@ -20,6 +20,8 @@ Distribute `ao-server` by itself (or the corresponding Windows binary). It can
run from an empty directory; static resources are served directly from the
binary. Saved characters remain in `data/players/` and certificates in
`data/https/`. Server logs go to `logs/server.log` and profiles to `logs/profiles/`.
+Packet, movement and HTTP request traces stay in `logs/server.log`; the terminal
+shows startup, connections and errors.
Back up `data/` when moving servers. Paths are relative to the working directory.
Each `data/players/<id>/` directory contains `player.yaml` for identity,
diff --git a/server/http.go b/server/http.go
@@ -52,7 +52,7 @@ func (server *server) httpHandler() http.Handler {
mux.HandleFunc("POST /teleport/{character}", server.teleportPlayer)
// Keep the original launcher's dimension list available.
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
- log.Printf("HTTP %s %s", r.Method, r.URL.Path)
+ traceLog.Printf("HTTP %s %s", r.Method, r.URL.Path)
if strings.HasSuffix(r.URL.Path, "dimensions.txt") {
server.dimensionList(w, r)
return
diff --git a/server/http_test.go b/server/http_test.go
@@ -2,12 +2,40 @@ package main
import (
"ao/server/assets"
+ "bytes"
+ "log"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
+func TestHTTPHandlerKeepsRequestTraceOutOfConsole(t *testing.T) {
+ world := &server{baseURL: "/"}
+ handler := world.httpHandler()
+ var console, trace bytes.Buffer
+ previousConsole, previousTrace := log.Writer(), traceLog.Writer()
+ log.SetOutput(&console)
+ traceLog.SetOutput(&trace)
+ t.Cleanup(func() {
+ log.SetOutput(previousConsole)
+ traceLog.SetOutput(previousTrace)
+ })
+
+ response := httptest.NewRecorder()
+ handler.ServeHTTP(response, httptest.NewRequest("GET", "/missing", nil))
+
+ if response.Code != http.StatusNotFound {
+ t.Fatalf("unknown path: HTTP %d", response.Code)
+ }
+ if console.Len() != 0 {
+ t.Fatalf("request trace reached console: %s", &console)
+ }
+ if !strings.Contains(trace.String(), "HTTP GET /missing") {
+ t.Fatalf("missing request trace: %s", &trace)
+ }
+}
+
func TestHTTPHandlerMountsGameAndControls(t *testing.T) {
for _, baseURL := range []string{"/", "/share/demo/"} {
t.Run(baseURL, func(t *testing.T) {
diff --git a/server/main.go b/server/main.go
@@ -18,6 +18,9 @@ import (
"time"
)
+// Protocol and movement traces are written only to the server log file.
+var traceLog = log.New(io.Discard, "", log.LstdFlags)
+
func main() {
loginPort := flag.Int("login-port", 7500, "login port")
worldPort := flag.Int("world-port", 7501, "world port")
@@ -36,7 +39,7 @@ func main() {
if *worldPort == 65535 || *worldPort+1 == *loginPort || *worldPort+1 == *httpPort || *worldPort+1 == 8443 {
log.Fatal("the port immediately after the world port must be available for chat")
}
- // Keep server logs on disk as well as in the launching terminal.
+ // Keep operational logs in the terminal and file, and detailed traces in the file.
if err := os.MkdirAll("logs", 0755); err != nil {
log.Fatal(err)
}
@@ -46,6 +49,7 @@ func main() {
}
defer logFile.Close()
log.SetOutput(io.MultiWriter(os.Stderr, logFile))
+ traceLog.SetOutput(logFile)
if err := prepareHTTPS(); err != nil {
log.Fatal(err)
@@ -143,7 +147,7 @@ func (server *server) serveLogin(conn net.Conn) error {
return err
}
opcode := binary.BigEndian.Uint32(packet[16:20])
- log.Printf("C2S opcode=0x%02x length=%d", opcode, len(packet))
+ traceLog.Printf("C2S opcode=0x%02x length=%d", opcode, len(packet))
var response []byte
switch opcode {
case 0x22:
@@ -254,7 +258,7 @@ func (server *server) serveWorldClient(client *worldClient) error {
}
return err
}
- log.Printf("World C2S: %x", packet)
+ traceLog.Printf("World C2S: %x", packet)
var response []byte
switch binary.BigEndian.Uint16(packet[2:4]) {
case 1:
@@ -307,7 +311,7 @@ func (server *server) serveWorldClient(client *worldClient) error {
playfield := character.playfield
server.mutex.Unlock()
for _, update := range updates {
- log.Printf("World S2C: %x", update)
+ traceLog.Printf("World S2C: %x", update)
if err := client.send(update); err != nil {
server.npcUpdateMutex.RUnlock()
return err
@@ -442,11 +446,11 @@ func (server *server) serveWorldClient(client *worldClient) error {
case 22, 23:
character.running = binary.BigEndian.Uint32(body[16:20]) == 23
}
- log.Printf("Character %d action=%d position=%v", character.id, binary.BigEndian.Uint32(body[16:20]), character.position)
+ traceLog.Printf("Character %d action=%d position=%v", character.id, binary.BigEndian.Uint32(body[16:20]), character.position)
destination := server.zoneDestination_locked(character, client)
if destination != nil {
server.mutex.Unlock()
- log.Printf("Character %d zoning %d -> %d", character.id, playfield, destination.Playfield)
+ traceLog.Printf("Character %d zoning %d -> %d", character.id, playfield, destination.Playfield)
if err := server.updateUser(*destination); err != nil {
return err
}
diff --git a/tools/client/sweep_browser.py b/tools/client/sweep_browser.py
@@ -118,7 +118,7 @@ def tick(message):
return {'action': 'unload'}
disconnect_started = None
queue.pop(0)
- log_start = (output / 'server.log').stat().st_size
+ log_start = (fixture / 'logs/server.log').stat().st_size
request('/teleport/73', {'playfield': zone['id']})
request('/time', {'hour': 13, 'minute': 30})
active = dict(zone, phase=phase, started=time.time(), status='loading',
@@ -144,7 +144,7 @@ def tick(message):
return {'action': 'finish', 'id': active['id'], 'status': active['status']}
if 'ready_time' not in active and player['connected'] and player['playfield'] == active['id']:
- with (output / 'server.log').open('rb') as log:
+ with (fixture / 'logs/server.log').open('rb') as log:
log.seek(active['server_log_start'])
received = log.read()
if re.search(rb'World C2S: dfdf000a[0-9a-f]{24}570c20390000c3500000004901', received):
diff --git a/tools/client/sweep_playfields.py b/tools/client/sweep_playfields.py
@@ -121,7 +121,7 @@ def run_zone(zone, phase):
while json.loads(request('/map-players'))['players'][0]['connected']:
assert time.monotonic() < deadline, 'server did not observe client disconnect'
time.sleep(.1)
- server_log_start = (output / 'server.log').stat().st_size
+ server_log_start = (fixture / 'logs/server.log').stat().st_size
request('/teleport/73', {'playfield': zone['id']})
request('/time', {'hour': 13, 'minute': 30})
started = time.monotonic()
@@ -152,7 +152,7 @@ def run_zone(zone, phase):
break
if player['playfield'] == zone['id'] and player['connected'] and ready is None:
# Connection registration precedes scene loading; wait for CharacterReady.
- with (output / 'server.log').open('rb') as log:
+ with (fixture / 'logs/server.log').open('rb') as log:
log.seek(server_log_start)
received = log.read()
if re.search(rb'World C2S: dfdf000a[0-9a-f]{24}570c20390000c3500000004901', received):
diff --git a/tools/client/verify_linux_game.py b/tools/client/verify_linux_game.py
@@ -32,6 +32,8 @@ def run_linux():
with socket.socket() as connection:
assert connection.connect_ex(('127.0.0.1', port)) != 0, 'Server port already in use: %d' % port
+ (fixture / 'logs').mkdir(exist_ok=True)
+ (fixture / 'logs/server.log').write_text('')
with (output / 'server.log').open('w') as log:
server = subprocess.Popen([str(fixture / 'server')], cwd=fixture,
stdout=log, stderr=subprocess.STDOUT)
@@ -117,7 +119,7 @@ def run_windows():
log = (output / 'client.log').read_text()
assert 'Smoke inputs complete at frame 700.' in log, log[-4000:]
positions = re.findall(r'Character 73 action=([12]) position=\[([^]]+)\]',
- (output / 'server.log').read_text())
+ (fixture / 'logs/server.log').read_text())
starts = [position for action, position in positions if action == '1']
stops = [position for action, position in positions if action == '2']
assert starts and stops and starts[0] != stops[-1], positions