Ejemplo n.º 1
0
        private int waitTillServerNotFull()
        {
            int  attempts = 0;
            bool failed   = false;

            do
            {
                _server.update(null);
                Thread.Sleep(1000); // wait a second so we don't costantly flood the server with ARE WE THERE YET?

                if (_server.queryStatus != Server.ServerQueryStatus.Successful)
                {
                    if (!failed) // haven't failed before? let's reset the counter AND GO HARDC0RE COUNTING HUUUUURRRR
                    {
                        attempts = 0;
                    }
                    failed = true;

                    if (attempts > 5)
                    {
                        editStatusText("Server timed out");
                        Thread.Sleep(1000);
                        _close_form_event.Set(); // tell the form to stop
                        return(attempts);
                    }

                    // reset the counter, and count to 5- if the server fails to respond. we're boned.
                    editStatusText("Server is not responding... attempt " + (attempts++));
                }
                else
                {
                    if (failed)
                    {
                        failed   = false;
                        attempts = 0;
                    }
                    editStatusText("Waiting for new space... attempt " + (attempts++)); // concatenating string like this is.. urrghghgh
                }
            }while (_server.serverNPlayers >= _server.serverMaxPlayers);                // onoes, server is full

            return(attempts);
        }