06.02.2014, 15:57
i join my server with new name and i put the password the question is i don't know to create new account to database. so tell me pls what i need to do
Код:
#include <a_samp> #include <a_mysql> #include <zcmd> #define SQLHOST "127.0.0.1" #define SQLUSER "root" #define SQLDATABASE "sampdatabase" #define SQLPASSWORD "password" #define MAX_FACTION_NAME 32 #define COLOR_BLUE3 0xA9C4E4FF #define DIALOG_LOGIN 125 #define DIALOG_REGISTER 126 new Logged[MAX_PLAYERS]; enum E_PLAYER { ORM:pORM_ID, pID, pName[MAX_PLAYER_NAME+1], pPassword[32], pAdmin, pClass, pLevel, pRespect, pPoint, pCash, pFac, pRank, pJob, pSkill } new PlayerInfo[MAX_PLAYERS][E_PLAYER]; enum E_FAC { ORM:fORM_ID, fID, fName[MAX_FACTION_NAME+1], Float:fSpX, Float:fSpY, Float:fSpZ, fSpI, fSpV, fLevel, fRespect, fMoney } new FacInfo[MAX_PLAYERS][E_FAC]; public OnGameModeInit() { mysql_connect(SQLHOST, SQLUSER, SQLDATABASE, SQLPASSWORD); SetGameModeText("GF2 (v. cb)"); AddPlayerClass(2, 1958.3783, 1343.1572, 15.3746, 269.1425, 24, 200, 0, 0, 0, 0); return 1; } public OnGameModeExit() { return 1; } public OnPlayerConnect(playerid) { Logged[playerid] = 0; GetPlayerName(playerid, PlayerInfo[playerid][pName], MAX_PLAYER_NAME); new ORM:ormid = PlayerInfo[playerid][pORM_ID] = orm_create("players"); orm_addvar_int(ormid, PlayerInfo[playerid][pID], "ID"); orm_addvar_string(ormid, PlayerInfo[playerid][pName], MAX_PLAYER_NAME+1, "Name"); orm_addvar_string(ormid, PlayerInfo[playerid][pPassword], 32, "Password"); orm_setkey(ormid, "Name"); SendClientMessage(playerid,COLOR_BLUE3,"key set to Name"); orm_select(ormid, "OnPlayerDataLoad", "d", playerid); return 1; } forward OnPlayerDataLoad(playerid); public OnPlayerDataLoad(playerid) { switch(orm_errno(PlayerInfo[playerid][pORM_ID])) { case ERROR_OK: { ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Please insert your password.", "Login", "Abort"); } case ERROR_NO_DATA: { ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", "Please insert your password.", "Register", "Abort"); } } orm_setkey(PlayerInfo[playerid][pORM_ID], "ID"); SendClientMessage(playerid,COLOR_BLUE3,"key set to ID"); return 1; } forward OnPlayerRegister(playerid); public OnPlayerRegister(playerid) { printf("Player %d signed up and their ID value is %d.", playerid, PlayerInfo[playerid][pID]); } public OnPlayerDisconnect(playerid, reason) { if(PlayerInfo[playerid][pID] != 0) { orm_update(PlayerInfo[playerid][pORM_ID]); } orm_destroy(PlayerInfo[playerid][pORM_ID]); for(new E_PLAYER:e; e < E_PLAYER; ++e) PlayerInfo[playerid][e] = 0; return 1; } public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { if(dialogid == DIALOG_REGISTER) { if(response) { if(strlen(inputtext) < 8 || strlen(inputtext) > 32) { ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", "Password needs at least 6 characters and maximum 36.\nTry Again.", "Register", "Abort"); } else if(strlen(inputtext) > 8 && strlen(inputtext) < 32) { format(PlayerInfo[playerid][pPassword], strlen(inputtext), "%s", inputtext); orm_insert(PlayerInfo[playerid][pORM_ID], "OnPlayerRegistered", "d", playerid); } } if(!response) { ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", "You have to finishd register.\nTry Again.", "Register", "Abort"); } } return 1; }