Mirage Source

Free ORPG making software.
It is currently Sat Apr 27, 2024 10:37 pm

All times are UTC




Post new topic Reply to topic  [ 48 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Fri Dec 08, 2006 8:21 am 
Offline
Pro

Joined: Mon May 29, 2006 2:15 am
Posts: 368
Original Author: Unknown


Description: This will be good, i'm sure william did something very similar to this for K2H's "who's online" internet portion of his website. Basically, this reads information, saves it to an HTML file, and automatically updates your site via FTP for you. It does require knowledge of HTML to get it working the way you want, however. Also, there are easier/better ways of doing this, such as using an SQL server. Final Note, FTP isn't the most secure protocol in the world (it sends passwords in plain-text), so if someone wants to revise this tutorial using SSH or something, that'd be awesome.


[Original Post]
Difficulty: Medium 3/5

What this does-

This code will create a Statis.htm file that will display whether the server is up or down. The server will then send the file via FTP to a webserver. It is really easy to customize the file that the server makes to whatever you want, the main purpose of this code is the sending of the file to the webserver.

What you need-

A FTP accessible webserver.

The code-

All of this code is Server side.

First add the following code to the top of any module, I created a new module called modStatis for this code. All of this code must go into the same module!

Code:
Dim Statis As String
Dim ServerStatis 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



The last part of this code contains the functions that do the "dirty" work. You'll see what they do in a second.

Now add this to the module
Code:
Sub SaveStatis(Stat As Byte)
Dim SS As String
Dim SS0 As String
Dim SS1 As String
Dim SS2 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

FileName = App.Path & "\Statis.htm"

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

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

SS0 = "<!-- " & Stat & " -->"

SS1 = "        <td width='53%'><font color='#" & Color & "' face='Courier New, Courier, mono'>" & SS & "</font></td>"
SS2 = "        <td width='72%'><font color='#999999' face='Courier New, Courier, mono'>" & Time & " (GMT -4:00)</font></td>"

Open FileName For Output As #1
    Print #1, "<HTML>"
    Print #1, "<HEAD>"
    Print #1, "<TITLE>Server Statis</TITLE>"
    Print #1, "</HEAD>"
    Print #1, "<BODY>"
    Print #1, SS0
    Print #1, "<h1 align='center'><font color='#333399'>Server Statis</font></h1>"
    Print #1, "<br></br><table width='18%' border='1' align='center'>"
    Print #1, "    <tr>"
    Print #1, "        <td width='47'>The server is</td>"
    Print #1, SS1
    Print #1, "    </tr>"
    Print #1, "</table>"
    Print #1, "<table width='31%' border='1' align='center'>"
    Print #1, "    <tr>"
    Print #1, "        <td width='28%'>Last Changed</td>"
    Print #1, SS2
    Print #1, "    </tr>"
    Print #1, "</table>"
    Print #1, "</BODY>"
    Print #1, "</HTML>"
Close #1

If Stat >= 2 Then Exit Sub

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

    InternetConnection = InternetOpen("FTPControl", 1, vbNullString, vbNullString, 0)
    If InternetConnection = 0 Then
        MsgBox ("Error opening internet connection!")
    Else
        FTPConnection = InternetConnect(InternetConnection, "<FTP SERVER>", 0, "<USERNAME>", "<PASSWORD>", 1, 0, 0)
        If FTPConnection = 0 Then MsgBox ("Error connecting to FTP server!")
    End If
    If FTPConnection <> 0 Then
        SaveFile = FtpPutFile(FTPConnection, FileName, "Statis.htm", 1, 0)
        If SaveFile = False Then MsgBox ("Error sending Statis.htm 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



What this code does-
Code:
CurrentTime = Now
Time = Format(CurrentTime, "h:mm AMPM d, yyyy")


This code get's the current time and gives it a 2:00 PM June 16, 2005 format.
Code:
If Stat = 0 Then
    SS = "Offline"
    Color = "FF0000"
ElseIf Stat = 1 Then
    SS = "Online"
    Color = "00FF00"
ElseIf Stat = 2 Then
    SS = "loading"
    Color = "0000FF"
End If


Simple enough, this code uses the number that was passed into Sub SaveStatis to dertermin weather the server is Online, Offline, Or Loading and assigns the color that will be used to display the statis. (For ex, if the server is Online then "Online" will be colored green in the Statis.htm file.
Code:
SS0 = "<!-- " & Stat & " -->"


This is used so other programs can easily determine the server's statis
Code:
SS1 = "        <td width='53%'><font color='#" & Color & "' face='Courier New, Courier, mono'>" & SS & "</font></td>"
SS2 = "        <td width='72%'><font color='#999999' face='Courier New, Courier, mono'>" & Time & " (GMT -4:00)</font></td>"



The two most important lines in the statis.htm file, they are the lines that display the server's statis and the time the file was updated.
Code:
Open FileName For Output As #1
    Print #1, "<HTML>"
    Print #1, "<HEAD>"
    Print #1, "<TITLE>Server Statis</TITLE>"
    Print #1, "</HEAD>"
    Print #1, "<BODY>"
    Print #1, SS0
    Print #1, "<h1 align='center'><font color='#333399'>Server Statis</font></h1>"
    Print #1, "<br></br><table width='18%' border='1' align='center'>"
    Print #1, "    <tr>"
    Print #1, "        <td width='47'>The server is</td>"
    Print #1, SS1
    Print #1, "    </tr>"
    Print #1, "</table>"
    Print #1, "<table width='31%' border='1' align='center'>"
    Print #1, "    <tr>"
    Print #1, "        <td width='28%'>Last Changed</td>"
    Print #1, SS2
    Print #1, "    </tr>"
    Print #1, "</table>"
    Print #1, "</BODY>"
    Print #1, "</HTML>"
Close #1


This is the code that creates the Server.htm file, The file is in HTML format. This may look a little confusing at first, but It's not too bad when you look at it line by line.
Code:
If Stat >= 2 Then Exit Sub


You may have noticed that there is a "Loading" statis, this is mainly for the benefit of external programs. This line of code keeps the "Loading" statis from being sent to the webserver, mainly to save on the time it takes for the server to load.
Code:
If FileExist("DontUpdateStatis") = True Then Exit Sub

I'll get to this latter.
Code:
InternetConnection = InternetOpen("FTPControl", 1, vbNullString, vbNullString, 0)


This line opens an internet connection and saves the handel to "InternetConnection" This handel is required to open the FTP connection, and later close the internet connection.
Code:
    If InternetConnection = 0 Then
        MsgBox ("Error opening internet connection!")
    Else
        FTPConnection = InternetConnect(InternetConnection, "<FTP SERVER>", 0, "<USERNAME>", "<PASSWORD>", 1, 0, 0)
        If FTPConnection = 0 Then MsgBox ("Error connecting to FTP server!")
    End If


As long as there is an internet connection this code will make a connection to the FTP server and save the handle to "FTPConnection", this handel is needed so the next bit of code can send the file. And so the FTP connection can be closed.

[size=18px]VERY INPORTANT![/size]

Make shour that you change <FTP SERVER> to the FTP server's URL, <USERNAME> to you'r username, and <PASSWORD> to you'r password.
Code:
    If FTPConnection <> 0 Then
        SaveFile = FtpPutFile(FTPConnection, FileName, "Statis.htm", 1, 0)
        If SaveFile = False Then MsgBox ("Error sending Statis.htm file to FTP server!")


This bit of code will send the Statis.htm file to the FTP server as long as there is a FTP connection.
Code:
        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


This code just cleans up so to speek, It closes the FTP connection and then the internet connection, in that order.

Ok, so now we are left with a sup that will send the server's Online/Offline statis to a FTP server. All that is left is to put in the sub's call's.

Att the very bottom of Sub InitServer() (In modGeneral) add:
Code:
    Call SaveStatis(1)



At the top add:
Code:
    Call SaveStatis(2)



And at the very bottom of Sub DestroyServer(), but BEFORE "End" add:
Code:
Call SaveStatis(0)



That's about it. If you rember befor I mentioned this bit of code:
Code:
If FileExist("DontUpdateStatis") = True Then Exit Sub




If you make a file called "DontUpdateStatis" (no extension) and put it in the server's directory the server won't send the Statis.htm file to the webhost, this is useful during debugging, to save time starting and stopping the server.

I also highly recommend adding the following code to frmServer if is isn't already there (CHECK, it might be there already).
Code:
Private Sub Form_Terminate()
    Call DestroyServer
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Call DestroyServer
End Sub



One last thing, if you want to get a file from a FTP server, or if you wan't to delete a file off of a FTP server you can use theas functions: (How they are use I'll leave up to you)
Code:
Private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" (ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean



Anyway, I hope this helps. :D

[/Original Post :) ]

If you need any help getting this to work or there are any problems with the code, let me know.

_________________
Image
Image
The quality of a man is not measured by how well he treats the knowledgeable and competent, but rather how he treats those less fortunate than himself.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 1:20 pm 
Offline
Knowledgeable
User avatar

Joined: Sun Dec 03, 2006 6:18 am
Posts: 228
Location: NJ, United States
wow, awesome tut dude. I'm deff gonna get this to my game but i got school right now, XD so il add it wen i get home and ill tell you how i did. nice job


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 3:00 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
Yeah.. its close to what Im doing. Thanks for releasing a unique feature :P

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 4:39 pm 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
William wrote:
Yeah.. its close to what Im doing. Thanks for releasing a unique feature :P


I doubt it's going to stay unique for long -_-


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 5:32 pm 
Offline
Persistant Poster
User avatar

Joined: Tue May 30, 2006 2:07 am
Posts: 836
Location: Nashville, Tennessee, USA
Google Talk: rs.ruggles@gmail.com
William wrote:
Yeah.. its close to what Im doing. Thanks for releasing a unique feature :P


This is not the first time that exact code surfaced on these forums. Obsidian put "Original Author: Unknown". I remember this tut because through out the whole thing "Status" is spelled as "Statis". I think the original author may have been Caine or that Grubert fella. *shrugs*

Thanks for posting, been trying to find this tut for ages :)

