Пример #1
0
        async void Start()
        {
            client = new UdpClient(Port);

            agones = GetComponent <AgonesSdk>();
            bool ok = await agones.Connect();

            if (ok)
            {
                Debug.Log(("Server - Connected"));
            }
            else
            {
                Debug.Log(("Server - Failed to connect, exiting"));
                Application.Quit(1);
            }

            ok = await agones.Ready();

            if (ok)
            {
                Debug.Log($"Server - Ready");
            }
            else
            {
                Debug.Log($"Server - Ready failed");
                Application.Quit();
            }
        }
Пример #2
0
        async void AgonesReady()
        {
            bool ok = await agones.Ready();

            if (ok)
            {
                Debug.Log($"Server - Ready");
            }
            else
            {
                Debug.Log($"Server - Ready failed");
                Application.Quit();
            }
        }
Пример #3
0
        async void Start()
        {
            client = new UdpClient(Port);

            agones = GetComponent <AgonesSdk>();
            bool ok = await agones.Ready();

            if (ok)
            {
                Debug.Log($"Server - Ready");
            }
            else
            {
                Debug.Log($"Server - Ready failed");
                Application.Quit();
            }
        }
Пример #4
0
 public static async Task Ready()
 {
     var agones = new AgonesSdk(new AgonesSdkOptions(), new DummyHttpClientFactory());
     await agones.Ready();
 }
Пример #5
0
        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}");
            }
        }