Skip to content

Commit 67aeae3

Browse files
committed
reduce LLM verbosity
1 parent b56d0ca commit 67aeae3

28 files changed

Lines changed: 88 additions & 380 deletions

‎Dockerfile‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /c4gateway ./cmd/c4gate
77

88
FROM alpine:3.20
99
COPY --from=build /c4gateway /usr/local/bin/c4gateway
10-
# Game files players download after registering (-patch-dir).
1110
COPY patched/ /patched/
1211
ENV C4GW_PATCH_DIR=/patched
1312
# for -capture; a volume mounted here starts out owned by nobody

‎docker-compose.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ services:
5252
C4GW_RAW_DUMP: "/logs/raw"
5353
volumes:
5454
- ./logs:/logs
55-
- ./patched:/patched:ro # game files players download after registering
55+
- ./patched:/patched:ro

‎gateway/cmd/c4assets/main.go‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ func run(data, out string) error {
200200
return fmt.Errorf("online menu art: %w", err)
201201
}
202202

203-
// Online scenarios are the .sco files.
204203
scos, err := filepath.Glob(filepath.Join(data, "Scenarios", "*.sco"))
205204
if err != nil {
206205
return err
@@ -271,7 +270,6 @@ func run(data, out string) error {
271270
return nil
272271
}
273272

274-
// Slug must match web.slug: lowercase, spaces to hyphens.
275273
func Slug(name string) string {
276274
return strings.ReplaceAll(strings.ToLower(name), " ", "-")
277275
}

‎gateway/internal/gateway/admin.go‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import (
88

99
// AdminHandler serves read-only debug endpoints. Bind it to localhost.
1010
//
11-
// /debug/stats command and route counters, open questions, unmatched statements
11+
// /debug/stats command and route counters, unmatched statements
1212
// /debug/unmatched just the unmatched statements
13-
// /debug/questions just the open-question hits
1413
// /debug/sessions connected clients
1514
// /debug/routes every accepted statement shape
1615
func (g *Gateway) AdminHandler() http.Handler {
@@ -36,9 +35,6 @@ func (g *Gateway) AdminHandler() http.Handler {
3635
mux.HandleFunc("/debug/unmatched", func(w http.ResponseWriter, r *http.Request) {
3736
writeJSON(w, g.rec.Snapshot()["unmatched"])
3837
})
39-
mux.HandleFunc("/debug/questions", func(w http.ResponseWriter, r *http.Request) {
40-
writeJSON(w, g.rec.Snapshot()["open_questions"])
41-
})
4238
mux.HandleFunc("/debug/sessions", func(w http.ResponseWriter, r *http.Request) {
4339
sessions := g.Sessions()
4440
sort.Slice(sessions, func(i, j int) bool { return sessions[i].ID < sessions[j].ID })
@@ -49,11 +45,10 @@ func (g *Gateway) AdminHandler() http.Handler {
4945
Name string `json:"name"`
5046
Template string `json:"template,omitempty"`
5147
Regexp string `json:"regexp"`
52-
Question string `json:"open_question,omitempty"`
5348
}
5449
out := make([]info, len(g.routes))
5550
for i, rt := range g.routes {
56-
out[i] = info{rt.name, rt.tmpl, rt.re.String(), rt.question}
51+
out[i] = info{rt.name, rt.tmpl, rt.re.String()}
5752
}
5853
writeJSON(w, out)
5954
})

‎gateway/internal/gateway/driver.go‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ func hLiteralSelect(ctx context.Context, c *call) (*result, error) {
212212
return c.queryCols(ctx, cols, c.sql)
213213
}
214214

215-
// ---- Screenshot blob writes ----
216-
//
217215
// The game writes screenshots by editing the recordset returned by
218216
// ScreenShot/*/GetRecord. How the ODBC driver turns that into SQL is not known
219217
// yet, so this route accepts the likely shape (UPDATE ... SET screenshot=<blob>
@@ -227,10 +225,9 @@ var andSplitRE = regexp.MustCompile(`(?i)\s+and\s+`)
227225

228226
func blobRoutes() []*route {
229227
return []*route{{
230-
name: "ScreenShot/*/blob write (driver generated)",
231-
re: blobUpdateRE,
232-
question: "README §10: how the screenshot blob is written; this is a guessed shape, confirm it and the image format",
233-
fn: hBlobWrite,
228+
name: "ScreenShot/*/blob write (driver generated)",
229+
re: blobUpdateRE,
230+
fn: hBlobWrite,
234231
}}
235232
}
236233

‎gateway/internal/gateway/handlers.go‎

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
func now32() int64 { return time.Now().Unix() & 0x7fffffff }
1717

18-
// query runs a backend SELECT and converts rows to the given columns. Integer
18+
// queryCols runs a backend SELECT and converts rows to the given columns. Integer
1919
// columns are clamped to 32 bits: the game aborts on 64-bit values.
2020
func (c *call) queryCols(ctx context.Context, cols []Column, q string, args ...any) (*result, error) {
2121
rs, err := c.g.db.QueryContext(ctx, q, args...)
@@ -93,8 +93,6 @@ func (c *call) backendErr(err error) error {
9393
func (c *call) uid() int64 { return int64(c.s.acct.UserID) }
9494
func (c *call) c4id() int64 { return int64(c.s.acct.C4ID) }
9595

96-
// ---- Login ----
97-
9896
func hStatus(ctx context.Context, c *call) (*result, error) {
9997
res, err := c.query(ctx, "SELECT version, status, message FROM c4_status LIMIT 1")
10098
if err != nil {
@@ -164,8 +162,6 @@ func hChecksums(ctx context.Context, c *call) (*result, error) {
164162
return res, err
165163
}
166164

167-
// ---- Scenario lists ----
168-
169165
func hEmpireScenarios(ctx context.Context, c *call) (*result, error) {
170166
return c.query(ctx, "SELECT scenario, scenid FROM c4_scenarios WHERE empire='1' ORDER BY scenario")
171167
}
@@ -213,8 +209,6 @@ func hTimeTrialGoals(ctx context.Context, c *call) (*result, error) {
213209
c.int(0), c.int(1))
214210
}
215211

216-
// ---- Single scenario ----
217-
218212
func hScenarioID(ctx context.Context, c *call) (*result, error) {
219213
return c.query(ctx, "SELECT scenid FROM c4_scenarios WHERE scenario=?", c.str(0))
220214
}
@@ -231,8 +225,6 @@ func hScenarioChecksum(ctx context.Context, c *call) (*result, error) {
231225
return res, err
232226
}
233227

234-
// ---- Seasons ----
235-
236228
func hSeasonID(ctx context.Context, c *call) (*result, error) {
237229
return c.query(ctx, "SELECT seasonid FROM c4_comp_seasons WHERE activedate < ? ORDER BY seasonid DESC LIMIT 1", now32())
238230
}
@@ -248,8 +240,6 @@ func hNextSeason(ctx context.Context, c *call) (*result, error) {
248240
return res, nil
249241
}
250242

251-
// ---- Rankings ----
252-
253243
func hArenaHasRank(ctx context.Context, c *call) (*result, error) {
254244
return c.query(ctx, "SELECT COUNT(1) FROM c4_comp_rankings WHERE seasonid=? AND scenid=? AND userid=?", c.int(0), c.int(1), c.uid())
255245
}
@@ -342,8 +332,6 @@ func hEmpireLeaderboard(ctx context.Context, c *call) (*result, error) {
342332
return c.leaderboard(ctx, "c4_map_cities", "r.scenid=?", []any{c.int(0)}, 1)
343333
}
344334

345-
// ---- Uploads ----
346-
347335
// checkUpload flags stat values and targets that look wrong. Ranges are
348336
// guesses, so by default problems are only logged; -enforce-uploads rejects.
349337
func (c *call) checkUpload(ctx context.Context, arena bool, seasonid, scenid int64, stats []Value) error {
@@ -455,8 +443,6 @@ func hEmpireUpdateRank(ctx context.Context, c *call) (*result, error) {
455443
WHERE scenid=? AND userid=?`, args...)
456444
}
457445

458-
// ---- Screenshots ----
459-
460446
func hArenaSSCount(ctx context.Context, c *call) (*result, error) {
461447
return c.query(ctx, "SELECT COUNT(1) FROM c4_comp_ss WHERE seasonid=? AND scenid=? AND userid=?", c.int(0), c.int(1), c.uid())
462448
}
@@ -489,8 +475,6 @@ func hEmpireSSGet(ctx context.Context, c *call) (*result, error) {
489475
return c.query(ctx, "SELECT scenid, userid, screenshot FROM c4_map_ss WHERE scenid=? AND userid=?", c.int(0), c.uid())
490476
}
491477

492-
// ---- Building lists ----
493-
494478
func hArenaBuildingsCount(ctx context.Context, c *call) (*result, error) {
495479
return c.query(ctx, "SELECT COUNT(1) FROM c4_comp_buildings WHERE seasonid=? AND scenid=? AND userid=?", c.int(0), c.int(1), c.uid())
496480
}
@@ -530,8 +514,6 @@ func hEmpireBuildingsUpdate(ctx context.Context, c *call) (*result, error) {
530514
return c.exec(ctx, "UPDATE c4_map_buildings SET buildings=? WHERE scenid=? AND userid=?", c.str(0), c.int(1), c.uid())
531515
}
532516

533-
// ---- End of game ----
534-
535517
func hEmpireEndgame(ctx context.Context, c *call) (*result, error) {
536518
return c.query(ctx, "SELECT favor, timeplayed, population, happiness, funds, treasury, culture, security, prosperity FROM c4_map_cities WHERE scenid=? AND userid=?",
537519
c.int(0), c.uid())

‎gateway/internal/gateway/recorder.go‎

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import (
1919
)
2020

2121
// Recorder is the logging and investigation layer. Everything the gateway
22-
// sees goes to a JSON-lines capture file; statements nothing understands, and
23-
// hits on routes tied to open reverse-engineering questions, are also kept in
22+
// sees goes to a JSON-lines capture file; statements nothing understands are also kept in
2423
// memory for the admin endpoint.
2524
type Recorder struct {
2625
Log *slog.Logger
@@ -32,7 +31,6 @@ type Recorder struct {
3231
mu sync.Mutex
3332
commands map[string]int64
3433
routes map[string]int64
35-
questions map[string]*questionEntry
3634
unmatched map[string]*unmatchedEntry
3735
}
3836

@@ -54,22 +52,13 @@ type unmatchedEntry struct {
5452
Users map[string]int64 `json:"users"`
5553
}
5654

57-
type questionEntry struct {
58-
Route string `json:"route"`
59-
Question string `json:"question"`
60-
Count int64 `json:"count"`
61-
LastSeen time.Time `json:"last_seen"`
62-
Example string `json:"example"`
63-
}
64-
6555
func NewRecorder(o RecorderOptions) (*Recorder, error) {
6656
r := &Recorder{
6757
sqlMax: o.SQLMax,
6858
rawDir: o.RawDir,
6959
started: time.Now(),
7060
commands: map[string]int64{},
7161
routes: map[string]int64{},
72-
questions: map[string]*questionEntry{},
7362
unmatched: map[string]*unmatchedEntry{},
7463
}
7564
handlers := multiHandler{slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: o.ConsoleLevel})}
@@ -115,21 +104,6 @@ func (r *Recorder) countRoute(name string) {
115104
r.mu.Unlock()
116105
}
117106

118-
// question records a hit on a route whose behaviour is not fully understood.
119-
func (r *Recorder) question(s *Session, rt *route, sql string) {
120-
r.mu.Lock()
121-
q := r.questions[rt.name]
122-
if q == nil {
123-
q = &questionEntry{Route: rt.name, Question: rt.question}
124-
r.questions[rt.name] = q
125-
}
126-
q.Count++
127-
q.LastSeen = time.Now()
128-
q.Example = r.SQL(sql)
129-
r.mu.Unlock()
130-
s.log.Warn("open question: route hit", "event", "open_question", "route", rt.name, "question", rt.question, "sql", r.SQL(sql))
131-
}
132-
133107
func (r *Recorder) recordUnmatched(s *Session, command, norm string, params []mysqlproto.Value) {
134108
fp := fingerprint(norm)
135109
ps := summarizeParams(params)
@@ -164,16 +138,10 @@ func (r *Recorder) Snapshot() map[string]any {
164138
unmatched = append(unmatched, c)
165139
}
166140
sort.Slice(unmatched, func(i, j int) bool { return unmatched[i].Count > unmatched[j].Count })
167-
questions := make([]questionEntry, 0, len(r.questions))
168-
for _, q := range r.questions {
169-
questions = append(questions, *q)
170-
}
171-
sort.Slice(questions, func(i, j int) bool { return questions[i].Route < questions[j].Route })
172141
return map[string]any{
173142
"uptime_seconds": int(time.Since(r.started).Seconds()),
174143
"commands": copyCounts(r.commands),
175144
"routes": copyCounts(r.routes),
176-
"open_questions": questions,
177145
"unmatched": unmatched,
178146
}
179147
}

0 commit comments

Comments
 (0)