Example #1
0
void ServerDB::open(Fl_Preferences &prefs){
    AutoLocker<const ServerDB * const> locker(this);

    clear();

    char *uid_list;
    if(!prefs.get("sys.server_uids", uid_list, "")){
        prefs.set("sys.server_uids", "");
        free(uid_list);
        return;
    }

    const char **server_uids = FJ::CSV::ParseString(uid_list);
    free(uid_list);

    char *groups;
    GetAndExist(prefs, "sys.group_uids", groups, "");
    const char **group_uids = FJ::CSV::ParseString(groups);
    free(groups);

    for(int i = 0; group_uids[i]!=nullptr; i++){
        guts->groups.push_back(group_uids[i]);
    }

    FJ::CSV::FreeParse(group_uids);

    for(int i = 0; server_uids[i]!=nullptr; i++){
        struct ServerData *server = new ServerData();
        server->UID = server_uids[i];
        server->owner = this;
        LoadServer(server, prefs);

        for(std::vector<std::string>::const_iterator iter = server->group_UIDs.cbegin();
              iter != server->group_UIDs.cend(); iter++){
start:
            if(std::find(guts->groups.cbegin(), guts->groups.cend(), *iter)==guts->groups.cend()){
                guts->groups.push_back(*iter);
                goto start;
            }
        }

        push_back(ServerDataP(server));
    }

    // The individual items are now owned by the ServerData.
    free(server_uids);

    GetAndExist(prefs, "sys.global.nickname", guts->global.nick, "KashyyykUser");
    GetAndExist(prefs, "sys.global.username", guts->global.user, "KashyyykUser");
    GetAndExist(prefs, "sys.global.realname", guts->global.real, "KashyyykUser");

}
Example #2
0
int ScorebotInput::Load()
{
    LoadChannels();
    m_bot = wxGetApp().GetMainFrame()->GetScorebot();
    
    if (m_bot)
    {
        m_host = m_bot->GetHost();
        m_port = m_bot->GetPort();
        m_abbrev = m_bot->GetGame();
        GetSbsTitleIn()->SetValue(m_bot->GetTitle());
        GetSbsInterIn()->SetValue(m_bot->GetInterval());
        GetSbsChanIn()->SetStringSelection(m_bot->GetChannel());

        LoadServer();
    }

    if (m_bot && m_bot->IsRunning())
        GetSbsStatusOut()->SetLabel("Scorebot Running");
    else
    {
        GetSbsStatusOut()->SetLabel("Scorebot Stopped");

        //If scorebot stopped, load in the current server from the main frame.
        wxString host, abbrev;
        int port;
        QueryInput *qi = wxGetApp().GetMainFrame()->GetQueryInput();
        if (qi->GetCurrentServer(host, port, abbrev) && abbrev != "Unk")
        {
            m_host = host;
            m_port = port;
            m_abbrev = abbrev;
            LoadServer();
        }
        else
        {
            wxMessageBox("No or unknown server selected");
            return wxID_CANCEL;
        }

        GetSbsCustChk()->Enable(true);
    }

    //load custom list
    PyGetBotList(m_botlist);
    for (int i = 0; i < m_botlist.GetCount(); i++)
        GetSbsBnameIn()->Append(m_botlist[i].name, (void *) &m_botlist[i]);

    m_pybot = dynamic_cast<PyScoreBot *>(m_bot);
    if (m_pybot)
    {
        BotType *bt = NULL;
        for (int i = 0; i < m_botlist.GetCount(); i++)
        {
            if (m_pybot->Check(&m_botlist[i]))
                bt = &m_botlist[i];
        }

        //bot should be in the list
        wxASSERT(bt);
        
        GetSbsCustChk()->SetValue(true);
        GetSbsBnameIn()->SetStringSelection(bt->name);
        if (GetSbsCustChk()->IsEnabled())
            GetSbsBnameIn()->Enable(true);

        LoadOptions(bt);
    }

    return ShowModal();
}