Hyunsu_Oh Posted March 26, 2010 Share Posted March 26, 2010 sorry, my bad english. It read xml, also after again reading, the value changed. Original value is "123456" It changed value is "123456 " what is " ""? I did not add !! please help me!! Link to comment
50p Posted March 26, 2010 Share Posted March 26, 2010 sorry, my bad english.It read xml, also after again reading, the value changed. Original value is "123456" It changed value is "123456 " what is " ""? I did not add !! please help me!! Show us your code. I've never had problem with xml files. Link to comment
Hyunsu_Oh Posted March 27, 2010 Author Share Posted March 27, 2010 GRoot = getRootElement() GRRoot = getResourceRootElement() UserFolderName = "UserFolder" function OnModeStart(startedmode) SecondTimerAddress = setTimer(SecondTimer, 1000, false) end function OnPlayerJoin() ResetPlayerValue(source) fadeCamera(source, true) SpawnPlayer(source) setCameraTarget(source, source) ClearChatBox(source) end function OnPlayerTarget(targetelement) end function OnPlayerSpawn() setElementPosition ( source, 100, 100, 20) end function OnPlayerWasted(ammo, killerelement, weapon, bodypart) setTimer(SpawnPlayer, 5000, 1, source) end function OnPlayerDamage(attackerelement, weapon, bodypart, damage) end function OnPlayerChat(message, messageType) cancelEvent() outputChatBox("[Player] ".. getPlayerName(source) .. " : " .. message) end addEventHandler("onResourceStart", GRRoot, OnModeStart) addEventHandler("onPlayerTarget", GRoot, OnPlayerTarget) addEventHandler("onPlayerJoin", GRoot, OnPlayerJoin) addEventHandler("onPlayerSpawn", GRoot, OnPlayerSpawn) addEventHandler("onPlayerWasted", GRoot, OnPlayerWasted) addEventHandler("onPlayerDamage", GRoot, OnPlayerDamage) addEventHandler("onPlayerChat", GRoot, OnPlayerChat) function consoleCheckParameters ( playerSource, commandName, ... ) local parametersTable = {...} local parameterCount = #parametersTable outputChatBox ( "Number of parameters: " .. parameterCount, playerSource ) local stringWithAllParameters = table.concat( parametersTable, ", " ) outputChatBox ( "Parameters passed: " .. stringWithAllParameters, playerSource ) end function RegisterPlayer(playerSource, commandName, id, password) if GetPlayerValue(playerSource, "Registered") then outputChatBox ("이미 가입 하셨습니다. 로그인 해주세요.", playerSource ) return end local UFN = GetUserFileName(id) if IsXmlCreated(UFN) then outputChatBox ("이미 이 아이디는 생성 되있습니다.", playerSource ) else local thenode = xmlCreateFile (UFN, "UserData") if thenode then xmlNodeSetValue (thenode, password) xmlCreateChild (thenode, "Info") xmlSaveFile(thenode) xmlUnloadFile(thenode) outputChatBox ("성공적으로 아이디가 생성되었습니다.", playerSource ) SetPlayerValue(playerSource, "Registered", true) setTimer(SavePlayer, 3000, 1, playerSource, id) else outputChatBox ("계정생성중 오류가 발생하였습니다.", playerSource ) outputChatBox ("[아이디는 영어로 해주세요]", playerSource ) end end end function LoginPlayer(playerSource, commandName, id, password) local UFN = GetUserFileName(id) local thenode = xmlLoadFile(UFN) if thenode then if xmlNodeGetValue(thenode) == password then local thenode_info = xmlFindChild (thenode, "Info", 0) SetPlayerValue(playerSource, "Password", xmlNodeGetValue(thenode)) SetPlayerValue(playerSource, "Age", xmlNodeGetAttribute (thenode_info, "Age")) outputChatBox ("성공적으로 로그인 되었습니다.", playerSource) else outputChatBox ("비밀번호가 틀립니다.", playerSource) print(xmlNodeGetValue(thenode)..password) end xmlUnloadFile(thenode) else outputChatBox ("존재하지 않는 아이디입니다.", playerSource) end end addCommandHandler ( "Check", consoleCheckParameters) addCommandHandler ( "register", RegisterPlayer) addCommandHandler ( "login", LoginPlayer) function SpawnPlayer(playerelement) spawnPlayer(playerelement, 0.0, 0.0, 0.0, 0.0, 0) end function GiveElementHealth(theelement, health) setElementHealth(theelement, getElementHealth(theelement) + health) end function GetConnectedPlayers() local playerstable = getElementsByType("player") return table.getn(playerstable) end function SecondTimer() local playerstable = getElementsByType("player") for tablepos, tableelement in ipairs(playerstable) do local x, y, z = getElementPosition(tableelement) --triggerClientEvent (tableelement, "onExplosionBlood", tableelement, x, y, z) end end function ClearChatBox(playerelement) for i = 0, 15 do outputChatBox(" ", playerelement) end end function GetUserFileName(id) return string.format("%s/%s.xml", UserFolderName, id) end function IsXmlCreated(xmlname) if not xmlLoadFile(xmlname) then return false end xmlUnloadFile(xmlname) return true end function MakeXmlFile(xmlname, subject) local thenode = xmlCreateFile (xmlname, subject) if thenode then xmlSaveFile(thenode) end end function GetPlayerValue(playerelement, valuename) return getElementData (playerelement, valuename) end function SetPlayerValue(playerelement, valuename, value) return setElementData (playerelement, valuename, value) end function ResetPlayerValue(playerelement) SetPlayerValue(playerelement, "Registered", false) SetPlayerValue(playerelement, "Age", 0) end function SavePlayer(playerelement, id) local pnode = xmlLoadFile(GetUserFileName(id)) local thenode_info = xmlFindChild (pnode, "Info", 0) xmlNodeSetAttribute (thenode_info, "Age", GetPlayerValue(playerelement, "Age")) xmlSaveFile(pnode) xmlUnloadFile(pnode) end This is my serverside. help me. Link to comment
Hyunsu_Oh Posted March 27, 2010 Author Share Posted March 27, 2010 "xmlLoadFile" should to do only once in one file? Link to comment
Xierra Posted March 27, 2010 Share Posted March 27, 2010 Based on this part (line 65 until end of the function): function RegisterPlayer(playerSource, commandName, id, password) if GetPlayerValue(playerSource, "Registered") then outputChatBox ("이미 가입 하셨습니다. 로그인 해주세요.", playerSource ) return end local UFN = GetUserFileName(id) if IsXmlCreated(UFN) then outputChatBox ("이미 이 아이디는 생성 되있습니다.", playerSource ) else local thenode = xmlCreateFile (UFN, "UserData") if thenode then xmlNodeSetValue (thenode, password) xmlCreateChild (thenode, "Info") xmlSaveFile(thenode) xmlUnloadFile(thenode) outputChatBox ("성공적으로 아이디가 생성되었습니다.", playerSource ) SetPlayerValue(playerSource, "Registered", true) setTimer(SavePlayer, 3000, 1, playerSource, id) else outputChatBox ("계정생성중 오류가 발생하였습니다.", playerSource ) outputChatBox ("[아이디는 영어로 해주세요]", playerSource ) end end end function LoginPlayer(playerSource, commandName, id, password) local UFN = GetUserFileName(id) local thenode = xmlLoadFile(UFN) if thenode then if xmlNodeGetValue(thenode) == password then local thenode_info = xmlFindChild (thenode, "Info", 0) SetPlayerValue(playerSource, "Password", xmlNodeGetValue(thenode)) SetPlayerValue(playerSource, "Age", xmlNodeGetAttribute (thenode_info, "Age")) outputChatBox ("성공적으로 로그인 되었습니다.", playerSource) else outputChatBox ("비밀번호가 틀립니다.", playerSource) print(xmlNodeGetValue(thenode)..password) end xmlUnloadFile(thenode) else outputChatBox ("존재하지 않는 아이디입니다.", playerSource) end end addCommandHandler ( "Check", consoleCheckParameters) addCommandHandler ( "register", RegisterPlayer) addCommandHandler ( "login", LoginPlayer) I'll give you a little translation of the outputChatBox writings. They're korean language. (Used a Google Translate) First output: You have already signed up. Please login. Second Output: Nick has already generated a doeitseupnida. (huh? generated what?) Third Output: Nick has been generated successfully. Fourth Output: St seongjung error has occurred account (maybe: "An account error has occured") Fifth Output: [sign Nick in English] (maybe: "Sign up/in your nick in English Language") Sixth Output: You have successfully logged in. Seventh Output: The password is incorrect. Ninth Output: Nick is a non-existent (maybe: "The nick doesn't exist") Means it should be like this: GRoot = getRootElement() GRRoot = getResourceRootElement() UserFolderName = "UserFolder" function OnModeStart(startedmode) SecondTimerAddress = setTimer(SecondTimer, 1000, false) end function OnPlayerJoin() ResetPlayerValue(source) fadeCamera(source, true) SpawnPlayer(source) setCameraTarget(source, source) ClearChatBox(source) end function OnPlayerTarget(targetelement) end function OnPlayerSpawn() setElementPosition ( source, 100, 100, 20) end function OnPlayerWasted(ammo, killerelement, weapon, bodypart) setTimer(SpawnPlayer, 5000, 1, source) end function OnPlayerDamage(attackerelement, weapon, bodypart, damage) end function OnPlayerChat(message, messageType) cancelEvent() outputChatBox("[Player] ".. getPlayerName(source) .. " : " .. message) end addEventHandler("onResourceStart", GRRoot, OnModeStart) addEventHandler("onPlayerTarget", GRoot, OnPlayerTarget) addEventHandler("onPlayerJoin", GRoot, OnPlayerJoin) addEventHandler("onPlayerSpawn", GRoot, OnPlayerSpawn) addEventHandler("onPlayerWasted", GRoot, OnPlayerWasted) addEventHandler("onPlayerDamage", GRoot, OnPlayerDamage) addEventHandler("onPlayerChat", GRoot, OnPlayerChat) function consoleCheckParameters ( playerSource, commandName, ... ) local parametersTable = {...} local parameterCount = #parametersTable outputChatBox ( "Number of parameters: " .. parameterCount, playerSource ) local stringWithAllParameters = table.concat( parametersTable, ", " ) outputChatBox ( "Parameters passed: " .. stringWithAllParameters, playerSource ) end function RegisterPlayer(playerSource, commandName, id, password) if GetPlayerValue(playerSource, "Registered") then outputChatBox ("You have already signed up. Please login.", playerSource ) return end local UFN = GetUserFileName(id) if IsXmlCreated(UFN) then outputChatBox ("Nick has already generated a doeitseupnida.", playerSource ) else local thenode = xmlCreateFile (UFN, "UserData") if thenode then xmlNodeSetValue (thenode, password) xmlCreateChild (thenode, "Info") xmlSaveFile(thenode) xmlUnloadFile(thenode) outputChatBox ("Nick has been generated successfully.", playerSource ) SetPlayerValue(playerSource, "Registered", true) setTimer(SavePlayer, 3000, 1, playerSource, id) else outputChatBox ("An account error has occured", playerSource ) outputChatBox ("[sign up your nick in English]", playerSource ) end end end function LoginPlayer(playerSource, commandName, id, password) local UFN = GetUserFileName(id) local thenode = xmlLoadFile(UFN) if thenode then if xmlNodeGetValue(thenode) == password then local thenode_info = xmlFindChild (thenode, "Info", 0) SetPlayerValue(playerSource, "Password", xmlNodeGetValue(thenode)) SetPlayerValue(playerSource, "Age", xmlNodeGetAttribute (thenode_info, "Age")) outputChatBox ("You have successfully logged in.", playerSource) else outputChatBox ("The password is incorrect.", playerSource) print(xmlNodeGetValue(thenode)..password) end xmlUnloadFile(thenode) else outputChatBox ("The nick doesn't exist.", playerSource) end end addCommandHandler ( "Check", consoleCheckParameters) addCommandHandler ( "register", RegisterPlayer) addCommandHandler ( "login", LoginPlayer) function SpawnPlayer(playerelement) spawnPlayer(playerelement, 0.0, 0.0, 0.0, 0.0, 0) end function GiveElementHealth(theelement, health) setElementHealth(theelement, getElementHealth(theelement) + health) end function GetConnectedPlayers() local playerstable = getElementsByType("player") return table.getn(playerstable) end function SecondTimer() local playerstable = getElementsByType("player") for tablepos, tableelement in ipairs(playerstable) do local x, y, z = getElementPosition(tableelement) --triggerClientEvent (tableelement, "onExplosionBlood", tableelement, x, y, z) end end function ClearChatBox(playerelement) for i = 0, 15 do outputChatBox(" ", playerelement) end end function GetUserFileName(id) return string.format("%s/%s.xml", UserFolderName, id) end function IsXmlCreated(xmlname) if not xmlLoadFile(xmlname) then return false end xmlUnloadFile(xmlname) return true end function MakeXmlFile(xmlname, subject) local thenode = xmlCreateFile (xmlname, subject) if thenode then xmlSaveFile(thenode) end end function GetPlayerValue(playerelement, valuename) return getElementData (playerelement, valuename) end function SetPlayerValue(playerelement, valuename, value) return setElementData (playerelement, valuename, value) end function ResetPlayerValue(playerelement) SetPlayerValue(playerelement, "Registered", false) SetPlayerValue(playerelement, "Age", 0) end function SavePlayer(playerelement, id) local pnode = xmlLoadFile(GetUserFileName(id)) local thenode_info = xmlFindChild (pnode, "Info", 0) xmlNodeSetAttribute (thenode_info, "Age", GetPlayerValue(playerelement, "Age")) xmlSaveFile(pnode) xmlUnloadFile(pnode) end Great, I think I have helped a bit? Link to comment
Gamesnert Posted March 27, 2010 Share Posted March 27, 2010 local thenode = xmlCreateFile (UFN, "UserData") if thenode then xmlNodeSetValue (thenode, password) xmlCreateChild (thenode, "Info") xmlSaveFile(thenode) xmlUnloadFile(thenode) I think here's your problem, it would look something like: <UserData>password <Info/> </UserData> (The forum actually fucks up the code if I set it into XML syntax, which can't be a good sign) Which doesn't seem to be valid XML syntax at all. A solution could be: local thenode = xmlCreateFile (UFN, "UserData") if thenode then local infoNode = xmlCreateChild (thenode, "Info") local passwordNode = xmlCreateChild (infoNode, "Password") xmlNodeSetValue (passwordNode, password) xmlSaveFile(thenode) xmlUnloadFile(thenode) ... This should look like: <UserData> <Info> <Password>password</Password> </Info> </UserData> Which should be valid XML syntax. I think that should solve your XML problem. (If I didn't make some stupid mistake, that is) Link to comment
Hyunsu_Oh Posted March 27, 2010 Author Share Posted March 27, 2010 Thank you. Really. 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