login

Započeo Salke, Jul 29, 2021, 00:04:09 PRE PODNE

prethodna tema - sledeća tema

0 članova i 5 gostiju pregledaju ovu temu.

Problem(error/warning): moze li neko da uskladi Login Count ja sam probao ali mi ne ide   
Deo skripte:
#include <a_samp>

#include <YSI\y_ini>

#define DIALOG_REGISTER 	1
#define DIALOG_LOGIN 		2

#define PATH "/Korisnici/%s.ini"

enum pInfo
{
	pLozinka,
	pNovac,
	pLevel,
	pAdmin
};
new PlayerInfo[MAX_PLAYERS][pInfo];

stock UserPath(playerid)
{
	new string[128],playername[MAX_PLAYER_NAME];
	GetPlayerName(playerid,playername,sizeof(playername));
	format(string,sizeof(string),PATH,playername);
	return string;
}

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;
}

main ( ) { }
public OnGameModeInit()
{
	SetGameModeText("B:DM v1.0");
	return 1;
}

public OnGameModeExit()
{
	return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
	return 1;
}

public OnPlayerConnect(playerid)
{
	SendClientMessage(playerid, -1, "Dobrodosli na server!");
	if(fexist(UserPath(playerid)))
	{
	    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra=true, .extra=playerid);
	    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Unesite vasu lozinku:", "Prijavi se", "Odustani");
	}
	else
 	{
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", "Unesite vasu lozinku:", "Registruj se", "Odustani");
 	}
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
	new INI:File = INI_Open(UserPath(playerid));
	INI_SetTag(File, "data");
 	INI_WriteInt(File, "Novac", GetPlayerMoney(playerid));
 	INI_WriteInt(File, "Level", PlayerInfo[playerid][pLevel]);
 	INI_WriteInt(File, "Admin", PlayerInfo[playerid][pAdmin]);
 	INI_Close(File);
	return 1;
}

public OnPlayerSpawn(playerid)
{
	SetPlayerPos(playerid, 1126.4000,-2036.9590,69.8837);
	return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
	return 1;
}

public OnVehicleSpawn(vehicleid)
{
	return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
	return 1;
}

public OnPlayerText(playerid, text[])
{
	return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/mycommand", cmdtext, true, 10) == 0)
	{
		// Do something here
		return 1;
	}
	return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
	return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
	return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
	return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
	return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
	return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
	return 1;
}

public OnRconCommand(cmd[])
{
	return 1;
}

public OnPlayerRequestSpawn(playerid)
{
	SpawnPlayer(playerid);
	return 1;
}

public OnObjectMoved(objectid)
{
	return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
	return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
	return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
	return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
	return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
	return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
	return 1;
}

public OnPlayerExitedMenu(playerid)
{
	return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
	return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
	return 1;
}

public OnPlayerUpdate(playerid)
{
	return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
	return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
	return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
	return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	switch(dialogid)
	{
	    case DIALOG_REGISTER:
	    {
		    if(!response) return Kick(playerid);
		    if(response)
		    {
		        if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", "Unesite vasu lozinku:", "Registruj se", "Odustani");
		        new INI:File = INI_Open(UserPath(playerid));
		        INI_SetTag(File, "data");
		        INI_WriteInt(File, "Lozinka", udb_hash(inputtext));
		        INI_WriteInt(File, "Novac", 25000);
		        INI_WriteInt(File, "Level", 2);
		        INI_WriteInt(File, "Admin", 0);
		        INI_Close(File);
		        SpawnPlayer(playerid);
		        GivePlayerMoney(playerid, 25000);
		        SetCameraBehindPlayer(playerid);
		    }
	    }
	    case DIALOG_LOGIN:
	    {
	        if(!response) return Kick(playerid);
		    if(response)
		    {
		        if(udb_hash(inputtext) == PlayerInfo[playerid][pLozinka])
		        {
		            INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra=true, .extra=playerid);
		            GivePlayerMoney(playerid, PlayerInfo[playerid][pNovac]);
		            SpawnPlayer(playerid);
		            return 1;
		        }
		        else
		        {
		            ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Unesite vasu lozinku:", "Prijavi se", "Odustani");
		            return 1;
		        }
		    }
	    }
	}
	return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
	return 1;
}
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
	INI_Int("Lozinka",PlayerInfo[playerid][pLozinka]);
	INI_Int("Novac",PlayerInfo[playerid][pNovac]);
	INI_Int("Level",PlayerInfo[playerid][pLevel]);
	INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
	return 1;
}

Pawno Code: // 
Debug iz server_log(ukoliko je u pitanju crashanje servera - crashdetect log)://  AKO MOZETE NA OVAJ KOD DA TO NAPRAVITE HVALA
Poslednja Izmena: Avgust 04, 2021, 20:27:40 POSLE PODNE od M Ө M Σ N Z I

Sta ti treba tacno nisam te skonto


Citat: Taylor Morelli poslato Jul 29, 2021, 00:14:18 PRE PODNE
Sta ti treba tacno nisam te skonto
pa nikad ni neces jer si wannabe  8)

Hoćete prestati sa if(!response) if(response) već jednom, evo već 15 godina kako pišete to.  ???


new loginFails[MAX_PLAYERS char];
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
    switch(dialogid)
    {
        case DIALOG_REGISTER: {
            if (!response) {
                return Kick(playerid);
            }
            
            if (!strlen(inputtext)) {
                return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", "Unesite vasu lozinku:", "Registruj se", "Odustani");
            }
            
            new INI:File = INI_Open(UserPath(playerid));
            INI_SetTag(File, "data");
            INI_WriteInt(File, "Lozinka", udb_hash(inputtext));
            INI_WriteInt(File, "Novac", 25000);
            INI_WriteInt(File, "Level", 2);
            INI_WriteInt(File, "Admin", 0);
            INI_Close(File);
            
            SpawnPlayer(playerid);
            GivePlayerMoney(playerid, 25000);
            
            SetCameraBehindPlayer(playerid);
        }
        case DIALOG_LOGIN: {
            if (!response) {
                return Kick(playerid);
            }

            #if !defined MAX_LOGIN_FAILS
                #define MAX_LOGIN_FAILS (3)
            #endif
            if (udb_hash(inputtext) != PlayerInfo[playerid][pLozinka]) {
                if (loginFails{playerid} >= MAX_LOGIN_FAILS) {
                    return Kick(playerid);
                } else {
                    return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Unesite vasu lozinku:", "Prijavi se", "Odustani");
                }
            }
            
            INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra=true, .extra=playerid);
            GivePlayerMoney(playerid, PlayerInfo[playerid][pNovac]);
            SpawnPlayer(playerid);
            
            return 1;
        }
    }
    return 1;
}

@Sage moraju se ljudi osigurati, ako nije response, moramo provjerit i drugo, odakle tebi pravo da zakljucis ako nije jedno da je automatski drugo.

Citat: Galardo poslato Jul 30, 2021, 11:46:19 PRE PODNE
@Sage moraju se ljudi osigurati, ako nije response, moramo provjerit i drugo, odakle tebi pravo da zakljucis ako nije jedno da je automatski drugo.
Sramota od mene stvarno :D
Bukvalno kako može da bude 1 ako nije 0  >:( >:( >:( >:( >:(

EDIT: Zaboravio sam da stavim, resetuj pod OnPlayerConnect varijablu,
loginFails{playerid} = 0;


EDIT 2: Ovo je razlog zbog kog ne volim obične SAMP Dialoge nego y_dialogs, bespotrebno pravljenje varijabli :D
Poslednja Izmena: Jul 30, 2021, 15:04:22 POSLE PODNE od Sage