Page 1 of 1

Adding spectators to Tris example

Posted: 13 Aug 2019, 19:49
by gg
Hi,

Clicking a game in the Lobby attempts to join as a player. In case there are 2 players already in the game, OnRoomJoinError(BaseEvent evt) fires. I am rejoining as a spectator in OnRoomJoinError(), but this seems a bad approach because if the game's MaxSpectators is already maxed out, or any other legitimate error, I won't be able to join as a spectator, and I wouldn't see why.

If there is a better approach than OnRoomJoinError() could you please let me know?

Also, other than setting my logs level from WARN to ERROR, can I disable the "Room is full" warning message in the log? I don't need to be warned about it every time a room is full.

Thank you!

Re: Adding spectators to Tris example

Posted: 14 Aug 2019, 07:10
by Lapo
Hello,
gg wrote:Clicking a game in the Lobby attempts to join as a player. In case there are 2 players already in the game, OnRoomJoinError(BaseEvent evt) fires. I am rejoining as a spectator in OnRoomJoinError(), but this seems a bad approach because if the game's MaxSpectators is already maxed out, or any other legitimate error, I won't be able to join as a spectator, and I wouldn't see why.

I am not very sure about this.
If you send another join request you will receive another event in response, positive or negative. So I am not sure why you wouldn't get an error if the spectator join fails.
Also, minor observation, you can check the current state of the Room before joining as a spectator and if all slots are already taken you can avoid joining entirely.

Also, other than setting my logs level from WARN to ERROR, can I disable the "Room is full" warning message in the log? I don't need to be warned about it every time a room is full.

I wouldn't do that. Logs are useful to backtrack potential issues and check the overall server activity.
With the same logic you could say that you don't need to know every user that logs in or Room creation error. This is how logs work, they keep track of important events in the server. If you want to silence everything you can set the level to ERROR, but I would not recommend it.

Cheers

Re: Adding spectators to Tris example

Posted: 15 Aug 2019, 20:15
by gg
you can check the current state of the Room before joining as a spectator and if all slots are already taken you can avoid joining entirely.
Oh, fantastic!!! This is the code for someone else that needs to do something similar

Code: Select all

if (sfs.RoomManager.GetRoomById(roomId).UserCount<2)         // Join the Room if only 1 player in
            sfs.Send(new Sfs2X.Requests.JoinRoomRequest(roomId));

        else  //join as spec
            sfs.Send(new Sfs2X.Requests.JoinRoomRequest(roomId, "", null, true));