Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

My Ultra-Cool Server Report Feature (FTP based)


dg1423
 Share

Recommended Posts

I've implemented it in my site [HERE](http://duckyp.org/server.php) if anyone wants to see some of the features in use.

Right now It can report these to any php based web page

* Online/Offline
* Server IP
* Server Port
* Last time the server was booted up, as "0:00 AM/PM January 1, 2000"
* Number of players online, as a single number "0"
* The names of the players online, as a comma seperated list "dg1423, monkey, test"
* Combo of number and names of players online, as "There are no players online." "There is 1 player online: dg1423" "There are 2 players online: dg1423, test"

All of which are run by php functions and can be returned printed or as a string to be used in statements.

Lets get started then:

Create a new module and call it modStatus.

Paste this inside:
```
Dim Status As String
Dim ServerStatus As String
Dim ServerTime As String

Dim InternetConnection As Long
Dim FTPConnection As Long

Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hFtpSession As Long, ByVal lpszLocalFile As String, ByVal lpszRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer

Sub SaveStatus(Stat As Byte)
Dim SS As String
Dim SS0 As String
Dim SS1 As String
Dim SS2 As String
Dim SS3 As String
Dim SS4 As String
Dim SS5 As String
Dim SS6 As String
Dim SS7 As String
Dim Time As String
Dim Color As String
Dim CurrentTime As Variant
Dim FileName As String
Dim SaveFile As Boolean
Dim CloseFTP As Integer
Dim s As String
Dim n As Long, i As Long
Dim t As String

    s = ""
    n = 0
    For i = 1 To MAX_PLAYERS
        If IsPlaying(i) Then
            s = s & GetPlayerName(i) & ", "
            n = n + 1
        End If
    Next i

    If n = 0 Then
        s = "There are no players online."
    ElseIf n = 1 Then
        s = Mid(s, 1, Len(s) - 2)
        t = s
        s = "There is " & n & " player online: " & s & "."
    Else
        s = Mid(s, 1, Len(s) - 2)
        t = s
        s = "There are " & n & " players online: " & s & "."
    End If

FileName = App.Path & "\status.php"

CurrentTime = Now '3:00 PM Jan 16, 2005
Time = Format(CurrentTime, "h:mm AMPM MMM d, yyyy")

If Stat = 0 Then
    SS = "Offline"
    Color = "FF0000"
ElseIf Stat = 1 Then
    SS = "Online"
    Color = "00FF00"
End If

SS0 = ""

SS1 = SS
SS2 = Time
SS3 = s
SS4 = n
SS5 = t
SS6 = STR(GameServer.LocalPort)
SS7 = frmServer.Socket(0).LocalIP

Open FileName For Output As #1
    Print #1, ""
Close #1

If Stat >= 2 Then Exit Sub

If FileExist("DontUpdateStatus") = True Then Exit Sub

    InternetConnection = InternetOpen("FTPControl", 1, vbNullString, vbNullString, 0)
    If InternetConnection = 0 Then
        MsgBox ("Error opening internet connection!")
    Else
        FTPConnection = InternetConnect(InternetConnection, "", 0, "", "", 1, 0, 0)
        If FTPConnection = 0 Then MsgBox ("Error connecting to FTP server!")
    End If
    If FTPConnection <> 0 Then
        SaveFile = FtpPutFile(FTPConnection, FileName, "status.php", 1, 0)
        If SaveFile = False Then MsgBox ("Error sending Status.php file to FTP server!")

        CloseFTP = InternetCloseHandle(FTPConnection)
        If CloseFTP = False Then MsgBox ("Error closing FTP connection!")
        CloseFTP = InternetCloseHandle(InternetConnection)
        If CloseFTP = False Then MsgBox ("Error closing internet connection!")
    End If
End Sub

```
Now lets open modGeneral.

Now at the bottom of sub InitServer, before the End Sub add this:
```
Call SaveStatus(1)
```
Now, still in modGeneral, go to sub DestroyServer find this:
```
DoEvents
```
and add this under it:
```
Call SaveStatus(0)
```
Done there. Open modGameLogic and head to sub JoinGame.
Find this:
```
Call DisabledTimeTo(index)
```
and under that add this:
```
Call SaveStatus(1)
```
head on over to sub LeftGame and find this:
```
Call RemovePMember(index)
```
just below that add this:
```
Call SaveStatus(1)
```
And we're done!!!

Make sure to change , , and to your info in modStatus.

What this does is it uploads the file status.php (can be changed) to the root (can be changed) of your ftp server where it can then be called by other php files.

here is a small tutorial on how to use to  the current functions if you aren't familiar with php.

let's take this:

```
server_status()
```
That will print either "Online" or "Offline"

but, as with all my functions, you can change it to

```
server_status($output_method = 'string')
```
to have it return a string instead of just printing it. This is useful if you want it to display a picture instead of just printing "Online" and can be used like this (I haven't tried this yet so if someone could confirm…)

```
if (server_status($output_method = 'string') == "Online")
echo "![](online.jpg)"
else
echo "![](offline.jpg)"
```
EDIT: Tested right now and it works like a charm!

Those are the basics on how to use the functions here's the list of them:

```
server_status()
```
returns/prints whether the server is online or offline

```
server_ip()
```
returns/prints the server ip address

```
server_port()
```
returns/prints the servers port

```
last_mod()
```
returns/prints the last time the server was started

```
number_online()
```
returns/prints the number of players online

```
whois_online()
```
returns/prints the names of the players online

```
full_online()
```
returns/prints a combination of the number and names of players online

NOTE: Remember to use an Include in order to use the commands

Well That's all, I hope everyone enjoys this!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...