fix user data resetting on adduser

This commit is contained in:
Elijah R 2024-06-23 14:58:53 -04:00
parent b02e967761
commit 59fa954e11

View file

@ -371,20 +371,32 @@ public class CollabVMClient {
case "adduser": {
for (int i = 2; i < msgArr.Length; i += 2) {
// This can happen when a user logs in
_users.RemoveAll(u => u.Username == msgArr[i]);
var user = new User {
Username = msgArr[i],
Rank = msgArr[i + 1] switch {
var user = _users.Find(u => u.Username == msgArr[i]);
if (user == null) {
user = new User {
Username = msgArr[i],
Rank = msgArr[i + 1] switch {
"0" => Rank.Unregistered,
"1" => Rank.Registered,
"2" => Rank.Admin,
"3" => Rank.Moderator,
_ => Rank.Unregistered
},
Turn = TurnStatus.None
};
this._users.Add(user);
}
else
{
user.Rank = msgArr[i + 1] switch {
"0" => Rank.Unregistered,
"1" => Rank.Registered,
"2" => Rank.Admin,
"3" => Rank.Moderator,
_ => Rank.Unregistered
},
Turn = TurnStatus.None
};
};
}
this.UserJoined.Invoke(this, user);
this._users.Add(user);
}
break;
}