Skip to content

Server Disconnect Client Code

jedh edited this page Mar 25, 2019 · 3 revisions

Sometimes it is necessary to manually disconnect a player from the server (on the server). First you will need to find out which NetworkingPlayer you are wishing to kick on the server. Once you have a reference to that player, you are going to want to call the disconnect on them. To do this you need to use the reference to your server's NetWorker.

// We are going to force the disconnect of the client
bool forcefully = true;

// Consider the player you want to disconnect is the targetPlayer object
// Also consider that serverNetworker is the server's networker (this can be NetworkManager.Instance.Networker)
((IServer)serverNetworker).Disconnect(targetPlayer, forcefully);

// This needs to be called whether "forced" is true or false in Disconnect()
((IServer)serverNetworker).CommitDisconnects();

That is it, you are ready to start kicking all of the players! :D

Home

Getting Started
Network Contract Wizard (NCW)
Network Object
Remote Procedure Calls (RPCs)
Unity Integration
Basic Network Samples
Scene Navigation
NetWorker
Master Server
Web Server
Netcoding Design Patterns
Troubleshooting
Miscellaneous
Clone this wiki locally
You can’t perform that action at this time.