QWClientPrivate.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. quint32 _mapChecksum; // checksum we got from error message
  126. bool myWrongChecksumFlag; // for faster reconection
  127. //========================================================================
  128. // Parsing functions
  129. /* Main parsing functions */
  130. void parseServerMessage();
  131. void parseConnectionless();
  132. /* Helpers */
  133. static float littleFloat(float f);
  134. static quint16 littleShort(quint16 s);
  135. static quint32 littleLong(quint32 l);
  136. /* Reading */
  137. bool checkForBadRead(quint8 typeSize);
  138. float readCoord();
  139. float readAngle();
  140. float readAngle16();
  141. quint8 readByte();
  142. float readFloat();
  143. qint16 readShort();
  144. qint32 readLong();
  145. const QString readString();
  146. void readUserDeltaCmd(userCmd_t *from, userCmd_t *move);
  147. void parseDelta(entityState_t *from, entityState_t *to, int bits);
  148. /* Writing */
  149. static void writeByte(QDataStream* stream, const quint8 b);
  150. static void writeShort(QDataStream* stream, const quint16 s);
  151. static void writeLong(QDataStream* stream, const quint32 l);
  152. static void writeString(QDataStream* stream, const QString& str);
  153. /* Command parsers */
  154. void parseSvcModellist();//s
  155. void parseSvcFTEModellistShort();//s
  156. void parseSvcDisconnect();//
  157. void parseSvcNoop();//
  158. void parseSvcPrint();//
  159. void parseSvcCenterPrint();//
  160. void parseSvcStuffText();//
  161. void parseSvcDamage();//
  162. void parseSvcServerData();//s
  163. void parseSvcSetAngle();//
  164. void parseSvcLightStyle();//
  165. void parseSvcSound();//
  166. void parseSvcStopSound();//
  167. void parseSvcUpdateFrags();//
  168. void parseSvcUpdatePing();//
  169. void parseSvcUpdatePL();//
  170. void parseSvcUpdateEnterTime();//
  171. void parseSvcSpawnBaseLine();//
  172. void parseSvcSpawnStatic();//
  173. void parseSvcTempEntity();//
  174. void parseSvcKilledMonster();//
  175. void parseSvcFoundSecret();//
  176. void parseSvcUpdateStat();//
  177. void parseSvcUpdateStatLong();//
  178. void parseSvcSpawnStaticSound();//
  179. void parseSvcCDTrack();//
  180. void parseSvcIntermission();//
  181. void parseSvcFinale();//
  182. void parseSvcSellScreen();//
  183. void parseSvcSmallKick();//
  184. void parseSvcBigKick();//
  185. void parseSvcMuzzleFlash();//
  186. void parseSvcUpdateUserinfo();//
  187. void parseSvcSetinfo();//
  188. void parseSvcServerinfo();//
  189. void parseSvcDownload();//
  190. void parseChunkedDownload();//NA
  191. void parseSvcPlayerinfo();//
  192. void parseSvcNails();//fixed
  193. void parseSvcChokeCount();//
  194. void parseSvcSoundlist();//
  195. void parseSvcPacketEntities();//look at it
  196. void parseSvcDeltaPacketEntities();//look at it
  197. void parseSvcMaxSpeed();//
  198. void parseSvcEntGravity();//
  199. void parseSvcSetPause();//
  200. void parseSvcNails2();//fixed
  201. void parseSvcFTESpawnBaseline2();//
  202. void parseSvcQizmoVoice();//
  203. void parseSvcFTEVoiceChat();//hmmf
  204. void parseSvcFTESpawnStatic2();//FIXED readbyte supposed to be readShort.
  205. void parseSvcUpdateName();
  206. void parseSvcUpdateColors();
  207. void parseSvcSignonNum();
  208. void parseSvcParticle();
  209. void parseSvcVersion();
  210. void parseSvcClientData();
  211. void parseSvcTime();
  212. };
  213. #endif // QWCLIENTPRIVATE_H