Commit 4946a49e authored by jan.koester's avatar jan.koester
Browse files

test

parent 3384b822
Loading
Loading
Loading
Loading
+99 −15
Changes for plugins/gameinfo/gameinfo.cpp: 99 added lines, 15 removed lines.
Original line number Diff line number Diff line
@@ -112,34 +112,65 @@ namespace blogi {
            form.parse(req);

            std::string formAddr, formPort, formProtocol;
            bool hasForm = false;
            std::string delId;
            bool hasServerForm = false;
            std::string delServerId;
            std::string formProtoName;
            bool hasProtoForm = false;
            std::string delProtoId;

            for(const auto &cur : form.urlData()){
                if(cur.key=="server_addr"){
                    formAddr = cur.value;
                    hasForm = true;
                    hasServerForm = true;
                }else if(cur.key=="server_port"){
                    formPort = cur.value;
                    hasForm = true;
                    hasServerForm = true;
                }else if(cur.key=="server_protocol"){
                    formProtocol = cur.value;
                    hasForm = true;
                }else if(cur.key=="delete_id"){
                    delId = cur.value;
                    hasServerForm = true;
                }else if(cur.key=="delete_server_id"){
                    delServerId = cur.value;
                }else if(cur.key=="protocol_name"){
                    formProtoName = cur.value;
                    hasProtoForm = true;
                }else if(cur.key=="delete_protocol_id"){
                    delProtoId = cur.value;
                }
            }

            if(!delId.empty()){
            // Delete protocol
            if(!delProtoId.empty()){
                dbpp::SQL sql;
                dbpp::DBResult res;
                std::vector<char> buf;
                sql << "DELETE FROM gameserver WHERE id='" << sql.escaped(buf, delId.c_str()) << "'";
                sql << "DELETE FROM gameserver_protocols WHERE id='" << sql.escaped(buf, delProtoId.c_str()) << "'";
                Args->database[tid]->exec(sql,res);
                saved = true;
            }

            if(hasForm && !formAddr.empty() && !formPort.empty()){
            // Add protocol
            if(hasProtoForm && !formProtoName.empty()){
                dbpp::SQL sql;
                dbpp::DBResult res;
                std::vector<char> buf;
                sql << "INSERT INTO gameserver_protocols (pname) VALUES ('"
                    << sql.escaped(buf, formProtoName.c_str()) << "')";
                Args->database[tid]->exec(sql,res);
                saved = true;
            }

            // Delete server
            if(!delServerId.empty()){
                dbpp::SQL sql;
                dbpp::DBResult res;
                std::vector<char> buf;
                sql << "DELETE FROM gameserver WHERE id='" << sql.escaped(buf, delServerId.c_str()) << "'";
                Args->database[tid]->exec(sql,res);
                saved = true;
            }

            // Add server
            if(hasServerForm && !formAddr.empty() && !formPort.empty()){
                dbpp::SQL sql;
                dbpp::DBResult res;
                std::vector<char> buf;
@@ -159,12 +190,65 @@ namespace blogi {
                json_object_object_add(jroot, "message_type", json_object_new_string("success"));
            }

            // Existing servers list
            // --- Protocols section ---
            json_object *jprotocols = json_object_new_array();
            {
                dbpp::SQL sql;
                dbpp::DBResult res;
                sql << "SELECT id,pname FROM gameserver_protocols";
                int count = Args->database[tid]->exec(sql,res);
                for(int i = 0; i < count; ++i){
                    json_object *jp = json_object_new_object();
                    json_object_object_add(jp, "id", json_object_new_string(res[i][0]));
                    json_object_object_add(jp, "pname", json_object_new_string(res[i][1]));
                    json_object_array_add(jprotocols, jp);
                }
            }
            json_object_object_add(jroot, "protocols", jprotocols);

            // Add protocol form
            json_object *jprotoform = json_object_new_object();
            json_object_object_add(jprotoform, "method", json_object_new_string("POST"));
            json_object_object_add(jprotoform, "action", json_object_new_string(
                Args->config->buildurl("settings/gamestatus").c_str()));
            {
                json_object *jfields = json_object_new_array();
                json_object *jf = json_object_new_object();
                json_object_object_add(jf, "name", json_object_new_string("protocol_name"));
                json_object_object_add(jf, "label", json_object_new_string("Protocol Name"));
                json_object_object_add(jf, "type", json_object_new_string("text"));
                json_object_object_add(jf, "value", json_object_new_string(""));
                json_object_array_add(jfields, jf);
                json_object_object_add(jprotoform, "fields", jfields);
            }
            json_object_object_add(jprotoform, "submit", json_object_new_string(tr(_lang,"Add Protocol").c_str()));
            json_object_object_add(jroot, "protocol_form", jprotoform);

            // Delete protocol form
            json_object *jdelprotoform = json_object_new_object();
            json_object_object_add(jdelprotoform, "method", json_object_new_string("POST"));
            json_object_object_add(jdelprotoform, "action", json_object_new_string(
                Args->config->buildurl("settings/gamestatus").c_str()));
            {
                json_object *jfields = json_object_new_array();
                json_object *jf = json_object_new_object();
                json_object_object_add(jf, "name", json_object_new_string("delete_protocol_id"));
                json_object_object_add(jf, "label", json_object_new_string("Protocol ID to delete"));
                json_object_object_add(jf, "type", json_object_new_string("text"));
                json_object_object_add(jf, "value", json_object_new_string(""));
                json_object_array_add(jfields, jf);
                json_object_object_add(jdelprotoform, "fields", jfields);
            }
            json_object_object_add(jdelprotoform, "submit", json_object_new_string(tr(_lang,"Delete Protocol").c_str()));
            json_object_object_add(jroot, "delete_protocol_form", jdelprotoform);

            // --- Servers section ---
            json_object *jservers = json_object_new_array();
            {
                dbpp::SQL sql;
                dbpp::DBResult res;
                sql << "SELECT id,protocol,addr,port FROM gameserver";
                sql << "SELECT g.id,COALESCE(p.pname,'unknown'),g.addr,g.port FROM gameserver g "
                    << "LEFT JOIN gameserver_protocols p ON g.protocol=p.id";
                int count = Args->database[tid]->exec(sql,res);
                for(int i = 0; i < count; ++i){
                    json_object *js = json_object_new_object();
@@ -196,13 +280,13 @@ namespace blogi {

            addField("server_addr", "Server Address", "text", "");
            addField("server_port", "Server Port", "text", "");
            addField("server_protocol", "Protocol (0=HLDS)", "text", "0");
            addField("server_protocol", "Protocol ID", "text", "");

            json_object_object_add(jform, "fields", jfields);
            json_object_object_add(jform, "submit", json_object_new_string(tr(_lang,"Add Server").c_str()));
            json_object_object_add(jroot, "form", jform);

            // Delete form
            // Delete server form
            json_object *jdelform = json_object_new_object();
            json_object_object_add(jdelform, "method", json_object_new_string("POST"));
            json_object_object_add(jdelform, "action", json_object_new_string(
@@ -210,7 +294,7 @@ namespace blogi {
            json_object *jdelfields = json_object_new_array();
            {
                json_object *jf = json_object_new_object();
                json_object_object_add(jf, "name", json_object_new_string("delete_id"));
                json_object_object_add(jf, "name", json_object_new_string("delete_server_id"));
                json_object_object_add(jf, "label", json_object_new_string("Server ID to delete"));
                json_object_object_add(jf, "type", json_object_new_string("text"));
                json_object_object_add(jf, "value", json_object_new_string(""));
+21 −2
Changes for plugins/youtube/youtube.cpp: 21 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -222,6 +222,24 @@ namespace blogi {
            }
            json_object_object_add(jroot, "items", jchannels);

            // Existing videos list
            json_object *jvideos = json_object_new_array();
            {
                dbpp::SQL sql;
                dbpp::DBResult res;
                sql << "SELECT v.id,COALESCE(c.channelname,'unknown'),v.youtube_id FROM youtube_videos v "
                    << "LEFT JOIN youtube_channels c ON v.youtube_channels_pkey=c.id";
                int count = Args->database[tid]->exec(sql,res);
                for(int i = 0; i < count; ++i){
                    json_object *jv = json_object_new_object();
                    json_object_object_add(jv, "id", json_object_new_string(res[i][0]));
                    json_object_object_add(jv, "channelname", json_object_new_string(res[i][1]));
                    json_object_object_add(jv, "youtube_id", json_object_new_string(res[i][2]));
                    json_object_array_add(jvideos, jv);
                }
            }
            json_object_object_add(jroot, "videos", jvideos);

            // Add channel form
            json_object *jform = json_object_new_object();
            json_object_object_add(jform, "method", json_object_new_string("POST"));
@@ -311,7 +329,7 @@ namespace blogi {
            try{
                netplus::x509cert ycert;
                ycert.loadFromBuffer(ycert.pemCertToDer(GOOGLECA));
                libhttppp::HttpUrl yurl("hhtps://www.googleapis.com");
                libhttppp::HttpUrl yurl("https://www.googleapis.com");
                libhttppp::HttpClient clt(yurl);
             //   ycsock->setTimeout(10);

@@ -350,7 +368,8 @@ namespace blogi {
                ytems = json_object_object_get(youindex,"items");
                int fcount = json_object_array_length(ytems);

                sql << "delete from youtube_videos where channel_id='" << channel_id <<"';";
                sql.clear();
                sql << "delete from youtube_videos where youtube_channels_pkey='" << channel_id <<"'";
                Args->database[tid]->exec(sql,dbres);

                for(int i =0; i<fcount; ++i) {
+87 −0
Changes for src/blogi.cpp: 87 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -912,6 +912,93 @@ static void renderSettingsJson(json_object *jroot, libhtmlpp::HtmlString &out, c
        out << "<div class=\"set-html\">" << json_object_get_string(jhtml) << "</div>";
    }

    // Render item arrays as tables (items, protocols, videos, etc.)
    auto renderItemArray = [&](const char *key, const char *heading){
        json_object *jarr = nullptr;
        if(!json_object_object_get_ex(jroot, key, &jarr)) return;
        if(json_object_get_type(jarr) != json_type_array) return;
        int alen = json_object_array_length(jarr);
        if(alen < 1) return;

        if(heading) out << "<h4 class=\"set-heading\">" << heading << "</h4>";
        out << "<table class=\"set-table\"><thead><tr>";

        // Collect headers from first item's keys
        json_object *first = json_object_array_get_idx(jarr, 0);
        std::vector<std::string> cols;
        json_object_object_foreach(first, k, v){
            cols.push_back(k);
            out << "<th>" << k << "</th>";
        }
        out << "</tr></thead><tbody>";
        for(int i = 0; i < alen; ++i){
            json_object *jrow = json_object_array_get_idx(jarr, i);
            out << "<tr>";
            for(auto &c : cols){
                json_object *jval = nullptr;
                json_object_object_get_ex(jrow, c.c_str(), &jval);
                out << "<td>" << (jval ? json_object_get_string(jval) : "") << "</td>";
            }
            out << "</tr>";
        }
        out << "</tbody></table>";
    };

    renderItemArray("protocols", "Protocols");
    renderItemArray("items", "Items");
    renderItemArray("videos", "Videos");

    // Render additional named forms (delete_form, sync_form, protocol_form, delete_protocol_form, etc.)
    auto renderExtraForm = [&](const char *key){
        json_object *jxform = nullptr;
        if(!json_object_object_get_ex(jroot, key, &jxform)) return;

        json_object *jmethod=nullptr, *jaction=nullptr;
        json_object_object_get_ex(jxform, "method", &jmethod);
        json_object_object_get_ex(jxform, "action", &jaction);

        out << "<form class=\"set-form\" style=\"margin-top:16px;\" method=\""
            << (jmethod ? json_object_get_string(jmethod) : "POST") << "\"";
        if(jaction) out << " action=\"" << json_object_get_string(jaction) << "\"";
        out << ">";

        json_object *jfields = nullptr;
        if(json_object_object_get_ex(jxform, "fields", &jfields)){
            int flen = json_object_array_length(jfields);
            for(int f=0; f<flen; ++f){
                json_object *jf = json_object_array_get_idx(jfields, f);
                json_object *jname=nullptr, *jtype=nullptr, *jlabel=nullptr, *jvalue=nullptr;
                json_object_object_get_ex(jf, "name", &jname);
                json_object_object_get_ex(jf, "type", &jtype);
                json_object_object_get_ex(jf, "label", &jlabel);
                json_object_object_get_ex(jf, "value", &jvalue);
                const char *type = jtype ? json_object_get_string(jtype) : "text";
                const char *name = jname ? json_object_get_string(jname) : "";
                const char *value = jvalue ? json_object_get_string(jvalue) : "";
                if(strcmp(type,"hidden")==0){
                    out << "<input type=\"hidden\" name=\"" << name << "\" value=\"" << value << "\" />";
                    continue;
                }
                out << "<div class=\"set-field\">";
                if(jlabel) out << "<label class=\"set-label\">" << json_object_get_string(jlabel) << "</label>";
                out << "<input class=\"set-input\" type=\"" << type << "\" name=\"" << name << "\" value=\"" << value << "\" />";
                out << "</div>";
            }
        }
        json_object *jsubmit = nullptr;
        if(json_object_object_get_ex(jxform, "submit", &jsubmit)){
            out << "<div class=\"set-actions\" style=\"margin-top:8px;\">"
                << "<button class=\"set-btn\" type=\"submit\">" << json_object_get_string(jsubmit) << "</button>"
                << "</div>";
        }
        out << "</form>";
    };

    renderExtraForm("protocol_form");
    renderExtraForm("delete_protocol_form");
    renderExtraForm("delete_form");
    renderExtraForm("sync_form");

    // Standalone links (action buttons like "New Navigation")
    json_object *jlinks = nullptr;
    if(json_object_object_get_ex(jroot, "links", &jlinks)){