async void Update() { while (client.Available > 0) { IPEndPoint remote = null; byte[] recvBytes = client.Receive(ref remote); string recvText = Encoding.UTF8.GetString(recvBytes); string[] recvTexts = recvText.Split(' '); bool ok = false; switch (recvTexts[0]) { case "Shutdown": ok = await agones.Shutdown(); Debug.Log($"Server - Shutdown {ok}"); Application.Quit(); break; case "Allocate": ok = await agones.Allocate(); Debug.Log($"Server - Allocate {ok}"); break; case "Label": if (recvTexts.Length == 3) { (string key, string value) = (recvTexts[1], recvTexts[2]); ok = await agones.SetLabel(key, value); Debug.Log($"Server - SetLabel {ok}"); } break; case "Annotation": if (recvTexts.Length == 3) { (string key, string value) = (recvTexts[1], recvTexts[2]); ok = await agones.SetAnnotation(key, value); Debug.Log($"Server - SetAnnotation {ok}"); } break; } byte[] echo = Encoding.UTF8.GetBytes($"Echo : {recvText}"); client.Send(echo, echo.Length, remote); Debug.Log($"Server - Receive[{remote.ToString()}] : {recvText}"); } }
async void Update() { if (client.Available > 0) { IPEndPoint remote = null; byte[] recvBytes = client.Receive(ref remote); string recvText = Encoding.UTF8.GetString(recvBytes); string[] recvTexts = recvText.Split(' '); byte[] echoBytes = null; bool ok = false; switch (recvTexts[0]) { case "Shutdown": ok = await agones.Shutdown(); Debug.Log($"Server - Shutdown {ok}"); echoBytes = Encoding.UTF8.GetBytes($"Shutdown {ok}"); client.Send(echoBytes, echoBytes.Length, remote); Application.Quit(); return; case "Allocate": ok = await agones.Allocate(); Debug.Log($"Server - Allocate {ok}"); echoBytes = Encoding.UTF8.GetBytes($"Allocate {ok}"); break; case "Label": if (recvTexts.Length == 3) { (string key, string value) = (recvTexts[1], recvTexts[2]); ok = await agones.SetLabel(key, value); Debug.Log($"Server - SetLabel({recvTexts[1]}, {recvTexts[2]}) {ok}"); echoBytes = Encoding.UTF8.GetBytes($"SetLabel({recvTexts[1]}, {recvTexts[2]}) {ok}"); } else { echoBytes = Encoding.UTF8.GetBytes($"ERROR: Invalid Label command, must use 2 arguments"); } break; case "Annotation": if (recvTexts.Length == 3) { (string key, string value) = (recvTexts[1], recvTexts[2]); ok = await agones.SetAnnotation(key, value); Debug.Log($"Server - SetAnnotation({recvTexts[1]}, {recvTexts[2]}) {ok}"); echoBytes = Encoding.UTF8.GetBytes($"SetAnnotation({recvTexts[1]}, {recvTexts[2]}) {ok}"); } else { echoBytes = Encoding.UTF8.GetBytes($"ERROR: Invalid Annotation command, must use 2 arguments"); } break; default: echoBytes = Encoding.UTF8.GetBytes($"Echo : {recvText}"); break; } client.Send(echoBytes, echoBytes.Length, remote); Debug.Log($"Server - Receive[{remote.ToString()}] : {recvText}"); } }
async void Update() { if (client.Available > 0) { IPEndPoint remote = null; byte[] recvBytes = client.Receive(ref remote); string recvText = Encoding.UTF8.GetString(recvBytes); string[] recvTexts = recvText.Split(' '); byte[] echoBytes = null; bool ok = false; switch (recvTexts[0]) { case "Shutdown": ok = await agones.Shutdown(); Debug.Log($"Server - Shutdown {ok}"); echoBytes = Encoding.UTF8.GetBytes($"Shutdown {ok}"); client.Send(echoBytes, echoBytes.Length, remote); Application.Quit(); return; case "Ready": ok = await agones.Ready(); Debug.Log($"Server - Ready {ok}"); echoBytes = Encoding.UTF8.GetBytes($"Ready {ok}"); break; case "Allocate": ok = await agones.Allocate(); Debug.Log($"Server - Allocate {ok}"); echoBytes = Encoding.UTF8.GetBytes($"Allocate {ok}"); break; case "GameServer": var gameserver = await agones.GameServer(); Debug.Log($"Server - GameServer {gameserver}"); ok = gameserver != null; echoBytes = Encoding.UTF8.GetBytes(ok ? $"GameServer() Name: {gameserver.ObjectMeta.Name} {ok}" : $"GameServer(): {ok}"); break; case "Label": if (recvTexts.Length == 3) { (string key, string value) = (recvTexts[1], recvTexts[2]); ok = await agones.SetLabel(key, value); Debug.Log($"Server - SetLabel({recvTexts[1]}, {recvTexts[2]}) {ok}"); echoBytes = Encoding.UTF8.GetBytes($"SetLabel({recvTexts[1]}, {recvTexts[2]}) {ok}"); } else { echoBytes = Encoding.UTF8.GetBytes($"ERROR: Invalid Label command, must use 2 arguments"); } break; case "Annotation": if (recvTexts.Length == 3) { (string key, string value) = (recvTexts[1], recvTexts[2]); ok = await agones.SetAnnotation(key, value); Debug.Log($"Server - SetAnnotation({recvTexts[1]}, {recvTexts[2]}) {ok}"); echoBytes = Encoding.UTF8.GetBytes($"SetAnnotation({recvTexts[1]}, {recvTexts[2]}) {ok}"); } else { echoBytes = Encoding.UTF8.GetBytes($"ERROR: Invalid Annotation command, must use 2 arguments"); } break; case "Reserve": if (recvTexts.Length == 2) { TimeSpan duration = new TimeSpan(0, 0, Int32.Parse(recvTexts[1])); ok = await agones.Reserve(duration); Debug.Log($"Server - Reserve({recvTexts[1]} {ok}"); echoBytes = Encoding.UTF8.GetBytes($"Reserve({recvTexts[1]}) {ok}"); } else { echoBytes = Encoding.UTF8.GetBytes($"ERROR: Invalid Reserve command, must use 1 argument"); } break; case "Watch": agones.WatchGameServer(gameServer => Debug.Log($"Server - Watch {gameServer}")); echoBytes = Encoding.UTF8.GetBytes("Watching()"); break; default: echoBytes = Encoding.UTF8.GetBytes($"Echo : {recvText}"); break; } client.Send(echoBytes, echoBytes.Length, remote); Debug.Log($"Server - Receive[{remote.ToString()}] : {recvText}"); } }