From 8d25432f6e8e93553795526f41ac7f3ad12b41e6 Mon Sep 17 00:00:00 2001 From: Lorenc Pekaj Date: Sun, 23 Dec 2018 00:06:42 +1100 Subject: [PATCH] made a start on auth modulization but WIP --- gamemodes/irresistible/README.md | 4 +- gamemodes/irresistible/cnr/_cnr.pwn | 1 + gamemodes/irresistible/cnr/auth/_auth.pwn | 9 ++ gamemodes/irresistible/cnr/auth/login.pwn | 27 ++++++ .../irresistible/cnr/features/cop/jail.pwn | 94 +++++++++++++++++++ gamemodes/sf-cnr.pwn | 94 ------------------- 6 files changed, 134 insertions(+), 95 deletions(-) create mode 100644 gamemodes/irresistible/cnr/auth/_auth.pwn create mode 100644 gamemodes/irresistible/cnr/auth/login.pwn diff --git a/gamemodes/irresistible/README.md b/gamemodes/irresistible/README.md index fe45e2e..49bfc5b 100644 --- a/gamemodes/irresistible/README.md +++ b/gamemodes/irresistible/README.md @@ -52,7 +52,9 @@ - Called when a player is unloading textdraws (on death, request class...) - `OnPlayerC4Blown( playerid, Float: X, Float: Y, Float: Z, worldid )` - Called when a player C4 is blown +- `OnPlayerJailed( playerid )` + - Called when a player is jailed - `OnPlayerUnjailed( playerid, reasonid )` - Called when a player is unjailed for a reason id -- ` OnPlayerArrested( playerid, victimid, totalarrests, totalpeople )` +- `OnPlayerArrested( playerid, victimid, totalarrests, totalpeople )` - Called when a player is arrested \ No newline at end of file diff --git a/gamemodes/irresistible/cnr/_cnr.pwn b/gamemodes/irresistible/cnr/_cnr.pwn index 78fedc3..f826418 100644 --- a/gamemodes/irresistible/cnr/_cnr.pwn +++ b/gamemodes/irresistible/cnr/_cnr.pwn @@ -20,6 +20,7 @@ #include "irresistible\cnr\wanted_level.pwn" // reliant on core definitions +#include "irresistible\cnr\auth\_auth.pwn" #include "irresistible\cnr\vip\_vip.pwn" #include "irresistible\cnr\jobs.pwn" #include "irresistible\cnr\experience.pwn" diff --git a/gamemodes/irresistible/cnr/auth/_auth.pwn b/gamemodes/irresistible/cnr/auth/_auth.pwn new file mode 100644 index 0000000..466ea7e --- /dev/null +++ b/gamemodes/irresistible/cnr/auth/_auth.pwn @@ -0,0 +1,9 @@ +/* + * Irresistible Gaming (c) 2018 + * Developed by Lorenc + * Module: cnr\vip\_vip.pwn + * Purpose: encloses all authentication modules & components (cnr) + */ + +/* ** Includes ** */ +#include "irresistible\cnr\auth\login.pwn" diff --git a/gamemodes/irresistible/cnr/auth/login.pwn b/gamemodes/irresistible/cnr/auth/login.pwn new file mode 100644 index 0000000..25fba23 --- /dev/null +++ b/gamemodes/irresistible/cnr/auth/login.pwn @@ -0,0 +1,27 @@ +/* + * Irresistible Gaming (c) 2018 + * Developed by Lorenc + * Module: cnr\auth\login.pwn + * Purpose: module associated with login componenets + */ + +/* ** Includes ** */ +#include < YSI\y_hooks > + +/* ** Definitions ** */ + +/* ** Variables ** */ + +/* ** Hooks ** */ +hook OnPlayerText( playerid, text[ ] ) +{ + if ( GetPlayerScore( playerid ) < 10 ) + return SendServerMessage( playerid, "You need at least 10 score to talk. "COL_GREY"Use /ask or /report to talk to an admin in the meanwhile." ), Y_HOOKS_BREAK_RETURN_1; + + if ( ! IsPlayerLoggedIn( playerid ) ) + return SendError( playerid, "You must be logged in to talk." ), Y_HOOKS_BREAK_RETURN_1; + + return Y_HOOKS_CONTINUE_RETURN_1; +} + +/* ** Functions ** */ diff --git a/gamemodes/irresistible/cnr/features/cop/jail.pwn b/gamemodes/irresistible/cnr/features/cop/jail.pwn index 23240e8..8f4678f 100644 --- a/gamemodes/irresistible/cnr/features/cop/jail.pwn +++ b/gamemodes/irresistible/cnr/features/cop/jail.pwn @@ -37,6 +37,10 @@ static stock g_alcatrazTimestamp = 0 ; +/* ** Forwards ** */ +forward OnPlayerJailed( playerid ); +forward OnPlayerUnjailed( playerid, reasonid ); + /* ** Hooks ** */ hook OnPlayerEnterDynamicCP( playerid, checkpointid ) { if ( IsPlayerJailed( playerid ) ) { @@ -192,6 +196,96 @@ CMD:pdjail( playerid, params[ ] ) } /* ** Functions ** */ +stock JailPlayer( playerid, seconds, admin = 0 ) +{ + if ( playerid == INVALID_PLAYER_ID ) + return 0; + + static + Query[ 72 ], Float: armour; + + // Neccessary Checks + if ( IsPlayerInMethlab( playerid ) ) { + haltMethamphetamine( playerid, GetPlayerMethLabVehicle( playerid ) ); + } + + // Callback + CallLocalFunction( "OnPlayerJailed", "d", playerid ); + + // Neccessary Functions + KillTimer ( p_JailTimer[ playerid ] ); + KillTimer ( p_CuffAbuseTimer[ playerid ] ); + PlayerTextDrawSetString ( playerid, p_JailTimeTD[ playerid ], "_" ); + PlayerTextDrawShow ( playerid, p_JailTimeTD[ playerid ] ); + + // External Variables to Jail (resetting) + p_TicketIssuer [ playerid ] = INVALID_PLAYER_ID; // Reset Tickets + p_TicketTimestamp [ playerid ] = 0; // Reset Tickets + p_Cuffed { playerid } = false; + p_InfectedHIV { playerid } = false; + //p_Detained { playerid } = false; + //Delete3DTextLabel ( p_DetainedLabel[ playerid ] ); + //p_DetainedLabel [ playerid ] = Text3D: INVALID_3DTEXT_ID; + //p_DetainedBy [ playerid ] = INVALID_PLAYER_ID; + + // Primary Jail Variables + p_Jailed { playerid } = true; + p_JailTime [ playerid ] = seconds; + p_AdminJailed { playerid } = admin; + p_JailTimer [ playerid ] = SetTimerEx( "Unjail", 950, true, "d", playerid ); + + CancelEdit ( playerid ); + RemovePlayerStolensFromHands( playerid ); + StopPlayerUsingSlotMachine ( playerid ); + RemoveEquippedOre ( playerid ); + ClearPlayerWantedLevel ( playerid ); + ResetPlayerWeapons ( playerid ); + UntiePlayer ( playerid ); + jailDoors ( playerid, false, true ); + SetPlayerPosToPrison ( playerid ); + Player_CheckPokerGame ( playerid, "Jailed" ); + + // External Functions + SetPlayerSpecialAction ( playerid, SPECIAL_ACTION_NONE ); + ClearAnimations ( playerid ); + RemovePlayerAttachedObject ( playerid, 2 ); + SetPlayerHealth ( playerid, INVALID_PLAYER_ID ); + + if ( ! IsPlayerAdminJailed( playerid ) ) { + if ( p_MetalMelter[ playerid ] ) { + ShowPlayerHelpDialog( playerid, 4000, "You can break yourself out of prison with ~p~/breakout." ); + } else { + ShowPlayerHelpDialog( playerid, 4000, "You can buy metal melters at Supa Save or a 24/7 store." ); + } + } + + format( Query, sizeof( Query ), "UPDATE `USERS` SET JAIL_TIME=%d,JAIL_ADMIN=%d WHERE `ID`=%d", seconds, admin, p_AccountID[ playerid ] ); + mysql_single_query( Query ); + + if ( GetPlayerArmour( playerid, armour ) && armour ) { + SetPlayerArmour( playerid, 0.0 ); + } + return 1; +} + +function Unjail( playerid ) +{ + static + Query[ 64 ]; + + if ( !IsPlayerConnected( playerid ) ) return KillTimer( p_JailTimer[ playerid ] ), 0; + + p_JailTime[ playerid ] --; + + format( Query, sizeof( Query ), "Time Remaining:~n~%d seconds", p_JailTime[ playerid ] ); + PlayerTextDrawSetString( playerid, p_JailTimeTD[ playerid ], Query ); + + if ( p_JailTime[ playerid ] < 1 ) + CallLocalFunction( "OnPlayerUnjailed", "dd", playerid, 0 ); + + return 1; +} + stock SetPlayerPosToPrison( playerid ) { static const diff --git a/gamemodes/sf-cnr.pwn b/gamemodes/sf-cnr.pwn index ab4bd01..02af665 100644 --- a/gamemodes/sf-cnr.pwn +++ b/gamemodes/sf-cnr.pwn @@ -90,7 +90,6 @@ public OnServerSecondTick( ); public OnHelpHTTPResponse( index, response_code, data[ ] ); public OnRulesHTTPResponse( index, response_code, data[ ] ); public OnTwitterHTTPResponse( index, response_code, data[ ] ); -public OnPlayerUnjailed( playerid, reasonid ); public OnPlayerAccessEntrance( playerid, entranceid, worldid, interiorid ); main() @@ -2011,12 +2010,6 @@ public OnPlayerText( playerid, text[ ] ) new time = g_iTime; - if ( GetPlayerScore( playerid ) < 10 ) - return SendServerMessage( playerid, "You need at least 10 score to talk. "COL_GREY"Use /ask or /report to talk to an admin in the meanwhile." ), 0; - - if ( !p_PlayerLogged{ playerid } ) - return SendError( playerid, "You must be logged in to talk." ), 0; - if ( textContainsIP( text ) ) return SendServerMessage( playerid, "Please do not advertise." ), 0; @@ -7794,98 +7787,11 @@ public OnPlayerClickPlayer(playerid, clickedplayerid, source) ///////////////////////// // Functions // ///////////////////////// - stock SetServerRule( const rule[ ], const value[ ] ) { return SendRconCommand( sprintf( "%s %s", rule, value ) ); } -stock JailPlayer( playerid, seconds, admin = 0 ) -{ - if ( playerid == INVALID_PLAYER_ID ) - return 0; - - static - Query[ 72 ], Float: armour - ; - - // Neccessary Checks - if ( IsPlayerInMethlab( playerid ) ) - haltMethamphetamine( playerid, GetPlayerMethLabVehicle( playerid ) ); - - // Neccessary Functions - KillTimer ( p_JailTimer[ playerid ] ); - KillTimer ( p_CuffAbuseTimer[ playerid ] ); - PlayerTextDrawSetString ( playerid, p_JailTimeTD[ playerid ], "_" ); - PlayerTextDrawShow ( playerid, p_JailTimeTD[ playerid ] ); - - // External Variables to Jail (resetting) - p_TicketIssuer [ playerid ] = INVALID_PLAYER_ID; // Reset Tickets - p_TicketTimestamp [ playerid ] = 0; // Reset Tickets - p_Cuffed { playerid } = false; - //p_Detained { playerid } = false; - p_InfectedHIV { playerid } = false; - //Delete3DTextLabel ( p_DetainedLabel[ playerid ] ); - //p_DetainedLabel [ playerid ] = Text3D: INVALID_3DTEXT_ID; - //p_DetainedBy [ playerid ] = INVALID_PLAYER_ID; - - // Primary Jail Variables - p_Jailed { playerid } = true; - p_JailTime [ playerid ] = seconds; - p_AdminJailed { playerid } = admin; - p_JailTimer [ playerid ] = SetTimerEx( "Unjail", 950, true, "d", playerid ); - - CancelEdit ( playerid ); - RemovePlayerStolensFromHands( playerid ); - StopPlayerUsingSlotMachine ( playerid ); - RemoveEquippedOre ( playerid ); - ClearPlayerWantedLevel ( playerid ); - ResetPlayerWeapons ( playerid ); - UntiePlayer ( playerid ); - jailDoors ( playerid, false, true ); - SetPlayerPosToPrison ( playerid ); - Player_CheckPokerGame ( playerid, "Jailed" ); - - // External Functions - SetPlayerSpecialAction ( playerid, SPECIAL_ACTION_NONE ); - ClearAnimations ( playerid ); - RemovePlayerAttachedObject ( playerid, 2 ); - SetPlayerHealth ( playerid, INVALID_PLAYER_ID ); - - if ( !IsPlayerAdminJailed( playerid ) ) - { - if ( p_MetalMelter[ playerid ] ) - ShowPlayerHelpDialog( playerid, 4000, "You can break yourself out of prison with ~p~/breakout." ); - else - ShowPlayerHelpDialog( playerid, 4000, "You can buy metal melters at Supa Save or a 24/7 store." ); - } - - format( Query, sizeof( Query ), "UPDATE `USERS` SET JAIL_TIME=%d,JAIL_ADMIN=%d WHERE `ID`=%d", seconds, admin, p_AccountID[ playerid ] ); - mysql_single_query( Query ); - - if ( GetPlayerArmour( playerid, armour ) && armour ) - SetPlayerArmour( playerid, 0.0 ); - return 1; -} - -function Unjail( playerid ) -{ - static - Query[ 64 ]; - - if ( !IsPlayerConnected( playerid ) ) return KillTimer( p_JailTimer[ playerid ] ), 0; - - p_JailTime[ playerid ] --; - - format( Query, sizeof( Query ), "Time Remaining:~n~%d seconds", p_JailTime[ playerid ] ); - PlayerTextDrawSetString( playerid, p_JailTimeTD[ playerid ], Query ); - - if ( p_JailTime[ playerid ] < 1 ) - CallLocalFunction( "OnPlayerUnjailed", "dd", playerid, 0 ); - - return 1; -} - stock SavePlayerData( playerid, bool: logout = false ) { static