[xchat] anti kick / away c++

Contenu du snippet

Bah voila, étant donné qu' apparemment programmer un script avec interface graphique en perl pour Xchat relève de l' exploit avec la nouvelle version (5.10), - et au passage qu' apparemment perl n' est pas un language aimé de tous - je vais au fur et a mesure reprendre mon script perso ( http://www.ircfr.com/codes/XCHAT-PERL-ANTI-KICK-AWAY_50779.aspx ) et le refaire en c++ sous forme de plugin, afin au final d' y intégrer une interface graphique...
Étant un peu rouillé en c++, je commence doucement en implantent pour l' instant que les fonctions antikick et away ( qui fonctionnent strictement de la même manière que celles en perl ).
Commentaires désagréables non utiles s' abstenir, commentaires désagréables utiles bienvenus :p

Source / Exemple :


#include <string>
#include <windows.h>
#include "xchat-plugin.h"

#define PNAME "Perso"
#define PDESC "Script perso"
#define PVERSION "0.4"
#define DLL_EXPORT extern "C" __declspec( dllexport )

using namespace std;
int iaway=0;
static xchat_plugin *ph;
string cmd;
xchat_hook *hmsg, *hnot;
HINSTANCE hThisInstance;
HWND hWnd, listBox;
DWORD dwGenericThread;
HANDLE hThread;

// Utilisation de string::find insensiblement a la case
bool caseFind(string s1, string s2){
    for(unsigned int i=0;i<s1.size();i++){
        s1[i] = tolower(s1.at(i));
    }
    for(unsigned int i=0;i<s2.size();i++){
        s2[i] = tolower(s2.at(i));
    }
    if(s1.find(s2)!=string::npos)return true;
    return false;
}

// Routine executée lors du hook sur les PRIVMSG du serveur
static int msgrecu(char *word[], char *word_eol[], void *userdata){
    if((xchat_get_info(ph, "away"))==NULL)return XCHAT_EAT_NONE;
    if(caseFind(word_eol[4], "gero")){
        int i=0;
        cmd = word[1];
        // Recupere le pseudo dans la string pseudo!xxxx@host.serveur
        while(cmd.at(i)!='!')i++;
        cmd = cmd.substr(1, i-1) + ":" + word[3] + word_eol[4];
        SendMessage(listBox, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR)cmd.c_str());
    }
    return XCHAT_EAT_NONE;
}
// Routine executée lors du hook sur les NOTICES du serveur
static int notrecu(char *word[], char *word_eol[], void *userdata){
    if((xchat_get_info(ph, "away"))==NULL)return XCHAT_EAT_NONE;
    int i=0;
    // Recupere le pseudo dans la string pseudo!xxxx@host.serveur
    cmd = word[1];
    while(cmd.at(i)!='!')i++;
    cmd = cmd.substr(1, i-1) + word_eol[4];
    cmd = "NOTICE:" + cmd;
    SendMessage(listBox, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR)cmd.c_str());
    return XCHAT_EAT_NONE;
}

// Si kické, retour sur le serveur et envoie d' une notice au kickeur ...
static int youkicked(char *word[], void *userdata){
    string s = string("Tu as été kické de ") + word[2] + " par : " + word[3] + " : " + word[4] + "\r\n";
    xchat_print(ph, s.c_str());
    xchat_print(ph, "Reconnection en cours ...\r\n");
    cmd = string("NOTICE ") + word[3] + " Plus jamais tu me kick toi :@ !!!\r\n";
    xchat_command(ph, cmd.c_str());
    cmd = string("JOIN ") + word[2];
    xchat_command(ph, cmd.c_str());
    return XCHAT_EAT_XCHAT;
}

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
    switch (message){
        case WM_DESTROY:
            PostQuitMessage (0);
        break;
        case WM_CREATE:
            //MessageBox(0, "fenetre cree", "fenetre", 0);
        break;
        default:
        return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return 0;
}

