1
0
mirror of https://github.com/deavmi/birchwood synced 2024-09-20 13:43:19 +02:00
- Just import `birchwood.config` package rather
- Call `setDefaults(this.connInfo)` to assign default `db` values
- `nick(string)` will now fetch the maximum nickname length and ensure the provided nickname is in said bounds, if not then a `BirchwoodException` with `ErrorType` `NICKNAME_TOO_LONG` is thrown

Unit tests

- Updated unit test to test the updated value of `MAXNICKLEN` (which on BonoboNET is 30)
This commit is contained in:
Tristan B. Velloza Kildaire 2023-03-25 13:38:49 +02:00
parent 9ca98ac664
commit ea3f6ec5cb

View File

@ -8,7 +8,7 @@ import core.sync.mutex : Mutex;
import core.thread : Thread, dur; import core.thread : Thread, dur;
import std.string; import std.string;
import eventy : EventyEvent = Event, Engine, EventType, Signal; import eventy : EventyEvent = Event, Engine, EventType, Signal;
import birchwood.config : ConnectionInfo; import birchwood.config;
import birchwood.client.exceptions : BirchwoodException, ErrorType; import birchwood.client.exceptions : BirchwoodException, ErrorType;
import birchwood.protocol.messages : Message, encodeMessage, decodeMessage, isValidText; import birchwood.protocol.messages : Message, encodeMessage, decodeMessage, isValidText;
@ -80,6 +80,11 @@ public class Client : Thread
*/ */
this.receiver = new ReceiverThread(this); this.receiver = new ReceiverThread(this);
this.sender = new SenderThread(this); this.sender = new SenderThread(this);
/**
* Set defaults in db
*/
setDefaults(this.connInfo);
} }
/** /**
@ -211,11 +216,23 @@ public class Client : Thread
{ {
/* Ensure no illegal characters in nick name */ /* Ensure no illegal characters in nick name */
if(isValidText(nickname)) if(isValidText(nickname))
{
// TODO: We could investigate this later if we want to be safer
ulong maxNickLen = connInfo.getDB!(ulong)("MAXNICKLEN");
/* If the username's lenght is within the allowed bounds */
if(nickname.length <= maxNickLen)
{ {
/* Set the nick */ /* Set the nick */
Message nickMessage = new Message("", "NICK", nickname); Message nickMessage = new Message("", "NICK", nickname);
sendMessage(nickMessage); sendMessage(nickMessage);
} }
/* If not */
else
{
throw new BirchwoodException(ErrorType.NICKNAME_TOO_LONG);
}
}
else else
{ {
throw new BirchwoodException(ErrorType.ILLEGAL_CHARACTERS); throw new BirchwoodException(ErrorType.ILLEGAL_CHARACTERS);
@ -1176,6 +1193,21 @@ public class Client : Thread
*/ */
client.leaveChannel(["#birchwoodLeave2"]); client.leaveChannel(["#birchwoodLeave2"]);
/**
* Definately by now we would have learnt the new MAXNICLEN
* which on BonoboNET is 30, hence the below should work
*/
try
{
client.nick("birchwood123456789123456789123");
assert(true);
}
catch(BirchwoodException e)
{
assert(false);
}
// TODO: Don't forget to re-enable this when done testing! // TODO: Don't forget to re-enable this when done testing!
Thread.sleep(dur!("seconds")(15)); Thread.sleep(dur!("seconds")(15));
client.quit(); client.quit();