NetCommandMsg.cpp 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  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. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  24. #include "GameNetwork/NetCommandMsg.h"
  25. #include "Common/GameState.h"
  26. #include "Common/PlayerList.h"
  27. #include "Common/Player.h"
  28. /**
  29. * Base constructor
  30. */
  31. NetCommandMsg::NetCommandMsg()
  32. {
  33. //Added By Sadullah Nader
  34. //Initializations inserted
  35. m_executionFrame = 0;
  36. m_id = 0;
  37. m_playerID = 0;
  38. //
  39. m_timestamp = 0;
  40. m_referenceCount = 1; // start this off as 1. This means that an "attach" is implied by creating a NetCommandMsg object.
  41. m_commandType = NETCOMMANDTYPE_UNKNOWN;
  42. }
  43. /**
  44. * Destructor
  45. */
  46. NetCommandMsg::~NetCommandMsg() {
  47. }
  48. /**
  49. * Adds one to the reference count.
  50. */
  51. void NetCommandMsg::attach() {
  52. ++m_referenceCount;
  53. }
  54. /**
  55. * Subtracts one from the reference count. If the reference count is 0, the this object is destroyed.
  56. */
  57. void NetCommandMsg::detach() {
  58. --m_referenceCount;
  59. if (m_referenceCount == 0) {
  60. deleteInstance();
  61. return;
  62. }
  63. DEBUG_ASSERTCRASH(m_referenceCount > 0, ("Invalid reference count for NetCommandMsg")); // Just to make sure...
  64. if (m_referenceCount < 0) {
  65. deleteInstance();
  66. }
  67. }
  68. /**
  69. * Returns the value by which this type of message should be sorted.
  70. */
  71. Int NetCommandMsg::getSortNumber() {
  72. return m_id;
  73. }
  74. //-------------------------------
  75. // NetGameCommandMsg
  76. //-------------------------------
  77. /**
  78. * Constructor with no argument, sets everything to default values.
  79. */
  80. NetGameCommandMsg::NetGameCommandMsg() : NetCommandMsg() {
  81. //Added By Sadullah Nader
  82. //Initializations inserted
  83. m_argSize = 0;
  84. m_numArgs = 0;
  85. //
  86. m_type = (GameMessage::Type)0;
  87. m_commandType = NETCOMMANDTYPE_GAMECOMMAND;
  88. m_argList = NULL;
  89. m_argTail = NULL;
  90. }
  91. /**
  92. * Constructor with a GameMessage argument. Sets member variables appropriately for this GameMessage.
  93. * Also copies all the arguments.
  94. */
  95. NetGameCommandMsg::NetGameCommandMsg(GameMessage *msg) : NetCommandMsg() {
  96. m_commandType = NETCOMMANDTYPE_GAMECOMMAND;
  97. m_type = msg->getType();
  98. Int count = msg->getArgumentCount();
  99. for (Int i = 0; i < count; ++i) {
  100. addArgument(msg->getArgumentDataType(i), *(msg->getArgument(i)));
  101. }
  102. }
  103. /**
  104. * Destructor
  105. */
  106. NetGameCommandMsg::~NetGameCommandMsg() {
  107. GameMessageArgument *arg = m_argList;
  108. while (arg != NULL) {
  109. m_argList = m_argList->m_next;
  110. arg->deleteInstance();
  111. arg = m_argList;
  112. }
  113. }
  114. /**
  115. * Add an argument to this command.
  116. */
  117. void NetGameCommandMsg::addArgument(const GameMessageArgumentDataType type, GameMessageArgumentType arg)
  118. {
  119. if (m_argTail == NULL) {
  120. m_argList = newInstance(GameMessageArgument);
  121. m_argTail = m_argList;
  122. m_argList->m_data = arg;
  123. m_argList->m_type = type;
  124. m_argList->m_next = NULL;
  125. return;
  126. }
  127. GameMessageArgument *newArg = newInstance(GameMessageArgument);
  128. newArg->m_data = arg;
  129. newArg->m_type = type;
  130. newArg->m_next = NULL;
  131. m_argTail->m_next = newArg;
  132. m_argTail = newArg;
  133. }
  134. // here's where we figure out which slot corresponds to which player
  135. static Int indexFromMask(UnsignedInt mask)
  136. {
  137. Player *player = NULL;
  138. Int i;
  139. for( i = 0; i < MAX_PLAYER_COUNT; i++ )
  140. {
  141. player = ThePlayerList->getNthPlayer( i );
  142. if( player && player->getPlayerMask() == mask )
  143. return i;
  144. } // end for i
  145. return -1;
  146. }
  147. /**
  148. * Construct a new GameMessage object from the data in this object.
  149. */
  150. GameMessage *NetGameCommandMsg::constructGameMessage()
  151. {
  152. GameMessage *retval = newInstance(GameMessage)(m_type);
  153. AsciiString name;
  154. name.format("player%d", getPlayerID());
  155. retval->friend_setPlayerIndex( ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey(name))->getPlayerIndex());
  156. // retval->friend_setPlayerIndex(indexFromMask(ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey(name))->getPlayerMask()));
  157. GameMessageArgument *arg = m_argList;
  158. while (arg != NULL) {
  159. // retval->appendGenericArgument(arg->m_data);
  160. if (arg->m_type == ARGUMENTDATATYPE_INTEGER) {
  161. retval->appendIntegerArgument(arg->m_data.integer);
  162. } else if (arg->m_type == ARGUMENTDATATYPE_REAL) {
  163. retval->appendRealArgument(arg->m_data.real);
  164. } else if (arg->m_type == ARGUMENTDATATYPE_BOOLEAN) {
  165. retval->appendBooleanArgument(arg->m_data.boolean);
  166. } else if (arg->m_type == ARGUMENTDATATYPE_OBJECTID) {
  167. retval->appendObjectIDArgument(arg->m_data.objectID);
  168. } else if (arg->m_type == ARGUMENTDATATYPE_DRAWABLEID) {
  169. retval->appendDrawableIDArgument(arg->m_data.drawableID);
  170. } else if (arg->m_type == ARGUMENTDATATYPE_TEAMID) {
  171. retval->appendTeamIDArgument(arg->m_data.teamID);
  172. } else if (arg->m_type == ARGUMENTDATATYPE_LOCATION) {
  173. retval->appendLocationArgument(arg->m_data.location);
  174. } else if (arg->m_type == ARGUMENTDATATYPE_PIXEL) {
  175. retval->appendPixelArgument(arg->m_data.pixel);
  176. } else if (arg->m_type == ARGUMENTDATATYPE_PIXELREGION) {
  177. retval->appendPixelRegionArgument(arg->m_data.pixelRegion);
  178. } else if (arg->m_type == ARGUMENTDATATYPE_TIMESTAMP) {
  179. retval->appendTimestampArgument(arg->m_data.timestamp);
  180. } else if (arg->m_type == ARGUMENTDATATYPE_WIDECHAR) {
  181. retval->appendWideCharArgument(arg->m_data.wChar);
  182. }
  183. arg = arg->m_next;
  184. }
  185. return retval;
  186. }
  187. /**
  188. * Sets the type of game message
  189. */
  190. void NetGameCommandMsg::setGameMessageType(GameMessage::Type type) {
  191. m_type = type;
  192. }
  193. AsciiString NetGameCommandMsg::getContentsAsAsciiString(void)
  194. {
  195. AsciiString ret;
  196. //AsciiString tmp;
  197. ret.format("Type:%s", GameMessage::getCommandTypeAsAsciiString((GameMessage::Type)m_type).str());
  198. return ret;
  199. }
  200. //-------------------------
  201. // NetAckBothCommandMsg
  202. //-------------------------
  203. /**
  204. * Constructor. Sets the member variables according to the given message.
  205. */
  206. NetAckBothCommandMsg::NetAckBothCommandMsg(NetCommandMsg *msg) : NetCommandMsg() {
  207. m_commandID = msg->getID();
  208. m_commandType = NETCOMMANDTYPE_ACKBOTH;
  209. m_originalPlayerID = msg->getPlayerID();
  210. }
  211. /**
  212. * Constructor. Sets the member variables to default values.
  213. */
  214. NetAckBothCommandMsg::NetAckBothCommandMsg() : NetCommandMsg() {
  215. m_commandType = NETCOMMANDTYPE_ACKBOTH;
  216. }
  217. /**
  218. * Destructor.
  219. */
  220. NetAckBothCommandMsg::~NetAckBothCommandMsg() {
  221. }
  222. /**
  223. * Returns the command ID of the command being ack'd.
  224. */
  225. UnsignedShort NetAckBothCommandMsg::getCommandID() {
  226. return m_commandID;
  227. }
  228. /**
  229. * Set the command ID of the command being ack'd.
  230. */
  231. void NetAckBothCommandMsg::setCommandID(UnsignedShort commandID) {
  232. m_commandID = commandID;
  233. }
  234. /**
  235. * Get the player id of the player who originally sent the command.
  236. */
  237. UnsignedByte NetAckBothCommandMsg::getOriginalPlayerID() {
  238. return m_originalPlayerID;
  239. }
  240. /**
  241. * Set the player id of the player who originally sent the command.
  242. */
  243. void NetAckBothCommandMsg::setOriginalPlayerID(UnsignedByte originalPlayerID) {
  244. m_originalPlayerID = originalPlayerID;
  245. }
  246. Int NetAckBothCommandMsg::getSortNumber() {
  247. return m_commandID;
  248. }
  249. //-------------------------
  250. // NetAckStage1CommandMsg
  251. //-------------------------
  252. /**
  253. * Constructor. Sets the member variables according to the given message.
  254. */
  255. NetAckStage1CommandMsg::NetAckStage1CommandMsg(NetCommandMsg *msg) : NetCommandMsg() {
  256. m_commandID = msg->getID();
  257. m_commandType = NETCOMMANDTYPE_ACKSTAGE1;
  258. m_originalPlayerID = msg->getPlayerID();
  259. }
  260. /**
  261. * Constructor. Sets the member variables to default values.
  262. */
  263. NetAckStage1CommandMsg::NetAckStage1CommandMsg() : NetCommandMsg() {
  264. m_commandType = NETCOMMANDTYPE_ACKSTAGE1;
  265. }
  266. /**
  267. * Destructor.
  268. */
  269. NetAckStage1CommandMsg::~NetAckStage1CommandMsg() {
  270. }
  271. /**
  272. * Returns the command ID of the command being ack'd.
  273. */
  274. UnsignedShort NetAckStage1CommandMsg::getCommandID() {
  275. return m_commandID;
  276. }
  277. /**
  278. * Set the command ID of the command being ack'd.
  279. */
  280. void NetAckStage1CommandMsg::setCommandID(UnsignedShort commandID) {
  281. m_commandID = commandID;
  282. }
  283. /**
  284. * Get the player id of the player who originally sent the command.
  285. */
  286. UnsignedByte NetAckStage1CommandMsg::getOriginalPlayerID() {
  287. return m_originalPlayerID;
  288. }
  289. /**
  290. * Set the player id of the player who originally sent the command.
  291. */
  292. void NetAckStage1CommandMsg::setOriginalPlayerID(UnsignedByte originalPlayerID) {
  293. m_originalPlayerID = originalPlayerID;
  294. }
  295. Int NetAckStage1CommandMsg::getSortNumber() {
  296. return m_commandID;
  297. }
  298. //-------------------------
  299. // NetAckStage2CommandMsg
  300. //-------------------------
  301. /**
  302. * Constructor. Sets the member variables according to the given message.
  303. */
  304. NetAckStage2CommandMsg::NetAckStage2CommandMsg(NetCommandMsg *msg) : NetCommandMsg() {
  305. m_commandID = msg->getID();
  306. m_commandType = NETCOMMANDTYPE_ACKSTAGE2;
  307. m_originalPlayerID = msg->getPlayerID();
  308. }
  309. /**
  310. * Constructor. Sets the member variables to default values.
  311. */
  312. NetAckStage2CommandMsg::NetAckStage2CommandMsg() : NetCommandMsg() {
  313. m_commandType = NETCOMMANDTYPE_ACKSTAGE2;
  314. }
  315. /**
  316. * Destructor.
  317. */
  318. NetAckStage2CommandMsg::~NetAckStage2CommandMsg() {
  319. }
  320. /**
  321. * Returns the command ID of the command being ack'd.
  322. */
  323. UnsignedShort NetAckStage2CommandMsg::getCommandID() {
  324. return m_commandID;
  325. }
  326. /**
  327. * Set the command ID of the command being ack'd.
  328. */
  329. void NetAckStage2CommandMsg::setCommandID(UnsignedShort commandID) {
  330. m_commandID = commandID;
  331. }
  332. /**
  333. * Get the player id of the player who originally sent the command.
  334. */
  335. UnsignedByte NetAckStage2CommandMsg::getOriginalPlayerID() {
  336. return m_originalPlayerID;
  337. }
  338. /**
  339. * Set the player id of the player who originally sent the command.
  340. */
  341. void NetAckStage2CommandMsg::setOriginalPlayerID(UnsignedByte originalPlayerID) {
  342. m_originalPlayerID = originalPlayerID;
  343. }
  344. Int NetAckStage2CommandMsg::getSortNumber() {
  345. return m_commandID;
  346. }
  347. //-------------------------
  348. // NetFrameCommandMsg
  349. //-------------------------
  350. /**
  351. * Constructor.
  352. */
  353. NetFrameCommandMsg::NetFrameCommandMsg() : NetCommandMsg() {
  354. m_commandCount = 0;
  355. m_commandType = NETCOMMANDTYPE_FRAMEINFO;
  356. }
  357. /**
  358. * Destructor
  359. */
  360. NetFrameCommandMsg::~NetFrameCommandMsg() {
  361. }
  362. /**
  363. * Set the command count of this frame.
  364. */
  365. void NetFrameCommandMsg::setCommandCount(UnsignedShort commandCount) {
  366. m_commandCount = commandCount;
  367. }
  368. /**
  369. * Return the command count of this frame.
  370. */
  371. UnsignedShort NetFrameCommandMsg::getCommandCount() {
  372. return m_commandCount;
  373. }
  374. //-------------------------
  375. // NetPlayerLeaveCommandMsg
  376. //-------------------------
  377. /**
  378. * Constructor
  379. */
  380. NetPlayerLeaveCommandMsg::NetPlayerLeaveCommandMsg() : NetCommandMsg() {
  381. m_leavingPlayerID = 0;
  382. m_commandType = NETCOMMANDTYPE_PLAYERLEAVE;
  383. }
  384. /**
  385. * Destructor
  386. */
  387. NetPlayerLeaveCommandMsg::~NetPlayerLeaveCommandMsg() {
  388. }
  389. /**
  390. * Get the id of the player leaving the game.
  391. */
  392. UnsignedByte NetPlayerLeaveCommandMsg::getLeavingPlayerID() {
  393. return m_leavingPlayerID;
  394. }
  395. /**
  396. * Set the id of the player leaving the game.
  397. */
  398. void NetPlayerLeaveCommandMsg::setLeavingPlayerID(UnsignedByte id) {
  399. m_leavingPlayerID = id;
  400. }
  401. //-------------------------
  402. // NetRunAheadMetricsCommandMsg
  403. //-------------------------
  404. /**
  405. * Constructor
  406. */
  407. NetRunAheadMetricsCommandMsg::NetRunAheadMetricsCommandMsg() : NetCommandMsg() {
  408. m_averageLatency = 0.0;
  409. m_averageFps = 0;
  410. m_commandType = NETCOMMANDTYPE_RUNAHEADMETRICS;
  411. }
  412. /**
  413. * Destructor
  414. */
  415. NetRunAheadMetricsCommandMsg::~NetRunAheadMetricsCommandMsg() {
  416. }
  417. /**
  418. * set the average latency
  419. */
  420. void NetRunAheadMetricsCommandMsg::setAverageLatency(Real avgLat) {
  421. m_averageLatency = avgLat;
  422. }
  423. /**
  424. * get the average latency
  425. */
  426. Real NetRunAheadMetricsCommandMsg::getAverageLatency() {
  427. return m_averageLatency;
  428. }
  429. /**
  430. * set the average fps
  431. */
  432. void NetRunAheadMetricsCommandMsg::setAverageFps(Int fps) {
  433. m_averageFps = fps;
  434. }
  435. /**
  436. * get the average fps
  437. */
  438. Int NetRunAheadMetricsCommandMsg::getAverageFps() {
  439. return m_averageFps;
  440. }
  441. //-------------------------
  442. // NetRunAheadCommandMsg
  443. //-------------------------
  444. NetRunAheadCommandMsg::NetRunAheadCommandMsg() : NetCommandMsg() {
  445. m_runAhead = min(max(20, MIN_RUNAHEAD), MAX_FRAMES_AHEAD/2);
  446. m_frameRate = 30;
  447. m_commandType = NETCOMMANDTYPE_RUNAHEAD;
  448. }
  449. NetRunAheadCommandMsg::~NetRunAheadCommandMsg() {
  450. }
  451. UnsignedShort NetRunAheadCommandMsg::getRunAhead() {
  452. return m_runAhead;
  453. }
  454. void NetRunAheadCommandMsg::setRunAhead(UnsignedShort runAhead) {
  455. m_runAhead = runAhead;
  456. }
  457. UnsignedByte NetRunAheadCommandMsg::getFrameRate() {
  458. return m_frameRate;
  459. }
  460. void NetRunAheadCommandMsg::setFrameRate(UnsignedByte frameRate) {
  461. m_frameRate = frameRate;
  462. }
  463. //-------------------------
  464. // NetDestroyPlayerCommandMsg
  465. //-------------------------
  466. /**
  467. * Constructor
  468. */
  469. NetDestroyPlayerCommandMsg::NetDestroyPlayerCommandMsg() : NetCommandMsg()
  470. {
  471. m_playerIndex = 0;
  472. m_commandType = NETCOMMANDTYPE_DESTROYPLAYER;
  473. }
  474. /**
  475. * Destructor
  476. */
  477. NetDestroyPlayerCommandMsg::~NetDestroyPlayerCommandMsg()
  478. {
  479. }
  480. /**
  481. * set the CRC
  482. */
  483. void NetDestroyPlayerCommandMsg::setPlayerIndex( UnsignedInt playerIndex )
  484. {
  485. m_playerIndex = playerIndex;
  486. }
  487. /**
  488. * get the average CRC
  489. */
  490. UnsignedInt NetDestroyPlayerCommandMsg::getPlayerIndex( void )
  491. {
  492. return m_playerIndex;
  493. }
  494. //-------------------------
  495. // NetKeepAliveCommandMsg
  496. //-------------------------
  497. /**
  498. * Constructor
  499. */
  500. NetKeepAliveCommandMsg::NetKeepAliveCommandMsg() : NetCommandMsg() {
  501. m_commandType = NETCOMMANDTYPE_KEEPALIVE;
  502. }
  503. NetKeepAliveCommandMsg::~NetKeepAliveCommandMsg() {
  504. }
  505. //-------------------------
  506. // NetDisconnectKeepAliveCommandMsg
  507. //-------------------------
  508. /**
  509. * Constructor
  510. */
  511. NetDisconnectKeepAliveCommandMsg::NetDisconnectKeepAliveCommandMsg() : NetCommandMsg() {
  512. m_commandType = NETCOMMANDTYPE_DISCONNECTKEEPALIVE;
  513. }
  514. NetDisconnectKeepAliveCommandMsg::~NetDisconnectKeepAliveCommandMsg() {
  515. }
  516. //-------------------------
  517. // NetDisconnectPlayerCommandMsg
  518. //-------------------------
  519. /**
  520. * Constructor
  521. */
  522. NetDisconnectPlayerCommandMsg::NetDisconnectPlayerCommandMsg() : NetCommandMsg() {
  523. m_commandType = NETCOMMANDTYPE_DISCONNECTPLAYER;
  524. m_disconnectSlot = 0;
  525. }
  526. /**
  527. * Destructor
  528. */
  529. NetDisconnectPlayerCommandMsg::~NetDisconnectPlayerCommandMsg() {
  530. }
  531. /**
  532. * Returns the disconnecting slot number
  533. */
  534. UnsignedByte NetDisconnectPlayerCommandMsg::getDisconnectSlot() {
  535. return m_disconnectSlot;
  536. }
  537. /**
  538. * Sets the disconnecting slot number
  539. */
  540. void NetDisconnectPlayerCommandMsg::setDisconnectSlot(UnsignedByte slot) {
  541. m_disconnectSlot = slot;
  542. }
  543. /**
  544. * Sets the disconnect frame
  545. */
  546. void NetDisconnectPlayerCommandMsg::setDisconnectFrame(UnsignedInt frame) {
  547. m_disconnectFrame = frame;
  548. }
  549. /**
  550. * returns the disconnect frame
  551. */
  552. UnsignedInt NetDisconnectPlayerCommandMsg::getDisconnectFrame() {
  553. return m_disconnectFrame;
  554. }
  555. //-------------------------
  556. // NetPacketRouterQueryCommandMsg
  557. //-------------------------
  558. /**
  559. * Constructor
  560. */
  561. NetPacketRouterQueryCommandMsg::NetPacketRouterQueryCommandMsg() : NetCommandMsg() {
  562. m_commandType = NETCOMMANDTYPE_PACKETROUTERQUERY;
  563. }
  564. /**
  565. * Destructor
  566. */
  567. NetPacketRouterQueryCommandMsg::~NetPacketRouterQueryCommandMsg() {
  568. }
  569. //-------------------------
  570. // NetPacketRouterAckCommandMsg
  571. //-------------------------
  572. /**
  573. * Constructor
  574. */
  575. NetPacketRouterAckCommandMsg::NetPacketRouterAckCommandMsg() : NetCommandMsg() {
  576. m_commandType = NETCOMMANDTYPE_PACKETROUTERACK;
  577. }
  578. /**
  579. * Destructor
  580. */
  581. NetPacketRouterAckCommandMsg::~NetPacketRouterAckCommandMsg() {
  582. }
  583. //-------------------------
  584. // NetDisconnectChatCommandMsg
  585. //-------------------------
  586. /**
  587. * Constructor
  588. */
  589. NetDisconnectChatCommandMsg::NetDisconnectChatCommandMsg() : NetCommandMsg() {
  590. m_commandType = NETCOMMANDTYPE_DISCONNECTCHAT;
  591. }
  592. /**
  593. * Destructor
  594. */
  595. NetDisconnectChatCommandMsg::~NetDisconnectChatCommandMsg() {
  596. }
  597. /**
  598. * Set the chat text for this message.
  599. */
  600. void NetDisconnectChatCommandMsg::setText(UnicodeString text) {
  601. m_text = text;
  602. }
  603. /**
  604. * Get the chat text for this message.
  605. */
  606. UnicodeString NetDisconnectChatCommandMsg::getText() {
  607. return m_text;
  608. }
  609. //-------------------------
  610. // NetChatCommandMsg
  611. //-------------------------
  612. /**
  613. * Constructor
  614. */
  615. NetChatCommandMsg::NetChatCommandMsg() : NetCommandMsg()
  616. {
  617. m_commandType = NETCOMMANDTYPE_CHAT;
  618. //added by Sadullah Nader
  619. //Initializations inserted
  620. m_playerMask = 0;
  621. //
  622. }
  623. /**
  624. * Destructor
  625. */
  626. NetChatCommandMsg::~NetChatCommandMsg()
  627. {
  628. }
  629. /**
  630. * Set the chat text for this message.
  631. */
  632. void NetChatCommandMsg::setText(UnicodeString text)
  633. {
  634. m_text = text;
  635. }
  636. /**
  637. * Get the chat text for this message.
  638. */
  639. UnicodeString NetChatCommandMsg::getText()
  640. {
  641. return m_text;
  642. }
  643. /**
  644. * Get the bitmask of chat recipients from this message.
  645. */
  646. Int NetChatCommandMsg::getPlayerMask()
  647. {
  648. return m_playerMask;
  649. }
  650. /**
  651. * Set a bitmask of chat recipients in this message.
  652. */
  653. void NetChatCommandMsg::setPlayerMask( Int playerMask )
  654. {
  655. m_playerMask = playerMask;
  656. }
  657. //-------------------------
  658. // NetDisconnectVoteCommandMsg
  659. //-------------------------
  660. /**
  661. * Constructor
  662. */
  663. NetDisconnectVoteCommandMsg::NetDisconnectVoteCommandMsg() : NetCommandMsg() {
  664. m_commandType = NETCOMMANDTYPE_DISCONNECTVOTE;
  665. m_slot = 0;
  666. }
  667. /**
  668. * Destructor
  669. */
  670. NetDisconnectVoteCommandMsg::~NetDisconnectVoteCommandMsg() {
  671. }
  672. /**
  673. * Set the slot that is being voted for.
  674. */
  675. void NetDisconnectVoteCommandMsg::setSlot(UnsignedByte slot) {
  676. m_slot = slot;
  677. }
  678. /**
  679. * Get the slot that is being voted for.
  680. */
  681. UnsignedByte NetDisconnectVoteCommandMsg::getSlot() {
  682. return m_slot;
  683. }
  684. /**
  685. * Get the vote frame.
  686. */
  687. UnsignedInt NetDisconnectVoteCommandMsg::getVoteFrame() {
  688. return m_voteFrame;
  689. }
  690. /**
  691. * Set the vote frame.
  692. */
  693. void NetDisconnectVoteCommandMsg::setVoteFrame(UnsignedInt voteFrame) {
  694. m_voteFrame = voteFrame;
  695. }
  696. //-------------------------
  697. // NetProgressCommandMsg
  698. //-------------------------
  699. NetProgressCommandMsg::NetProgressCommandMsg( void ) : NetCommandMsg()
  700. {
  701. m_commandType = NETCOMMANDTYPE_PROGRESS;
  702. m_percent = 0;
  703. }
  704. NetProgressCommandMsg::~NetProgressCommandMsg( void ) {}
  705. UnsignedByte NetProgressCommandMsg::getPercentage()
  706. {
  707. return m_percent;
  708. }
  709. void NetProgressCommandMsg::setPercentage( UnsignedByte percent )
  710. {
  711. m_percent = percent;
  712. }
  713. //-------------------------
  714. // NetWrapperCommandMsg
  715. //-------------------------
  716. NetWrapperCommandMsg::NetWrapperCommandMsg() : NetCommandMsg() {
  717. m_commandType = NETCOMMANDTYPE_WRAPPER;
  718. m_numChunks = 0;
  719. m_data = NULL;
  720. m_totalDataLength = 0;
  721. m_chunkNumber = 0;
  722. m_dataLength = 0;
  723. m_dataOffset = 0;
  724. m_wrappedCommandID = 0;
  725. }
  726. NetWrapperCommandMsg::~NetWrapperCommandMsg() {
  727. if (m_data != NULL) {
  728. delete m_data;
  729. m_data = NULL;
  730. }
  731. }
  732. UnsignedByte * NetWrapperCommandMsg::getData() {
  733. return m_data;
  734. }
  735. void NetWrapperCommandMsg::setData(UnsignedByte *data, UnsignedInt dataLength)
  736. {
  737. if (m_data != NULL) {
  738. delete m_data;
  739. m_data = NULL;
  740. }
  741. m_data = NEW UnsignedByte[dataLength]; // pool[]ify
  742. memcpy(m_data, data, dataLength);
  743. m_dataLength = dataLength;
  744. }
  745. UnsignedInt NetWrapperCommandMsg::getDataLength() {
  746. return m_dataLength;
  747. }
  748. UnsignedInt NetWrapperCommandMsg::getDataOffset() {
  749. return m_dataOffset;
  750. }
  751. void NetWrapperCommandMsg::setDataOffset(UnsignedInt offset) {
  752. m_dataOffset = offset;
  753. }
  754. UnsignedInt NetWrapperCommandMsg::getChunkNumber() {
  755. return m_chunkNumber;
  756. }
  757. void NetWrapperCommandMsg::setChunkNumber(UnsignedInt chunkNumber) {
  758. m_chunkNumber = chunkNumber;
  759. }
  760. UnsignedInt NetWrapperCommandMsg::getNumChunks() {
  761. return m_numChunks;
  762. }
  763. void NetWrapperCommandMsg::setNumChunks(UnsignedInt numChunks) {
  764. m_numChunks = numChunks;
  765. }
  766. UnsignedInt NetWrapperCommandMsg::getTotalDataLength() {
  767. return m_totalDataLength;
  768. }
  769. void NetWrapperCommandMsg::setTotalDataLength(UnsignedInt totalDataLength) {
  770. m_totalDataLength = totalDataLength;
  771. }
  772. UnsignedShort NetWrapperCommandMsg::getWrappedCommandID() {
  773. return m_wrappedCommandID;
  774. }
  775. void NetWrapperCommandMsg::setWrappedCommandID(UnsignedShort wrappedCommandID) {
  776. m_wrappedCommandID = wrappedCommandID;
  777. }
  778. //-------------------------
  779. // NetFileCommandMsg
  780. //-------------------------
  781. NetFileCommandMsg::NetFileCommandMsg() : NetCommandMsg() {
  782. m_commandType = NETCOMMANDTYPE_FILE;
  783. m_data = NULL;
  784. m_portableFilename.clear();
  785. m_dataLength = 0;
  786. }
  787. NetFileCommandMsg::~NetFileCommandMsg() {
  788. if (m_data != NULL) {
  789. delete[] m_data;
  790. m_data = NULL;
  791. }
  792. }
  793. AsciiString NetFileCommandMsg::getRealFilename()
  794. {
  795. return TheGameState->portableMapPathToRealMapPath(m_portableFilename);
  796. }
  797. void NetFileCommandMsg::setRealFilename(AsciiString filename)
  798. {
  799. m_portableFilename = TheGameState->realMapPathToPortableMapPath(filename);
  800. }
  801. UnsignedInt NetFileCommandMsg::getFileLength() {
  802. return m_dataLength;
  803. }
  804. UnsignedByte * NetFileCommandMsg::getFileData() {
  805. return m_data;
  806. }
  807. void NetFileCommandMsg::setFileData(UnsignedByte *data, UnsignedInt dataLength)
  808. {
  809. m_dataLength = dataLength;
  810. m_data = NEW UnsignedByte[dataLength]; // pool[]ify
  811. memcpy(m_data, data, dataLength);
  812. }
  813. //-------------------------
  814. // NetFileAnnounceCommandMsg
  815. //-------------------------
  816. NetFileAnnounceCommandMsg::NetFileAnnounceCommandMsg() : NetCommandMsg() {
  817. m_commandType = NETCOMMANDTYPE_FILEANNOUNCE;
  818. m_portableFilename.clear();
  819. m_fileID = 0;
  820. m_playerMask = 0;
  821. }
  822. NetFileAnnounceCommandMsg::~NetFileAnnounceCommandMsg() {
  823. }
  824. AsciiString NetFileAnnounceCommandMsg::getRealFilename()
  825. {
  826. return TheGameState->portableMapPathToRealMapPath(m_portableFilename);
  827. }
  828. void NetFileAnnounceCommandMsg::setRealFilename(AsciiString filename)
  829. {
  830. m_portableFilename = TheGameState->realMapPathToPortableMapPath(filename);
  831. }
  832. UnsignedShort NetFileAnnounceCommandMsg::getFileID() {
  833. return m_fileID;
  834. }
  835. void NetFileAnnounceCommandMsg::setFileID(UnsignedShort fileID) {
  836. m_fileID = fileID;
  837. }
  838. UnsignedByte NetFileAnnounceCommandMsg::getPlayerMask(void) {
  839. return m_playerMask;
  840. }
  841. void NetFileAnnounceCommandMsg::setPlayerMask(UnsignedByte playerMask) {
  842. m_playerMask = playerMask;
  843. }
  844. //-------------------------
  845. // NetFileProgressCommandMsg
  846. //-------------------------
  847. NetFileProgressCommandMsg::NetFileProgressCommandMsg() : NetCommandMsg() {
  848. m_commandType = NETCOMMANDTYPE_FILEPROGRESS;
  849. m_fileID = 0;
  850. m_progress = 0;
  851. }
  852. NetFileProgressCommandMsg::~NetFileProgressCommandMsg() {
  853. }
  854. UnsignedShort NetFileProgressCommandMsg::getFileID() {
  855. return m_fileID;
  856. }
  857. void NetFileProgressCommandMsg::setFileID(UnsignedShort val) {
  858. m_fileID = val;
  859. }
  860. Int NetFileProgressCommandMsg::getProgress() {
  861. return m_progress;
  862. }
  863. void NetFileProgressCommandMsg::setProgress(Int val) {
  864. m_progress = val;
  865. }
  866. //-------------------------
  867. // NetDisconnectFrameCommandMsg
  868. //-------------------------
  869. NetDisconnectFrameCommandMsg::NetDisconnectFrameCommandMsg() : NetCommandMsg() {
  870. m_commandType = NETCOMMANDTYPE_DISCONNECTFRAME;
  871. m_disconnectFrame = 0;
  872. }
  873. NetDisconnectFrameCommandMsg::~NetDisconnectFrameCommandMsg() {
  874. }
  875. UnsignedInt NetDisconnectFrameCommandMsg::getDisconnectFrame() {
  876. return m_disconnectFrame;
  877. }
  878. void NetDisconnectFrameCommandMsg::setDisconnectFrame(UnsignedInt disconnectFrame) {
  879. m_disconnectFrame = disconnectFrame;
  880. }
  881. //-------------------------
  882. // NetDisconnectScreenOffCommandMsg
  883. //-------------------------
  884. NetDisconnectScreenOffCommandMsg::NetDisconnectScreenOffCommandMsg() : NetCommandMsg() {
  885. m_commandType = NETCOMMANDTYPE_DISCONNECTSCREENOFF;
  886. m_newFrame = 0;
  887. }
  888. NetDisconnectScreenOffCommandMsg::~NetDisconnectScreenOffCommandMsg() {
  889. }
  890. UnsignedInt NetDisconnectScreenOffCommandMsg::getNewFrame() {
  891. return m_newFrame;
  892. }
  893. void NetDisconnectScreenOffCommandMsg::setNewFrame(UnsignedInt newFrame) {
  894. m_newFrame = newFrame;
  895. }
  896. //-------------------------
  897. // NetFrameResendRequestCommandMsg
  898. //-------------------------
  899. NetFrameResendRequestCommandMsg::NetFrameResendRequestCommandMsg() : NetCommandMsg() {
  900. m_commandType = NETCOMMANDTYPE_FRAMERESENDREQUEST;
  901. m_frameToResend = 0;
  902. }
  903. NetFrameResendRequestCommandMsg::~NetFrameResendRequestCommandMsg() {
  904. }
  905. UnsignedInt NetFrameResendRequestCommandMsg::getFrameToResend() {
  906. return m_frameToResend;
  907. }
  908. void NetFrameResendRequestCommandMsg::setFrameToResend(UnsignedInt frame) {
  909. m_frameToResend = frame;
  910. }