_________________
I'm on Facebook! Google Plus My Youtube Channel My Steam Profile

Image


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 6:17 pm 
Offline
Pro

Joined: Mon May 29, 2006 2:15 am
Posts: 368
yeah i saw this on the backup forum, i went through and fixed a lot of spelling errors, and stuff. Sorry to kind of rain on your parade though william, it is still a great feature that you added without the use of this code. nicely done :D

but yeah it's an older tutorial that i thought i should bring back up, since a lot of people were trying to do something like this.

[Edit]
I think i'm going to rewrite this sometime next week and replace FTP with SSH though. I'm not sure what VB has in the neighborhood of SSH controls but atleast you won't have to worry about your site getting compromised (from this)

_________________
Image
Image
The quality of a man is not measured by how well he treats the knowledgeable and competent, but rather how he treats those less fortunate than himself.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 09, 2006 1:00 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
Hehe :P I thought you made it. didnt see the author thing.

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 9:10 pm 
Offline
Persistant Poster
User avatar

Joined: Wed Nov 29, 2006 11:25 pm
Posts: 860
Location: Ayer
Mm nice code. I converted it to users in 5 minutes or so.
Spiffy! Is it me or does this lag your server 0____o

:: Pando

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 9:58 pm 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
Pando wrote:
Mm nice code. I converted it to users in 5 minutes or so.
Spiffy! Is it me or does this lag your server 0____o

