Adding spectators to Tris example

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

User avatar
gg
Posts: 89
Joined: 19 Sep 2010, 21:16
Contact:

Adding spectators to Tris example

Postby gg » 13 Aug 2019, 19:49

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!
User avatar
Lapo
Site Admin
Posts: 21680
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Adding spectators to Tris example

Postby Lapo » 14 Aug 2019, 07:10

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
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
gg
Posts: 89
Joined: 19 Sep 2010, 21:16
Contact:

Re: Adding spectators to Tris example

Postby gg » 15 Aug 2019, 20:15

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));

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 7 guests