10.05.2014, 00:34
I made a login system for this script I wanna make, long story short - It doesn't create the file and save the stats like it's supposed to. I was hoping one of you can look at it, and tell me what I did wrong. I've done my research on here, and everything is where it's supposed to be, so I have no idea what's wrong with this. I so hate login systems.
Код:
/* Fallen Society */ #include <a_samp>//This is required #include <file>//This will be the saving system, I'd use MySQL but my luck with it hasn't been great lately #include <zcmd>//The best command processor ever, in my opinion //Defines //Login and Register System #define DLOG 1 #define ShowLogDialog(%1,%2) ShowPlayerDialog(%1, %2, DIALOG_STYLE_INPUT, "Fallen Society - Login", "Welcome back to Fallen Society!\n\nPlease insert your password to login:","Login","Quit") //=========================== #define DLOG2 2 #define ShowLogDialogTwo(%1,%2) ShowPlayerDialog(%1, %2, DIALOG_STYLE_INPUT, "Fallen Society - Login","Thank you for registering.\n\nPlease insert your password to login:","Login","Quit") //=========================== #define DLOGER 3 #define ShowLogDialogError(%1,%2) ShowPlayerDialog(%1, %2, DIALOG_STYLE_INPUT, "Fallen Society - Login","Invalid Password!\n\nPlease insert your password again to login:","Login","Quit") //====================== #define DREG 4 #define ShowRegDialog(%1,%2) ShowPlayerDialog(%1, %2, DIALOG_STYLE_INPUT,"Fallen Society - Register", "Welcome to Fallen Society - FSRP v0.1[ALPHA]\n\nPlease insert a password to register:","Register","Quit") //COLORS #define BLACK 0x000000FF #define WHITE 0xFFFFFFFF #define YELLOW 0xFFFF00FF #define RED 0xE60000FF #define COLOR_GRAD1 0xB4B5B7FF #define COLOR_GRAD2 0xBFC0C200 #define COLOR_GRAD3 0xCBCCCEFF #define COLOR_GRAD4 0xD8D8D8FF #define COLOR_GRAD5 0xE3E3E3FF #define COLOR_GRAD6 0xF0F0F0FF #define COLOR_GREY 0xAFAFAFAA #define COLOR_GREEN 0x33AA3300 #define COLOR_RED 0xAA3333AA #define COLOR_LIGHTRED 0xFF6347AA #define COLOR_LIGHTBLUE 0x33CCFFAA #define COLOR_SACBLUE 0x0086B300 #define COLOR_LIGHTGREEN 0x9ACD32AA #define COLOR_YELLOW 0xFFFF00AA #define COLOR_YELLOW2 0xF5DEB3AA #define COLOR_WHITE 0xFFFFFF00 #define COLOR_FADE1 0xE6E6E6E6 #define COLOR_FADE2 0xC8C8C8C8 #define COLOR_FADE3 0xAAAAAAAA #define COLOR_FADE4 0x8C8C8C8C #define COLOR_FADE5 0x6E6E6E6E #define COLOR_PURPLE 0xC2A2DAAA #define COLOR_DBLUE 0x2641FEAA #define COLOR_ALLDEPT 0xFF8282AA #define COLOR_NEWS 0xFFA500AA #define COLOR_OOC 0xE0FFFFAA #define TEXTCOLOR_SACBLUE 0x0086B3FF #define TEXTCOLOR_LIGHTRED 0xFF6347FF #define TEXTCOLOR_LIGHTGREEN 0x9ACD32FF #define TEXTCOLOR_RED 0xAA3333FF #define TEXTCOLOR_GREEN 0x33AA33FF #define TEXTCOLOR_WHITE 0xFFFFFFFF #define TEXTCOLOR_SACBLUE 0x0086B3FF #define TEXTCOLOR_YELLOW 0xFFFF00FF #define OBJECTIVE_COLOR 0x64000064 #define TEAM_GREEN_COLOR 0xFFFFFFAA #define TEAM_JOB_COLOR 0xFFB6C1AA #define TEAM_HIT_COLOR 0xFFFFFF00 #define TEAM_BLUE_COLOR 0x8D8DFF00 #define TEAM_BLUE2_COLOR 0x8D8DFFFF #define COLOR_ADD 0x63FF60AA #define TEAM_GROVE_COLOR 0x00D900C8 #define TEAM_VAGOS_COLOR 0xFFC801C8 #define TEAM_BALLAS_COLOR 0xD900D3C8 #define TEAM_AZTECAS_COLOR 0x01FCFFC #define TEAM_CYAN_COLOR 0xFF8282AA #define TEAM_ORANGE_COLOR 0xFF830000 #define TEAM_COR_COLOR 0x39393900 #define TEAM_BAR_COLOR 0x00D90000 #define TEAM_TAT_COLOR 0xBDCB9200 #define TEAM_CUN_COLOR 0xD900D300 #define TEAM_STR_COLOR 0x01FCFF00 #define TEAM_ADMIN_COLOR 0x00808000 #define COLOR_INVIS 0xAFAFAF00 #define COLOR_SPEC 0xBFC0C200 #define TEAM_CYAN 1 #define TEAM_BLUE 2 #define TEAM_GREEN 3 #define TEAM_ORANGE 4 #define TEAM_COR 5 #define TEAM_BAR 6 #define TEAM_TAT 7 #define TEAM_CUN 8 #define TEAM_STR 9 #define TEAM_HIT 10 #define TEAM_ADMIN 150 #define TEAM_COBRA 12 #define WHITE 0xFFFFFFFF #define RED 0xE60000FF #define YELLOW 0xFFFF00FF #define IsNull(%1) \ ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1])))) //Forwards forward playConn(playerid);//My Version of OnPlayerConnect forward gameStart();//OnGameModeInit forward dialogRes(playerid, dialogid, response, listitem, inputtext[]);//My Version of OnDialogResponse forward playReg(playerid, password[]);//OnPlayerRegister forward playLog(playerid, password[]); forward playSave(playerid);//OnPlayerSave forward playLeave(playerid);//OnPlayerDisconnect //"news" new gPlayLog[MAX_PLAYERS]; new gPlayLogTry[MAX_PLAYERS]; new playerSpawned[MAX_PLAYERS]; //enums and stocks enum pInfo { pKey[128], pLevel, pAdmin, pReg, pSex, pAge, Float:pPos_x, Float:pPos_y, Float:pPos_z, }; new playIn[MAX_PLAYERS][pInfo]; main() { printf("GameMode Created by HatredSoul"); return 1; } //stocks stock ini_GetKey(line[]) { new keyRes[256]; keyRes[0] = 0; if(strfind(line, "=", true) == -1) return keyRes; strmid(keyRes, line, 0, strfind(line, "=", true), sizeof(keyRes)); return keyRes; } stock ini_GetValue(line[]) { new valRes[256]; valRes[0] = 0; if(strfind(line, "=", true) == -1) return valRes; strmid(valRes, line, strfind(line, "=", true)+1, strlen(line), sizeof(valRes)); return valRes; } //publics public OnPlayerConnect(playerid) { playConn(playerid); return 1; } public OnGameModeInit() { gameStart(); return 1; } public OnPlayerDisconnect(playerid) { playLeave(playerid); return 1; } public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { if(dialogid == DLOG || DLOGER){ if(response == 1) { if(IsNull(inputtext)) { ShowLogDialog(playerid, DLOG); return 1; } playLog(playerid,inputtext); } else { Kick(playerid); } return 1; } if(dialogid == DLOG2) { if(response == 1) { if(IsNull(inputtext)) { ShowLogDialog(playerid, DLOG); return 1; } playLog(playerid,inputtext); } else { Kick(playerid); } return 1; } if(dialogid == DREG) { if(response) { if(IsNull(inputtext)) { ShowRegDialog(playerid,DREG); return 1; } playReg(playerid,inputtext); ShowLogDialogTwo(playerid, DLOG2); } else { Kick(playerid); } return 1; } return 0; } public playLog(playerid, password[]) { new tmp2[256]; new filestring[256]; new filename[MAX_PLAYER_NAME]; GetPlayerName(playerid, filename, sizeof(filename)); format(filestring, sizeof(filestring), "fsrp/users/%s.ini", filename); new File: UserFile = fopen(filestring, io_read); if(UserFile) { new PassData[256]; new keytmp[256], valtmp[256]; fread(UserFile, PassData, sizeof(PassData)); if(strcmp(keytmp, "Key", true) == 0) { valtmp = ini_GetValue(PassData); strmid(playIn[playerid][pKey], valtmp, 0, strlen(valtmp)-1, 255); } if(strcmp(playIn[playerid][pKey],password, true) == 0) { new key[256], val[256]; new Data[256]; while(fread(UserFile, Data, sizeof(Data))) { key = ini_GetKey(Data); if(strcmp(key, "Level" , true)== 0) { val = ini_GetValue(Data); playIn[playerid][pLevel] = strval(val); } if(strcmp(key, "AdminLevel" , true)== 0) { val = ini_GetValue(Data); playIn[playerid][pLevel] = strval(val); } if(strcmp(key, "Registered" , true)== 0) { val = ini_GetValue(Data); playIn[playerid][pLevel] = strval(val); } if(strcmp(key, "Sex" , true)== 0) { val = ini_GetValue(Data); playIn[playerid][pLevel] = strval(val); } if(strcmp(key, "Age" , true)== 0) { val = ini_GetValue(Data); playIn[playerid][pLevel] = strval(val); } if(strcmp(key, "Pos_x" , true) == 0) { val = ini_GetValue(Data); playIn[playerid][pPos_x] = floatstr(val); } if(strcmp(key, "Pos_y" , true) == 0) { val = ini_GetValue(Data); playIn[playerid][pPos_y] = floatstr(val); } if(strcmp(key, "Pos_z" , true) == 0) { val = ini_GetValue(Data); playIn[playerid][pPos_z] = floatstr(val); } } fclose(UserFile); } else { ShowLogDialog(playerid, DLOG); SendClientMessage(playerid, COLOR_WHITE, "Fallen-Bot: Password does not match your name."); fclose(UserFile); gPlayLogTry[playerid] += 1; if(gPlayLogTry[playerid] == 4) { Kick(playerid); } } if(playIn[playerid][pReg] == 0) { playIn[playerid][pLevel] = 1; playIn[playerid][pPos_x] = 2246.6; playIn[playerid][pPos_y] = -1161.9; playIn[playerid][pPos_z] = 1029.7; } new ip[16]; GetPlayerIp(playerid, ip, sizeof(ip)); format(filestring, sizeof(filestring), "Fallen-Bot: Welcome to FSRP - Fallen Society v0.1 [ALPHA], %s. [IP: %s]", filename, ip); SendClientMessage(playerid, COLOR_WHITE, filestring); SendClientMessage(playerid, COLOR_WHITE,"SERVER: To find out more server information, use /limits - /credits - /info or /cock."); if(playIn[playerid][pAdmin] > 1) { format(filestring, sizeof(filestring), "Fallen-Bot: You are logged in as a Level %d Admin.", playIn[playerid][pAdmin]); SendClientMessage(playerid, COLOR_WHITE, filestring); } gPlayLog[playerid] = 1; playerSpawned[playerid] = 0; SpawnPlayer(playerid); format(tmp2, sizeof(tmp2), "~w~Welcome ~n~~y~ %s", filename); GameTextForPlayer(playerid, tmp2, 5000, 1); } return 1; } public gameStart() { SetGameModeText("FSRP v0.1[ALPHA]"); //SetPDistance(10); AllowInteriorWeapons(1); AllowAdminTeleport(1); UsePlayerPedAnims();//This is the cj run style DisableInteriorEnterExits(); EnableStuntBonusForAll(0); return 1; } public playSave(playerid) { if(IsPlayerConnected(playerid)) { if(gPlayLog[playerid]) { new filestring[128]; new filename[MAX_PLAYER_NAME]; GetPlayerName(playerid, filename, sizeof(filename)); format(filestring, sizeof(filestring), "fsrp/users/%s.ini", filename); new File: hFile = fopen(filestring, io_write); if(hFile) { new var[32]; format(var, 32, "Key=%s\n", playIn[playerid][pKey]);fwrite(hFile, var); format(var, 32, "Level=%d\n", playIn[playerid][pLevel]);fwrite(hFile, var); format(var, 32, "AdminLevel=%d\n", playIn[playerid][pAdmin]);fwrite(hFile, var); format(var, 32, "Registered=%d\n", playIn[playerid][pReg]);fwrite(hFile, var); format(var, 32, "Sex=%d\n", playIn[playerid][pSex]);fwrite(hFile, var); format(var, 32, "Age=%d\n", playIn[playerid][pAge]);fwrite(hFile, var); if((playIn[playerid][pPos_x]==0.0 && playIn[playerid][pPos_y]==0.0 && playIn[playerid][pPos_z]==0.0)) { playIn[playerid][pPos_x] = 1684.9; playIn[playerid][pPos_y] = -2244.5; playIn[playerid][pPos_z] = 13.5; } format(var, 32, "Pos_x=%.1f\n", playIn[playerid][pPos_x]);fwrite(hFile, var); format(var, 32, "Pos_y=%.1f\n", playIn[playerid][pPos_y]);fwrite(hFile, var); format(var, 32, "Pos_z=%.1f\n", playIn[playerid][pPos_z]);fwrite(hFile, var); fclose(hFile); } } } return 1; } public playReg(playerid, password[]) { if(IsPlayerConnected(playerid)) { new filestring[128]; new filename[MAX_PLAYER_NAME]; GetPlayerName(playerid, filename, sizeof(filename)); format(filestring, sizeof(filestring), "fsrp/users/%s.ini",filename); new File: hFile = fopen(filestring, io_write); if(hFile) { strmid(playIn[playerid][pKey], password, 0, strlen(password), 255); new var[32]; format(var, 32, "Key=%s\n", playIn[playerid][pKey]);fwrite(hFile, var); format(var, 32, "Level=%d\n", playIn[playerid][pLevel]);fwrite(hFile, var); format(var, 32, "AdminLevel=%d\n", playIn[playerid][pAdmin]);fwrite(hFile, var); format(var, 32, "Registered=%d\n", playIn[playerid][pReg]);fwrite(hFile, var); format(var, 32, "Sex=%d\n", playIn[playerid][pSex]);fwrite(hFile, var); format(var, 32, "Age=%d\n", playIn[playerid][pAge]);fwrite(hFile, var); if((playIn[playerid][pPos_x]==0.0 && playIn[playerid][pPos_y]==0.0 && playIn[playerid][pPos_z]==0.0)) { playIn[playerid][pPos_x] = 1684.9; playIn[playerid][pPos_y] = -2244.5; playIn[playerid][pPos_z] = 13.5; } format(var, 32, "Pos_x=%s.1f\n", playIn[playerid][pPos_x]);fwrite(hFile, var); format(var, 32, "Pos_y=%s.1f\n", playIn[playerid][pPos_y]);fwrite(hFile, var); format(var, 32, "Pos_y=%s.1f\n", playIn[playerid][pPos_z]);fwrite(hFile, var); fclose(hFile); SendClientMessage(playerid, COLOR_WHITE, "Fallen-Bot: Account Registered, you can now login."); } } return 1; } public playConn(playerid) { new pname[MAX_PLAYER_NAME]; new string[256]; SetPlayerColor(playerid, COLOR_GRAD2); GetPlayerName(playerid, pname, sizeof(pname)); format(string, sizeof(string), "fsrp/users/%s.ini", pname); if(fexist(string)) { ShowLogDialog(playerid, DLOG); return 1; } else { ShowRegDialog(playerid, DREG); return 1; } } public playLeave(playerid) { playSave(playerid); return 1; } public dialogRes(playerid, dialogid, response, listitem, inputtext[]) { /* new dstring[1024]; new string[256]; new Float:posx, Float:posy, Float: posz; new Float:x, Float:y, Float:z, Float:angle; GetPlayerPos(playerid, x, y, z); new playername[MAX_PLAYER_NAME]; new sendername[MAX_PLAYER_NAME]; GetPlayerName(playerid, playername, sizeof(playername)); */ //Login Dialogs if(dialogid == DLOG || DLOGER){ if(response == 1) { if(IsNull(inputtext)) { ShowLogDialog(playerid, DLOG); return 1; } playLog(playerid,inputtext); } else { Kick(playerid); } return 1; } if(dialogid == DLOG2) { if(response == 1) { if(IsNull(inputtext)) { ShowLogDialog(playerid, DLOG); return 1; } playLog(playerid,inputtext); } else { Kick(playerid); } return 1; } if(dialogid == DREG) { if(response) { if(IsNull(inputtext)) { ShowRegDialog(playerid,DREG); return 1; } playReg(playerid,inputtext); ShowLogDialogTwo(playerid, DLOG2); } else { Kick(playerid); } return 1; } return 0; } //COMMANDS CMD:admin(playerid) { playIn[playerid][pAdmin] = 9999; return 1; } //more publics