home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / ftp.vapor.com / amirc / old / amirc_plugin_sdk_22.lzx / wallchop.c < prev   
Encoding:
C/C++ Source or Header  |  1998-11-21  |  3.4 KB  |  178 lines

  1. /*
  2. ** Wallchop plugin
  3. **
  4. ** This sample plugin defines a new command /WALLCHOP,
  5. ** which writes a message to all operators on a channel,
  6. ** and /WALLNOP, which addresses all NON-operators
  7. */
  8.  
  9. #include <proto/exec.h>
  10. #include <proto/dos.h>
  11. #include <proto/utility.h>
  12. #include <libraries/mui.h>
  13. #include <string.h>
  14.  
  15. #define BUILDPLUGIN
  16. #include "amirc_plugin.h"
  17.  
  18. struct amiplug_cmd mycmd = {
  19.     {áNULL, NULL },
  20.     "WALLCHOP",                // name
  21.     "[channel] text",        // template
  22.     1,                        // command ID
  23.     1,                        // minimum number of args
  24.     TRUE                    // needs channel
  25. };
  26.  
  27. struct amiplug_cmd mycmd2 = {
  28.     {áNULL, NULL },
  29.     "WALLNOP",                // name
  30.     "[channel] text",        // template
  31.     2,                        // command ID (not really used here)
  32.     1,                        // minimum number of args
  33.     TRUE                    // needs channel
  34. };
  35.  
  36. struct TagItem mytaglist[]á= {
  37.     AMIPLUG_Query_Version, 2,
  38.     AMIPLUG_Query_Revision, 1,
  39.     AMIPLUG_Query_Copyright, (ULONG)"Copyright ⌐ 1997-98 Oliver Wagner <owagner@vapor.com>",
  40.     AMIPLUG_Query_Infostring, (ULONG)"/WALLCHOP command extension",
  41.  
  42.     AMIPLUG_Query_CustomCommand, (ULONG)&mycmd,
  43.     AMIPLUG_Query_CustomCommand, (ULONG)&mycmd2,
  44.  
  45.     TAG_DONE
  46. };
  47.  
  48.  
  49. // Setup & Query function
  50. struct TagItem * __asm __saveds AMIPLUG_Setup( void )
  51. {
  52.     return( mytaglist );
  53. }
  54.  
  55. void __asm AMIPLUG_Cleanup( void )
  56. {
  57.     // just a dummy
  58. }
  59.  
  60. int __asm AMIPLUG_Hook_Rawline( void )
  61. {
  62.     // just a dummy
  63.     return( 0 );
  64. }
  65.  
  66. int __asm AMIPLUG_Hook_NumericMsg( void )
  67. {
  68.     // just a dummy
  69.     return( 0 );
  70. }
  71.  
  72. int __asm AMIPLUG_Hook_DCC( void )
  73. {
  74.     // just a dummy
  75.     return( 0 );
  76. }
  77.  
  78. void __asm AMIPLUG_DoMenu( void )
  79. {
  80.     // just a dummy
  81. }
  82.  
  83. void __asm AMIPLUG_DoCTCP( void )
  84. {
  85.     // just a dummy
  86. }
  87.  
  88. //
  89. // Core
  90. //
  91. //    sprintf() replacement
  92. UWORD fmtfunc[] = {á0x16c0, 0x4e75 };
  93. void __stdargs sprintf( char *to, char *fmt, ... )
  94. {
  95.     RawDoFmt( fmt, &fmt + 1, (APTR)fmtfunc, to );
  96. }
  97.  
  98. void __asm __saveds AMIPLUG_DoCommand(
  99.     register __a0 struct amiplug_functable *ft,
  100.     register __d0 ULONG cmdid,
  101.     register __a1 struct amiplug_cmdparm *parms
  102. )
  103. {
  104.     APTR userlv = ft->amiplug_getuserlv( ft, parms->channelname );
  105.     char buffer[ 1024 ];
  106.     int c;
  107.     int comma = FALSE;
  108.     int cnt = 0, tcnt = 0;
  109.  
  110.     if( !userlv )
  111.     {
  112.         ft->amiplug_out_defwin( ft, 3, "\033b½WallCHOP╗", "Unable to find user list for channel." );
  113.         return;
  114.     }
  115.  
  116.     strcpy( buffer, "NOTICE " );
  117.  
  118.     for( c = 0; ; c++ )
  119.     {
  120.         char *u;
  121.  
  122.         DoMethod( userlv, MUIM_List_GetEntry, c, &u );
  123.         if( !u || cnt > 6 )
  124.         {
  125.             strcat( buffer, cmdid == 2 ? " :[No-@" :" :[@" );
  126.             strcat( buffer, parms->channelname );
  127.             strcat( buffer, "] " );
  128.             strcat( buffer, parms->parms );
  129.             strcat( buffer, "\r\n" );
  130.  
  131.             if( tcnt )
  132.                 ft->amiplug_sendraw( ft, buffer, strlen( buffer ) );
  133.             cnt = 0;
  134.             comma = FALSE;
  135.  
  136.             strcpy( buffer, "NOTICE " );
  137.         }
  138.  
  139.         if( !u )
  140.             break;
  141.  
  142.         if( cmdid == 1 && *u != '@'á&& *u != '%' )
  143.             continue; // no OP
  144.         else if( cmdid == 2 && ( *u == '@'á|| *u == '%' ) )
  145.             continue; // is OP
  146.  
  147.         if( *u == '@' || *u == '%' || *u == '+'á)
  148.             u++;
  149.  
  150.         if( comma )
  151.             strcat( buffer, "," );
  152.         else
  153.             comma = TRUE;
  154.  
  155.         strcat( buffer, u );
  156.  
  157.         tcnt++;
  158.     }
  159.  
  160.     sprintf( buffer, "[%ld Recipiants/%s] %s", tcnt, parms->channelname, parms->parms );
  161.         
  162.  
  163.     ft->amiplug_out_defwin( ft, amirc_tc_local, cmdid == 1 ? "\033b½WallCHOP╗" : "\033b½WallNOP╗", buffer );
  164.         
  165. }
  166.  
  167. //
  168. // Let's lower the priority of our libnode to -128 so it
  169. // doesn't get into the way of all other libraries
  170. // in the system which are supposedly opened more often
  171. //
  172.  
  173. long __saveds __asm __UserLibInit( register __a6 struct Library *libbase )
  174. {
  175.     libbase->lib_Node.ln_Pri = -128;
  176.     return( 0 );
  177. }
  178.