To create new wiki account, please join us on #znc at freenode and ask admins to create a wiki account for you. You can say thanks to spambots for this inconvenience.

Savebuff/XChat

From ZNC
< Savebuff
Revision as of 18:26, 17 December 2011 by DarthGandalf (talk) (Created page with "===== XChat Plugin ===== # Save the code below as ~/.xchat2/znc-savebuff.c # cd ~/.xchat2 && gcc -Wl,--export-dynamic -Wall -O1 -shared -fPIC -I/usr/include/xchat znc-savebuf...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
XChat Plugin[edit]
  1. Save the code below as ~/.xchat2/znc-savebuff.c
  2. cd ~/.xchat2 && gcc -Wl,--export-dynamic -Wall -O1 -shared -fPIC -I/usr/include/xchat znc-savebuff.c -o znc-savebuff.so
    • Note: your include dir may be different from above
  3. In xchat go to the "Window" menu and choose "Plugins and Scripts..."
  4. Navigate to your compiled znc-savebuff.so file and choose "Load..."
  5. Restart xchat and the modes should now look pretty
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#ifdef _WIN32
#include <windows.h>
#endif

#include "xchat-plugin.h"

#ifdef _WIN32
static xchat_plugin *ph;
#endif

#define EMITPRINT( ... ) xchat_emit_print( plugin_handle, __VA_ARGS__ )
#define SHOWMODE "mode \00310%s\003 \002%s\002 by \002%s\002"
#define MODNAME "*savebuff"

void ShowMode( xchat_plugin *plugin_handle, const char *pChannel, const char *pModes, const char *pNick )
{
	char *pText;
	u_int iLength = strlen( SHOWMODE );
	iLength += strlen( pChannel );
	iLength += strlen( pModes );
	iLength += strlen( pNick ) + 1; // ( allow for NULL )

	pText = (char *)malloc( iLength );
	sprintf( pText, SHOWMODE, pChannel, pModes, pNick );

	EMITPRINT( "Generic Message", "-\00310-\002-\002\003",  pText, NULL );

	free( pText );
}

int ProcessPMSG( char **word, char **word_eol, void *userdata )
{
	xchat_plugin *plugin_handle = (xchat_plugin *)userdata;

	if ( ( word[1] ) && ( strncmp( (word[1]+1), MODNAME, strlen( MODNAME ) ) == 0 ) && ( word[4] ) && ( word[5] ) && (  word[6] ) )
	{
		char *pHostMask, *pType, *pChannel, *pArgs = NULL;
		char *pNick, *pHost;

		pChannel = word[3];
		pHostMask = word[5];
		pType = word[6];
		if ( word[7] )
			pArgs = word_eol[7];
		
		pNick = strdup( pHostMask );
		pHost = strrchr( pNick, '!' );

		if ( pHost )
			*pHost++ = '\0';
		
		if ( ( strcmp( "MODE", pType ) == 0 ) && ( pArgs ) )
		{
			ShowMode( plugin_handle, pChannel, pArgs, pNick );
		}
		else if ( strcmp( "JOIN", pType ) == 0 )
		{
			EMITPRINT( "Join", pNick, pChannel, pHost, NULL );
		}
		else if ( strcmp( "PART", pType ) == 0 )
		{
			EMITPRINT( "Part", pNick, pHost, pChannel, NULL );
		}
		else if ( strcmp( "NICK", pType ) == 0 )
		{
			if ( pArgs )
				EMITPRINT( "Change Nick", pNick, pArgs, NULL );
			else
				EMITPRINT( "Change Nick", pNick, "*shrug*", NULL );
		}
		else if ( strcmp( "QUIT", pType ) == 0 )
		{
			if ( pArgs )
				EMITPRINT( "Quit", pNick, pArgs, pHost, NULL );
			else
				EMITPRINT( "Quit", pNick, "No Reason", pHost, NULL );
		}
		else if ( ( strcmp( "KICK", pType ) == 0 ) && ( pArgs ) )
		{
			char *pNickB = strdup( word[7] );
			pHost = strrchr( pNickB, '!' );
			if ( pHost )
				*pHost++ = '\0';

			if ( word[8] )
				EMITPRINT( "Kick", pNickB, pNick, pChannel, word_eol[8], NULL );
			else
				EMITPRINT( "Kick", pNickB, pNick, pChannel, "No Reason", NULL );

			free( pNickB );
		}
		else
			fprintf( stderr, "Unhandled Text! [%s]\n", word_eol[4] );

		free( pNick );
		return( XCHAT_EAT_ALL );
	}
	
	return( XCHAT_EAT_NONE );
}

void xchat_plugin_get_info(char **name, char **desc, char **version, void **reserved)
{
	*name = "znc-xchat";
	*desc = "wraps messages sent by *savebuff module to fake modes and such";
	*version = "1.0";
	if ( reserved )
		*reserved = NULL;
}

int DontDisplay( char **word, void *userdata )
{
	return( XCHAT_EAT_XCHAT );
}

int ShowModes( char **word, char **word_eol, void *userdata )
{
	xchat_plugin *plugin_handle = (xchat_plugin *)userdata;
	char *pChannel = word[3], *pNick = strdup( (word[1]+1) ), *pModes = word_eol[4];
	char *pTmp;
	
	pTmp = strchr( pNick, '!' );
	if ( pTmp )
		*pTmp = '\0';

	ShowMode( plugin_handle, pChannel, pModes, pNick );

	free( pNick );
	return( XCHAT_EAT_NONE );
}

int xchat_plugin_init( xchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char  *arg )
{
#ifdef _WIN32
	ph = plugin_handle;
#endif

	xchat_plugin_get_info (plugin_name, plugin_desc, plugin_version, NULL);
	xchat_hook_server( plugin_handle, "PRIVMSG", XCHAT_PRI_NORM, ProcessPMSG, (void *)plugin_handle );
	xchat_hook_server( plugin_handle, "MODE", XCHAT_PRI_NORM, ShowModes, (void *)plugin_handle );
	xchat_hook_print( plugin_handle, "Channel Operator", XCHAT_PRI_NORM, DontDisplay, (void *)plugin_handle );
	xchat_hook_print( plugin_handle, "Channel DeOp", XCHAT_PRI_NORM, DontDisplay, (void *)plugin_handle );
	xchat_hook_print( plugin_handle, "Channel Voice", XCHAT_PRI_NORM, DontDisplay, (void *)plugin_handle );
	xchat_hook_print( plugin_handle, "Channel DeVoice", XCHAT_PRI_NORM, DontDisplay, (void *)plugin_handle );
	xchat_hook_print( plugin_handle, "Channel Ban", XCHAT_PRI_NORM, DontDisplay, (void *)plugin_handle );
	xchat_hook_print( plugin_handle, "Channel UnBan", XCHAT_PRI_NORM, DontDisplay, (void *)plugin_handle );
	xchat_hook_print( plugin_handle, "Channel Mode Generic", XCHAT_PRI_NORM, DontDisplay, (void *)plugin_handle );
	xchat_hook_print( plugin_handle, "Channel Set Key", XCHAT_PRI_NORM, DontDisplay, (void *)plugin_handle );
	xchat_hook_print( plugin_handle, "Channel Set Limit", XCHAT_PRI_NORM, DontDisplay, (void *)plugin_handle );
	xchat_hook_print( plugin_handle, "Channel Remove Keyword", XCHAT_PRI_NORM, DontDisplay, (void *)plugin_handle );
	xchat_hook_print( plugin_handle, "Channel Remove Limit", XCHAT_PRI_NORM, DontDisplay, (void *)plugin_handle );
	return( 1 );
}

int xchat_plugin_deinit( xchat_plugin *plugin_handle )
{
	return( 1 );
}