:: Pando


Constantly writing to a file?

I'd say.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 11:22 pm 
Offline
Persistant Poster
User avatar

Joined: Tue May 30, 2006 2:07 am
Posts: 836
Location: Nashville, Tennessee, USA
Google Talk: rs.ruggles@gmail.com
I'm sure it'd be just as easy to write a seperate program that does this. I guess it'd be more work, but oviously less server stress.

_________________
I'm on Facebook! Google Plus My Youtube Channel My Steam Profile

Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 12:49 am 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
sql ftw tbh


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 12:54 am 
Offline
Pro

Joined: Sat Jun 03, 2006 8:32 pm
Posts: 415
yeah I dont see why more dont use SQL... its a better way to store data and makes viewing it on a website pretty easy


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 1:15 am 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
Plus having multi-server sharing the same account/item/npc info is as easy as 1,2,3 ^_^


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 1:17 am 
Offline
Pro

Joined: Mon May 29, 2006 2:15 am
Posts: 368
Not everyone hosts their own server. And not all hosting companys have SQL automatically set up for their sites. Or maybe they just don't know how to USE it

_________________
Image
Image
The quality of a man is not measured by how well he treats the knowledgeable and competent, but rather how he treats those less fortunate than himself.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 1:18 am 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
Obsidian wrote:
Not everyone hosts their own server. And not all hosting companys have SQL automatically set up for their sites. Or maybe they just don't know how to USE it


