Facepunch.Steamworks Wiki

Revision Difference

Get_Server_List#526431

<cat>code.servers</cat> <title>Get Server List</title> # Creating The Request First step is to create the request. You have a few different options, but here's how to create an Internet request. ``` Request = new Steamworks.ServerList.Internet(); ``` # Filters You can optionally add filters to avoid showing servers you don't want to show. ``` // Show only secure servers Request.AddFilter( "secure", "1" ); // AND with the next 1 rule (if not it'll OR) Request.AddFilter( "and", "1" ); // Show only servers that are the same version Request.AddFilter( "gametype", GameVersionString ); ``` # Set up a callback Set up a function to be called when new servers are found. This won't be called for every server, but it might be called every frame. ``` Request.OnChanges += OnServersUpdated; ``` # Run the request You can start the request. You don't have to await this function. It takes a timeout, in seconds, where it'll stop updating. ``` Request.RunQueryAsync( 30 ); ``` # Server Responded Your callback function will get called when new servers are found. ``` void OnServersUpdated() { // No reponsive servers yet, bail if ( Request.Responsive.Count == 0 ) return; // Process each responsive server foreach ( var s in Request.Responsive ) { ServerResponded( s ); } // Clear the responsive server list so we don't // reprocess them on the next call. Request.Responsive.Clear(); } void ServerResponded( ServerInfo server ) { // Do whatever you want with the server information Log( $"{server.Name} Responded!" ); } ``` # Cancelling If you want a Stop button on or a Refresh button, you should stop the request. ``` if ( Request != null ) { Request.Dispose(); Request = null; } ``` ⤶ <title>getusersSteamids</title>