irc-op.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * ngIRCd -- The Next Generation IRC Daemon
  3. * Copyright (c)2001-2005 by Alexander Barton (alex@barton.de)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * Please read the file COPYING, README and AUTHORS for more information.
  10. *
  11. * Channel operator commands
  12. */
  13. #include "portab.h"
  14. static char UNUSED id[] = "$Id: irc-op.c,v 1.15.4.2 2007/04/03 20:23:31 fw Exp $";
  15. #include "imp.h"
  16. #include <assert.h>
  17. #include <string.h>
  18. #include <stdio.h>
  19. #include "defines.h"
  20. #include "conn.h"
  21. #include "client.h"
  22. #include "channel.h"
  23. #include "irc-write.h"
  24. #include "lists.h"
  25. #include "log.h"
  26. #include "messages.h"
  27. #include "parse.h"
  28. #include "exp.h"
  29. #include "irc-op.h"
  30. GLOBAL bool
  31. IRC_KICK( CLIENT *Client, REQUEST *Req )
  32. {
  33. CLIENT *target, *from;
  34. assert( Client != NULL );
  35. assert( Req != NULL );
  36. /* Falsche Anzahl Parameter? */
  37. if(( Req->argc < 2) || ( Req->argc > 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
  38. if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
  39. else from = Client;
  40. if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
  41. /* Ziel-User suchen */
  42. target = Client_Search( Req->argv[1] );
  43. if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[1] );
  44. Channel_Kick( target, from, Req->argv[0], Req->argc == 3 ? Req->argv[2] : Client_ID( from ));
  45. return CONNECTED;
  46. } /* IRC_KICK */
  47. GLOBAL bool
  48. IRC_INVITE( CLIENT *Client, REQUEST *Req )
  49. {
  50. CHANNEL *chan;
  51. CLIENT *target, *from;
  52. bool remember = false;
  53. assert( Client != NULL );
  54. assert( Req != NULL );
  55. /* Wrong number of parameters? */
  56. if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
  57. if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
  58. else from = Client;
  59. if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
  60. /* Search user */
  61. target = Client_Search( Req->argv[0] );
  62. if(( ! target ) || ( Client_Type( target ) != CLIENT_USER )) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
  63. chan = Channel_Search( Req->argv[1] );
  64. if( chan )
  65. {
  66. /* Channel exists. Is the user a valid member of the channel? */
  67. if( ! Channel_IsMemberOf( chan, from )) return IRC_WriteStrClient( from, ERR_NOTONCHANNEL_MSG, Client_ID( Client ), Req->argv[1] );
  68. /* Is the channel "invite-only"? */
  69. if( strchr( Channel_Modes( chan ), 'i' ))
  70. {
  71. /* Yes. The user must be channel operator! */
  72. if( ! strchr( Channel_UserModes( chan, from ), 'o' )) return IRC_WriteStrClient( from, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( from ), Channel_Name( chan ));
  73. remember = true;
  74. }
  75. /* Is the target user already member of the channel? */
  76. if( Channel_IsMemberOf( chan, target )) return IRC_WriteStrClient( from, ERR_USERONCHANNEL_MSG, Client_ID( from ), Req->argv[0], Req->argv[1] );
  77. /* If the target user is banned on that channel: remember invite */
  78. if( Lists_Check(Channel_GetListBans(chan), target )) remember = true;
  79. if (remember) {
  80. /* We must remember this invite */
  81. if( ! Channel_AddInvite(chan, Client_Mask( target ), true))
  82. return CONNECTED;
  83. }
  84. }
  85. LogDebug("User \"%s\" invites \"%s\" to \"%s\" ...", Client_Mask(from), Req->argv[0], Req->argv[1]);
  86. /* Inform target client */
  87. IRC_WriteStrClientPrefix( target, from, "INVITE %s %s", Req->argv[0], Req->argv[1] );
  88. if( Client_Conn( target ) > NONE )
  89. {
  90. /* The target user is local, so we have to send the status code */
  91. if( ! IRC_WriteStrClientPrefix( from, target, RPL_INVITING_MSG, Client_ID( from ), Req->argv[0], Req->argv[1] )) return DISCONNECTED;
  92. }
  93. return CONNECTED;
  94. } /* IRC_INVITE */
  95. /* -eof- */