From 58ee7ae052b1ff9ebe27125c4aa72c42f2ae2291 Mon Sep 17 00:00:00 2001 From: Lorenc Pekaj Date: Tue, 1 Jan 2019 23:01:24 +1100 Subject: [PATCH] move help command to commands/cmd_help.pwn --- .../irresistible/cnr/commands/_commands.pwn | 3 +- .../irresistible/cnr/commands/cmd_help.pwn | 158 ++++++++++++++++++ gamemodes/irresistible/config/server.pwn | 1 + gamemodes/sf-cnr.pwn | 133 --------------- 4 files changed, 161 insertions(+), 134 deletions(-) create mode 100644 gamemodes/irresistible/cnr/commands/cmd_help.pwn diff --git a/gamemodes/irresistible/cnr/commands/_commands.pwn b/gamemodes/irresistible/cnr/commands/_commands.pwn index 39c9c1d..defedbd 100644 --- a/gamemodes/irresistible/cnr/commands/_commands.pwn +++ b/gamemodes/irresistible/cnr/commands/_commands.pwn @@ -13,4 +13,5 @@ #include "irresistible\cnr\commands\cmd_twitter.pwn" #include "irresistible\cnr\commands\cmd_highscores.pwn" #include "irresistible\cnr\commands\cmd_nametags.pwn" -#include "irresistible\cnr\commands\cmd_feedback.pwn" \ No newline at end of file +#include "irresistible\cnr\commands\cmd_feedback.pwn" +#include "irresistible\cnr\commands\cmd_help.pwn" \ No newline at end of file diff --git a/gamemodes/irresistible/cnr/commands/cmd_help.pwn b/gamemodes/irresistible/cnr/commands/cmd_help.pwn new file mode 100644 index 0000000..f8edca7 --- /dev/null +++ b/gamemodes/irresistible/cnr/commands/cmd_help.pwn @@ -0,0 +1,158 @@ +/* + * Irresistible Gaming (c) 2018 + * Developed by Lorenc + * Module: cnr\commands\cmd_help.pwn + * Purpose: help system for the server (requires threads to be made via UCP) + */ + +/* ** Includes ** */ +#include < YSI\y_hooks > + +/* ** Error Checking ** */ +#if !defined SERVER_HELP_API_URL + #endinput +#endif + +/* ** Forwards ** */ +forward OnHelpHTTPResponse( index, response_code, data[ ] ); + +/* ** Commands ** */ +CMD:help( playerid, params[ ] ) { + return ShowPlayerDialog( playerid, DIALOG_HELP, DIALOG_STYLE_LIST, "{FFFFFF}Help", "Server Information\nFeatures\nHelp\nF.A.Q.\nGuides\nTips n' Tricks", "Okay", "" ), 1; +} + +CMD:features( playerid, params[ ] ) { + SetPVarInt( playerid, "help_category", 1 ); + mysql_function_query( dbHandle, "SELECT `SUBJECT`,`ID`,`CATEGORY` FROM `HELP` WHERE `CATEGORY`=1 ORDER BY `SUBJECT` ASC", true, "OnFetchCategoryResponse", "dd", playerid, 1 ); + return 1; +} + +CMD:faq( playerid, params[ ] ) { + SetPVarInt( playerid, "help_category", 3 ); + mysql_function_query( dbHandle, "SELECT `SUBJECT`,`ID`,`CATEGORY` FROM `HELP` WHERE `CATEGORY`=3 ORDER BY `SUBJECT` ASC", true, "OnFetchCategoryResponse", "dd", playerid, 3 ); + return 1; +} + +CMD:tips( playerid, params[ ] ) { + SetPVarInt( playerid, "help_category", 5 ); + mysql_function_query( dbHandle, "SELECT `SUBJECT`,`ID`,`CATEGORY` FROM `HELP` WHERE `CATEGORY`=5 ORDER BY `SUBJECT` ASC", true, "OnFetchCategoryResponse", "dd", playerid, 5 ); + return 1; +} + +/* ** Hooks ** */ +hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] ) +{ + if ( dialogid == DIALOG_HELP && response ) + { + SetPVarInt( playerid, "help_category", listitem ); + mysql_function_query( dbHandle, sprintf( "SELECT `SUBJECT`,`ID`,`CATEGORY` FROM `HELP` WHERE `CATEGORY`=%d ORDER BY `SUBJECT` ASC", listitem ), true, "OnFetchCategoryResponse", "dd", playerid, listitem ); + } + else if ( dialogid == DIALOG_HELP_CATEGORY ) + { + if ( ! response ) + return cmd_help( playerid, "" ); + + if ( listitem >= 64 ) + return SendError( playerid, "Unable to process request, contact Lorenc in regards to this." ); + + new + digits[ 64 ]; + + GetPVarString( playerid, "help_ids", szBigString, sizeof( szBigString ) ); + sscanf( szBigString, "a[64]", digits ); + + //format( szNormalString, 96, "SELECT * FROM `HELP` WHERE `CATEGORY`=%d AND `ID`=%d", GetPVarInt( playerid, "help_category" ), digits[ listitem ] ); + //mysql_function_query( dbHandle, szNormalString, true, "OnFetchThreadData", "ddd", playerid, GetPVarInt( playerid, "help_category" ), digits[ listitem ] ); + + HTTP( playerid, HTTP_GET, sprintf( SERVER_HELP_API_URL # "/%d", digits[ listitem ] ), "", "OnHelpHTTPResponse" ); + } + else if ( dialogid == DIALOG_HELP_THREAD && ! response ) + { + mysql_function_query( dbHandle, sprintf( "SELECT `SUBJECT`,`ID`,`CATEGORY` FROM `HELP` WHERE `CATEGORY`=%d ORDER BY `SUBJECT` ASC", GetPVarInt( playerid, "help_category" ) ), true, "OnFetchCategoryResponse", "dd", playerid, GetPVarInt( playerid, "help_category" ) ); + return 1; + } + else if ( dialogid == DIALOG_HELP_BACK && !response ) + { + return cmd_help( playerid, "" ); + } + return 1; +} + +/* ** SQL Threads ** */ +thread OnFetchCategoryResponse( playerid, category ) +{ + new + rows = cache_get_row_count( ); + + if ( rows ) + { + new + szCategory[ 64 ]; + + erase( szLargeString ); + erase( szBigString ); + + for ( new i = 0; i < rows; i ++ ) + { + cache_get_field_content( i, "SUBJECT", szCategory ); + format( szLargeString, sizeof( szLargeString ), "%s%s\n", szLargeString, szCategory ); + + cache_get_field_content( i, "ID", szCategory ); + format( szBigString, sizeof( szBigString ), "%s %d", szBigString, strval( szCategory ) ); + } + + SetPVarString( playerid, "help_ids", szBigString ); + ShowPlayerDialog( playerid, DIALOG_HELP_CATEGORY, DIALOG_STYLE_LIST, "{FFFFFF}Help Topics", szLargeString, "Select", "Back" ); + } + else + { + ShowPlayerDialog( playerid, DIALOG_HELP_BACK, DIALOG_STYLE_LIST, "{FFFFFF}Help Topics", "{FF0000}There are no threads available.", "Close", "Back" ); + } + return 1; +} + +/*thread OnFetchThreadData( playerid, category, thread ) +{ + new + rows, fields; + + cache_get_data( rows, fields ); + if ( rows ) + { + static + RegEx: rCIP, + szSubject[ 64 ], + szContent[ 2048 ] + ; + + cache_get_field_content( 0, "CONTENT", szContent, dbHandle, sizeof( szContent ) ); + cache_get_field_content( 0, "SUBJECT", szSubject ); + + strins( szSubject, "{FFFFFF}", 0 ); + strins( szContent, "{FFFFFF}", 0 ); + + + if ( !rCIP ) + rCIP = regex_build( "(?i)<[^>]*>" ); + + regex_replace_exid( szContent, rCIP, " ", szContent, sizeof( szContent ) ); + strreplace( szContent, " ", "" ); + strreplace( szContent, "&", "" ); + strreplace( szContent, "'", "" ); + + ShowPlayerDialog( playerid, DIALOG_HELP_THREAD, DIALOG_STYLE_MSGBOX, szSubject, szContent, "Close", "Back" ); + } + else ShowPlayerDialog( playerid, DIALOG_NULL, DIALOG_STYLE_LIST, "{FFFFFF}Help Topics", "{FFFFFF}An error has occurred. Try again later.", "Okay", "" ); + return 1; +}*/ + +/* ** Callbacks ** */ +public OnHelpHTTPResponse( index, response_code, data[ ] ) +{ + if ( response_code == 200 ) { + ShowPlayerDialog( index, DIALOG_HELP_THREAD, DIALOG_STYLE_MSGBOX, "{FFFFFF}Help Topics", data, "Close", "Back" ); + } else { + ShowPlayerDialog( index, DIALOG_NULL, DIALOG_STYLE_LIST, "{FFFFFF}Help Topics", "{FFFFFF}An error has occurred. Try again later.", "Okay", "" ); + } + return 1; +} \ No newline at end of file diff --git a/gamemodes/irresistible/config/server.pwn b/gamemodes/irresistible/config/server.pwn index 22aee9f..061c1fa 100644 --- a/gamemodes/irresistible/config/server.pwn +++ b/gamemodes/irresistible/config/server.pwn @@ -24,6 +24,7 @@ /* ** Comment line to disable feature ** */ #define SERVER_RULES_URL "files.sfcnr.com/en_rules.txt" // used for /rules (cnr\features\server_rules.pwn) #define SERVER_TWITTER_FEED_URL "files.sfcnr.com/cnr_twitter.php" // used for /twitter (cnr\commands\cmd_twitter.pwn) +#define SERVER_HELP_API_URL "sfcnr.com/api/player/help" // used for /help (cnr\commands\cmd_help.pwn) #define SERVER_CHANGES_FILE "updates.txt" // used for /changes (cnr\commands\cmd_changes.pwn) /* ** Hooks ** */ diff --git a/gamemodes/sf-cnr.pwn b/gamemodes/sf-cnr.pwn index d6222c6..d48021f 100644 --- a/gamemodes/sf-cnr.pwn +++ b/gamemodes/sf-cnr.pwn @@ -85,7 +85,6 @@ new bool: False = false; public OnPlayerDriveVehicle( playerid, vehicleid ); public OnServerUpdateTimer( ); public OnServerSecondTick( ); -public OnHelpHTTPResponse( index, response_code, data[ ] ); public OnPlayerAccessEntrance( playerid, entranceid, worldid, interiorid ); public OnPlayerLoadTextdraws( playerid ); public OnPlayerUnloadTextdraws( playerid ); @@ -3796,33 +3795,6 @@ CMD:stats( playerid, params[ ] ) return 1; } -CMD:help( playerid, params[ ] ) -{ - ShowPlayerDialog( playerid, DIALOG_HELP, DIALOG_STYLE_LIST, "{FFFFFF}Help", "Server Information\nFeatures\nHelp\nF.A.Q.\nGuides\nTips n' Tricks", "Okay", "" ); - return 1; -} - -CMD:features( playerid, params[ ] ) -{ - SetPVarInt( playerid, "help_category", 1 ); - mysql_function_query( dbHandle, "SELECT `SUBJECT`,`ID`,`CATEGORY` FROM `HELP` WHERE `CATEGORY`=1 ORDER BY `SUBJECT` ASC", true, "OnFetchCategoryResponse", "dd", playerid, 1 ); - return 1; -} - -CMD:faq( playerid, params[ ] ) -{ - SetPVarInt( playerid, "help_category", 3 ); - mysql_function_query( dbHandle, "SELECT `SUBJECT`,`ID`,`CATEGORY` FROM `HELP` WHERE `CATEGORY`=3 ORDER BY `SUBJECT` ASC", true, "OnFetchCategoryResponse", "dd", playerid, 3 ); - return 1; -} - -CMD:tips( playerid, params[ ] ) -{ - SetPVarInt( playerid, "help_category", 5 ); - mysql_function_query( dbHandle, "SELECT `SUBJECT`,`ID`,`CATEGORY` FROM `HELP` WHERE `CATEGORY`=5 ORDER BY `SUBJECT` ASC", true, "OnFetchCategoryResponse", "dd", playerid, 5 ); - return 1; -} - CMD:commands( playerid, params[ ] ) return cmd_cmds( playerid, params ); CMD:cmds( playerid, params[ ] ) { @@ -6586,34 +6558,6 @@ public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] ) } else ShowAmmunationMenu( playerid ); } - if ( ( dialogid == DIALOG_HELP ) && response ) - { - SetPVarInt( playerid, "help_category", listitem ); - mysql_function_query( dbHandle, sprintf( "SELECT `SUBJECT`,`ID`,`CATEGORY` FROM `HELP` WHERE `CATEGORY`=%d ORDER BY `SUBJECT` ASC", listitem ), true, "OnFetchCategoryResponse", "dd", playerid, listitem ); - } - if ( dialogid == DIALOG_HELP_CATEGORY ) - { - if ( !response ) - return cmd_help( playerid, "" ); - - if ( listitem >= 64 ) - return SendError( playerid, "Unable to process request, contact Lorenc in regards to this." ); - - new - digits[ 64 ]; - - GetPVarString( playerid, "help_ids", szBigString, sizeof( szBigString ) ); - sscanf( szBigString, "a[64]", digits ); - - //format( szNormalString, 96, "SELECT * FROM `HELP` WHERE `CATEGORY`=%d AND `ID`=%d", GetPVarInt( playerid, "help_category" ), digits[ listitem ] ); - //mysql_function_query( dbHandle, szNormalString, true, "OnFetchThreadData", "ddd", playerid, GetPVarInt( playerid, "help_category" ), digits[ listitem ] ); - - HTTP( playerid, HTTP_GET, sprintf( "sfcnr.com/api/player/help/%d", digits[ listitem ] ), "", "OnHelpHTTPResponse" ); - } - if ( ( dialogid == DIALOG_HELP_THREAD ) && !response ) { - mysql_function_query( dbHandle, sprintf( "SELECT `SUBJECT`,`ID`,`CATEGORY` FROM `HELP` WHERE `CATEGORY`=%d ORDER BY `SUBJECT` ASC", GetPVarInt( playerid, "help_category" ) ), true, "OnFetchCategoryResponse", "dd", playerid, GetPVarInt( playerid, "help_category" ) ); - } - if ( ( dialogid == DIALOG_HELP_BACK ) && !response ) return cmd_help( playerid, "" ); if ( ( dialogid == DIALOG_UNBAN_CLASS ) && response ) { @@ -6805,83 +6749,6 @@ public OnPlayerClickMap(playerid, Float:fX, Float:fY, Float:fZ) return 1; } -thread OnFetchCategoryResponse( playerid, category ) -{ - new - rows, fields, i = 0; - - cache_get_data( rows, fields ); - if ( rows ) - { - new - szCategory[ 64 ]; - - erase( szLargeString ); - erase( szBigString ); - - while( i < rows ) - { - cache_get_field_content( i, "SUBJECT", szCategory ); - format( szLargeString, sizeof( szLargeString ), "%s%s\n", szLargeString, szCategory ); - - cache_get_field_content( i, "ID", szCategory ); - format( szBigString, sizeof( szBigString ), "%s %d", szBigString, strval( szCategory ) ); - - i++; - } - - SetPVarString( playerid, "help_ids", szBigString ); - ShowPlayerDialog( playerid, DIALOG_HELP_CATEGORY, DIALOG_STYLE_LIST, "{FFFFFF}Help Topics", szLargeString, "Select", "Back" ); - } - else ShowPlayerDialog( playerid, DIALOG_HELP_BACK, DIALOG_STYLE_LIST, "{FFFFFF}Help Topics", "{FF0000}There are no threads available.", "Close", "Back" ); - return 1; -} - -/*public OnFetchThreadData( playerid, category, thread ); -public OnFetchThreadData( playerid, category, thread ) -{ - new - rows, fields; - - cache_get_data( rows, fields ); - if ( rows ) - { - static - RegEx: rCIP, - szSubject[ 64 ], - szContent[ 2048 ] - ; - - cache_get_field_content( 0, "CONTENT", szContent, dbHandle, sizeof( szContent ) ); - cache_get_field_content( 0, "SUBJECT", szSubject ); - - strins( szSubject, "{FFFFFF}", 0 ); - strins( szContent, "{FFFFFF}", 0 ); - - - if ( !rCIP ) - rCIP = regex_build( "(?i)<[^>]*>" ); - - regex_replace_exid( szContent, rCIP, " ", szContent, sizeof( szContent ) ); - strreplace( szContent, " ", "" ); - strreplace( szContent, "&", "" ); - strreplace( szContent, "'", "" ); - - ShowPlayerDialog( playerid, DIALOG_HELP_THREAD, DIALOG_STYLE_MSGBOX, szSubject, szContent, "Close", "Back" ); - } - else ShowPlayerDialog( playerid, DIALOG_NULL, DIALOG_STYLE_LIST, "{FFFFFF}Help Topics", "{FFFFFF}An error has occurred. Try again later.", "Okay", "" ); - return 1; -}*/ - -public OnHelpHTTPResponse( index, response_code, data[ ] ) -{ - if ( response_code == 200 ) //Did the request succeed? - ShowPlayerDialog( index, DIALOG_HELP_THREAD, DIALOG_STYLE_MSGBOX, "{FFFFFF}Help Topics", data, "Close", "Back" ); - else - ShowPlayerDialog( index, DIALOG_NULL, DIALOG_STYLE_LIST, "{FFFFFF}Help Topics", "{FFFFFF}An error has occurred. Try again later.", "Okay", "" ); - return 1; -} - public OnPlayerClickPlayer(playerid, clickedplayerid, source) { return 1;