add hacky tox add by id + use ips instead of dns names for bsnodes and relays

This commit is contained in:
Green Sky 2023-10-20 21:40:45 +02:00
parent dce42b866a
commit 869edb8d84
No known key found for this signature in database
7 changed files with 144 additions and 4 deletions

View File

@ -55,6 +55,9 @@ add_executable(tomato
./settings_window.hpp
./settings_window.cpp
./tox_ui_utils.hpp
./tox_ui_utils.cpp
./chat_gui4.hpp
./chat_gui4.cpp
)

View File

@ -2,7 +2,6 @@
#include "./file_selector.hpp"
#include <cstdio>
#include <solanaceae/message3/components.hpp>
#include <solanaceae/tox_messages/components.hpp>
#include <solanaceae/contact/components.hpp>
@ -22,6 +21,7 @@
#include <vector>
#include <chrono>
#include <ctime>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <sstream>

View File

@ -19,7 +19,8 @@ MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path, std::stri
tam(rmm, cr, conf),
sdlrtu(renderer_),
cg(conf, rmm, cr, sdlrtu),
sw(conf)
sw(conf),
tuiu(tc, conf)
{
tel.subscribeAll(tc);
@ -111,6 +112,7 @@ Screen* MainScreen::poll(bool& quit) {
cg.render();
sw.render();
tuiu.render();
if constexpr (false) {
ImGui::ShowDemoWindow();

View File

@ -22,6 +22,7 @@
#include "./sdlrenderer_texture_uploader.hpp"
#include "./chat_gui4.hpp"
#include "./settings_window.hpp"
#include "./tox_ui_utils.hpp"
#include <string>
#include <iostream>
@ -59,6 +60,7 @@ struct MainScreen final : public Screen {
ChatGui4 cg;
SettingsWindow sw;
ToxUIUtils tuiu;
MainScreen(SDL_Renderer* renderer_, std::string save_path, std::string save_password, std::vector<std::string> plugins);
~MainScreen(void);

View File

@ -91,9 +91,16 @@ ToxClient::ToxClient(std::string_view save_path, std::string_view save_password)
{
// TODO: more/diff nodes
// you can change or add your own bs and tcprelays here, ideally closer to you
{"tox.plastiras.org", 443, "8E8B63299B3D520FB377FE5100E65E3322F7AE5B20A0ACED2981769FC5B43725", {}}, // LU tha14
{"tox2.plastiras.org", 33445, "B6626D386BE7E3ACA107B46F48A5C4D522D29281750D44A0CBA6A2721E79C951", {}}, // DE tha14
//{"tox.plastiras.org", 33445, "8E8B63299B3D520FB377FE5100E65E3322F7AE5B20A0ACED2981769FC5B43725", {}}, // LU tha14
{"104.244.74.69", 443, "8E8B63299B3D520FB377FE5100E65E3322F7AE5B20A0ACED2981769FC5B43725", {}}, // LU tha14
{"104.244.74.69", 33445, "8E8B63299B3D520FB377FE5100E65E3322F7AE5B20A0ACED2981769FC5B43725", {}}, // LU tha14
//{"tox2.plastiras.org", 33445, "B6626D386BE7E3ACA107B46F48A5C4D522D29281750D44A0CBA6A2721E79C951", {}}, // DE tha14
//{"tox4.plastiras.org", 33445, "836D1DA2BE12FE0E669334E437BE3FB02806F1528C2B2782113E0910C7711409", {}}, // MD tha14
{"37.221.66.161", 443, "836D1DA2BE12FE0E669334E437BE3FB02806F1528C2B2782113E0910C7711409", {}}, // MD tha14
{"37.221.66.161", 33445, "836D1DA2BE12FE0E669334E437BE3FB02806F1528C2B2782113E0910C7711409", {}}, // MD tha14
};
for (size_t i = 0; i < sizeof(nodes)/sizeof(DHT_node); i ++) {

105
src/tox_ui_utils.cpp Normal file
View File

@ -0,0 +1,105 @@
#include "./tox_ui_utils.hpp"
#include <solanaceae/toxcore/tox_interface.hpp>
#include <solanaceae/toxcore/utils.hpp>
#include <solanaceae/util/config_model.hpp>
#include <imgui/imgui.h>
#include <imgui/misc/cpp/imgui_stdlib.h>
ToxUIUtils::ToxUIUtils(
ToxI& t,
ConfigModelI& conf
) : _t(t), _conf(conf) {
}
void ToxUIUtils::render(void) {
{ // main window menubar injection
// assumes the window "tomato" was rendered already by cg
if (ImGui::Begin("tomato")) {
if (ImGui::BeginMenuBar()) {
ImGui::Separator();
if (ImGui::BeginMenu("Tox")) {
if (ImGui::MenuItem("add Friend by ID")) {
_show_add_friend_window = true;
}
if (ImGui::MenuItem("join Group by ID (ngc)")) {
_show_add_group_window = true;
}
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
}
ImGui::End();
}
if (_show_add_friend_window) {
if (ImGui::Begin("Tox add Friend", &_show_add_friend_window)) {
static char tox_id[TOX_ADDRESS_SIZE*2+1] = {};
ImGui::InputText("Tox ID", tox_id, TOX_ADDRESS_SIZE*2+1);
static std::string message = "Add me, I'm tomat";
ImGui::InputText("message", &message);
static Tox_Err_Friend_Add err = Tox_Err_Friend_Add::TOX_ERR_FRIEND_ADD_OK;
if (ImGui::Button("add")) {
// TODO: add string_view variant to utils
auto [_, err_r] = _t.toxFriendAdd(hex2bin(std::string{tox_id}), message);
err = err_r;
}
if (err != Tox_Err_Friend_Add::TOX_ERR_FRIEND_ADD_OK) {
ImGui::SameLine();
ImGui::Text("error adding friend (code: %d)", err);
}
}
ImGui::End();
}
if (_show_add_group_window) {
if (ImGui::Begin("Tox join Group", &_show_add_group_window)) {
ImGui::TextDisabled("NGC refers to the New DHT enabled Group Chats.");
ImGui::TextDisabled("Connecting via ID might take a very long time.");
static char chat_id[TOX_GROUP_CHAT_ID_SIZE*2+1] = {};
ImGui::InputText("chat ID", chat_id, TOX_GROUP_CHAT_ID_SIZE*2+1);
static std::string self_name = _conf.get_string("tox", "name").value_or("default_tomato");
ImGui::InputText("name to join with", &self_name);
static std::string password;
ImGui::InputText("password to join with", &password);
static Tox_Err_Group_Join err = Tox_Err_Group_Join::TOX_ERR_GROUP_JOIN_OK;
if (ImGui::Button("join")) {
auto [_, err_r] = _t.toxGroupJoin(
hex2bin(std::string{chat_id}), // TODO: add string_view variant to utils
self_name,
password
);
err = err_r;
{ // reset everything
for (size_t i = 0; i < sizeof(chat_id); i++) {
chat_id[i] = '\0';
}
self_name = _conf.get_string("tox", "name").value_or("default_tomato");
for (size_t i = 0; i < password.size(); i++) {
password.at(i) = '\0';
}
password.clear();
}
}
if (err != Tox_Err_Group_Join::TOX_ERR_GROUP_JOIN_OK) {
ImGui::SameLine();
ImGui::Text("error joining group (code: %d)", err);
}
}
ImGui::End();
}
}

21
src/tox_ui_utils.hpp Normal file
View File

@ -0,0 +1,21 @@
#pragma once
struct ToxI;
struct ConfigModelI;
class ToxUIUtils {
bool _show_add_friend_window {false};
bool _show_add_group_window {false};
ToxI& _t;
ConfigModelI& _conf;
public:
ToxUIUtils(
ToxI& t,
ConfigModelI& conf
);
void render(void);
};