Example #1
0
        IEnumerator addServer(ServerJson server)
        {
            added         = true;
            sending       = true;
            currentServer = server;

            UnityWebRequest request = requestCreator.Post("servers", currentServer);

            yield return(requestCreator.SendRequestEnumerator(request, onSuccess, onFail));

            sending = false;

            void onSuccess(string responseBody)
            {
                CreatedIdJson created = JsonUtility.FromJson <CreatedIdJson>(responseBody);

                serverId = created.id;

                // Start ping to keep server alive
                _pingCoroutine = runner.StartCoroutine(ping());
            }

            void onFail(string responseBody)
            {
                added = false;
            }
        }
        public void AddServer(ServerJson server) {
            if (added) {
                Logger.LogWarning("AddServer called when server was already adding or added");
                return;
            }
            bool valid = server.Validate();
            if (!valid) {
                return;
            }

            runner.StartCoroutine(addServer(server));
        }
        public void UpdateServer(ServerJson server) {
            // TODO, use PartialServerJson as Arg Instead
            if (!added) {
                Logger.LogWarning("UpdateServer called when before server was added");
                return;
            }

            PartialServerJson partialServer = new PartialServerJson {
                displayName = server.displayName,
                playerCount = server.playerCount,
                maxPlayerCount = server.maxPlayerCount,
                customData = server.customData,
            };
            partialServer.Validate();

            runner.StartCoroutine(updateServer(partialServer));
        }
Example #4
0
        bool ValidateServerJson(ServerJson server)
        {
            if (string.IsNullOrEmpty(server.protocol))
            {
                Logger.LogError("ServerJson should not have empty protocol");
                return(false);
            }
            if (server.port == 0)
            {
                Logger.LogError("ServerJson should not have port equal 0");
                return(false);
            }
            if (server.maxPlayerCount == 0)
            {
                Logger.LogError("ServerJson should not have maxPlayerCount equal 0");
                return(false);
            }

            return(true);
        }