robreuss / VirtualGameController

Software-based game controllers for iOS, tvOS, OS X and watchOS in Swift 4.2.
MIT License
462 stars 44 forks source link

Limiting the number of connected controllers #19

Closed Tdflowers closed 5 years ago

Tdflowers commented 8 years ago

Is it possible limit the number of connected devices? I am building a game and need to cap it at 4 players. Is there a way to refuse a connection?

Tdflowers commented 8 years ago

I created a work around by checking after adding a controller to a local array if there are 4 controllers are connected and calling unpublishCentralService(). Then when a controller disconnects I republish.

robreuss commented 8 years ago

I'm planning to add built-in support for controller limits, but for now, this is something you have to implement. Note, you might want to be sensitive to the difference between software and hardware controllers in your business logic. You can inspect the type of controller with controller.deviceInfo.controllerType.

robreuss commented 8 years ago

That's a cleaver work-around for how to avoid additional connections, BTW. It will not, of course, prevent hardware-based controllers from connecting because those don't go through the service - they directly connect via bluetooth.

Tdflowers commented 8 years ago

Thanks for the reply, I will keep that in mind! Just got myself a hardware controller to do testing with.