jkub Posted September 23, 2011 Share Posted September 23, 2011 I have been hard at work on making a centralized "entrance system" for my new 1.1 server. The most important parts seem to work so far and I am trying to implement a remember password/username feature. I figured comparing a player's serial would be the best way to check users who haven't logged in. I am clueless when it comes to SQL so instead I am writing my script so it saves all the account names and serials inside an xml file. I have it set up to where if no accounts (child nodes) were found in the file it creates a new one and sets the data for the user's serial and shit from there. If there are already accounts in the file it will compare the serial from each account node to the current clients serial, if he has a match in the database his corresponding account node is updated with current information (ip, serial username etc). If he does not have a match in the database but there are already other accounts in the database a new account node is added for him. This formula works for the first account that is saved into the database. Everytime I reconnect with the same account it works perfect and the nodes don't keep being created because a node was found with his information. But lets say I add another account into the database, this is when it tells me that his account is not found in the information (when in infact it is in there because I look manually everytime for myself). So since it "thinks" the account node for that player is not there it ends up creating a duplicate node for that player. I have tried many things and I am stuck. Please help me this has me stumped. Here is some code for the matter. This section of code is a function that is triggered every time a player logs into his account with my entrance system resource. function client_login ( usrNm, pass, rememberUsr, rememberPass ) if getAccount ( usrNm ) == false then outputChatBox ( "*An account with this username was not found", client, 255, 0, 0 ) else if getAccount ( usrNm, pass ) == false then outputChatBox ( "*You specified an incorrect password for this account", client, 255, 0, 0 ) else if logIn ( client, getAccount ( usrNm, pass ), pass ) == true then isGangMember = getAccountData ( getAccount ( usrNm, pass ), "gangMember" ) hasProperty = getAccountData ( getPlayerAccount ( client ), "hasProperty" ) isAdmin = getAccountData ( getPlayerAccount ( client ), "isAdmin" ) if isGangMember == "true" then setPlayerTeam ( client, getTeamFromName ( getAccountData ( getPlayerAccount ( client ), "gangName" ) ) ) elseif isGangMember == "false" or isGangMember == nil then if hasObjectPermissionTo ( client, "function.banPlayer" ) == true then setPlayerTeam ( client, getTeamFromName ( "Admins" ) ) else setPlayerTeam ( client, getTeamFromName ( "Registered Users" ) ) end end triggerClientEvent ( client, "playerLoggedIn", client, isGangMember, hasProperty, isAdmin ) -------- playerSerial = getPlayerSerial ( client ) playerIP = getPlayerIP ( client ) actName = getAccountName ( getPlayerAccount ( client ) ) actDatabase = xmlLoadFile ( "data/server/account database.xml" ) accountNodes = xmlNodeGetChildren ( actDatabase ) if table.getn ( accountNodes ) == 0 then firstActNode = xmlCreateChild ( actDatabase, "user" ) xmlNodeSetAttribute ( firstActNode, "actName", ""..actName.."" ) xmlNodeSetAttribute ( firstActNode, "actPass", ""..pass.."" ) xmlNodeSetAttribute ( firstActNode, "curActSerial", ""..playerSerial.."" ) xmlNodeSetAttribute ( firstActNode, "curActIP", ""..playerIP.."" ) xmlNodeSetAttribute ( firstActNode, "rememberUsername", tostring(rememberUsr) ) xmlNodeSetAttribute ( firstActNode, "rememberPassword", tostring(rememberPass) ) outputChatBox ( "No accounts found in database, adding first entry" ) end outputChatBox ( table.getn ( accountNodes ) ) for i, actNode in pairs ( accountNodes ) do if xmlNodeGetName ( actNode ) == "user" then if actName == xmlNodeGetAttribute ( actNode, "actName" ) then --only update the node instead of adding one xmlNodeSetAttribute ( actNode, "actName", ""..actName.."" ) xmlNodeSetAttribute ( actNode, "actPass", ""..pass.."" ) xmlNodeSetAttribute ( actNode, "curActSerial", ""..playerSerial.."" ) xmlNodeSetAttribute ( actNode, "curActIP", ""..playerIP.."" ) xmlNodeSetAttribute ( actNode, "rememberUsername", tostring(rememberUsr) ) xmlNodeSetAttribute ( actNode, "rememberPassword", tostring(rememberPass) ) outputChatBox ( "Your account was found in the database and is being updated" ) break else --add a whole new node for this account newAccountNode = xmlCreateChild ( actDatabase, "user" ) xmlNodeSetAttribute ( newAccountNode, "actName", ""..actName.."" ) xmlNodeSetAttribute ( newAccountNode, "actPass", ""..pass.."" ) xmlNodeSetAttribute ( newAccountNode, "curActSerial", ""..playerSerial.."" ) xmlNodeSetAttribute ( newAccountNode, "curActIP", ""..playerIP.."" ) xmlNodeSetAttribute ( newAccountNode, "rememberUsername", tostring(rememberUsr) ) xmlNodeSetAttribute ( newAccountNode, "rememberPassword", tostring(rememberPass) ) outputChatBox ( "There are accounts in the database but yours was not found. Adding it now" ) break end end end xmlSaveFile ( actDatabase ) end end end end Link to comment
SDK Posted September 23, 2011 Share Posted September 23, 2011 Your for loop stopped after it found a user node, but it should stop if it finds the correct user node instead. How 'bout this: function client_login ( usrNm, pass, rememberUsr, rememberPass ) if getAccount ( usrNm ) == false then outputChatBox ( "*An account with this username was not found", client, 255, 0, 0 ) elseif getAccount ( usrNm, pass ) == false then outputChatBox ( "*You specified an incorrect password for this account", client, 255, 0, 0 ) elseif logIn ( client, getAccount ( usrNm, pass ), pass ) == true then isGangMember = getAccountData ( getAccount ( usrNm, pass ), "gangMember" ) hasProperty = getAccountData ( getPlayerAccount ( client ), "hasProperty" ) isAdmin = getAccountData ( getPlayerAccount ( client ), "isAdmin" ) if isGangMember == "true" then setPlayerTeam ( client, getTeamFromName ( getAccountData ( getPlayerAccount ( client ), "gangName" ) ) ) elseif isGangMember == "false" or isGangMember == nil then if hasObjectPermissionTo ( client, "function.banPlayer" ) == true then setPlayerTeam ( client, getTeamFromName ( "Admins" ) ) else setPlayerTeam ( client, getTeamFromName ( "Registered Users" ) ) end end triggerClientEvent ( client, "playerLoggedIn", client, isGangMember, hasProperty, isAdmin ) -------- playerSerial = getPlayerSerial ( client ) playerIP = getPlayerIP ( client ) actName = getAccountName ( getPlayerAccount ( client ) ) actDatabase = xmlLoadFile ( "data/server/account database.xml" ) accountNodes = xmlNodeGetChildren ( actDatabase ) if table.getn ( accountNodes ) == 0 then firstActNode = xmlCreateChild ( actDatabase, "user" ) xmlNodeSetAttribute ( firstActNode, "actName", ""..actName.."" ) xmlNodeSetAttribute ( firstActNode, "actPass", ""..pass.."" ) xmlNodeSetAttribute ( firstActNode, "curActSerial", ""..playerSerial.."" ) xmlNodeSetAttribute ( firstActNode, "curActIP", ""..playerIP.."" ) xmlNodeSetAttribute ( firstActNode, "rememberUsername", tostring(rememberUsr) ) xmlNodeSetAttribute ( firstActNode, "rememberPassword", tostring(rememberPass) ) outputChatBox ( "No accounts found in database, adding first entry" ) end outputChatBox ( table.getn ( accountNodes ) ) for i, actNode in pairs ( accountNodes ) do if xmlNodeGetName ( actNode ) == "user" and actName == xmlNodeGetAttribute ( actNode, "actName" ) then --only update the node instead of adding one xmlNodeSetAttribute ( actNode, "actName", ""..actName.."" ) xmlNodeSetAttribute ( actNode, "actPass", ""..pass.."" ) xmlNodeSetAttribute ( actNode, "curActSerial", ""..playerSerial.."" ) xmlNodeSetAttribute ( actNode, "curActIP", ""..playerIP.."" ) xmlNodeSetAttribute ( actNode, "rememberUsername", tostring(rememberUsr) ) xmlNodeSetAttribute ( actNode, "rememberPassword", tostring(rememberPass) ) outputChatBox ( "Your account was found in the database and is being updated" ) xmlSaveFile ( actDatabase ) return end end --add a whole new node for this account newAccountNode = xmlCreateChild ( actDatabase, "user" ) xmlNodeSetAttribute ( newAccountNode, "actName", ""..actName.."" ) xmlNodeSetAttribute ( newAccountNode, "actPass", ""..pass.."" ) xmlNodeSetAttribute ( newAccountNode, "curActSerial", ""..playerSerial.."" ) xmlNodeSetAttribute ( newAccountNode, "curActIP", ""..playerIP.."" ) xmlNodeSetAttribute ( newAccountNode, "rememberUsername", tostring(rememberUsr) ) xmlNodeSetAttribute ( newAccountNode, "rememberPassword", tostring(rememberPass) ) outputChatBox ( "There are accounts in the database but yours was not found. Adding it now" ) xmlSaveFile ( actDatabase ) end end Link to comment
jkub Posted September 23, 2011 Author Share Posted September 23, 2011 Thanks I added that in and it works great. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now