Repos / gorts / f6ba840aaf
commit f6ba840aafd942eddd1f1cf766c01c8e066240cc
Author: Nhân <hi@imnhan.com>
Date:   Wed Jun 21 20:25:08 2023 +0700

    remove cheats from initialize proc
    
    in preparation for migrating to netstring-based IPC.

diff --git a/main.go b/main.go
index ce0e2e7..9b582cc 100644
--- a/main.go
+++ b/main.go
@@ -89,18 +89,9 @@ func startGUI() {
 
 	allplayers := players.FromFile(PlayersFile)
 	scoreboard := initScoreboard()
-	b64icon := base64.StdEncoding.EncodeToString(gortsPngIcon)
 	startggInputs := startgg.LoadInputs(StartggFile)
 
-	fmt.Fprintf(
-		stdin,
-		"initialize %s %s {%s} %s %s\n",
-		b64icon,
-		WebPort,
-		strings.Join(startgg.CountryCodes, " "),
-		startggInputs.Token,
-		startggInputs.Slug,
-	)
+	fmt.Fprintln(stdin, "initialize")
 
 	scanner := bufio.NewScanner(stdout)
 
@@ -112,7 +103,11 @@ func startGUI() {
 	}
 
 	respond := func(s string) {
-		println("<--", s)
+		debug := "<-- " + s
+		if len(debug) > 35 {
+			debug = debug[:35] + "[...]"
+		}
+		println(debug)
 		io.WriteString(stdin, s+"\n")
 	}
 
@@ -177,8 +172,21 @@ func startGUI() {
 			respond("fetchplayers__resp")
 			respond("All done.")
 			startggInputs.Write(StartggFile)
-		}
 
+		case "readwebport":
+			respond(WebPort)
+
+		case "geticon":
+			b64icon := base64.StdEncoding.EncodeToString(gortsPngIcon)
+			respond(b64icon)
+
+		case "getcountrycodes":
+			respond(strings.Join(startgg.CountryCodes, " "))
+
+		case "readstartgg":
+			respond(startggInputs.Token)
+			respond(startggInputs.Slug)
+		}
 	}
 
 	println("Tcl process terminated.")
diff --git a/tcl/main.tcl b/tcl/main.tcl
index 875e7b8..616a87a 100644
--- a/tcl/main.tcl
+++ b/tcl/main.tcl
@@ -147,7 +147,7 @@ grid rowconfigure .n.m.players 3 -pad 5
 
 # start.gg tab:
 
-.n select .n.s; # for debug only
+#.n select .n.s; # for debug only
 ttk::label .n.s.tokenlbl -text "Personal token: "
 ttk::entry .n.s.token -show * -textvariable startgg(token)
 ttk::label .n.s.tournamentlbl -text "Tournament slug: "
@@ -167,26 +167,45 @@ grid rowconfigure .n.s 1 -pad 5
 # The following procs constitute a very simple line-based IPC system where Tcl
 # client talks to Go server via stdin/stdout.
 
-proc initialize {b64icon webport countrycodes startgg_token startgg_slug} {
-    seticon $b64icon
-    set ::mainstatus "Point your OBS browser source to http://localhost:${webport}"
-    .n.m.players.p1country configure -values $countrycodes
-    .n.m.players.p2country configure -values $countrycodes
-    set ::startgg(token) $startgg_token
-    set ::startgg(slug) $startgg_slug
+proc initialize {} {
+    seticon
+    setwebport
+    setcountrycodes
+    setstartgg
     readscoreboard
     setupdiffcheck
     readplayernames
     setupplayersuggestion
 }
 
-proc seticon {b64data} {
+proc setstartgg {} {
+    puts "readstartgg"
+    set ::startgg(token) [gets stdin]
+    set ::startgg(slug) [gets stdin]
+}
+
+proc setwebport {} {
+    puts "readwebport"
+    set webport [gets stdin]
+    set ::mainstatus "Point your OBS browser source to http://localhost:${webport}"
+}
+
+proc seticon {} {
+    puts "geticon"
+    set b64data [gets stdin]
     image create photo applicationIcon -data [
         binary decode base64 $b64data
     ]
     wm iconphoto . -default applicationIcon
 }
 
+proc setcountrycodes {} {
+    puts getcountrycodes
+    set countrycodes [gets stdin]
+    .n.m.players.p1country configure -values $countrycodes
+    .n.m.players.p2country configure -values $countrycodes
+}
+
 proc readscoreboard {} {
     puts "readscoreboard"
     set ::scoreboard(description) [gets stdin]