Mirage Source

Free ORPG making software.
It is currently Fri Mar 29, 2024 2:59 pm

All times are UTC


Forum rules


Make sure your tutorials are kept up to date with the latest MS4 releases.



Post new topic Reply to topic  [ 1379 posts ]  Go to page 1, 2, 3, 4, 5 ... 56  Next
Author Message
 Post subject: Config File
PostPosted: Tue Apr 07, 2009 4:39 pm 
Offline
Pro
User avatar

Joined: Sun Aug 05, 2007 2:26 pm
Posts: 547
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

_________________
GIAKEN wrote:
I think what I see is this happening:

Labmonkey gets mod, everybody loves him, people find out his code sucks, he gets demoted, then banned, then he makes an engine called Chaos Engine.


Last edited by Labmonkey on Thu Apr 09, 2009 6:30 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Tue Apr 07, 2009 5:53 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
People shouldn't be able to change the IP.

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Tue Apr 07, 2009 6:20 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
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

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

Image


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Tue Apr 07, 2009 6:21 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
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.

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Tue Apr 07, 2009 6:27 pm 
Offline
Newbie

Joined: Sun Apr 05, 2009 10:29 am
Posts: 20
It may be cuter to encrypt p/w's before storing them in a .txt file.


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Tue Apr 07, 2009 6:37 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
And then you'd have to make like a /setip command or something. Server side access checks and what not.

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

Image


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Tue Apr 07, 2009 6:42 pm 
Offline
Pro
User avatar

Joined: Sun Aug 05, 2007 2:26 pm
Posts: 547
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 :D.


@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 :shock: .

_________________
GIAKEN wrote:
I think what I see is this happening:

Labmonkey gets mod, everybody loves him, people find out his code sucks, he gets demoted, then banned, then he makes an engine called Chaos Engine.


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Tue Apr 07, 2009 7:07 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
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 :shock: .


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?

:D

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

Image


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Tue Apr 07, 2009 7:09 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
How does the client save the IP? The user can just change it...

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Tue Apr 07, 2009 11:01 pm 
Offline
Pro
User avatar

Joined: Sun Aug 05, 2007 2:26 pm
Posts: 547
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.

_________________
GIAKEN wrote:
I think what I see is this happening:

Labmonkey gets mod, everybody loves him, people find out his code sucks, he gets demoted, then banned, then he makes an engine called Chaos Engine.


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Wed Apr 08, 2009 6:32 pm 
Offline
Pro

Joined: Mon May 29, 2006 5:01 pm
Posts: 420
Location: Canada, BC
Google Talk: anthony.fleck@gmail.com
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?


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Thu Apr 09, 2009 6:17 pm 
Offline
Pro
User avatar

Joined: Sun Aug 05, 2007 2:26 pm
Posts: 547
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 ;).

_________________
GIAKEN wrote:
I think what I see is this happening:

Labmonkey gets mod, everybody loves him, people find out his code sucks, he gets demoted, then banned, then he makes an engine called Chaos Engine.


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Thu Apr 09, 2009 6:22 pm 
Offline
Pro

Joined: Mon May 29, 2006 5:01 pm
Posts: 420
Location: Canada, BC
Google Talk: anthony.fleck@gmail.com
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.


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Thu Apr 09, 2009 6:27 pm 
Offline
Pro
User avatar

Joined: Sun Aug 05, 2007 2:26 pm
Posts: 547
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 :D.


EDIT: Just realized you did. I will make a link at the top to your post.

_________________
GIAKEN wrote:
I think what I see is this happening:

Labmonkey gets mod, everybody loves him, people find out his code sucks, he gets demoted, then banned, then he makes an engine called Chaos Engine.


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Thu Apr 09, 2009 7:07 pm 
Offline
Pro

Joined: Mon May 29, 2006 5:01 pm
Posts: 420
Location: Canada, BC
Google Talk: anthony.fleck@gmail.com
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.


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Thu Apr 09, 2009 7:19 pm 
Offline
Pro
User avatar

Joined: Sun Aug 05, 2007 2:26 pm
Posts: 547
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?

_________________
GIAKEN wrote:
I think what I see is this happening:

Labmonkey gets mod, everybody loves him, people find out his code sucks, he gets demoted, then banned, then he makes an engine called Chaos Engine.


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Thu Apr 09, 2009 7:20 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
Just use GetVar and PutVar.

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Thu Apr 09, 2009 7:21 pm 
Offline
Pro
User avatar

Joined: Sun Aug 05, 2007 2:26 pm
Posts: 547
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>

_________________
GIAKEN wrote:
I think what I see is this happening:

Labmonkey gets mod, everybody loves him, people find out his code sucks, he gets demoted, then banned, then he makes an engine called Chaos Engine.


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Fri Apr 10, 2009 1:00 am 
Offline
Persistant Poster
User avatar

