![]() |
Updating a Website with Server Information - Printable Version +- Mirage Engine (https://mirage-engine.uk/forums) +-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61) +--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18) +---- Forum: Resources (https://mirage-engine.uk/forums/forumdisplay.php?fid=49) +---- Thread: Updating a Website with Server Information (/showthread.php?tid=455) Pages:
1
2
|
Updating a Website with Server Information - Obsidian - 08-12-2006 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 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) What this code does- Code: CurrentTime = Now This code get's the current time and gives it a 2:00 PM June 16, 2005 format. Code: If Stat = 0 Then 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 = "" This is used so other programs can easily determine the server's statis Code: SS1 = " " & SS & "" 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 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 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 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 to the FTP server's URL, to you'r username, and to you'r password. Code: If FTPConnection 0 Then 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) 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() 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 Anyway, I hope this helps. ![]() [/Original Post ![]() If you need any help getting this to work or there are any problems with the code, let me know. - Forte - 08-12-2006 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 - William - 08-12-2006 Yeah.. its close to what Im doing. Thanks for releasing a unique feature ![]() - Robin - 08-12-2006 William Wrote:Yeah.. its close to what Im doing. Thanks for releasing a unique feature I doubt it's going to stay unique for long -_- - Rian - 08-12-2006 William Wrote:Yeah.. its close to what Im doing. Thanks for releasing a unique feature 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 ![]() - Obsidian - 08-12-2006 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 ![]() 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) - William - 09-12-2006 Hehe ![]() - Tony - 15-12-2006 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 - Robin - 15-12-2006 Pando Wrote:Mm nice code. I converted it to users in 5 minutes or so. Constantly writing to a file? I'd say. - Rian - 15-12-2006 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. - Robin - 16-12-2006 sql ftw tbh - halla - 16-12-2006 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 - Robin - 16-12-2006 Plus having multi-server sharing the same account/item/npc info is as easy as 1,2,3 ^_^ - Obsidian - 16-12-2006 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 - Robin - 16-12-2006 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? - halla - 16-12-2006 Yeah you could have a seperate person to just host the MySQL if you wanted. Plus its pretty simple to set up actually. - Obsidian - 16-12-2006 Yeah, but some people are pretty lazy and won't do it themselves... - halla - 16-12-2006 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. - Matt - 16-12-2006 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. - Robin - 16-12-2006 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. But if he wanted that, he shouldn't be trying to have the server update a webpage. - Matt - 16-12-2006 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. - Robin - 16-12-2006 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. *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? - Robin - 16-12-2006 Dave, did you even read his post? - Matt - 16-12-2006 And you are once again thinking you are a god at programming. I didn't say speed is the most important. If you use binary, you get the speed, and you don't use up as much memory. The speed is needed too. It's not the most important factor, but it is a nice optimization to have. And when did I say I was the ONLY one on the game? You think I test everything by myself? Geeze, stop assuming shit. You're really getting annoying. - Robin - 16-12-2006 I am not saying I am great at programming, hell, I know next to nothing about MySQL. I am simply saying that having the server updating and re-uploading a webpage constantly is going to have very bad speed effects on your game, and that a better way would to simply save everything in MySQL which your server can access. Also, MySQL is generally faster. |