优化:连接状态auth, bool=>string, 记录授权用户key
git-svn-id: svn://47.119.165.148/zhub@166 e63fbceb-bcc3-4977-ac22-735b83d8d0f4
This commit is contained in:
@@ -32,7 +32,7 @@ func msgAccept(v Message) {
|
|||||||
if LogDebug {
|
if LogDebug {
|
||||||
log.Printf("[%d] rcmd: %s\n", v.Conn.sn, strings.Join(rcmd, " "))
|
log.Printf("[%d] rcmd: %s\n", v.Conn.sn, strings.Join(rcmd, " "))
|
||||||
}
|
}
|
||||||
if !c.auth && !strings.EqualFold("auth", rcmd[0]) && strings.EqualFold(GetStr("service.auth", "0"), "1") {
|
if strings.TrimSpace(c.auth) == "" && !strings.EqualFold("auth", rcmd[0]) && strings.EqualFold(GetStr("service.auth", "0"), "1") {
|
||||||
c.send("-Auth: NOAUTH Authentication required:" + rcmd[0])
|
c.send("-Auth: NOAUTH Authentication required:" + rcmd[0])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -162,7 +162,7 @@ func msgAccept(v Message) {
|
|||||||
inx := strings.IndexAny(rcmd[1], "@") //user@pwd
|
inx := strings.IndexAny(rcmd[1], "@") //user@pwd
|
||||||
|
|
||||||
if strings.EqualFold(GetStr("auth."+rcmd[1][:inx], ""), rcmd[1][inx+1:]) {
|
if strings.EqualFold(GetStr("auth."+rcmd[1][:inx], ""), rcmd[1][inx+1:]) {
|
||||||
c.auth = true
|
c.auth = rcmd[1][:inx]
|
||||||
c.send("+Auth: ok!")
|
c.send("+Auth: ok!")
|
||||||
} else {
|
} else {
|
||||||
c.send("-Auth: invalid password!")
|
c.send("-Auth: invalid password!")
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ type ZConn struct { //ZConn
|
|||||||
substoped map[string]chan int // 关闭信号量
|
substoped map[string]chan int // 关闭信号量
|
||||||
ping int64 // 最后心跳时间
|
ping int64 // 最后心跳时间
|
||||||
pong int64 // 最后心跳回复时间
|
pong int64 // 最后心跳回复时间
|
||||||
auth bool // 是否已验证授权
|
auth string // 是否已验证授权
|
||||||
}
|
}
|
||||||
|
|
||||||
type Lock struct {
|
type Lock struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user