QWClientPrivate.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. GNU General Public License version 3 notice
  3. Copyright (C) 2012 Mihawk <luiz@netdome.biz>. All rights reserved.
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see < http://www.gnu.org/licenses/ >.
  14. */
  15. #ifndef QWCLIENTPRIVATE_H
  16. #define QWCLIENTPRIVATE_H
  17. #include <qglobal.h>
  18. #include <QBuffer>
  19. #include <QDataStream>
  20. #include <QHostAddress>
  21. #include <QList>
  22. #include "QWClient.h"
  23. #include "quakedef.h"
  24. class QWClient;
  25. class QWPack;
  26. class QWClientPrivate
  27. {
  28. public:
  29. QWClientPrivate(QWClient *client);
  30. ~QWClientPrivate();
  31. void connect(const char *host, quint16 port);
  32. void run();
  33. void disconnect();
  34. void observe();
  35. void join();
  36. void setBindHost(const QString& host);
  37. void setName(const char *name);
  38. void setTeam(const char *team);
  39. void setColor(quint8 bottom, quint8 top);
  40. void setQuakeFolder(const QString& path);
  41. void setSpectator(bool spectate = true);
  42. void setPassword(const QString& password);
  43. void setPing(quint16 ping);
  44. void setRate(quint16 rate);
  45. void sendCmd(const QString& cmd);
  46. const QString& gameDir() const;
  47. const QString& quakeDir() const;
  48. void reconnect();
  49. const QString host() const { return myHost.toString(); }
  50. quint16 port() const { return myPort; }
  51. QWClient::ClientState state() const { return myState; }
  52. static void stripColor(char* string);
  53. private:
  54. class QWClient* myClient;
  55. class QUdpSocket* mySocket;
  56. class QTime* myTime;
  57. class QTime* myLastServerReplyTime;
  58. class QFile* myDownload; //current active download
  59. QHostAddress myHost;
  60. quint16 myPort;
  61. /* Incoming data buffers */
  62. QByteArray myInData;
  63. QBuffer myInBuffer;
  64. QDataStream myInStream;
  65. /* Outgoing client data buffers */
  66. QDataStream myUnreliableOutStream;
  67. QBuffer myUnreliableOutBuffer;
  68. QByteArray myUnreliableOutData;
  69. QDataStream myReliableOutStream;
  70. QBuffer myReliableOutBuffer;
  71. QByteArray myReliableOutData;
  72. QByteArray myReliableData; //saves reliable messages not acked
  73. /* Everything is assembled here b4 sending */
  74. QDataStream myOutStream;
  75. QBuffer myOutBuffer;
  76. QByteArray myOutData;
  77. bool myBadReadFlag;
  78. static const char*ClientName;
  79. static const char*ClientVersion;
  80. QString myClientName;
  81. QString myClientVersion;
  82. QWClient::ClientState myState;
  83. quint16 myQPort;
  84. quint32 myProtocolVersion;
  85. quint32 myFTEProtocolExtensions;
  86. quint32 myServerCount;
  87. QString myGameDir;
  88. QString myQuakeDir;
  89. QString myMapName;
  90. QString myPassword; // For connecting on servers that require a password
  91. quint32 myIncomingSeq;
  92. quint32 myIncomingAck;
  93. quint32 myOutgoingSeq;
  94. quint32 myLastRealiableSeq;
  95. bool myIncomingSeqReliableFlag;
  96. bool myIncomingAckReliableFlag;
  97. bool myOutgoingSeqReliableFlag;
  98. quint8 myPacketLoss;
  99. quint16 myPing;
  100. /* Download */
  101. QList<QWPack*> myPacks;
  102. /* Client Cvars */
  103. quint16 myRate;
  104. quint8 myTopColor;
  105. quint8 myBottomColor;
  106. QString myName;
  107. bool mySpectatorFlag;
  108. QString myTeam;
  109. /* NameFun Conversion */
  110. static char ourReadableCharsTable[256];
  111. static bool ourReadableCharsTableInitialized;
  112. static void fillReadableCharsTable();
  113. void reloadPackFiles();
  114. void loadPackFile(const QString& filename);
  115. void sendConnectionless(const QByteArray& data);
  116. void sendMovement(); //required on MVDSV
  117. void sendToServer(bool dontWait = false);
  118. void readPackets();
  119. void startDownload(const QString& filename);
  120. bool fileExists(const QString& filename);
  121. bool readFile(const QString& filename, char **data, quint64 *len);
  122. void preSpawn(int mapChecksum);
  123. static unsigned blockCheckSum(void *buffer, int len);
  124. quint32 mapChecksum(const QString& mapName);
  125. //========================================================================
  126. // Parsing functions
  127. /* Main parsing functions */
  128. void parseServerMessage();
  129. void parseConnectionless();
  130. /* Helpers */
  131. static float littleFloat(float f);
  132. static quint16 littleShort(quint16 s);
  133. static quint32 littleLong(quint32 l);
  134. /* Reading */
  135. bool checkForBadRead(quint8 typeSize);
  136. float readCoord();
  137. float readAngle();
  138. float readAngle16();
  139. quint8 readByte();
  140. float readFloat();
  141. qint16 readShort();
  142. qint32 readLong();
  143. const QString readString();
  144. void readUserDeltaCmd(userCmd_t *from, userCmd_t *move);
  145. void parseDelta(entityState_t *from, entityState_t *to, int bits);
  146. /* Writing */
  147. static void writeByte(QDataStream* stream, const quint8 b);
  148. static void writeShort(QDataStream* stream, const quint16 s);
  149. static void writeLong(QDataStream* stream, const quint32 l);
  150. static void writeString(QDataStream* stream, const QString& str);
  151. /* Command parsers */
  152. void parseSvcModellist();//s
  153. void parseSvcFTEModellistShort();//s
  154. void parseSvcDisconnect();//
  155. void parseSvcNoop();//
  156. void parseSvcPrint();//
  157. void parseSvcCenterPrint();//
  158. void parseSvcStuffText();//
  159. void parseSvcDamage();//
  160. void parseSvcServerData();//s
  161. void parseSvcSetAngle();//
  162. void parseSvcLightStyle();//
  163. void parseSvcSound();//
  164. void parseSvcStopSound();//
  165. void parseSvcUpdateFrags();//
  166. void parseSvcUpdatePing();//
  167. void parseSvcUpdatePL();//
  168. void parseSvcUpdateEnterTime();//
  169. void parseSvcSpawnBaseLine();//
  170. void parseSvcSpawnStatic();//
  171. void parseSvcTempEntity();//
  172. void parseSvcKilledMonster();//
  173. void parseSvcFoundSecret();//
  174. void parseSvcUpdateStat();//
  175. void parseSvcUpdateStatLong();//
  176. void parseSvcSpawnStaticSound();//
  177. void parseSvcCDTrack();//
  178. void parseSvcIntermission();//
  179. void parseSvcFinale();//
  180. void parseSvcSellScreen();//
  181. void parseSvcSmallKick();//
  182. void parseSvcBigKick();//
  183. void parseSvcMuzzleFlash();//
  184. void parseSvcUpdateUserinfo();//
  185. void parseSvcSetinfo();//
  186. void parseSvcServerinfo();//
  187. void parseSvcDownload();//
  188. void parseChunkedDownload();//NA
  189. void parseSvcPlayerinfo();//
  190. void parseSvcNails();//fixed
  191. void parseSvcChokeCount();//
  192. void parseSvcSoundlist();//
  193. void parseSvcPacketEntities();//look at it
  194. void parseSvcDeltaPacketEntities();//look at it
  195. void parseSvcMaxSpeed();//
  196. void parseSvcEntGravity();//
  197. void parseSvcSetPause();//
  198. void parseSvcNails2();//fixed
  199. void parseSvcFTESpawnBaseline2();//
  200. void parseSvcQizmoVoice();//
  201. void parseSvcFTEVoiceChat();//hmmf
  202. void parseSvcFTESpawnStatic2();//FIXED readbyte supposed to be readShort.
  203. void parseSvcUpdateName();
  204. void parseSvcUpdateColors();
  205. void parseSvcSignonNum();
  206. void parseSvcParticle();
  207. void parseSvcVersion();
  208. void parseSvcClientData();
  209. void parseSvcTime();
  210. };
  211. #endif // QWCLIENTPRIVATE_H