mirror of
https://github.com/deavmi/birchwood
synced 2024-09-20 11:22:53 +02:00
Client
- 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:
parent
9ca98ac664
commit
ea3f6ec5cb
@ -8,7 +8,7 @@ import core.sync.mutex : Mutex;
|
||||
import core.thread : Thread, dur;
|
||||
import std.string;
|
||||
import eventy : EventyEvent = Event, Engine, EventType, Signal;
|
||||
import birchwood.config : ConnectionInfo;
|
||||
import birchwood.config;
|
||||
import birchwood.client.exceptions : BirchwoodException, ErrorType;
|
||||
import birchwood.protocol.messages : Message, encodeMessage, decodeMessage, isValidText;
|
||||
|
||||
@ -80,6 +80,11 @@ public class Client : Thread
|
||||
*/
|
||||
this.receiver = new ReceiverThread(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 */
|
||||
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 */
|
||||
Message nickMessage = new Message("", "NICK", nickname);
|
||||
sendMessage(nickMessage);
|
||||
}
|
||||
/* If not */
|
||||
else
|
||||
{
|
||||
throw new BirchwoodException(ErrorType.NICKNAME_TOO_LONG);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BirchwoodException(ErrorType.ILLEGAL_CHARACTERS);
|
||||
@ -1176,6 +1193,21 @@ public class Client : Thread
|
||||
*/
|
||||
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!
|
||||
Thread.sleep(dur!("seconds")(15));
|
||||
client.quit();
|
||||
|
Loading…
Reference in New Issue
Block a user