Jump to content

script to restart empty game servers


LFA

Recommended Posts

Just change the game id TCXXXXXXXXXXXX and run it on the master. To restart all empty game servers of all game types leave it like it is.

 

<tcascript>
<language name="VB" />
<waitForUserAction value="true"/>

<scriptCode><![CDATA[

Imports System

Public Class Collector
   Public Shared Sub Main()
       Dim gameid As String = "TCXXXXXXXXXXXX"
       Dim services() As TCAdminSDK.Objects.Service = TCAdminSDK.Objects.Service.GetServices()

       If Not services Is Nothing Then
           For Each service As TCAdminSDK.Objects.Service In services
               Try
                   If service.GameID = gameid Or gameid = "TCXXXXXXXXXXXX" Then
                       If service.CurrentStatus = TCAdminSDK.Objects.ServiceStatus.Running Then
                           Dim gswPlugin As TCAdminBase.Plugins.IGenericPlugIn = TCAdminSDK.Remote.InstanceCreator.GetPluginFromServer(service.ServerID, "TCAdmin.Plugins.GameStats.ServerPlugin", "TCAdmin.Plugins.GameStats")
                           Dim xmldata As String = gswPlugin.Execute(New Object() {"GetGameServerStatus", service.ServerIP, service.ServerQueryPort, service.GameID, service.ServiceID})
                           If Not xmldata Is Nothing Then
                               Dim ds As New System.Data.DataSet
                               Dim stream As New System.IO.StringReader(xmldata)
                               ds.ReadXml(stream)
                               stream.Close()

                               If ds.Tables.Count = 0 Then
                                   Console.WriteLine("No results were returned: {0}", service.UniqueDisplayNameWithOwner)
                               Else
                                   Dim activeplayers As Integer = ds.Tables(0).Rows(0).Item("Active Players")
                                   Console.WriteLine("{0} has {1} active players.", service.UniqueDisplayNameWithOwner, activeplayers)
                                   If activeplayers = 0 Then
                                       Console.WriteLine("Stopping...")
                                       service.Stop()
                                       Console.WriteLine("Starting...")
                                       service.Start()
                                   End If
                               End If

                           Else
                               Console.WriteLine("No results were returned: {0}", service.UniqueDisplayNameWithOwner)
                           End If
                       Else
                           Console.WriteLine("{0} is not running", service.UniqueDisplayNameWithOwner)
                       End If
                   End If
               Catch ex As Exception
                   Console.WriteLine("Error checking {0}: {1}", service.UniqueDisplayNameWithOwner, ex.ToString())
               End Try
           Next
       End If
       Console.WriteLine("Done.")
   End Sub
End Class

]]></scriptCode>

</tcascript>

Link to comment
Share on other sites

It can be used to restart any game.

 

I updated the script so you can restart all games. Just leave the game id ="TCXXXXXXXXXXXX"

 

There was also a script error that I fixed :|:

 

 

what derek meant was "can it restart all empty game servers at once" with the condition they are empty i assume.

 

However derek some games cant be queried so they would be considered as empty even if full.

Maybe Luis can manage a way to include the condition "game has compatibility set" so it would restart ALL game servers that can be queried and that are empty.

 

I tried to make such a script without chance but i might use it for other purposes.

Link to comment
Share on other sites

what derek meant was "can it restart all empty game servers at once" with the condition they are empty i assume.

 

However derek some games cant be queried so they would be considered as empty even if full.

Maybe Luis can manage a way to include the condition "game has compatibility set" so it would restart ALL game servers that can be queried and that are empty.

 

I tried to make such a script without chance but i might use it for other purposes.

 

Yes that is what it does just leave the script as it is and it will restart all game servers of any game type that does not have any players.

 

If the game does not have the game compatibility set it will fail and move to the next game server. It will not restart it.

Link to comment
Share on other sites

Yes that is what it does just leave the script as it is and it will restart all game servers of any game type that does not have any players.

 

If the game does not have the game compatibility set it will fail and move to the next game server. It will not restart it.

 

 

oh good i didnt understand it this way the first time, very nice script then, ima use it.

Link to comment
Share on other sites

nice! ahha sorry im not sure if you missed my question ;P

hiow about server with HLTV or sourcetv?

 

does it skip it or restart it as well?

 

thanks! have a great weekend guys ;)

 

It only restarts the main game. You will have to run another script with the HLTV game id.

Link to comment
Share on other sites

Nice, but i would add some sleep time between stopping, starting and going to the next server.

 

Something like....

 

If activeplayers = 0 Then
    Console.WriteLine("Stopping...")
    service.Stop()
[color="green"]     ' Wait 2 seconds before starting it up again[/color]
    Threading.Thread.CurrentThread.Sleep(2000)
    Console.WriteLine("Starting...")
    service.Start()
[color="green"]     ' Wait 10 seconds before the next stop[/color]
    Threading.Thread.CurrentThread.Sleep(10000)
End If

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use