Here's a hard one!

  • OK, so I've got a database running that stores a players "friends" list. Using the chat command /add friend PlayerName this gets the players UID with;


    Player p = getServer.getPlayer("playername");


    String friendUID = (String)p.getUID();


    (or something like that!)


    Here comes the perplexing part!


    Now say the players "friend" goes off and destroys their stuff whilst they are not online. When they next login they want to remove the player with something like /remove friend PlayerName now clearly this is only going to be possible *if* the "bad" player is logged in at the same time to enable the server to work out the UID.


    Now, I could execute this with a command such as /remove friend PlayerNameUID (like 28372728294828282) but that's going to be very difficult for a user to do.


    Can anyone think of any magic way to make this easier?


    (I'm half way thinking a GUI is going to be the only way. . .)

  • i would suggest you save the friend list as the server unique id numbers, then to get the names of the players you can sql query the world db for the player with that number then your remove friend command can be something like:


    /Removefriend serverID

  • A possibility would be to store the uid together with the friends name in your table when you add the friend. Then you can retrieve the uid even when the friend is not logged in.

    the only problem with using the name is that the player can change it at will now :/


    Unless you check it every time someone logs in and change your db names accordingly


    For example i may add John as a friend but then need to remove Rick because John has changed his name to Rick in the meantime

  • General question but why do you want to implement an in-server friend list? Isn't the steam one sufficient? I understand that standalone users cannot benefit from the steam one but still think it is too much effort with no real benefit for most users.


    Or is the in-server friend list benefiting your users in some way? Like adding custom waypoints to the map where their friends are or having a compass or an arrow point to the direction a friend is at?


    If I had to implement an in-server friend list I would do it this way:


    1) /addfriend Name (when friend player is online)
    This would save in my own database the server unique ID of the player. My db would look like this:


    Int primary key autoincrementID of player who added the otherID of player who was added
    11015
    21510


    meaning player with server ID 10 (e.g. Minotorious) has added player with server ID 15 (e.g. yahwho) as their friend. (you can add a confirm command before this is saved to the db for the other player e.g. once I use /addfriend yahwho you get a chat message and need to type /confirm for the entry to be added to the db. Then ofc the reverse entry would be added too see line 2 above of you adding me as a friend)


    2) /friendlist or /listfriends
    shows all friends of a player querying the world db for their current names using the Server UDs from my DB.


    e.g steps: query my db for all IDs (in column 3 above) that have my number as the ID who added them (column 2 above), then query the world db for each of the numbers to get the name, and finally output the results.


    e.g. output in chat:


    Friend List:
    Name ID
    Minotorious 10
    yahgiggle 5
    red51 2
    etc.


    3) /removefriend ServerID (serverID obtained easily from /friendlist or /listfriends)
    using an sql query removes the friends from my db without the need to obtain the player names or get mixed up with changed names and try to figure out when they were changed.


    Hope this helps :)

  • General question but why do you want to implement an in-server friend list? Isn't the steam one sufficient? I understand that standalone users cannot benefit from the steam one but still think it is too much effort with no real benefit for most users.


    Hi Minotorious,


    I'm writing a chunk protection program.


    My `Friends` database consists of (ID, OwnerUID, FriendUID) - very similar to the same as what you've suggested.


    Your point 2 sounds good to list the friends and then possibly have a "shortcut ID" created on the fly to remove the friend from the list, rather than the user having to type in the whole UID.


    Something like,


    /list friends


    8023098235768907230572 last known name Bob (ID: 1)
    8237592385682375872387 last known name Jane (ID: 2)


    /remove friend 2



    CHEERS!

  • Your point 2 sounds good to list the friends and then possibly have a "shortcut ID" created on the fly to remove the friend from the list, rather than the user having to type in the whole UID.

    I would use the serverIDs to remove players from my list but an ID created on the fly as long as it remains constant for the time required to read the /list commadn output and type the /removefriend command sounds good too.



    Something like,


    /list friends


    8023098235768907230572 last known name Bob (ID: 1)
    8237592385682375872387 last known name Jane (ID: 2)

    I wouldn't include the steam ID in the /list command's output but that is just personal taste :D

  • @yawhoo: yes, you would need to synchronize the stored uuid / name combinations on login of a user. Should not be too complicated... you could even perform an update any time a player logs in. like : update <table> set friend_name = <login_name> where friend_uuid = <login_uuid>

  • hi guys, I've already written that part of the program using the UID for owner and friend. So I'll have to leave it as it is (far too much on my plate to rewrite code that already works). I was just trying to work out how someone could easily remove a friend.


    Min, you're probably right not to include the UID string in the output. Maybe have an extra field in case the users wants to see this like:


    /list friends showuid


    :thumbup:

  • I've already written that part of the program using the UID for owner and friend. So I'll have to leave it as it is (far too much on my plate to rewrite code that already works). I was just trying to work out how someone could easily remove a friend.

    Well if it works ofc don't change it :D There are always at least 10 ways to do everything so whichever way you like the most is the best for you :) (so long as it is not 100 times slower than another way but that is not the case here ;) )

  • /list friends


    8023098235768907230572 last known name Bob (ID: 1)
    8237592385682375872387 last known name Jane (ID: 2)


    /remove friend 2

    A small thing that just came to mind when using on the fly IDs, if I have the following list:


    Minotorious 1
    Bob 2
    yahwho 3
    Rick 4
    Jane 5


    and then I want to remove two friends e.g. Bob and Rick and I do /remove friend 2 then what ID does Rick have afterwards? retain the number 4 till I disconnect from the server or does he become number 3 because Bob is now gone?


    I would definitely use the Server unique IDs to avoid such confusion or make sure the on the fly IDs remain constant at least until the player retypes /list friends.

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!