remove SUCCESS, add INITIALIZED for use with validating socket connection

This commit is contained in:
Liam Stanley 2017-02-05 07:42:59 -05:00
parent 9ee2f208d7
commit 5aa9303fd3
3 changed files with 10 additions and 6 deletions

@ -234,6 +234,9 @@ func (c *Client) Connect() error {
c.state.reader = newDecoder(c.state.conn)
c.state.writer = newEncoder(c.state.conn)
// Send a virtual event allowing hooks for successful socket connection.
c.Events <- &Event{Command: INITIALIZED, Trailing: c.Server()}
for _, event := range c.connectMessages() {
if err := c.write(event); err != nil {
return err

@ -16,11 +16,12 @@ const (
CTCP_ERRMSG = "ERRMSG"
)
// Misc constants for use with the client.
// Misc constants for use with the client. Most of these are "fake" events
// emitted/emulated by the client for various hooks.
const (
ALLEVENTS = "*" // trigger on all events
CONNECTED = "CONNECTED" // event command which can be used to start responding, after SUCCESS
SUCCESS = "001" // RPL_WELCOME alias, assumes successful connection
ALLEVENTS = "*" // trigger on all events
CONNECTED = "CONNECTED" // when it's safe to send arbitrary commands (joins, list, who, etc), trailing is host:port
INITIALIZED = "INIT" // verifies successful socket connection, trailing is host:port
)
// User/channel prefixes :: RFC1459

@ -16,7 +16,7 @@ func (c *Client) registerHandlers() {
c.Callbacks.mu.Lock()
// Built-in things that should always be supported.
c.Callbacks.register(true, SUCCESS, CallbackFunc(func(c *Client, e Event) {
c.Callbacks.register(true, RPL_WELCOME, CallbackFunc(func(c *Client, e Event) {
go handleConnect(c, e)
}))
c.Callbacks.register(true, PING, CallbackFunc(handlePING))
@ -76,7 +76,7 @@ func handleConnect(c *Client, e Event) {
time.Sleep(2 * time.Second)
c.Events <- &Event{Command: CONNECTED}
c.Events <- &Event{Command: CONNECTED, Trailing: c.Server()}
}
// nickCollisionHandler helps prevent the client from having conflicting