|
|
|
|
@@ -28,6 +28,8 @@ type HubConnection struct {
|
|
|
|
|
connValid bool
|
|
|
|
|
sentOurHello bool
|
|
|
|
|
autoReconnect bool
|
|
|
|
|
|
|
|
|
|
supports map[string]struct{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Thread-safe user accessor.
|
|
|
|
|
@@ -67,10 +69,11 @@ func (this *HubConnection) UserCount() int {
|
|
|
|
|
|
|
|
|
|
func (this *HubConnection) userJoined_NameOnly(nick string) {
|
|
|
|
|
if !this.UserExists(nick) {
|
|
|
|
|
this.userLock.Lock()
|
|
|
|
|
defer this.userLock.Unlock()
|
|
|
|
|
|
|
|
|
|
this.userLock.Lock()
|
|
|
|
|
this.users[nick] = *NewUserInfo(nick)
|
|
|
|
|
this.userLock.Unlock() // Don't lock over a processEvent boundary
|
|
|
|
|
|
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_USER_JOINED, Nick: nick})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -78,14 +81,14 @@ func (this *HubConnection) userJoined_NameOnly(nick string) {
|
|
|
|
|
func (this *HubConnection) userJoined_Full(uinf *UserInfo) {
|
|
|
|
|
// n.b. also called when we get a replacement MyINFO for someone
|
|
|
|
|
this.userLock.Lock()
|
|
|
|
|
defer this.userLock.Unlock()
|
|
|
|
|
|
|
|
|
|
_, userExisted := this.users[uinf.Nick] // don't use UserExists as it would deadlock the mutex
|
|
|
|
|
|
|
|
|
|
this.users[uinf.Nick] = *uinf
|
|
|
|
|
this.userLock.Unlock() // Don't lock over a processEvent boundary
|
|
|
|
|
|
|
|
|
|
if !userExisted {
|
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_USER_JOINED, Nick: uinf.Nick})
|
|
|
|
|
} else {
|
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_USER_UPDATED_INFO, Nick: uinf.Nick})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -132,9 +135,8 @@ func (this *HubConnection) processProtocolMessage(message string) {
|
|
|
|
|
switch commandParts[0] {
|
|
|
|
|
|
|
|
|
|
case "$Lock":
|
|
|
|
|
this.SayRaw("$Supports NoGetINFO UserCommand UserIP2|" +
|
|
|
|
|
"$Key " + unlock([]byte(commandParts[1])) + "|" +
|
|
|
|
|
"$ValidateNick " + Escape(this.Hco.Self.Nick) + "|")
|
|
|
|
|
this.SayRaw("$Supports NoHello NoGetINFO UserCommand UserIP2 QuickList ChatOnly|" +
|
|
|
|
|
"$Key " + unlock([]byte(commandParts[1])) + "|")
|
|
|
|
|
this.sentOurHello = false
|
|
|
|
|
|
|
|
|
|
case "$Hello":
|
|
|
|
|
@@ -167,26 +169,32 @@ func (this *HubConnection) processProtocolMessage(message string) {
|
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_CONN, Message: "Incorrect password."})
|
|
|
|
|
|
|
|
|
|
case "$GetPass":
|
|
|
|
|
this.SayRaw("$MyPass " + Escape(this.Hco.NickPassword) + "|")
|
|
|
|
|
if len(this.Hco.NickPassword) == 0 {
|
|
|
|
|
// We've got a problem. MyPass with no arguments is a syntax error with no message = instant close
|
|
|
|
|
// Just drop the connection
|
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_CONN, Message: "This account is passworded."})
|
|
|
|
|
this.Disconnect()
|
|
|
|
|
} else {
|
|
|
|
|
this.SayRaw("$MyPass " + Escape(this.Hco.NickPassword) + "|")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "$Quit":
|
|
|
|
|
func() {
|
|
|
|
|
this.userLock.Lock()
|
|
|
|
|
defer this.userLock.Unlock()
|
|
|
|
|
this.userLock.Lock()
|
|
|
|
|
delete(this.users, commandParts[1])
|
|
|
|
|
this.userLock.Unlock() // Don't lock over a processEvent boundary
|
|
|
|
|
|
|
|
|
|
delete(this.users, commandParts[1])
|
|
|
|
|
}()
|
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_USER_PART, Nick: commandParts[1]})
|
|
|
|
|
|
|
|
|
|
case "$MyINFO":
|
|
|
|
|
u := UserInfo{}
|
|
|
|
|
err := u.fromMyINFO(commandParts[1])
|
|
|
|
|
if err == nil {
|
|
|
|
|
this.userJoined_Full(&u)
|
|
|
|
|
} else {
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_DEBUG_MESSAGE, Message: err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.userJoined_Full(&u)
|
|
|
|
|
|
|
|
|
|
case "$NickList":
|
|
|
|
|
nicklist := strings.Split(commandParts[1], "$$")
|
|
|
|
|
for _, nick := range nicklist {
|
|
|
|
|
@@ -237,11 +245,39 @@ func (this *HubConnection) processProtocolMessage(message string) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "$UserIP":
|
|
|
|
|
// Final message in PtokaX connection handshake - trigger connection callback.
|
|
|
|
|
// This might not be the case for other hubsofts, though
|
|
|
|
|
if this.State != CONNECTIONSTATE_CONNECTED {
|
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_CONNECTION_STATE_CHANGED, StateChange: CONNECTIONSTATE_CONNECTED})
|
|
|
|
|
this.State = CONNECTIONSTATE_CONNECTED
|
|
|
|
|
this.userLock.Lock()
|
|
|
|
|
|
|
|
|
|
pairs := strings.Split(commandParts[1], "$$")
|
|
|
|
|
notifyOfUpdate := make([]string, 0, len(pairs))
|
|
|
|
|
|
|
|
|
|
nextIPPair:
|
|
|
|
|
for _, pair := range pairs {
|
|
|
|
|
parts := strings.SplitN(pair, " ", 2)
|
|
|
|
|
if len(parts) != 2 {
|
|
|
|
|
// ????
|
|
|
|
|
continue nextIPPair
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ip2nick := parts[0]
|
|
|
|
|
ip2addr := parts[1]
|
|
|
|
|
|
|
|
|
|
uinfo, ok := this.users[ip2nick]
|
|
|
|
|
if !ok {
|
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_DEBUG_MESSAGE, Message: "Recieved IP '" + ip2addr + "' for unknown user '" + ip2nick + "'"})
|
|
|
|
|
continue nextIPPair
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if uinfo.IPAddress != ip2addr {
|
|
|
|
|
uinfo.IPAddress = ip2addr
|
|
|
|
|
notifyOfUpdate = append(notifyOfUpdate, ip2nick)
|
|
|
|
|
this.users[ip2nick] = uinfo
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.userLock.Unlock()
|
|
|
|
|
|
|
|
|
|
for _, nick := range notifyOfUpdate {
|
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_USER_UPDATED_INFO, Nick: nick})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "$ForceMove":
|
|
|
|
|
@@ -269,8 +305,34 @@ func (this *HubConnection) processProtocolMessage(message string) {
|
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_DEBUG_MESSAGE, Message: "Malformed usercommand '" + commandParts[1] + "'"})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IGNORABLE COMMANDS
|
|
|
|
|
case "$Supports":
|
|
|
|
|
this.supports = make(map[string]struct{})
|
|
|
|
|
for _, s := range strings.Split(commandParts[1], " ") {
|
|
|
|
|
this.supports[s] = struct{}{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !this.sentOurHello {
|
|
|
|
|
|
|
|
|
|
// Need to log in.
|
|
|
|
|
// If the hub supports QuickList, we can skip one network roundtrip
|
|
|
|
|
if _, ok := this.supports["QuickList"]; ok {
|
|
|
|
|
this.SayInfo()
|
|
|
|
|
this.SayRaw("$GetNickList|")
|
|
|
|
|
} else {
|
|
|
|
|
this.SayRaw("$ValidateNick " + Escape(this.Hco.Self.Nick) + "|")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This also counts as the end of the handshake from our POV. Consider
|
|
|
|
|
// ourselves logged in
|
|
|
|
|
this.sentOurHello = true
|
|
|
|
|
if this.State != CONNECTIONSTATE_CONNECTED {
|
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_CONNECTION_STATE_CHANGED, StateChange: CONNECTIONSTATE_CONNECTED})
|
|
|
|
|
this.State = CONNECTIONSTATE_CONNECTED
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IGNORABLE COMMANDS
|
|
|
|
|
case "$HubTopic":
|
|
|
|
|
case "$Search":
|
|
|
|
|
case "$ConnectToMe":
|
|
|
|
|
|