0

So I have a game server that has 50-200 players online at a time. Everyone are able to change their usernames every 30 days. Where i'm running into issue is i'm not exactly sure how to deal with username change on that user's friend list. I'm allowing everyone to add 200 friends, and friends list contains userID (unique for everyone) and userName. For example when a user changes name, and has 200 friends, and only 2 of 200 friends are online, how would i change username on the offline users, so whenever they login, they see that user's new name. Ways i thought about:

  1. Loop thru friends list and make changes in ever friend's database whenever u change name
  2. When user logins and logoffs, friend list is looped and usernames are selected from db
  3. Whenever someone opens a friend list, re-select all friends's usernames from db

When user has 200 friends, i'm pretty sure all of those ways are going to consume too many resources and cause delays in the server. But i'm not sure what's the best way to even do it. And there's one more thing, name changes doesn't always happen when u change name, they happen when u get higher or lower role too, so there may be alot of name changes at some point. What would be the best way to handle it?

public class PlayerFriend
        {
            [ProtoMember(1)]
            public ulong userID { get; set; }
            [ProtoMember(2)]
            public string displayName { get; set; }
        }

public class PlayerData
{
            [ProtoMember(34)]
            public Dictionary<ulong, PlayerFriend> friends = new Dictionary<ulong, PlayerFriend>();
}

  • 1
    If a user changes their display name, it should only be modifying a single row in the entirety of the database. Period. How are you linking users and friends in the database? Are you repeating display name elsewhere? Do you have some mechanism to notify clients when data is modified? – gunr2171 May 11 '22 at 18:19
  • I meant when a user's friend that changed displayName, checks its friend list, a new name should be contained there, not the old one. Like if he/she's offline, then logins, he/she will still see the old name of its user forever. – RJFromEstonia May 11 '22 at 18:21
  • Well every user's friends are saved in the database as a serialized list that contains userID and displayName from when that user added a friend. – RJFromEstonia May 11 '22 at 18:23
  • you should not include displayName there, you should store the user id of the friend instead and look up the display name when you need it – ysth May 11 '22 at 18:28
  • "Well every user's friends are saved in the database as a serialized list that contains userID and displayName from when that user added a friend." that's your problem. This is a classic relational db thing. You need a many-many relationship between people. – gilliduck May 11 '22 at 18:28
  • If i got you right, you meant i should store every friend in a seperate row on that user's table, and connect them with users database via userID that contains displayName? – RJFromEstonia May 11 '22 at 18:34
  • I forgot to include, whenever someone checks their friends list, its displayed instantly, all 200 friends. – RJFromEstonia May 11 '22 at 18:36
  • 1
    Alright, i got that figured out, redesigned my databases. "friends" database stores userID and friends_userID, and userID is connected to player's database userID. – RJFromEstonia May 11 '22 at 20:05

0 Answers0