예제 #1
0
 public override void Render(float dt)
 {
     if (game.reconnect)
     {
         game.Dispose();
         menu.StartGame(singleplayer, singleplayerSavePath, connectData);
         return;
     }
     if (game.exitToMainMenu)
     {
         game.Dispose();
         if (game.GetRedirect() != null)
         {
             //Query new server for public key
             QueryClient qclient = new QueryClient();
             qclient.SetPlatform(platform);
             qclient.PerformQuery(game.GetRedirect().GetIP(), game.GetRedirect().GetPort());
             if (qclient.queryPerformed && !qclient.querySuccess)
             {
                 //Query did not succeed. Back to main menu
                 platform.MessageBoxShowError(qclient.GetServerMessage(), "Redirection error");
                 menu.StartMainMenu();
                 return;
             }
             QueryResult qresult = qclient.GetResult();
             //Get auth hash for new server
             LoginClientCi lic    = new LoginClientCi();
             LoginData     lidata = new LoginData();
             string        token  = platform.StringSplit(qresult.PublicHash, "=", new IntRef())[1];
             lic.Login(platform, connectData.Username, "", token, platform.GetPreferences().GetString("Password", ""), new LoginResultRef(), lidata);
             while (lic.loginResult.value == LoginResult.Connecting)
             {
                 lic.Update(platform);
             }
             //Check if login was successful
             if (!lidata.ServerCorrect)
             {
                 //Invalid server adress
                 platform.MessageBoxShowError("Invalid server address!", "Redirection error!");
                 menu.StartMainMenu();
             }
             else if (!lidata.PasswordCorrect)
             {
                 //Authentication failed
                 menu.StartLogin(token, null, 0);
             }
             else if (lidata.ServerAddress != null && lidata.ServerAddress != "")
             {
                 //Finally switch to the new server
                 menu.ConnectToGame(lidata, connectData.Username);
             }
         }
         else
         {
             menu.StartMainMenu();
         }
         return;
     }
     game.OnRenderFrame(dt);
 }
