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