From b39e287e41cbebdfd08ef8d3b5378dcf84966444 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 13 Oct 2020 16:41:50 -0600 Subject: [PATCH] Debug prod server, apparently for the first time. --- cmd/mothd/httpd_test.go | 4 +- cmd/mothd/mothballs.go | 2 +- cmd/mothd/mothballs_test.go | 12 +- cmd/mothd/server.go | 5 +- cmd/mothd/server_test.go | 12 ++ cmd/transpile/main.go | 4 +- theme/moth.js | 1 + theme/points.json | 255 ------------------------------------ theme/puzzle.js | 2 +- theme/puzzles.json | 54 -------- 10 files changed, 27 insertions(+), 324 deletions(-) delete mode 100644 theme/points.json delete mode 100644 theme/puzzles.json diff --git a/cmd/mothd/httpd_test.go b/cmd/mothd/httpd_test.go index 6bd66dc..ea8619f 100644 --- a/cmd/mothd/httpd_test.go +++ b/cmd/mothd/httpd_test.go @@ -50,8 +50,8 @@ func TestHttpd(t *testing.T) { if r := hs.TestRequest("/state", nil); r.Result().StatusCode != 200 { t.Error(r.Result()) - } else if r.Body.String() != `{"Config":{"Devel":false},"Messages":"messages.html","TeamNames":{"self":""},"PointsLog":[],"Puzzles":{"pategory":[1]}}` { - t.Error("Unexpected state") + } else if r.Body.String() != `{"Config":{"Devel":false},"Messages":"messages.html","TeamNames":{"self":""},"PointsLog":[],"Puzzles":{}}` { + t.Error("Unexpected state", r.Body.String()) } if r := hs.TestRequest("/register", map[string]string{"id": "bad team id", "name": "GoTeam"}); r.Result().StatusCode != 200 { diff --git a/cmd/mothd/mothballs.go b/cmd/mothd/mothballs.go index 6c3ada4..8d44a0e 100644 --- a/cmd/mothd/mothballs.go +++ b/cmd/mothd/mothballs.go @@ -51,7 +51,7 @@ func (m *Mothballs) Open(cat string, points int, filename string) (ReadSeekClose return nil, time.Time{}, fmt.Errorf("No such category: %s", cat) } - f, err := zc.Open(fmt.Sprintf("content/%d/%s", points, filename)) + f, err := zc.Open(fmt.Sprintf("%d/%s", points, filename)) if err != nil { return nil, time.Time{}, err } diff --git a/cmd/mothd/mothballs_test.go b/cmd/mothd/mothballs_test.go index e32ca17..9b75838 100644 --- a/cmd/mothd/mothballs_test.go +++ b/cmd/mothd/mothballs_test.go @@ -13,12 +13,12 @@ var testFiles = []struct { }{ {"puzzles.txt", "1\n3\n2\n"}, {"answers.txt", "1 answer123\n1 answer456\n2 wat\n"}, - {"content/1/puzzle.json", `{"name": "moo"}`}, - {"content/1/moo.txt", `moo`}, - {"content/2/puzzle.json", `{}`}, - {"content/2/moo.txt", `moo`}, - {"content/3/puzzle.json", `{}`}, - {"content/3/moo.txt", `moo`}, + {"1/puzzle.json", `{"name": "moo"}`}, + {"1/moo.txt", `moo`}, + {"2/puzzle.json", `{}`}, + {"2/moo.txt", `moo`}, + {"3/puzzle.json", `{}`}, + {"3/moo.txt", `moo`}, } func (m *Mothballs) createMothball(cat string) { diff --git a/cmd/mothd/server.go b/cmd/mothd/server.go index 35619bc..556bbf7 100644 --- a/cmd/mothd/server.go +++ b/cmd/mothd/server.go @@ -175,7 +175,8 @@ func (mh *MothRequestHandler) ExportState() *StateExport { export := StateExport{} export.Config = mh.Config - teamName, _ := mh.State.TeamName(mh.teamID) + teamName, err := mh.State.TeamName(mh.teamID) + registered := (err == nil) export.Messages = mh.State.Messages() export.TeamNames = map[string]string{"self": teamName} @@ -204,7 +205,7 @@ func (mh *MothRequestHandler) ExportState() *StateExport { } export.Puzzles = make(map[string][]int) - if _, ok := export.TeamNames["self"]; ok { + if registered { // We used to hand this out to everyone, // but then we got a bad reputation on some secretive blacklist, // and now the Navy can't register for events. diff --git a/cmd/mothd/server_test.go b/cmd/mothd/server_test.go index 2c5f732..586ce7e 100644 --- a/cmd/mothd/server_test.go +++ b/cmd/mothd/server_test.go @@ -34,6 +34,18 @@ func TestServer(t *testing.T) { server := NewTestServer() handler := server.NewHandler(participantID, teamID) + + { + es := handler.ExportState() + if es.Config.Devel { + t.Error("Marked as development server", es.Config) + } + if len(es.Puzzles) != 0 { + t.Log("State", es) + t.Error("Unauthenticated state has non-empty puzzles list") + } + } + if err := handler.Register(teamName); err != nil { t.Error(err) } diff --git a/cmd/transpile/main.go b/cmd/transpile/main.go index 34cec5b..82f034b 100644 --- a/cmd/transpile/main.go +++ b/cmd/transpile/main.go @@ -81,7 +81,6 @@ func (t *T) ParseArgs() (Command, error) { return nothing, err } if *directory != "" { - log.Println(*directory) t.fs = afero.NewBasePathFs(t.BaseFs, *directory) } else { t.fs = t.BaseFs @@ -151,7 +150,7 @@ func (t *T) DumpMothball() error { if t.filename == "" { w = t.Stdout } else { - log.Println("Writing to", t.filename, t.fs) + log.Println("Writing mothball to", t.filename) outf, err := t.BaseFs.Create(t.filename) if err != nil { return err @@ -159,7 +158,6 @@ func (t *T) DumpMothball() error { defer outf.Close() w = outf } - log.Println(t.fs) if err := transpile.Mothball(c, w); err != nil { return err } diff --git a/theme/moth.js b/theme/moth.js index ccf2080..8631f30 100644 --- a/theme/moth.js +++ b/theme/moth.js @@ -97,6 +97,7 @@ function renderPuzzles(obj) { } function renderState(obj) { + window.state = obj devel = obj.Config.Devel if (devel) { let params = new URLSearchParams(window.location.search) diff --git a/theme/points.json b/theme/points.json deleted file mode 100644 index 36e0aef..0000000 --- a/theme/points.json +++ /dev/null @@ -1,255 +0,0 @@ -{ - "__comment__": [ - "This file is to help debug themes.", - "MOTHd will ignore it." - ], - "teams": { - "0": "4HED Followers", - "1": "Dirtbags", - "17": "Eyeball", - "2": "Soup Giver!!!!!!!!!", - "24": "Dumb freshmans 3", - "25": "Winner", - "2d": "Cool team name", - "2f": "Dumm freshmans #1", - "4": "K19 the Widow Maker", - "5": "2T2", - "6": "Apples", - "7": "Top Minds", - "8": "DIRTBAGS", - "b": "Antiderivative of Pizza" - }, - "points": [ - [1573007086,"0","codebreaking",1], - [1573007096,"1","codebreaking",1], - [1573007114,"2","codebreaking",1], - [1573007153,"0","codebreaking",2], - [1573007159,"4","codebreaking",1], - [1573007169,"5","codebreaking",1], - [1573007181,"6","sequence",1], - [1573007184,"7","codebreaking",1], - [1573007209,"8","codebreaking",1], - [1573007212,"2","codebreaking",2], - [1573007240,"1","sequence",1], - [1573007244,"b","codebreaking",1], - [1573007246,"1","nocode",1], - [1573007258,"5","nocode",1], - [1573007271,"5","nocode",2], - [1573007284,"1","steg",1], - [1573007295,"7","codebreaking",2], - [1573007298,"2","codebreaking",4], - [1573007305,"5","nocode",3], - [1573007316,"7","codebreaking",4], - [1573007321,"0","codebreaking",4], - [1573007328,"5","nocode",4], - [1573007331,"7","nocode",1], - [1573007336,"17","codebreaking",1], - [1573007340,"7","nocode",2], - [1573007367,"0","nocode",10], - [1573007369,"7","nocode",3], - [1573007371,"b","nocode",1], - [1573007379,"7","nocode",4], - [1573007388,"b","nocode",2], - [1573007391,"6","sequence",2], - [1573007397,"4","codebreaking",2], - [1573007407,"b","nocode",3], - [1573007411,"7","nocode",10], - [1573007413,"5","nocode",10], - [1573007429,"b","nocode",4], - [1573007442,"24","codebreaking",2], - [1573007451,"25","codebreaking",1], - [1573007456,"7","sequence",1], - [1573007460,"b","nocode",10], - [1573007467,"5","sequence",1], - [1573007471,"7","sequence",2], - [1573007478,"5","sequence",2], - [1573007479,"17","codebreaking",2], - [1573007490,"2","codebreaking",5], - [1573007509,"2d","codebreaking",1], - [1573007536,"8","codebreaking",2], - [1573007544,"2f","codebreaking",1], - [1573007546,"b","sequence",1], - [1573007574,"24","codebreaking",4], - [1573007581,"b","sequence",2], - [1573007591,"25","codebreaking",2], - [1573007603,"8","codebreaking",4], - [1573007614,"0","nocode",20], - [1573007639,"4","codebreaking",4], - [1573007678,"6","codebreaking",1], - [1573007692,"8","nocode",1], - [1573007695,"24","codebreaking",5], - [1573007705,"7","codebreaking",5], - [1573007707,"8","nocode",2], - [1573007713,"17","nocode",1], - [1573007727,"17","nocode",2], - [1573007735,"8","nocode",3], - [1573007737,"b","steg",1], - [1573007739,"25","codebreaking",4], - [1573007749,"8","nocode",4], - [1573007757,"17","codebreaking",4], - [1573007768,"8","nocode",10], - [1573007795,"0","sequence",1], - [1573007799,"8","sequence",1], - [1573007816,"0","sequence",2], - [1573007822,"8","sequence",2], - [1573007834,"24","codebreaking",6], - [1573007853,"2d","codebreaking",2], - [1573007905,"1","codebreaking",2], - [1573007941,"4","codebreaking",5], - [1573007956,"1","codebreaking",4], - [1573007974,"6","codebreaking",2], - [1573007998,"17","sequence",1], - [1573008022,"b","codebreaking",4], - [1573008055,"24","sequence",2], - [1573008063,"6","codebreaking",4], - [1573008066,"2d","codebreaking",4], - [1573008074,"24","sequence",1], - [1573008099,"17","nocode",4], - [1573008101,"0","codebreaking",7], - [1573008108,"2d","nocode",1], - [1573008135,"24","nocode",30], - [1573008146,"1","codebreaking",5], - [1573008162,"2d","nocode",2], - [1573008174,"b","codebreaking",2], - [1573008191,"2","codebreaking",6], - [1573008234,"6","codebreaking",5], - [1573008240,"2","nocode",10], - [1573008291,"5","steg",1], - [1573008310,"6","nocode",1], - [1573008323,"2d","nocode",3], - [1573008327,"6","nocode",2], - [1573008330,"25","codebreaking",5], - [1573008334,"2f","codebreaking",2], - [1573008348,"6","nocode",3], - [1573008356,"2d","nocode",4], - [1573008362,"b","codebreaking",5], - [1573008364,"6","nocode",4], - [1573008364,"17","codebreaking",5], - [1573008371,"24","nocode",4], - [1573008385,"24","nocode",3], - [1573008390,"6","nocode",10], - [1573008397,"24","nocode",2], - [1573008400,"25","nocode",1], - [1573008402,"2d","nocode",10], - [1573008408,"24","nocode",1], - [1573008419,"25","nocode",2], - [1573008429,"24","steg",1], - [1573008437,"25","nocode",3], - [1573008451,"25","nocode",4], - [1573008479,"25","nocode",10], - [1573008502,"2d","sequence",1], - [1573008506,"17","codebreaking",6], - [1573008537,"2d","sequence",2], - [1573008649,"17","codebreaking",7], - [1573008668,"2f","codebreaking",4], - [1573008716,"1","codebreaking",6], - [1573008768,"8","steg",1], - [1573008808,"7","nocode",50], - [1573008817,"24","steg",2], - [1573008832,"2f","codebreaking",5], - [1573008890,"17","steg",1], - [1573008902,"b","steg",2], - [1573008932,"7","steg",1], - [1573008944,"24","steg",3], - [1573008978,"2","steg",1], - [1573009006,"24","steg",4], - [1573009032,"6","steg",1], - [1573009038,"b","steg",3], - [1573009052,"2d","codebreaking",5], - [1573009098,"b","steg",4], - [1573009122,"8","steg",2], - [1573009125,"4","nocode",1], - [1573009160,"24","nocode",10], - [1573009161,"4","nocode",2], - [1573009179,"2","steg",2], - [1573009180,"1","steg",2], - [1573009194,"24","nocode",20], - [1573009203,"0","nocode",50], - [1573009212,"2f","codebreaking",6], - [1573009240,"2f","nocode",1], - [1573009250,"4","nocode",4], - [1573009255,"2f","nocode",2], - [1573009258,"2","steg",4], - [1573009282,"4","nocode",10], - [1573009299,"25","sequence",1], - [1573009305,"6","steg",4], - [1573009308,"17","steg",3], - [1573009310,"1","steg",3], - [1573009334,"7","steg",4], - [1573009345,"1","steg",4], - [1573009345,"7","steg",3], - [1573009354,"8","steg",4], - [1573009357,"25","sequence",2], - [1573009402,"6","steg",3], - [1573009402,"b","sequence",8], - [1573009413,"2f","nocode",3], - [1573009437,"17","steg",2], - [1573009455,"2f","nocode",10], - [1573009481,"b","sequence",16], - [1573009502,"b","sequence",19], - [1573009520,"b","sequence",25], - [1573009525,"17","steg",4], - [1573009559,"7","steg",2], - [1573009561,"b","sequence",35], - [1573009571,"0","sequence",35], - [1573009588,"25","steg",1], - [1573009602,"24","sequence",8], - [1573009607,"2","steg",5], - [1573009614,"1","steg",5], - [1573009617,"17","sequence",35], - [1573009620,"7","sequence",50], - [1573009621,"6","steg",5], - [1573009629,"5","steg",3], - [1573009632,"7","sequence",35], - [1573009644,"17","sequence",25], - [1573009670,"6","steg",6], - [1573009698,"8","steg",6], - [1573009700,"17","sequence",19], - [1573009703,"24","steg",6], - [1573009703,"4","sequence",1], - [1573009707,"0","sequence",50], - [1573009710,"25","steg",2], - [1573009729,"2f","sequence",1], - [1573009768,"1","steg",6], - [1573009814,"2","codebreaking",8], - [1573009842,"0","steg",1], - [1573009844,"2f","sequence",2], - [1573009882,"4","steg",1], - [1573009896,"25","steg",3], - [1573009931,"1","sequence",2], - [1573009937,"25","steg",4], - [1573010066,"7","steg",6], - [1573010101,"25","steg",5], - [1573010114,"5","steg",4], - [1573010137,"25","steg",6], - [1573010185,"4","sequence",2], - [1573010229,"17","nocode",80], - [1573010256,"24","sequence",35], - [1573010281,"6","codebreaking",7], - [1573010336,"25","codebreaking",6], - [1573010390,"7","codebreaking",7], - [1573010468,"2f","steg",1], - [1573010712,"0","steg",2], - [1573010739,"0","steg",3], - [1573010754,"0","steg",4], - [1573010778,"0","steg",5], - [1573010784,"7","nocode",90], - [1573010792,"0","steg",6], - [1573011760,"7","sequence",60], - [1573056120,"0","sequence",100], - [1573056324,"0","sequence",200], - [1573056791,"0","sequence",300], - [1573057092,"0","sequence",400], - [1573076767,"25","sequence",400], - [1573076809,"25","sequence",300], - [1573076838,"25","sequence",200], - [1573076936,"25","nocode",20], - [1573077275,"25","nocode",50], - [1573078364,"0","sequence",19], - [1573078432,"0","sequence",25], - [1573078487,"25","sequence",35], - [1573078501,"25","sequence",50], - [1573079359,"0","nocode",90], - [1573079714,"25","nocode",9] - ] -} diff --git a/theme/puzzle.js b/theme/puzzle.js index 9c8e42a..7dd24c5 100644 --- a/theme/puzzle.js +++ b/theme/puzzle.js @@ -132,7 +132,7 @@ async function loadPuzzle(categoryName, points, puzzleId) { document.getElementById("authors").textContent = window.puzzle.Pre.Authors.join(", ") // If answers are provided, this is the devel server - if (window.puzzle.Answers) { + if (window.puzzle.Answers.length > 0) { devel_addin(document.getElementById("devel")) } diff --git a/theme/puzzles.json b/theme/puzzles.json deleted file mode 100644 index 5a6735d..0000000 --- a/theme/puzzles.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "__comment__": [ - "This file is to help debug themes.", - "MOTHd will ignore it." - ], - "codebreaking": [ - [1,"37117e6b034696b86c6516477cc0bc60bc1e642e"], - [2,"546b586428979771b061608489327da4940086a7"], - [4,"6f2a33c93f56b4f29cc79e6576ba4d1000aa1756"], - [5,"c654fe263909b1940d7aad8c572363a0569c07c6"], - [6,"f30bd32bf940f2bb03506ec334d2d204efc4695b"], - [7,"128b119083b6ae70c380a8eb70ec6a518425e7af"], - [8,"edd4f57aeb565b3b053fa194f5e677cb77ef0285"], - [15,"9781863bca9f596972e2a10460932ec5ec6be3fe"] - ], - "nocode": [ - [1,"37117e6b034696b86c6516477cc0bc60bc1e642e"], - [2,"546b586428979771b061608489327da4940086a7"], - [3,"79c08697a1923da1118fd0c2e922b5d3899cabcc"], - [4,"6f2a33c93f56b4f29cc79e6576ba4d1000aa1756"], - [10,"bf4fae263bf6e4243b143f4ecd64e471f3ec75dd"], - [20,"9f374f6dac9f972fac4693099a7bfa7c535f7503"], - [30,"02de1196d43976b2d050c6c597f068623d2df201"], - [50,"9acb3af947cb4aa10a9c1221c04518f956cdc0d0"], - [80,"78f807ac44f3cbf537861e7cdf1ac53937e4ee47"], - [90,"6d537653aa599178c72528f7e1f2fbb36e6333f9"], - [100,"4f5982a3a7cc9b9af0320130132e8cab39a1fd2c"] - ], - "sequence": [ - [1,"37117e6b034696b86c6516477cc0bc60bc1e642e"], - [2,"546b586428979771b061608489327da4940086a7"], - [8,"edd4f57aeb565b3b053fa194f5e677cb77ef0285"], - [16,"a9ace4b773f045c422260edefaa8563dcd80ac59"], - [19,"f11ca0172451f37ba6f4d66ff9add80013480a49"], - [25,"0458533d28705548829e53d686215cc6fbeec8f5"], - [35,"91aac06bae090ae7d1699b5a78601ef8d29e9271"], - [50,"9acb3af947cb4aa10a9c1221c04518f956cdc0d0"], - [60,"bf84beed9e382268ab40d0113dfeb73c96aa919a"], - [100,"4f5982a3a7cc9b9af0320130132e8cab39a1fd2c"], - [200,"3b9b8993fe639cf0c19a58b39ebbf6077828887a"], - [300,"0f13c4d19bc5d2e10d43e8cd2e40f759e731cece"], - [400,"db7a59f313818fc9598969d2a0a04e21bd26697f"], - [500,"81c5389eb5406aa44053662f6482f246b8a12e0c"] - ], - "steg": [ - [1,"200e8cd902ba7304765c463f6ed1322bc25f3454"], - [2,"707328988c3986d450d8fe419eb49f078fb7998c"], - [3,"d0b336ad59cbcd4415ddf200c6c099db5c3fea1d"], - [4,"f071503b403ffee2b38e186e800bfd5dd28e8f0e"], - [5,"186f425fa5762ef37f874cc602fe0edc4325a5d2"], - [6,"c6527c3c30c4e6a33026192d358d83d259cd17a7"], - [10,"84973f77a1b14e4666f3d8a8bdeead7633c4ed56"] - ] -}