Joined: Wed Nov 29, 2006 11:25 pm
Posts: 860
Location: Ayer
Why not binary?

_________________
Image


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Fri Apr 10, 2009 3:03 am 
Offline
Pro
User avatar

Joined: Sun Aug 05, 2007 2:26 pm
Posts: 547
viewtopic.php?p=65655#p65655

_________________
GIAKEN wrote:
I think what I see is this happening:

Labmonkey gets mod, everybody loves him, people find out his code sucks, he gets demoted, then banned, then he makes an engine called Chaos Engine.


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Fri Apr 10, 2009 3:06 am 
Offline
Persistant Poster
User avatar

Joined: Wed Nov 29, 2006 11:25 pm
Posts: 860
Location: Ayer
Oh, I see.

Excuse me lol I tend to just skip to the bottom of pages.

_________________
Image


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Wed Dec 01, 2021 8:43 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
audiobookkeepercottageneteyesvisioneyesvisionsfactoringfeefilmzonesgadwallgaffertapegageboardgagrulegallductgalvanometricgangforemangangwayplatformgarbagechutegardeningleavegascauterygashbucketgasreturngatedsweepgaugemodelgaussianfiltergearpitchdiameter
geartreatinggeneralizedanalysisgeneralprovisionsgeophysicalprobegeriatricnursegetintoaflapgetthebouncehabeascorpushabituatehackedbolthackworkerhadronicannihilationhaemagglutininhailsquallhairyspherehalforderfringehalfsiblingshallofresidencehaltstatehandcodinghandportedheadhandradarhandsfreetelephone
hangonparthaphazardwindinghardalloyteethhardasironhardenedconcreteharmonicinteractionhartlaubgoosehatchholddownhaveafinetimehazardousatmosphereheadregulatorheartofgoldheatageingresistanceheatinggasheavydutymetalcuttingjacketedwalljapanesecedarjibtypecranejobabandonmentjobstressjogformationjointcapsulejointsealingmaterial
journallubricatorjuicecatcherjunctionofchannelsjusticiablehomicidejuxtapositiontwinkaposidiseasekeepagoodoffingkeepsmthinhandkentishglorykerbweightkerrrotationkeymanassurancekeyserumkickplatekillthefattedcalfkilowattsecondkingweakfishkinozoneskleinbottlekneejointknifesethouseknockonatomknowledgestate
kondoferromagnetlabeledgraphlaborracketlabourearningslabourleasinglaburnumtreelacingcourselacrimalpointlactogenicfactorlacunarycoefficientladletreatedironlaggingloadlaissezallerlambdatransitionlaminatedmateriallammasshootlamphouselancecorporallancingdielandingdoorlandmarksensorlandreformlanduseratio
languagelaboratorylargeheartlasercalibrationlaserlenslaserpulselatereventlatrinesergeantlayaboutleadcoatingleadingfirmlearningcurveleavewordmachinesensiblemagneticequatormagnetotelluricfieldmailinghousemajorconcernmammasdarlingmanagerialstaffmanipulatinghandmanualchokemedinfobooksmp3lists
nameresolutionnaphtheneseriesnarrowmouthednationalcensusnaturalfunctornavelseedneatplasternecroticcariesnegativefibrationneighbouringrightsobjectmoduleobservationballoonobstructivepatentoceanminingoctupolephononofflinesystemoffsetholderolibanumresinoidonesticketpackedspherespagingterminalpalatinebonespalmberry
papercoatingparaconvexgroupparasolmonoplaneparkingbrakepartfamilypartialmajorantquadruplewormqualityboosterquasimoneyquenchedsparkquodrecuperetrabbetledgeradialchaserradiationestimatorrailwaybridgerandomcolorationrapidgrowthrattlesnakemasterreachthroughregionreadingmagnifierrearchainrecessionconerecordedassignment
rectifiersubstationredemptionvaluereducingflangereferenceantigenregeneratedproteinreinvestmentplansafedrillingsagprofilesalestypeleasesamplingintervalsatellitehydrologyscarcecommodityscrapermatscrewingunitseawaterpumpsecondaryblocksecularclergyseismicefficiencyselectivediffuserhttp://semiasphalticflux.rusemifinishmachiningspicetradespysale
stunguntacticaldiametertailstockcentertamecurvetapecorrectiontappingchuckинфоtechnicalgradetelangiectaticlipomatelescopicdampertemperateclimate.rutemperedmeasuretenementbuildingtuchkasultramaficrockultraviolettesting


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Mon Jan 03, 2022 6:14 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Econ


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Mon Jan 03, 2022 6:15 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
84


Top
 Profile  
 
 Post subject: Re: Config File
PostPosted: Mon Jan 03, 2022 6:17 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 456192
Bett


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1379 posts ]  Go to page 1, 2, 3, 4, 5 ... 56  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 12 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:  
cron
Powered by phpBB® Forum Software © phpBB Group