PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Teambuilder/analyze.h

https://bitbucket.org/encukou/patched-po
C Header | 187 lines | 135 code | 24 blank | 28 comment | 0 complexity | 62b9aa66d3532712c011816002aa149c MD5 | raw file
  1. #ifndef ANALYZE_H
  2. #define ANALYZE_H
  3. #include <QtCore>
  4. #include "network.h"
  5. class Client;
  6. class FullInfo;
  7. class PlayerInfo;
  8. class BattleChoice;
  9. class TeamBattle;
  10. class BattleConfiguration;
  11. class ChallengeInfo;
  12. class Battle;
  13. class UserInfo;
  14. class TrainerTeam;
  15. /* Commands to dialog with the server */
  16. namespace NetworkCli
  17. {
  18. #include "../Shared/networkcommands.h"
  19. }
  20. /* Analyzes the messages received from the network and emits the corresponding signals.
  21. Also allows you to send your own messages to the network
  22. The client actually uses this widgets to send orders and receive commands from the outside. */
  23. class Analyzer : public QObject
  24. {
  25. Q_OBJECT
  26. public:
  27. Analyzer(bool registry_connection = false);
  28. /* functions called by the client */
  29. void login(const FullInfo &team);
  30. void sendMessage(const QString &message);
  31. void sendChanMessage(int channelid, const QString &message);
  32. void connectTo(const QString &host, quint16 port);
  33. void sendTeam(const TrainerTeam & team);
  34. void sendChallengeStuff(const ChallengeInfo &c);
  35. void sendBattleResult(int id, int result);
  36. bool isConnected() const;
  37. void goAway(bool away);
  38. QString getIp() const;
  39. void disconnectFromHost();
  40. /* Convenience functions to avoid writing a new one every time */
  41. void notify(int command);
  42. template<class T>
  43. void notify(int command, const T& param);
  44. template<class T1, class T2>
  45. void notify(int command, const T1& param1, const T2& param2);
  46. template<class T1, class T2, class T3>
  47. void notify(int command, const T1& param1, const T2& param2, const T3 &param3);
  48. signals:
  49. /* to send to the network */
  50. void sendCommand(const QByteArray &command);
  51. /* to send to the client */
  52. void connectionError(int errorNum, const QString &errorDesc);
  53. void protocolError(int errorNum, const QString &errorDesc);
  54. void connected();
  55. void disconnected();
  56. /* Message to appear in all the mainchats */
  57. void messageReceived(const QString &mess);
  58. void htmlMessageReceived(const QString &mess);
  59. /* Command specific to a channel */
  60. void channelCommandReceived(int command, int channel, QDataStream *stream);
  61. /* player from the players list */
  62. void playerReceived(const PlayerInfo &p);
  63. /* login of a player */
  64. void playerLogin(const PlayerInfo &p);
  65. /* Change of team of a player */
  66. void teamChanged(const PlayerInfo &p);
  67. /* logout... */
  68. void playerLogout(int id);
  69. /* challengerelated */
  70. void challengeStuff(const ChallengeInfo &c);
  71. /* battle including self */
  72. void battleStarted(int battleid, int id, const TeamBattle &myteam, const BattleConfiguration &conf);
  73. /* battle of strangers */
  74. void battleStarted(int battleid, int id1, int id2);
  75. void battleFinished(int battleid, int res, int srcid, int destid);
  76. void battleMessage(int battleid, const QByteArray &mess);
  77. void spectatedBattle(int battleId, const BattleConfiguration &conf);
  78. void spectatingBattleMessage(int battleId, const QByteArray &mess);
  79. void spectatingBattleFinished(int battleId);
  80. void passRequired(const QString &salt);
  81. void serverPassRequired(const QString &salt);
  82. void notRegistered(bool);
  83. void playerKicked(int p, int src);
  84. void playerBanned(int p, int src);
  85. void serverReceived(const QString &name, const QString &desc, quint16 num_players, const QString &ip, quint16 max, quint16 port);
  86. void PMReceived(int id, const QString &mess);
  87. void awayChanged(int id, bool away);
  88. void tierListReceived(const QByteArray &tl);
  89. void announcement(const QString &announcement);
  90. /* From the control panel */
  91. void userInfoReceived(const UserInfo &ui);
  92. void userAliasReceived(const QString &s);
  93. void banListReceived(const QString &n, const QString &ip);
  94. void versionDiff(const QString &a, const QString &b);
  95. void serverNameReceived(const QString &serverName);
  96. /* Ranking */
  97. void rankingStarted(int,int,int);
  98. void rankingReceived(const QString&,int);
  99. void channelsListReceived(const QHash<qint32, QString> &channels);
  100. void channelPlayers(int chanid, const QVector<qint32> &channels);
  101. void addChannel(QString name, int id);
  102. void channelNameChanged(int id, const QString &name);
  103. void removeChannel(int id);
  104. public slots:
  105. /* slots called by the network */
  106. void error();
  107. void wasConnected();
  108. void commandReceived (const QByteArray &command);
  109. /* by a channel */
  110. void channelCommand(int command, int channelid, const QByteArray &body);
  111. /* by the battle window */
  112. void battleCommand(int, const BattleChoice &comm);
  113. void battleMessage(int, const QString &mess);
  114. /* By the pm window */
  115. void sendPM(int id, const QString &mess);
  116. /* By the control panel */
  117. void getUserInfo(const QString &name);
  118. void getBanList();
  119. void getTBanList();
  120. void CPUnban(const QString &name);
  121. void CPTUnban(const QString &name);
  122. /* By the rankings window */
  123. void getRanking(const QString &tier, const QString &name);
  124. void getRanking(const QString &tier, int page);
  125. private:
  126. /* The connection to the outside */
  127. Network &socket();
  128. const Network &socket() const;
  129. /* To tell if its the registry we're connected to*/
  130. bool registry_socket;
  131. QList<QByteArray> storedCommands;
  132. QSet<int> channelCommands;
  133. Network mysocket;
  134. };
  135. template<class T>
  136. void Analyzer::notify(int command, const T& param)
  137. {
  138. QByteArray tosend;
  139. QDataStream out(&tosend, QIODevice::WriteOnly);
  140. out.setVersion(QDataStream::Qt_4_7);
  141. out << uchar(command) << param;
  142. emit sendCommand(tosend);
  143. }
  144. template<class T1, class T2>
  145. void Analyzer::notify(int command, const T1& param1, const T2 &param2)
  146. {
  147. QByteArray tosend;
  148. QDataStream out(&tosend, QIODevice::WriteOnly);
  149. out.setVersion(QDataStream::Qt_4_7);
  150. out << uchar(command) << param1 << param2;
  151. emit sendCommand(tosend);
  152. }
  153. template<class T1, class T2, class T3>
  154. void Analyzer::notify(int command, const T1& param1, const T2 &param2, const T3 &param3)
  155. {
  156. QByteArray tosend;
  157. QDataStream out(&tosend, QIODevice::WriteOnly);
  158. out.setVersion(QDataStream::Qt_4_7);
  159. out << uchar(command) << param1 << param2 << param3;
  160. emit sendCommand(tosend);
  161. }
  162. #endif // ANALYZE_H