-
Notifications
You must be signed in to change notification settings - Fork 0
Poolhelper
This handles the Lobby as well as the user input to said lobby
Method to create a new empty pool and make channels and maps.
The method returns said Pool.
Sample Usage:
thisPool := newPool()
This is a method that is attached to every pool variable. Once called it will start the PoolUpdate method as a goroutine and listen on all pool channels for input. It also handles said input by saving it in its fields for further use.
It takes a boolean as parameter to determine whether the method will exit if the killpool boolean has been set to true. (This gets passed to the PoolUpdate Method)
It does not return a value.
Sample Usage:
this.Pool.Start(false)
The method is only called by Start as a coroutine and is responsible for handling reoccurring tasks for every lobby. It checks whether the lobby is empty and is able to close the lobby (if lobby not permanent). Every 200 milliseconds it also sends an update for the player positions to every connected client.
It takes a boolean as a parameter which determines whether the lobby is permanent or not as well as the pool it is attached to.
It does not return a value.
Sample Usage:
go PoolUpdate(pool, isPermanent)
This method is called once a user has connected and has been successfully authenticated. It generates a client variable with the connection, the Playername and the playerID. The generated client will always have a Pool of nil as the client has not joined a room yet.
This method then calls the HandleInput method for the client.
This method takes the client connection (as a pointer), the map with all active lobbies as well as the client username as parameters.
Sample Usage:
InitInputHandler(socketConn, roomList, userName)
Similar the Start() method, this method is attached to the all variables based on the client interface.
This method listens for client input via the websocket and will pass it to GenerateMessage. If the clients pool is nil the next message will be handled as a join message. If no lobbyID to join was provided a new Lobby will be generated.
The parameter for this function is the map containing all lobbies.
Sample Usage:
c.HandleInput(LobbyMap)
This method handles user input and communicates with the lobby via channels. The method is provided with the client message as a byte array and extracts all relevant fields of the payload based on its type variable.
This method takes the payload as a byte array and the client that the payload is from as parameters.
It does not return a value (yea the name might be misleading)
Sample Usage:
GenerateMessage(payload, client)