20.03.2010, 13:57
I got a registration script but it doesn't save the stuff
Whats wrong? Its a FS
Код:
#include <a_samp> #include <dini> #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1 #define COLOR_RED 0xFF0000FF #define COLOR_YELLOW 0xFFFF00AA new level[MAX_PLAYERS]; new logged[MAX_PLAYERS]; stock udb_hash(buf[]) { new length=strlen(buf); new s1 = 1; new s2 = 0; new n; for (n=0; n<length; n++) { s1 = (s1 + buf[n]) % 65521; s2 = (s2 + s1) % 65521; } return (s2 << 16) + s1; } public OnPlayerCommandText(playerid, cmdtext[]) { dcmd(register, 8, cmdtext); dcmd(login, 5, cmdtext); return 0; } dcmd_register(playerid, params[]) { new file[256], pname[MAX_PLAYER_NAME]; GetPlayerName(playerid, pname, sizeof(pname)); format(file, sizeof(file), "\\Users\\%s.ini", pname); if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "[Usage] /register [password]"); if(dini_Exists(file)) return SendClientMessage(playerid, COLOR_RED, "[Error] You are already registered!"); dini_Create(file); dini_IntSet(file, "HashPW", udb_hash(params)); dini_Set(file, "Password", params); dini_IntSet(file, "Level", 0); dini_IntSet(file, "Score", GetPlayerScore(playerid)); dini_IntSet(file, "Money", GetPlayerMoney(playerid)); new string[256]; format(string, 256, "[System] You succesfully registered the nickname %s with password %s", pname, params); SendClientMessage(playerid, COLOR_YELLOW, string); logged[playerid] = 1; SendClientMessage(playerid, COLOR_YELLOW, "[System] You have been automatically logged in!"); return 1; } dcmd_login(playerid, params[]) { new file[256]; new string[256], pname[MAX_PLAYER_NAME]; GetPlayerName(playerid, pname, sizeof(pname)); format(file, sizeof(string), "\\Users\\%s.ini", pname); if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "[Usage] /login [password]"); if(!dini_Exists(file)) return SendClientMessage(playerid, COLOR_RED, "[Error] You are not registered!"); if(logged[playerid]) return SendClientMessage(playerid, COLOR_RED, "[Error] You are already logged in!"); new tmp[256]; tmp = dini_Get(file, "HashPW"); if(udb_hash(params) != strval(tmp)) { format(string, 256, "[Error] You specified the wrong password for %s!", pname); SendClientMessage(playerid, COLOR_RED, string); } else { logged[playerid] = 1; level[playerid] = dini_Int(file, "Level"); SetPlayerScore(playerid, dini_Int(file, "Score")); GivePlayerMoney(playerid, dini_Int(file, "Money")-GetPlayerMoney(playerid)); SendClientMessage(playerid, COLOR_YELLOW, "[System] You have succesfully logged in!"); printf("%s (%i) logged in with password %s", pname, playerid, params); } return 1; }