dg1423 Posted June 23, 2007 Author Share Posted June 23, 2007 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 StringDim ServerStatus As StringDim ServerTime As StringDim InternetConnection As LongDim FTPConnection As LongPrivate 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 LongPrivate 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 LongPrivate 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 BooleanPrivate Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As IntegerSub SaveStatus(Stat As Byte)Dim SS As StringDim SS0 As StringDim SS1 As StringDim SS2 As StringDim SS3 As StringDim SS4 As StringDim SS5 As StringDim SS6 As StringDim SS7 As StringDim Time As StringDim Color As StringDim CurrentTime As VariantDim FileName As StringDim SaveFile As BooleanDim CloseFTP As IntegerDim s As StringDim n As Long, i As LongDim 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 IfFileName = App.Path & "\status.php"CurrentTime = Now '3:00 PM Jan 16, 2005Time = 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 IfSS0 = ""SS1 = SSSS2 = TimeSS3 = sSS4 = nSS5 = tSS6 = STR(GameServer.LocalPort)SS7 = frmServer.Socket(0).LocalIPOpen FileName For Output As #1 Print #1, ""Close #1If Stat >= 2 Then Exit SubIf 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 IfEnd 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)"elseecho "![](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 onlineNOTE: Remember to use an Include in order to use the commandsWell That's all, I hope everyone enjoys this! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now