remove SUCCESS, add INITIALIZED for use with validating socket connection
This commit is contained in:
parent
9ee2f208d7
commit
5aa9303fd3
@ -234,6 +234,9 @@ func (c *Client) Connect() error {
|
|||||||
c.state.reader = newDecoder(c.state.conn)
|
c.state.reader = newDecoder(c.state.conn)
|
||||||
c.state.writer = newEncoder(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() {
|
for _, event := range c.connectMessages() {
|
||||||
if err := c.write(event); err != nil {
|
if err := c.write(event); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -16,11 +16,12 @@ const (
|
|||||||
CTCP_ERRMSG = "ERRMSG"
|
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 (
|
const (
|
||||||
ALLEVENTS = "*" // trigger on all events
|
ALLEVENTS = "*" // trigger on all events
|
||||||
CONNECTED = "CONNECTED" // event command which can be used to start responding, after SUCCESS
|
CONNECTED = "CONNECTED" // when it's safe to send arbitrary commands (joins, list, who, etc), trailing is host:port
|
||||||
SUCCESS = "001" // RPL_WELCOME alias, assumes successful connection
|
INITIALIZED = "INIT" // verifies successful socket connection, trailing is host:port
|
||||||
)
|
)
|
||||||
|
|
||||||
// User/channel prefixes :: RFC1459
|
// User/channel prefixes :: RFC1459
|
||||||
|
@ -16,7 +16,7 @@ func (c *Client) registerHandlers() {
|
|||||||
c.Callbacks.mu.Lock()
|
c.Callbacks.mu.Lock()
|
||||||
|
|
||||||
// Built-in things that should always be supported.
|
// 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)
|
go handleConnect(c, e)
|
||||||
}))
|
}))
|
||||||
c.Callbacks.register(true, PING, CallbackFunc(handlePING))
|
c.Callbacks.register(true, PING, CallbackFunc(handlePING))
|
||||||
@ -76,7 +76,7 @@ func handleConnect(c *Client, e Event) {
|
|||||||
|
|
||||||
time.Sleep(2 * time.Second)
|
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
|
// nickCollisionHandler helps prevent the client from having conflicting
|
||||||
|
Loading…
Reference in New Issue
Block a user