void ChooseServerForm::Refresh(bool show_errors) {
    bool success = RequestInfos();

    ListControl *plstc = (ListControl *)GetControlPtr(kidcServerList);
    plstc->Clear();

    if (infos_.size() == 0) {
        if (success) {
            errorstr_ = "The multiplayer service is down for maintenance. Try again later.";
        }
        if (show_errors) {
            HtMessageBox(kfMbWhiteBorder, "Service Message",
                errorstr_.c_str());
        } else {
            errors_ = true;
        }
    } else {
        for (int i = 0; i < infos_.size(); i++) {
            const ServerInfo& info = infos_[i];
            const char *s = base::Format::ToString("%s\t%s\t%s\t%d",
                info.name.c_str(), info.location.c_str(), info.status.c_str(),
                info.player_count);
            plstc->Add(s);
        }
        plstc->Select(0, true);
    }
    ShowHide();
}
void DownloadMissionPackForm::ShowIndex(const PackId *ppackidSelect) {
    // Add entries to the list

    ListControl *plstc = (ListControl *)GetControlPtr(kidcMissionPackList);
    plstc->SetTabStops(x0_, x1_, x2_, x3_);
    plstc->SetTabFlags(kfLstTabCenter, kfLstTabEllipsis, kfLstTabCenterOn,
            kfLstTabCenterOn);
    plstc->Clear();
    int iSelect = 0;
    int cAdded = 0;
    int c = idxl_.GetCount();
    for (int i = 0; i < c; i++) {
        const IndexEntry *pentry = idxl_.GetEntry(i);

        // Show either single player packs, or multiplayer packs.
        // If a pack has both single and multiplayer missions, show
        // these in both cases.

        if (pentry->packid.id != PACKID_CUSTOMURL) {
            if (fMultiplayer_) {
                if (pentry->cPlayersMax == 1) {
                    continue;
                }
            } else {
                if (pentry->cPlayersMin != 1) {
                    continue;
                }
            }
        }

        // Remember which entry to select

        if (iSelect == 0 && ppackidSelect != NULL) {
            if (memcmp(ppackidSelect, &pentry->packid,
                    sizeof(*ppackidSelect)) == 0) {
                iSelect = cAdded;
            }
        }

        plstc->Add(GetItemString(pentry), (void *)pentry);
        cAdded++;
    }

    if (cAdded > 0) {
        plstc->Select(iSelect, true, true);
    }
}
void DownloadMissionPackForm::ShowStatus(void *ctx, const char *psz) {
    if (ctx == CTX_INDEX) {
        ListControl *plstc = (ListControl *)GetControlPtr(kidcMissionPackList);
        plstc->Clear();
        plstc->SetTabStops(0);
        plstc->SetTabFlags(0);
        plstc->Add(psz, NULL);
    }

    if (ctx == CTX_INFO) {
        LabelControl *plbl =
                (LabelControl *)GetControlPtr(kidcMissionPackInfo);
        plbl->SetText((char *)psz);
    }

    // Force the frame draw, since this gets called while the main loop
    // is "asleep".
    gpmfrmm->DrawFrame(false);
}
void LobbyForm::OnTimeout(int id) {
    refresh_ = false;
    ListControl *plstc = (ListControl *)GetControlPtr(kidcRoomList);
    dword roomid = (dword)(pword)plstc->GetSelectedItemData();
    if (!selected_main_) {
        roomid = kroomidMain;
    }
    plstc->Clear();
    RoomMap::iterator it = map_.begin();
    for (; it != map_.end(); it++) {
        RoomInfo& info = it->second;
        const char *s;
        if (info.priv) {
            s = base::Format::ToString("\t%s (%d %s, %d %s)\tPRIVATE",
                    info.name.c_str(), info.cPlayers,
                    info.cPlayers == 1 ? "player" : "players",
                    info.cGames,
                    info.cGames == 1 ? "game" : "games");
        } else {
            s = base::Format::ToString("\t%s (%d %s, %d %s)",
                    info.name.c_str(), info.cPlayers,
                    info.cPlayers == 1 ? "player" : "players",
                    info.cGames,
                    info.cGames == 1 ? "game" : "games");
        }
        plstc->Add(s, (void *)(uintptr_t)info.roomid);
    }
    int selected = FindIndex(roomid);
    if (selected < 0 && map_.size() != 0) {
        plstc->Select(0, true, true);
    } else {
        plstc->Select(selected, true);
        selected_main_ = true;
    }
    Control *pctl = GetControlPtr(kidcJoinRoom);
    refresh_ = true;
    pctl->Show(plstc->GetSelectedItemIndex() >= 0);
}
bool CreateGameForm::DoModal(int *pnResult) {
    // Format the lists.
    
    int aidcList[] = { kidcChallengeList, kidcAddOnList };
    for (int i = 0; i < ARRAYSIZE(aidcList); i++) {
        ListControl *plstc = (ListControl *)GetControlPtr(aidcList[i]);
        m_aplstc[i] = plstc;
        Rect rc;
        plstc->GetRect(&rc);
        Font *pfnt = gapfnt[kifntShadow];
        int cxComplete = pfnt->GetTextExtent("Complete");
        int xTitle = rc.Width() / 2 - cxComplete * 3 / 2;
        plstc->SetTabStops(xTitle);
        plstc->SetTabFlags(kfLstTabEllipsis);
        plstc->SetFlags(plstc->GetFlags() | kfLstcKeepInteriorPositioning);
        plstc->Clear();
    }
    
    if (m_pml == NULL) {
        m_pml = CreateMissionList(NULL, kmltMultiplayer);
    }
    if (m_pml == NULL) {
        return false;
    }
    
    // If asked to find a certain mission, find it first to
    // see what type it is, and switch the radio button bar to
    // that type.
    
    int iPack = -1;
    int iMission = -1;
    int cLevels = m_pml->GetCount();
    for (int nLevel = 0; nLevel < cLevels; nLevel++) {
        MissionIdentifier miid;
        m_pml->GetMissionIdentifier(nLevel, &miid);
        if (memcmp(&miid.packid, &m_miidFind.packid,
                   sizeof(miid.packid)) == 0) {
            if (iPack == -1) {
                iPack = nLevel;
            }
            if (strcmp(miid.szLvlFilename,
                       m_miidFind.szLvlFilename) == 0) {
                iMission = nLevel;
                break;
            }
        }
    }
    if (iMission == -1) {
        iMission = iPack;
    }
    int iMissionSelect = iMission;
    
    // Init the lists
    
    MissionType mt = InitLists(iMissionSelect);
    SwitchToMissionType(mt);
    
    // Game Speed
    
    m_tGameSpeed = gtGameSpeed;
    if (m_tGameSpeed < 4)
        m_tGameSpeed = 4;
    SliderControl *psldr = (SliderControl *)GetControlPtr(kidcGameSpeed);
    psldr->SetRange(2, ARRAYSIZE(gatGameSpeeds) - 1 - 3);	// bring the extremes in a bit for multiplayer
    psldr->SetValue(8);
    for (int i = 0; i < ARRAYSIZE(gatGameSpeeds); i++) {
        if (gatGameSpeeds[i] == m_tGameSpeed) {
            psldr->SetValue(i);
            break;
        }
    }
    
    // Hide this label. If we're finding an Add-On mission, then
    // there are add-on missions and this label isn't meant to be visible.
    
    GetControlPtr(kidcAddOnMessage)->Show(false);
    
    UpdateLabels();
    
    gptra->SetCallback(this);
    bool fSuccess = ShellForm::DoModal(pnResult);
    gptra->SetCallback(NULL);
    delete m_pml;
    m_pml = NULL;
    return fSuccess;
}