mirror of
https://github.com/deavmi/birchwood
synced 2024-09-20 13:43:19 +02:00
Merge branch 'master' into ping_pong_fix
This commit is contained in:
commit
f3b5246a1c
@ -71,30 +71,58 @@ public class Client : Thread
|
||||
//TODO: Do something here, tare downs
|
||||
}
|
||||
|
||||
// TODO: Investigate
|
||||
public ConnectionInfo getConnInfo()
|
||||
{
|
||||
return connInfo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* User overridable handler functions below
|
||||
*/
|
||||
* Called on reception of a channel message
|
||||
*
|
||||
* Params:
|
||||
* fullMessage = the channel message in its entirety
|
||||
* channel = the channel
|
||||
* msgBody = the body of the message
|
||||
*/
|
||||
public void onChannelMessage(Message fullMessage, string channel, string msgBody)
|
||||
{
|
||||
/* Default implementation */
|
||||
logger.log("Channel("~channel~"): "~msgBody);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on reception of a direct message
|
||||
*
|
||||
* Params:
|
||||
* fullMessage = the direct message in its entirety
|
||||
* nickname = the sender
|
||||
* msgBody = the body of the message
|
||||
*/
|
||||
public void onDirectMessage(Message fullMessage, string nickname, string msgBody)
|
||||
{
|
||||
/* Default implementation */
|
||||
logger.log("DirectMessage("~nickname~"): "~msgBody);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on generic commands
|
||||
*
|
||||
* Params:
|
||||
* commandReply = the generic message
|
||||
*/
|
||||
public void onGenericCommand(Message message)
|
||||
{
|
||||
/* Default implementation */
|
||||
logger.log("Generic("~message.getCommand()~", "~message.getFrom()~"): "~message.getParams());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on command replies
|
||||
*
|
||||
* Params:
|
||||
* commandReply = the command's reply
|
||||
*/
|
||||
public void onCommandReply(Message commandReply)
|
||||
{
|
||||
/* Default implementation */
|
||||
@ -105,8 +133,6 @@ public class Client : Thread
|
||||
* User operations (request-response type)
|
||||
*/
|
||||
|
||||
// TODO: Add joinChannels(strung[])
|
||||
|
||||
/**
|
||||
* Joins the requested channel
|
||||
*
|
||||
@ -138,6 +164,75 @@ public class Client : Thread
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Joins the requested channels
|
||||
*
|
||||
* Params:
|
||||
* channels = the channels to join
|
||||
* Throws:
|
||||
* BirchwoodException on invalid channel name
|
||||
*/
|
||||
public void joinChannel(string[] channels)
|
||||
{
|
||||
/* If single channel */
|
||||
if(channels.length == 1)
|
||||
{
|
||||
/* Join the channel */
|
||||
joinChannel(channels[0]);
|
||||
}
|
||||
/* If multiple channels */
|
||||
else if(channels.length > 1)
|
||||
{
|
||||
string channelLine = channels[0];
|
||||
|
||||
/* Ensure valid characters in first channel */
|
||||
if(isValidText(channelLine))
|
||||
{
|
||||
//TODO: Add check for #
|
||||
|
||||
/* Append on a trailing `,` */
|
||||
channelLine ~= ",";
|
||||
|
||||
for(ulong i = 1; i < channels.length; i++)
|
||||
{
|
||||
string currentChannel = channels[i];
|
||||
|
||||
/* Ensure the character channel is valid */
|
||||
if(isValidText(currentChannel))
|
||||
{
|
||||
//TODO: Add check for #
|
||||
|
||||
if(i == channels.length-1)
|
||||
{
|
||||
channelLine~=currentChannel;
|
||||
}
|
||||
else
|
||||
{
|
||||
channelLine~=currentChannel~",";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BirchwoodException(BirchwoodException.ErrorType.ILLEGAL_CHARACTERS);
|
||||
}
|
||||
}
|
||||
|
||||
/* Join multiple channels */
|
||||
Message joinMessage = new Message("", "JOIN", channelLine);
|
||||
sendMessage(joinMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BirchwoodException(BirchwoodException.ErrorType.ILLEGAL_CHARACTERS);
|
||||
}
|
||||
}
|
||||
/* If no channels provided at all (error) */
|
||||
else
|
||||
{
|
||||
throw new BirchwoodException(BirchwoodException.ErrorType.EMPTY_PARAMS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parts from a list of channel(s) in one go
|
||||
*
|
||||
@ -632,25 +727,6 @@ public class Client : Thread
|
||||
receiver.rq(message);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Sends a message to the server by enqueuing it on
|
||||
// * the client-side send queue
|
||||
// *
|
||||
// * Params:
|
||||
// * messageOut = the message to send
|
||||
// */
|
||||
// private void sendMessage(string messageOut)
|
||||
// {
|
||||
// // TODO: Do message splits here
|
||||
|
||||
|
||||
// /* Encode the mesage */
|
||||
// ubyte[] encodedMessage = encodeMessage(messageOut);
|
||||
|
||||
// /* Enqueue the message to the send queue */
|
||||
// sender.sq(encodedMessage);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Sends a message to the server by enqueuing it on
|
||||
* the client-side send queue.
|
||||
@ -873,6 +949,7 @@ public class Client : Thread
|
||||
|
||||
unittest
|
||||
{
|
||||
/* FIXME: Get domaina name resolution support */
|
||||
// ConnectionInfo connInfo = ConnectionInfo.newConnection("irc.freenode.net", 6667, "testBirchwood");
|
||||
//freenode: 149.28.246.185
|
||||
//snootnet: 178.62.125.123
|
||||
@ -899,9 +976,11 @@ public class Client : Thread
|
||||
client.joinChannel("#birchwood");
|
||||
// TODO: Add a joinChannels(string[])
|
||||
client.joinChannel("#birchwood2");
|
||||
client.joinChannel("#birchwoodLeave1");
|
||||
client.joinChannel("#birchwoodLeave2");
|
||||
client.joinChannel("#birchwoodLeave3");
|
||||
|
||||
client.joinChannel(["#birchwoodLeave1", "#birchwoodLeave2", "#birchwoodLeave3"]);
|
||||
// client.joinChannel("#birchwoodLeave1");
|
||||
// client.joinChannel("#birchwoodLeave2");
|
||||
// client.joinChannel("#birchwoodLeave3");
|
||||
|
||||
Thread.sleep(dur!("seconds")(2));
|
||||
client.command(new Message("", "NAMES", "")); // TODO: add names commdn
|
||||
|
@ -53,6 +53,13 @@ public final class ReceiverThread : Thread
|
||||
}
|
||||
|
||||
// TODO: Rename to `receiveQ`
|
||||
/**
|
||||
* Enqueues the raw message into the receieve queue
|
||||
* for eventual processing
|
||||
*
|
||||
* Params:
|
||||
* encodedMessage = the message to enqueue
|
||||
*/
|
||||
public void rq(ubyte[] encodedMessage)
|
||||
{
|
||||
/* Lock queue */
|
||||
|
@ -48,6 +48,13 @@ public final class SenderThread : Thread
|
||||
}
|
||||
|
||||
// TODO: Rename to `sendQ`
|
||||
/**
|
||||
* Enqueues the raw message into the send queue
|
||||
* for eventual sending
|
||||
*
|
||||
* Params:
|
||||
* encodedMessage = the message to enqueue
|
||||
*/
|
||||
public void sq(ubyte[] encodedMessage)
|
||||
{
|
||||
/* Lock queue */
|
||||
|
@ -1,6 +1,7 @@
|
||||
module birchwood.protocol;
|
||||
|
||||
public import birchwood.protocol.messages : Message;
|
||||
public import birchwood.protocol.constants : ReplyType;
|
||||
|
||||
// TODO: Look how to neaten up (if any)
|
||||
public import birchwood.protocol.formatting;
|
Loading…
Reference in New Issue
Block a user