00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00023 #ifndef __MASTERSERVER_H
00024 #define __MASTERSERVER_H
00025
00026 #include <winsock2.h>
00027 #include <fstream>
00028 #include <sql.h>
00029 #include <sqlext.h>
00030 #include "Allegiance.h"
00031 #include "DataBase.h"
00032 #include "Fellowship.h"
00033 #include "CorpseCleaner.h"
00034 #include "cMonsterServer.h"
00035 #include "SimpleAI.h"
00036 #include "Status.h"
00037
00038 class cClient;
00039 class cJobPool;
00040
00041 class cMasterServer
00042 {
00043 friend class cClient;
00044 friend class cCommandParser;
00045 friend class cAltar;
00046 friend class cCovenant;
00047 friend class cDatabase;
00048 friend class cFellowship;
00049 friend class cHouse;
00050 friend class cMonsterServer;
00051
00052 public:
00053 static void WriteToFile ( char *szMessage );
00054 static void Load ( );
00055 static BOOL Unload ( );
00056
00057 static void StartThread ( );
00058 static void StopThread ( DWORD dwTimeOut );
00059 static DWORD WINAPI ServerThread ( LPVOID lpVoid );
00060
00061 static void ParseCommand ( char *szCommand, WORD wSize, cClient *pcClient );
00062
00063 static void LoadAvatar ( cClient *pcClient );
00064 static void CreateNewAvatar ( cAvatar **ppcAvatar, DWORD dwGUID );
00065 static void SendLoginData ( cClient *pcClient );
00066 static void CreateInventory ( cClient *pcClient );
00067 static void ServerMessage ( DWORD dwColor, cClient *pcClient, char *szMessage, ... );
00068 static void SendTell ( char *szMessage, cClient *pcDestination, cClient *pcOrigin );
00069
00070 static void CALLBACK ScavengeIdleSockets ( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime );
00071 static void CALLBACK Status_Update ( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime );
00072 static BOOL DisconnectClient ( cClient *pcClient );
00073 static BOOL Corpse ( cClient *pcClient );
00074 static BOOL DisconnectAllClients( );
00075 static void LoadMonsterModels ( );
00076 static void LoadItemModels ( );
00077 static void LoadWorldModels ( );
00078 static void LoadMonsters ( );
00079 static void LoadGroundSpawns ( );
00080 static void LoadSpellModels ( );
00081 static void LoadSpells ( );
00082 static void LoadSpellComps ( );
00083 static void LoadNPCs ( );
00084 static void LoadAltars ( );
00085 static void LoadCovenants ( );
00086 static void LoadHousing ( );
00087 static void LoadHooks ( );
00088 static void LoadStorage ( );
00089 static void LoadDoors ( );
00090 static void LoadChests ( );
00091 static void LoadLifestones ( );
00092 static void LoadPortals ( );
00093 static void LoadWorldObjects ( );
00094 static void LoadWorldObjects2 ( );
00095 static void LoadNPCModels ( );
00096
00097 static void LoadItem ( cObject *pcItem );
00098
00099 static void LoadSpawns (WORD LB);
00100
00101 static bool SpawnMonster ( char* szMonster, cLocation pcLoc, DWORD Respawn = 0 );
00102 static bool SpawnType ( char* szMonster, cLocation pcLoc, DWORD dwModelNumber, DWORD dwExp_Value, DWORD dwHealth, DWORD dwStamina, DWORD dwMana );
00103 static bool SpawnSave ( char* szMonster, cLocation pcLoc, bool bFacing, bool bOverride, DWORD Respawn, DWORD Decay, DWORD Chase, DWORD Influence );
00104
00105
00106 static BOOL FindHeaderInFile ( FILE* fin, char* header );
00107 static void FixSpaces ( char* str );
00108 static void FixName ( char* str );
00109
00110 static void LoadStartingLocation( );
00111 static void LoadTeleTownList ( );
00112 static void LoadAllegiances ( );
00113
00114 static void ClearAllObjects ( );
00115 static BOOL PKLite ( cClient *pcClient, bool bState );
00116 static CStatus *cStatus;
00117
00118 inline static void FormatIP( SOCKADDR_IN& saSockAddr, char *szStore )
00119 {
00120 wsprintf( szStore, "%u.%u.%u.%u", saSockAddr.sin_addr.S_un.S_un_b.s_b1, saSockAddr.sin_addr.S_un.S_un_b.s_b2,
00121 saSockAddr.sin_addr.S_un.S_un_b.s_b3, saSockAddr.sin_addr.S_un.S_un_b.s_b4 );
00122 }
00123
00124 inline static void FormatIP_Port( SOCKADDR_IN& saSockAddr, char *szStore )
00125 {
00126 wsprintf( szStore, "%u.%u.%u.%u:%u", saSockAddr.sin_addr.S_un.S_un_b.s_b1, saSockAddr.sin_addr.S_un.S_un_b.s_b2,
00127 saSockAddr.sin_addr.S_un.S_un_b.s_b3, saSockAddr.sin_addr.S_un.S_un_b.s_b4, saSockAddr.sin_port );
00128 }
00129 static CorpseCleaner *m_pcCorpse;
00130 static SimpleAI *m_pcSimpleAI;
00131 static cJobPool *m_pcJobPool;
00132 static char m_szServerName[64];
00133 static DWORD m_dwNumUsers;
00134 static DWORD m_UserCount;
00135 static std::list < cEnchantment * > m_lstEnchantments;
00136 static std::vector< cTeleTownList > m_TeleTownList;
00137 static std::vector< cAllegiance * > m_AllegianceList;
00138 static std::vector< cFellowship * > m_FellowshipList;
00139
00140 static inline DWORD NewFellowID ( ) { return ++m_dwFellowID; }
00141
00142
00143
00144
00145
00146 static cLocation m_HoltburgWest;
00147 static cLocation m_HoltburgSouth;
00148 static cLocation m_ShoushiSE;
00149 static cLocation m_ShoushiWest;
00150 static cLocation m_YaraqNorth;
00151 static cLocation m_YaraqEast;
00152
00153
00154 static cLocation m_LSHoltburgWest;
00155 static cLocation m_LSHoltburgSouth;
00156 static cLocation m_LSShoushiSE;
00157 static cLocation m_LSShoushiWest;
00158 static cLocation m_LSYaraqNorth;
00159 static cLocation m_LSYaraqEast;
00160
00161
00162 protected:
00163 static DWORD m_dwFellowID;
00164
00165 private:
00166 static HANDLE m_hThread;
00167 static HANDLE m_hExitEvent;
00168 static UINT_PTR m_uipTimer;
00169 static UINT_PTR m_uipStatusTimer;
00170 static DWORD m_dwThreadID;
00171
00172 static cLocation m_StartingLoc;
00173 static cLocation m_MarketLoc;
00174
00175 static int m_iLoadCount;
00176 static FILE* pFile;
00177
00178 };
00179
00180
00181
00182
00183 #endif // #ifndef __MASTERSERVER_H