3 Commits

Author SHA1 Message Date
51b08dad3d readme 2016-10-08 16:32:10 +13:00
1a3e4fe072 support parsing usercommands 2016-10-08 15:19:21 +13:00
086281dab2 Added tag libnmdc-r9 for changeset e7c2c71ef24b 2016-08-27 17:39:00 +12:00
6 changed files with 56 additions and 1 deletions

View File

@@ -11,3 +11,4 @@ cb86f3a40115cc46f450c0c83fd9b9d3b740e820 nmdc-log-service-1.0.4
cb86f3a40115cc46f450c0c83fd9b9d3b740e820 libnmdc-r6 cb86f3a40115cc46f450c0c83fd9b9d3b740e820 libnmdc-r6
71343a2c641a438206d30ea7e75dc89a11dbef00 libnmdc-r7 71343a2c641a438206d30ea7e75dc89a11dbef00 libnmdc-r7
b0e57a5fcffdf4102d669db51a3648ddf66a0792 libnmdc-r8 b0e57a5fcffdf4102d669db51a3648ddf66a0792 libnmdc-r8
e7c2c71ef24b386add728fad35fff4a996fccbac libnmdc-r9

View File

@@ -3,6 +3,7 @@ package libnmdc
import ( import (
"crypto/tls" "crypto/tls"
"net" "net"
"strconv"
"strings" "strings"
"sync" "sync"
"time" "time"
@@ -244,9 +245,29 @@ func (this *HubConnection) processProtocolMessage(message string) {
this.Hco.Address = HubAddress(commandParts[1]) this.Hco.Address = HubAddress(commandParts[1])
this.conn.Close() // we'll reconnect onto the new address this.conn.Close() // we'll reconnect onto the new address
case "$UserCommand":
// $UserCommand 1 1 Group chat\New group chat$<%[mynick]> !groupchat_new&#124;|
if rx_userCommand.MatchString(commandParts[1]) {
usc := rx_userCommand.FindStringSubmatch(commandParts[1])
typeInt, _ := strconv.Atoi(usc[1])
contextInt, _ := strconv.Atoi(usc[2])
uscStruct := UserCommand{
Type: UserCommandType(typeInt),
Context: UserCommandContext(contextInt),
Message: usc[3],
Command: NMDCUnescape(usc[4]),
}
this.processEvent(HubEvent{EventType: EVENT_USERCOMMAND, UserCommand: &uscStruct})
} else {
this.processEvent(HubEvent{EventType: EVENT_DEBUG_MESSAGE, Message: "Malformed usercommand '" + commandParts[1] + "'"})
}
// IGNORABLE COMMANDS // IGNORABLE COMMANDS
case "$Supports": case "$Supports":
case "$UserCommand": // TODO $UserCommand 1 1 Group chat\New group chat$<%[mynick]> !groupchat_new&#124;|
case "$HubTopic": case "$HubTopic":
case "$Search": case "$Search":
case "$ConnectToMe": case "$ConnectToMe":

View File

@@ -11,6 +11,7 @@ const (
EVENT_CONNECTION_STATE_CHANGED = 8 EVENT_CONNECTION_STATE_CHANGED = 8
EVENT_HUBNAME_CHANGED = 9 EVENT_HUBNAME_CHANGED = 9
EVENT_DEBUG_MESSAGE = 10 EVENT_DEBUG_MESSAGE = 10
EVENT_USERCOMMAND = 11
) )
type HubEventType int type HubEventType int
@@ -20,4 +21,5 @@ type HubEvent struct {
Nick string Nick string
Message string Message string
StateChange ConnectionState StateChange ConnectionState
UserCommand *UserCommand
} }

26
UserCommand.go Normal file
View File

@@ -0,0 +1,26 @@
package libnmdc
type UserCommandType uint8
const (
USERCOMMAND_TYPE_SEPARATOR UserCommandType = 0
USERCOMMAND_TYPE_RAW UserCommandType = 1
USERCOMMAND_TYPE_NICKLIMITED UserCommandType = 2
USERCOMMAND_TYPE_CLEARALL UserCommandType = 255
)
type UserCommandContext uint8
const (
USERCOMMAND_CONTEXT_HUB UserCommandContext = 1
USERCOMMAND_CONTEXT_USER UserCommandContext = 2
USERCOMMAND_CONTEXT_SEARCH UserCommandContext = 4
USERCOMMAND_CONTEXT_FILELIST UserCommandContext = 8
)
type UserCommand struct {
Type UserCommandType
Context UserCommandContext
Message string
Command string
}

View File

@@ -9,6 +9,9 @@ Tags: nmdc
=CHANGELOG= =CHANGELOG=
2016-10-08 r10
- Feature: Support `$UserCommand`
2016-08-27 r9 2016-08-27 r9
- Fix an issue with parsing MyINFO strings with zero-length speed descriptions - Fix an issue with parsing MyINFO strings with zero-length speed descriptions
- Fix an issue with not storing updated profile information - Fix an issue with not storing updated profile information

View File

@@ -19,12 +19,14 @@ const (
var rx_protocolMessage *regexp.Regexp var rx_protocolMessage *regexp.Regexp
var rx_publicChat *regexp.Regexp var rx_publicChat *regexp.Regexp
var rx_incomingTo *regexp.Regexp var rx_incomingTo *regexp.Regexp
var rx_userCommand *regexp.Regexp
var ErrNotConnected error = errors.New("Not connected") var ErrNotConnected error = errors.New("Not connected")
func init() { func init() {
rx_protocolMessage = regexp.MustCompile("(?ms)^[^|]*\\|") rx_protocolMessage = regexp.MustCompile("(?ms)^[^|]*\\|")
rx_publicChat = regexp.MustCompile("(?ms)^<([^>]*)> (.*)$") rx_publicChat = regexp.MustCompile("(?ms)^<([^>]*)> (.*)$")
rx_incomingTo = regexp.MustCompile("(?ms)^([^ ]+) From: ([^ ]+) \\$<([^>]*)> (.*)") rx_incomingTo = regexp.MustCompile("(?ms)^([^ ]+) From: ([^ ]+) \\$<([^>]*)> (.*)")
rx_userCommand = regexp.MustCompile(`(?ms)^(\d+) (\d+)\s?([^\$]*)\$?(.*)`)
} }
func NMDCUnescape(encoded string) string { func NMDCUnescape(encoded string) string {