DWORD WINAPI interface_graphique(LPVOID iValue){
    MSG messages;
    WNDCLASSEX wincl;
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = "XchatPlugin";
    wincl.lpfnWndProc = WindowProcedure;
    wincl.style = CS_DBLCLKS;
    wincl.cbSize = sizeof (WNDCLASSEX);
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;
    wincl.cbClsExtra = 0;
    wincl.cbWndExtra = 0;
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    if (!RegisterClassEx (&wincl)){
        MessageBox(0, "Erreur", "Impossible d' enregistrer la classe windows !", 0);
        return 0;
    }

    hWnd = CreateWindowEx (0,"XchatPlugin","Messages Reçus",WS_OVERLAPPED ,CW_USEDEFAULT,CW_USEDEFAULT,
    527,355,HWND_DESKTOP,NULL,hThisInstance,NULL);

    listBox = CreateWindowEx(WS_EX_CLIENTEDGE, "LISTBOX", NULL, WS_VISIBLE|WS_CHILD|LBS_SORT|LBS_NOTIFY|\
            WS_HSCROLL|WS_VSCROLL, 10, 10, 500, 320, hWnd, (HMENU)100, hThisInstance, NULL);

    ShowWindow(hWnd, 0);
    while (GetMessage (&messages, NULL, 0, 0)){
        TranslateMessage(&messages);
        DispatchMessage(&messages);
    }
    return 0;
}

// Passe en mode away et rajoute [away] a la fin de votre nom
// Ou annule le mode away et remets votre pseudo sans le [away] ...
static int away(char *word[], char *word_eol[], void *userdata){
    string pseudo;
    if((xchat_get_info(ph, "away"))==NULL){
        pseudo = string(xchat_get_info(ph, "nick"));
        cmd = "nick " + pseudo + "[away]";
        xchat_command(ph, cmd.c_str());
        // Active le hook sur les PRIVMSG et NOTICE du serveur
        // Evite la multiplication des hooks si away sur plusieurs serveurs
        if(iaway==0){
            hmsg = xchat_hook_server(ph, "PRIVMSG", XCHAT_PRI_NORM, msgrecu, 0);
            hnot = xchat_hook_server(ph, "NOTICE", XCHAT_PRI_NORM, notrecu, 0);
            ShowWindow(hWnd, SW_SHOW);
            UpdateWindow(hWnd);
        }
        iaway++;

    }else{
        pseudo = string(xchat_get_info(ph, "nick"));
        pseudo = pseudo.substr(0, pseudo.size()-6);
        cmd = "nick " + pseudo;
        xchat_command(ph, cmd.c_str());
        xchat_command(ph, "back");
        iaway--;
        // Si on est en ligne sur tous les serveurs alors on supprime les hooks et la fenetre msg_recu
        if(iaway==0){
            xchat_unhook(ph, hmsg);
            xchat_unhook(ph, hnot);
            ShowWindow(hWnd, SW_HIDE);
            UpdateWindow(hWnd);
        }
    }
    return XCHAT_EAT_NONE;
}

// Envoie des infos du plugin au progz
DLL_EXPORT void xchat_plugin_get_info(char **name, char **desc, char **version, void **reserved){

  • name = PNAME;
  • desc = PDESC;
  • version = PVERSION;
} // Initialisation du plugin DLL_EXPORT int xchat_plugin_init(xchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg){ ph = plugin_handle;
  • plugin_name = PNAME;
  • plugin_desc = PDESC;
  • plugin_version = PVERSION;
xchat_hook_print(ph, "You kicked", XCHAT_PRI_NORM, youkicked, 0); xchat_hook_command(ph, "away", XCHAT_PRI_NORM, away, "", 0); hThisInstance = GetModuleHandle(0); hThread = CreateThread(NULL,0,interface_graphique,0,0,&dwGenericThread); xchat_print(ph, "Script perso cpp chargé!\n"); return 1; } DLL_EXPORT int xchat_plugin_deinit(){ ShowWindow(hWnd, SW_HIDE); TerminateThread(hThread, 0); return 0; }

Conclusion :


Bah reste plus qu'a faire une belle interface conviviale à la place de la fenêtre et ça sera bon :)

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.