VNetState.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //-----------------------------------------------------------------------------
  2. // Verve
  3. // Copyright (C) 2014 - Violent Tulip
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //-----------------------------------------------------------------------------
  23. #include "VNetState.h"
  24. //-----------------------------------------------------------------------------
  25. U32 VNetState::gInvalidMask = 0;
  26. //-----------------------------------------------------------------------------
  27. VNetState::VNetState() :
  28. mMask( 0 )
  29. {
  30. }
  31. VNetState::~VNetState( void )
  32. {
  33. for ( VNetState::iterator itr = begin(); itr != end(); itr++ )
  34. {
  35. // Fetch info.
  36. VNetStateInfo *state = ( *itr );
  37. // Delete State.
  38. delete state;
  39. }
  40. // Clear.
  41. clear();
  42. }
  43. //-----------------------------------------------------------------------------
  44. //
  45. // Connection Methods.
  46. //
  47. //-----------------------------------------------------------------------------
  48. bool VNetState::isConnection( NetConnection *pConnection )
  49. {
  50. for ( VNetState::iterator itr = begin(); itr != end(); itr++ )
  51. {
  52. VNetStateInfo *state = ( *itr );
  53. if ( state->Connection == pConnection )
  54. {
  55. // Valid.
  56. return true;
  57. }
  58. }
  59. // Invalid.
  60. return false;
  61. }
  62. void VNetState::addConnection( NetConnection *pConnection )
  63. {
  64. // Init State.
  65. VNetStateInfo *state = new VNetStateInfo( pConnection, mMask );
  66. // Add.
  67. push_back( state );
  68. }
  69. void VNetState::clearConnection( NetConnection *pConnection )
  70. {
  71. for ( VNetState::iterator itr = begin(); itr != end(); itr++ )
  72. {
  73. VNetStateInfo *state = ( *itr );
  74. if ( state->Connection == pConnection )
  75. {
  76. // Delete.
  77. delete state;
  78. // Erase.
  79. erase( itr );
  80. // Quit.
  81. return;
  82. }
  83. }
  84. }
  85. //-----------------------------------------------------------------------------
  86. //
  87. // Mask Methods.
  88. //
  89. //-----------------------------------------------------------------------------
  90. VNetStateInfo *VNetState::getState( NetConnection *pConnection )
  91. {
  92. for ( VNetState::iterator itr = begin(); itr != end(); itr++ )
  93. {
  94. VNetStateInfo *state = ( *itr );
  95. if ( state->Connection == pConnection )
  96. {
  97. return state;
  98. }
  99. }
  100. return NULL;
  101. }
  102. void VNetState::setMaskBits( const U32 &pMask )
  103. {
  104. // Apply Mask.
  105. mMask |= pMask;
  106. for ( VNetState::iterator itr = begin(); itr != end(); itr++ )
  107. {
  108. // Fetch info.
  109. VNetStateInfo *state = ( *itr );
  110. // Apply Mask.
  111. state->Mask |= pMask;
  112. }
  113. }
  114. void VNetState::clearMaskBits( const U32 &pMask )
  115. {
  116. // Clear Mask.
  117. mMask &= ~pMask;
  118. for ( VNetState::iterator itr = begin(); itr != end(); itr++ )
  119. {
  120. // Fetch info.
  121. VNetStateInfo *state = ( *itr );
  122. // Clear Mask.
  123. state->Mask &= ~pMask;
  124. }
  125. }