NetworkSystem.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code 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. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "../../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "NetworkSystem.h"
  23. idNetworkSystem networkSystemLocal;
  24. idNetworkSystem * networkSystem = &networkSystemLocal;
  25. /*
  26. ==================
  27. idNetworkSystem::ServerSendReliableMessage
  28. ==================
  29. */
  30. void idNetworkSystem::ServerSendReliableMessage( int clientNum, const idBitMsg &msg ) {
  31. if ( idAsyncNetwork::server.IsActive() ) {
  32. idAsyncNetwork::server.SendReliableGameMessage( clientNum, msg );
  33. }
  34. }
  35. /*
  36. ==================
  37. idNetworkSystem::ServerSendReliableMessageExcluding
  38. ==================
  39. */
  40. void idNetworkSystem::ServerSendReliableMessageExcluding( int clientNum, const idBitMsg &msg ) {
  41. if ( idAsyncNetwork::server.IsActive() ) {
  42. idAsyncNetwork::server.SendReliableGameMessageExcluding( clientNum, msg );
  43. }
  44. }
  45. /*
  46. ==================
  47. idNetworkSystem::ServerGetClientPing
  48. ==================
  49. */
  50. int idNetworkSystem::ServerGetClientPing( int clientNum ) {
  51. if ( idAsyncNetwork::server.IsActive() ) {
  52. return idAsyncNetwork::server.GetClientPing( clientNum );
  53. }
  54. return 0;
  55. }
  56. /*
  57. ==================
  58. idNetworkSystem::ServerGetClientPrediction
  59. ==================
  60. */
  61. int idNetworkSystem::ServerGetClientPrediction( int clientNum ) {
  62. if ( idAsyncNetwork::server.IsActive() ) {
  63. return idAsyncNetwork::server.GetClientPrediction( clientNum );
  64. }
  65. return 0;
  66. }
  67. /*
  68. ==================
  69. idNetworkSystem::ServerGetClientTimeSinceLastPacket
  70. ==================
  71. */
  72. int idNetworkSystem::ServerGetClientTimeSinceLastPacket( int clientNum ) {
  73. if ( idAsyncNetwork::server.IsActive() ) {
  74. return idAsyncNetwork::server.GetClientTimeSinceLastPacket( clientNum );
  75. }
  76. return 0;
  77. }
  78. /*
  79. ==================
  80. idNetworkSystem::ServerGetClientTimeSinceLastInput
  81. ==================
  82. */
  83. int idNetworkSystem::ServerGetClientTimeSinceLastInput( int clientNum ) {
  84. if ( idAsyncNetwork::server.IsActive() ) {
  85. return idAsyncNetwork::server.GetClientTimeSinceLastInput( clientNum );
  86. }
  87. return 0;
  88. }
  89. /*
  90. ==================
  91. idNetworkSystem::ServerGetClientOutgoingRate
  92. ==================
  93. */
  94. int idNetworkSystem::ServerGetClientOutgoingRate( int clientNum ) {
  95. if ( idAsyncNetwork::server.IsActive() ) {
  96. return idAsyncNetwork::server.GetClientOutgoingRate( clientNum );
  97. }
  98. return 0;
  99. }
  100. /*
  101. ==================
  102. idNetworkSystem::ServerGetClientIncomingRate
  103. ==================
  104. */
  105. int idNetworkSystem::ServerGetClientIncomingRate( int clientNum ) {
  106. if ( idAsyncNetwork::server.IsActive() ) {
  107. return idAsyncNetwork::server.GetClientIncomingRate( clientNum );
  108. }
  109. return 0;
  110. }
  111. /*
  112. ==================
  113. idNetworkSystem::ServerGetClientIncomingPacketLoss
  114. ==================
  115. */
  116. float idNetworkSystem::ServerGetClientIncomingPacketLoss( int clientNum ) {
  117. if ( idAsyncNetwork::server.IsActive() ) {
  118. return idAsyncNetwork::server.GetClientIncomingPacketLoss( clientNum );
  119. }
  120. return 0.0f;
  121. }
  122. /*
  123. ==================
  124. idNetworkSystem::ClientSendReliableMessage
  125. ==================
  126. */
  127. void idNetworkSystem::ClientSendReliableMessage( const idBitMsg &msg ) {
  128. if ( idAsyncNetwork::client.IsActive() ) {
  129. idAsyncNetwork::client.SendReliableGameMessage( msg );
  130. } else if ( idAsyncNetwork::server.IsActive() ) {
  131. idAsyncNetwork::server.LocalClientSendReliableMessage( msg );
  132. }
  133. }
  134. /*
  135. ==================
  136. idNetworkSystem::ClientGetPrediction
  137. ==================
  138. */
  139. int idNetworkSystem::ClientGetPrediction( void ) {
  140. if ( idAsyncNetwork::client.IsActive() ) {
  141. return idAsyncNetwork::client.GetPrediction();
  142. }
  143. return 0;
  144. }
  145. /*
  146. ==================
  147. idNetworkSystem::ClientGetTimeSinceLastPacket
  148. ==================
  149. */
  150. int idNetworkSystem::ClientGetTimeSinceLastPacket( void ) {
  151. if ( idAsyncNetwork::client.IsActive() ) {
  152. return idAsyncNetwork::client.GetTimeSinceLastPacket();
  153. }
  154. return 0;
  155. }
  156. /*
  157. ==================
  158. idNetworkSystem::ClientGetOutgoingRate
  159. ==================
  160. */
  161. int idNetworkSystem::ClientGetOutgoingRate( void ) {
  162. if ( idAsyncNetwork::client.IsActive() ) {
  163. return idAsyncNetwork::client.GetOutgoingRate();
  164. }
  165. return 0;
  166. }
  167. /*
  168. ==================
  169. idNetworkSystem::ClientGetIncomingRate
  170. ==================
  171. */
  172. int idNetworkSystem::ClientGetIncomingRate( void ) {
  173. if ( idAsyncNetwork::client.IsActive() ) {
  174. return idAsyncNetwork::client.GetIncomingRate();
  175. }
  176. return 0;
  177. }
  178. /*
  179. ==================
  180. idNetworkSystem::ClientGetIncomingPacketLoss
  181. ==================
  182. */
  183. float idNetworkSystem::ClientGetIncomingPacketLoss( void ) {
  184. if ( idAsyncNetwork::client.IsActive() ) {
  185. return idAsyncNetwork::client.GetIncomingPacketLoss();
  186. }
  187. return 0.0f;
  188. }