IrcClient.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*\
  2. |*| Copyright 2015-2016 bill-auger <https://github.com/bill-auger/av-caster/issues>
  3. |*|
  4. |*| This file is part of the AvCaster program.
  5. |*|
  6. |*| AvCaster is free software: you can redistribute it and/or modify
  7. |*| it under the terms of the GNU General Public License version 3
  8. |*| as published by the Free Software Foundation.
  9. |*|
  10. |*| AvCaster is distributed in the hope that it will be useful,
  11. |*| but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. |*| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. |*| GNU General Public License for more details.
  14. |*|
  15. |*| You should have received a copy of the GNU General Public License
  16. |*| along with AvCaster. If not, see <http://www.gnu.org/licenses/>.
  17. \*/
  18. #include "../Constants/Constants.h"
  19. #ifndef DISABLE_CHAT
  20. #ifndef _IRCCLIENT_H_
  21. #define _IRCCLIENT_H_
  22. #include <libircclient.h>
  23. #include "../Constants/Constants.h"
  24. /**
  25. IrcClient is the IRC network communications class for the AvCaster application.
  26. It encapsulates interactions with the libircclient C library
  27. and provides cross-network channel bridging.
  28. Each instance manages a single network connection which auto-joins a single channel.
  29. */
  30. class IrcClient : public Thread
  31. {
  32. friend class AvCaster ;
  33. public:
  34. ~IrcClient() ;
  35. // session management
  36. void configure(bool should_create_session) ;
  37. private:
  38. IrcClient(ValueTree network_store) ;
  39. // libircclient callbacks
  40. static void OnConnect (irc_session_t* session , const char* event , const char* origin ,
  41. const char** params , unsigned int count ) ;
  42. static void OnChannelMsg(irc_session_t* session , const char* event , const char* origin ,
  43. const char** params , unsigned int count ) ;
  44. static void OnJoin (irc_session_t* session , const char* event , const char* origin ,
  45. const char** params , unsigned int count ) ;
  46. static void OnPart (irc_session_t* session , const char* event , const char* origin ,
  47. const char** params , unsigned int count ) ;
  48. static void OnNickChange(irc_session_t* session , const char* event , const char* origin ,
  49. const char** params , unsigned int count ) ;
  50. static void OnNumeric (irc_session_t* session , unsigned int event , const char* origin ,
  51. const char** params , unsigned int count ) ;
  52. // helpers
  53. static bool IsSufficientVersion() ;
  54. static void SetRetries (int n_retries) ;
  55. static void HandleNicks (String nicks) ;
  56. static void UpdateNicks () ;
  57. static String ProcessTextMeta (const char* message) ;
  58. static StringArray ProcessTimestamp (String message) ;
  59. static void AddServerChat (String message) ;
  60. static void AddClientChat (String message) ;
  61. static void AddUserChat (String prefix , String nick , String message) ;
  62. // session management
  63. void createSession () ;
  64. void destroySession() ;
  65. void run () override ;
  66. bool login () ;
  67. void sendChat (String chat_message) ;
  68. static ValueTree NetworkStore ;
  69. static irc_callbacks_t ServerCallbacks ;
  70. static StringArray Nicks ;
  71. irc_session_t* session ;
  72. } ;
  73. #endif // _IRCCLIENT_H_
  74. #endif // DISABLE_CHAT