Now we delete users after closing connection
This commit is contained in:
parent
e29cc04203
commit
a4d6137a5a
|
@ -55,6 +55,8 @@ func main() {
|
||||||
func handleClient(conn net.Conn) {
|
func handleClient(conn net.Conn) {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
buf := make([]byte, 512)
|
buf := make([]byte, 512)
|
||||||
|
var registeredID uint16
|
||||||
|
var isRegistered bool
|
||||||
ask, err := com.ServerAskClientAboutNickname()
|
ask, err := com.ServerAskClientAboutNickname()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("ERROR: %#v\n", err)
|
log.Printf("ERROR: %#v\n", err)
|
||||||
|
@ -104,6 +106,8 @@ func handleClient(conn net.Conn) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
conn.Write(answ)
|
conn.Write(answ)
|
||||||
|
isRegistered = true
|
||||||
|
registeredID = id
|
||||||
}
|
}
|
||||||
case com.ID_CLIENT_SEND_SERVER_LINK:
|
case com.ID_CLIENT_SEND_SERVER_LINK:
|
||||||
default:
|
default:
|
||||||
|
@ -111,4 +115,7 @@ func handleClient(conn net.Conn) {
|
||||||
// Handle
|
// Handle
|
||||||
}
|
}
|
||||||
log.Println("server: conn: closed")
|
log.Println("server: conn: closed")
|
||||||
|
if isRegistered {
|
||||||
|
userCenter.DeleteIfHaveOne(registeredID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,17 @@ func (u *UserCenter) AddUser(name string) (uint16, error) {
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *UserCenter) DeleteIfHaveOne(id uint16) {
|
||||||
|
name, found := u.UsersITOS[id]
|
||||||
|
if !found {
|
||||||
|
log.Printf("User with %d id is not found; Can not delete\n", id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
delete(u.UsersITOS, id)
|
||||||
|
delete(u.UsersSTOI, name)
|
||||||
|
log.Printf("User with %s name and %d id was found; User is deleted\n", name, id)
|
||||||
|
}
|
||||||
|
|
||||||
func (u *UserCenter) GetID(name string) (uint16, error) {
|
func (u *UserCenter) GetID(name string) (uint16, error) {
|
||||||
id, have := u.UsersSTOI[name]
|
id, have := u.UsersSTOI[name]
|
||||||
if !have {
|
if !have {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user