Clone of UAS2 @ https://github.com/drudgedance/uas2

Client.cpp 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * This file is part of UAS2.
  3. *
  4. * UAS2 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 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * UAS2 is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. * You should have received a copy of the GNU General Public License
  14. * along with UASv1; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /**
  18. * @file cClient.cpp
  19. * Implements functionality for the cClient class.
  20. */
  21. #include "Client.h"
  22. #include "WorldManager.h"
  23. cClient *cClient::m_lpcHashTable[1020];
  24. /**
  25. * Erases all clients from the client hash list.
  26. */
  27. void cClient::Hash_Erase( )
  28. {
  29. cClient *pcClient, *pcPrevClient;
  30. for ( int i = 0; i < 1020; ++i )
  31. {
  32. pcClient = m_lpcHashTable[i];
  33. while ( pcClient )
  34. {
  35. pcPrevClient = pcClient;
  36. pcClient = pcClient->m_pcNext;
  37. Hash_Remove( pcPrevClient );
  38. }
  39. }
  40. }
  41. /**
  42. * Removes a client from the client hash list.
  43. *
  44. * This function is called when a client disconnects from the server.
  45. *
  46. * @param *pcClient - A pointer to the client to be removed.
  47. */
  48. void cClient::Hash_Remove( cClient *pcClient )
  49. {
  50. if ( pcClient->m_pcAvatar )
  51. {
  52. pcClient->m_pcAvatar->SaveToDB();
  53. cWorldManager::RemoveClient( pcClient );
  54. }
  55. SAFEDELETE( pcClient )
  56. }
  57. /**
  58. * Finds a client.
  59. *
  60. * This function is called when a particular client needs to be found.
  61. * The search is performed by searching for the client's avatar's GUID.
  62. *
  63. * @param dwGUID - The client's avatar's GUID.
  64. *
  65. * @return *cClient - A pointer to the client.
  66. */
  67. cClient *cClient::FindClient( DWORD dwGUID )
  68. {
  69. cClient *pcClient;
  70. for ( int i = 0; i < 1020; ++i )
  71. {
  72. pcClient = m_lpcHashTable[i];
  73. while ( pcClient )
  74. {
  75. if ( pcClient->m_pcAvatar )
  76. {
  77. if ( dwGUID == pcClient->m_pcAvatar->GetGUID( ) )
  78. return pcClient;
  79. }
  80. pcClient = pcClient->m_pcNext;
  81. }
  82. }
  83. return NULL;
  84. }
  85. /**
  86. * Finds a client.
  87. *
  88. * This function is called when a particular client needs to be found.
  89. * The search is performed by searching for the client's avatar's name.
  90. *
  91. * @param szName - The client's avatar's name.
  92. *
  93. * @return *cClient - A pointer to the client.
  94. */
  95. cClient *cClient::FindClient( char *szName )
  96. {
  97. cClient *pcClient;
  98. for ( int i = 0; i < 1020; ++i )
  99. {
  100. pcClient = m_lpcHashTable[i];
  101. while ( pcClient )
  102. {
  103. if ( pcClient->m_pcAvatar )
  104. {
  105. if ( !lstrcmpi( szName, pcClient->m_pcAvatar->TokenlessName( ) ) )
  106. return pcClient;
  107. }
  108. pcClient = pcClient->m_pcNext;
  109. }
  110. }
  111. return NULL;
  112. }
  113. /**
  114. * Finds an avatar.
  115. *
  116. * This function is called when a particular avatar needs to be found.
  117. * The search is performed by searching for the client's avatar's GUID.
  118. *
  119. * @param dwGUID - The client's avatar's GUID.
  120. *
  121. * @return *cAvatar - A pointer to the avatar.
  122. */
  123. cAvatar *cClient::FindAvatar( DWORD dwGUID )
  124. {
  125. cClient *pcClient;
  126. for ( int i = 0; i < 1020; ++i )
  127. {
  128. pcClient = m_lpcHashTable[i];
  129. while ( pcClient )
  130. {
  131. if ( pcClient->m_pcAvatar )
  132. {
  133. if ( dwGUID == pcClient->m_pcAvatar->GetGUID( ) )
  134. return pcClient->m_pcAvatar;
  135. }
  136. pcClient = pcClient->m_pcNext;
  137. }
  138. }
  139. return NULL;
  140. }
  141. /**
  142. * Finds an avatar.
  143. *
  144. * This function is called when a particular avatar needs to be found.
  145. * The search is performed by searching for the client's avatar's name.
  146. *
  147. * @param szName - The client's avatar's name.
  148. *
  149. * @return *cAvatar - A pointer to the avatar.
  150. */
  151. cAvatar *cClient::FindAvatar( char *szName )
  152. {
  153. cClient *pcClient;
  154. for ( int i = 0; i < 1020; ++i )
  155. {
  156. pcClient = m_lpcHashTable[i];
  157. while ( pcClient )
  158. {
  159. if ( pcClient->m_pcAvatar )
  160. {
  161. if ( !lstrcmpi( szName, pcClient->m_pcAvatar->TokenlessName( ) ) )
  162. return pcClient->m_pcAvatar;
  163. }
  164. pcClient = pcClient->m_pcNext;
  165. }
  166. }
  167. return NULL;
  168. }