AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Cs:s rank mysql jailbreak (https://forums.alliedmods.net/showthread.php?t=318184)

freanky 08-18-2019 13:05

Cs:s rank mysql jailbreak
 
Hi, have restarted my old jailbreak serveur with my backup. All working without my css rank mysql. Database connection is ok and is restore too with old backup.
My jailteam manager is relied with my css rank. Css rank record rank and time played for each player. When new player coming or have player less 30 mins. This player is restricted to joint ct team.
But my problem is the css rank dont update player/new player coming in my server. But read player in my database

I can paid!


Code:

public OnPluginStart()
{
        RegConsoleCmd("say", Command_Say);
        HookEvent("player_death", EventPlayerDeath);
        HookEvent("player_hurt", EventPlayerHurt);
        SQL_TConnect(LoadMySQLBase, "cssrank");
}

public LoadMySQLBase(Handle:owner, Handle:hndl, const String:error[], any:data)
{
        if (hndl == INVALID_HANDLE)
        {
                PrintToServer("Failed to connect: %s", error)
                db = INVALID_HANDLE;
                return;
        } else {
                PrintToServer("DEBUG: DatabaseInit (CONNECTED)");
        }

        db = hndl;
        decl String:query[1024];
        decl String:query2[1024];
        FormatEx(query, sizeof(query), "SET NAMES \"UTF8\"");
        SQL_TQuery(db, SQLErrorCheckCallback, query);
        FormatEx(query2, sizeof(query2), "DELETE FROM css_rank WHERE last_active <= %i", GetTime() - PLAYER_STATSOLD * 12 * 60 * 60);
        SQL_TQuery(db, SQLErrorCheckCallback, query2);
}


public OnClientAuthorized(client, const String:auth[])
{
        InitializeClient(client);
}


public InitializeClient( client )
{
        if ( !IsFakeClient(client) )
        {
                Points[client]=0;
                HeadShots[client]=0;
                userFlood[client]=0;
                userPtime[client]=GetTime();
                decl String:steamId[64];
                GetClientAuthString(client, steamId, sizeof(steamId));
                steamIdSave[client] = steamId;
                CreateTimer(1.0, initPlayerBase, client);
        }
}

public Action:initPlayerBase(Handle:timer, any:client){
                if (db != INVALID_HANDLE)
                {
                        decl String:buffer[200];
                        Format(buffer, sizeof(buffer), "SELECT * FROM css_rank WHERE steamId = '%s'", steamIdSave[client]);
                        if(DEBUG == 1){
                                PrintToServer("DEBUG: Action:initPlayerBase (%s)", buffer);
                        }
                        SQL_TQuery(db, SQLUserLoad, buffer, client);
                }
}

public EventPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{

        new victimId = GetEventInt(event, "userid");
        new attackerId = GetEventInt(event, "attacker");
       
        new victim = GetClientOfUserId(victimId);
        new attacker = GetClientOfUserId(attackerId);
       
        new nombreDeT = GetTeamClientCount(CS_TEAM_T);
        new nombreDeCT = GetTeamClientCount(CS_TEAM_CT);
        new joueursTotals = nombreDeT + nombreDeCT;
       

        if(victim != attacker && joueursTotals >= 5 && attacker > 0)
        {
                if(GetClientTeam(attacker) == CS_TEAM_CT)
                {
                        Points[attacker]++;
                }
                else if(GetClientTeam(attacker) == CS_TEAM_T)
                {
                        Points[attacker]++;
                        Points[attacker]++;
                        Points[attacker]++;
                }
        }
        else if (victim == attacker)
        {
                Suicide[victim]++;
        }
}

public EventPlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
{
        new attackerId = GetEventInt(event, "attacker");
        new hitgroup = GetEventInt(event,"hitgroup");
       
        new attacker = GetClientOfUserId(attackerId);

        if ( hitgroup == 1 )
        {
                HeadShots[attacker]++;
        }
}


public OnClientDisconnect (client)
{
        if ( !IsFakeClient(client) && userInit[client] == 1)
        {               
                if (db != INVALID_HANDLE)
                {
                        saveUser(client);
                        userInit[client] = 0;
                }
        }
}

public saveUser(client){
        if ( !IsFakeClient(client) && userInit[client] == 1)
        {               
                if (db != INVALID_HANDLE)
                {
                        new String:buffer[200];
                        Format(buffer, sizeof(buffer), "SELECT * FROM css_rank WHERE steamId = '%s'", steamIdSave[client]);
                        if(DEBUG == 1){
                                PrintToServer("DEBUG: saveUser (%s)", buffer);
                        }
                        SQL_TQuery(db, SQLUserSave, buffer, client);
                }
        }
}

public Action:Command_Say(client, args){

        decl String:text[192], String:command[64];

        new startidx = 0;

        GetCmdArgString(text, sizeof(text));

        if (text[strlen(text)-1] == '"')
        {               
                text[strlen(text)-1] = '\0';
                startidx = 1;       
        }       
        if (strcmp(command, "say2", false) == 0)

        startidx += 4;

        if (strcmp(text[startidx], "/rank", false) == 0)        {
                if(userFlood[client] != 1){
                        saveUser(client);
                        GetMyRank(client);
                        userFlood[client]=1;
                        CreateTimer(10.0, removeFlood, client);
                } else {
                        PrintToChat(client,"%cDo not flood the server!", GREEN);
                }
        } else        if (strcmp(text[startidx], "/top10", false) == 0)
        {               
                if(userFlood[client] != 1){
                        saveUser(client);
                        showTOP(client);
                        userFlood[client]=1;
                        CreateTimer(10.0, removeFlood, client);
                } else {
                        PrintToChat(client,"%cDo not flood the server!", GREEN);
                }
        }
        else        if (strcmp(text[startidx], "/headhunters", false) == 0)
        {               
                if(userFlood[client] != 1){
                        saveUser(client);
                        showTOPHeadHunter(client);
                        userFlood[client]=1;
                        CreateTimer(10.0, removeFlood, client);
                } else {
                        PrintToChat(client,"%cDo not flood the server!", GREEN);
                }
        }
        else        if (strcmp(text[startidx], "/topsuicide", false) == 0)
        {               
                if(userFlood[client] != 1){
                        saveUser(client);
                        showTOPSuicide(client);
                        userFlood[client]=1;
                        CreateTimer(10.0, removeFlood, client);
                } else {
                        PrintToChat(client,"%cDo not flood the server!", GREEN);
                }
        }
        return Plugin_Continue;
}


public Action:removeFlood(Handle:timer, any:client){
        userFlood[client]=0;
}

public GetMyRank(client){
        if (db != INVALID_HANDLE)
        {
                if(userInit[client] == 1)
                {

                        decl String:buffer[200];
                        Format(buffer, sizeof(buffer), "SELECT `points`, `headshots`, `suicide`  FROM `css_rank` WHERE `steamId` = '%s' LIMIT 1", steamIdSave[client]);
                        if(DEBUG == 1)
                        {
                                PrintToServer("DEBUG: GetMyRank (%s)", buffer);
                        }
                        SQL_TQuery(db, SQLGetMyRank, buffer, client);

                }
                else
                {

                        PrintToChat(client,"%cVous n'est pas integrer au systeme, reconnectez-vous.", GREEN);

                }
        } else {
                PrintToChat(client, "%cLe systeme de rank n'est pas en ligne.");
        }
}

public showTOP(client){

        if (db != INVALID_HANDLE)
        {
                decl String:buffer[200];
                Format(buffer, sizeof(buffer), "SELECT * FROM css_rank ORDER BY points DESC LIMIT 10");
                if(DEBUG == 1){
                        PrintToServer("DEBUG: showTOP (%s)", buffer);
                }
                SQL_TQuery(db, SQLTopShow, buffer, client);
        } else {
                PrintToChat(client, "%cLe systeme de rank n'est pas en ligne.");
        }
}

public showTOPHeadHunter(client){

        if (db != INVALID_HANDLE)
        {
                decl String:buffer[200];
                Format(buffer, sizeof(buffer), "SELECT * FROM css_rank ORDER BY headshots DESC LIMIT 10");
                if(DEBUG == 1){
                        PrintToServer("DEBUG: showTOPHeadHunter (%s)", buffer);
                }
                SQL_TQuery(db, SQLTopShowHS, buffer, client);
        } else {
                PrintToChat(client, "%cLe service n'est pas disponible.", GREEN);
        }
}

public showTOPSuicide(client){

        if (db != INVALID_HANDLE)
        {
                decl String:buffer[200];
                Format(buffer, sizeof(buffer), "SELECT * FROM css_rank ORDER BY suicide DESC LIMIT 10");
                if(DEBUG == 1){
                        PrintToServer("DEBUG: showTOPSuicide (%s)", buffer);
                }
                SQL_TQuery(db, SQLTopShowSuicide, buffer, client);
        } else {
                PrintToChat(client, "%cLe service n'est pas disponible.", GREEN);
        }
}

public TopMenu(Handle:menu, MenuAction:action, param1, param2)
{
}

// ================================================================================

public SQLErrorCheckCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
{
        if(!StrEqual("", error))
        {
                PrintToServer("Last Connect SQL Error: %s", error);
        }
}


public SQLUserLoad(Handle:owner, Handle:hndl, const String:error[], any:client){
        if(SQL_FetchRow(hndl))
        {
                decl String:name[MAX_LINE_WIDTH];
                GetClientName(client, name, sizeof(name) );

                ReplaceString(name, sizeof(name), "'", "");
                ReplaceString(name, sizeof(name), "<", "");
                ReplaceString(name, sizeof(name), "\"", "");

                decl String:buffer[512];
                Format(buffer, sizeof(buffer), "UPDATE css_rank SET nick = '%s', last_active = '%i' WHERE steamId = '%s'", name, GetTime(), steamIdSave[client]);
                if(DEBUG == 1){
                        PrintToServer("DEBUG: SQLUserLoad (%s)", buffer);
                }
                SQL_TQuery(db, SQLErrorCheckCallback, buffer);

                userInit[client] = 1;
        } else {

                decl String:name[MAX_LINE_WIDTH];
                decl String:buffer[200];

                GetClientName( client, name, sizeof(name) );

                ReplaceString(name, sizeof(name), "'", "");
                ReplaceString(name, sizeof(name), "<", "");
                ReplaceString(name, sizeof(name), "\"", "");

                Format(buffer, sizeof(buffer), "INSERT INTO css_rank (steamId, nick, last_active) VALUES('%s','%s', '%i')", steamIdSave[client], name, GetTime())
                if(DEBUG == 1){
                        PrintToServer("DEBUG: SQLUserLoad (%s)", buffer);
                }
                SQL_TQuery(db, SQLErrorCheckCallback, buffer);

                userInit[client] = 1;
        }
}

public SQLUserSave(Handle:owner, Handle:hndl, const String:error[], any:client){
        if(hndl == INVALID_HANDLE)
        {
                LogError(error);
                PrintToServer("Last Connect SQL Error: %s", error);
                return;
        }
       
        decl QueryReadRow_POINTS;
        decl QueryReadRow_HEADSHOTS;
        decl QueryReadRow_PTIME;
        decl QueryReadRow_SUICIDE;
        TimePlayed = GetTime() - userPtime[client];

        if(SQL_FetchRow(hndl))
        {
                QueryReadRow_POINTS=SQL_FetchInt(hndl,3) + Points[client];
                QueryReadRow_HEADSHOTS=SQL_FetchInt(hndl,4) + HeadShots[client];
                QueryReadRow_PTIME=SQL_FetchInt(hndl,6) + TimePlayed;
                QueryReadRow_SUICIDE=SQL_FetchInt(hndl,7) + Suicide[client];
                Points[client] = 0;
                HeadShots[client] = 0;
                userPtime[client] = GetTime();
                Suicide[client] = 0;
                decl String:buffer[512];
                Format(buffer, sizeof(buffer), "UPDATE css_rank SET Points = '%i', headshots = '%i',  played_time = '%i', suicide = '%i' WHERE steamId = '%s'", QueryReadRow_POINTS, QueryReadRow_HEADSHOTS, QueryReadRow_PTIME, QueryReadRow_SUICIDE, steamIdSave[client])
               
                if(DEBUG == 1){
                        PrintToServer("DEBUG: SQLUserSave (%s)", buffer);
                }

                SQL_TQuery(db, SQLErrorCheckCallback, buffer);
        }

}

public SQLGetMyRank(Handle:owner, Handle:hndl, const String:error[], any:client){
        if(hndl == INVALID_HANDLE)
        {
                LogError(error);
                PrintToServer("Last Connect SQL Error: %s", error);
                return;
        }
   
        decl RApoints;
        decl RAheadshots;
        decl RAsuicide;

        if(SQL_FetchRow(hndl))
        {
                RApoints=SQL_FetchInt(hndl, 0);
                RAheadshots=SQL_FetchInt(hndl, 1);
                RAsuicide=SQL_FetchInt(hndl, 2);
                decl String:buffer[512];
                //test
                // 0.00027144
                //STEAM_0:1:13462423
                Format(buffer, sizeof(buffer), "SELECT rank_id FROM `css_rank` WHERE (`points` > 0) AND (`points`) > (SELECT ((`points`)) FROM `css_rank` WHERE steamId = '%s' LIMIT 1) AND `steamId` != '%s' ORDER BY points DESC", steamIdSave[client], steamIdSave[client]);
                if(DEBUG == 1){
                        PrintToServer("DEBUG: SQLGetMyRank (%s)", buffer);
                }
               
                SQL_TQuery(db, SQLShowRank, buffer, client);
               
                new nombreDeT = GetTeamClientCount(CS_TEAM_T);
                new nombreDeCT = GetTeamClientCount(CS_TEAM_CT);
                new joueursTotals = nombreDeT + nombreDeCT;
               
                if (joueursTotals >= 5)
                {
                PrintToChat(client,"%cPoints: %i || Headshots: %i || Suicide: %i",GREEN, RApoints, RAheadshots, RAsuicide);
                }
                else
                {
                PrintToChat(client,"%cPoints: %i || Headshots: %i  Attention, trop peu de personnes pour sauvegarder les points, besoin de 5+",GREEN, RApoints, RAheadshots);
                }
        }
        else {
                PrintToChat(client, "%cRank non disponible", GREEN);
        }
}

Code:

compile error
/home/groups/sourcemod/upload_tmp/phpYpoq8C.sp(143) : warning 234: symbol "GetClientAuthString" is marked as deprecated: Use GetClientAuthId

/home/groups/sourcemod/upload_tmp/phpYpoq8C.sp(527) : warning 219: local variable "Panel" shadows a variable at a preceding level
/home/groups/sourcemod/upload_tmp/phpYpoq8C.sp(575) : warning 219: local variable "Panel" shadows a variable at a preceding level
/home/groups/sourcemod/upload_tmp/phpYpoq8C.sp(584) : warning 203: symbol is never used: "textime"
/home/groups/sourcemod/upload_tmp/phpYpoq8C.sp(583) : warning 203: symbol is never used: "ptimed"
/home/groups/sourcemod/upload_tmp/phpYpoq8C.sp(625) : warning 219: local variable "Panel" shadows a variable at a preceding level
/home/groups/sourcemod/upload_tmp/phpYpoq8C.sp(634) : warning 203: symbol is never used: "textime"
/home/groups/sourcemod/upload_tmp/phpYpoq8C.sp(633) : warning 203: symbol is never used: "ptimed"
/home/groups/sourcemod/upload_tmp/phpYpoq8C.sp(698) : warning 203: symbol is never used: "PrintQueryData"



All times are GMT -4. The time now is 12:50.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.