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) {
|
||||
this.SayRaw("<" + this.Hco.Self.Nick + "> " + NMDCEscape(message) + "|")
|
||||
this.SayRaw("<" + this.Hco.Self.Nick + "> " + Escape(message) + "|")
|
||||
}
|
||||
|
||||
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() {
|
||||
@ -111,14 +111,14 @@ func (this *HubConnection) processProtocolMessage(message string) {
|
||||
// ```````````
|
||||
if rx_publicChat.MatchString(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
|
||||
}
|
||||
|
||||
// System messages
|
||||
// ```````````````
|
||||
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
|
||||
}
|
||||
|
||||
@ -130,8 +130,8 @@ func (this *HubConnection) processProtocolMessage(message string) {
|
||||
|
||||
case "$Lock":
|
||||
this.SayRaw("$Supports NoGetINFO UserCommand UserIP2|" +
|
||||
"$Key " + NMDCUnlock([]byte(commandParts[1])) + "|" +
|
||||
"$ValidateNick " + NMDCEscape(this.Hco.Self.Nick) + "|")
|
||||
"$Key " + unlock([]byte(commandParts[1])) + "|" +
|
||||
"$ValidateNick " + Escape(this.Hco.Self.Nick) + "|")
|
||||
this.sentOurHello = false
|
||||
|
||||
case "$Hello":
|
||||
@ -164,7 +164,7 @@ func (this *HubConnection) processProtocolMessage(message string) {
|
||||
this.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_CONN, Message: "Incorrect password."})
|
||||
|
||||
case "$GetPass":
|
||||
this.SayRaw("$MyPass " + NMDCEscape(this.Hco.NickPassword) + "|")
|
||||
this.SayRaw("$MyPass " + Escape(this.Hco.NickPassword) + "|")
|
||||
|
||||
case "$Quit":
|
||||
func() {
|
||||
@ -224,7 +224,7 @@ func (this *HubConnection) processProtocolMessage(message string) {
|
||||
if rx_incomingTo.MatchString(commandParts[1]) {
|
||||
txparts := rx_incomingTo.FindStringSubmatch(commandParts[1])
|
||||
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
|
||||
}
|
||||
}
|
||||
@ -257,7 +257,7 @@ func (this *HubConnection) processProtocolMessage(message string) {
|
||||
Type: UserCommandType(typeInt),
|
||||
Context: UserCommandContext(contextInt),
|
||||
Message: usc[3],
|
||||
Command: NMDCUnescape(usc[4]),
|
||||
Command: Unescape(usc[4]),
|
||||
}
|
||||
|
||||
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)
|
||||
if matches != nil {
|
||||
this.Nick = matches[1]
|
||||
this.Description = NMDCUnescape(matches[2])
|
||||
this.ClientTag = NMDCUnescape(matches[3])
|
||||
this.Description = Unescape(matches[2])
|
||||
this.ClientTag = Unescape(matches[3])
|
||||
this.ClientVersion = matches[4]
|
||||
this.ConnectionMode = ConnectionMode(matches[5][0])
|
||||
maybeParse(matches[6], &this.HubsUnregistered, 0)
|
||||
@ -76,7 +76,7 @@ func (this *UserInfo) fromMyINFO(protomsg string) error {
|
||||
this.Speed = ""
|
||||
}
|
||||
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)
|
||||
|
||||
return nil
|
||||
@ -86,7 +86,7 @@ func (this *UserInfo) fromMyINFO(protomsg string) error {
|
||||
matches = rx_myinfo_notag.FindStringSubmatch(protomsg)
|
||||
if matches != nil {
|
||||
this.Nick = matches[1]
|
||||
this.Description = NMDCUnescape(matches[2])
|
||||
this.Description = Unescape(matches[2])
|
||||
this.ClientTag = ""
|
||||
this.ClientVersion = "0"
|
||||
this.ConnectionMode = CONNECTIONMODE_PASSIVE
|
||||
@ -101,7 +101,7 @@ func (this *UserInfo) fromMyINFO(protomsg string) error {
|
||||
this.Speed = ""
|
||||
}
|
||||
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)
|
||||
|
||||
return nil
|
||||
|
@ -28,19 +28,19 @@ func init() {
|
||||
rx_userCommand = regexp.MustCompile(`(?ms)^(\d+) (\d+)\s?([^\$]*)\$?(.*)`)
|
||||
}
|
||||
|
||||
func NMDCUnescape(encoded string) string {
|
||||
func Unescape(encoded string) string {
|
||||
v1 := strings.Replace(encoded, "$", "$", -1)
|
||||
v2 := strings.Replace(v1, "|", "|", -1)
|
||||
return strings.Replace(v2, "&", "&", -1)
|
||||
}
|
||||
|
||||
func NMDCEscape(plaintext string) string {
|
||||
func Escape(plaintext string) string {
|
||||
v1 := strings.Replace(plaintext, "&", "&", -1)
|
||||
v2 := strings.Replace(v1, "|", "|", -1)
|
||||
return strings.Replace(v2, "$", "$", -1)
|
||||
}
|
||||
|
||||
func NMDCUnlock(lock []byte) string {
|
||||
func unlock(lock []byte) string {
|
||||
|
||||
nibble_swap := func(b byte) byte {
|
||||
return ((b << 4) & 0xF0) | ((b >> 4) & 0x0F)
|
||||
|
Loading…
Reference in New Issue
Block a user