mirror of
https://github.com/deavmi/birchwood
synced 2024-09-20 08:43:05 +02:00
- Implemented Message type to hold messages
- Create IRCEvent type - Print out information for handling of IRCEvent in the signal handler registered with Eventy - Finished initial message parser (splits into `from`, `command` and `params`)
This commit is contained in:
parent
e4bb38c766
commit
ce8dbd7f5e
@ -8,6 +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;
|
import eventy;
|
||||||
|
import birchwood.messages : Message;
|
||||||
|
|
||||||
// TODO: Remove this import
|
// TODO: Remove this import
|
||||||
import std.stdio : writeln;
|
import std.stdio : writeln;
|
||||||
@ -145,6 +146,9 @@ public class Client
|
|||||||
this(ConnectionInfo connInfo)
|
this(ConnectionInfo connInfo)
|
||||||
{
|
{
|
||||||
this.connInfo = connInfo;
|
this.connInfo = connInfo;
|
||||||
|
|
||||||
|
/* Set the client inside IRCEvent so all can access it when handling events */
|
||||||
|
IRCEvent.client = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
~this()
|
~this()
|
||||||
@ -153,23 +157,30 @@ public class Client
|
|||||||
}
|
}
|
||||||
|
|
||||||
class IRCEvent : Event
|
class IRCEvent : Event
|
||||||
|
{
|
||||||
|
/* The client itself */
|
||||||
|
private static __gshared Client client;
|
||||||
|
|
||||||
|
private Message msg;
|
||||||
|
|
||||||
|
this(ulong typeID, Message msg)
|
||||||
{
|
{
|
||||||
private string message;
|
super(typeID, null);
|
||||||
|
|
||||||
this(ulong typeID, ubyte[] payload)
|
this.msg = msg;
|
||||||
{
|
|
||||||
super(typeID, payload);
|
|
||||||
|
|
||||||
/* TODFO: actuially parse message here */
|
|
||||||
this.message = cast(string)payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string getMessage()
|
|
||||||
{
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Message getMessage()
|
||||||
|
{
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string toString()
|
||||||
|
{
|
||||||
|
return msg.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void initEvents()
|
private void initEvents()
|
||||||
{
|
{
|
||||||
/* TODO: For now we just register one signal type for all messages */
|
/* TODO: For now we just register one signal type for all messages */
|
||||||
@ -192,9 +203,12 @@ public class Client
|
|||||||
/* TODO: Insert cast here to our custoim type */
|
/* TODO: Insert cast here to our custoim type */
|
||||||
IRCEvent ircEvent = cast(IRCEvent)e;
|
IRCEvent ircEvent = cast(IRCEvent)e;
|
||||||
assert(ircEvent); //Should never fail, unless some BOZO regged multiple handles for 1 - wait idk does eventy do that even mmm
|
assert(ircEvent); //Should never fail, unless some BOZO regged multiple handles for 1 - wait idk does eventy do that even mmm
|
||||||
import std.stdio;
|
|
||||||
writeln("IRCEvent (id): "~to!(string)(ircEvent.id));
|
writeln("IRCEvent (id): "~to!(string)(ircEvent.id));
|
||||||
writeln("IRCEvent (payload): "~to!(string)(ircEvent.getMessage));
|
writeln("IRCEvent "~ircEvent.getMessage().toString());
|
||||||
|
|
||||||
|
|
||||||
|
writeln(IRCEvent.client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,35 +298,25 @@ public class Client
|
|||||||
// return null;
|
// return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void defaultHandler(string from, string command, string params)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// private
|
|
||||||
private void function() getHandler()
|
|
||||||
{
|
|
||||||
/* The chosen handler */
|
|
||||||
void function() handlerPtr;
|
|
||||||
|
|
||||||
|
|
||||||
return handlerPtr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TODO: Implement me */
|
/* TODO: Implement me */
|
||||||
|
/* TODO: This should be a static method in `birchwood.messages.Message`
|
||||||
|
* which geneartes a Message object for us
|
||||||
|
*/
|
||||||
private void parseReceivedMessage(string message)
|
private void parseReceivedMessage(string message)
|
||||||
{
|
{
|
||||||
/* TODO: testing */
|
/* TODO: testing */
|
||||||
Event eTest = new IRCEvent(1, cast(ubyte[])message);
|
|
||||||
engine.push(eTest);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* From */
|
||||||
|
string from;
|
||||||
|
|
||||||
/* Command */
|
/* Command */
|
||||||
string command;
|
string command;
|
||||||
|
|
||||||
|
/* Params */
|
||||||
|
string params;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Check if there is a PREFIX (according to RFC 1459) */
|
/* Check if there is a PREFIX (according to RFC 1459) */
|
||||||
if(message[0] == ':')
|
if(message[0] == ':')
|
||||||
{
|
{
|
||||||
@ -323,7 +327,7 @@ public class Client
|
|||||||
/* TODO: double check the condition */
|
/* TODO: double check the condition */
|
||||||
if(firstSpace > 0)
|
if(firstSpace > 0)
|
||||||
{
|
{
|
||||||
string from = message[1..firstSpace];
|
from = message[1..firstSpace];
|
||||||
|
|
||||||
writeln("from: "~from);
|
writeln("from: "~from);
|
||||||
|
|
||||||
@ -346,6 +350,18 @@ public class Client
|
|||||||
/* Extract the command */
|
/* Extract the command */
|
||||||
command = rem[0..idx];
|
command = rem[0..idx];
|
||||||
writeln("command: "~command);
|
writeln("command: "~command);
|
||||||
|
|
||||||
|
/* Params are everything till the end */
|
||||||
|
i = idx;
|
||||||
|
for(; i < rem.length; i++)
|
||||||
|
{
|
||||||
|
if(rem[i] != ' ')
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
params = rem[i..rem.length];
|
||||||
|
writeln("params: "~params);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -356,6 +372,16 @@ public class Client
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import birchwood.messages;
|
||||||
|
|
||||||
|
Message msg = new Message(from, command, message);
|
||||||
|
|
||||||
|
/* TODO: Set static in IRCEvent field for access to Client (and hence socket) */
|
||||||
|
/* TODO: This should be done in reeive handler me thinks, or rather
|
||||||
|
shouild return something not yet TRIGGER an event */
|
||||||
|
Event eTest = new IRCEvent(1, msg);
|
||||||
|
engine.push(eTest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Spawn a thread worker that reacts */
|
/* TODO: Spawn a thread worker that reacts */
|
||||||
@ -370,6 +396,8 @@ public class Client
|
|||||||
* It pays high priority to looking for a PING
|
* It pays high priority to looking for a PING
|
||||||
* message first and handling those and then doing
|
* message first and handling those and then doing
|
||||||
* a second pass for other messages
|
* a second pass for other messages
|
||||||
|
*
|
||||||
|
* TODO: Do decode here and triggering of events here
|
||||||
*/
|
*/
|
||||||
private void recvHandlerFunc()
|
private void recvHandlerFunc()
|
||||||
{
|
{
|
||||||
@ -400,6 +428,22 @@ public class Client
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: Plan of action
|
||||||
|
*
|
||||||
|
* 1. Firstly, we must run `parseReceivedMessage()` on the dequeued
|
||||||
|
* ping message (if any)
|
||||||
|
* 2. Then (if there was a PING) trigger said PING handler
|
||||||
|
* 3. Normal message handling; `parseReceivedMessage()` on one of the messages
|
||||||
|
* (make the dequeue amount configurable possibly)
|
||||||
|
* 4. Trigger generic handler
|
||||||
|
* 5. We might need to also have a queue for commands ISSUED and command-replies
|
||||||
|
* RECEIVED and then match those first and do something with them (tasky-esque)
|
||||||
|
* 6. We can just make a generic reply queue of these things - we have to maybe to this
|
||||||
|
* - we can cache or remember stuff when we get 353
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* If we found a PING */
|
/* If we found a PING */
|
||||||
if(pingMessage.length > 0)
|
if(pingMessage.length > 0)
|
||||||
@ -495,6 +539,13 @@ public class Client
|
|||||||
sendQueueLock.unlock();
|
sendQueueLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TODO: For commands with an expected reply */
|
||||||
|
// private SList!()
|
||||||
|
private Object ask()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool yes = true;
|
bool yes = true;
|
||||||
bool hasJoined = false;
|
bool hasJoined = false;
|
||||||
@ -539,6 +590,11 @@ public class Client
|
|||||||
Thread.sleep(dur!("seconds")(4));
|
Thread.sleep(dur!("seconds")(4));
|
||||||
this.socket.send((cast(ubyte[])"join #birchwoodtesting")~[cast(ubyte)13, cast(ubyte)10]);
|
this.socket.send((cast(ubyte[])"join #birchwoodtesting")~[cast(ubyte)13, cast(ubyte)10]);
|
||||||
hasJoined = true;
|
hasJoined = true;
|
||||||
|
|
||||||
|
import core.thread;
|
||||||
|
Thread.sleep(dur!("seconds")(2));
|
||||||
|
|
||||||
|
sendMessage("names");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,19 @@ module birchwood.messages;
|
|||||||
*/
|
*/
|
||||||
public class Message
|
public class Message
|
||||||
{
|
{
|
||||||
|
public string from;
|
||||||
|
public string command;
|
||||||
|
public string message;
|
||||||
|
|
||||||
private string messageRaw;
|
this(string from, string command, string message)
|
||||||
|
{
|
||||||
|
this.from = from;
|
||||||
|
this.command = command;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string toString()
|
||||||
|
{
|
||||||
|
return "(from: "~from~", command: "~command~", message: `"~message~"`)";
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user