#1

Why when I connect to server server fails? use gm below
[pawn]#include <a_samp>
#include <a_sampmysql>

#define MYSQL_HOST "localhost"
#define MYSQL_USER "root"
#define MYSQL_PASS ""
#define MYSQL_DB "samp"

#define MAX_STRING 255

//Colours
#define COLOR_RED 0xAA3333AA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_LIGHTRED 0xFF6347AA

//Forward MYSQL
forward MySQLConnect(sqlhost[], sqluser[], sqlpass[], sqldb[]);
forward MySQLDisconnect();
forward MySQLCheckConnection();
forward MySQLUpdatePlayerInt(query[], sqlplayerid, sqlvalname[], sqlupdateint);
forward MySQLUpdatePlayerFlo(query[], sqlplayerid, sqlvalname[], Floatqlupdateflo);
forward MySQLUpdatePlayerStr(query[], sqlplayerid, sqlvalname[], sqlupdatestr[]);
forward MySQLUpdateBuild(query[], sqlplayerid);
forward MySQLCreateAccount(newplayersname[], newpassword[]);
forward MySQLCheckAccount(sqlplayersname[]);
forward MySQLCheckAccountLocked(sqlplayerid);
forward MySQLFetchAcctSingle(sqlplayerid, sqlvalname[], sqlresult[]);
forward MySQLFetchAcctRecord(sqlplayerid, sqlresult[]);
forward MySQLAddLoginRecord(sqlplayerid, ipaddr[]);
forward MySQLUpdateFinish(query[], sqlplayerid);
forward MySQLUpdatePlayerIntSingle(sqlplayerid, sqlvalname[], sqlupdateint);
//Forward Regyster & Login System
forward OnPlayerLogin(playerid,password[]);
forward OnPlayerUpdate(playerid);
forward OnPlayerRegister(playerid, password[]);
forward split(const strsrc[], strdest[][], delimiter);
//New Function
new gPlayerAccount[MAX_PLAYERS];
new gPlayerLogged[MAX_PLAYERS];
new gPlayerLogTries[MAX_PLAYERS];

enum pInfo
{
pKey[128],
pSQLID,
};
new PlayerInfo[MAX_PLAYERS][pInfo];

main()
{
print("\n----------------------------------");
print(" Blank Gamemode by your name here");
print("----------------------------------\n");
}

public OnGameModeInit()
{
// Don't use these lines if it's a filterscript
SetGameModeText("Blank Script");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;
}

public OnGameModeExit()
{
return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
if(IsPlayerNPC(playerid) != 1)
{
// new string[128];
PlayerPlaySound(playerid, 1187, 0.0, 0.0, 0.0);
//PlayerInfo[playerid][pModel] = Peds[classid][0];

if (/*RegistrationStep[playerid] == 0 && */gPlayerLogged[playerid] != 1 && IsPlayerNPC(playerid) !=1)
{
if (gPlayerAccount[playerid] != 0)
{
new loginstring[128];
new loginname[64];
GetPlayerName(playerid,loginname,sizeof(loginname) );
format(loginstring,sizeof(loginstring),"Bine ai venit, {91B17A}%s{A9C4E4}\nAcel nick este inregistrat.\nTe rog logheaza-te:",loginname);
ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Lo gin",loginstring,"Login","Exit");
}
else
{
gPlayerAccount[playerid] = 0;
new regstring[128];
new regname[64];
GetPlayerName(playerid,regname,sizeof(regname));
format(regstring,sizeof(regstring),"Bine ai venit, {91B17A}%s{A9C4E4}\nNu ai cont.\nTe rog inregistreaza-te:",regname);
ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Re gister",regstring,"Register","Exit");
}
//PlayerPlaySound(playerid, 1187, 0.0, 0.0, 0.0);
//PlayerInfo[playerid][pModel] = Peds[classid][0];
}
return 1;
}
return 1;
}

public OnPlayerConnect(playerid)
{
if(IsPlayerNPC(playerid) != 1)
{
new plname[MAX_PLAYER_NAME];
gPlayerAccount[playerid] = 0;
gPlayerLogged[playerid] = 0;
gPlayerLogTries[playerid] = 0;
GetPlayerName(playerid, plname, sizeof(plname));
MySQLCheckConnection();
new sqlaccountstatus = MySQLCheckAccount(plname);
if(sqlaccountstatus != 0)
{
// Check if the account is locked
if (MySQLCheckAccountLocked(sqlaccountstatus) != 0)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "This account has been locked and cannot be accessed. Please contact an admin.");
Kick(playerid);
return 0;
}
gPlayerAccount[playerid] = 1;
PlayerInfo[playerid][pSQLID] = sqlaccountstatus;
}
else
{
gPlayerAccount[playerid] = 0;
}
}
SendClientMessage(playerid, COLOR_YELLOW, "Please wait...");
return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
return 1;
}

