Unity Integration and the Legacy Split-String Protocol
UnityWebRequest handles those natively. This guide covers both ways to do it: the JSON API, which is the right choice for new projects, and the legacy split-string mode, a plain text response format made for clients that would rather call Split() than parse JSON. The legacy mode is the exact protocol the original Unity chess integration grew up on, kept alive so older clients keep working unchanged.
Unity With the JSON API
For a new Unity project, use the JSON API and a small serializable class per response. UnityWebRequest.Post sends the form fields, JsonUtility.FromJson reads the reply, and the five endpoints in the API reference map to five small coroutines. The demo page's JavaScript client is a direct blueprint for the C# version: join, poll status until matched, then poll actions on a timer and send moves as they happen.
Two Unity-specific habits pay off. First, run the polling in a coroutine with WaitForSeconds(2f) rather than polling every frame, turn-based games feel identical and your server barely notices the traffic. Second, keep the returned lastActionID in your game state, because it is also your reconnect token: when the app comes back from a suspend, call status, and if the match is still live, re-pull actions from 0 to rebuild the board.
What the Legacy Mode Is
Add format=legacy to any call, as a query string or a body field, and responses arrive as plain text lines instead of JSON. Request fields keep their JSON names, and three older field names are also accepted for clients that predate the JSON API: currentActionID works for since, multirequest sends an action as one actionType=data1=data2=data3 string, and totalMoveTimer works for totalTime.
The mode is per request, so the same server answers JSON to your new mobile client and split strings to the old Unity build in the same match. Use JSON for anything new, and use the split-string mode when it makes your client code simpler.
The Legacy Response Formats
| Call | Legacy response |
|---|---|
join, status | Matched: line one is 1,matchid,numPlayers,yourPlayerNum,timeLimit,gameMode,private,0, then one line per player slot as playerInfo*talentInfo*charInfo. Waiting: 2. Not anywhere: 3. Error: 0,message. |
action | 1 ok, 0 error. |
actions | One line per action as actionID,player,actionType,data1,data2,data3,totalTime, or OK when there is nothing new. |
leave | 3 |
The first character of the first line tells the whole story on join and status: 1 means matched and the rest of the line has the match, 2 means keep polling, 3 means join again. The OK response on an empty actions poll is worth noting, it is the exact string the original protocol used, so old clients checking for it keep working.
A Minimal Unity Example
IEnumerator JoinQueue() {
WWWForm form = new WWWForm();
form.AddField("apiKey", "YOUR_KEY");
form.AddField("format", "legacy");
form.AddField("playerid", myPlayerId);
form.AddField("gameMode", "1V1");
using (UnityWebRequest req = UnityWebRequest.Post(baseUrl + "/api.php/join", form)) {
yield return req.SendWebRequest();
string[] lines = req.downloadHandler.text.Split('\n');
string[] header = lines[0].Split(',');
if (header[0] == "1") { matchId = header[1]; myPlayerNum = int.Parse(header[3]); }
else if (header[0] == "2") { /* waiting, poll status */ }
}
}
Two calls to Split() and the match is parsed. Polling actions is the same shape: split on newlines, and split each line on commas into the seven action fields. The player info lines after the header split on * into the three info strings per slot.
Choosing Your Separators Wisely
The legacy format uses commas, asterisks, and newlines as its separators, so design your playerInfo, talentInfo, charInfo, and action data values around them in this mode, letters, digits, and underscores always travel safely. JSON mode carries any string untouched, which is one of the reasons it is the default recommendation for new clients.
Pairing With an AI Game Master
A Unity game on this server pairs naturally with our AbraTabia AI Storyteller: the game server syncs the players while a gamehost bot narrates, adjudicates, and reacts. Both speak plain HTTPS, so the same UnityWebRequest patterns cover both servers, and the gamehost guide covers the AI side of the table.
Unity talks to the server through UnityWebRequest either way: JSON for new projects, or format=legacy for plain text lines that parse with two calls to Split(). The legacy mode preserves the original Unity protocol exactly, including the OK empty-poll response, and both formats can serve different clients in the same match.