Attribute VB_Name = "Console" Function WriteLine(uiLine As String) 'Main function to add a new line in the box on the GUI window hUI.uiConsole.Text = hUI.uiConsole & vbCrLf & uiLine End Function Function startConsole() 'Print the server information in the box on the GUI window hUI.uiConsole = "" Call Console.WriteLine("HOLOGRAPH***********************************************************") Call Console.WriteLine("THE FREE OPEN-SOURCE HABBO HOTEL EMULATOR") Call Console.WriteLine("FOR MORE DETAILS CHECK LEGAL.TXT") Call Console.WriteLine("COPYRIGHT (C) 2007-2008 BY HOLOGRAPH TEAM") Call Console.WriteLine("VISIT WWW.HOLOGRAPHEMULATOR.COM") Call Console.WriteLine("") Call Console.WriteLine("VERSION:") Call Console.WriteLine(" CORE: V" & App.Major) Call Console.WriteLine(" REVISION: R" & App.Revision) Call Console.WriteLine(" CLIENT: V18") Call Console.WriteLine("") End Function Function startServer() 'Start the server hUI.uiCommand.Enabled = False hUI.Show startConsole Call Console.WriteLine("[SERVER] Starting up server...") DoEvents Sleep 700 Call Console.WriteLine("[SERVER] Retrieving settings from config.ini...") Call Console.WriteLine("") If FSO.FileExists(App.Path & "\bin\config.ini") = False Then 'If the config.file in the /bin/ folder is not found 'Shutdown Call Console.WriteLine("[SERVER] config.ini not found! Shutting down...") stopServer End If 'Set the location of the config.ini file in memory, so the app can find it later CONF = App.Path & "\bin\config.ini" Dim sqlHost As String Dim sqlPort As Integer Dim sqlDB As String Dim sqlUser As String Dim sqlPassword As String 'Read the SQL details from the config.ini with the ReadINI function sqlHost = ReadINI("mysql", "host", CONF) sqlPort = ReadINI("mysql", "port", CONF) sqlUser = ReadINI("mysql", "username", CONF) sqlPassword = ReadINI("mysql", "password", CONF) sqlDB = ReadINI("mysql", "database", CONF) 'Make a line of ****s as long as the password, so you can run the server and others don't see the password For p = 1 To Len(sqlPassword) sqlPassword_Hidden = sqlPassword_Hidden & "*" Next p If sqlPassword_Hidden = "" Then sqlPassword_Hidden = "EMPTY" 'If the password is blank, then show 'EMPTY' as password 'Display we're attempting to connect Call Console.WriteLine("[MYSQL] Attempting to connect on " & sqlHost & ":" & sqlPort & ", with UID: " & sqlUser & " and PWD: " & sqlPassword_Hidden) If HoloDB.checkConnection(sqlHost, sqlPort, sqlDB, sqlUser, sqlPassword) = False Then 'If the attempting to connect has failed, display it and shutdown Call Console.WriteLine("[MYSQL] Connection failed.") Call Console.WriteLine("") Sleep 2300 DoEvents stopServer End If 'Open the connection to the database HoloDB.openConnection sqlHost, sqlPort, sqlDB, sqlUser, sqlPassword Call Console.WriteLine("[MYSQL] Connection successfull.") Call Console.WriteLine("") 'Load the settings from the config.ini file modServer.loadPreferences Call Console.WriteLine("[SERVER] Preferences succesfully loaded.") Call Console.WriteLine("") DoEvents Sleep 400 'Load the static room data (guestrooms) modServer.loadRoomModels Call Console.WriteLine("[SERVER] Loaded static guestroom data into memory.") Call Console.WriteLine("") DoEvents Sleep 400 modServer.rehashCatalogue DoEvents Call Console.WriteLine("[SERVER] Retrieved catalogue pages to \bin\catalogue\ folder.") Call Console.WriteLine("") DoEvents 'Perform some housekeeping HoloDB.runQuery ("UPDATE guestrooms SET incnt = '0'") Call Console.WriteLine("[MYSQL] Guestroom incounts reset.") HoloDB.runQuery ("TRUNCATE TABLE sso") Call Console.WriteLine("[MYSQL] 'sso' table cleared.") Call Console.WriteLine("") 'Perform some housekeeping DoEvents 'Read users, guestrooms and furnitures count from system table in database cntRw = HoloDB.runRead("SELECT users,guestrooms,furnitures FROM system") 'Display it Call Console.WriteLine("[MYSQL] Found " & Split(cntRw, Chr(9))(0) & " users, " & Split(cntRw, Chr(9))(1) & " guestrooms and " & Split(cntRw, Chr(9))(2) & " furnitures.") Call Console.WriteLine("") DoEvents Dim sckPort As Integer 'Read the port from the config.ini file, where the main socket has to listen on sckPort = ReadINI("sckmgr", "port", CONF) Call Console.WriteLine("[SCKMGR] Setting up socket manager on port " & sckPort & "...") DoEvents Sleep 340 On Error GoTo err_sck 'If a socket error is detected, go to the error handling part hSYS.sckGame(0).LocalPort = sckPort 'Set the port for the main socket hSYS.sckGame(0).Listen 'Open the main socket On Error Resume Next Server.sPort = sckPort 'Set the port used in the Server. 'thing', where the settings and preferences are recorded Call Console.WriteLine("[SCKMGR] Socket manager ready.") Call Console.WriteLine("") Call Console.WriteLine("[SERVER] Ready for connections.") Call Console.WriteLine("") 'Make it able to type text in the bar hUI.uiCommand.Enabled = True hUI.uiCommand.SetFocus Exit Function 'Exit here, don't go further err_sck: 'Oh noes a socket error!, let's tell it to the user eh? Call Console.WriteLine("[SCKMGR] Failed to set up SCKMGR on port " & sckPort & ". Probably another application is already bound to this port.") Call Console.WriteLine("") Sleep 2300 DoEvents 'Wait for other things stopServer 'Close the server End Function Function singleCall(uiCommand As String) Select Case uiCommand 'Select the command entered from the one-part commands Case "stats" 'View status cntRw = HoloDB.runRead("SELECT users,guestrooms,furnitures FROM system") 'Select users, guestrooms and furnitures from system table in database If Server.freeScks = "" Then sfreeScks = "none" Else sfreeScks = Server.freeScks 'Make a display string for the free sockets list 'Write it to the lines box on the interface form Call Console.WriteLine("[STATS] Holograph Emulator found " & Split(cntRw, Chr(9))(0) & " users, " & Split(cntRw, Chr(9))(1) & " guestrooms and " & Split(cntRw, Chr(9))(2) & " furnitures.") Call Console.WriteLine("[STATS] Online users: " & Server.onlineCount & ", online peak: " & Server.onlinePeak & ", accepted connections: " & Server.acceptedConnections & ".") Call Console.WriteLine("[STATS] Socket range: " & Server.sckCount & ", free sockets: " & sfreeScks & ".") Case "help" 'Commands available list Call Console.WriteLine("") Call Console.WriteLine("Available commands:") Call Console.WriteLine(" - mysql QUERY = runs MySQL query") Call Console.WriteLine(" - clear = clears debugger") Call Console.WriteLine(" - exit/shutdown = close server") Call Console.WriteLine("") Case "exit", "shutdown" 'Stop the server stopServer Case "clear" 'Clear the lines box startConsole Case "catconvert" 'TESTING COMMAND, add catalogue pages to database, only works for my (Nillus) comp Dim pS() As String pP = FSO.OpenTextFile(App.Path & "\bin\pp.txt", ForReading).ReadAll pS() = Split(pP, ";") For a = 0 To UBound(pS) nP = pS(a) If nP <> "" And InStr(pD, "|" & nP & "|") = False Then If FSO.FolderExists("C:\DEVELOPMENT\DebboProject V4\local\catalogue\" & nP & "\") = True Then nD = Replace(FSO.OpenTextFile("C:\DEVELOPMENT\DebboProject V4\local\catalogue\" & nP & "\page.txt", ForReading).ReadAll, "'", Chr(129)) HoloDB.runQuery ("INSERT INTO catalogue (tab,content) VALUES ('" & nP & "','" & nD & "')") pD = pD & "|" & nP & "|" End If End If Next a Case "about" 'Show info about this server Call Console.WriteLine("[ABOUT] Holograph is the light-weight open source VB Habbo Hotel emulator, check progress on RaGEZONE MMORPG Development forums.") Case "rehash" 'Reload settings Call modServer.loadPreferences Call Console.WriteLine("[SERVER] Reloaded settings succesfully.") Case Else 'A non-existing command, tell the user to check 'help' to see all commands Call Console.WriteLine("Command '" & uiCommand & "' not found. Use 'help' to see all commands.") End Select End Function Function multiCall(uiCommand As String) 'Select the command entered from the multi-part commands Select Case Mid(uiCommand, 1, InStr(uiCommand, " ") - 1) Case "mysql" 'MySQL command from the command line, handy! uiCommand = Replace(uiCommand, "mysql ", "") 'Cut the first part off, so you get the second part If InStr(uiCommand, "select") Then 'If it's a SELECT query, do it different uiCommand = HoloDB.runRead(uiCommand) 'Get the result from the database If uiCommand <> "" Then 'If there is a result found Call Console.WriteLine("[MYSQL] Result: " & uiCommand) Else 'There is nothing found, table or field was probably not found Call Console.WriteLine("[MYSQL] Result: ERROR! FIELD/TABLE NOT FOUND") End If Else 'It was a non-SELECT command, so execute something on the database, like deleting something HoloDB.runQuery (uiCommand) 'Run it on the database Console.WriteLine ("[MYSQL] Query executed on database (non-verified)") End If Case Else 'A non-existing command, tell the user to check 'help' to see all commands Call Console.WriteLine("Command '" & uiCommand & "' not found. Use 'help' to see all commands.") End Select End Function Function stopServer() 'Write 'what's going to happen now' in the lines box Call Console.WriteLine("[MYSQL] Closing existing database connection(s)...") Call Console.WriteLine("[SERVER] Dumping catalogue .bin files...") Call Console.WriteLine("[SERVER] Shutting down...") DoEvents 'Wait for other things 'Set the catalogue folder location folPath = App.Path & "\bin\catalogue" 'Dump the folder (if it exists) If FSO.FolderExists(folPath) = True Then FSO.DeleteFolder (folPath) HoloDB.closeConnection 'Close the database connection DoEvents Sleep 1500 'Wait 1,5 seconds hUI.Hide 'Hide the main form For Each Form In Forms 'Unload all forms from the memory Unload Form Next End 'Dump the thread + stop application End Function