Only connect to one test server, take in authentication details on Connection construction

This commit is contained in:
Tristan B. Kildaire 2020-10-17 15:58:09 +02:00
parent fde6ce576b
commit 5d76b434cb
2 changed files with 28 additions and 8 deletions

View File

@ -20,16 +20,18 @@ public final class Connection : Thread
private DClient client;
private Address address;
private string[] auth;
/* TODO: Check if we need to protect */
/* TODO: So far usage is in signal handlers (mutex safved) and within te-tl lock for notifications */
private string currentChannel;
this(GUI gui, Address address)
this(GUI gui, Address address, string[] auth)
{
super(&worker);
this.gui = gui;
this.address = address;
this.auth = auth;
start();
}
@ -41,7 +43,7 @@ public final class Connection : Thread
te();
box = getChatPane();
gui.notebook.add(box);
gui.notebook.setTabLabelText(box, "user@"~address.toString());
gui.notebook.setTabLabelText(box, auth[0]~"@"~address.toString());
gui.notebook.showAll();
tl();
@ -50,7 +52,7 @@ public final class Connection : Thread
* Connects and logs in
*/
client = new DClient(address);
client.auth("bru", "kak"); /* TODO: DO this without auth (the list in the loop, crahses server) */
client.auth(auth[0], auth[1]); /* TODO: DO this without auth (the list in the loop, crahses server) */
/* Display all channels */
channelList();
@ -229,18 +231,19 @@ public final class Connection : Thread
userBox.add(new Label("Users"));
userBox.add(users);
textArea = new ListBox();
box.add(channelBox);
box.add(textArea);
box.add(userBox);
box.packEnd(userBox,0,0,0);
return box;
}

View File

@ -11,6 +11,7 @@ import gtk.Box;
import gtk.Menu;
import gtk.MenuItem;
import std.stdio;
import gtk.Statusbar;
import Connection;
import std.socket;
@ -22,6 +23,8 @@ public class GUI : Thread
private MenuBar menuBar;
public Notebook notebook;
private Statusbar statusBar;
private Connection[] connections;
@ -53,8 +56,10 @@ public class GUI : Thread
/* Test adding a connection */
for(uint i = 0; i < 5; i++)
{
connections ~= new Connection(this, parseAddress("0.0.0.0", 7777));
// connections ~= new Connection(this, parseAddress("0.0.0.0", 7777));
}
connections ~= new Connection(this, parseAddress("0.0.0.0", 7777), ["testGustav1", "bruh"]);
}
@ -90,6 +95,9 @@ public class GUI : Thread
box.add(menuBar);
notebook = new Notebook();
box.add(notebook);
statusBar = new Statusbar();
statusBar.add(new Label("Gustav: Bruh"));
box.packEnd(statusBar, 0, 0, 0);
//notebook.add(createServerTab());
@ -116,6 +124,13 @@ public class GUI : Thread
Menu gustavMenu = new Menu();
gustavMenuItem.setSubmenu(gustavMenu);
/* Connect option */
MenuItem connectItem = new MenuItem();
connectItem.setLabel("Connect");
connectItem.addOnActivate(&exitButton);
gustavMenu.add(connectItem);
/* Exit option */
MenuItem exitItem = new MenuItem();
exitItem.setLabel("Exit");
exitItem.addOnActivate(&exitButton);
@ -123,6 +138,8 @@ public class GUI : Thread
/* Add all menues */
menuBar.add(gustavMenuItem);