' LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
' L Server-COntrol-Center 1.01 L
' LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL

' This Software is under the GPLv3 Licence !
' Info: http://www.gnu.org/licenses/gpl-3.0.html
' If you payed for this Program then you were tricked !




Imports System
Imports System.Management
Imports System.ServiceProcess


Public Class Form1

    ' Change this values to your Servicenames !

    Dim AccLogDB As String = "_AccountLog DB Server"
    Dim CharacDB As String = "_Character DB Server0"
    Dim GameLoDB As String = "_GameLog DB Server0"
    Dim LoginSrv As String = "_Login Server"
    Dim ManagSrv As String = "_Manager Server0"
    Dim ORestSrv As String = "_OdinRestServer"
    Dim Zone0Srv As String = "_Zone Server00"
    Dim Zone1Srv As String = "_Zone Server01"
    Dim Zone2Srv As String = "_Zone Server02"
    Dim Zone3Srv As String = "_Zone Server03"


    ' You dont need to touch the rest of the code, exept you want to clean out :D



    Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click
        If MessageBox.Show("Really quit ? ( Serverstatus will NOT be affected ! )", "Server Control Center", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then End
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label2.Text = "Checking..."
        Label4.Text = "Checking..."
        Label13.Text = "Checking..."
        Label14.Text = "Checking..."
        Label15.Text = "Checking..."
        Label16.Text = "Checking..."
        Label17.Text = "Checking..."
        Label18.Text = "Checking..."
        Label19.Text = "Checking..."
        Label20.Text = "Checking..."
        Label2.ForeColor = Color.Yellow
        Label4.ForeColor = Color.Yellow
        Label13.ForeColor = Color.Yellow
        Label14.ForeColor = Color.Yellow
        Label15.ForeColor = Color.Yellow
        Label16.ForeColor = Color.Yellow
        Label17.ForeColor = Color.Yellow
        Label18.ForeColor = Color.Yellow
        Label19.ForeColor = Color.Yellow
        Label20.ForeColor = Color.Yellow
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim helper As String
        helper = ServiceAvailable(AccLogDB)
        If helper = "True" Then
            Label2.ForeColor = Color.Green
            Label2.Text = "Online"
        Else
            If helper = "False" Then
                Label2.ForeColor = Color.Red
                Label2.Text = "Offline"
            Else
                Label2.ForeColor = Color.RoyalBlue
                Label2.Text = "Missing !"
            End If
        End If
        helper = ServiceAvailable(CharacDB)
        If helper = "True" Then
            Label4.ForeColor = Color.Green
            Label4.Text = "Online"
        Else
            If helper = "False" Then
                Label4.ForeColor = Color.Red
                Label4.Text = "Offline"
            Else
                Label4.ForeColor = Color.RoyalBlue
                Label4.Text = "Missing !"
            End If
        End If
        helper = ServiceAvailable(GameLoDB)
        If helper = "True" Then
            Label13.ForeColor = Color.Green
            Label13.Text = "Online"
        Else
            If helper = "False" Then
                Label13.ForeColor = Color.Red
                Label13.Text = "Offline"
            Else
                Label13.ForeColor = Color.RoyalBlue
                Label13.Text = "Missing !"
            End If
        End If
        helper = ServiceAvailable(LoginSrv)
        If helper = "True" Then
            Label14.ForeColor = Color.Green
            Label14.Text = "Online"
        Else
            If helper = "False" Then
                Label14.ForeColor = Color.Red
                Label14.Text = "Offline"
            Else
                Label14.ForeColor = Color.RoyalBlue
                Label14.Text = "Missing !"
            End If
        End If
        helper = ServiceAvailable(ManagSrv)
        If helper = "True" Then
            Label15.ForeColor = Color.Green
            Label15.Text = "Online"
        Else
            If helper = "False" Then
                Label15.ForeColor = Color.Red
                Label15.Text = "Offline"
            Else
                Label15.ForeColor = Color.RoyalBlue
                Label15.Text = "Missing !"
            End If
        End If
        helper = ServiceAvailable(ORestSrv)
        If helper = "True" Then
            Label16.ForeColor = Color.Green
            Label16.Text = "Online"
        Else
            If helper = "False" Then
                Label16.ForeColor = Color.Red
                Label16.Text = "Offline"
            Else
                Label16.ForeColor = Color.RoyalBlue
                Label16.Text = "Missing !"
            End If
        End If
        helper = ServiceAvailable(Zone0Srv)
        If helper = "True" Then
            Label17.ForeColor = Color.Green
            Label17.Text = "Online"
        Else
            If helper = "False" Then
                Label17.ForeColor = Color.Red
                Label17.Text = "Offline"
            Else
                Label17.ForeColor = Color.RoyalBlue
                Label17.Text = "Missing !"
            End If
        End If
        helper = ServiceAvailable(Zone1Srv)
        If helper = "True" Then
            Label18.ForeColor = Color.Green
            Label18.Text = "Online"
        Else
            If helper = "False" Then
                Label18.ForeColor = Color.Red
                Label18.Text = "Offline"
            Else
                Label18.ForeColor = Color.RoyalBlue
                Label18.Text = "Missing !"
            End If
        End If
        helper = ServiceAvailable(Zone2Srv)
        If helper = "True" Then
            Label19.ForeColor = Color.Green
            Label19.Text = "Online"
        Else
            If helper = "False" Then
                Label19.ForeColor = Color.Red
                Label19.Text = "Offline"
            Else
                Label19.ForeColor = Color.RoyalBlue
                Label19.Text = "Missing !"
            End If
        End If
        helper = ServiceAvailable(Zone3Srv)
        If helper = "True" Then
            Label20.ForeColor = Color.Green
            Label20.Text = "Online"
        Else
            If helper = "False" Then
                Label20.ForeColor = Color.Red
                Label20.Text = "Offline"
            Else
                Label20.ForeColor = Color.RoyalBlue
                Label20.Text = "Missing !"
            End If
        End If
        Dim ram As Integer
        Dim maxram As Integer
        Dim vram As Integer
        Dim maxvram As Integer
        ram = My.Computer.Info.AvailablePhysicalMemory / 1024
        maxram = My.Computer.Info.TotalPhysicalMemory / 1024
        vram = My.Computer.Info.AvailableVirtualMemory / 1024
        maxvram = My.Computer.Info.TotalVirtualMemory / 1024
        ram = maxram - ram
        vram = maxvram - vram
        Label21.Text = "RAM: " + ram.ToString + "/" + maxram.ToString
        Label22.Text = "V-RAM: " + vram.ToString + "/" + maxvram.ToString
        ProgressBar1.Maximum = maxram
        ProgressBar2.Maximum = maxvram
        ProgressBar1.Value = ram
        ProgressBar2.Value = vram

    End Sub


    Public Function ServiceAvailable(ByVal Dienst As String)
        Dim Service As ServiceController = New ServiceController(Dienst)
        On Error GoTo fehler
        If Service.Status = ServiceProcess.ServiceControllerStatus.Running Then
            Return "True"
        Else
            Return "False"
        End If
        Service.Close()
        Exit Function
fehler:
        Return "Error"
    End Function

    Public Function ServiceStart(ByVal Dienst As String)
        Dim Service As ServiceController = New ServiceController(Dienst)
        On Error GoTo fehler
        If Service.Status = ServiceProcess.ServiceControllerStatus.Running Then
            Return "NO"
        Else
            Service.Start()
        End If
        Service.Close()
        Return "OK"
        Exit Function
fehler:
        Return "Error"
    End Function

    Public Function ServiceStop(ByVal Dienst As String)
        Dim Service As ServiceController = New ServiceController(Dienst)
        On Error GoTo fehler
        If Service.Status = ServiceProcess.ServiceControllerStatus.Running Then
            Service.Stop()            
        Else
            Return "NO"
        End If
        Service.Close()
        Return "OK"
        Exit Function
fehler:
        Return "Error"
    End Function

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        ServiceStart(AccLogDB)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ServiceStart(CharacDB)
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        ServiceStart(GameLoDB)
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        ServiceStart(LoginSrv)
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        ServiceStart(ManagSrv)
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        ServiceStart(ORestSrv)
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        ServiceStart(Zone0Srv)
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        ServiceStart(Zone1Srv)
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        ServiceStart(Zone2Srv)
    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        ServiceStart(Zone3Srv)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ServiceStop(AccLogDB)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        ServiceStop(CharacDB)
    End Sub

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        ServiceStop(GameLoDB)
    End Sub

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        ServiceStop(LoginSrv)
    End Sub

    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        ServiceStop(ManagSrv)
    End Sub

    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        ServiceStop(ORestSrv)
    End Sub

    Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
        ServiceStop(Zone0Srv)
    End Sub

    Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
        ServiceStop(Zone1Srv)
    End Sub

    Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
        ServiceStop(Zone2Srv)
    End Sub

    Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
        ServiceStop(Zone3Srv)
    End Sub

    Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button22.Click
        MessageBox.Show("Server-Control-Center is made by Zorno" + vbNewLine + "under GPLv3 Licence. This Software is" + vbNewLine + "free of charge, so if you payed for it" + vbNewLine + "you were tricked !", "Server Control Center", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub
End Class