public OnPlayerSpawn(playerid)
{
if(IsPlayerNPC(playerid) != 1)
{
if(gPlayerLogged[playerid] == 0 && IsPlayerNPC(playerid) != 1)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "** This server requires you to login first (Kicked) **");
Kick(playerid);
}
}
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)
{
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 OnPlayerRegister(playerid, password[]) // v1.0 by Luk0r
{
if(IsPlayerConnected(playerid))
{
MySQLCheckConnection();
new playername3[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername3, sizeof(playername3));
new newaccountsqlid = MySQLCreateAccount(playername3, password);
if (newaccountsqlid != 0)
{
PlayerInfo[playerid][pSQLID] = newaccountsqlid;
//PlayerInfo[playerid][pKey] = password;
strmid(PlayerInfo[playerid][pKey], password, 0, strlen(password), 255);
OnPlayerUpdate(playerid);
new loginstring[128];
new loginname[64];
GetPlayerName(playerid,loginname,sizeof(loginname) );
format(loginstring,sizeof(loginstring),"Bine ai venit, {91B17A}%s{A9C4E4}\nAcum poti sa te loghezi pe cont:",loginname);
ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Lo gin",loginstring,"Login","Exit");
return 1;
}
else
{
SendClientMessage(playerid, COLOR_RED, "There was an error creating your account. You will be disconnected now.");
Kick(playerid);
return 0;
}
}
return 0;
}

public OnPlayerUpdate(playerid) // by Luk0r v1.2
{
if(IsPlayerConnected(playerid))
{
if(gPlayerLogged[playerid])
{
MySQLCheckConnection();
new query[MAX_STRING];
format(query, MAX_STRING, "UPDATE players SET ");
MySQLUpdatePlayerStr(query, PlayerInfo[playerid][pSQLID], "Password", PlayerInfo[playerid][pKey]);
MySQLUpdateFinish(query, PlayerInfo[playerid][pSQLID]);
}
}
return 1;
}

public OnPlayerLogin(playerid,password[]) // by Luk0r v1.0
{
MySQLCheckConnection();
// new tmp2[256];
// new string2[64];
new playername2[MAX_PLAYER_NAME];
new playernamesplit[3][MAX_PLAYER_NAME];
GetPlayerName(playerid, playername2, sizeof(playername2));
split(playername2, playernamesplit, '_');
MySQLFetchAcctSingle(PlayerInfo[playerid][pSQLID], "Password", PlayerInfo[playerid][pKey]);
if(strcmp(PlayerInfo[playerid][pKey],password, true ) == 0 )
{
new Data[1024];
new Field[64];
new rcnt = 1;
MySQLFetchAcctRecord(PlayerInfo[playerid][pSQLID], Data);
samp_mysql_strtok(Field, "|", Data);
while (samp_mysql_strtok(Field, "|", "")==1)
{
rcnt++;
}
samp_mysql_free_result();
}
else
{
new loginstring[128];
new loginname[64];
GetPlayerName(playerid,loginname,sizeof(loginname) );
format(loginstring,sizeof(loginstring),"PAROLA GRESITA\nTe rog baga parola corecta:",loginname);
ShowPlayerDialog(playerid,3,DIALOG_STYLE_INPUT,"Lo gin",loginstring,"Login","Exit");
gPlayerLogTries[playerid] += 1;
if(gPlayerLogTries[playerid] == 4) { Ban(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[])
{
new sendername[MAX_PLAYER_NAME];
// new string[128];
if(response)
{
if(dialogid == 2 || dialogid == 3)
{
if(strlen(inputtext))
{
new tmppass[64];
strmid(tmppass, inputtext, 0, strlen(inputtext), 255);
//Encrypt(tmppass);
OnPlayerLogin(playerid,tmppass);
}
else
{
new loginstring[128];
new loginname[64];
GetPlayerName(playerid,loginname,sizeof(loginname) );
format(loginstring,sizeof(loginstring),"PAROLA GRESITA\nTe rog baga parola corecta:",loginname);
ShowPlayerDialog(playerid,12347,DIALOG_STYLE_INPUT ,"Login",loginstring,"Login","Exit");
gPlayerLogTries[playerid] += 1;
if(gPlayerLogTries[playerid] == 5) { Ban(playerid); }
}
}
if(dialogid == 1)
{
if(strlen(inputtext))
{
GetPlayerName(playerid, sendername, sizeof(sendername));
new sqlaccountexists = MySQLCheckAccount(sendername);
if (sqlaccountexists != 0)
{
SendClientMessage(playerid, COLOR_RED, "Immigration: There is already a citizen with that name.");
//fclose(hFile);
return 1;
}
new tmppass[64];
strmid(tmppass, inputtext, 0, strlen(inputtext), 255);
//Encrypt(tmppass);
OnPlayerRegister(playerid,tmppass);
}
else
{
new regstring[128];
new regname[64];
GetPlayerName(playerid,regname,sizeof(regname));
format(regstring,sizeof(regstring),"Bine ai venit, {91B17A}%s{A9C4E4}\nNu ai cont.\nTe rog inregistreaza-te:",regname);
ShowPlayerDialog(playerid,12345,DIALOG_STYLE_INPUT ,"Register",regstring,"Register","Exit");
}
}
}
return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}

public MySQLConnect(sqlhost[], sqluser[], sqlpass[], sqldb[]) // by Luk0r
{
print("MYSQL: Attempting to connect to server...");
samp_mysql_connect(sqlhost, sqluser, sqlpass);
samp_mysql_select_db(sqldb);
if(samp_mysql_ping()==0)
{
print("MYSQL: Database connection established.");
return 1;
}
else
{
print("MYSQL: Connection error, retrying...");
samp_mysql_connect(sqlhost, sqluser, sqlpass);
samp_mysql_select_db(sqldb);
if(samp_mysql_ping()==0)
{
print("MYSQL: Reconnection successful. We can continue as normal.");
return 1;
}
else
{
print("MYSQL: Could not reconnect to server, terminating server...");
SendRconCommand("exit");
return 0;
}
}
}

public MySQLDisconnect() // by Luk0r
{
samp_mysql_close();
return 1;
}

public MySQLCheckConnection() // by Luk0r
{
if(samp_mysql_ping()==0)
{
return 1;
}
else
{
print("MYSQL: Connection seems dead, retrying...");
MySQLDisconnect();
MySQLConnect(MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQ L_DB);
if(samp_mysql_ping()==0)
{
print("MYSQL: Reconnection successful. We can continue as normal.");
return 1;
}
else
{
print("MYSQL: Could not reconnect to server, terminating server...");
SendRconCommand("exit");
return 0;
}
}
}

public MySQLUpdatePlayerInt(query[], sqlplayerid, sqlvalname[], sqlupdateint) // by Luk0r
{
MySQLUpdateBuild(query, sqlplayerid);
new updval[64];
format(updval, sizeof(updval), "%s=%d", sqlvalname, sqlupdateint);
strcat(query, updval, MAX_STRING);
return 1;
}

public MySQLUpdatePlayerFlo(query[], sqlplayerid, sqlvalname[], Floatqlupdateflo) // by Luk0r
{
/* new query[128];
format(query, sizeof(query), "UPDATE players SET %s=%f WHERE id=%d", sqlvalname, sqlupdateflo, sqlplayerid);
samp_mysql_query(query);*/
new flotostr[32];
format(flotostr, sizeof(flotostr), "%f", sqlupdateflo);
MySQLUpdatePlayerStr(query, sqlplayerid, sqlvalname, flotostr);
return 1;
}

public MySQLUpdatePlayerStr(query[], sqlplayerid, sqlvalname[], sqlupdatestr[]) // by Luk0r
{
MySQLUpdateBuild(query, sqlplayerid);
new escstr[128];
new updval[128];
samp_mysql_real_escape_string(sqlupdatestr, escstr);
format(updval, sizeof(updval), "%s='%s'", sqlvalname, escstr);
strcat(query, updval, MAX_STRING);
return 1;
}

public MySQLUpdateBuild(query[], sqlplayerid) // by Luk0r
{
new querylen = strlen(query);
//new querymax = sizeof(query);
new querymax = MAX_STRING;
if (querylen < 1) format(query, querymax, "UPDATE players SET ");
else if (querymax-querylen < 50) // make sure we're being safe here
{
// query is too large, send this one and reset
new whereclause[32];
format(whereclause, sizeof(whereclause), " WHERE id=%d", sqlplayerid);
strcat(query, whereclause, querymax);
samp_mysql_query(query);
format(query, querymax, "UPDATE players SET ");
}
else if (strfind(query, "=", true) != -1) strcat(query, ",", MAX_STRING);
return 1;
}

public MySQLCreateAccount(newplayersname[], newpassword[]) // by Luk0r
{
new query[128];
new sqlplyname[64];
new sqlpassword[64];
samp_mysql_real_escape_string(newplayersname, sqlplyname);
samp_mysql_real_escape_string(newpassword, sqlpassword);
format(query, sizeof(query), "INSERT INTO players (Name, Password) VALUES ('%s', '%s')", sqlplyname, sqlpassword);
samp_mysql_query(query);
new newplayersid = MySQLCheckAccount(newplayersname);
if (newplayersid != 0)
{
return newplayersid;
}
return 0;
}

public MySQLCheckAccount(sqlplayersname[]) // by Luk0r
{
new query[128];
new escstr[MAX_PLAYER_NAME];
samp_mysql_real_escape_string(sqlplayersname, escstr);
format(query, sizeof(query), "SELECT id FROM players WHERE LOWER(Name) = LOWER('%s') LIMIT 1", escstr);
samp_mysql_query(query);
samp_mysql_store_result();
if (samp_mysql_num_rows()==0)
{
return 0;
}
else
{
new strid[32];
new intid;
samp_mysql_fetch_row(strid);
intid = strval(strid);
return intid;
}
}

public MySQLCheckAccountLocked(sqlplayerid)
{
new query[64];
new lockedboolstr[4];
format(query, sizeof(query), "SELECT Locked FROM players WHERE id = %d LIMIT 1", sqlplayerid);
samp_mysql_query(query);
samp_mysql_store_result();
samp_mysql_fetch_row(lockedboolstr);
if (strval(lockedboolstr) != 0)
{
return 1;
}
return 0;
}

public MySQLFetchAcctSingle(sqlplayerid, sqlvalname[], sqlresult[])
{
new query[128];
format(query, sizeof(query), "SELECT %s FROM players WHERE id = %d LIMIT 1", sqlvalname, sqlplayerid);
samp_mysql_query(query);
samp_mysql_store_result();
if(samp_mysql_fetch_row(sqlresult)==1)
{
return 1;
}
return 0;
}

public MySQLFetchAcctRecord(sqlplayerid, sqlresult[]) // by Luk0r
{
new query[64];
format(query, sizeof(query), "SELECT * FROM players WHERE id = %d LIMIT 1", sqlplayerid);
samp_mysql_query(query);
samp_mysql_store_result();
if(samp_mysql_fetch_row(sqlresult)==1)
{
return 1;
}
return 0;
}

public MySQLAddLoginRecord(sqlplayerid, ipaddr[]) // by Luk0r
{
new query[128];
new escip[16];
samp_mysql_real_escape_string(ipaddr, escip);
format(query, sizeof(query), "INSERT INTO logins (time,ip,userid) VALUES (UNIX_TIMESTAMP(),'%s',%d)", escip, sqlplayerid);
samp_mysql_query(query);
return 1;
}

public MySQLUpdateFinish(query[], sqlplayerid) // by Luk0r
{
if (strcmp(query, "WHERE id=", false) == 0) samp_mysql_query(query);
else
{
new whereclause[32];
format(whereclause, sizeof(whereclause), " WHERE id=%d", sqlplayerid);
strcat(query, whereclause, MAX_STRING);
samp_mysql_query(query);
format(query, MAX_STRING, "UPDATE players SET ");
}
return 1;
}

public MySQLUpdatePlayerIntSingle(sqlplayerid, sqlvalname[], sqlupdateint) // by Luk0r
{
new query[128];
format(query, sizeof(query), "UPDATE players SET %s=%d WHERE id=%d", sqlvalname, sqlupdateint, sqlplayerid);
samp_mysql_query(query);
return 1;
}

public split(const strsrc[], strdest[][], delimiter)
{
new i, li;
new aNum;
new len;
while(i <= strlen(strsrc)){
if(strsrc[i]==delimiter || i==strlen(strsrc)){
len = strmid(strdest[aNum], strsrc, li, i, 12;
strdest[aNum][len] = 0;
li = i+1;
aNum++;
}
i++;
}
return 1;
}[/[pawn]
Reply
#2

How the server can fail?Show us you server_logs or something
Reply
#3

Okay, first of all nice job using the freaking PAWN tags! Oh and by the way, nobody can help you when we don't know what error you are having.

P.S. I noticed you were attempting to use MySQL; double check that the connection information is correct and that the MySQL server is turned on. Also check to make sure that the needed database is populated with the proper tables.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)