예제 #2
0
    public override void Render(float dt)
    {
        if (!loaded)
        {
            menu.p.WebClientDownloadDataAsync("http://manicdigger.sourceforge.net/serverlistcsv.php", serverListAddress);
            loaded = true;
        }
        if (serverListAddress.done)
        {
            serverListAddress.done = false;
            menu.p.WebClientDownloadDataAsync(serverListAddress.GetString(menu.p), serverListCsv);
        }
        if (serverListCsv.done)
        {
            loading            = false;
            serverListCsv.done = false;
            for (int i = 0; i < serversOnListCount; i++)
            {
                serversOnList[i]  = null;
                thumbResponses[i] = null;
            }
            IntRef   serversCount = new IntRef();
            string[] servers      = menu.p.StringSplit(serverListCsv.GetString(menu.p), "\n", serversCount);
            for (int i = 0; i < serversCount.value; i++)
            {
                IntRef   ssCount = new IntRef();
                string[] ss      = menu.p.StringSplit(servers[i], "\t", ssCount);
                if (ssCount.value < 10)
                {
                    continue;
                }
                ServerOnList s = new ServerOnList();
                s.hash           = ss[0];
                s.name           = menu.p.DecodeHTMLEntities(ss[1]);
                s.motd           = menu.p.DecodeHTMLEntities(ss[2]);
                s.port           = menu.p.IntParse(ss[3]);
                s.ip             = ss[4];
                s.version        = ss[5];
                s.users          = menu.p.IntParse(ss[6]);
                s.max            = menu.p.IntParse(ss[7]);
                s.gamemode       = ss[8];
                s.players        = ss[9];
                serversOnList[i] = s;
            }
        }

        GamePlatform p = menu.p;

        float scale = menu.GetScale();

        back.x     = 40 * scale;
        back.y     = p.GetCanvasHeight() - 104 * scale;
        back.sizex = 256 * scale;
        back.sizey = 64 * scale;

        connect.x     = p.GetCanvasWidth() / 2 - 300 * scale;
        connect.y     = p.GetCanvasHeight() - 104 * scale;
        connect.sizex = 256 * scale;
        connect.sizey = 64 * scale;

        connectToIp.x     = p.GetCanvasWidth() / 2 - 0 * scale;
        connectToIp.y     = p.GetCanvasHeight() - 104 * scale;
        connectToIp.sizex = 256 * scale;
        connectToIp.sizey = 64 * scale;

        refresh.x     = p.GetCanvasWidth() / 2 + 350 * scale;
        refresh.y     = p.GetCanvasHeight() - 104 * scale;
        refresh.sizex = 256 * scale;
        refresh.sizey = 64 * scale;

        pageUp.x     = p.GetCanvasWidth() - 94 * scale;
        pageUp.y     = 100 * scale + (serversPerPage - 1) * 70 * scale;
        pageUp.sizex = 64 * scale;
        pageUp.sizey = 64 * scale;
        pageUp.image = "serverlist_nav_down.png";

        pageDown.x     = p.GetCanvasWidth() - 94 * scale;
        pageDown.y     = 100 * scale;
        pageDown.sizex = 64 * scale;
        pageDown.sizey = 64 * scale;
        pageDown.image = "serverlist_nav_up.png";

        loggedInName.x     = p.GetCanvasWidth() - 228 * scale;
        loggedInName.y     = 32 * scale;
        loggedInName.sizex = 128 * scale;
        loggedInName.sizey = 32 * scale;
        if (loggedInName.text == "")
        {
            if (p.GetPreferences().GetString("Password", "") != "")
            {
                loggedInName.text = p.GetPreferences().GetString("Username", "Invalid");
            }
        }
        logout.visible = loggedInName.text != "";

        logout.x     = p.GetCanvasWidth() - 228 * scale;
        logout.y     = 62 * scale;
        logout.sizex = 128 * scale;
        logout.sizey = 32 * scale;
        logout.text  = "Logout";

        menu.DrawBackground();
        menu.DrawText(title, menu.fontMenuHeading, p.GetCanvasWidth() / 2, 10, TextAlign.Center, TextBaseline.Top);
        menu.DrawText(p.IntToString(page + 1), fontDefault, p.GetCanvasWidth() - 68 * scale, p.GetCanvasHeight() / 2, TextAlign.Center, TextBaseline.Middle);

        if (loading)
        {
            menu.DrawText(menu.lang.Get("MainMenu_MultiplayerLoading"), fontDefault, 100 * scale, 50 * scale, TextAlign.Left, TextBaseline.Top);
        }

        UpdateThumbnails();
        for (int i = 0; i < serverButtonsCount; i++)
        {
            serverButtons[i].visible = false;
        }

        serversPerPage = menu.p.FloatToInt((menu.p.GetCanvasHeight() - (2 * 100 * scale)) / 70 * scale);
        if (serversPerPage <= 0)
        {
            // Do not let this get negative
            serversPerPage = 1;
        }
        for (int i = 0; i < serversPerPage; i++)
        {
            int index = i + (serversPerPage * page);
            if (index > serversOnListCount)
            {
                //Reset to first page
                page  = 0;
                index = i + (serversPerPage * page);
            }
            ServerOnList s = serversOnList[index];
            if (s == null)
            {
                continue;
            }
            string t = menu.p.StringFormat2("{1}", menu.p.IntToString(index), s.name);
            t = menu.p.StringFormat2("{0}\n{1}", t, s.motd);
            t = menu.p.StringFormat2("{0}\n{1}", t, s.gamemode);
            t = menu.p.StringFormat2("{0}\n{1}", t, menu.p.IntToString(s.users));
            t = menu.p.StringFormat2("{0}/{1}", t, menu.p.IntToString(s.max));
            t = menu.p.StringFormat2("{0}\n{1}", t, s.version);

            serverButtons[i].text        = t;
            serverButtons[i].x           = 100 * scale;
            serverButtons[i].y           = 100 * scale + i * 70 * scale;
            serverButtons[i].sizex       = p.GetCanvasWidth() - 200 * scale;
            serverButtons[i].sizey       = 64 * scale;
            serverButtons[i].visible     = true;
            serverButtons[i].buttonStyle = ButtonStyle.ServerEntry;
            if (s.thumbnailError)
            {
                //Server did not respond to ServerQuery. Maybe not reachable?
                serverButtons[i].description = "Server did not respond to query!";
            }
            else
            {
                serverButtons[i].description = null;
            }
            if (s.thumbnailFetched && !s.thumbnailError)
            {
                serverButtons[i].image = menu.p.StringFormat("serverlist_entry_{0}.png", s.hash);
            }
            else
            {
                serverButtons[i].image = "serverlist_entry_noimage.png";
            }
        }
        UpdateScrollButtons();
        DrawWidgets();
        DrawServerWidgets();
    }