Then get a hosting company that does?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 1:22 am 
Offline
Pro

Joined: Sat Jun 03, 2006 8:32 pm
Posts: 415
Yeah you could have a seperate person to just host the MySQL if you wanted. Plus its pretty simple to set up actually.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 1:24 am 
Offline
Pro

Joined: Mon May 29, 2006 2:15 am
Posts: 368
Yeah, but some people are pretty lazy and won't do it themselves...

_________________
Image
Image
The quality of a man is not measured by how well he treats the knowledgeable and competent, but rather how he treats those less fortunate than himself.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 1:28 am 
Offline
Pro

Joined: Sat Jun 03, 2006 8:32 pm
Posts: 415
Yeah for people entirely new to all of this it might not be a good idea but if someone wanted to make a serious game I think it would be the best option... at least better than text files.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 1:30 am 
I like binary. It runs alot faster than text or ini. Maybe not as fast as mysql, but you stand a higher chance to be hacked with mysql.


Top
  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 3:19 am 
Offline
Community Leader
User avatar

Joined: Sun May 28, 2006 10:29 pm
Posts: 1762
Location: Salt Lake City, UT, USA
Google Talk: Darunada@gmail.com
MySQL uses more memory. You have a copy of everything in memory for the database, then a copy of everything used in the game in memory for hte game. Essentially for Mirage Source as it is, you would use 2x the memory by using MySQL.

Maybe the slight speed increase is worth it to you...

_________________
I'm on Facebook! Google Plus LinkedIn My Youtube Channel Send me an email Call me with Skype Check me out on Bitbucket Yup, I'm an EVE Online player!
Why not try my app, ColorEye, on your Android devlce?
Do you like social gaming? Fight it out in Battle Juice!

I am a professional software developer in Salt Lake City, UT.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 1:52 pm 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
Dave wrote:
MySQL uses more memory. You have a copy of everything in memory for the database, then a copy of everything used in the game in memory for hte game. Essentially for Mirage Source as it is, you would use 2x the memory by using MySQL.

Maybe the slight speed increase is worth it to you...


But if he wanted that, he shouldn't be trying to have the server update a webpage.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 2:56 pm 
I toyed with a MS 307, it really wasn't worth it, imo. Sure, the server loaded up pretty quick, but other than that, I saw no significant improvement over the binary files I use now.

I suggest you use 303 or MSE1, and add the binary stuff, I'll help you add it, if you need.


Top
  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 3:01 pm 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
Advocate wrote:
I toyed with a MS 307, it really wasn't worth it, imo. Sure, the server loaded up pretty quick, but other than that, I saw no significant improvement over the binary files I use now.

I suggest you use 303 or MSE1, and add the binary stuff, I'll help you add it, if you need.


*sigh*

You are once again saying that speed is the most important factor when it comes to the server.

Also, why would you see any speed increase when you were the only one online?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 3:06 pm 
Offline
Community Leader
User avatar

Joined: Sun May 28, 2006 10:29 pm
Posts: 1762
Location: Salt Lake City, UT, USA
Google Talk: Darunada@gmail.com
The server boots faster, kite.

If speed is the most important thing, by all means use MySQL, as long as you understand that you will be using a lot of memory.

_________________
I'm on Facebook! Google Plus LinkedIn My Youtube Channel Send me an email Call me with Skype Check me out on Bitbucket Yup, I'm an EVE Online player!
Why not try my app, ColorEye, on your Android devlce?
Do you like social gaming? Fight it out in Battle Juice!

I am a professional software developer in Salt Lake City, UT.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 3:28 pm 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
Dave, did you even read his post?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 48 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group