Advertisement
Guest User

plainte plaintif csgo

a guest
Nov 27th, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 15.55 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #include <morecolors>
  4. #include <smlib>
  5.  
  6.  
  7. #define PLUGIN_NAME         "plainte_se"
  8. #define PLUGIN_AUTHOR       "Dertione"
  9. #define PLUGIN_DESCRIPTION  "susteme plainte pour jailbreak"
  10. #define PLUGIN_VERSION      "0.1"
  11. #define PLUGIN_URL          "http://www.supreme-elite.fr/"
  12. #define DATABASE_NAME "dertione"
  13.  
  14. new g_IsWaitingForChatReason[MAXPLAYERS+1];
  15. new Handle:g_hTimerPlainte[MAXPLAYERS+1];
  16. new Handle:g_hDatabase = INVALID_HANDLE;
  17.  
  18. public Plugin:myinfo =
  19. {
  20.     name        = PLUGIN_NAME,
  21.     author      = PLUGIN_AUTHOR,
  22.     description = PLUGIN_DESCRIPTION,
  23.     version     = PLUGIN_VERSION,
  24.     url         = PLUGIN_URL,
  25. };
  26.  
  27. public OnClientPutInServer(client)
  28. {
  29.     g_IsWaitingForChatReason[client] = false;
  30.     g_hTimerPlainte[client] = CreateTimer(60.0, Timer_Plainte, client, TIMER_REPEAT);
  31. }
  32.  
  33. public OnClientDisconnect(client)
  34. {
  35.     if (g_hTimerPlainte[client] != INVALID_HANDLE)
  36.     {
  37.         KillTimer(g_hTimerPlainte[client])
  38.         g_hTimerPlainte[client] = INVALID_HANDLE
  39.     }
  40. }
  41.  
  42. public OnPluginStart()
  43. {
  44.     RegConsoleCmd("plainte", Command_Plainte, "", 0);
  45.     RegConsoleCmd("say", Command_Say);
  46.     RegConsoleCmd("say_team", Command_Say);
  47. }
  48.  
  49. public OnMapStart()
  50. {
  51.     ConnectBDD();
  52.     //PrecacheSound("supremeelite/beep.mp3", true);
  53.     //AddFileToDownloadsTable("sound/supremeelite/beep.mp3");
  54. }
  55.  
  56. public OnMapEnd()
  57. {
  58.     new Handle:hQuery = INVALID_HANDLE;
  59.     new String:sQuery[255];
  60.     if(CheckSQL())
  61.     {
  62.         // Requete SQL
  63.         Format(sQuery, sizeof(sQuery), "TRUNCATE TABLE `plainte_se`");
  64.         hQuery = SQL_Query(g_hDatabase, sQuery);
  65.         CloseHandle(hQuery);
  66.     }
  67.     DisconnectSQL();
  68. }
  69.  
  70. public Action:Timer_Plainte(Handle:timer, any:client)
  71. {
  72.     CPrintToChat(client, "\x01\x0B\x02[Plainte-SE] \x06 Toute plainte devra passer par la commande /plainte ou !plainte");
  73.     CPrintToChat(client, "\x01\x0B\x02[Plainte-SE] \x06 Pour compléter votre plainte, il suffit d'écrire dans le chat le supplément");
  74.     CPrintToChat(client, "\x01\x0B\x02[Plainte-SE] \x06 Si aucune information supplémentaire n'est écrite, votre plainte ne sera pas traitée !");
  75. }
  76.  
  77. public Action:Command_Plainte(client, args)
  78. {
  79.     new Handle:hQuery = INVALID_HANDLE;
  80.     new String:sQuery[255];
  81.     new Handle:menu = CreateMenu(MenuHandler_DebutPlainte);
  82.     new String:sAuth[20];
  83.     if(GetClientAuthString(client, sAuth, sizeof(sAuth)) == false)
  84.     {
  85.         ThrowNativeError(2, "User auth ID not availlable yet, please try later.");
  86.     }
  87.     if(CheckSQL())
  88.     {
  89.         // Requete SQL
  90.         Format(sQuery, sizeof(sQuery), "SELECT `name_plaignant` FROM `plainte_se` WHERE `authid_plaignant`='%s' ", sAuth);
  91.         hQuery = SQL_Query(g_hDatabase, sQuery);
  92.         if(g_hDatabase == INVALID_HANDLE)
  93.         {
  94.             LogError("Query failed! ");
  95.         }
  96.         else if(!SQL_GetRowCount(hQuery))
  97.         {
  98.             SetMenuTitle(menu, "Plainte menu");
  99.            
  100.            
  101.             AddMenuItem(menu, "0", "Nouvelle Plainte");
  102.             AddMenuItem(menu, "1", "Annuler");
  103.             SetMenuExitBackButton(menu, true);
  104.            
  105.             DisplayMenu(menu, client, MENU_TIME_FOREVER);
  106.         }
  107.         else
  108.         {
  109.             CPrintToChat(client, "\x01\x0B\x02[Plainte-SE] \x06 Une plainte est deja en cours, veuillez attendre que celle-ci soit regle !");
  110.             CloseHandle(menu);
  111.         }
  112.     }
  113.     else
  114.     {
  115.         DisconnectSQL();
  116.     }
  117.     CloseHandle(hQuery);
  118. }
  119.  
  120.  
  121. public MenuHandler_DebutPlainte(Handle:menu, MenuAction:action, client, param2)
  122. {
  123.     new Handle:hQuery = INVALID_HANDLE;
  124.     new String:sQuery[255];
  125.     if (action == MenuAction_Cancel)
  126.     {
  127.  
  128.     }
  129.     else if (action == MenuAction_Select)
  130.     {
  131.         decl String:info[32];
  132.  
  133.         GetMenuItem(menu, param2, info, sizeof(info));
  134.         if(param2==0)
  135.         {
  136.             DisplayBanTypeMenu(client);
  137.             new String:sAuth[20];
  138.             new String:szClientName[50];
  139.             new String:szClientNameSQL[50];
  140.             GetClientName(client, szClientName, sizeof(szClientName));
  141.             SQL_EscapeString(g_hDatabase, szClientName, szClientNameSQL, sizeof(szClientNameSQL));
  142.             if(GetClientAuthString(client, sAuth, sizeof(sAuth)) == false)
  143.             {
  144.                 ThrowNativeError(2, "User auth ID not availlable yet, please try later.");
  145.             }
  146.             //determination de l'heure de la plainte
  147.             new String:buffer[20];
  148.             FormatTime(buffer, sizeof(buffer), "%H", GetTime());
  149.             new String:hour[10];
  150.             Format(hour, 10, buffer);
  151.             FormatTime(buffer, sizeof(buffer), "%M", GetTime());
  152.             new String:minute[10];
  153.             Format(minute, 10, buffer);
  154.             Format(buffer, 20, "%s%s00", hour, minute);
  155.             if(CheckSQL())
  156.             {
  157.                 // Requete SQL
  158.                 Format(sQuery, sizeof(sQuery), "INSERT INTO `plainte_se` (`authid_plaignant`, `name_plaignant`, `authid_freekilleur`, `name_freekilleur`, `type`, `lieu`, `info`, `date`) VALUES ('%s', '%s', '0', '0', '0', '0', '0', '%s')", sAuth, szClientNameSQL, buffer);
  159.                 hQuery = SQL_Query(g_hDatabase, sQuery);
  160.             }
  161.             else
  162.             {
  163.                 DisconnectSQL();
  164.             }
  165.             CloseHandle(hQuery);
  166.         }
  167.         else if(param2==1)
  168.         {
  169.  
  170.         }
  171.     }
  172. }
  173.  
  174. DisplayBanTypeMenu(client)
  175. {
  176.     new Handle:menu2 = CreateMenu(MenuHandler_Type);
  177.     /* :TODO: we should either remove this or make it configurable */
  178.     AddMenuItem(menu2, "Freekill", "Freekill");
  179.     AddMenuItem(menu2, "Freeshot", "Freeshot");
  180.     AddMenuItem(menu2, "Insulte", "Insulte");
  181.     AddMenuItem(menu2, "Autre", "Autre");
  182.     SetMenuTitle(menu2, "Type de plainte");
  183.     SetMenuExitBackButton(menu2, true);
  184.     DisplayMenu(menu2, client, MENU_TIME_FOREVER);
  185. }
  186.  
  187. public MenuHandler_Type(Handle:menu, MenuAction:action, client, param2)
  188. {
  189.     new Handle:hQuery = INVALID_HANDLE;
  190.     new String:sQuery[255];
  191.     if (action == MenuAction_End)
  192.     {
  193.         new String:steamid_plaignant[20];
  194.         if(IsClientInGame(client))
  195.         {
  196.             GetClientAuthString(client, steamid_plaignant,20);
  197.             if(CheckSQL())
  198.             {
  199.                 Format(sQuery, sizeof(sQuery), "DELETE FROM plainte_se WHERE authid_plaignant='%s'", steamid_plaignant);
  200.                 hQuery = SQL_Query(g_hDatabase, sQuery);CloseHandle(hQuery);
  201.             }
  202.             else
  203.             {
  204.                 DisconnectSQL();
  205.             }
  206.         }
  207.         CloseHandle(hQuery);
  208.        
  209.         CloseHandle(menu);
  210.     }
  211.     else if (action == MenuAction_Cancel)
  212.     {
  213.         new String:steamid_plaignant[20];
  214.        
  215.         GetClientAuthString(client, steamid_plaignant,20);
  216.         if(CheckSQL())
  217.         {
  218.             Format(sQuery, sizeof(sQuery), "DELETE FROM plainte_se WHERE authid_plaignant='%s'", steamid_plaignant);
  219.             hQuery = SQL_Query(g_hDatabase, sQuery);CloseHandle(hQuery);
  220.         }
  221.         else
  222.         {
  223.             DisconnectSQL();
  224.         }
  225.         CloseHandle(hQuery);
  226.     }
  227.     else if (action == MenuAction_Select)
  228.     {
  229.         decl String:info[50];
  230.         DisplayBanClientMenu(client);
  231.         GetMenuItem(menu, param2, info, sizeof(info));
  232.         new String:steamid_plaignant[20];
  233.         new String:szClientNameSQL[50];
  234.         new String:szClientTypeSQL[50];
  235.        
  236.         GetClientAuthString(client, steamid_plaignant,20);
  237.        
  238.         SQL_EscapeString(g_hDatabase, info, szClientTypeSQL, sizeof(szClientTypeSQL));
  239.         SQL_EscapeString(g_hDatabase, steamid_plaignant, szClientNameSQL, sizeof(szClientNameSQL));
  240.         if(CheckSQL())
  241.         {
  242.             Format(sQuery, sizeof(sQuery), "UPDATE `plainte_se` SET `type`='%s' WHERE `authid_plaignant`='%s'",
  243.             szClientTypeSQL, steamid_plaignant);
  244.             hQuery = SQL_Query(g_hDatabase, sQuery);
  245.         }
  246.         else
  247.         {
  248.             DisconnectSQL();
  249.         }
  250.         CloseHandle(hQuery);
  251.        
  252.     }
  253. }
  254.  
  255.  
  256.  
  257. DisplayBanClientMenu(client)
  258. {
  259.     new Handle:menu2 = CreateMenu(MenuHandler_Freekilleur);
  260.  
  261.     decl String:sUserId[12];
  262.     decl String:sName[MAX_NAME_LENGTH];
  263.     decl String:sDisplay[MAX_NAME_LENGTH+15];
  264.     /* :TODO: we should either remove this or make it configurable */
  265.     for (new i = 1; i <= MaxClients; i++)
  266.     {
  267.         if (IsClientInGame(i) && !IsFakeClient(i) && GetClientTeam(i)==3)
  268.         {
  269.             IntToString(GetClientUserId(i), sUserId, sizeof(sUserId));    
  270.             GetClientName(i, sName, sizeof(sName));
  271.             Format(sDisplay, sizeof(sDisplay), "%s", sName);
  272.  
  273.             AddMenuItem(menu2, sUserId, sDisplay);
  274.         }
  275.     }
  276.     SetMenuTitle(menu2, "Freekilleur");
  277.     SetMenuExitBackButton(menu2, true);
  278.     DisplayMenu(menu2, client, MENU_TIME_FOREVER);
  279. }
  280.  
  281. public MenuHandler_Freekilleur(Handle:menu, MenuAction:action, client, param2)
  282. {
  283.     new Handle:hQuery = INVALID_HANDLE;
  284.     new String:sQuery[255];
  285.     if (action == MenuAction_End)
  286.     {
  287.         new String:steamid_plaignant[20];
  288.        
  289.         GetClientAuthString(client, steamid_plaignant,20);
  290.         if(CheckSQL())
  291.         {
  292.             Format(sQuery, sizeof(sQuery), "DELETE FROM plainte_se WHERE authid_plaignant='%s'", steamid_plaignant);
  293.             hQuery = SQL_Query(g_hDatabase, sQuery);
  294.            
  295.         }
  296.         else
  297.         {
  298.             DisconnectSQL();
  299.         }
  300.         CloseHandle(hQuery);
  301.         CloseHandle(menu);
  302.     }
  303.     else if (action == MenuAction_Cancel)
  304.     {
  305.         new String:steamid_plaignant[20];
  306.        
  307.         GetClientAuthString(client, steamid_plaignant,20);
  308.         if(CheckSQL())
  309.         {
  310.             Format(sQuery, sizeof(sQuery), "DELETE FROM plainte_se WHERE authid_plaignant='%s'", steamid_plaignant);
  311.             hQuery = SQL_Query(g_hDatabase, sQuery);
  312.         }
  313.         else
  314.         {
  315.             DisconnectSQL();
  316.         }
  317.         CloseHandle(hQuery);
  318.     }
  319.     else if (action == MenuAction_Select)
  320.     {
  321.         decl String:info[50];
  322.         DisplayBanLieuMenu(client);
  323.         GetMenuItem(menu, param2, info, sizeof(info));
  324.         new userid_freekilleur = StringToInt(info);
  325.         new freekilleur = GetClientOfUserId(userid_freekilleur);
  326.         new String:steamid_plaignant[20];
  327.         new String:steamid_freekilleur[20];
  328.         new String:name_freekilleur[60];
  329.         new String:szClientNameSQL[50];
  330.        
  331.         GetClientAuthString(client, steamid_plaignant,20);
  332.         GetClientAuthString(freekilleur, steamid_freekilleur,20);
  333.         GetClientName(freekilleur, name_freekilleur, 60);
  334.        
  335.         SQL_EscapeString(g_hDatabase, name_freekilleur, szClientNameSQL, sizeof(szClientNameSQL));
  336.         if(CheckSQL())
  337.         {
  338.             Format(sQuery, sizeof(sQuery), "UPDATE `plainte_se` SET `authid_freekilleur`='%s', `name_freekilleur`='%s' WHERE `authid_plaignant`='%s'",
  339.             steamid_freekilleur, name_freekilleur, steamid_plaignant);
  340.             //PrintToChat(client, "%s  :  %s  :  %s", freekilleur, szClientNameSQL, steamid_plaignant);
  341.             hQuery = SQL_Query(g_hDatabase, sQuery);
  342.         }
  343.         else
  344.         {
  345.             DisconnectSQL();
  346.         }
  347.         CloseHandle(hQuery);
  348.        
  349.     }
  350. }
  351.  
  352. DisplayBanLieuMenu(client)
  353. {
  354.     new Handle:menu = CreateMenu(MenuHandler_BanLieuList);
  355.  
  356.     SetMenuTitle(menu, "Lieu du freekill");
  357.     SetMenuExitBackButton(menu, true);
  358.  
  359.     /* :TODO: we should either remove this or make it configurable */
  360.     AddMenuItem(menu, "Insulte", "Dans le chat (pour insulte)");
  361.     AddMenuItem(menu, "Piscine", "Piscine");
  362.     AddMenuItem(menu, "Armurerie", "Armurerie apres 7:30");
  363.     AddMenuItem(menu, "Jail", "Jail");
  364.     AddMenuItem(menu, "Foot", "Foot");
  365.     AddMenuItem(menu, "Disco", "Disco");
  366.     AddMenuItem(menu, "Climb", "Climb");
  367.     AddMenuItem(menu, "Simon Say", "Simon Say");
  368.     AddMenuItem(menu, "Toilette", "Toilette");
  369.     AddMenuItem(menu, "Infirmerie", "Infirmerie");
  370.     AddMenuItem(menu, "Big Jail", "Big Jail");
  371.     AddMenuItem(menu, "Refectoire", "Refectoire");
  372.     AddMenuItem(menu, "Salle des commandes", "Salle des commandes");
  373.     AddMenuItem(menu, "Isoloire", "Isoloire");
  374.     AddMenuItem(menu, "Labyrinthes", "Labyrinthes");
  375.     AddMenuItem(menu, "Jeux des canapes", "Jeux des canapes");
  376.     AddMenuItem(menu, "Jeux de course", "Jeux de course");
  377.     AddMenuItem(menu, "Autre", "Autre preciser dans le chat");
  378.  
  379.     DisplayMenu(menu, client, MENU_TIME_FOREVER);
  380. }
  381.  
  382.  
  383. public MenuHandler_BanLieuList(Handle:menu, MenuAction:action, client, param2)
  384. {
  385.     new Handle:hQuery = INVALID_HANDLE;
  386.     new String:sQuery[255];
  387.     if (action == MenuAction_End)
  388.     {
  389.         new String:steamid_plaignant[20];
  390.         if(client)
  391.         {
  392.             if(IsClientInGame(client))
  393.             {
  394.                 GetClientAuthString(client, steamid_plaignant,20);
  395.                 if(CheckSQL())
  396.                 {
  397.                     Format(sQuery, sizeof(sQuery), "DELETE FROM plainte_se WHERE authid_plaignant='%s'", steamid_plaignant);
  398.                     hQuery = SQL_Query(g_hDatabase, sQuery);
  399.                 }
  400.                 else
  401.                 {
  402.                     DisconnectSQL();
  403.                 }
  404.                 CloseHandle(hQuery);
  405.             }
  406.         }
  407.         CloseHandle(menu);
  408.     }
  409.     else if (action == MenuAction_Cancel)
  410.     {
  411.         new String:steamid_plaignant[20];
  412.        
  413.         GetClientAuthString(client, steamid_plaignant,20);
  414.         if(CheckSQL())
  415.         {
  416.             Format(sQuery, sizeof(sQuery), "DELETE FROM plainte_se WHERE authid_plaignant='%s'", steamid_plaignant);
  417.             hQuery = SQL_Query(g_hDatabase, sQuery);
  418.         }
  419.         else
  420.         {
  421.             DisconnectSQL();
  422.         }
  423.         CloseHandle(hQuery);
  424.     }
  425.     else if (action == MenuAction_Select)
  426.     {
  427.         decl String:info[40];
  428.         GetMenuItem(menu, param2, info, sizeof(info));
  429.         g_IsWaitingForChatReason[client] = true;
  430.         CPrintToChat(client, "\x01\x0B\x02[Plainte-SE] \x06  Tapez plus en details votre plainte dans le chat, ce sera enregistré, merci de patienter par la suite");
  431.         CPrintToChat(client, "\x01\x0B\x02[Plainte-SE] \x06  Tapez /annuler pour annuler votre plainte !");
  432.         new String:steamid_plaignant[20];
  433.         GetClientAuthString(client, steamid_plaignant,20);
  434.         if(CheckSQL())
  435.         {
  436.             Format(sQuery, sizeof(sQuery), "UPDATE `plainte_se` SET `lieu`='%s' WHERE `authid_plaignant`='%s'",
  437.             info, steamid_plaignant);
  438.             hQuery = SQL_Query(g_hDatabase, sQuery);
  439.         }
  440.         else
  441.         {
  442.             DisconnectSQL();
  443.         }
  444.         CloseHandle(hQuery);
  445.     }
  446. }
  447.  
  448. public Action:Command_Say(client, args)
  449. {
  450.     decl String:Cmd[128];
  451.     GetCmdArgString(Cmd, 127);
  452.     StripQuotes(Cmd);
  453.     TrimString(Cmd);
  454.     decl String:sText[192];
  455.     new Start = 0;
  456.  
  457.     GetCmdArgString(sText, sizeof(sText));
  458.  
  459.     if (sText[strlen(sText)-1] == '"')
  460.     {
  461.         sText[strlen(sText)-1] = '\0';
  462.         Start = 1;
  463.     }
  464.  
  465.     if(g_IsWaitingForChatReason[client])
  466.     {
  467.         g_IsWaitingForChatReason[client] = false;
  468.         new Handle:hQuery = INVALID_HANDLE;
  469.         new String:sQuery[255];
  470.         if (strcmp(sText[Start], "/annuler", false) == 0)
  471.         {
  472.             new String:steamid_plaignant[20];
  473.             GetClientAuthString(client, steamid_plaignant,20);
  474.             if(CheckSQL())
  475.             {
  476.                 Format(sQuery, sizeof(sQuery), "DELETE FROM plainte_se WHERE authid_plaignant='%s'", steamid_plaignant);
  477.                 hQuery = SQL_Query(g_hDatabase, sQuery);
  478.             }
  479.             else
  480.             {
  481.                 DisconnectSQL();
  482.             }
  483.             CloseHandle(hQuery);
  484.             return Plugin_Handled;
  485.         }
  486.         else
  487.         {
  488.             new String:steamid_plaignant[20];
  489.             new String:szClientNameSQL[255];
  490.             GetClientAuthString(client, steamid_plaignant,20);
  491.             SQL_EscapeString(g_hDatabase, Cmd, szClientNameSQL, sizeof(szClientNameSQL));
  492.             if(CheckSQL())
  493.             {
  494.                 Format(sQuery, sizeof(sQuery), "UPDATE `plainte_se` SET `info`='%s' WHERE `authid_plaignant`='%s'", szClientNameSQL, steamid_plaignant);
  495.                 ServerCommand("say_team @UNE PLAINTE VIENT D'ETRE POSTER !!! /listeplainte pour la voir. Merci");
  496.                 hQuery = SQL_Query(g_hDatabase, sQuery);
  497.             }
  498.             else
  499.             {
  500.                 DisconnectSQL();
  501.             }
  502.             CloseHandle(hQuery);
  503.             return Plugin_Handled;
  504.         }
  505.     }
  506.     return Plugin_Continue;
  507. }
  508.  
  509.  
  510.  
  511.  
  512. public ConnectBDD()
  513. {
  514.     // On check la config présente dans database.cfg
  515.     if (SQL_CheckConfig(DATABASE_NAME))
  516.     {
  517.         new String:error[255];
  518.         // On créé une connexion à la base de donné via la config présente dans database.cfg
  519.         g_hDatabase = SQL_Connect(DATABASE_NAME,true,error, sizeof(error));
  520.         if (g_hDatabase == INVALID_HANDLE)
  521.         {
  522.             LogMessage("Erreur de connexion: %s", error);
  523.         }
  524.         else
  525.         {
  526.             LogMessage("Connexion à la BDD MySQL réussie");
  527.         }
  528.     }
  529.     else
  530.     {
  531.         LogError("Impossible de trouvé <%s> dans le fichier databases.cfg", DATABASE_NAME);
  532.     }
  533.  
  534. }
  535.  
  536.  
  537. stock bool:DisconnectSQL()
  538. {
  539.     if(g_hDatabase != INVALID_HANDLE)
  540.     {
  541.         CloseHandle(g_hDatabase);
  542.         g_hDatabase = INVALID_HANDLE;
  543.     }
  544.    
  545.     return true;
  546. }
  547.  
  548. stock bool:CheckSQL()
  549. {
  550.     if(g_hDatabase == INVALID_HANDLE)
  551.     {
  552.         ConnectBDD();
  553.         return false ;
  554.     }
  555.    
  556.     return true;
  557. }
  558.  
  559.  
  560.  
  561.  
  562. public IsAdmin(client)
  563. {
  564.     decl String:steamId[30];
  565.     GetClientAuthString(client, steamId, sizeof(steamId));
  566.     if (GetUserFlagBits(client) & ADMFLAG_SLAY) return true;
  567.     else if (GetUserFlagBits(client) & ADMFLAG_GENERIC) return true;
  568.     else if (GetUserFlagBits(client) & ADMFLAG_BAN) return true;
  569.     else return false;
  570. }
  571.  
  572. public IsRoot(client)
  573. {
  574.     decl String:steamId[30];
  575.     GetClientAuthString(client, steamId, sizeof(steamId));
  576.     if (GetUserFlagBits(client) & ADMFLAG_ROOT) return true;
  577.     else return false;
  578. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement