02.05.2014, 00:33
Ok, so the script compiles, but when I login, after I type in the password I wanna use, it just kicks me, and only saves my account in the `userinfo` and not in the `userstrings` as well. Can't seem to locate the issue, was hoping one of you might be able to. This is basically my entire MySQL system right here. Hopefulyl one of you find the issue, I sure as hell know I can't. Everything seems correct for me :S
Код:
public OnGameModeInit() { MySQLConnect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB); new string[MAX_PLAYER_NAME]; GetServerVarAsString("bind", string, sizeof(string)); format(serverip, sizeof(serverip), "%s:%d", string, GetServerVarAsInt("port")); UsePlayerPedAnims(); SetGameModeText(SERVER_GM_TEXT); AllowInteriorWeapons(1); EnableStuntBonusForAll(0); AllowAdminTeleport(1); ShowNameTags(true); DisableInteriorEnterExits(); return 1; } public OnPlayerConnect(playerid) { if(IsPlayerNPC(playerid)) return 1; PlayerInfo[playerid][pAdmin] = 0; SetPlayerColor(playerid, COLOR_BLACK); TogglePlayerClock(playerid,0); if(Security == 1) { Kick(playerid); } new name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name)); new ip[16]; GetPlayerIp(playerid, ip, sizeof(ip)); new cmdd[264]; format(cmdd, sizeof(cmdd), "SELECT `IP` FROM `bans` WHERE `IP`='%s' LIMIT 1;", ip); mysql_query(cmdd); mysql_store_result(); if (mysql_num_rows() != 0) { SendClientMessage(playerid, COLOR_BRIGHTRED, "You are banned from this server, please make an UnBan Application"); Kick(playerid); return 1; } format(cmdd, sizeof(cmdd), "SELECT `Username` FROM `bans` WHERE `Username`='%s' LIMIT 1;", name); mysql_query(cmdd); mysql_store_result(); if (mysql_num_rows() != 0) { SendClientMessage(playerid, COLOR_BRIGHTRED, "You are banned from this server, please make an UnBan Application"); Kick(playerid); return 1; } //MySQL Info Ok C: PlayerInfo[playerid][pSQLID] = 0; SendClientMessage(playerid, COLOR_ORANGE, "Connected! Joining server now..."); PlayerConnected(playerid); return 1; } public PlayerConnected(playerid) { SpawnPlayer(playerid); new plname[MAX_PLAYER_NAME],string[150]; GetPlayerName(playerid, plname, 24); MySQLCheckConnection(); new sqlaccountstatus = MySQLCheckAccount(plname); if(sqlaccountstatus > 0) { gPlayerAccount[playerid] = 1; PlayerInfo[playerid][pSQLID] = sqlaccountstatus; //This will pre load the passwords format(string, sizeof(string), "SELECT `Password` FROM `userstrings` WHERE `id`=%d LIMIT 1;", sqlaccountstatus); mysql_query(string); mysql_store_result(); mysql_fetch_field("Password", PlayerInfo[playerid][pKey]); mysql_free_result(); SendClientMessage(playerid, COLOR_ORANGE, "*******************"); SendClientMessage(playerid, COLOR_ORANGE, "Welcome to New Nation!"); SendClientMessage(playerid, COLOR_ORANGE, "This username is registered please login."); SendClientMessage(playerid, COLOR_ORANGE, "Current Version:"SERVER_GM_TEXT); SendClientMessage(playerid, COLOR_ORANGE, "Website: Site Coming soon"); SendClientMessage(playerid, COLOR_ORANGE, "*******************"); ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "{00FF00}New Nation","{FFFFFF}This account is already registered.\nPlease enter your pass!", "Login", "Exit"); return 1; } else { gPlayerAccount[playerid] = 0; SendClientMessage(playerid, COLOR_ORANGE, "*******************"); SendClientMessage(playerid, COLOR_ORANGE, "Welcome to New Nation!"); SendClientMessage(playerid, COLOR_ORANGE, "This username is registered please login."); SendClientMessage(playerid, COLOR_ORANGE, "Current Version:"SERVER_GM_TEXT); SendClientMessage(playerid, COLOR_ORANGE, "Website: Site Coming soon"); SendClientMessage(playerid, COLOR_ORANGE, "*******************"); ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "{00FF00}New Nation","This account is not in our system.\nPlease create your password!", "Create", "Exit"); } return 1; } public OnPlayerRegister(playerid, password[]) { //FuncLog("OnPlayerRegister"); if(IsPlayerConnected(playerid)) { MySQLCheckConnection(); new playername[MAX_PLAYER_NAME]; new playername3[MAX_PLAYER_NAME]; new newpass[64]; GetPlayerName(playerid, playername3, sizeof(playername3)); mysql_real_escape_string(playername3, playername); mysql_real_escape_string(password, newpass); new query[128];//PASSWORD format(query, sizeof(query), "INSERT INTO `userinfo` (UserName) VALUES ('%s');", playername); mysql_query(query); new newaccountsqlid = MySQLCheckAccount(playername3); if (newaccountsqlid != 0) { //format(query, sizeof(query), "INSERT INTO `uservehicles` (ID, UserName) VALUES (%d, '%s');", newaccountsqlid, playername); //mysql_query(query); format(query, sizeof(query), "INSERT INTO `userstrings` (ID, UserName, Password) VALUES (%d, '%s', '%s');", newaccountsqlid, playername, newpass); mysql_query(query); //format(query, sizeof(query), "INSERT INTO `userlocker` (ID, Username) VALUES (%d, '%s');", newaccountsqlid, playername); //mysql_query(query); PlayerInfo[playerid][pSQLID] = newaccountsqlid; strmid(PlayerInfo[playerid][pKey], password, 0, strlen(password), 127); //SendClientMessage(playerid, COLOR_YELLOW, "Account registered, you can now login."); //ShowPlayerDialog(playerid, 115, DIALOG_STYLE_INPUT, "{00BFFF}Epic Reality Roleplay", "This account is Registered!\nPlease enter your Password!", "Login", "Exit"); gPlayerAccount[playerid] = 1; OnPlayerLogin(playerid, password); return 1; } else { SendClientMessage(playerid, COLOR_BRIGHTRED, "There was an error creating your account. You will be disconnected now1."); gPlayerLogged[playerid] = 0; Kick(playerid); return 0; } } return 0; } public OnPlayerLogin(playerid,password[]) { if(IsPlayerConnected(playerid)) { MySQLCheckConnection(); { new query[256]; if(gPlayerAccount[playerid] == 1) { format(query, sizeof(query), "SELECT `Password` FROM `userstrings` WHERE `id`=%d LIMIT 1;", PlayerInfo[playerid][pSQLID]); mysql_query(query); mysql_store_result(); mysql_fetch_field("Password", PlayerInfo[playerid][pKey]); mysql_free_result(); if(!strcmp(PlayerInfo[playerid][pKey], password)) { format(query, sizeof(query), "UPDATE `userinfo` SET `Logged`=1 WHERE `id` = %d", PlayerInfo[playerid][pSQLID]); mysql_query(query); format(query, sizeof(query), "SELECT * FROM `userinfo` WHERE `id`=%d LIMIT 1;", PlayerInfo[playerid][pSQLID]); mysql_query(query); mysql_store_result(); mysql_fetch_row(MySQLData, "|"); mysql_free_result(); split(MySQLData, MySQLField, '|'); //Lets start loading shit shall we? PlayerInfo[playerid][pLevel] = strval( MySQLField[3] ); PlayerInfo[playerid][pAdmin] = strval( MySQLField[4] ); PlayerInfo[playerid][pBanned] = strval( MySQLField[5] ); PlayerInfo[playerid][pReg] = strval( MySQLField[6] ); PlayerInfo[playerid][pSex] = strval( MySQLField[7] ); PlayerInfo[playerid][pAge] = strval( MySQLField[8] ); PlayerInfo[playerid][pOrigin] = strval( MySQLField[9] ); //Now we're gonna load the floats and strings format(query, sizeof(query), "SELECT * FROM `userstrings` WHERE `id` = %d LIMIT 1;", PlayerInfo[playerid][pSQLID]); mysql_query(query); mysql_store_result(); mysql_fetch_row(MySQLData, "|"); mysql_free_result(); split(MySQLData, MySQLField, '|');//Once again you dumpfuck, MySQLFIeld 0 and 1 are the ID AND USERS | MySQLField 2 = Password which is already fucking loaded ok? PlayerInfo[playerid][pLogX] = floatstr(MySQLField[4]); PlayerInfo[playerid][pLogY] = floatstr(MySQLField[5]); PlayerInfo[playerid][pLogZ] = floatstr(MySQLField[6]); PlayerInfo[playerid][pLogA] = floatstr(MySQLField[7]); PlayerInfo[playerid][pSHealth] = floatstr(MySQLField[8]); PlayerInfo[playerid][pSArmour] = floatstr(MySQLField[9]); PlayerInfo[playerid][pAccount] = strval(MySQLField[10]); format(PlayerInfo[playerid][pBirthdate], 11, "%s", MySQLField[11]); } } else { gPlayerLogTries[playerid] += 1; if(gPlayerLogTries[playerid] >= MAX_SPAWN_ATTEMPTS) { format(query, sizeof(query), "System: %s has been kicked by NationBot, Reason: Too many login attempts!", PlayerNameEx(playerid)); ABroadCast(COLOR_LIGHTRED, query, 1); SendClientMessage(playerid, COLOR_LIGHTRED, "You have been kicked for too many login attempts"); Kick(playerid); return 1; } SendClientMessage(playerid, COLOR_LIGHTRED, "Invalid Pass! Multiple false attempts will see you kicked!"); ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "{00FF00}New Nation", "Password invalid!\nThis account is in our database\nPlease Enter your password","Login","Exit"); return 1; } } new sendername[MAX_PLAYER_NAME]; GetPlayerName(playerid, sendername, MAX_PLAYER_NAME); if(PlayerInfo[playerid][pReg] == 0) { PlayerInfo[playerid][pLevel] = 1; PlayerInfo[playerid][pSHealth] = 100.0; PlayerInfo[playerid][pSArmour] = 0.0; } if(PlayerInfo[playerid][pLevel] == -999) //This will auto ban the person { SendClientMessage(playerid, COLOR_LIGHTRED, "Your account has been banned from this server"); Kick(playerid); } new query[128]; for(new i; i<50; i++) SendClientMessage(playerid, COLOR_WHITE, " "); format(query, sizeof(query), "SYSTEM: Welcome to New Nation %s", PlayerNameEx(playerid)); SendClientMessage(playerid, COLOR_WHITE, query); gPlayerLogged[playerid] = 1; SpawnPlayer(playerid); } return 1; } public UpdatePlayer(playerid) { if(IsPlayerConnected(playerid)) { if(gPlayerLogged[playerid]) { MySQLCheckConnection(); new string[256]; format(UpdateQuery, sizeof(UpdateQuery), "UPDATE `userinfo` SET `Level`=%d",PlayerInfo[playerid][pLevel]); MySQLUpdatePlayerInt("Level", PlayerInfo[playerid][pLevel]); MySQLUpdatePlayerInt("AdminLevel",PlayerInfo[playerid][pAdmin]); MySQLUpdatePlayerInt("Banned",PlayerInfo[playerid][pBanned]); MySQLUpdatePlayerInt("Registered",PlayerInfo[playerid][pReg]); MySQLUpdatePlayerInt("Sex",PlayerInfo[playerid][pSex]); MySQLUpdatePlayerInt("Age",PlayerInfo[playerid][pAge]); MySQLUpdatePlayerInt("Origin",PlayerInfo[playerid][pOrigin]); MySQLUpdatePlayerInt("Logged", 0); format(string, sizeof(string), " WHERE `id`=%d;",PlayerInfo[playerid][pSQLID]); strcat(UpdateQuery, string); mysql_query(UpdateQuery); //Now for the strings and floats //format(UpdateQuery), sizeof(UpdateQuery), "UPDATE `userstrings` SET`Cash`=%d", GetPlayerMoneyEx(playerid); Save this though MySQLUpdatePlayerStr("Password", PlayerInfo[playerid][pKey]); format(string, sizeof(string), ", `Account`=%d", PlayerInfo[playerid][pAccount]); strcat(UpdateQuery, string); MySQLUpdatePlayerFlo("LogX",PlayerInfo[playerid][pLogX]); MySQLUpdatePlayerFlo("LogY",PlayerInfo[playerid][pLogY]); MySQLUpdatePlayerFlo("LogZ",PlayerInfo[playerid][pLogZ]); MySQLUpdatePlayerFlo("LogA",PlayerInfo[playerid][pLogA]); MySQLUpdatePlayerFlo("SpawnHealth",PlayerInfo[playerid][pSHealth]); MySQLUpdatePlayerFlo("SpawnArmor",PlayerInfo[playerid][pSArmour]); MySQLUpdatePlayerFlo("Birthdate",PlayerInfo[playerid][pBirthdate]); new year,month,day; getdate(year,month,day); format(string, sizeof(string), "%d-%d-%d", year,month,day); MySQLUpdatePlayerStr("LastLogin", string); } } return 1; } public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { if(dialogid == 1)//Register { if(response) { if(strlen(inputtext) < 5) { SendClientMessage(playerid, COLOR_GRAD1, "Your password needs to be at least 5 Characters long!"); ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "{00BFFF}Epic Reality Roleplay", "Your password needs to be at least 5 characters long!\nThis account is not registered!\nPlease enter your Password!", "Register", "Quit"); return 1; } else if(strlen(inputtext) > 60) { SendClientMessage(playerid, COLOR_GRAD1, "Your password can't be longer than 63 Characters!"); ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "{00BFFF}Epic Reality Roleplay", "Your password can't be longer than 60 characters!\nThis account is not registered!\nPlease enter your Password!", "Register", "Quit"); return 1; } //strmid(tmppass, inputtext, 0, strlen(inputtext), 255); OnPlayerRegister(playerid,inputtext); return 1; } else { Kick(playerid); return 1; } } if(dialogid == 2)//This will be the login screen { if(response) { if(gPlayerLogged[playerid] == 1) { SendClientMessage(playerid, COLOR_WHITE, "SYSTEM: You are already logged in."); return 1; } if(isnull(inputtext)) { new string[128]; gPlayerLogTries[playerid] += 1; if(gPlayerLogTries[playerid] >= MAX_PLAYER_SPAWN_ATTEMPTS) { format(string, sizeof(string), "System: %s has been kicked by NationBot, Reason: Too many login attempts!", PlayerName(playerid)); ABroadCast(COLOR_LIGHTRED, string, 1); SendClientMessage(playerid, COLOR_LIGHTRED, "You have been kicked for multiple login attempts"); Kick(playerid); return 1; } SendClientMessage(playerid, COLOR_LIGHTRED, "Invalid Password! Multiple false logins will result in you being kicked!"); ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "{00FF00}New Nation", "Password invalid!\nThis account is in our database\nPlease Enter your password","Login","Exit"); return 1; } OnPlayerLogin(playerid,inputtext); OnPlayerRequestSpawn(playerid); return 1; } else { Kick(playerid); } return 1; } return 0; } public OnPlayerSpawn(playerid)//Lets hope this works { if(PlayerInfo[playerid][pReg] == 1) { SetPlayerPos(playerid, 1682.51,-2327.55, 13.54); SetPlayerFacingAngle(playerid, 0.0); SetPlayerVirtualWorld(playerid, 0); SetPlayerInterior(playerid, 0); SetCameraBehindPlayer(playerid); SetPlayerHealth(playerid, 100.0); } return 1; } public OnPlayerRequestSpawn(playerid) { if(IsPlayerNPC(playerid)) return 1; if (gPlayerLogged[playerid] == 0) { SendClientMessage(playerid, COLOR_LIGHTRED, "You have to login or register first!"); return 0; } return 1; } public MySQLConnect(sqlhost[], sqluser[], sqlpass[], sqldb[]) { print("MYSQL: Attempting to connect to server..."); new MySQL:connection; if(DEBUG == 1) { connection = mysql_init(LOG_ALL, 0); } else { connection = mysql_init(LOG_ONLY_ERRORS, 0); } mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB, connection, 1); if(mysql_ping() == 0) { print("MYSQL: Database connection established."); return 1; } else { print("MYSQL: Could not connect! Retrying..."); mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB, connection, 1); if(mysql_ping()==0) { print("MYSQL: Reconnection successful!"); return 1; } else { print("MYSQL: Could not reconnect to Database! Terminating server..."); SendRconCommand("exit"); return 0; } } } public MySQLCheckConnection() { //FuncLog("MySQLCheckConnection"); if(mysql_ping()==0) { return 1; } else { print("MYSQL: Connection is dead! Attempting to reconnect..."); mysql_close(); MySQLConnect(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB); if(mysql_ping()==0) { print("MYSQL: Reconnection successful!"); return 1; } else { print("MYSQL: Could not reconnect to Database! Terminating server..."); SendRconCommand("exit"); return 0; } } } public MySQLUpdatePlayerInt(sqlvalname[], sqlupdateint) { //FuncLog("MySQLUpdatePlayerInt"); new query[128]; format(query, sizeof(query), ",`%s`=%d", sqlvalname, sqlupdateint); strcat(UpdateQuery, query); return 1; } public MySQLUpdatePlayerFlo(sqlvalname[], Float:sqlupdateflo) { //FuncLog("MySQLUpdatePlayerFlo"); new query[128]; format(query, sizeof(query), ",`%s`='%.3f'", sqlvalname, sqlupdateflo); strcat(UpdateQuery, query); return 1; } public MySQLUpdatePlayerStr(sqlvalname[], sqlupdatestr[]) { //FuncLog("MySQLUpdatePlayerStr"); new escstr[128]; new query[128]; mysql_real_escape_string(sqlupdatestr, escstr); format(query, sizeof(query), ",`%s`='%s'", sqlvalname, escstr); strcat(UpdateQuery, query); return 1; } public MySQLCheckAccount(sqlplayersname[]) { //FuncLog("MySQLCheckAccount"); new query[128]; new escstr[MAX_PLAYER_NAME]; mysql_real_escape_string(sqlplayersname, escstr); format(query, sizeof(query), "SELECT `id` FROM `userinfo` WHERE LOWER(UserName) = LOWER('%s') LIMIT 1 ;", escstr); mysql_query(query); mysql_store_result(); if (mysql_num_rows()==0) { return 0; } else { new strid[32]; new intid; mysql_fetch_row(strid); intid = strval(strid); return intid; } }