public static void MessageReceived(HS_SocketDataWorker sdw, string message) { JsonDataMessage request = JsonDataMessage.Parse(message.Trim()); Log(message); if (request.Data1 == "login") { clients[sdw].userid = request.Data2; //TODO make this async Log("API call"); string stringResponse = NetUtil.PostSynchro(Settings.Current.InternalTokenLookupUrl, new Dictionary <string, string> { { "code", Settings.Current.InternalApiAccessCode }, { "userid", request.Data2 } }); Log("Response: " + stringResponse); ServerResponse response = ServerResponse.Parse(stringResponse); clients[sdw].symkey = response.Data1; Log("Sym token: " + response.Data1); sdw.Symkey = response.Data1; JsonDataMessage readyRequest = new JsonDataMessage("ready"); Log("User joined, sending ready message: " + readyRequest.Json); sdw.Send(readyRequest.Json); legacy2PlayerQueue.Enqueue(sdw); } CheckGameStart(); }
public void PlayerCommandReceived(HS_SocketDataWorker sdw, string message) { if (!gameon) { return; } HS_PlayerInstance callingPlayer = playerInstances[sdw]; JsonDataMessage request = JsonDataMessage.Parse(message.Trim()); string query = request.Data1; if (query == "login") { names[callingPlayer] = request.Data2; } int spaceindex = query.IndexOf(' '); string q = (spaceindex > 0) ? query.Substring(0, spaceindex) : query; string[] cs = query.Split(' '); string response = ""; switch (q) { case "hands": response = PrintHands(callingPlayer); break; case "fields": response = PrintFields(); break; //explain card case "play": response = Play(callingPlayer, cs); break; case "attack": response = Attack(callingPlayer, cs); break; case "a": response = Attack(callingPlayer, cs); break; case "allface": response = AllFace(callingPlayer, cs); break; //case "help": break; //case "clear": System.Console.Clear(); break; case "end": response = EndTurn(callingPlayer); break; case "hero": response = Hero(callingPlayer); break; case "whoturn": response = WhoTurn(); break; default: response = "Unknown command"; break; } sdw.Send(response); CheckDeadPlayers(); }