PageRenderTime 23ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/common/clientservice.h

http://schat.googlecode.com/
C Header | 136 lines | 103 code | 11 blank | 22 comment | 0 complexity | 4962d8d8e7ef207b16f1d7dee69d52ad MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
  1. /* $Id: clientservice.h 1413 2011-01-16 15:03:54Z IMPOMEZIA $
  2. * IMPOMEZIA Simple Chat
  3. * Copyright Š 2008-2011 IMPOMEZIA <schat@impomezia.com>
  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 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef CLIENTSERVICE_H_
  19. #define CLIENTSERVICE_H_
  20. #include <QObject>
  21. #include <QPointer>
  22. #include <QTcpSocket>
  23. #include <QTimer>
  24. #include "abstractprofile.h"
  25. #include "network.h"
  26. #include "protocol.h"
  27. /*!
  28. * \brief ????????????? ?????? ??????? ????.
  29. *
  30. * ????? ????????????? ? ???????????? ??????????.
  31. */
  32. class ClientService : public QObject
  33. {
  34. Q_OBJECT
  35. public:
  36. ClientService(AbstractProfile *profile, const Network *network, QObject *parent = 0);
  37. ~ClientService();
  38. bool isReady() const;
  39. bool sendMessage(const QString &channel, const QString &message);
  40. bool sendRelayMessage(const QString &channel, const QString &sender, const QString &message);
  41. bool sendUniversal(quint16 sub, const QList<quint32> &data1, const QStringList &data2);
  42. inline QString safeNick() const { return m_safeNick; };
  43. inline void sendByeMsg() { send(OpcodeByeMsg, m_profile->byeMsg()); }
  44. inline void sendByeMsg(const QString &msg) { send(OpcodeByeMsg, msg); }
  45. inline void sendSyncBye(const QString &nick, const QString &bye) { send(OpcodeSyncByeMsg, nick, bye); }
  46. inline void sendSyncProfile(quint8 gender, const QString &nick, const QString &nNick, const QString &name) { send(OpcodeNewNick, gender, nick, nNick, name); }
  47. inline void sendUserLeave(const QString &nick, const QString &bye, quint8 flag) { send(OpcodeUserLeave, flag, nick, bye); }
  48. inline void setSafeNick(const QString &nick) { m_safeNick = nick; }
  49. void quit(bool end = true);
  50. void sendNewUser(const QStringList &list, quint8 echo = 1, quint8 numeric = 0);
  51. signals:
  52. void accessDenied(quint16 reason);
  53. void accessGranted(const QString &network, const QString &server, quint16 level);
  54. void connecting(const QString &server, bool network);
  55. void fatal();
  56. void linkLeave(quint8 numeric, const QString &network, const QString &ip);
  57. void message(const QString &sender, const QString &message);
  58. void newLink(quint8 numeric, const QString &network, const QString &ip);
  59. void newNick(quint8 gender, const QString &nick, const QString &newNick, const QString &name);
  60. void newProfile(quint8 gender, const QString &nick, const QString &name);
  61. void newUser(const QStringList &list, quint8 echo = 1, quint8 numeric = 0);
  62. void privateMessage(quint8 flag, const QString &nick, const QString &message);
  63. void relayMessage(const QString &channel, const QString &sender, const QString &message);
  64. void serverMessage(const QString &msg);
  65. void syncBye(const QString &nick, const QString &bye);
  66. void syncNumerics(const QList<quint8> &numerics);
  67. void syncUsersEnd();
  68. void unconnected(bool echo = true);
  69. void universal(quint16 sub, const QList<quint32> &data1, const QStringList &data2);
  70. void universalLite(quint16 sub, const QList<quint32> &data1);
  71. void userLeave(const QString &nick, const QString &bye, quint8 flag);
  72. public slots:
  73. inline void sendNewProfile() { send(OpcodeNewProfile, m_profile->genderNum(), m_profile->nick(), m_profile->fullName()); }
  74. void connectToHost();
  75. private slots:
  76. void check();
  77. void connected();
  78. void disconnected();
  79. void ping();
  80. void readyRead();
  81. void reconnect();
  82. private:
  83. bool send(quint16 opcode);
  84. bool send(quint16 opcode, const QString &msg);
  85. bool send(quint16 opcode, const QString &str1, const QString &str2);
  86. bool send(quint16 opcode, quint8 gender, const QString &nick, const QString &name);
  87. bool send(quint16 opcode, quint8 gender, const QString &nick, const QString &nNick, const QString &name);
  88. int activeInterfaces();
  89. void createSocket();
  90. void mangleNick();
  91. void opcodeAccessDenied();
  92. void opcodeAccessGranted();
  93. void opcodeLinkLeave();
  94. void opcodeMessage();
  95. void opcodeNewLink();
  96. void opcodeNewNick();
  97. void opcodeNewProfile();
  98. void opcodeNewUser();
  99. void opcodePing();
  100. void opcodePrivateMessage();
  101. void opcodeRelayMessage();
  102. void opcodeServerMessage();
  103. void opcodeSyncByeMsg();
  104. void opcodeSyncNumerics();
  105. void opcodeSyncUsersEnd();
  106. void opcodeUniversal();
  107. void opcodeUserLeave();
  108. void unknownOpcode();
  109. AbstractProfile *m_profile;
  110. bool m_accepted;
  111. bool m_fatal;
  112. bool m_synced;
  113. const Network *m_network;
  114. int m_reconnects;
  115. QDataStream m_stream;
  116. QPointer<QTcpSocket> m_socket;
  117. QString m_safeNick;
  118. QTimer m_checkTimer;
  119. QTimer m_ping;
  120. QTimer m_reconnectTimer;
  121. quint16 m_nextBlockSize;
  122. quint16 m_opcode;
  123. ServerInfo m_server;
  124. };
  125. #endif /*CLIENTSERVICE_H_*/