| 373 | } |
| 374 | |
| 375 | func LogOutUserByConnectionId(connectionId connections.ConnectionId) error { |
| 376 | |
| 377 | u := GetByConnectionId(connectionId) |
| 378 | |
| 379 | userManagerMu.Lock() |
| 380 | defer userManagerMu.Unlock() |
| 381 | |
| 382 | if _, ok := userManager.Connections[connectionId]; ok { |
| 383 | |
| 384 | // Make sure the user data is saved to a file. |
| 385 | if u != nil { |
| 386 | u.Character.Validate() |
| 387 | SaveUser(*u) |
| 388 | |
| 389 | delete(userManager.Users, u.UserId) |
| 390 | delete(userManager.Usernames, u.Username) |
| 391 | delete(userManager.Connections, u.connectionId) |
| 392 | delete(userManager.UserConnections, u.UserId) |
| 393 | } else { |
| 394 | // Connection exists but user record is missing - clean up the connection entry |
| 395 | delete(userManager.Connections, connectionId) |
| 396 | } |
| 397 | |
| 398 | return nil |
| 399 | } |
| 400 | return errors.New("user not found for connection") |
| 401 | } |
| 402 | |
| 403 | // First time creating a user. |
| 404 | func CreateUser(u *UserRecord) error { |