mirror of
https://github.com/deavmi/birchwood
synced 2024-09-20 14:23:38 +02:00
Merge branch 'master' into rfc2812
This commit is contained in:
commit
2c25a20ffb
@ -124,29 +124,62 @@ public final class ReceiverThread : Thread
|
|||||||
/* Lock the receieve queue */
|
/* Lock the receieve queue */
|
||||||
recvQueueLock.lock();
|
recvQueueLock.lock();
|
||||||
|
|
||||||
/* Message being analysed */
|
/* Parsed messages */
|
||||||
Message curMsg;
|
SList!(Message) currentMessageQueue;
|
||||||
|
|
||||||
/* Search for a PING */
|
/**
|
||||||
ubyte[] pingMessage;
|
* Parse all messages and save them
|
||||||
|
* into the above array
|
||||||
ulong pos = 0;
|
*/
|
||||||
foreach(ubyte[] message; recvQueue[])
|
foreach(ubyte[] message; recvQueue[])
|
||||||
{
|
{
|
||||||
// FIXME: Holy shit this is funny (see https://github.com/deavmi/birchwood/issues/13)
|
/* Decode the message */
|
||||||
if(indexOf(cast(string)message, "PING") > -1)
|
string decodedMessage = decodeMessage(message);
|
||||||
{
|
|
||||||
pingMessage = message;
|
|
||||||
recvQueue.linearRemoveElement(message);
|
|
||||||
|
|
||||||
import std.stdio;
|
/* Parse the message */
|
||||||
writeln("\n\nHOLY SHIT\n: "~cast(string)(message)~"\n\n");
|
Message parsedMessage = Message.parseReceivedMessage(decodedMessage);
|
||||||
|
|
||||||
|
/* Save it */
|
||||||
|
currentMessageQueue.insertAfter(currentMessageQueue[], parsedMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search for any PING messages, then store it if so
|
||||||
|
* and remove it so it isn't processed again later
|
||||||
|
*/
|
||||||
|
Message pingMessage;
|
||||||
|
foreach(Message curMsg; currentMessageQueue[])
|
||||||
|
{
|
||||||
|
import std.string : cmp;
|
||||||
|
if(cmp(curMsg.getCommand(), "PING") == 0)
|
||||||
|
{
|
||||||
|
currentMessageQueue.linearRemoveElement(curMsg);
|
||||||
|
pingMessage = curMsg;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If we have a PING then respond with a PONG
|
||||||
|
*/
|
||||||
|
if(pingMessage !is null)
|
||||||
|
{
|
||||||
|
logger.log("Found a ping: "~pingMessage.toString());
|
||||||
|
|
||||||
|
/* Extract the PING ID */
|
||||||
|
string pingID = pingMessage.getParams();
|
||||||
|
|
||||||
|
/* Spawn a PONG event */
|
||||||
|
EventyEvent pongEvent = new PongEvent(pingID);
|
||||||
|
client.engine.push(pongEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Plan of action
|
* TODO: Plan of action
|
||||||
@ -163,62 +196,26 @@ public final class ReceiverThread : Thread
|
|||||||
* - we can cache or remember stuff when we get 353
|
* - we can cache or remember stuff when we get 353
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* If we found a PING */
|
|
||||||
if(pingMessage.length > 0)
|
|
||||||
{
|
|
||||||
/* Decode the message and parse it */
|
|
||||||
curMsg = Message.parseReceivedMessage(decodeMessage(pingMessage));
|
|
||||||
logger.log("Found a ping: "~curMsg.toString());
|
|
||||||
|
|
||||||
// string ogMessage = cast(string)pingMessage;
|
|
||||||
// long idxSigStart = indexOf(ogMessage, ":")+1;
|
|
||||||
// long idxSigEnd = lastIndexOf(ogMessage, '\r');
|
|
||||||
|
|
||||||
// string pingID = ogMessage[idxSigStart..idxSigEnd];
|
|
||||||
string pingID = curMsg.getParams();
|
|
||||||
|
|
||||||
|
|
||||||
// this.socket.send(encodeMessage("PONG "~pingID));
|
|
||||||
// string messageToSend = "PONG "~pingID;
|
|
||||||
|
|
||||||
// sendMessage(messageToSend);
|
|
||||||
|
|
||||||
// logger.log("Ponged");
|
|
||||||
|
|
||||||
/* TODO: Implement */
|
|
||||||
// TODO: Remove the Eventy push and replace with a handler call (on second thought no)
|
|
||||||
EventyEvent pongEvent = new PongEvent(pingID);
|
|
||||||
client.engine.push(pongEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process each message remaining in the queue now
|
* Process each message remaining in the queue now
|
||||||
* till it is empty
|
* till it is empty
|
||||||
*/
|
*/
|
||||||
while(!recvQueue.empty())
|
while(!currentMessageQueue.empty())
|
||||||
{
|
{
|
||||||
ubyte[] message = recvQueue.front();
|
/* Get the frontmost Message */
|
||||||
|
Message curMsg = currentMessageQueue.front();
|
||||||
/* Decode message */
|
|
||||||
string messageNormal = decodeMessage(message);
|
|
||||||
|
|
||||||
recvQueue.linearRemoveElement(recvQueue.front());
|
|
||||||
|
|
||||||
// writeln("Normal message: "~messageNormal);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* TODO: Parse message and call correct handler */
|
|
||||||
curMsg = Message.parseReceivedMessage(messageNormal);
|
|
||||||
|
|
||||||
// TODO: Remove the Eventy push and replace with a handler call (on second thought no)
|
// TODO: Remove the Eventy push and replace with a handler call (on second thought no)
|
||||||
EventyEvent ircEvent = new IRCEvent(curMsg);
|
EventyEvent ircEvent = new IRCEvent(curMsg);
|
||||||
client.engine.push(ircEvent);
|
client.engine.push(ircEvent);
|
||||||
|
|
||||||
|
/* Remove the message from the queue */
|
||||||
|
currentMessageQueue.linearRemoveElement(curMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Clear the receive queue */
|
||||||
|
recvQueue.clear();
|
||||||
|
|
||||||
/* Unlock the receive queue */
|
/* Unlock the receive queue */
|
||||||
recvQueueLock.unlock();
|
recvQueueLock.unlock();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user