Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #include <sdktools>
- #include <morecolors>
- #include <smlib>
- #define PLUGIN_NAME "plainte_se"
- #define PLUGIN_AUTHOR "Dertione"
- #define PLUGIN_DESCRIPTION "susteme plainte pour jailbreak"
- #define PLUGIN_VERSION "0.1"
- #define PLUGIN_URL "http://www.supreme-elite.fr/"
- #define DATABASE_NAME "dertione"
- new g_IsWaitingForChatReason[MAXPLAYERS+1];
- new Handle:g_hTimerPlainte[MAXPLAYERS+1];
- new Handle:g_hDatabase = INVALID_HANDLE;
- public Plugin:myinfo =
- {
- name = PLUGIN_NAME,
- author = PLUGIN_AUTHOR,
- description = PLUGIN_DESCRIPTION,
- version = PLUGIN_VERSION,
- url = PLUGIN_URL,
- };
- public OnClientPutInServer(client)
- {
- g_IsWaitingForChatReason[client] = false;
- g_hTimerPlainte[client] = CreateTimer(60.0, Timer_Plainte, client, TIMER_REPEAT);
- }
- public OnClientDisconnect(client)
- {
- if (g_hTimerPlainte[client] != INVALID_HANDLE)
- {
- KillTimer(g_hTimerPlainte[client])
- g_hTimerPlainte[client] = INVALID_HANDLE
- }
- }
- public OnPluginStart()
- {
- RegConsoleCmd("plainte", Command_Plainte, "", 0);
- RegConsoleCmd("say", Command_Say);
- RegConsoleCmd("say_team", Command_Say);
- }
- public OnMapStart()
- {
- ConnectBDD();
- //PrecacheSound("supremeelite/beep.mp3", true);
- //AddFileToDownloadsTable("sound/supremeelite/beep.mp3");
- }
- public OnMapEnd()
- {
- new Handle:hQuery = INVALID_HANDLE;
- new String:sQuery[255];
- if(CheckSQL())
- {
- // Requete SQL
- Format(sQuery, sizeof(sQuery), "TRUNCATE TABLE `plainte_se`");
- hQuery = SQL_Query(g_hDatabase, sQuery);
- CloseHandle(hQuery);
- }
- DisconnectSQL();
- }
- public Action:Timer_Plainte(Handle:timer, any:client)
- {
- CPrintToChat(client, "\x01\x0B\x02[Plainte-SE] \x06 Toute plainte devra passer par la commande /plainte ou !plainte");
- CPrintToChat(client, "\x01\x0B\x02[Plainte-SE] \x06 Pour compléter votre plainte, il suffit d'écrire dans le chat le supplément");
- CPrintToChat(client, "\x01\x0B\x02[Plainte-SE] \x06 Si aucune information supplémentaire n'est écrite, votre plainte ne sera pas traitée !");
- }
- public Action:Command_Plainte(client, args)
- {
- new Handle:hQuery = INVALID_HANDLE;
- new String:sQuery[255];
- new Handle:menu = CreateMenu(MenuHandler_DebutPlainte);
- new String:sAuth[20];
- if(GetClientAuthString(client, sAuth, sizeof(sAuth)) == false)
- {
- ThrowNativeError(2, "User auth ID not availlable yet, please try later.");
- }
- if(CheckSQL())
- {
- // Requete SQL
- Format(sQuery, sizeof(sQuery), "SELECT `name_plaignant` FROM `plainte_se` WHERE `authid_plaignant`='%s' ", sAuth);
- hQuery = SQL_Query(g_hDatabase, sQuery);
- if(g_hDatabase == INVALID_HANDLE)
- {
- LogError("Query failed! ");
- }
- else if(!SQL_GetRowCount(hQuery))
- {
- SetMenuTitle(menu, "Plainte menu");
- AddMenuItem(menu, "0", "Nouvelle Plainte");
- AddMenuItem(menu, "1", "Annuler");
- SetMenuExitBackButton(menu, true);
- DisplayMenu(menu, client, MENU_TIME_FOREVER);
- }
- else
- {
- CPrintToChat(client, "\x01\x0B\x02[Plainte-SE] \x06 Une plainte est deja en cours, veuillez attendre que celle-ci soit regle !");
- CloseHandle(menu);
- }
- }
- else
- {
- DisconnectSQL();
- }
- CloseHandle(hQuery);
- }
- public MenuHandler_DebutPlainte(Handle:menu, MenuAction:action, client, param2)
- {
- new Handle:hQuery = INVALID_HANDLE;
- new String:sQuery[255];
- if (action == MenuAction_Cancel)
- {
- }
- else if (action == MenuAction_Select)
- {
- decl String:info[32];
- GetMenuItem(menu, param2, info, sizeof(info));
- if(param2==0)
- {
- DisplayBanTypeMenu(client);
- new String:sAuth[20];
- new String:szClientName[50];
- new String:szClientNameSQL[50];
- GetClientName(client, szClientName, sizeof(szClientName));
- SQL_EscapeString(g_hDatabase, szClientName, szClientNameSQL, sizeof(szClientNameSQL));
- if(GetClientAuthString(client, sAuth, sizeof(sAuth)) == false)
- {
- ThrowNativeError(2, "User auth ID not availlable yet, please try later.");
- }
- //determination de l'heure de la plainte
- new String:buffer[20];
- FormatTime(buffer, sizeof(buffer), "%H", GetTime());
- new String:hour[10];
- Format(hour, 10, buffer);
- FormatTime(buffer, sizeof(buffer), "%M", GetTime());
- new String:minute[10];
- Format(minute, 10, buffer);
- Format(buffer, 20, "%s%s00", hour, minute);
- if(CheckSQL())
- {
- // Requete SQL
- 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);
- hQuery = SQL_Query(g_hDatabase, sQuery);
- }
- else
- {
- DisconnectSQL();
- }
- CloseHandle(hQuery);
- }
- else if(param2==1)
- {
- }
- }
- }
- DisplayBanTypeMenu(client)
- {
- new Handle:menu2 = CreateMenu(MenuHandler_Type);
- /* :TODO: we should either remove this or make it configurable */
- AddMenuItem(menu2, "Freekill", "Freekill");
- AddMenuItem(menu2, "Freeshot", "Freeshot");
- AddMenuItem(menu2, "Insulte", "Insulte");
- AddMenuItem(menu2, "Autre", "Autre");
- SetMenuTitle(menu2, "Type de plainte");
- SetMenuExitBackButton(menu2, true);
- DisplayMenu(menu2, client, MENU_TIME_FOREVER);
- }
- public MenuHandler_Type(Handle:menu, MenuAction:action, client, param2)
- {
- new Handle:hQuery = INVALID_HANDLE;
- new String:sQuery[255];
- if (action == MenuAction_End)
- {
- new String:steamid_plaignant[20];
- if(IsClientInGame(client))
- {
- GetClientAuthString(client, steamid_plaignant,20);
- if(CheckSQL())
- {
- Format(sQuery, sizeof(sQuery), "DELETE FROM plainte_se WHERE authid_plaignant='%s'", steamid_plaignant);
- hQuery = SQL_Query(g_hDatabase, sQuery);CloseHandle(hQuery);
- }
- else
- {
- DisconnectSQL();
- }
- }
- CloseHandle(hQuery);
- CloseHandle(menu);
- }
- else if (action == MenuAction_Cancel)
- {
- new String:steamid_plaignant[20];
- GetClientAuthString(client, steamid_plaignant,20);
- if(CheckSQL())
- {
- Format(sQuery, sizeof(sQuery), "DELETE FROM plainte_se WHERE authid_plaignant='%s'", steamid_plaignant);
- hQuery = SQL_Query(g_hDatabase, sQuery);CloseHandle(hQuery);
- }
- else
- {
- DisconnectSQL();
- }
- CloseHandle(hQuery);
- }
- else if (action == MenuAction_Select)
- {
- decl String:info[50];
- DisplayBanClientMenu(client);
- GetMenuItem(menu, param2, info, sizeof(info));
- new String:steamid_plaignant[20];
- new String:szClientNameSQL[50];
- new String:szClientTypeSQL[50];
- GetClientAuthString(client, steamid_plaignant,20);
- SQL_EscapeString(g_hDatabase, info, szClientTypeSQL, sizeof(szClientTypeSQL));
- SQL_EscapeString(g_hDatabase, steamid_plaignant, szClientNameSQL, sizeof(szClientNameSQL));
- if(CheckSQL())
- {
- Format(sQuery, sizeof(sQuery), "UPDATE `plainte_se` SET `type`='%s' WHERE `authid_plaignant`='%s'",
- szClientTypeSQL, steamid_plaignant);
- hQuery = SQL_Query(g_hDatabase, sQuery);
- }
- else
- {
- DisconnectSQL();
- }
- CloseHandle(hQuery);
- }
- }
- DisplayBanClientMenu(client)
- {
- new Handle:menu2 = CreateMenu(MenuHandler_Freekilleur);
- decl String:sUserId[12];
- decl String:sName[MAX_NAME_LENGTH];
- decl String:sDisplay[MAX_NAME_LENGTH+15];
- /* :TODO: we should either remove this or make it configurable */
- for (new i = 1; i <= MaxClients; i++)
- {
- if (IsClientInGame(i) && !IsFakeClient(i) && GetClientTeam(i)==3)
- {
- IntToString(GetClientUserId(i), sUserId, sizeof(sUserId));
- GetClientName(i, sName, sizeof(sName));
- Format(sDisplay, sizeof(sDisplay), "%s", sName);
- AddMenuItem(menu2, sUserId, sDisplay);
- }
- }
- SetMenuTitle(menu2, "Freekilleur");
- SetMenuExitBackButton(menu2, true);
- DisplayMenu(menu2, client, MENU_TIME_FOREVER);
- }
- public MenuHandler_Freekilleur(Handle:menu, MenuAction:action, client, param2)
- {
- new Handle:hQuery = INVALID_HANDLE;
- new String:sQuery[255];
- if (action == MenuAction_End)
- {
- new String:steamid_plaignant[20];
- GetClientAuthString(client, steamid_plaignant,20);
- if(CheckSQL())
- {
- Format(sQuery, sizeof(sQuery), "DELETE FROM plainte_se WHERE authid_plaignant='%s'", steamid_plaignant);
- hQuery = SQL_Query(g_hDatabase, sQuery);
- }
- else
- {
- DisconnectSQL();
- }
- CloseHandle(hQuery);
- CloseHandle(menu);
- }
- else if (action == MenuAction_Cancel)
- {
- new String:steamid_plaignant[20];
- GetClientAuthString(client, steamid_plaignant,20);
- if(CheckSQL())
- {
- Format(sQuery, sizeof(sQuery), "DELETE FROM plainte_se WHERE authid_plaignant='%s'", steamid_plaignant);
- hQuery = SQL_Query(g_hDatabase, sQuery);
- }
- else
- {
- DisconnectSQL();
- }
- CloseHandle(hQuery);
- }
- else if (action == MenuAction_Select)
- {
- decl String:info[50];
- DisplayBanLieuMenu(client);
- GetMenuItem(menu, param2, info, sizeof(info));
- new userid_freekilleur = StringToInt(info);
- new freekilleur = GetClientOfUserId(userid_freekilleur);
- new String:steamid_plaignant[20];
- new String:steamid_freekilleur[20];
- new String:name_freekilleur[60];
- new String:szClientNameSQL[50];
- GetClientAuthString(client, steamid_plaignant,20);
- GetClientAuthString(freekilleur, steamid_freekilleur,20);
- GetClientName(freekilleur, name_freekilleur, 60);
- SQL_EscapeString(g_hDatabase, name_freekilleur, szClientNameSQL, sizeof(szClientNameSQL));
- if(CheckSQL())
- {
- Format(sQuery, sizeof(sQuery), "UPDATE `plainte_se` SET `authid_freekilleur`='%s', `name_freekilleur`='%s' WHERE `authid_plaignant`='%s'",
- steamid_freekilleur, name_freekilleur, steamid_plaignant);
- //PrintToChat(client, "%s : %s : %s", freekilleur, szClientNameSQL, steamid_plaignant);
- hQuery = SQL_Query(g_hDatabase, sQuery);
- }
- else
- {
- DisconnectSQL();
- }
- CloseHandle(hQuery);
- }
- }
- DisplayBanLieuMenu(client)
- {
- new Handle:menu = CreateMenu(MenuHandler_BanLieuList);
- SetMenuTitle(menu, "Lieu du freekill");
- SetMenuExitBackButton(menu, true);
- /* :TODO: we should either remove this or make it configurable */
- AddMenuItem(menu, "Insulte", "Dans le chat (pour insulte)");
- AddMenuItem(menu, "Piscine", "Piscine");
- AddMenuItem(menu, "Armurerie", "Armurerie apres 7:30");
- AddMenuItem(menu, "Jail", "Jail");
- AddMenuItem(menu, "Foot", "Foot");
- AddMenuItem(menu, "Disco", "Disco");
- AddMenuItem(menu, "Climb", "Climb");
- AddMenuItem(menu, "Simon Say", "Simon Say");
- AddMenuItem(menu, "Toilette", "Toilette");
- AddMenuItem(menu, "Infirmerie", "Infirmerie");
- AddMenuItem(menu, "Big Jail", "Big Jail");
- AddMenuItem(menu, "Refectoire", "Refectoire");
- AddMenuItem(menu, "Salle des commandes", "Salle des commandes");
- AddMenuItem(menu, "Isoloire", "Isoloire");
- AddMenuItem(menu, "Labyrinthes", "Labyrinthes");
- AddMenuItem(menu, "Jeux des canapes", "Jeux des canapes");
- AddMenuItem(menu, "Jeux de course", "Jeux de course");
- AddMenuItem(menu, "Autre", "Autre preciser dans le chat");
- DisplayMenu(menu, client, MENU_TIME_FOREVER);
- }
- public MenuHandler_BanLieuList(Handle:menu, MenuAction:action, client, param2)
- {
- new Handle:hQuery = INVALID_HANDLE;
- new String:sQuery[255];
- if (action == MenuAction_End)
- {
- new String:steamid_plaignant[20];
- if(client)
- {
- if(IsClientInGame(client))
- {
- GetClientAuthString(client, steamid_plaignant,20);
- if(CheckSQL())
- {
- Format(sQuery, sizeof(sQuery), "DELETE FROM plainte_se WHERE authid_plaignant='%s'", steamid_plaignant);
- hQuery = SQL_Query(g_hDatabase, sQuery);
- }
- else
- {
- DisconnectSQL();
- }
- CloseHandle(hQuery);
- }
- }
- CloseHandle(menu);
- }
- else if (action == MenuAction_Cancel)
- {
- new String:steamid_plaignant[20];
- GetClientAuthString(client, steamid_plaignant,20);
- if(CheckSQL())
- {
- Format(sQuery, sizeof(sQuery), "DELETE FROM plainte_se WHERE authid_plaignant='%s'", steamid_plaignant);
- hQuery = SQL_Query(g_hDatabase, sQuery);
- }
- else
- {
- DisconnectSQL();
- }
- CloseHandle(hQuery);
- }
- else if (action == MenuAction_Select)
- {
- decl String:info[40];
- GetMenuItem(menu, param2, info, sizeof(info));
- g_IsWaitingForChatReason[client] = true;
- 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");
- CPrintToChat(client, "\x01\x0B\x02[Plainte-SE] \x06 Tapez /annuler pour annuler votre plainte !");
- new String:steamid_plaignant[20];
- GetClientAuthString(client, steamid_plaignant,20);
- if(CheckSQL())
- {
- Format(sQuery, sizeof(sQuery), "UPDATE `plainte_se` SET `lieu`='%s' WHERE `authid_plaignant`='%s'",
- info, steamid_plaignant);
- hQuery = SQL_Query(g_hDatabase, sQuery);
- }
- else
- {
- DisconnectSQL();
- }
- CloseHandle(hQuery);
- }
- }
- public Action:Command_Say(client, args)
- {
- decl String:Cmd[128];
- GetCmdArgString(Cmd, 127);
- StripQuotes(Cmd);
- TrimString(Cmd);
- decl String:sText[192];
- new Start = 0;
- GetCmdArgString(sText, sizeof(sText));
- if (sText[strlen(sText)-1] == '"')
- {
- sText[strlen(sText)-1] = '\0';
- Start = 1;
- }
- if(g_IsWaitingForChatReason[client])
- {
- g_IsWaitingForChatReason[client] = false;
- new Handle:hQuery = INVALID_HANDLE;
- new String:sQuery[255];
- if (strcmp(sText[Start], "/annuler", false) == 0)
- {
- new String:steamid_plaignant[20];
- GetClientAuthString(client, steamid_plaignant,20);
- if(CheckSQL())
- {
- Format(sQuery, sizeof(sQuery), "DELETE FROM plainte_se WHERE authid_plaignant='%s'", steamid_plaignant);
- hQuery = SQL_Query(g_hDatabase, sQuery);
- }
- else
- {
- DisconnectSQL();
- }
- CloseHandle(hQuery);
- return Plugin_Handled;
- }
- else
- {
- new String:steamid_plaignant[20];
- new String:szClientNameSQL[255];
- GetClientAuthString(client, steamid_plaignant,20);
- SQL_EscapeString(g_hDatabase, Cmd, szClientNameSQL, sizeof(szClientNameSQL));
- if(CheckSQL())
- {
- Format(sQuery, sizeof(sQuery), "UPDATE `plainte_se` SET `info`='%s' WHERE `authid_plaignant`='%s'", szClientNameSQL, steamid_plaignant);
- ServerCommand("say_team @UNE PLAINTE VIENT D'ETRE POSTER !!! /listeplainte pour la voir. Merci");
- hQuery = SQL_Query(g_hDatabase, sQuery);
- }
- else
- {
- DisconnectSQL();
- }
- CloseHandle(hQuery);
- return Plugin_Handled;
- }
- }
- return Plugin_Continue;
- }
- public ConnectBDD()
- {
- // On check la config présente dans database.cfg
- if (SQL_CheckConfig(DATABASE_NAME))
- {
- new String:error[255];
- // On créé une connexion à la base de donné via la config présente dans database.cfg
- g_hDatabase = SQL_Connect(DATABASE_NAME,true,error, sizeof(error));
- if (g_hDatabase == INVALID_HANDLE)
- {
- LogMessage("Erreur de connexion: %s", error);
- }
- else
- {
- LogMessage("Connexion à la BDD MySQL réussie");
- }
- }
- else
- {
- LogError("Impossible de trouvé <%s> dans le fichier databases.cfg", DATABASE_NAME);
- }
- }
- stock bool:DisconnectSQL()
- {
- if(g_hDatabase != INVALID_HANDLE)
- {
- CloseHandle(g_hDatabase);
- g_hDatabase = INVALID_HANDLE;
- }
- return true;
- }
- stock bool:CheckSQL()
- {
- if(g_hDatabase == INVALID_HANDLE)
- {
- ConnectBDD();
- return false ;
- }
- return true;
- }
- public IsAdmin(client)
- {
- decl String:steamId[30];
- GetClientAuthString(client, steamId, sizeof(steamId));
- if (GetUserFlagBits(client) & ADMFLAG_SLAY) return true;
- else if (GetUserFlagBits(client) & ADMFLAG_GENERIC) return true;
- else if (GetUserFlagBits(client) & ADMFLAG_BAN) return true;
- else return false;
- }
- public IsRoot(client)
- {
- decl String:steamId[30];
- GetClientAuthString(client, steamId, sizeof(steamId));
- if (GetUserFlagBits(client) & ADMFLAG_ROOT) return true;
- else return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement