aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/GtkGif.cpp4
-rw-r--r--src/UserSettingsWindow.cpp2
-rw-r--r--src/Window.cpp51
3 files changed, 50 insertions, 7 deletions
diff --git a/src/GtkGif.cpp b/src/GtkGif.cpp
index 76a6ebe..dc5cc53 100644
--- a/src/GtkGif.cpp
+++ b/src/GtkGif.cpp
@@ -18,7 +18,7 @@ namespace dchat
{
unsigned char *pixels = surface->get_data();
surface->flush();
- char *p = (char*)textureData;
+ unsigned char *p = (unsigned char*)textureData;
// TODO: Optimize this
for(int i = 0; i < surface->get_stride() * surface->get_height(); i += 4)
{
@@ -48,4 +48,4 @@ namespace dchat
cairo->set_source(surface, 0.0, 0.0);
cairo->mask(surface, 0.0, 0.0);
}
-} \ No newline at end of file
+}
diff --git a/src/UserSettingsWindow.cpp b/src/UserSettingsWindow.cpp
index ac53f7a..8c945ff 100644
--- a/src/UserSettingsWindow.cpp
+++ b/src/UserSettingsWindow.cpp
@@ -82,7 +82,7 @@ namespace dchat
avatarUrlEntry.set_hexpand(true);
rightPanel->attach_next_to(avatarUrlEntry, *avatarUrlLabel, Gtk::POS_BOTTOM, 2, 1);
- Gtk::Button *resetButton = Gtk::manage(new Gtk::Button("Rest"));
+ Gtk::Button *resetButton = Gtk::manage(new Gtk::Button("Reset"));
resetButton->set_halign(Gtk::ALIGN_END);
rightPanel->attach_next_to(*resetButton, avatarUrlEntry, Gtk::POS_BOTTOM, 1, 1);
resetButton->signal_clicked().connect([this]
diff --git a/src/Window.cpp b/src/Window.cpp
index 4c4aab6..5e4930f 100644
--- a/src/Window.cpp
+++ b/src/Window.cpp
@@ -10,6 +10,37 @@ namespace dchat
const int nodesPerColumn = 10;
const int nodesPerRow = 10;
+ static std::vector<std::string> getBootstrapNodesFromFile()
+ {
+ std::vector<std::string> result;
+ auto boostrapNodesConfigFile = Gio::File::create_for_path("bootstrap_nodes");
+ auto bootstrapNodesFileContent = boostrapNodesConfigFile->read()->read_bytes(1024 * 10, Glib::RefPtr<Gio::Cancellable>());
+ if(!bootstrapNodesFileContent)
+ throw std::runtime_error("Failed to read bootstrap_nodes file");
+
+ gsize start = 0;
+
+ gsize size = bootstrapNodesFileContent->get_size();
+ const unsigned char *data = (const unsigned char*)bootstrapNodesFileContent->get_data(size);
+ for(gsize i = 0; i < size; ++i)
+ {
+ unsigned char c = data[i];
+ if(c == ' ' || c == '\n' || c == '\r' || c == '\t')
+ {
+ gsize length = i - start;
+ if(length > 0)
+ result.push_back(std::string(&data[start], &data[start + length]));
+ start = i + 1;
+ }
+ }
+
+ gsize length = size - start;
+ if(length > 0)
+ result.push_back(std::string(&data[start], &data[start + length]));
+
+ return result;
+ }
+
Window::Window() :
chatWindow(this)
{
@@ -91,15 +122,28 @@ namespace dchat
windowNotification->show("Passwords do not match");
});
+ auto bootstrapNodes = getBootstrapNodesFromFile();
+ if(bootstrapNodes.empty())
+ throw std::runtime_error("No boostrap nodes in boostrap_nodes file");
+
+ std::string msg = "Connecting to first boostrap node: ";
+ msg += bootstrapNodes[0];
+ msg += ":27130";
+ windowNotification->show(msg);
+ std::string *bootstrapNode = new std::string(bootstrapNodes[0]);
+
RoomCallbackFuncs roomCallbackFuncs;
- roomCallbackFuncs.connectCallbackFunc = [this](std::shared_ptr<Rooms> rooms, const char *errMsg)
+ roomCallbackFuncs.connectCallbackFunc = [this, bootstrapNode](std::shared_ptr<Rooms> rooms, const char *errMsg)
{
this->rooms = rooms;
if(rooms)
{
loginWindow.show();
stack.set_visible_child(loginWindow);
- windowNotification->show("Connected to 83.252.53.188:27130");
+ std::string msg = "Connected to ";
+ msg += *bootstrapNode;
+ msg += ":27130";
+ windowNotification->show(msg);
loginWindow.loginUsernameInput.grab_focus();
}
else
@@ -138,8 +182,7 @@ namespace dchat
chatWindow.addInviteRequest(request);
};
- windowNotification->show("Connecting to 83.252.53.188:27130");
- Rooms::connect("83.252.53.188", 27130, roomCallbackFuncs);
+ Rooms::connect(bootstrapNode->c_str(), 27130, roomCallbackFuncs);
backgroundRng.seed(std::random_device()());
std::uniform_int_distribution<std::mt19937::result_type> sizeDeviationRand(0, 5);