rename NMDC{Escape,Unescape,Unlock} functions; don't export NMDCUnlock
This commit is contained in:
parent
5713b58c7c
commit
084b629ad7
@ -38,11 +38,11 @@ func (this *HubConnection) Users(cb func(*map[string]UserInfo) error) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *HubConnection) SayPublic(message string) {
|
func (this *HubConnection) SayPublic(message string) {
|
||||||
this.SayRaw("<" + this.Hco.Self.Nick + "> " + NMDCEscape(message) + "|")
|
this.SayRaw("<" + this.Hco.Self.Nick + "> " + Escape(message) + "|")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *HubConnection) SayPrivate(recipient string, message string) {
|
func (this *HubConnection) SayPrivate(recipient string, message string) {
|
||||||
this.SayRaw("$To: " + recipient + " From: " + this.Hco.Self.Nick + " $<" + this.Hco.Self.Nick + "> " + NMDCEscape(message) + "|")
|
this.SayRaw("$To: " + recipient + " From: " + this.Hco.Self.Nick + " $<" + this.Hco.Self.Nick + "> " + Escape(message) + "|")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *HubConnection) SayInfo() {
|
func (this *HubConnection) SayInfo() {
|
||||||
@ -111,14 +111,14 @@ func (this *HubConnection) processProtocolMessage(message string) {
|
|||||||
// ```````````
|
// ```````````
|
||||||
if rx_publicChat.MatchString(message) {
|
if rx_publicChat.MatchString(message) {
|
||||||
pubchat_parts := rx_publicChat.FindStringSubmatch(message)
|
pubchat_parts := rx_publicChat.FindStringSubmatch(message)
|
||||||
this.processEvent(HubEvent{EventType: EVENT_PUBLIC, Nick: pubchat_parts[1], Message: NMDCUnescape(pubchat_parts[2])})
|
this.processEvent(HubEvent{EventType: EVENT_PUBLIC, Nick: pubchat_parts[1], Message: Unescape(pubchat_parts[2])})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// System messages
|
// System messages
|
||||||
// ```````````````
|
// ```````````````
|
||||||
if message[0] != '$' {
|
if message[0] != '$' {
|
||||||
this.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_HUB, Nick: this.HubName, Message: NMDCUnescape(message)})
|
this.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_HUB, Nick: this.HubName, Message: Unescape(message)})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,8 +130,8 @@ func (this *HubConnection) processProtocolMessage(message string) {
|
|||||||
|
|
||||||
case "$Lock":
|
case "$Lock":
|
||||||
this.SayRaw("$Supports NoGetINFO UserCommand UserIP2|" +
|
this.SayRaw("$Supports NoGetINFO UserCommand UserIP2|" +
|
||||||
"$Key " + NMDCUnlock([]byte(commandParts[1])) + "|" +
|
"$Key " + unlock([]byte(commandParts[1])) + "|" +
|
||||||
"$ValidateNick " + NMDCEscape(this.Hco.Self.Nick) + "|")
|
"$ValidateNick " + Escape(this.Hco.Self.Nick) + "|")
|
||||||
this.sentOurHello = false
|
this.sentOurHello = false
|
||||||
|
|
||||||
case "$Hello":
|
case "$Hello":
|
||||||
@ -164,7 +164,7 @@ func (this *HubConnection) processProtocolMessage(message string) {
|
|||||||
this.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_CONN, Message: "Incorrect password."})
|
this.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_CONN, Message: "Incorrect password."})
|
||||||
|
|
||||||
case "$GetPass":
|
case "$GetPass":
|
||||||
this.SayRaw("$MyPass " + NMDCEscape(this.Hco.NickPassword) + "|")
|
this.SayRaw("$MyPass " + Escape(this.Hco.NickPassword) + "|")
|
||||||
|
|
||||||
case "$Quit":
|
case "$Quit":
|
||||||
func() {
|
func() {
|
||||||
@ -224,7 +224,7 @@ func (this *HubConnection) processProtocolMessage(message string) {
|
|||||||
if rx_incomingTo.MatchString(commandParts[1]) {
|
if rx_incomingTo.MatchString(commandParts[1]) {
|
||||||
txparts := rx_incomingTo.FindStringSubmatch(commandParts[1])
|
txparts := rx_incomingTo.FindStringSubmatch(commandParts[1])
|
||||||
if txparts[1] == this.Hco.Self.Nick && txparts[2] == txparts[3] {
|
if txparts[1] == this.Hco.Self.Nick && txparts[2] == txparts[3] {
|
||||||
this.processEvent(HubEvent{EventType: EVENT_PRIVATE, Nick: txparts[2], Message: NMDCUnescape(txparts[4])})
|
this.processEvent(HubEvent{EventType: EVENT_PRIVATE, Nick: txparts[2], Message: Unescape(txparts[4])})
|
||||||
valid = true
|
valid = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -257,7 +257,7 @@ func (this *HubConnection) processProtocolMessage(message string) {
|
|||||||
Type: UserCommandType(typeInt),
|
Type: UserCommandType(typeInt),
|
||||||
Context: UserCommandContext(contextInt),
|
Context: UserCommandContext(contextInt),
|
||||||
Message: usc[3],
|
Message: usc[3],
|
||||||
Command: NMDCUnescape(usc[4]),
|
Command: Unescape(usc[4]),
|
||||||
}
|
}
|
||||||
|
|
||||||
this.processEvent(HubEvent{EventType: EVENT_USERCOMMAND, UserCommand: &uscStruct})
|
this.processEvent(HubEvent{EventType: EVENT_USERCOMMAND, UserCommand: &uscStruct})
|
||||||
|
10
UserInfo.go
10
UserInfo.go
@ -62,8 +62,8 @@ func (this *UserInfo) fromMyINFO(protomsg string) error {
|
|||||||
matches := rx_myinfo.FindStringSubmatch(protomsg)
|
matches := rx_myinfo.FindStringSubmatch(protomsg)
|
||||||
if matches != nil {
|
if matches != nil {
|
||||||
this.Nick = matches[1]
|
this.Nick = matches[1]
|
||||||
this.Description = NMDCUnescape(matches[2])
|
this.Description = Unescape(matches[2])
|
||||||
this.ClientTag = NMDCUnescape(matches[3])
|
this.ClientTag = Unescape(matches[3])
|
||||||
this.ClientVersion = matches[4]
|
this.ClientVersion = matches[4]
|
||||||
this.ConnectionMode = ConnectionMode(matches[5][0])
|
this.ConnectionMode = ConnectionMode(matches[5][0])
|
||||||
maybeParse(matches[6], &this.HubsUnregistered, 0)
|
maybeParse(matches[6], &this.HubsUnregistered, 0)
|
||||||
@ -76,7 +76,7 @@ func (this *UserInfo) fromMyINFO(protomsg string) error {
|
|||||||
this.Speed = ""
|
this.Speed = ""
|
||||||
}
|
}
|
||||||
this.Flag = UserFlag(matches[10][len(matches[10])-1])
|
this.Flag = UserFlag(matches[10][len(matches[10])-1])
|
||||||
this.Email = NMDCUnescape(matches[11])
|
this.Email = Unescape(matches[11])
|
||||||
maybeParse(matches[12], &this.ShareSize, 0)
|
maybeParse(matches[12], &this.ShareSize, 0)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -86,7 +86,7 @@ func (this *UserInfo) fromMyINFO(protomsg string) error {
|
|||||||
matches = rx_myinfo_notag.FindStringSubmatch(protomsg)
|
matches = rx_myinfo_notag.FindStringSubmatch(protomsg)
|
||||||
if matches != nil {
|
if matches != nil {
|
||||||
this.Nick = matches[1]
|
this.Nick = matches[1]
|
||||||
this.Description = NMDCUnescape(matches[2])
|
this.Description = Unescape(matches[2])
|
||||||
this.ClientTag = ""
|
this.ClientTag = ""
|
||||||
this.ClientVersion = "0"
|
this.ClientVersion = "0"
|
||||||
this.ConnectionMode = CONNECTIONMODE_PASSIVE
|
this.ConnectionMode = CONNECTIONMODE_PASSIVE
|
||||||
@ -101,7 +101,7 @@ func (this *UserInfo) fromMyINFO(protomsg string) error {
|
|||||||
this.Speed = ""
|
this.Speed = ""
|
||||||
}
|
}
|
||||||
this.Flag = UserFlag(matches[3][len(matches[3])-1])
|
this.Flag = UserFlag(matches[3][len(matches[3])-1])
|
||||||
this.Email = NMDCUnescape(matches[4])
|
this.Email = Unescape(matches[4])
|
||||||
maybeParse(matches[5], &this.ShareSize, 0)
|
maybeParse(matches[5], &this.ShareSize, 0)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -28,19 +28,19 @@ func init() {
|
|||||||
rx_userCommand = regexp.MustCompile(`(?ms)^(\d+) (\d+)\s?([^\$]*)\$?(.*)`)
|
rx_userCommand = regexp.MustCompile(`(?ms)^(\d+) (\d+)\s?([^\$]*)\$?(.*)`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NMDCUnescape(encoded string) string {
|
func Unescape(encoded string) string {
|
||||||
v1 := strings.Replace(encoded, "$", "$", -1)
|
v1 := strings.Replace(encoded, "$", "$", -1)
|
||||||
v2 := strings.Replace(v1, "|", "|", -1)
|
v2 := strings.Replace(v1, "|", "|", -1)
|
||||||
return strings.Replace(v2, "&", "&", -1)
|
return strings.Replace(v2, "&", "&", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NMDCEscape(plaintext string) string {
|
func Escape(plaintext string) string {
|
||||||
v1 := strings.Replace(plaintext, "&", "&", -1)
|
v1 := strings.Replace(plaintext, "&", "&", -1)
|
||||||
v2 := strings.Replace(v1, "|", "|", -1)
|
v2 := strings.Replace(v1, "|", "|", -1)
|
||||||
return strings.Replace(v2, "$", "$", -1)
|
return strings.Replace(v2, "$", "$", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NMDCUnlock(lock []byte) string {
|
func unlock(lock []byte) string {
|
||||||
|
|
||||||
nibble_swap := func(b byte) byte {
|
nibble_swap := func(b byte) byte {
|
||||||
return ((b << 4) & 0xF0) | ((b >> 4) & 0x0F)
|
return ((b << 4) & 0xF0) | ((b >> 4) & 0x0F)
|
||||||
|
Loading…
Reference in New Issue
Block a user