twohoursonelife / OneLife

Two Hours One Life, building upon One Hour One Life. Join us on Discord to play.
https://twohoursonelife.com
Other
46 stars 39 forks source link

Added ability for an outside application to query server list of alive players names, age, gender and fertilityStatus #207

Closed Eboubaker closed 1 year ago

Eboubaker commented 1 year ago

issue https://github.com/twohoursonelife/OneLife/issues/202

check added text in protocol.txt for details:

An outside application can also respond with the message PLAYER_LIST <secret># instead of the previous LOGIN message in this case the server
will then send a list of players status in the format
----
num_players
p_id,eve_id,parent_id,gender,age,delcaredInfertile,isTutorial,name,familyName
p_id,eve_id,parent_id,gender,age,delcaredInfertile,isTutorial,name,familyName
p_id,eve_id,parent_id,gender,age,delcaredInfertile,isTutorial,name,familyName
....
p_id,eve_id,parent_id,gender,age,delcaredInfertile,isTutorial,name,familyName
#
----
where
num_players: number of players (count of next lines).
p_id: player id
eve_id: the player id of the player's EVE
parent_id: the player id of the player's parent
gender: F or M.
age: player age with 1 decimal.
declaredInfertile: 1 if the player has declared themselves as infertile, otherwise 0 (if player said one of infertilityDeclaringPhrases.ini).
isTutorial: 1 if player is playing Tutorial
name: player full name can include the word "EVE", empty if player is nameless.
familyName: player's family name, assigned at birth if mother has familyName, can be assigned for an orphaned baby if another family names them, NOTE: EVE without a name has no familyName. until she declares her name all her babies will have familyName null.

if <secret> differs from playerListSecret.ini REJECTED response will be sent.
if playerListSecret.ini is empty the request can just be PLAYER_LIST# without a secret.

if memory requirement for the message was too much for the server to be
handled the message will not be complete. to check if the server sent the full
message see if the server's response ended with #. if it did not end with #,
it means that some player lines are missing.

NOTE: if server is full, the server will still send SERVER_FULL message, changing this behavior requires big changes to the way the server handles the first connection-establishing messages that i don't want to touch.

Eboubaker commented 1 year ago

Requires more testing, i only tested by typing in nc localhost 8005

connorhsm commented 1 year ago

Impressive work here! Much appreciated. I look forward to testing this.

Eboubaker commented 1 year ago

This is done and is ready to be reviewed/tested. can be discarded if not suitable. if this reached live server I recommend replacing playerListSecret.ini

Eboubaker commented 1 year ago

@connorhsm

  1. I tried with the same input and got this: image Are you sure you were on the latest commit on branch get-player-list when you tested it? I could not reproduce it.

  2. I didn't get what you mean exactly but I put in the protocol.txt that when the player is nameless the name part will be empty string, it's up to the client to parse that response and replace it with nameless or other symbol. if you do a .split(" ") (with space character argument) on the player line the first-name part will be empty string and no last-name part if the player is namless.

  3. will do!.

Eboubaker commented 1 year ago

If you don't want problems with empty string replacing both firstname and lastname we could concatenate them with an underscore _ or other symbol instead of space character like now . so it will be easier to read(when someone is nameless) by the client(the bot) but then the client has to replcace that underscore back into a space character!.

other solution is simply to swap name and declaredInfertile positions, to let name be the last part then it is easier to know if someone is nameless. instead of

gender age name delcaredInfertile

we do

gender age delcaredInfertile name

since all the first 3 parts will definitely be there. Also This way the display lines will be more aligned because the name part has random lengths and by leaving it at the end it will look better.

connorhsm commented 1 year ago

I agree about ordering, let's put the name last. I was also about to agree about not concatenating the name, but I think this will be necessary for the primary use case that initiated this idea.

We need a way to discern whether or not a name is a first or last name so that a client can group together families by last name. I think an underscore would help by allowing the ability to check whether it's at the start or end of a name, which indicates a player without a last or first name respectively. Like so:

gender age delcaredInfertile first_last
gender age delcaredInfertile first_
gender age delcaredInfertile _last

This also may not be a problem if a missing first or last is being replaced by an extra space, I'll test this further and also confirm the differences we've had with the LOGIN message later.

Eboubaker commented 1 year ago

looking at the way you seperate firstname and lastname, I think you expect the server to show you the player last name even if they are still a baby and no one gave them a firstname. currently I just use player->name it has both firstname and lastname concatenated with a space, the problem is it is only set once someone gives them a name or they spawn as eve. in that case(baby) I probably need to follow their lineage and get the lastname.

connorhsm commented 1 year ago

Given there's no separation internally, let's keep name one field.

connorhsm commented 1 year ago

sealofapproval

Eboubaker commented 1 year ago

@connorhsm Can you Add isTutorial after declaredInfertile in protocol.txt as in the updated description of this PR