Mirage Source http://miragesource.net/forums/ |
|
Config File http://miragesource.net/forums/viewtopic.php?f=183&t=5385 |
Page 1 of 56 |
Author: | Labmonkey [ Tue Apr 07, 2009 4:39 pm ] |
Post subject: | Config File |
This is a simple config file that stores player's usernames/passwords. It also is an IP config. If you are a bit more advanced or just don't like ini files you can use this method instead viewtopic.php?p=65515#p65515 Difficulty 2/5 if copy paste Difficulty 3/5 if customizing first we have to make some ini read/write functions. That starts by declaring some stuff for ini files at the top of modGeneral (right?) put this Code: '--------for INI file read/write Private Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long Private Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long '------------------- Now all the way at the bottom of modGeneral put the actual ini functions. Code: 'reads ini string Public Function ReadIni(FileName As String, Section As String, Key As String) As String Dim RetVal As String * 255, v As Long v = GetPrivateProfileString(Section, Key, "", RetVal, 255, FileName) ReadIni = Left(RetVal, v) End Function 'reads ini section Public Function ReadIniSection(FileName As String, Section As String) As String Dim RetVal As String * 255, v As Long v = GetPrivateProfileSection(Section, RetVal, 255, FileName) ReadIniSection = Left(RetVal, v - 1) End Function 'writes ini Public Sub WriteIni(FileName As String, Section As String, Key As String, Value As String) WritePrivateProfileString Section, Key, Value, FileName End Sub 'writes ini section Public Sub WriteIniSection(FileName As String, Section As String, Value As String) WritePrivateProfileSection Section, Value, FileName End Sub DON'T FORGET THIS PART! Create a file called Config.ini in the client folder. In my config file I am putting the IP, Player's Username, and Player's Password. Mine looks like this Code: [GENERAL] Username=Labmonkey Password=nopeeking IP=localhost First lets do the ip config find Code: ' Winsock globals Replace the entire section (2 lines) with Code: ' Winsock globals Public GAME_IP As String Now our ip is a variable, so let us go to Sub Main to set it to what is in our config file. Find Code: Call SetStatus("Loading...") Under it put Code: ' Get the ip from the file GAME_IP = ReadIni(App.Path & "\Config.ini", "GENERAL", "Ip") Now lets read the username and password from the config file. In frmLogin, in Sub Form_Load, under Code: Me.Picture = LoadPicture(App.Path & "/gfx/interface/Menu.bmp") put Code: txtName.Text = ReadIni(App.Path & "/Config.ini", "GENERAL", "Username") txtPassword.Text = ReadIni(App.Path & "/Config.ini", "GENERAL", "Password") Now we want to store the username and password in the ini file. We will do that when the player logs in. still in frmLogin, in sub lblConnect_Click, under Code: Call MenuState(MENU_STATE_LOGIN) put Code: Call WriteIni(App.Path & "/Config.ini", "GENERAL", "Username", txtName.Text) Now before we put the password in, some people might not want their password stored in a file on their computer for anyone to steal. That is why we are going to make a little "remember password" checkbox. Ok so in frmLogin make a new checkbox. Call it chkRemember. I also suggest making it 13x13, and adding a label saying "Remember Password", but it all depends on how your game looks. now under where we put Code: Call WriteIni(App.Path & "/Config.ini", "GENERAL", "Username", txtName.Text) put Code: if chkRemember.Value = 1 Then Call WriteIni(App.Path & "/Config.ini", "GENERAL", "Password", txtPassword.Text) else Call WriteIni(App.Path & "/Config.ini", "GENERAL", "Password", "") In frmLogin, sub frmload, at the bottom right before endsub up Code: If txtPassword.Text = "" Then chkRemember.Value = 0 Else chkRemember.Value = 1
|
Author: | GIAKEN [ Tue Apr 07, 2009 5:53 pm ] |
Post subject: | Re: Config File |
People shouldn't be able to change the IP. |
Author: | Rian [ Tue Apr 07, 2009 6:20 pm ] |
Post subject: | Re: Config File |
They should if they're making a game-maker rather than a game. Though I wouldn't suggest writeINI and readINI. Use getVar and putVar. It does the same thing, and the server already comes equipped with it. Why shouldn't the client follow suit? Code: Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyname As Any, ByVal lpdefault As String, ByVal lpreturnedstring As String, ByVal nsize As Long, ByVal lpfilename As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyname As Any, ByVal lpString As String, ByVal lpfilename As String) As Long ' gets a string from a text file Public Function GetVar(File As String, Header As String, Var As String) As String Dim sSpaces As String ' Max string length Dim szReturn As String ' Return default value if not found szReturn = vbNullString sSpaces = Space$(5000) Call GetPrivateProfileString$(Header, Var, szReturn, sSpaces, Len(sSpaces), File) GetVar = RTrim$(sSpaces) GetVar = Left$(GetVar, Len(GetVar) - 1) End Function ' writes a variable to a text file Public Sub PutVar(File As String, Header As String, Var As String, Value As String) Call WritePrivateProfileString$(Header, Var, Value, File) End Sub |
Author: | GIAKEN [ Tue Apr 07, 2009 6:21 pm ] |
Post subject: | Re: Config File |
The person that made the game should be able to change it, but the players shouldn't be able to change it. That's 1 way how I hacked some games by hooking their client up with my server and catching the packets. |
Author: | doomJoost1 [ Tue Apr 07, 2009 6:27 pm ] |
Post subject: | Re: Config File |
It may be cuter to encrypt p/w's before storing them in a .txt file. |
Author: | Rian [ Tue Apr 07, 2009 6:37 pm ] |
Post subject: | Re: Config File |
And then you'd have to make like a /setip command or something. Server side access checks and what not. |
Author: | Labmonkey [ Tue Apr 07, 2009 6:42 pm ] |
Post subject: | Re: Config File |
Code: The person that made the game should be able to change it, but the players shouldn't be able to change it. That's 1 way how I hacked some games by hooking their client up with my server and catching the packets. Giaken, I showed you how to do that lol. If your game isn't programmed idiotically (which mirage currently is right now, don't worry I am going to fix it!) then there is nothing you can do by changing the ip through the Config.ini file. Code: It may be cuter to encrypt p/w's before storing them in a .txt file. I don't think it is worth it to add a whole encryption system just to read a string that you can choose not to store if you are paranoid. If someone really wants your password, encrypting it won't help as they will have the program to decrypt it also (the client). Just don't check the remember password checkbox. I realized that the remember password button does not stay checked, and I will fix that shorty. Then I will work on some security, and maybe we can have hackfest again . @Rian: You posted while I was posting, but I really don't get what you are saying. I am pretty sure giaken was implying to do something like he has in asphodel where the configuration is sent from the server to the client after connection. A /setip wouldnt work because you would need to be connected to something (a ip) in order to be able to use it . |
Author: | Rian [ Tue Apr 07, 2009 7:07 pm ] |
Post subject: | Re: Config File |
Labmonkey wrote: [code]@Rian: You posted while I was posting, but I really don't get what you are saying. I am pretty sure giaken was implying to do something like he has in asphodel where the configuration is sent from the server to the client after connection. A /setip wouldnt work because you would need to be connected to something (a ip) in order to be able to use it . Actually, I think quite the opposite. If you have a /setip command, it will write to the configuration file, and all you have to do is restart the client for the changes to take affect, and then you can distribute your client that way. Mind telling me how to connect to the server to retrieve the ip address used to connect to the server? |
Author: | GIAKEN [ Tue Apr 07, 2009 7:09 pm ] |
Post subject: | Re: Config File |
How does the client save the IP? The user can just change it... |
Author: | Labmonkey [ Tue Apr 07, 2009 11:01 pm ] |
Post subject: | Re: Config File |
Ok so here is how this works for all of you who somehow can't get this. Person A doesn't have vb6, but wants to make a game. They can't obtain vb6 in thier area, and don't want to "obtain" it. They use this, and change the ip to the ip from ipchicken.com or something. They then forward thier ports (portforward.com) and distribute the client to thier friends. They start making some maps and items and monsters and eventually have a little world in which people can play. YES! You can change the ip. That is the whole point. Yes it is also easy to change the ip for other people's games, but why would you want to? And don't tell me for hacking, because I already stated that I am going to fix the abuses. |
Author: | Anthony [ Wed Apr 08, 2009 6:32 pm ] |
Post subject: | Re: Config File |
I didn't read most of the posts but if it's being configured within the client and you aren't actually going to be editing the ini file then why not just save/load it as a binary file and instead of adding that extra code for read/get/write/whatever you can just do it like maps and stuff. This is what I do. Code: Public Sub LoadUserData() Dim FileName As String Dim f As Long FileName = App.Path & "\Data Files\config.dat" If Not FileExist("Data Files\config.dat") Then Call SetStatus("Creating user data file...") Call SaveUserData Exit Sub Else f = FreeFile Open FileName For Binary As #f Call SetStatus("Loading user data...") Get #f, , UserData.Pinned Get #f, , UserData.Save Get #f, , UserData.Username Get #f, , UserData.Password Close #f End If DoEvents End Sub Public Sub SaveUserData() Dim FileName As String Dim f As Long FileName = App.Path & "\Data Files\config.dat" f = FreeFile Open FileName For Binary As #f Put #f, , UserData.Pinned Put #f, , UserData.Save Put #f, , UserData.Username Put #f, , UserData.Password Close #f End Sub Public Sub ClearUserData() UserData.Pinned = 0 UserData.Save = 0 UserData.Username = vbNullString UserData.Password = vbNullString End Sub Type UserDataRec Pinned As Byte Save As Byte Username As String * NAME_LENGTH Password As String * NAME_LENGTH VitalConfig As Byte End Type Then in Sub Main I just clear it then load it and when I want to save it.. UserData.Username = "text".... Save UserData. Better? |
Author: | Labmonkey [ Thu Apr 09, 2009 6:17 pm ] |
Post subject: | Re: Config File |
The config.ini file makes it easy for the owner to edit it. If you read some other posts of mine (its fine if you aren't) I am trying to make a sort of "mirage for noobs" in order to get some more games made. Yes, binary configs are great! But if you are willing to make a binary editor, well, you probably don't need a tutorial for this . |
Author: | Anthony [ Thu Apr 09, 2009 6:22 pm ] |
Post subject: | Re: Config File |
The thing I was saying though was having it editable within the client. Have the IP Config in the client and then it'll just write it that way. It's easier and I think more noob friendly as well. |
Author: | Labmonkey [ Thu Apr 09, 2009 6:27 pm ] |
Post subject: | Re: Config File |
This tutorial was aimed for making an engine for people without vb6. Putting the button in-game means that all of the players need to find out what ip-config means, and why they shouldn't touch it. I don't want to go the route of playerworlds where it is put in your face that you are using a game generator thing. I really don't think it matters enough to argue over. If you would like to post anther way to do it go ahead . EDIT: Just realized you did. I will make a link at the top to your post. |
Author: | Anthony [ Thu Apr 09, 2009 7:07 pm ] |
Post subject: | Re: Config File |
I just prefer the binary way, it's less code and seems cleaner to me. Not arguing just trying to show alternatives xD. Other benefits include passwords and user names that aren't easily readable. Another option would be having a check for the clients first time being loaded or if the config file is non existent. Then if it isn't there run a quick setup for the client which asks for the IP and other things needed and it enters it into the binary config file on it's own. I get what you're saying with the ini files though but it just seems strange to me to do it in a non optimized fashion. |
Author: | Labmonkey [ Thu Apr 09, 2009 7:19 pm ] |
Post subject: | Re: Config File |
Quote: If you are a bit more advanced or just don't like ini files you can use this method instead viewtopic.php?p=65515#p65515 All good? |
Author: | GIAKEN [ Thu Apr 09, 2009 7:20 pm ] |
Post subject: | Re: Config File |
Just use GetVar and PutVar. |
Author: | Labmonkey [ Thu Apr 09, 2009 7:21 pm ] |
Post subject: | Re: Config File |
If you would like to rewrite the tutorial that is fine. I am kind of busy. I would really appreciate it tough. <was not sarcastic in case it looked that way> |
Author: | Tony [ Fri Apr 10, 2009 1:00 am ] |
Post subject: | Re: Config File |
Why not binary? |
Author: | Labmonkey [ Fri Apr 10, 2009 3:03 am ] |
Post subject: | Re: Config File |
viewtopic.php?p=65655#p65655 |
Author: | Tony [ Fri Apr 10, 2009 3:06 am ] |
Post subject: | Re: Config File |
Oh, I see. Excuse me lol I tend to just skip to the bottom of pages. |
Author: | wanai [ Mon Jan 03, 2022 6:14 am ] |
Post subject: | Re: Config File |
Econ |
Author: | wanai [ Mon Jan 03, 2022 6:15 am ] |
Post subject: | Re: Config File |
84 |
Author: | wanai [ Mon Jan 03, 2022 6:17 am ] |
Post subject: | Re: Config File |
Bett |
Page 1 of 56 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |