Jump to content

Making a game.


rawrr
 Share

Recommended Posts

Hello Autoit'ers!

I'm in the middle of making a game and I need the players to login with an account but how would I make it so when the login button is pressed it makes sure the password and username match, and if it does then open up a different GUI?

Thanks in advance.

Link to comment
Share on other sites

#cs ==================== Function Login =============
    Original by Jex, improved by Linux
    Working!
    Check the current page, and login if needed.
#ce

$config = "Login.ini"
Global $Link = IniRead($config, "UserData", "Site", "_")
Global $User = IniRead($config, "UserData", "Login", "_")
Global $Pass = IniRead($config, "UserData", "Pass", "_")


Login($User,$Pass)


Func Login($Username, $Password)
    $Source = _IEDocReadHTML($oIE) ; read the source of the page
    If (StringInStr($Source, $CLang[5]) Or StringInStr($Source, $CLang[6])) Then ; If page is "Thank you for your visit", or "Please Login" 
        Consolewrite(", LOGIN")
        $oForm = _IEFormGetCollection($oIE, 0)
        If @error Then
            consolewrite("Table Error!!! ")
            Return
        EndIf
        $oQuery = _IEFormElementGetCollection($oForm, 2)
         _IEFormElementSetValue($oQuery, $Username)
        $oQuery = _IEFormElementGetCollection($oForm, 3) 
        _IEFormElementSetValue($oQuery, $Password)
        _IEFormSubmit($oForm)
        $Source = _IEDocReadHTML($oIE)
        Local $Link, $linkURL, $alllinks[1], $links = $oIE.document.links
    EndIf
    If Not StringInStr($Source, "login success") Then ;If not contains wellcome string
Msgbox(-1,"","login Error")
exit
    EndIf
EndFunc   ;==>Login

Every time you need to navigate to a page, you need to check you if are not logged out.

To get the proper element name, for the field of user and password, get some web development tools plugins for firefox. they will show the names.

Hope it helps

Login.ini example:

[UserData]
Site=http://server.game.com/
Login=Yournick
Pass=yourpass
Edited by Linux
You can help! Donate to AutoIt! or, visit ClimatePREDICTION.netMy posts:Travian Bot Example (100+ servers) BETAHow to Host you code/app for free! (unlimited team number) (Public or Private)"Sir, we're surrounded!" "Excellent. We can attack in any direction!"
Link to comment
Share on other sites

Thanks but this game isn't made with IE.. Its GUI.. So that won't work. Thanks though. Btw theres an error..

$oForm = _IEFormGetCollection($oIE, 0)oÝ÷ Ù«­¢+ØÀÌØí½%

Is used without being declared.

"]

Link to comment
Share on other sites

Ok So heres an example text file

Username|Password
John_Smith|pass
Monkey|Foo
SuperMooMooImaCowMan|MOOOOOO6

#include <GuiConstants.au3>
#include <EditConstants.au3>
#Include <File.au3>

Opt('GuiOnEventMode',1)

$LoginGUI=GuiCreate("Login", 300, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
$UserName = GUICtrlCreateInput("Username", 30, 30, 240, 20)
$Password = GUICtrlCreateInput("Password", 30, 60, 240, 20,$ES_PASSWORD)
$Submit = GUICtrlCreateButton("Submit", 75, 130, 150, 30)
GUICtrlSetOnEvent(-1, "Validate")
GUISetState(@SW_SHOWNORMAL)

While 1
    Sleep(100)
WEnd

Func Quit()
    Exit
EndFunc

Func Validate()
    Local $FilePath = @ScriptDir&"\Users.txt", $Array ,$UN = GUICtrlRead($UserName), $PW = GUICtrlRead($Password), $Match =0
    _FileReadToArray($FilePath, $Array)
    If @error then
        Msgbox(0,"Error","Error! The file: "&@CRLF&$FilePath&@CRLF&" is missing or corrupt. Please re-create or modify the file.")
        Return 0
    EndIf
    For $i = 1 to $Array[0]
        $Parts = StringSplit($Array[$i], "|")
        If $UN = $Parts[1] Then
            $Match = 1
            If $PW == $Parts[2] then ;Password is correct
                GameFuncHere($UN)
            Else ;password is incorrect
                MsgBox(0,"Invalid", "Sorry, Invalid Password. Remember, Passwords are case-sensitive.")
                Return 0
            EndIf
        EndIf
    Next
    If Not $Match then ;username not on list
        MsgBox(0,"Invalid", "Sorry, That Username is invalid.")
    EndIf
EndFunc

Func GameFuncHere($Username)
    GUIDelete($LoginGUI)
    Msgbox(0,"Valid", "Thank you! You are now logged in as: "&$Username)
    ;Play game here
    Exit
EndFunc
Edited by Paulie
Link to comment
Share on other sites

Oie is the IE object.

Have you look for an example on the forum? you have great ones in the EXAMPLES corner

You can help! Donate to AutoIt! or, visit ClimatePREDICTION.netMy posts:Travian Bot Example (100+ servers) BETAHow to Host you code/app for free! (unlimited team number) (Public or Private)"Sir, we're surrounded!" "Excellent. We can attack in any direction!"
Link to comment
Share on other sites

I personally would use tcp to connect to the server and when the button is pressed send the username and password to the server have it check and send back error or success.

[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Link to comment
Share on other sites

@Paulie.

Thanks man. Only one problem.. Says,

"For $i = 1 to $Array[0]"

"For $i = 1 to $Array^ ERROR"

Help please.

"]

That probably means it couldn't open the text file to read it.

I edited the above post to notify of that error.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...