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

cHouse.cpp 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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 cHouse.cpp
  19. * Implements functionality for house objects.
  20. *
  21. * This class is referenced whenever a house object is created, used, or assessed.
  22. * Inherits from the cObject class.
  23. */
  24. #include "object.h"
  25. #include "masterserver.h"
  26. #include "worldmanager.h"
  27. /***************
  28. * constructors
  29. **************/
  30. /**
  31. * Handles the creation of houses.
  32. *
  33. * Called whenever a house object should be initialized.
  34. *
  35. * Generally, house objects reside where the house models are located in the world.
  36. * By default, the houses are inaccessable (restricted client-side) by characters unless the proper house object is created.
  37. */
  38. cHouse::cHouse( char *szName, char *szDescription, WORD type, DWORD dwGUID, cLocation *pcLoc )
  39. {
  40. SetLocation( pcLoc );
  41. m_dwGUID = dwGUID;
  42. m_strName.assign( szName );
  43. m_strDescription.assign( szDescription );
  44. m_dwModel = type;
  45. m_fStatic = TRUE;
  46. }
  47. /**********
  48. * methods
  49. *********/
  50. /**
  51. * Handles the message sent for the creation of house objects in the world.
  52. *
  53. * This function is called whenever a house object should be created in the world for a client.
  54. *
  55. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  56. */
  57. cMessage cHouse::CreatePacket()
  58. {
  59. cMessage cmReturn;
  60. float flpScale; // Scale used in Packet being Sent
  61. float flmScale = 0.1f;// Model Data Scale
  62. /*
  63. wModelID
  64. 0x4720 apartment
  65. 0x4727 apartment
  66. 0x5130 cottage
  67. 0x512E cottage
  68. 0x512F cottage
  69. 0x36A0 cottage
  70. 0x37A8 cottage
  71. 0x2920 villa
  72. 0x218B mansion
  73. wIconID
  74. 0x2181 apartment
  75. 0x2181 cottage
  76. 0x218E villa
  77. 0x218B mansion
  78. */
  79. cmReturn << 0xF745L
  80. << m_dwGUID
  81. << BYTE( 0x11 )
  82. << BYTE( 0 )
  83. << BYTE( 0 )
  84. << BYTE( 0 );
  85. DWORD dwFlags1 = 0x00028081;// Flags 1 defines whats next
  86. cmReturn << dwFlags1;
  87. cmReturn << 0x00000034; // Unknown
  88. // Flags1 Mask 0x00028081
  89. {
  90. // Flags1 & 0x00020000 -- Unknown DWORD
  91. cmReturn << 0x00000065;
  92. // Flags1 & 0x00008000 -- Location
  93. cmReturn.pasteData( (UCHAR*)&m_Location, sizeof(m_Location) ); //Next comes the location
  94. // Flags1 & 0x00000001
  95. //DWORD dwModel = 0x02000001; // the model.
  96. DWORD dwModel = 0x02000000L + m_dwModel;
  97. cmReturn << dwModel; // dwModel;
  98. // Flags1 & 0x00000080 -- unknown_green
  99. flpScale = 0.1f; // FLOAT flpScale
  100. cmReturn << flpScale;
  101. }
  102. //Next comes some unknown flags...these flags contain information such
  103. //as whether or not the object is solid (collision detection), the radar color
  104. //PK information, and more. I will crack these some time
  105. // SeaGreens
  106. WORD wUnkFlag2 = 0x0000;
  107. WORD wUnkFlag3 = 0x0000;
  108. WORD wUnkFlag4 = 0x0000;
  109. WORD wUnkFlag6 = 0x0000;
  110. WORD wUnkFlag7 = 0x0000;
  111. WORD wUnkFlag8 = 0x0000;
  112. WORD wUnkFlag10 = 0x0000;
  113. cmReturn << WORD(0x0001) // m_wPositionSequence // movement 0x0001 (can also be 0x0000)
  114. << wUnkFlag2 // animations
  115. << wUnkFlag3 // bubble modes
  116. << wUnkFlag4 // num jumps
  117. << m_wNumPortals
  118. << wUnkFlag6 // anim count
  119. << wUnkFlag7 // overrides
  120. << wUnkFlag8
  121. << WORD(0x0D7F) // m_wNumLogins // 0x0D4B
  122. << wUnkFlag10;
  123. char szCommand[200];
  124. RETCODE retcode;
  125. // Flags2 -- Defines what data comes next
  126. DWORD dwFlags2;
  127. if (m_dwOwnerID) {
  128. dwFlags2 = 0x0E200010; // mask for owned dwelling
  129. } else {
  130. dwFlags2 = 0x0C200010; // mask for unowned dwelling (excludes owner)
  131. }
  132. cmReturn << dwFlags2;
  133. cmReturn << Name( ); // Object's Name
  134. cmReturn << m_wModel << m_wIcon;
  135. DWORD dwObjectFlags1 = 0x00000080; // 0x0080 Miscellaneous Object
  136. DWORD dwObjectFlags2 = 0x00000094; // 0x0004 - Cannot be picked up, 0x0080 Unknown - Cannot be selected 0x0010 Unknown - Can be selected.
  137. // appears to contradict it self; sets Cannot be Selected and Can be Selected. Housing Item, may set house open/closed
  138. cmReturn << dwObjectFlags1 << dwObjectFlags2;
  139. // Flags2 & 0x00000010 -- DWORD unknown10
  140. cmReturn << 0x00000001;
  141. // Flags2 & 0x08000000 -- WORD unknown8000000
  142. cmReturn << WORD(0x0098);
  143. // Flags2 & 0x00200000 -- WORD burden
  144. cmReturn << WORD(0x000A); // total burden of this object
  145. if (dwFlags2 == 0x0E200010) // if masked for owned dwelling
  146. {
  147. // Flags2 & 0x02000000 // ObjectID owner
  148. cmReturn << m_dwOwnerID;// the owner of the object
  149. }
  150. WORD wGuestCount = 0;
  151. char GuestIDBuff[9];
  152. DWORD GuestID = NULL;
  153. WORD StorageOpen;
  154. sprintf( szCommand, "SELECT COUNT(ID) FROM houses_guest_lists WHERE HouseID=%d;",m_wModel );
  155. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  156. retcode = SQLExecute( cDatabase::m_hStmt );
  157. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &wGuestCount, sizeof( wGuestCount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  158. retcode = SQLFetch( cDatabase::m_hStmt );
  159. if( retcode == SQL_NO_DATA )
  160. wGuestCount = 0;
  161. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  162. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  163. // Flags2 & 0x04000000 // Dwelling access control list
  164. cmReturn << 0x10000002 // DWORD flags -- believed to be flags that control the size and content of this structure
  165. << IsOpen // DWORD open: 0 = private dwelling, 1 = open to public
  166. << 0x00000000 // ObjectID allegiance -- allegiance monarch (if allegiance access granted)
  167. << wGuestCount // WORD guestCount -- number of guests on list
  168. << WORD(0x0300);// WORD guestLimit -- Maximum number of guests on guest list (cottage is 32)
  169. sprintf( szCommand, "SELECT GuestGUID,StorageAccess FROM houses_guest_lists WHERE HouseID=%d;",m_wModel );
  170. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  171. retcode = SQLExecute( cDatabase::m_hStmt );
  172. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_CHAR, GuestIDBuff, sizeof( GuestIDBuff ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1)
  173. retcode = SQLBindCol( cDatabase::m_hStmt, 2, SQL_C_USHORT, &StorageOpen, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  174. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i ) {
  175. sscanf(GuestIDBuff,"%08x",&GuestID);
  176. cmReturn << DWORD(GuestID) << StorageOpen; //0x0000 = access to dwelling; 0x0001 = access also to storage;
  177. }
  178. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  179. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  180. return cmReturn;
  181. }
  182. /**
  183. * Handles the actions of house objects.
  184. *
  185. * This function is called whenever a house object is used or should perform an action.
  186. */
  187. void cHouse::Action(cClient* who)
  188. {
  189. cMessage cmActionComplete;
  190. cmActionComplete << 0xF7B0L << who->m_pcAvatar->GetGUID( ) << ++who->m_dwF7B0Sequence << 0x01C7L << 0L;
  191. who->AddPacket(WORLD_SERVER,cmActionComplete,4);
  192. }
  193. /**
  194. * Handles the assessment of house objects.
  195. *
  196. * This function is called whenever a house object is assessed by a client.
  197. * House objects are intended to be imperceptible to the client.
  198. *
  199. * Returns a Game Event (0x0000F7B0) server message of type Identify Object (0x000000C9).
  200. */
  201. void cHouse::Assess(cClient *pcAssesser)
  202. {
  203. cMessage cmAssess;
  204. cmAssess << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID() << ++pcAssesser->m_dwF7B0Sequence << 0xC9L;
  205. cmAssess << m_dwGUID << 0x00000080L << 1L;
  206. cmAssess << 0xEL;
  207. cmAssess << 30L << 50L << 50L;
  208. cmAssess << 60L << 40L << 50L << 60L << 100L << 100L << 70L << 150L << 70L << 150L << 1L;
  209. cmAssess << 0xFFFFFFFFL << 0xFFFFFFFFL;
  210. cmAssess << 50L << 100L << 0L;
  211. cmAssess << "Male" << "Isparian" << "NPC" << "" << "" << "" << 1L << 2L << 1L << 3L << 2L << 3L << 0L;
  212. pcAssesser->AddPacket(WORLD_SERVER,cmAssess,4);
  213. cMessage cmActionComplete;
  214. cmActionComplete << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID( ) << ++pcAssesser->m_dwF7B0Sequence << 0x01C7L << 0L;
  215. pcAssesser->AddPacket(WORLD_SERVER,cmActionComplete,4);
  216. }