1
0
mirror of https://github.com/deavmi/birchwood synced 2024-09-20 09:23:38 +02:00

ConnectionInfo

- Made field `nickname` public
- Added public fields `username` and `realname`
- Updated constructor to take in additional parameters `username` and `realname`

Client

- Calling `connect()` on a `Client` object will now call `doAuth()` which will do `/NICK` and `/USER` for you automatically (no need to do it manually anymore)
- The newly added `doAuth()` will take `hostname=username` from `connInfo.username`, it will set `servername` to `"bogus.net"` and `realname==connInfo.realname`
- Added `user(username, hostname, servername, realname)`
This commit is contained in:
Tristan B. Velloza Kildaire 2023-03-25 14:11:03 +02:00
parent ea3f6ec5cb
commit fa9de6dad5
2 changed files with 51 additions and 12 deletions

View File

@ -813,6 +813,9 @@ public class Client : Thread
/* Start the socket read-decode loop */
this.start();
// TODO: We should add a call to NICK followed by USER here
doAuth();
}
catch(SocketOSException e)
{
@ -826,6 +829,26 @@ public class Client : Thread
}
}
private void doAuth()
{
Thread.sleep(dur!("seconds")(2));
nick(connInfo.nickname);
Thread.sleep(dur!("seconds")(2));
// TODO: Note I am making hostname the same as username always (is this okay?)
// TODO: Note I am making the servername always bogus.net
user(connInfo.username, connInfo.username, "bogus.net", connInfo.realname);
}
public void user(string username, string hostname, string servername, string realname)
{
// TODO: Implement me properly with all required checks
/* User message */
Message userMessage = new Message("", "USER", username~" "~hostname~" "~servername~" "~":"~realname);
sendMessage(userMessage);
}
/**
* Adds a given message onto the receieve queue for
@ -1067,7 +1090,7 @@ public class Client : Thread
//freenode: 149.28.246.185
//snootnet: 178.62.125.123
//bonobonet: fd08:8441:e254::5
ConnectionInfo connInfo = ConnectionInfo.newConnection("worcester.community.networks.deavmi.assigned.network", 6667, "testBirchwood");
ConnectionInfo connInfo = ConnectionInfo.newConnection("worcester.community.networks.deavmi.assigned.network", 6667, "birchwood", "doggie", "Tristan B. Kildaire");
// // Set the fakelag to 1 second
// connInfo.setFakeLag(1);
@ -1080,12 +1103,16 @@ public class Client : Thread
// TODO: The below should all be automatic, maybe once IRCV3 is done
// ... we should automate sending in NICK and USER stuff
Thread.sleep(dur!("seconds")(2));
// client.command(new Message("", "NICK", "birchwood")); // TODO: add nickcommand
client.nick("birchwood");
// Thread.sleep(dur!("seconds")(2));
// client.nick("birchwood");
// Thread.sleep(dur!("seconds")(2));
// client.command(new Message("", "USER", "doggie doggie irc.frdeenode.net :Tristan B. Kildaire"));
// client.user("doggie", "doggie", "irc.frdeenode.net", "Tristan B. Kildaire");
Thread.sleep(dur!("seconds")(2));
client.command(new Message("", "USER", "doggie doggie irc.frdeenode.net :Tristan B. Kildaire"));
Thread.sleep(dur!("seconds")(4));
// client.command(new Message("", "JOIN", "#birchwood"));

View File

@ -21,7 +21,17 @@ public shared struct ConnectionInfo
/**
* Nickname to use
*/
private string nickname;
public string nickname;
/**
* Username
*/
public string username;
/**
* Real name
*/
public string realname;
/**
* Size to use to dequeue bytes
@ -59,11 +69,13 @@ public shared struct ConnectionInfo
* bulkReadSize = the dequeue read size
* quitMessage = the message to use when quitting
*/
private this(Address addrInfo, string nickname, ulong bulkReadSize = 20, string quitMessage = "birchwood client disconnecting...")
private this(Address addrInfo, string nickname, string username, string realname, ulong bulkReadSize = 20, string quitMessage = "birchwood client disconnecting...")
{
// NOTE: Not sure if much mutable in Address anyways
this.addrInfo = cast(shared Address)addrInfo;
this.nickname = nickname;
this.username = username;
this.realname = realname;
this.bulkReadSize = bulkReadSize;
this.quitMessage = quitMessage;
@ -167,7 +179,7 @@ public shared struct ConnectionInfo
*
* Returns: ConnectionInfo for this server
*/
public static ConnectionInfo newConnection(string hostname, ushort port, string nickname)
public static ConnectionInfo newConnection(string hostname, ushort port, string nickname, string username, string realname)
{
try
{
@ -183,7 +195,7 @@ public shared struct ConnectionInfo
/* TODO: Add feature to choose which address to use, prefer v4 or v6 type of thing */
Address chosenAddress = addrInfo[0];
return ConnectionInfo(chosenAddress, nickname);
return ConnectionInfo(chosenAddress, nickname, username, realname);
}
catch(SocketException e)
{
@ -201,7 +213,7 @@ public shared struct ConnectionInfo
{
try
{
newConnection("1.", 21, "deavmi");
newConnection("1.", 21, "deavmi", "thedeavmi", "Tristan Brice Birchwood Kildaire");
assert(false);
}
catch(BirchwoodException e)
@ -211,7 +223,7 @@ public shared struct ConnectionInfo
try
{
newConnection("1.1.1.1", 21, "");
newConnection("1.1.1.1", 21, "", "thedeavmi", "Tristan Brice Birchwood Kildaire");
assert(false);
}
catch(BirchwoodException e)