MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / LoginUser

Function LoginUser

internal/users/users.go:239–319  ·  view source on GitHub ↗

First time creating a user.

(user *UserRecord, connectionId connections.ConnectionId)

Source from the content-addressed store, hash-verified

237
238// First time creating a user.
239func LoginUser(user *UserRecord, connectionId connections.ConnectionId) (*UserRecord, string, error) {
240
241 mudlog.Info("LoginUser()", "username", user.Username, "connectionId", connectionId)
242
243 user.Character.SetAdjective(`zombie`, false)
244
245 userManagerMu.Lock()
246
247 // If they're already logged in
248 if userId, ok := userManager.Usernames[user.Username]; ok {
249
250 // Do they have a connection tracked?
251 if otherConnId, ok := userManager.UserConnections[userId]; ok {
252
253 // Is it a link-dead connection? If so, lets make this new connection the owner
254 if isLinkDeadConnectionLocked(otherConnId) {
255
256 mudlog.Info("LoginUser()", "LinkDead", true)
257
258 if linkDeadUser, ok := userManager.Users[user.UserId]; ok {
259 user = linkDeadUser
260 }
261
262 removeLinkDeadConnectionLocked(otherConnId)
263
264 user.connectionId = connectionId
265
266 userManager.Users[user.UserId] = user
267 userManager.Usernames[user.Username] = user.UserId
268 userManager.Connections[user.connectionId] = user.UserId
269 userManager.UserConnections[user.UserId] = user.connectionId
270
271 userManagerMu.Unlock()
272
273 for _, mobInstId := range user.Character.GetCharmIds() {
274 if !mobs.MobInstanceExists(mobInstId) {
275 user.Character.TrackCharmed(mobInstId, false)
276 }
277 }
278
279 // Set their input round to current to track idle time fresh
280 user.SetLastInputRound(util.GetRoundCount())
281
282 user.EventLog.Add(`conn`, `Reconnected`)
283
284 return user, "Reconnecting...", nil
285 }
286
287 }
288
289 userManagerMu.Unlock()
290 // Otherwise, someone else is logged in, can't double-login!
291 return nil, "That user is already logged in.", errors.New("user is already logged in")
292 }
293
294 mudlog.Info("LoginUser()", "LinkDead", false)
295
296 // Set their input round to current to track idle time fresh

Callers 1

FinalizeLoginOrCreateFunction · 0.92

Calls 13

InfoFunction · 0.92
MobInstanceExistsFunction · 0.92
GetRoundCountFunction · 0.92
LockMethod · 0.80
UnlockMethod · 0.80
GetCharmIdsMethod · 0.80
TrackCharmedMethod · 0.80
SetLastInputRoundMethod · 0.80
NewMethod · 0.80
SetAdjectiveMethod · 0.45

Tested by

no test coverage detected