1
0
forked from metin2/server

Rewrote network stack, started working on porting to 64-bit

This commit is contained in:
2022-03-12 11:39:41 +02:00
parent 64596d344c
commit a056345a7b
167 changed files with 1388 additions and 3085 deletions

View File

@@ -202,7 +202,7 @@ SECTREE_MANAGER::~SECTREE_MANAGER()
*/
}
LPSECTREE_MAP SECTREE_MANAGER::GetMap(long lMapIndex)
LPSECTREE_MAP SECTREE_MANAGER::GetMap(int lMapIndex)
{
std::map<DWORD, LPSECTREE_MAP>::iterator it = m_map_pkSectree.find(lMapIndex);
@@ -233,7 +233,7 @@ LPSECTREE SECTREE_MANAGER::Get(DWORD dwIndex, DWORD x, DWORD y)
// -----------------------------------------------------------------------------
// Setting.txt <20><> <20><><EFBFBD><EFBFBD> SECTREE <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// -----------------------------------------------------------------------------
int SECTREE_MANAGER::LoadSettingFile(long lMapIndex, const char * c_pszSettingFileName, TMapSetting & r_setting)
int SECTREE_MANAGER::LoadSettingFile(int lMapIndex, const char * c_pszSettingFileName, TMapSetting & r_setting)
{
memset(&r_setting, 0, sizeof(TMapSetting));
@@ -458,21 +458,17 @@ bool SECTREE_MANAGER::LoadAttribute(LPSECTREE_MAP pkMapSectree, const char * c_p
return false;
}
int iWidth, iHeight;
int32_t iWidth, iHeight;
fread(&iWidth, sizeof(int), 1, fp);
fread(&iHeight, sizeof(int), 1, fp);
fread(&iWidth, sizeof(int32_t), 1, fp);
fread(&iHeight, sizeof(int32_t), 1, fp);
int maxMemSize = LZOManager::instance().GetMaxCompressedSize(sizeof(DWORD) * (SECTREE_SIZE / CELL_SIZE) * (SECTREE_SIZE / CELL_SIZE));
size_t maxMemSize = LZOManager::instance().GetMaxCompressedSize(sizeof(DWORD) * (SECTREE_SIZE / CELL_SIZE) * (SECTREE_SIZE / CELL_SIZE));
size_t uiSize;
lzo_uint uiDestSize;
#ifndef _MSC_VER
BYTE abComp[maxMemSize];
#else
BYTE* abComp = M2_NEW BYTE[maxMemSize];
#endif
DWORD * attr = M2_NEW DWORD[maxMemSize];
for (int y = 0; y < iHeight; ++y)
@@ -497,9 +493,8 @@ bool SECTREE_MANAGER::LoadAttribute(LPSECTREE_MAP pkMapSectree, const char * c_p
abort();
M2_DELETE_ARRAY(attr);
#ifdef _MSC_VER
M2_DELETE_ARRAY(abComp);
#endif
return false;
}
// END_OF_SERVER_ATTR_LOAD_ERROR
@@ -511,14 +506,13 @@ bool SECTREE_MANAGER::LoadAttribute(LPSECTREE_MAP pkMapSectree, const char * c_p
fclose(fp);
M2_DELETE_ARRAY(attr);
#ifdef _MSC_VER
M2_DELETE_ARRAY(abComp);
#endif
return false;
}
fread(&uiSize, sizeof(int), 1, fp);
fread(abComp, sizeof(char), uiSize, fp);
fread(&uiSize, sizeof(int32_t), 1, fp);
fread(abComp, sizeof(BYTE), uiSize, fp);
//LZOManager::instance().Decompress(abComp, uiSize, (BYTE *) tree->GetAttributePointer(), &uiDestSize);
uiDestSize = sizeof(DWORD) * maxMemSize;
@@ -531,9 +525,8 @@ bool SECTREE_MANAGER::LoadAttribute(LPSECTREE_MAP pkMapSectree, const char * c_p
fclose(fp);
M2_DELETE_ARRAY(attr);
#ifdef _MSC_VER
M2_DELETE_ARRAY(abComp);
#endif
return false;
}
@@ -543,9 +536,8 @@ bool SECTREE_MANAGER::LoadAttribute(LPSECTREE_MAP pkMapSectree, const char * c_p
fclose(fp);
M2_DELETE_ARRAY(attr);
#ifdef _MSC_VER
M2_DELETE_ARRAY(abComp);
#endif
return true;
}
@@ -577,7 +569,7 @@ bool SECTREE_MANAGER::GetRecallPositionByEmpire(int iMapIndex, BYTE bEmpire, PIX
return false;
}
bool SECTREE_MANAGER::GetCenterPositionOfMap(long lMapIndex, PIXEL_POSITION & r_pos)
bool SECTREE_MANAGER::GetCenterPositionOfMap(int lMapIndex, PIXEL_POSITION & r_pos)
{
std::vector<TMapRegion>::iterator it = m_vec_mapRegion.begin();
@@ -597,7 +589,7 @@ bool SECTREE_MANAGER::GetCenterPositionOfMap(long lMapIndex, PIXEL_POSITION & r_
return false;
}
bool SECTREE_MANAGER::GetSpawnPositionByMapIndex(long lMapIndex, PIXEL_POSITION& r_pos)
bool SECTREE_MANAGER::GetSpawnPositionByMapIndex(int lMapIndex, PIXEL_POSITION& r_pos)
{
if (lMapIndex> 10000) lMapIndex /= 10000;
std::vector<TMapRegion>::iterator it = m_vec_mapRegion.begin();
@@ -616,7 +608,7 @@ bool SECTREE_MANAGER::GetSpawnPositionByMapIndex(long lMapIndex, PIXEL_POSITION&
return false;
}
bool SECTREE_MANAGER::GetSpawnPosition(long x, long y, PIXEL_POSITION & r_pos)
bool SECTREE_MANAGER::GetSpawnPosition(int x, int y, PIXEL_POSITION & r_pos)
{
std::vector<TMapRegion>::iterator it = m_vec_mapRegion.begin();
@@ -634,7 +626,7 @@ bool SECTREE_MANAGER::GetSpawnPosition(long x, long y, PIXEL_POSITION & r_pos)
return false;
}
bool SECTREE_MANAGER::GetMapBasePositionByMapIndex(long lMapIndex, PIXEL_POSITION & r_pos)
bool SECTREE_MANAGER::GetMapBasePositionByMapIndex(int lMapIndex, PIXEL_POSITION & r_pos)
{
if (lMapIndex> 10000) lMapIndex /= 10000;
std::vector<TMapRegion>::iterator it = m_vec_mapRegion.begin();
@@ -656,7 +648,7 @@ bool SECTREE_MANAGER::GetMapBasePositionByMapIndex(long lMapIndex, PIXEL_POSITIO
return false;
}
bool SECTREE_MANAGER::GetMapBasePosition(long x, long y, PIXEL_POSITION & r_pos)
bool SECTREE_MANAGER::GetMapBasePosition(int x, int y, PIXEL_POSITION & r_pos)
{
std::vector<TMapRegion>::iterator it = m_vec_mapRegion.begin();
@@ -693,7 +685,7 @@ const TMapRegion * SECTREE_MANAGER::FindRegionByPartialName(const char* szMapNam
return NULL;
}
const TMapRegion * SECTREE_MANAGER::GetMapRegion(long lMapIndex)
const TMapRegion * SECTREE_MANAGER::GetMapRegion(int lMapIndex)
{
std::vector<TMapRegion>::iterator it = m_vec_mapRegion.begin();
@@ -708,7 +700,7 @@ const TMapRegion * SECTREE_MANAGER::GetMapRegion(long lMapIndex)
return NULL;
}
int SECTREE_MANAGER::GetMapIndex(long x, long y)
int SECTREE_MANAGER::GetMapIndex(int x, int y)
{
std::vector<TMapRegion>::iterator it = m_vec_mapRegion.begin();
@@ -745,7 +737,7 @@ int SECTREE_MANAGER::Build(const char * c_pszListFileName, const char* c_pszMapB
return 0;
char buf[256 + 1];
char szFilename[256];
char szFilename[1024];
char szMapName[256];
int iIndex;
@@ -815,7 +807,7 @@ int SECTREE_MANAGER::Build(const char * c_pszListFileName, const char* c_pszMapB
return 1;
}
bool SECTREE_MANAGER::IsMovablePosition(long lMapIndex, long x, long y)
bool SECTREE_MANAGER::IsMovablePosition(int lMapIndex, int x, int y)
{
LPSECTREE tree = SECTREE_MANAGER::instance().Get(lMapIndex, x, y);
@@ -825,14 +817,14 @@ bool SECTREE_MANAGER::IsMovablePosition(long lMapIndex, long x, long y)
return (!tree->IsAttr(x, y, ATTR_BLOCK | ATTR_OBJECT));
}
bool SECTREE_MANAGER::GetMovablePosition(long lMapIndex, long x, long y, PIXEL_POSITION & pos)
bool SECTREE_MANAGER::GetMovablePosition(int lMapIndex, int x, int y, PIXEL_POSITION & pos)
{
int i = 0;
do
{
long dx = x + aArroundCoords[i].x;
long dy = y + aArroundCoords[i].y;
int dx = x + aArroundCoords[i].x;
int dy = y + aArroundCoords[i].y;
LPSECTREE tree = SECTREE_MANAGER::instance().Get(lMapIndex, dx, dy);
@@ -852,7 +844,7 @@ bool SECTREE_MANAGER::GetMovablePosition(long lMapIndex, long x, long y, PIXEL_P
return false;
}
bool SECTREE_MANAGER::GetValidLocation(long lMapIndex, long x, long y, long & r_lValidMapIndex, PIXEL_POSITION & r_pos, BYTE empire)
bool SECTREE_MANAGER::GetValidLocation(int lMapIndex, int x, int y, int & r_lValidMapIndex, PIXEL_POSITION & r_pos, BYTE empire)
{
LPSECTREE_MAP pkSectreeMap = GetMap(lMapIndex);
@@ -860,7 +852,7 @@ bool SECTREE_MANAGER::GetValidLocation(long lMapIndex, long x, long y, long & r_
{
if (lMapIndex >= 10000)
{
/* long m = lMapIndex / 10000;
/* int m = lMapIndex / 10000;
if (m == 216)
{
if (GetRecallPositionByEmpire (m, empire, r_pos))
@@ -880,7 +872,7 @@ bool SECTREE_MANAGER::GetValidLocation(long lMapIndex, long x, long y, long & r_
}
}
long lRealMapIndex = lMapIndex;
int lRealMapIndex = lMapIndex;
if (lRealMapIndex >= 10000)
lRealMapIndex = lRealMapIndex / 10000;
@@ -912,7 +904,7 @@ bool SECTREE_MANAGER::GetValidLocation(long lMapIndex, long x, long y, long & r_
return false;
}
bool SECTREE_MANAGER::GetRandomLocation(long lMapIndex, PIXEL_POSITION & r_pos, DWORD dwCurrentX, DWORD dwCurrentY, int iMaxDistance)
bool SECTREE_MANAGER::GetRandomLocation(int lMapIndex, PIXEL_POSITION & r_pos, DWORD dwCurrentX, DWORD dwCurrentY, int iMaxDistance)
{
LPSECTREE_MAP pkSectreeMap = GetMap(lMapIndex);
@@ -979,7 +971,7 @@ bool SECTREE_MANAGER::GetRandomLocation(long lMapIndex, PIXEL_POSITION & r_pos,
return false;
}
long SECTREE_MANAGER::CreatePrivateMap(long lMapIndex)
int SECTREE_MANAGER::CreatePrivateMap(int lMapIndex)
{
if (lMapIndex >= 10000) // 10000<30><30> <20>̻<EFBFBD><CCBB><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>. (Ȥ<><C8A4> <20>̹<EFBFBD> private <20>̴<EFBFBD>)
return 0;
@@ -993,7 +985,7 @@ long SECTREE_MANAGER::CreatePrivateMap(long lMapIndex)
}
// <Factor> Circular private map indexing
long base = lMapIndex * 10000;
int base = lMapIndex * 10000;
int index_cap = 10000;
if ( lMapIndex == 107 || lMapIndex == 108 || lMapIndex == 109 ) {
index_cap = (test_server ? 1 : 51);
@@ -1015,7 +1007,7 @@ long SECTREE_MANAGER::CreatePrivateMap(long lMapIndex)
// No available index
return 0;
}
long lNewMapIndex = base + next_index;
int lNewMapIndex = base + next_index;
if (++next_index >= index_cap) {
next_index = 0;
}
@@ -1054,7 +1046,7 @@ long SECTREE_MANAGER::CreatePrivateMap(long lMapIndex)
return 0;
}
long lNewMapIndex = lMapIndex * 10000 + i;
int lNewMapIndex = lMapIndex * 10000 + i;
*/
pkMapSectree = M2_NEW SECTREE_MAP(*pkMapSectree);
@@ -1090,7 +1082,7 @@ struct FDestroyPrivateMapEntity
}
};
void SECTREE_MANAGER::DestroyPrivateMap(long lMapIndex)
void SECTREE_MANAGER::DestroyPrivateMap(int lMapIndex)
{
if (lMapIndex < 10000) // private map <20><> <20>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD> 10000 <20>̻<EFBFBD> <20>̴<EFBFBD>.
return;
@@ -1114,7 +1106,7 @@ void SECTREE_MANAGER::DestroyPrivateMap(long lMapIndex)
sys_log(0, "PRIVATE_MAP: %d destroyed", lMapIndex);
}
TAreaMap& SECTREE_MANAGER::GetDungeonArea(long lMapIndex)
TAreaMap& SECTREE_MANAGER::GetDungeonArea(int lMapIndex)
{
itertype(m_map_pkArea) it = m_map_pkArea.find(lMapIndex);
@@ -1131,7 +1123,7 @@ void SECTREE_MANAGER::SendNPCPosition(LPCHARACTER ch)
if (!d)
return;
long lMapIndex = ch->GetMapIndex();
int lMapIndex = ch->GetMapIndex();
if (m_mapNPCPosition[lMapIndex].empty())
return;
@@ -1159,19 +1151,19 @@ void SECTREE_MANAGER::SendNPCPosition(LPCHARACTER ch)
if (buf.size())
{
d->BufferedPacket(&p, sizeof(TPacketGCNPCPosition));
d->RawPacket(&p, sizeof(TPacketGCNPCPosition));
d->Packet(buf.read_peek(), buf.size());
}
else
d->Packet(&p, sizeof(TPacketGCNPCPosition));
}
void SECTREE_MANAGER::InsertNPCPosition(long lMapIndex, BYTE bType, const char* szName, long x, long y)
void SECTREE_MANAGER::InsertNPCPosition(int lMapIndex, BYTE bType, const char* szName, int x, int y)
{
m_mapNPCPosition[lMapIndex].push_back(npc_info(bType, szName, x, y));
}
BYTE SECTREE_MANAGER::GetEmpireFromMapIndex(long lMapIndex)
BYTE SECTREE_MANAGER::GetEmpireFromMapIndex(int lMapIndex)
{
if (lMapIndex >= 1 && lMapIndex <= 20)
return 1;
@@ -1242,15 +1234,15 @@ class FRemoveIfAttr
DWORD m_dwCheckAttr;
};
bool SECTREE_MANAGER::ForAttrRegionCell( long lMapIndex, long lCX, long lCY, DWORD dwAttr, EAttrRegionMode mode )
bool SECTREE_MANAGER::ForAttrRegionCell( int lMapIndex, int lCX, int lCY, DWORD dwAttr, EAttrRegionMode mode )
{
SECTREEID id;
id.coord.x = lCX / (SECTREE_SIZE / CELL_SIZE);
id.coord.y = lCY / (SECTREE_SIZE / CELL_SIZE);
long lTreeCX = id.coord.x * (SECTREE_SIZE / CELL_SIZE);
long lTreeCY = id.coord.y * (SECTREE_SIZE / CELL_SIZE);
int lTreeCX = id.coord.x * (SECTREE_SIZE / CELL_SIZE);
int lTreeCY = id.coord.y * (SECTREE_SIZE / CELL_SIZE);
LPSECTREE pSec = Get( lMapIndex, id.package );
if ( !pSec )
@@ -1279,7 +1271,7 @@ bool SECTREE_MANAGER::ForAttrRegionCell( long lMapIndex, long lCX, long lCY, DWO
return false;
}
bool SECTREE_MANAGER::ForAttrRegionRightAngle( long lMapIndex, long lCX, long lCY, long lCW, long lCH, long lRotate, DWORD dwAttr, EAttrRegionMode mode )
bool SECTREE_MANAGER::ForAttrRegionRightAngle( int lMapIndex, int lCX, int lCY, int lCW, int lCH, int lRotate, DWORD dwAttr, EAttrRegionMode mode )
{
if (1 == lRotate/90 || 3 == lRotate/90)
{
@@ -1306,7 +1298,7 @@ bool SECTREE_MANAGER::ForAttrRegionRightAngle( long lMapIndex, long lCX, long lC
#define min( l, r ) ((l) < (r) ? (l) : (r))
#define max( l, r ) ((l) < (r) ? (r) : (l))
bool SECTREE_MANAGER::ForAttrRegionFreeAngle( long lMapIndex, long lCX, long lCY, long lCW, long lCH, long lRotate, DWORD dwAttr, EAttrRegionMode mode )
bool SECTREE_MANAGER::ForAttrRegionFreeAngle( int lMapIndex, int lCX, int lCY, int lCW, int lCH, int lRotate, DWORD dwAttr, EAttrRegionMode mode )
{
float fx1 = (-lCW/2) * sinf(float(lRotate)/180.0f*3.14f) + (-lCH/2) * cosf(float(lRotate)/180.0f*3.14f);
float fy1 = (-lCW/2) * cosf(float(lRotate)/180.0f*3.14f) - (-lCH/2) * sinf(float(lRotate)/180.0f*3.14f);
@@ -1368,7 +1360,7 @@ bool SECTREE_MANAGER::ForAttrRegionFreeAngle( long lMapIndex, long lCX, long lCY
return mode == ATTR_REGION_MODE_CHECK ? false : true;
}
bool SECTREE_MANAGER::ForAttrRegion(long lMapIndex, long lStartX, long lStartY, long lEndX, long lEndY, long lRotate, DWORD dwAttr, EAttrRegionMode mode)
bool SECTREE_MANAGER::ForAttrRegion(int lMapIndex, int lStartX, int lStartY, int lEndX, int lEndY, int lRotate, DWORD dwAttr, EAttrRegionMode mode)
{
LPSECTREE_MAP pkMapSectree = GetMap(lMapIndex);
@@ -1391,10 +1383,10 @@ bool SECTREE_MANAGER::ForAttrRegion(long lMapIndex, long lStartX, long lStartY,
// Cell <20><>ǥ<EFBFBD><C7A5> <20><><EFBFBD>Ѵ<EFBFBD>.
//
long lCX = lStartX / CELL_SIZE;
long lCY = lStartY / CELL_SIZE;
long lCW = (lEndX - lStartX) / CELL_SIZE;
long lCH = (lEndY - lStartY) / CELL_SIZE;
int lCX = lStartX / CELL_SIZE;
int lCY = lStartY / CELL_SIZE;
int lCW = (lEndX - lStartX) / CELL_SIZE;
int lCH = (lEndY - lStartY) / CELL_SIZE;
sys_log(1, "ForAttrRegion %d %d ~ %d %d", lStartX, lStartY, lEndX, lEndY);
@@ -1527,7 +1519,7 @@ struct FPurgeMonsters
}
};
void SECTREE_MANAGER::PurgeMonstersInMap(long lMapIndex)
void SECTREE_MANAGER::PurgeMonstersInMap(int lMapIndex)
{
LPSECTREE_MAP sectree = SECTREE_MANAGER::instance().GetMap(lMapIndex);
@@ -1555,7 +1547,7 @@ struct FPurgeStones
}
};
void SECTREE_MANAGER::PurgeStonesInMap(long lMapIndex)
void SECTREE_MANAGER::PurgeStonesInMap(int lMapIndex)
{
LPSECTREE_MAP sectree = SECTREE_MANAGER::instance().GetMap(lMapIndex);
@@ -1583,7 +1575,7 @@ struct FPurgeNPCs
}
};
void SECTREE_MANAGER::PurgeNPCsInMap(long lMapIndex)
void SECTREE_MANAGER::PurgeNPCsInMap(int lMapIndex)
{
LPSECTREE_MAP sectree = SECTREE_MANAGER::instance().GetMap(lMapIndex);
@@ -1613,7 +1605,7 @@ struct FCountMonsters
}
};
size_t SECTREE_MANAGER::GetMonsterCountInMap(long lMapIndex)
size_t SECTREE_MANAGER::GetMonsterCountInMap(int lMapIndex)
{
LPSECTREE_MAP sectree = SECTREE_MANAGER::instance().GetMap(lMapIndex);
@@ -1653,7 +1645,7 @@ struct FCountSpecifiedMonster
}
};
size_t SECTREE_MANAGER::GetMonsterCountInMap(long lMapIndex, DWORD dwVnum)
size_t SECTREE_MANAGER::GetMonsterCountInMap(int lMapIndex, DWORD dwVnum)
{
LPSECTREE_MAP sectree = SECTREE_MANAGER::instance().GetMap(lMapIndex);