fix: when searching player by id, create new player if client name does not match the one found

This commit is contained in:
Deluan
2020-03-17 19:09:49 -04:00
parent 811703ab60
commit ced87be57b
2 changed files with 19 additions and 4 deletions
+5 -2
View File
@@ -30,11 +30,14 @@ func (p *players) Register(ctx context.Context, id, client, typ, ip string) (*mo
userName := ctx.Value("username").(string)
if id != "" {
plr, err = p.ds.Player(ctx).Get(id)
if err == nil && plr.Client != client {
id = ""
}
}
if err != nil || id == "" {
plr, err = p.ds.Player(ctx).FindByName(client, userName)
if err == nil {
log.Trace("Found player by name", "id", plr.ID, "client", client, "userName", userName)
log.Debug("Found player by name", "id", plr.ID, "client", client, "userName", userName)
} else {
r, _ := uuid.NewRandom()
plr = &model.Player{
@@ -43,7 +46,7 @@ func (p *players) Register(ctx context.Context, id, client, typ, ip string) (*mo
UserName: userName,
Client: client,
}
log.Trace("Create new player", "id", plr.ID, "client", client, "userName", userName)
log.Info("Registering new player", "id", plr.ID, "client", client, "userName", userName)
}
}
plr.LastSeen = time.Now()