Server Registry
The server registry is a central place with which game servers can register so that clients can see what servers are available for a game. It provides an easy way to implement a server list as seen commonly in many game lobbies. The server registry is implemented in the ServerRegistry class.Adding and Removing Servers
To add a server to the server registry you use the AddServer() method:void AddServer(string ipAddress, int port, params object[] data)
void AddServer(int port, params object[] data)
This can only be called by peers with the server peer type, and adds the server
to the lobby's server registry. The supplied IP address and port are what
clients will see when they list the server. If the IP address is omitted, the
address that the lobby uses to communicate with the game server will be used.
The data argument is an arbitrary list of data that is associated
with the server and can be retrieved by clients.
To remove a server from the registry you use the
RemoveServer() method:
void RemoveServer()
This can only be called by a currently registered server and will remove it from
the server registry. If a server peer disconnects from the lobby it will be
automatically removed from the server registry, so there is no need to call this
method in that case.
Server Data
Each server can specify arbitrary data to be stored in the registry together with the server. This data can be used for storing game-specific information regarding the server that clients would want to know. For example, for an FPS game, the data might include the server's name, the current number of players in the server and the maximum number of players allowed. This would then be displayed on the clients when they list the available servers. As mentioned previously you can specify initial data when registering a server. This data can later be updated using the UpdateServerData() method:void UpdateServerData(params object[] data)
This will replace the current data for the server with the specified data. To
reuse the FPS example, this would be called whenever a player joins or leaves
the server and the current player number changes. When this happens, clients
will be notified that the data for a server has changed, giving them a chance to
update their server list.
Retrieving the Server List
The list of registered servers will automatically be loaded and updated in the background on clients. Clients can use the GetServers() method to retrieve this list:IEnumerable<ServerInfo> GetServers()
This method returns a list of ServerInfo, which contains the server's
peer, endpoint, and the data the server has registered with (if any).
Server Registry Notifications
There are several events clients can listen to regarding the server list.- OnServerAdded - Called when a server was added to the registry.
- OnServerRemoved - Called when a server was removed from the registry.
- OnServerDataUpdated - Called when the data of a server has been updated.






