Compare commits

..

10 Commits

120 changed files with 1009 additions and 1303 deletions

View File

@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 3.12)
# Build mode debug/release?
set(CMAKE_BUILD_TYPE Debug)
# Set C++ standard to C++11
set(CMAKE_CXX_STANDARD 11)
# Set C++ standard to C++17
set(CMAKE_CXX_STANDARD 17)
project("Metin2 Server")

View File

@ -96,24 +96,6 @@ namespace std
a.clear();
}
template <typename T> T MIN(T a, T b)
{
return a < b ? a : b;
}
template <typename T> T MAX(T a, T b)
{
return a > b ? a : b;
}
template <typename T> T MINMAX(T min, T value, T max)
{
T tv;
tv = (min > value ? min : value);
return (max < tv) ? max : tv;
}
template <class _Ty>
class void_mem_fun_t : public unary_function<_Ty *, void>
{

View File

@ -352,8 +352,8 @@ typedef struct SPacketDGCreateSuccess
typedef struct TPlayerItemAttribute
{
BYTE bType;
WORD sValue;
uint8_t bType;
int16_t sValue;
} TPlayerItemAttribute;
typedef struct SPlayerItem

View File

@ -21,8 +21,15 @@ set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads)
# LibBSD
target_link_libraries(${PROJECT_NAME} PRIVATE bsd)
# Libevent
find_package(Libevent CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE libevent::core libevent::extra libevent::pthreads)
# effolkronium/random
find_package(effolkronium_random CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE effolkronium_random)
target_link_libraries(${PROJECT_NAME} PRIVATE libpoly libsql libthecore)

View File

@ -61,7 +61,7 @@ bool CBlockCountry::Load()
BLOCK_IP *block_ip = new BLOCK_IP;
block_ip->ip_from = strtoul(row[0], NULL, 10);
block_ip->ip_to = strtoul(row[1], NULL, 10);
strncpy(block_ip->country, row[2], sizeof(block_ip->country));
strlcpy(block_ip->country, row[2], sizeof(block_ip->country));
m_block_ip.push_back(block_ip);
sys_log(0, "BLOCKED_IP : %u - %u", block_ip->ip_from, block_ip->ip_to);
@ -174,7 +174,7 @@ void CBlockCountry::SendBlockExceptionOne(CPeer *peer, const char *login, BYTE c
TPacketBlockException packet;
packet.cmd = cmd;
strncpy(packet.login, login, sizeof(packet.login));
strlcpy(packet.login, login, sizeof(packet.login));
peer->EncodeHeader(HEADER_DG_BLOCK_EXCEPTION, 0, sizeof(TPacketBlockException));
peer->Encode(&packet, sizeof(packet));

View File

@ -22,7 +22,7 @@ const int auctionMinFlushSec = 1800;
CItemCache::CItemCache()
{
m_expireTime = MIN(1800, g_iItemCacheFlushSeconds);
m_expireTime = std::min(1800, g_iItemCacheFlushSeconds);
}
CItemCache::~CItemCache()
@ -138,7 +138,7 @@ void CItemCache::OnFlush()
p->aAttr[6].bType, p->aAttr[6].sValue);
}
char szItemQuery[QUERY_MAX_LEN + QUERY_MAX_LEN];
char szItemQuery[QUERY_MAX_LEN + QUERY_MAX_LEN + 100];
snprintf(szItemQuery, sizeof(szItemQuery), "REPLACE INTO item%s (%s) VALUES(%s)", GetTablePostfix(), szColumns, szValues);
if (g_test_server)
@ -158,7 +158,7 @@ void CItemCache::OnFlush()
//
CPlayerTableCache::CPlayerTableCache()
{
m_expireTime = MIN(1800, g_iPlayerCacheFlushSeconds);
m_expireTime = std::min(1800, g_iPlayerCacheFlushSeconds);
}
CPlayerTableCache::~CPlayerTableCache()
@ -184,7 +184,7 @@ const int CItemPriceListTableCache::s_nMinFlushSec = 1800;
CItemPriceListTableCache::CItemPriceListTableCache()
{
m_expireTime = MIN(s_nMinFlushSec, g_iItemPriceListTableCacheFlushSeconds);
m_expireTime = std::min(s_nMinFlushSec, g_iItemPriceListTableCacheFlushSeconds);
}
void CItemPriceListTableCache::UpdateList(const TItemPriceListTable* pUpdateList)

View File

@ -192,7 +192,7 @@ bool CClientManager::Initialize()
char szBindIP[128];
if (!CConfig::instance().GetValue("BIND_IP", szBindIP, 128))
strncpy(szBindIP, "0", sizeof(szBindIP));
strlcpy(szBindIP, "0", sizeof(szBindIP));
// Create a new libevent base and listen for new connections
m_base = event_base_new();
@ -558,7 +558,7 @@ void CClientManager::QUERY_QUEST_SAVE(CPeer * pkPeer, TQuestTable * pTable, DWOR
else
{
snprintf(szQuery, sizeof(szQuery),
"REPLACE INTO quest%s (dwPID, szName, szState, lValue) VALUES(%d, '%s', '%s', %ld)",
"REPLACE INTO quest%s (dwPID, szName, szState, lValue) VALUES(%d, '%s', '%s', %d)",
GetTablePostfix(), pTable->dwPID, pTable->szName, pTable->szState, pTable->lValue);
}
@ -569,11 +569,11 @@ void CClientManager::QUERY_QUEST_SAVE(CPeer * pkPeer, TQuestTable * pTable, DWOR
void CClientManager::QUERY_SAFEBOX_LOAD(CPeer * pkPeer, DWORD dwHandle, TSafeboxLoadPacket * packet, bool bMall)
{
ClientHandleInfo * pi = new ClientHandleInfo(dwHandle);
strncpy(pi->safebox_password, packet->szPassword, sizeof(pi->safebox_password));
strlcpy(pi->safebox_password, packet->szPassword, sizeof(pi->safebox_password));
pi->account_id = packet->dwID;
pi->account_index = 0;
pi->ip[0] = bMall ? 1 : 0;
strncpy(pi->login, packet->szLogin, sizeof(pi->login));
strlcpy(pi->login, packet->szLogin, sizeof(pi->login));
char szQuery[QUERY_MAX_LEN];
snprintf(szQuery, sizeof(szQuery),
@ -599,7 +599,7 @@ void CClientManager::RESULT_SAFEBOX_LOAD(CPeer * pkPeer, SQLMsg * msg)
if (pi->account_index == 0)
{
char szSafeboxPassword[SAFEBOX_PASSWORD_MAX_LEN + 1];
strncpy(szSafeboxPassword, pi->safebox_password, sizeof(szSafeboxPassword));
strlcpy(szSafeboxPassword, pi->safebox_password, sizeof(szSafeboxPassword));
TSafeboxTable * pSafebox = new TSafeboxTable;
memset(pSafebox, 0, sizeof(TSafeboxTable));
@ -702,7 +702,7 @@ void CClientManager::RESULT_SAFEBOX_LOAD(CPeer * pkPeer, SQLMsg * msg)
if (pSet && !m_vec_itemTable.empty())
{
CGrid grid(5, MAX(1, pi->pSafebox->bSize) * 9);
CGrid grid(5, std::max<int>(1, pi->pSafebox->bSize) * 9);
bool bEscape = false;
for (DWORD i = 0; i < s_items.size(); ++i)
@ -777,7 +777,7 @@ void CClientManager::RESULT_SAFEBOX_LOAD(CPeer * pkPeer, SQLMsg * msg)
do
{
dwSkillIdx = number(0, m_vec_skillTable.size()-1);
dwSkillIdx = Random::get<int>(0, m_vec_skillTable.size() - 1);
dwSkillVnum = m_vec_skillTable[dwSkillIdx].dwVnum;
@ -939,8 +939,8 @@ void CClientManager::RESULT_SAFEBOX_CHANGE_SIZE(CPeer * pkPeer, SQLMsg * msg)
void CClientManager::QUERY_SAFEBOX_CHANGE_PASSWORD(CPeer * pkPeer, DWORD dwHandle, TSafeboxChangePasswordPacket * p)
{
ClientHandleInfo * pi = new ClientHandleInfo(dwHandle);
strncpy(pi->safebox_password, p->szNewPassword, sizeof(pi->safebox_password));
strncpy(pi->login, p->szOldPassword, sizeof(pi->login));
strlcpy(pi->safebox_password, p->szNewPassword, sizeof(pi->safebox_password));
strlcpy(pi->login, p->szOldPassword, sizeof(pi->login));
pi->account_id = p->dwID;
char szQuery[QUERY_MAX_LEN];
@ -1167,7 +1167,7 @@ void CClientManager::QUERY_SETUP(CPeer * peer, DWORD dwHandle, const char * c_pD
//
TMapLocation kMapLocations;
strncpy(kMapLocations.szHost, peer->GetPublicIP(), sizeof(kMapLocations.szHost));
strlcpy(kMapLocations.szHost, peer->GetPublicIP(), sizeof(kMapLocations.szHost));
kMapLocations.wPort = peer->GetListenPort();
memcpy(kMapLocations.alMaps, peer->GetMaps(), sizeof(kMapLocations.alMaps));
@ -1190,7 +1190,7 @@ void CClientManager::QUERY_SETUP(CPeer * peer, DWORD dwHandle, const char * c_pD
if (tmp->GetChannel() == GUILD_WARP_WAR_CHANNEL || tmp->GetChannel() == peer->GetChannel())
{
TMapLocation kMapLocation2;
strncpy(kMapLocation2.szHost, tmp->GetPublicIP(), sizeof(kMapLocation2.szHost));
strlcpy(kMapLocation2.szHost, tmp->GetPublicIP(), sizeof(kMapLocation2.szHost));
kMapLocation2.wPort = tmp->GetListenPort();
memcpy(kMapLocation2.alMaps, tmp->GetMaps(), sizeof(kMapLocation2.alMaps));
vec_kMapLocations.push_back(kMapLocation2);
@ -1217,7 +1217,7 @@ void CClientManager::QUERY_SETUP(CPeer * peer, DWORD dwHandle, const char * c_pD
if (tmp->GetChannel() == 1 || tmp->GetChannel() == peer->GetChannel())
{
TMapLocation kMapLocation2;
strncpy(kMapLocation2.szHost, tmp->GetPublicIP(), sizeof(kMapLocation2.szHost));
strlcpy(kMapLocation2.szHost, tmp->GetPublicIP(), sizeof(kMapLocation2.szHost));
kMapLocation2.wPort = tmp->GetListenPort();
memcpy(kMapLocation2.alMaps, tmp->GetMaps(), sizeof(kMapLocation2.alMaps));
vec_kMapLocations.push_back(kMapLocation2);
@ -1245,7 +1245,7 @@ void CClientManager::QUERY_SETUP(CPeer * peer, DWORD dwHandle, const char * c_pD
{
TMapLocation kMapLocation2;
strncpy(kMapLocation2.szHost, tmp->GetPublicIP(), sizeof(kMapLocation2.szHost));
strlcpy(kMapLocation2.szHost, tmp->GetPublicIP(), sizeof(kMapLocation2.szHost));
kMapLocation2.wPort = tmp->GetListenPort();
memcpy(kMapLocation2.alMaps, tmp->GetMaps(), sizeof(kMapLocation2.alMaps));
@ -1277,7 +1277,7 @@ void CClientManager::QUERY_SETUP(CPeer * peer, DWORD dwHandle, const char * c_pD
TPacketDGP2P p2pSetupPacket;
p2pSetupPacket.wPort = peer->GetP2PPort();
p2pSetupPacket.bChannel = peer->GetChannel();
strncpy(p2pSetupPacket.szHost, peer->GetPublicIP(), sizeof(p2pSetupPacket.szHost));
strlcpy(p2pSetupPacket.szHost, peer->GetPublicIP(), sizeof(p2pSetupPacket.szHost));
for (itertype(m_peerList) i = m_peerList.begin(); i != m_peerList.end();++i)
{
@ -1312,8 +1312,8 @@ void CClientManager::QUERY_SETUP(CPeer * peer, DWORD dwHandle, const char * c_pD
r.id = pck->dwID;
trim_and_lower(pck->szLogin, r.login, sizeof(r.login));
strncpy(r.social_id, pck->szSocialID, sizeof(r.social_id));
strncpy(r.passwd, "TEMP", sizeof(r.passwd));
strlcpy(r.social_id, pck->szSocialID, sizeof(r.social_id));
strlcpy(r.passwd, "TEMP", sizeof(r.passwd));
InsertLoginData(pkLD);
@ -1326,8 +1326,8 @@ void CClientManager::QUERY_SETUP(CPeer * peer, DWORD dwHandle, const char * c_pD
{
TPacketBillingRepair pck_repair;
pck_repair.dwLoginKey = pkLD->GetKey();
strncpy(pck_repair.szLogin, pck->szLogin, sizeof(pck_repair.szLogin));
strncpy(pck_repair.szHost, pck->szHost, sizeof(pck_repair.szHost));
strlcpy(pck_repair.szLogin, pck->szLogin, sizeof(pck_repair.szLogin));
strlcpy(pck_repair.szHost, pck->szHost, sizeof(pck_repair.szHost));
vec_repair.push_back(pck_repair);
}
}
@ -1402,7 +1402,7 @@ void CClientManager::QUERY_ITEM_SAVE(CPeer * pkPeer, const char * c_pData)
"attrtype4, attrvalue4, "
"attrtype5, attrvalue5, "
"attrtype6, attrvalue6) "
"VALUES(%u, %u, %d, %d, %u, %u, %ld, %ld, %ld, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)",
"VALUES(%u, %u, %d, %d, %u, %u, %d, %d, %d, %hd, %hd, %hd, %hd, %hd, %hd, %hd, %hd, %hd, %hd, %hd, %hd, %hd, %hd)",
GetTablePostfix(),
p->id,
p->owner,
@ -1624,7 +1624,7 @@ void CClientManager::UpdatePlayerCache()
void CClientManager::SetCacheFlushCountLimit(int iLimit)
{
m_iCacheFlushCountLimit = MAX(10, iLimit);
m_iCacheFlushCountLimit = std::max(10, iLimit);
sys_log(0, "CACHE_FLUSH_LIMIT_PER_SECOND: %d", m_iCacheFlushCountLimit);
}
@ -1877,8 +1877,8 @@ void CClientManager::QUERY_AUTH_LOGIN(CPeer * pkPeer, DWORD dwHandle, TPacketGDA
r.id = p->dwID;
trim_and_lower(p->szLogin, r.login, sizeof(r.login));
strncpy(r.social_id, p->szSocialID, sizeof(r.social_id));
strncpy(r.passwd, "TEMP", sizeof(r.passwd));
strlcpy(r.social_id, p->szSocialID, sizeof(r.social_id));
strlcpy(r.passwd, "TEMP", sizeof(r.passwd));
sys_log(0, "AUTH_LOGIN id(%u) login(%s) social_id(%s) login_key(%u), client_key(%u %u %u %u)",
p->dwID, p->szLogin, p->szSocialID, p->dwLoginKey,
@ -1918,7 +1918,7 @@ void CClientManager::BillingExpire(TPacketBillingExpire * p)
if (pkPeer)
{
strncpy(p->szLogin, pkLD->GetAccountRef().login, sizeof(p->szLogin));
strlcpy(p->szLogin, pkLD->GetAccountRef().login, sizeof(p->szLogin));
pkPeer->EncodeHeader(HEADER_DG_BILLING_EXPIRE, 0, sizeof(TPacketBillingExpire));
pkPeer->Encode(p, sizeof(TPacketBillingExpire));
}
@ -2031,8 +2031,8 @@ void CClientManager::SendAllLoginToBilling()
CLoginData * pkLD = (it++)->second;
p.dwLoginKey = pkLD->GetKey();
strncpy(p.szLogin, pkLD->GetAccountRef().login, sizeof(p.szLogin));
strncpy(p.szHost, pkLD->GetIP(), sizeof(p.szHost));
strlcpy(p.szLogin, pkLD->GetAccountRef().login, sizeof(p.szLogin));
strlcpy(p.szHost, pkLD->GetIP(), sizeof(p.szHost));
sys_log(0, "SendAllLoginToBilling %s %s", pkLD->GetAccountRef().login, pkLD->GetIP());
vec.push_back(p);
}
@ -3065,8 +3065,8 @@ int CClientManager::Process()
//30ºÐ¸´Ù º¯°æ
if (((thecore_pulse() % (60 * 30 * 10)) == 0))
{
g_iPlayerCacheFlushSeconds = MAX(60, rand() % 180);
g_iItemCacheFlushSeconds = MAX(60, rand() % 180);
g_iPlayerCacheFlushSeconds = std::max(60, rand() % 180);
g_iItemCacheFlushSeconds = std::max(60, rand() % 180);
sys_log(0, "[SAVE_TIME]Change saving time item %d player %d", g_iPlayerCacheFlushSeconds, g_iItemCacheFlushSeconds);
}
*/
@ -3130,7 +3130,7 @@ int CClientManager::Process()
DWORD dwCount = CClientManager::instance().GetUserCount();
g_dwUsageAvg += dwCount;
g_dwUsageMax = MAX(g_dwUsageMax, dwCount);
g_dwUsageMax = std::max(g_dwUsageMax, dwCount);
memset(&thecore_profiler[0], 0, sizeof(thecore_profiler));
@ -3351,8 +3351,8 @@ bool CClientManager::InitializeLocalization()
int col = 0;
tLocale locale;
strncpy(locale.szValue, row[col++], sizeof(locale.szValue));
strncpy(locale.szKey, row[col++], sizeof(locale.szKey));
strlcpy(locale.szValue, row[col++], sizeof(locale.szValue));
strlcpy(locale.szKey, row[col++], sizeof(locale.szKey));
//DB_NAME_COLUMN Setting
if (strcmp(locale.szKey, "LOCALE") == 0)
@ -3750,9 +3750,9 @@ bool CClientManager::__GetAdminInfo(const char *szIP, std::vector<tAdminInfo> &
str_to_number(Info.m_ID, row[idx++]);
trim_and_lower(row[idx++], Info.m_szAccount, sizeof(Info.m_szAccount));
strncpy(Info.m_szName, row[idx++], sizeof(Info.m_szName));
strncpy(Info.m_szContactIP, row[idx++], sizeof(Info.m_szContactIP));
strncpy(Info.m_szServerIP, row[idx++], sizeof(Info.m_szServerIP));
strlcpy(Info.m_szName, row[idx++], sizeof(Info.m_szName));
strlcpy(Info.m_szContactIP, row[idx++], sizeof(Info.m_szContactIP));
strlcpy(Info.m_szServerIP, row[idx++], sizeof(Info.m_szServerIP));
std::string stAuth = row[idx++];
if (!stAuth.compare("IMPLEMENTOR"))
@ -4073,7 +4073,7 @@ void CClientManager::RMCandidacy(CPeer * peer, DWORD dwHandle, const char * data
{
char szName[32];
strncpy(szName, data, sizeof(szName));
strlcpy(szName, data, sizeof(szName));
sys_log(0, "[MONARCH_GM] Remove candidacy name(%s)", szName);
int iRet = CMonarch::instance().DelCandidacy(szName) ? 1 : 0;
@ -4114,7 +4114,7 @@ void CClientManager::SetMonarch(CPeer * peer, DWORD dwHandle, const char * data)
{
char szName[32];
strncpy(szName, data, sizeof(szName));
strlcpy(szName, data, sizeof(szName));
if (g_test_server)
sys_log(0, "[MONARCH_GM] Set Monarch name(%s)", szName);
@ -4157,7 +4157,7 @@ void CClientManager::RMMonarch(CPeer * peer, DWORD dwHandle, const char * data)
{
char szName[32];
strncpy(szName, data, sizeof(szName));
strlcpy(szName, data, sizeof(szName));
if (g_test_server)
sys_log(0, "[MONARCH_GM] Remove Monarch name(%s)", szName);
@ -4216,8 +4216,8 @@ void CClientManager::ChangeMonarchLord(CPeer * peer, DWORD dwHandle, TPacketChan
ack.dwPID = info->dwPID;
MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
strncpy(ack.szName, row[0], sizeof(ack.szName));
strncpy(ack.szDate, row[1], sizeof(ack.szDate));
strlcpy(ack.szName, row[0], sizeof(ack.szName));
strlcpy(ack.szDate, row[1], sizeof(ack.szDate));
snprintf(szQuery, sizeof(szQuery), "UPDATE monarch SET pid=%u, windate=NOW() WHERE empire=%d", ack.dwPID, ack.bEmpire);
SQLMsg* pMsg2 = CDBManager::instance().DirectQuery(szQuery, SQL_PLAYER);

View File

@ -170,7 +170,7 @@ class CClientManager : public singleton<CClientManager>
void SendNotice(const char * c_pszFormat, ...);
char* GetCommand(char* str); //독일선물기능에서 명령어 얻는 함수
std::string GetCommand(char* str); //독일선물기능에서 명령어 얻는 함수
void ItemAward(CPeer * peer, char* login); //독일 선물 기능
CPeer * AddPeer(bufferevent* bufev, sockaddr* addr);

View File

@ -312,8 +312,8 @@ bool CClientManager::InitializeMobTable()
TMobTable *tempTable = it_map_mobTable->second;
mob_table->dwVnum = tempTable->dwVnum;
strncpy(mob_table->szName, tempTable->szName, sizeof(tempTable->szName));
strncpy(mob_table->szLocaleName, tempTable->szLocaleName, sizeof(tempTable->szName));
strlcpy(mob_table->szName, tempTable->szName, sizeof(tempTable->szName));
strlcpy(mob_table->szLocaleName, tempTable->szLocaleName, sizeof(tempTable->szName));
mob_table->bRank = tempTable->bRank;
mob_table->bType = tempTable->bType;
mob_table->bBattleType = tempTable->bBattleType;
@ -323,7 +323,7 @@ bool CClientManager::InitializeMobTable()
mob_table->dwRaceFlag = tempTable->dwRaceFlag;
mob_table->dwImmuneFlag = tempTable->dwImmuneFlag;
mob_table->bEmpire = tempTable->bEmpire;
strncpy(mob_table->szFolder, tempTable->szFolder, sizeof(tempTable->szName));
strlcpy(mob_table->szFolder, tempTable->szFolder, sizeof(tempTable->szName));
mob_table->bOnClickType = tempTable->bOnClickType;
mob_table->bStr = tempTable->bStr;
mob_table->bDex = tempTable->bDex;
@ -545,12 +545,12 @@ bool CClientManager::InitializeQuestItemTable()
str_to_number(tbl.dwVnum, row[col++]);
if (row[col])
strncpy(tbl.szName, row[col], sizeof(tbl.szName));
strlcpy(tbl.szName, row[col], sizeof(tbl.szName));
col++;
if (row[col])
strncpy(tbl.szLocaleName, row[col], sizeof(tbl.szLocaleName));
strlcpy(tbl.szLocaleName, row[col], sizeof(tbl.szLocaleName));
col++;
@ -724,8 +724,8 @@ bool CClientManager::InitializeItemTable()
TItemTable *tempTable = it_map_itemTable->second;
item_table->dwVnum = tempTable->dwVnum;
strncpy(item_table->szName, tempTable->szName, sizeof(item_table->szName));
strncpy(item_table->szLocaleName, tempTable->szLocaleName, sizeof(item_table->szLocaleName));
strlcpy(item_table->szName, tempTable->szName, sizeof(item_table->szName));
strlcpy(item_table->szLocaleName, tempTable->szLocaleName, sizeof(item_table->szLocaleName));
item_table->bType = tempTable->bType;
item_table->bSubType = tempTable->bSubType;
item_table->bSize = tempTable->bSize;
@ -888,33 +888,33 @@ bool CClientManager::InitializeSkillTable()
col = 0;
str_to_number(t.dwVnum, data[col++]);
strncpy(t.szName, data[col++], sizeof(t.szName));
strlcpy(t.szName, data[col++], sizeof(t.szName));
str_to_number(t.bType, data[col++]);
str_to_number(t.bMaxLevel, data[col++]);
str_to_number(t.dwSplashRange, data[col++]);
strncpy(t.szPointOn, data[col++], sizeof(t.szPointOn));
strncpy(t.szPointPoly, data[col++], sizeof(t.szPointPoly));
strncpy(t.szSPCostPoly, data[col++], sizeof(t.szSPCostPoly));
strncpy(t.szDurationPoly, data[col++], sizeof(t.szDurationPoly));
strncpy(t.szDurationSPCostPoly, data[col++], sizeof(t.szDurationSPCostPoly));
strncpy(t.szCooldownPoly, data[col++], sizeof(t.szCooldownPoly));
strncpy(t.szMasterBonusPoly, data[col++], sizeof(t.szMasterBonusPoly));
strlcpy(t.szPointOn, data[col++], sizeof(t.szPointOn));
strlcpy(t.szPointPoly, data[col++], sizeof(t.szPointPoly));
strlcpy(t.szSPCostPoly, data[col++], sizeof(t.szSPCostPoly));
strlcpy(t.szDurationPoly, data[col++], sizeof(t.szDurationPoly));
strlcpy(t.szDurationSPCostPoly, data[col++], sizeof(t.szDurationSPCostPoly));
strlcpy(t.szCooldownPoly, data[col++], sizeof(t.szCooldownPoly));
strlcpy(t.szMasterBonusPoly, data[col++], sizeof(t.szMasterBonusPoly));
str_to_number(t.dwFlag, data[col++]);
str_to_number(t.dwAffectFlag, data[col++]);
strncpy(t.szPointOn2, data[col++], sizeof(t.szPointOn2));
strncpy(t.szPointPoly2, data[col++], sizeof(t.szPointPoly2));
strncpy(t.szDurationPoly2, data[col++], sizeof(t.szDurationPoly2));
strlcpy(t.szPointOn2, data[col++], sizeof(t.szPointOn2));
strlcpy(t.szPointPoly2, data[col++], sizeof(t.szPointPoly2));
strlcpy(t.szDurationPoly2, data[col++], sizeof(t.szDurationPoly2));
str_to_number(t.dwAffectFlag2, data[col++]);
// ADD_GRANDMASTER_SKILL
strncpy(t.szPointOn3, data[col++], sizeof(t.szPointOn3));
strncpy(t.szPointPoly3, data[col++], sizeof(t.szPointPoly3));
strncpy(t.szDurationPoly3, data[col++], sizeof(t.szDurationPoly3));
strlcpy(t.szPointOn3, data[col++], sizeof(t.szPointOn3));
strlcpy(t.szPointPoly3, data[col++], sizeof(t.szPointPoly3));
strlcpy(t.szDurationPoly3, data[col++], sizeof(t.szDurationPoly3));
strncpy(t.szGrandMasterAddSPCostPoly, data[col++], sizeof(t.szGrandMasterAddSPCostPoly));
strlcpy(t.szGrandMasterAddSPCostPoly, data[col++], sizeof(t.szGrandMasterAddSPCostPoly));
// END_OF_ADD_GRANDMASTER_SKILL
str_to_number(t.bLevelStep, data[col++]);
@ -924,7 +924,7 @@ bool CClientManager::InitializeSkillTable()
str_to_number(t.lMaxHit, data[col++]);
strncpy(t.szSplashAroundDamageAdjustPoly, data[col++], sizeof(t.szSplashAroundDamageAdjustPoly));
strlcpy(t.szSplashAroundDamageAdjustPoly, data[col++], sizeof(t.szSplashAroundDamageAdjustPoly));
str_to_number(t.bSkillAttrType, data[col++]);
str_to_number(t.dwTargetRange, data[col++]);
@ -956,7 +956,7 @@ bool CClientManager::InitializeBanwordTable()
if (data[0])
{
strncpy(t.szWord, data[0], sizeof(t.szWord));
strlcpy(t.szWord, data[0], sizeof(t.szWord));
m_vec_banwordTable.push_back(t);
}
}
@ -999,7 +999,7 @@ bool CClientManager::InitializeItemAttrTable()
int col = 0;
strncpy(t.szApply, data[col++], sizeof(t.szApply));
strlcpy(t.szApply, data[col++], sizeof(t.szApply));
str_to_number(t.dwApplyIndex, data[col++]);
str_to_number(t.dwProb, data[col++]);
str_to_number(t.lValues[0], data[col++]);
@ -1073,7 +1073,7 @@ bool CClientManager::InitializeItemRareTable()
int col = 0;
strncpy(t.szApply, data[col++], sizeof(t.szApply));
strlcpy(t.szApply, data[col++], sizeof(t.szApply));
str_to_number(t.dwApplyIndex, data[col++]);
str_to_number(t.dwProb, data[col++]);
str_to_number(t.lValues[0], data[col++]);
@ -1178,7 +1178,7 @@ void parse_pair_number_string(const char * c_pszString, std::vector<std::pair<in
{
if (isdigit(*t))
{
strncpy(szNum, t, MIN(sizeof(szNum), (p-t)+1));
strlcpy(szNum, t, std::min<size_t>(sizeof(szNum), (p-t)+1));
comma = strchr(szNum, ',');
@ -1200,7 +1200,7 @@ void parse_pair_number_string(const char * c_pszString, std::vector<std::pair<in
if (isdigit(*t))
{
strncpy(szNum, t, sizeof(szNum));
strlcpy(szNum, t, sizeof(szNum));
comma = strchr(const_cast<char*>(t), ',');
@ -1236,7 +1236,7 @@ bool CClientManager::InitializeObjectProto()
m_vec_kObjectProto.clear();
}
m_vec_kObjectProto.reserve(MAX(0, pRes->uiNumRows));
m_vec_kObjectProto.reserve(std::max<size_t>(0, pRes->uiNumRows));
MYSQL_ROW data;
@ -1277,7 +1277,7 @@ bool CClientManager::InitializeObjectProto()
str_to_number(t.dwDependOnGroupVnum, data[col++]);
t.lNPCX = 0;
t.lNPCY = MAX(t.lRegion[1], t.lRegion[3])+300;
t.lNPCY = std::max(t.lRegion[1], t.lRegion[3])+300;
// END_OF_ADD_BUILDING_NPC
sys_log(0, "OBJ_PROTO: vnum %lu price %lu mat %lu %lu",

View File

@ -19,7 +19,7 @@ void CClientManager::LoadEventFlag()
while ((row = mysql_fetch_row(pRes->pSQLResult)))
{
TPacketSetEventFlag p;
strncpy(p.szFlagName, row[0], sizeof(p.szFlagName));
strlcpy(p.szFlagName, row[0], sizeof(p.szFlagName));
str_to_number(p.lValue, row[1]);
sys_log(0, "EventFlag Load %s %d", p.szFlagName, p.lValue);
m_map_lEventFlag.insert(std::make_pair(std::string(p.szFlagName), p.lValue));
@ -50,7 +50,7 @@ void CClientManager::SetEventFlag(TPacketSetEventFlag* p)
{
char szQuery[1024];
snprintf(szQuery, sizeof(szQuery),
"REPLACE INTO quest%s (dwPID, szName, szState, lValue) VALUES(0, '%s', '', %ld)",
"REPLACE INTO quest%s (dwPID, szName, szState, lValue) VALUES(0, '%s', '', %d)",
GetTablePostfix(), p->szFlagName, p->lValue);
szQuery[1023] = '\0';
@ -68,7 +68,7 @@ void CClientManager::SendEventFlagsOnSetup(CPeer* peer)
for (it = m_map_lEventFlag.begin(); it != m_map_lEventFlag.end(); ++it)
{
TPacketSetEventFlag p;
strncpy(p.szFlagName, it->first.c_str(), sizeof(p.szFlagName));
strlcpy(p.szFlagName, it->first.c_str(), sizeof(p.szFlagName));
p.lValue = it->second;
peer->EncodeHeader(HEADER_DG_SET_EVENT_FLAG, 0, sizeof(TPacketSetEventFlag));
peer->Encode(&p, sizeof(TPacketSetEventFlag));

View File

@ -60,7 +60,7 @@ void CClientManager::GuildAddMember(CPeer* peer, TPacketGDGuildAddMember * p)
str_to_number(dg.dwOffer, row[3]);
str_to_number(dg.bLevel, row[4]);
str_to_number(dg.bJob, row[5]);
strncpy(dg.szName, row[6], sizeof(dg.szName));
strlcpy(dg.szName, row[6], sizeof(dg.szName));
ForwardPacket(HEADER_DG_GUILD_ADD_MEMBER, &dg, sizeof(TPacketDGGuildMember));
}

View File

@ -31,7 +31,7 @@ void CClientManager::AckHorseName(DWORD dwPID, CPeer* peer)
else
{
MYSQL_ROW row = mysql_fetch_row(pmsg->Get()->pSQLResult);
strncpy(packet.szHorseName, row[0], sizeof(packet.szHorseName));
strlcpy(packet.szHorseName, row[0], sizeof(packet.szHorseName));
}
peer->EncodeHeader(HEADER_DG_ACK_HORSE_NAME, 0, sizeof(TPacketUpdateHorseName));

View File

@ -98,7 +98,7 @@ void CClientManager::QUERY_LOGIN_BY_KEY(CPeer * pkPeer, DWORD dwHandle, TPacketG
{
sys_log(0, "LOGIN_BY_KEY already login %s %lu", r.login, p->dwLoginKey);
TPacketDGLoginAlready ptog;
strncpy(ptog.szLogin, szLogin, sizeof(ptog.szLogin));
strlcpy(ptog.szLogin, szLogin, sizeof(ptog.szLogin));
pkPeer->EncodeHeader(HEADER_DG_LOGIN_ALREADY, dwHandle, sizeof(TPacketDGLoginAlready));
pkPeer->Encode(&ptog, sizeof(TPacketDGLoginAlready));
return;
@ -129,13 +129,13 @@ void CClientManager::QUERY_LOGIN_BY_KEY(CPeer * pkPeer, DWORD dwHandle, TPacketG
pkTab->id = r.id;
trim_and_lower(r.login, pkTab->login, sizeof(pkTab->login));
strncpy(pkTab->passwd, r.passwd, sizeof(pkTab->passwd));
strncpy(pkTab->social_id, r.social_id, sizeof(pkTab->social_id));
strncpy(pkTab->status, "OK", sizeof(pkTab->status));
strlcpy(pkTab->passwd, r.passwd, sizeof(pkTab->passwd));
strlcpy(pkTab->social_id, r.social_id, sizeof(pkTab->social_id));
strlcpy(pkTab->status, "OK", sizeof(pkTab->status));
ClientHandleInfo * info = new ClientHandleInfo(dwHandle);
info->pAccountTable = pkTab;
strncpy(info->ip, p->szIP, sizeof(info->ip));
strlcpy(info->ip, p->szIP, sizeof(info->ip));
sys_log(0, "LOGIN_BY_KEY success %s %lu %s", r.login, p->dwLoginKey, info->ip);
char szQuery[QUERY_MAX_LEN];
@ -232,17 +232,17 @@ TAccountTable * CreateAccountTableFromRes(MYSQL_RES * res)
memset(pkTab, 0, sizeof(TAccountTable));
// 첫번째 컬럼 것만 참고 한다 (JOIN QUERY를 위한 것 임)
strncpy(input_pwd, row[col++], sizeof(input_pwd));
strlcpy(input_pwd, row[col++], sizeof(input_pwd));
str_to_number(pkTab->id, row[col++]);
strncpy(pkTab->login, row[col++], sizeof(pkTab->login));
strncpy(pkTab->passwd, row[col++], sizeof(pkTab->passwd));
strncpy(pkTab->social_id, row[col++], sizeof(pkTab->social_id));
strlcpy(pkTab->login, row[col++], sizeof(pkTab->login));
strlcpy(pkTab->passwd, row[col++], sizeof(pkTab->passwd));
strlcpy(pkTab->social_id, row[col++], sizeof(pkTab->social_id));
str_to_number(pkTab->bEmpire, row[col++]);
for (int j = 0; j < PLAYER_PER_ACCOUNT; ++j)
str_to_number(pkTab->players[j].dwID, row[col++]);
strncpy(pkTab->status, row[col++], sizeof(pkTab->status));
strlcpy(pkTab->status, row[col++], sizeof(pkTab->status));
if (strcmp(pkTab->passwd, input_pwd))
{
@ -280,7 +280,7 @@ void CreateAccountPlayerDataFromRes(MYSQL_RES * pRes, TAccountTable * pkTab)
if (pt)
{
strncpy(pkTab->players[j].szName, pt->name, sizeof(pkTab->players[j].szName));
strlcpy(pkTab->players[j].szName, pt->name, sizeof(pkTab->players[j].szName));
pkTab->players[j].byJob = pt->job;
pkTab->players[j].byLevel = pt->level;
@ -301,7 +301,7 @@ void CreateAccountPlayerDataFromRes(MYSQL_RES * pRes, TAccountTable * pkTab)
if (!row[col++])
*pkTab->players[j].szName = '\0';
else
strncpy(pkTab->players[j].szName, row[col - 1], sizeof(pkTab->players[j].szName));
strlcpy(pkTab->players[j].szName, row[col - 1], sizeof(pkTab->players[j].szName));
pkTab->players[j].byJob = 0;
pkTab->players[j].byLevel = 0;
@ -410,7 +410,7 @@ void CClientManager::RESULT_LOGIN(CPeer * peer, SQLMsg * msg)
sys_log(0, "RESULT_LOGIN: already logon %s", info->pAccountTable->login);
TPacketDGLoginAlready p;
strncpy(p.szLogin, info->pAccountTable->login, sizeof(p.szLogin));
strlcpy(p.szLogin, info->pAccountTable->login, sizeof(p.szLogin));
peer->EncodeHeader(HEADER_DG_LOGIN_ALREADY, info->dwHandle, sizeof(TPacketDGLoginAlready));
peer->Encode(&p, sizeof(p));
@ -520,7 +520,7 @@ void CClientManager::QUERY_CHANGE_NAME(CPeer * peer, DWORD dwHandle, TPacketGDCh
TPacketDGChangeName pdg;
peer->EncodeHeader(HEADER_DG_CHANGE_NAME, dwHandle, sizeof(TPacketDGChangeName));
pdg.pid = p->pid;
strncpy(pdg.name, p->name, sizeof(pdg.name));
strlcpy(pdg.name, p->name, sizeof(pdg.name));
peer->Encode(&pdg, sizeof(TPacketDGChangeName));
}

View File

@ -84,9 +84,9 @@ size_t CreatePlayerSaveQuery(char * pszQuery, size_t querySize, TPlayerTable * p
"y = %d, "
"z = %d, "
"map_index = %d, "
"exit_x = %ld, "
"exit_y = %ld, "
"exit_map_index = %ld, "
"exit_x = %d, "
"exit_y = %d, "
"exit_map_index = %d, "
"hp = %d, "
"mp = %d, "
"stamina = %d, "
@ -110,7 +110,7 @@ size_t CreatePlayerSaveQuery(char * pszQuery, size_t querySize, TPlayerTable * p
"part_hair = %d, "
"last_play = NOW(), "
"skill_group = %d, "
"alignment = %ld, "
"alignment = %d, "
"horse_level = %d, "
"horse_riding = %d, "
"horse_hp = %d, "
@ -405,7 +405,7 @@ void CClientManager::QUERY_PLAYER_LOAD(CPeer * peer, DWORD dwHandle, TPlayerLoad
void CClientManager::ItemAward(CPeer * peer,char* login)
{
char login_t[LOGIN_MAX_LEN + 1] = "";
strncpy(login_t,login,LOGIN_MAX_LEN + 1);
strlcpy(login_t,login,LOGIN_MAX_LEN + 1);
std::set<TItemAward *> * pSet = ItemAwardManager::instance().GetByLogin(login_t);
if(pSet == NULL)
return;
@ -417,7 +417,7 @@ void CClientManager::ItemAward(CPeer * peer,char* login)
char cmdStr[100] = ""; //why콜룸에서 읽은 값을 임시 문자열에 복사해둠
strcpy(cmdStr,whyStr); //명령어 얻는 과정에서 토큰쓰면 원본도 토큰화 되기 때문
char command[20] = "";
strcpy(command,GetCommand(cmdStr)); // command 얻기
strcpy(command,GetCommand(cmdStr).c_str()); // command 얻기
if( !(strcmp(command,"GIFT") )) // command 가 GIFT이면
{
TPacketItemAwardInfromer giftData;
@ -428,7 +428,7 @@ void CClientManager::ItemAward(CPeer * peer,char* login)
}
}
}
char* CClientManager::GetCommand(char* str)
std::string CClientManager::GetCommand(char* str)
{
char command[20] = "";
char* tok;
@ -458,7 +458,7 @@ bool CreatePlayerTableFromRes(MYSQL_RES * res, TPlayerTable * pkTab)
// "stat_point,skill_point,sub_skill_point,stat_reset_count,part_base,part_hair,"
// "skill_level,quickslot,skill_group,alignment,mobile,horse_level,horse_riding,horse_hp,horse_stamina FROM player%s WHERE id=%d",
str_to_number(pkTab->id, row[col++]);
strncpy(pkTab->name, row[col++], sizeof(pkTab->name));
strlcpy(pkTab->name, row[col++], sizeof(pkTab->name));
str_to_number(pkTab->job, row[col++]);
str_to_number(pkTab->voice, row[col++]);
str_to_number(pkTab->dir, row[col++]);
@ -509,7 +509,7 @@ bool CreatePlayerTableFromRes(MYSQL_RES * res, TPlayerTable * pkTab)
if (row[col])
{
strncpy(pkTab->szMobile, row[col], sizeof(pkTab->szMobile));
strlcpy(pkTab->szMobile, row[col], sizeof(pkTab->szMobile));
}
col++;
@ -531,11 +531,11 @@ bool CreatePlayerTableFromRes(MYSQL_RES * res, TPlayerTable * pkTab)
int max_point = pkTab->level - 9;
int skill_point =
MIN(20, pkTab->skills[121].bLevel) + // SKILL_LEADERSHIP 통솔력
MIN(20, pkTab->skills[124].bLevel) + // SKILL_MINING 채광
MIN(10, pkTab->skills[131].bLevel) + // SKILL_HORSE_SUMMON 말소환
MIN(20, pkTab->skills[141].bLevel) + // SKILL_ADD_HP HP보강
MIN(20, pkTab->skills[142].bLevel); // SKILL_RESIST_PENETRATE 관통저항
std::min<int>(20, pkTab->skills[121].bLevel) + // SKILL_LEADERSHIP 통솔력
std::min<int>(20, pkTab->skills[124].bLevel) + // SKILL_MINING 채광
std::min<int>(10, pkTab->skills[131].bLevel) + // SKILL_HORSE_SUMMON 말소환
std::min<int>(20, pkTab->skills[141].bLevel) + // SKILL_ADD_HP HP보강
std::min<int>(20, pkTab->skills[142].bLevel); // SKILL_RESIST_PENETRATE 관통저항
pkTab->sub_skill_point = max_point - skill_point;
}
@ -759,8 +759,8 @@ void CClientManager::RESULT_QUEST_LOAD(CPeer * peer, MYSQL_RES * pRes, DWORD dwH
row = mysql_fetch_row(pRes);
str_to_number(r.dwPID, row[0]);
strncpy(r.szName, row[1], sizeof(r.szName));
strncpy(r.szState, row[2], sizeof(r.szState));
strlcpy(r.szName, row[1], sizeof(r.szName));
strlcpy(r.szState, row[2], sizeof(r.szState));
str_to_number(r.lValue, row[3]);
}
@ -939,7 +939,7 @@ void CClientManager::__QUERY_PLAYER_CREATE(CPeer *peer, DWORD dwHandle, TPlayerC
pack.bAccountCharacterIndex = packet->account_index;
pack.player.dwID = player_id;
strncpy(pack.player.szName, packet->player_table.name, sizeof(pack.player.szName));
strlcpy(pack.player.szName, packet->player_table.name, sizeof(pack.player.szName));
pack.player.byJob = packet->player_table.job;
pack.player.byLevel = 1;
pack.player.dwPlayMinutes = 0;
@ -1045,7 +1045,7 @@ void CClientManager::__RESULT_PLAYER_DELETE(CPeer *peer, SQLMsg* msg)
str_to_number(deletedLevelLimit, row[1]);
char szName[64];
strncpy(szName, row[2], sizeof(szName));
strlcpy(szName, row[2], sizeof(szName));
if (deletedLevelLimit >= m_iPlayerDeleteLevelLimit && !IsChinaEventServer())
{
@ -1187,7 +1187,7 @@ void CClientManager::QUERY_ADD_AFFECT(CPeer * peer, TPacketGDAddAffect * p)
*/
snprintf(queryStr, sizeof(queryStr),
"REPLACE INTO affect%s (dwPID, bType, bApplyOn, lApplyValue, dwFlag, lDuration, lSPCost) "
"VALUES(%u, %u, %u, %ld, %u, %ld, %ld)",
"VALUES(%u, %u, %u, %d, %u, %d, %d)",
GetTablePostfix(),
p->dwPID,
p->elem.dwType,
@ -1220,7 +1220,7 @@ void CClientManager::QUERY_HIGHSCORE_REGISTER(CPeer* peer, TPacketGDHighscore *
sys_log(0, "HEADER_GD_HIGHSCORE_REGISTER: PID %u", data->dwPID);
ClientHandleInfo * pi = new ClientHandleInfo(0);
strncpy(pi->login, data->szBoard, sizeof(pi->login));
strlcpy(pi->login, data->szBoard, sizeof(pi->login));
pi->account_id = (DWORD)data->lValue;
pi->player_id = data->dwPID;
pi->account_index = (data->cDir > 0);
@ -1235,7 +1235,7 @@ void CClientManager::RESULT_HIGHSCORE_REGISTER(CPeer * pkPeer, SQLMsg * msg)
//DWORD dwHandle = pi->dwHandle;
char szBoard[21];
strncpy(szBoard, pi->login, sizeof(szBoard));
strlcpy(szBoard, pi->login, sizeof(szBoard));
int value = (int)pi->account_id;
SQLResult * res = msg->Get();

View File

@ -117,7 +117,7 @@ bool CConfig::LoadFile(const char* filename)
switch (mode)
{
case 0:
strncpy(comment, szTmp, sizeof(comment));
strlcpy(comment, szTmp, sizeof(comment));
++mode;
break;
@ -229,7 +229,7 @@ bool CConfig::GetValue(const char * key, char *dest, size_t destSize)
if (!Search(key))
return false;
strncpy(dest, Get(key), destSize);
strlcpy(dest, Get(key), destSize);
if (!*dest)
return false;

View File

@ -54,7 +54,7 @@ namespace
{
FSendPeerWar(BYTE bType, BYTE bWar, DWORD GID1, DWORD GID2)
{
if (number(0, 1))
if (Random::get<bool>())
std::swap(GID1, GID2);
memset(&p, 0, sizeof(TPacketGuildWar));
@ -137,7 +137,7 @@ void CGuildManager::ParseResult(SQLResult * pRes)
TGuild & r_info = TouchGuild(GID);
strncpy(r_info.szName, row[1], sizeof(r_info.szName));
strlcpy(r_info.szName, row[1], sizeof(r_info.szName));
str_to_number(r_info.ladder_point, row[2]);
str_to_number(r_info.win, row[3]);
str_to_number(r_info.draw, row[4]);
@ -211,7 +211,7 @@ int CGuildManager::GetRanking(DWORD dwGID)
if (it == map_kLadderPointRankingByGID.end())
return GUILD_RANK_MAX_NUM;
return MINMAX(0, it->second, GUILD_RANK_MAX_NUM);
return std::clamp(it->second, 0, GUILD_RANK_MAX_NUM);
}
void CGuildManager::ResultRanking(MYSQL_RES * pRes)
@ -1013,7 +1013,7 @@ bool CGuildManager::ReserveWar(TPacketGuildWar * p)
// ÆÄ¿ö °è»ê
TGuild & k1 = TouchGuild(GID1);
lvp = c_aiScoreByLevel[MIN(GUILD_MAX_LEVEL, k1.level)];
lvp = c_aiScoreByLevel[std::min<size_t>(GUILD_MAX_LEVEL, k1.level)];
rkp = c_aiScoreByRanking[GetRanking(GID1)];
alv = GetAverageGuildMemberLevel(GID1);
mc = GetGuildMemberCount(GID1);
@ -1029,7 +1029,7 @@ bool CGuildManager::ReserveWar(TPacketGuildWar * p)
// ÆÄ¿ö °è»ê
TGuild & k2 = TouchGuild(GID2);
lvp = c_aiScoreByLevel[MIN(GUILD_MAX_LEVEL, k2.level)];
lvp = c_aiScoreByLevel[std::min<size_t>(GUILD_MAX_LEVEL, k2.level)];
rkp = c_aiScoreByRanking[GetRanking(GID2)];
alv = GetAverageGuildMemberLevel(GID2);
mc = GetGuildMemberCount(GID2);
@ -1228,7 +1228,7 @@ void CGuildWarReserve::Initialize()
while ((row = mysql_fetch_row(res)))
{
dwGuild = dwGold = 0;
strncpy(szLogin, row[0], sizeof(szLogin));
strlcpy(szLogin, row[0], sizeof(szLogin));
str_to_number(dwGuild, row[1]);
str_to_number(dwGold, row[2]);
@ -1254,7 +1254,7 @@ void CGuildWarReserve::OnSetup(CPeer * peer)
while (it != mapBet.end())
{
strncpy(pckBet.szLogin, it->first.c_str(), sizeof(pckBet.szLogin));
strlcpy(pckBet.szLogin, it->first.c_str(), sizeof(pckBet.szLogin));
pckBet.dwGuild = it->second.first;
pckBet.dwGold = it->second.second;
@ -1316,7 +1316,7 @@ bool CGuildWarReserve::Bet(const char * pszLogin, DWORD dwGold, DWORD dwGuild)
TPacketGDGuildWarBet pckBet;
pckBet.dwWarID = m_data.dwID;
strncpy(pckBet.szLogin, pszLogin, sizeof(pckBet.szLogin));
strlcpy(pckBet.szLogin, pszLogin, sizeof(pckBet.szLogin));
pckBet.dwGuild = dwGuild;
pckBet.dwGold = dwGold;

View File

@ -53,13 +53,13 @@ void ItemAwardManager::Load(SQLMsg * pMsg)
if (row[col])
{
strncpy(kData->szWhy, row[col], sizeof(kData->szWhy));
strlcpy(kData->szWhy, row[col], sizeof(kData->szWhy));
//게임 중에 why콜룸에 변동이 생기면
char* whyStr = kData->szWhy; //why 콜룸 읽기
char cmdStr[100] = ""; //why콜룸에서 읽은 값을 임시 문자열에 복사해둠
strcpy(cmdStr,whyStr); //명령어 얻는 과정에서 토큰쓰면 원본도 토큰화 되기 때문
char command[20] = "";
strcpy(command,CClientManager::instance().GetCommand(cmdStr)); // command 얻기
strcpy(command,CClientManager::instance().GetCommand(cmdStr).c_str()); // command 얻기
//sys_err("%d, %s",pItemAward->dwID,command);
if( !(strcmp(command,"GIFT") )) // command 가 GIFT이면
{

View File

@ -66,7 +66,7 @@ DWORD CLoginData::GetLogonTime()
void CLoginData::SetIP(const char * c_pszIP)
{
strncpy(m_szIP, c_pszIP, sizeof(m_szIP));
strlcpy(m_szIP, c_pszIP, sizeof(m_szIP));
}
const char * CLoginData::GetIP()

View File

@ -169,7 +169,7 @@ int Start()
if (CConfig::instance().GetValue("LOG_KEEP_DAYS", &tmpValue))
{
tmpValue = MINMAX(3, tmpValue, 30);
tmpValue = std::clamp(tmpValue, 3, 30);
log_set_expiration_days(tmpValue);
fprintf(stderr, "Setting log keeping days to %d\n", tmpValue);
}

View File

@ -121,8 +121,8 @@ namespace marriage
p.dwPID1 = dwPID1;
p.dwPID2 = dwPID2;
p.tMarryTime = now;
strncpy(p.szName1, szName1, sizeof(p.szName1));
strncpy(p.szName2, szName2, sizeof(p.szName2));
strlcpy(p.szName1, szName1, sizeof(p.szName1));
strlcpy(p.szName2, szName2, sizeof(p.szName2));
CClientManager::instance().ForwardPacket(HEADER_DG_MARRIAGE_ADD, &p, sizeof(p));
}
@ -263,8 +263,8 @@ namespace marriage
p.dwPID1 = pMarriage->pid1;
p.dwPID2 = pMarriage->pid2;
p.tMarryTime = pMarriage->time;
strncpy(p.szName1, pMarriage->name1.c_str(), sizeof(p.szName1));
strncpy(p.szName2, pMarriage->name2.c_str(), sizeof(p.szName2));
strlcpy(p.szName1, pMarriage->name1.c_str(), sizeof(p.szName1));
strlcpy(p.szName2, pMarriage->name2.c_str(), sizeof(p.szName2));
peer->EncodeHeader(HEADER_DG_MARRIAGE_ADD, 0, sizeof(p));
peer->Encode(&p, sizeof(p));
}

View File

@ -81,7 +81,7 @@ bool CMonarch::AddCandidacy(DWORD pid, const char * name)
MonarchCandidacy info;
info.pid = pid;
strncpy(info.name, name, sizeof(info.name));
strlcpy(info.name, name, sizeof(info.name));
m_vec_MonarchCandidacy.push_back(info);
char szQuery[256];
@ -129,7 +129,7 @@ bool CMonarch::AddMoney(int Empire, int64_t Money)
int64_t Money64 = m_MonarchInfo.money[Empire];
char szQuery[1024];
snprintf(szQuery, sizeof(szQuery), "UPDATE monarch set money=%lld where empire=%d", Money64, Empire);
snprintf(szQuery, sizeof(szQuery), "UPDATE monarch set money=%ld where empire=%d", Money64, Empire);
CDBManager::instance().AsyncQuery(szQuery);
@ -145,7 +145,7 @@ bool CMonarch::DecMoney(int Empire, int64_t Money)
int64_t Money64 = m_MonarchInfo.money[Empire];
char szQuery[1024];
snprintf(szQuery, sizeof(szQuery), "UPDATE monarch set money=%lld where empire=%d", Money64, Empire);
snprintf(szQuery, sizeof(szQuery), "UPDATE monarch set money=%ld where empire=%d", Money64, Empire);
CDBManager::instance().AsyncQuery(szQuery);
return true;
@ -163,7 +163,7 @@ bool CMonarch::TakeMoney(int Empire, DWORD pid, int64_t Money)
char szQuery[1024];
snprintf(szQuery, sizeof(szQuery),
"UPDATE monarch set money=%lld; where empire=%d", m_MonarchInfo.money[Empire], Empire);
"UPDATE monarch set money=%ld; where empire=%d", m_MonarchInfo.money[Empire], Empire);
CDBManager::instance().AsyncQuery(szQuery);
@ -192,10 +192,10 @@ bool CMonarch::LoadMonarch()
int Empire = 0; str_to_number(Empire, row[idx++]);
str_to_number(p->pid[Empire], row[idx++]);
strncpy(p->name[Empire], row[idx++], sizeof(p->name[Empire]));
strlcpy(p->name[Empire], row[idx++], sizeof(p->name[Empire]));
str_to_number(p->money[Empire], row[idx++]);
strncpy(p->date[Empire], row[idx++], sizeof(p->date[Empire]));
strlcpy(p->date[Empire], row[idx++], sizeof(p->date[Empire]));
if (g_test_server)
sys_log(0, "[LOAD_MONARCH] Empire %d pid %d money %lld windate %s", Empire, p->pid[Empire], p->money[Empire], p->date[Empire]);
@ -227,7 +227,7 @@ bool CMonarch::SetMonarch(const char * name)
str_to_number(Empire, row[idx++]);
str_to_number(p->pid[Empire], row[idx++]);
strncpy(p->name[Empire], row[idx++], sizeof(p->name[Empire]));
strlcpy(p->name[Empire], row[idx++], sizeof(p->name[Empire]));
p->money[Empire] = atoll(row[idx++]);
if (g_test_server)
@ -237,7 +237,7 @@ bool CMonarch::SetMonarch(const char * name)
//db¿¡ ÀÔ·Â
snprintf(szQuery, sizeof(szQuery),
"REPLACE INTO monarch (empire, name, windate, money) VALUES(%d, %d, now(), %lld)", Empire, p->pid[Empire], p->money[Empire]);
"REPLACE INTO monarch (empire, name, windate, money) VALUES(%d, %d, now(), %ld)", Empire, p->pid[Empire], p->money[Empire]);
CDBManager::instance().AsyncQuery(szQuery, SQL_PLAYER);
return true;

View File

@ -586,16 +586,16 @@ bool Set_Proto_Mob_Table(TMobTable *mobTable, cCsvTable &csvTable,std::map<int,c
{
int col = 0;
str_to_number(mobTable->dwVnum, csvTable.AsStringByIndex(col++));
strncpy(mobTable->szName, csvTable.AsStringByIndex(col++), sizeof(mobTable->szName));
strlcpy(mobTable->szName, csvTable.AsStringByIndex(col++), sizeof(mobTable->szName));
//3. 지역별 이름 넣어주기.
map<int,const char*>::iterator it;
it = nameMap.find(mobTable->dwVnum);
if (it != nameMap.end()) {
const char * localeName = it->second;
strncpy(mobTable->szLocaleName, localeName, sizeof (mobTable->szLocaleName));
strlcpy(mobTable->szLocaleName, localeName, sizeof (mobTable->szLocaleName));
} else {
strncpy(mobTable->szLocaleName, mobTable->szName, sizeof (mobTable->szLocaleName));
strlcpy(mobTable->szLocaleName, mobTable->szName, sizeof (mobTable->szLocaleName));
}
//RANK
@ -626,7 +626,7 @@ bool Set_Proto_Mob_Table(TMobTable *mobTable, cCsvTable &csvTable,std::map<int,c
str_to_number(mobTable->bEmpire, csvTable.AsStringByIndex(col++)); //col = 11
strncpy(mobTable->szFolder, csvTable.AsStringByIndex(col++), sizeof(mobTable->szFolder));
strlcpy(mobTable->szFolder, csvTable.AsStringByIndex(col++), sizeof(mobTable->szFolder));
str_to_number(mobTable->bOnClickType, csvTable.AsStringByIndex(col++));
@ -776,15 +776,15 @@ bool Set_Proto_Item_Table(TItemTable *itemTable, cCsvTable &csvTable,std::map<in
}
}
strncpy(itemTable->szName, csvTable.AsStringByIndex(1), sizeof(itemTable->szName));
strlcpy(itemTable->szName, csvTable.AsStringByIndex(1), sizeof(itemTable->szName));
//지역별 이름 넣어주기.
map<int,const char*>::iterator it;
it = nameMap.find(itemTable->dwVnum);
if (it != nameMap.end()) {
const char * localeName = it->second;
strncpy(itemTable->szLocaleName, localeName, sizeof (itemTable->szLocaleName));
strlcpy(itemTable->szLocaleName, localeName, sizeof (itemTable->szLocaleName));
} else {
strncpy(itemTable->szLocaleName, itemTable->szName, sizeof (itemTable->szLocaleName));
strlcpy(itemTable->szLocaleName, itemTable->szName, sizeof (itemTable->szLocaleName));
}
itemTable->bType = dataArray[2];
itemTable->bSubType = dataArray[3];

View File

@ -12,7 +12,7 @@ CGrid::CGrid(int w, int h) : m_iWidth(w), m_iHeight(h)
CGrid::CGrid(CGrid * pkGrid, int w, int h) : m_iWidth(w), m_iHeight(h)
{
m_pGrid = new char[m_iWidth * m_iHeight];
int iSize = std::MIN(w * h, pkGrid->m_iWidth * pkGrid->m_iHeight);
int iSize = std::min(w * h, pkGrid->m_iWidth * pkGrid->m_iHeight);
memcpy(m_pGrid, pkGrid->m_pGrid, sizeof(char) * iSize);
}

View File

@ -42,10 +42,16 @@ if (LZO_FOUND)
target_link_libraries (${PROJECT_NAME} ${LZO_LIBRARIES})
endif (LZO_FOUND)
# Pthreads
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package (Threads REQUIRED)
target_link_libraries (${PROJECT_NAME} Threads::Threads)
# LibBSD
target_link_libraries(${PROJECT_NAME} bsd)
# effolkronium/random
find_package(effolkronium_random CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} effolkronium_random)
target_link_libraries(${PROJECT_NAME} libgame libpoly libsql libthecore liblua)

View File

@ -312,7 +312,7 @@ void CBattleArena::SpawnRandomStone()
if ( idx < 0 || idx >= 3 ) return;
CHARACTER_MANAGER::instance().SpawnMobRange(
vnum[number(0, 6)],
vnum[Random::get(0, 6)],
m_nMapIndex,
region_info[idx][0], region_info[idx][1], region_info[idx][2], region_info[idx][3],
false, true);

View File

@ -37,7 +37,7 @@ time_t UseBlueDragonSkill(LPCHARACTER pChar, unsigned int idx)
pSecMap->for_each( f );
nextUsingTime = number(BlueDragon_GetSkillFactor(3, "Skill0", "period", "min"), BlueDragon_GetSkillFactor(3, "Skill0", "period", "max"));
nextUsingTime = Random::get(BlueDragon_GetSkillFactor(3, "Skill0", "period", "min"), BlueDragon_GetSkillFactor(3, "Skill0", "period", "max"));
}
break;
@ -49,7 +49,7 @@ time_t UseBlueDragonSkill(LPCHARACTER pChar, unsigned int idx)
pSecMap->for_each( f );
nextUsingTime = number(BlueDragon_GetSkillFactor(3, "Skill1", "period", "min"), BlueDragon_GetSkillFactor(3, "Skill1", "period", "max"));
nextUsingTime = Random::get(BlueDragon_GetSkillFactor(3, "Skill1", "period", "min"), BlueDragon_GetSkillFactor(3, "Skill1", "period", "max"));
}
break;
@ -61,7 +61,7 @@ time_t UseBlueDragonSkill(LPCHARACTER pChar, unsigned int idx)
pSecMap->for_each( f );
nextUsingTime = number(BlueDragon_GetSkillFactor(3, "Skill2", "period", "min"), BlueDragon_GetSkillFactor(3, "Skill2", "period", "max"));
nextUsingTime = Random::get(BlueDragon_GetSkillFactor(3, "Skill2", "period", "min"), BlueDragon_GetSkillFactor(3, "Skill2", "period", "max"));
if (NULL != f.pFarthestChar)
{

View File

@ -10,9 +10,9 @@ struct FSkillBreath
{
pAttacker = p;
Set1 = static_cast<EJobs>(number(0,3));
Set2 = static_cast<EJobs>(number(0,3));
gender = static_cast<ESex>(number(0,2));
Set1 = static_cast<EJobs>(Random::get(0,3));
Set2 = static_cast<EJobs>(Random::get(0,3));
gender = static_cast<ESex>(Random::get(0,2));
}
void operator()(LPENTITY ent)
@ -53,7 +53,7 @@ struct FSkillBreath
}
int firstDamagePercent = number(BlueDragon_GetSkillFactor(4, "Skill0", "damage", ptr, "min"), BlueDragon_GetSkillFactor(4, "Skill0", "damage", ptr, "max"));
int firstDamagePercent = Random::get(BlueDragon_GetSkillFactor(4, "Skill0", "damage", ptr, "min"), BlueDragon_GetSkillFactor(4, "Skill0", "damage", ptr, "max"));
pct += firstDamagePercent;
if (firstDamagePercent > 0)
@ -75,7 +75,7 @@ struct FSkillBreath
case JOB_MAX_NUM: return;
}
int secondDamagePercent = number(BlueDragon_GetSkillFactor(4, "Skill0", "damage", ptr, "min"), BlueDragon_GetSkillFactor(4, "Skill0", "damage", ptr, "max"));
int secondDamagePercent = Random::get(BlueDragon_GetSkillFactor(4, "Skill0", "damage", ptr, "min"), BlueDragon_GetSkillFactor(4, "Skill0", "damage", ptr, "max"));
pct += secondDamagePercent;
if (secondDamagePercent > 0)
@ -93,7 +93,7 @@ struct FSkillBreath
default: return;
}
int thirdDamagePercent = number(BlueDragon_GetSkillFactor(4, "Skill0", "gender", ptr, "min"), BlueDragon_GetSkillFactor(4, "Skill0", "gender", ptr, "max"));
int thirdDamagePercent = Random::get(BlueDragon_GetSkillFactor(4, "Skill0", "gender", ptr, "min"), BlueDragon_GetSkillFactor(4, "Skill0", "gender", ptr, "max"));
pct += thirdDamagePercent;
if (thirdDamagePercent > 0)
@ -117,7 +117,7 @@ struct FSkillBreath
pct += addPct;
int dam = number(BlueDragon_GetSkillFactor(3, "Skill0", "default_damage", "min"), BlueDragon_GetSkillFactor(3, "Skill0", "default_damage", "max"));
int dam = Random::get(BlueDragon_GetSkillFactor(3, "Skill0", "default_damage", "min"), BlueDragon_GetSkillFactor(3, "Skill0", "default_damage", "max"));
dam += (dam * addPct) / 100;
dam += (ch->GetMaxHP() * pct) / 100;
@ -161,7 +161,7 @@ struct FSkillWeakBreath
int addPct = BlueDragon_GetRangeFactor("hp_damage", pAttacker->GetHPPct());
int dam = number( BlueDragon_GetSkillFactor(3, "Skill1", "default_damage", "min"), BlueDragon_GetSkillFactor(3, "Skill1", "default_damage", "max") );
int dam = Random::get( BlueDragon_GetSkillFactor(3, "Skill1", "default_damage", "min"), BlueDragon_GetSkillFactor(3, "Skill1", "default_damage", "max") );
dam += (dam * addPct) / 100;
ch->Damage( pAttacker, dam, DAMAGE_TYPE_ICE );
@ -189,9 +189,9 @@ struct FSkillEarthQuake
MaxDistance = 0;
pFarthestChar = NULL;
Set1 = static_cast<EJobs>(number(0,3));
Set2 = static_cast<EJobs>(number(0,3));
gender = static_cast<ESex>(number(0,2));
Set1 = static_cast<EJobs>(Random::get(0,3));
Set2 = static_cast<EJobs>(Random::get(0,3));
gender = static_cast<ESex>(Random::get(0,2));
}
void operator()(LPENTITY ent)
@ -213,7 +213,7 @@ struct FSkillEarthQuake
return;
}
int sec = number(BlueDragon_GetSkillFactor(4, "Skill2", "stun_time", "default", "min"), BlueDragon_GetSkillFactor(4, "Skill2", "stun_time", "default", "max"));
int sec = Random::get(BlueDragon_GetSkillFactor(4, "Skill2", "stun_time", "default", "min"), BlueDragon_GetSkillFactor(4, "Skill2", "stun_time", "default", "max"));
if (ch->GetJob() == Set1)
{
@ -230,7 +230,7 @@ struct FSkillEarthQuake
case JOB_MAX_NUM: return;
}
sec += number(BlueDragon_GetSkillFactor(4, "Skill2", "stun_time", ptr, "min"), BlueDragon_GetSkillFactor(4, "Skill2", "stun_time", ptr, "max"));
sec += Random::get(BlueDragon_GetSkillFactor(4, "Skill2", "stun_time", ptr, "min"), BlueDragon_GetSkillFactor(4, "Skill2", "stun_time", ptr, "max"));
}
if (ch->GetJob() == Set2)
@ -248,7 +248,7 @@ struct FSkillEarthQuake
case JOB_MAX_NUM: return;
}
sec += number(BlueDragon_GetSkillFactor(4, "Skill2", "stun_time", ptr, "min"), BlueDragon_GetSkillFactor(4, "Skill2", "stun_time", ptr, "max"));
sec += Random::get(BlueDragon_GetSkillFactor(4, "Skill2", "stun_time", ptr, "min"), BlueDragon_GetSkillFactor(4, "Skill2", "stun_time", ptr, "max"));
}
if (GET_SEX(ch) == gender)
@ -262,12 +262,12 @@ struct FSkillEarthQuake
default: return;
}
sec += number(BlueDragon_GetSkillFactor(4, "Skill2", "gender", ptr, "min"), BlueDragon_GetSkillFactor(4, "Skill2", "gender", ptr, "max"));
sec += Random::get(BlueDragon_GetSkillFactor(4, "Skill2", "gender", ptr, "min"), BlueDragon_GetSkillFactor(4, "Skill2", "gender", ptr, "max"));
}
int addPct = BlueDragon_GetRangeFactor("hp_damage", pAttacker->GetHPPct());
int dam = number( BlueDragon_GetSkillFactor(3, "Skill2", "default_damage", "min"), BlueDragon_GetSkillFactor(3, "Skill2", "default_damage", "max") );
int dam = Random::get( BlueDragon_GetSkillFactor(3, "Skill2", "default_damage", "min"), BlueDragon_GetSkillFactor(3, "Skill2", "default_damage", "max") );
dam += (dam * addPct) / 100;
ch->Damage( pAttacker, dam, DAMAGE_TYPE_ICE);
@ -311,12 +311,12 @@ struct FSkillEarthQuake
ty = ch->GetY() + vec.y * nFlyDistance * -1;
break;
case 3:
tx = ch->GetX() + vec.x * number(1,100);
ty = ch->GetY() + vec.y * number(1,100);
tx = ch->GetX() + vec.x * Random::get(1,100);
ty = ch->GetY() + vec.y * Random::get(1,100);
break;
case 4:
tx = ch->GetX() + vec.x * number(1,10);
ty = ch->GetY() + vec.y * number(1,10);
tx = ch->GetX() + vec.x * Random::get(1,10);
ty = ch->GetY() + vec.y * Random::get(1,10);
break;
}
}

View File

@ -20,7 +20,7 @@ int Gamble(std::vector<float>& vec_probs)
{
range += vec_probs[i];
}
float fProb = fnumber(0.f, range);
float fProb = Random::get<float>(0.f, range);
float sum = 0.f;
for (int idx = 0; idx < vec_probs.size(); idx++)
{
@ -47,7 +47,7 @@ bool MakeDistinctRandomNumberSet(std::list <float> prob_lst, OUT std::vector<int
{
range += *it;
}
float r = fnumber (0.f, range);
float r = Random::get<float>(0.f, range);
float sum = 0.f;
int idx = 0;
for (std::list <float>::iterator it = prob_lst.begin(); it != prob_lst.end(); it++)
@ -184,7 +184,7 @@ bool DSManager::RefreshItemAttributes(LPITEM pDS)
}
fWeight /= 100.f;
int n = MIN(basic_apply_num, vec_basic_applys.size());
int n = std::min<int>(basic_apply_num, vec_basic_applys.size());
for (int i = 0; i < n; i++)
{
const SApply& basic_apply = vec_basic_applys[i];
@ -253,7 +253,7 @@ bool DSManager::PutAttributes(LPITEM pDS)
}
fWeight /= 100.f;
int n = MIN(basic_apply_num, vec_basic_applys.size());
int n = std::min<int>(basic_apply_num, vec_basic_applys.size());
for (int i = 0; i < n; i++)
{
const SApply& basic_apply = vec_basic_applys[i];
@ -263,7 +263,7 @@ bool DSManager::PutAttributes(LPITEM pDS)
pDS->SetForceAttribute(i, bType, sValue);
}
BYTE additional_attr_num = MIN(number (add_min, add_max), 3);
BYTE additional_attr_num = std::min(Random::get(add_min, add_max), 3);
std::vector <int> random_set;
if (additional_attr_num > 0)
@ -355,7 +355,7 @@ bool DSManager::ExtractDragonHeart(LPCHARACTER ch, LPITEM pItem, LPITEM pExtract
}
float fCharge = vec_chargings[idx] * (100 + iBonus) / 100.f;
fCharge = std::MINMAX <float> (0.f, fCharge, 100.f);
fCharge = std::clamp<float>(fCharge, 0.f, 100.f);
if (fCharge < FLT_EPSILON)
{
@ -450,7 +450,7 @@ bool DSManager::PullOut(LPCHARACTER ch, TItemPos DestCell, LPITEM& pItem, LPITEM
iBonus = pExtractor->GetValue(ITEM_VALUE_DRAGON_SOUL_POLL_OUT_BONUS_IDX);
pExtractor->SetCount(pExtractor->GetCount() - 1);
}
fDice = fnumber(0.f, 100.f);
fDice = Random::get<float>(0.f, 100.f);
bSuccess = fDice <= (fProb * (100 + iBonus) / 100.f);
}
@ -948,7 +948,7 @@ bool DSManager::DoRefineStrength(LPCHARACTER ch, TItemPos (&aItemPoses)[DRAGON_S
LPITEM pResult = NULL;
BYTE bSubHeader;
if (fnumber(0.f, 100.f) <= fProb)
if (Random::get<float>(0.f, 100.f) <= fProb)
{
pResult = ITEM_MANAGER::instance().CreateItem(MakeDragonSoulVnum(bType, bGrade, bStep, bStrength + 1));
if (NULL == pResult)

View File

@ -140,7 +140,7 @@ bool COXEventManager::AddQuiz(unsigned char level, const char* pszQuestion, bool
struct tag_Quiz tmpQuiz;
tmpQuiz.level = level;
strncpy(tmpQuiz.Quiz, pszQuestion, sizeof(tmpQuiz.Quiz));
strlcpy(tmpQuiz.Quiz, pszQuestion, sizeof(tmpQuiz.Quiz));
tmpQuiz.answer = answer;
m_vec_quiz[level].push_back(tmpQuiz);
@ -217,7 +217,7 @@ EVENTFUNC(oxevent_timer)
if (LC_IsJapan())
{
SendNoticeMap("間違えた方々を外に移動させます。", OXEVENT_MAP_INDEX, true);
SendNoticeMap("??????X??O??????????B", OXEVENT_MAP_INDEX, true);
}
else
{
@ -245,7 +245,7 @@ bool COXEventManager::Quiz(unsigned char level, int timelimit)
if (timelimit < 0) timelimit = 30;
int idx = number(0, m_vec_quiz[level].size()-1);
int idx = Random::get<int>(0, m_vec_quiz[level].size() - 1);
SendNoticeMap(LC_TEXT("문제 입니다."), OXEVENT_MAP_INDEX, true);
SendNoticeMap(m_vec_quiz[level][idx].Quiz, OXEVENT_MAP_INDEX, true);
@ -313,10 +313,10 @@ bool COXEventManager::CheckAnswer(bool answer)
else
{
pkChar->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("정답입니다!"));
// pkChar->CreateFly(number(FLY_FIREWORK1, FLY_FIREWORK6), pkChar);
// pkChar->CreateFly(Random::get(FLY_FIREWORK1, FLY_FIREWORK6), pkChar);
char chatbuf[256];
int len = snprintf(chatbuf, sizeof(chatbuf),
"%s %u %u", number(0, 1) == 1 ? "cheer1" : "cheer2", (DWORD)pkChar->GetVID(), 0);
"%s %u %u", Random::get(0, 1) == 1 ? "cheer1" : "cheer2", (DWORD)pkChar->GetVID(), 0);
// 리턴값이 sizeof(chatbuf) 이상일 경우 truncate되었다는 뜻..
if (len < 0 || len >= (int) sizeof(chatbuf))
@ -370,7 +370,7 @@ void COXEventManager::WarpToAudience()
if (pkChar != NULL)
{
switch ( number(0, 3))
switch ( Random::get(0, 3))
{
case 0 : pkChar->Show(OXEVENT_MAP_INDEX, 896300, 28900); break;
case 1 : pkChar->Show(OXEVENT_MAP_INDEX, 890900, 28100); break;

View File

@ -141,13 +141,13 @@ DWORD CPetActor::Summon(const char* petName, LPITEM pSummonItem, bool bSpawnFar)
if (true == bSpawnFar)
{
x += (number(0, 1) * 2 - 1) * number(2000, 2500);
y += (number(0, 1) * 2 - 1) * number(2000, 2500);
x += (Random::get(0, 1) * 2 - 1) * Random::get(2000, 2500);
y += (Random::get(0, 1) * 2 - 1) * Random::get(2000, 2500);
}
else
{
x += number(-100, 100);
y += number(-100, 100);
x += Random::get(-100, 100);
y += Random::get(-100, 100);
}
if (0 != m_pkChar)
@ -192,12 +192,12 @@ DWORD CPetActor::Summon(const char* petName, LPITEM pSummonItem, bool bSpawnFar)
bool CPetActor::_UpdatAloneActionAI(float fMinDist, float fMaxDist)
{
float fDist = number(fMinDist, fMaxDist);
float r = (float)number (0, 359);
float fDist = Random::get(fMinDist, fMaxDist);
float r = Random::get<float>(0, 359);
float dest_x = GetOwner()->GetX() + fDist * cos(r);
float dest_y = GetOwner()->GetY() + fDist * sin(r);
//m_pkChar->SetRotation(number(0, 359)); // 방향은 랜덤으로 설정
//m_pkChar->SetRotation(Random::get(0, 359)); // 방향은 랜덤으로 설정
//GetDeltaByDegree(m_pkChar->GetRotation(), fDist, &fx, &fy);
@ -291,7 +291,7 @@ bool CPetActor::_UpdateFollowAI()
// Follow 중이지만 주인과 일정 거리 이내로 가까워졌다면 멈춤
else
m_pkChar->SendMovePacket(FUNC_WAIT, 0, 0, 0, 0);
//else if (currentTime - m_dwLastActionTime > number(5000, 12000))
//else if (currentTime - m_dwLastActionTime > Random::get(5000, 12000))
//{
// this->_UpdatAloneActionAI(START_FOLLOW_DISTANCE / 2, START_FOLLOW_DISTANCE);
//}

View File

@ -157,27 +157,27 @@ DWORD ANI::load_one_weapon(const char *dir_name, int weapon, BYTE combo, bool ho
switch (weapon)
{
case WEAPON_SWORD:
strncpy(format, "%s/%sonehand_sword/combo_%02d.msa", sizeof(format));
strlcpy(format, "%s/%sonehand_sword/combo_%02d.msa", sizeof(format));
break;
case WEAPON_DAGGER:
strncpy(format, "%s/%sdualhand_sword/combo_%02d.msa", sizeof(format));
strlcpy(format, "%s/%sdualhand_sword/combo_%02d.msa", sizeof(format));
break;
case WEAPON_BOW:
strncpy(format, "%s/%sbow/attack.msa", sizeof(format));
strlcpy(format, "%s/%sbow/attack.msa", sizeof(format));
break;
case WEAPON_TWO_HANDED:
strncpy(format, "%s/%stwohand_sword/combo_%02d.msa", sizeof(format));
strlcpy(format, "%s/%stwohand_sword/combo_%02d.msa", sizeof(format));
break;
case WEAPON_BELL:
strncpy(format, "%s/%sbell/combo_%02d.msa", sizeof(format));
strlcpy(format, "%s/%sbell/combo_%02d.msa", sizeof(format));
break;
case WEAPON_FAN:
strncpy(format, "%s/%sfan/combo_%02d.msa", sizeof(format));
strlcpy(format, "%s/%sfan/combo_%02d.msa", sizeof(format));
break;
default:
@ -206,11 +206,11 @@ bool ANI::load_one_race(int race, const char *dir_name)
{
// ¸» ¾ÈÅÀÀ» ¶§
m_speed[race][0][weapon][combo] = load_one_weapon(dir_name, weapon, combo, false);
m_speed[race][0][weapon][0] = MIN(m_speed[race][0][weapon][0], m_speed[race][0][weapon][combo]); // ÃÖ¼Ò°ª
m_speed[race][0][weapon][0] = std::min(m_speed[race][0][weapon][0], m_speed[race][0][weapon][combo]); // ÃÖ¼Ò°ª
// ¸» ÅÀÀ» ¶§
m_speed[race][1][weapon][combo] = load_one_weapon(dir_name, weapon, combo, true);
m_speed[race][1][weapon][0] = MIN(m_speed[race][1][weapon][0], m_speed[race][1][weapon][combo]); // ÃÖ¼Ò°ª
m_speed[race][1][weapon][0] = std::min(m_speed[race][1][weapon][0], m_speed[race][1][weapon][combo]); // ÃÖ¼Ò°ª
dev_log(LOG_DEB0, "combo%02d speed=%d horse=%d",
combo, m_speed[race][0][weapon][combo], m_speed[race][1][weapon][combo]);

View File

@ -22,8 +22,6 @@
#include "ani.h"
#include "locale_service.h"
int battle_hit(LPCHARACTER ch, LPCHARACTER victim, int & iRetDam);
bool battle_distance_valid_by_xy(int x, int y, int tx, int ty)
{
int distance = DISTANCE_APPROX(x - tx, y - ty);
@ -137,7 +135,7 @@ int battle_melee_attack(LPCHARACTER ch, LPCHARACTER victim)
{
// PC일 경우 상대가 melee 몹일 경우 몹의 공격 거리가 최대 공격 거리
if (false == victim->IsPC() && BATTLE_TYPE_MELEE == victim->GetMobBattleType())
max = MAX(300, (int) (victim->GetMobAttackRange() * 1.15f));
max = std::max(300, (int) (victim->GetMobAttackRange() * 1.15f));
}
if (distance > max)
@ -161,9 +159,7 @@ int battle_melee_attack(LPCHARACTER ch, LPCHARACTER victim)
const PIXEL_POSITION & vpos = victim->GetXYZ();
ch->SetRotationToXY(vpos.x, vpos.y);
int dam;
int ret = battle_hit(ch, victim, dam);
return (ret);
return battle_hit(ch, victim);
}
// 실제 GET_BATTLE_VICTIM을 NULL로 만들고 이벤트를 캔슬 시킨다.
@ -183,7 +179,7 @@ void battle_end(LPCHARACTER ch)
int CalcBattleDamage(int iDam, int iAttackerLev, int iVictimLev)
{
if (iDam < 3)
iDam = number(1, 5);
iDam = Random::get(1, 5);
//return CALCULATE_DAMAGE_LVDELTA(iAttackerLev, iVictimLev, iDam);
return iDam;
@ -215,8 +211,8 @@ float CalcAttackRating(LPCHARACTER pkAttacker, LPCHARACTER pkVictim, bool bIgnor
if (LC_IsYMIR()) // 천마
{
iARSrc = MIN(90, pkAttacker->GetPolymorphPoint(POINT_DX));
iERSrc = MIN(90, pkVictim->GetPolymorphPoint(POINT_DX));
iARSrc = std::min(90, pkAttacker->GetPolymorphPoint(POINT_DX));
iERSrc = std::min(90, pkVictim->GetPolymorphPoint(POINT_DX));
}
else
{
@ -226,8 +222,8 @@ float CalcAttackRating(LPCHARACTER pkAttacker, LPCHARACTER pkVictim, bool bIgnor
int victim_dx = pkVictim->GetPolymorphPoint(POINT_DX);
int victim_lv = pkAttacker->GetLevel();
iARSrc = MIN(90, (attacker_dx * 4 + attacker_lv * 2) / 6);
iERSrc = MIN(90, (victim_dx * 4 + victim_lv * 2) / 6);
iARSrc = std::min(90, (attacker_dx * 4 + attacker_lv * 2) / 6);
iERSrc = std::min(90, (victim_dx * 4 + victim_lv * 2) / 6);
}
float fAR = ((float) iARSrc + 210.0f) / 300.0f; // fAR = 0.7 ~ 1.0
@ -443,7 +439,7 @@ int CalcMeleeDamage(LPCHARACTER pkAttacker, LPCHARACTER pkVictim, bool bIgnoreDe
iDamMax = pkAttacker->GetMobDamageMax();
}
iDam = number(iDamMin, iDamMax) * 2;
iDam = Random::get(iDamMin, iDamMax) * 2;
// TESTSERVER_SHOW_ATTACKINFO
DEBUG_iDamCur = iDam;
@ -483,7 +479,7 @@ int CalcMeleeDamage(LPCHARACTER pkAttacker, LPCHARACTER pkVictim, bool bIgnoreDe
if (pkAttacker->IsNPC())
iAtk = (int) (iAtk * pkAttacker->GetMobDamageMultiply());
iDam = MAX(0, iAtk - iDef);
iDam = std::max(0, iAtk - iDef);
if (test_server)
{
@ -572,7 +568,7 @@ int CalcArrowDamage(LPCHARACTER pkAttacker, LPCHARACTER pkVictim, LPITEM pkBow,
int iDam = 0;
float fAR = CalcAttackRating(pkAttacker, pkVictim, false);
iDam = number(pkBow->GetValue(3), pkBow->GetValue(4)) * 2 + pkArrow->GetValue(3);
iDam = Random::get(pkBow->GetValue(3), pkBow->GetValue(4)) * 2 + pkArrow->GetValue(3);
int iAtk;
// level must be ignored when multiply by fAR, so subtract it before calculation.
@ -596,7 +592,7 @@ int CalcArrowDamage(LPCHARACTER pkAttacker, LPCHARACTER pkVictim, LPITEM pkBow,
if (pkAttacker->IsNPC())
iAtk = (int) (iAtk * pkAttacker->GetMobDamageMultiply());
iDam = MAX(0, iAtk - iDef);
iDam = std::max(0, iAtk - iDef);
int iPureDam = iDam;
@ -621,7 +617,7 @@ void NormalAttackAffect(LPCHARACTER pkAttacker, LPCHARACTER pkVictim)
// 독 공격은 특이하므로 특수 처리
if (pkAttacker->GetPoint(POINT_POISON_PCT) && !pkVictim->IsAffectFlag(AFF_POISON))
{
if (number(1, 100) <= pkAttacker->GetPoint(POINT_POISON_PCT))
if (Random::get(1, 100) <= pkAttacker->GetPoint(POINT_POISON_PCT))
pkVictim->AttackedByPoison(pkAttacker);
}
@ -633,12 +629,8 @@ void NormalAttackAffect(LPCHARACTER pkAttacker, LPCHARACTER pkVictim)
AttackAffect(pkAttacker, pkVictim, POINT_SLOW_PCT, IMMUNE_SLOW, AFFECT_SLOW, POINT_MOV_SPEED, -30, AFF_SLOW, 20, "SLOW");
}
int battle_hit(LPCHARACTER pkAttacker, LPCHARACTER pkVictim, int & iRetDam)
int battle_hit(LPCHARACTER pkAttacker, LPCHARACTER pkVictim)
{
//PROF_UNIT puHit("Hit");
if (test_server)
sys_log(0, "battle_hit : [%s] attack to [%s] : dam :%d type :%d", pkAttacker->GetName(), pkVictim->GetName(), iRetDam);
int iDam = CalcMeleeDamage(pkAttacker, pkVictim);
if (iDam <= 0)
@ -684,7 +676,9 @@ int battle_hit(LPCHARACTER pkAttacker, LPCHARACTER pkVictim, int & iRetDam)
float tempIDam = iDam;
iDam = attMul * tempIDam + 0.5f;
iRetDam = iDam;
//PROF_UNIT puHit("Hit");
if (test_server)
sys_log(0, "battle_hit : [%s] attack to [%s] : dam: %d", pkAttacker->GetName(), pkVictim->GetName(), iDam);
//PROF_UNIT puDam("Dam");
if (pkVictim->Damage(pkAttacker, iDam, DAMAGE_TYPE_NORMAL))

View File

@ -28,6 +28,8 @@ extern int battle_count_attackers(LPCHARACTER ch);
extern void NormalAttackAffect(LPCHARACTER pkAttacker, LPCHARACTER pkVictim);
extern int battle_hit(LPCHARACTER ch, LPCHARACTER victim);
// Ư¼º °ø°Ý
inline void AttackAffect(LPCHARACTER pkAttacker,
LPCHARACTER pkVictim,
@ -42,7 +44,7 @@ inline void AttackAffect(LPCHARACTER pkAttacker,
{
if (pkAttacker->GetPoint(att_point) && !pkVictim->IsAffectFlag(affect_flag))
{
if (number(1, 100) <= pkAttacker->GetPoint(att_point) && !pkVictim->IsImmune(immune_flag))
if (Random::get(1, 100) <= pkAttacker->GetPoint(att_point) && !pkVictim->IsImmune(immune_flag))
{
pkVictim->AddAffect(affect_idx, affect_point, affect_amount, affect_flag, time, 0, true);
@ -70,7 +72,7 @@ inline void SkillAttackAffect(LPCHARACTER pkVictim,
{
if (success_pct && !pkVictim->IsAffectFlag(affect_flag))
{
if (number(1, 1000) <= success_pct && !pkVictim->IsImmune(immune_flag))
if (Random::get(1, 1000) <= success_pct && !pkVictim->IsImmune(immune_flag))
{
pkVictim->AddAffect(affect_idx, affect_point, affect_amount, affect_flag, time, 0, true);

View File

@ -155,7 +155,7 @@ bool Blend_Item_load(char *file)
static int FN_random_index()
{
int percent = number(1,100);
int percent = Random::get(1,100);
if (percent<=10) // level 1 :10%
return 0;
@ -179,7 +179,7 @@ static int FN_random_index()
static int FN_ECS_random_index()
{
int percent = number(1,100);
int percent = Random::get(1,100);
if (percent<=5) // level 1 : 5%
return 0;

View File

@ -6,7 +6,7 @@ TEMP_BUFFER::TEMP_BUFFER(int Size, bool bForceDelete)
forceDelete = bForceDelete;
if (forceDelete)
Size = MAX(Size, 1024 * 128);
Size = std::max(Size, 1024 * 128);
buf = buffer_new(Size);
}

View File

@ -296,7 +296,7 @@ static DWORD FN_random_stone()
8027
};
int index = number(0, 6);
int index = Random::get(0, 6);
return vnum[index];
}
@ -746,7 +746,7 @@ static DWORD FN_random_tower()
11510
};
int index = number(0, 4);
int index = Random::get(0, 4);
return vnum[index];
}
@ -786,7 +786,7 @@ bool castle_spawn_tower(int empire, int tower_count)
GET_TOWER(empire, i) = NULL;
}
int spawn_count = MINMAX(MIN_CASTLE_TOWER, tower_count, MAX_CASTLE_TOWER); // 5 ~ 10마리
int spawn_count = std::clamp(tower_count, MIN_CASTLE_TOWER, MAX_CASTLE_TOWER); // 5 ~ 10마리
for (int j = 0; j < spawn_count; ++j)
{

View File

@ -597,7 +597,7 @@ void CHARACTER::OpenMyShop(const char * c_pszSign, TShopItemTable * pTable, BYTE
}
char szSign[SHOP_SIGN_MAX_LEN+1];
strncpy(szSign, c_pszSign, sizeof(szSign));
strlcpy(szSign, c_pszSign, sizeof(szSign));
m_stShopSign = szSign;
@ -698,7 +698,7 @@ void CHARACTER::OpenMyShop(const char * c_pszSign, TShopItemTable * pTable, BYTE
p.bHeader = HEADER_GC_SHOP_SIGN;
p.dwVID = GetVID();
strncpy(p.szSign, c_pszSign, sizeof(p.szSign));
strlcpy(p.szSign, c_pszSign, sizeof(p.szSign));
PacketAround(&p, sizeof(TPacketGCShopSign));
@ -894,7 +894,7 @@ void CHARACTER::EncodeInsertPacket(LPENTITY entity)
else
{
show_all_info:
strncpy(addPacket.name, GetName(), sizeof(addPacket.name));
strlcpy(addPacket.name, GetName(), sizeof(addPacket.name));
if (GetGuild() != NULL)
{
@ -944,7 +944,7 @@ void CHARACTER::EncodeInsertPacket(LPENTITY entity)
p.bHeader = HEADER_GC_SHOP_SIGN;
p.dwVID = GetVID();
strncpy(p.szSign, m_stShopSign.c_str(), sizeof(p.szSign));
strlcpy(p.szSign, m_stShopSign.c_str(), sizeof(p.szSign));
d->Packet(&p, sizeof(TPacketGCShopSign));
}
@ -1127,14 +1127,14 @@ void CHARACTER::CreatePlayerProto(TPlayerTable & tab)
if (GetNewName().empty())
{
strncpy(tab.name, GetName(), sizeof(tab.name));
strlcpy(tab.name, GetName(), sizeof(tab.name));
}
else
{
strncpy(tab.name, GetNewName().c_str(), sizeof(tab.name));
strlcpy(tab.name, GetNewName().c_str(), sizeof(tab.name));
}
strncpy(tab.ip, GetDesc()->GetHostName(), sizeof(tab.ip));
strlcpy(tab.ip, GetDesc()->GetHostName(), sizeof(tab.ip));
tab.id = m_dwPlayerID;
tab.voice = GetPoint(POINT_VOICE);
@ -1224,7 +1224,7 @@ void CHARACTER::CreatePlayerProto(TPlayerTable & tab)
tab.quickslot[i] = m_quickslot[i];
if (m_stMobile.length() && !*m_szMobileAuth)
strncpy(tab.szMobile, m_stMobile.c_str(), sizeof(tab.szMobile));
strlcpy(tab.szMobile, m_stMobile.c_str(), sizeof(tab.szMobile));
memcpy(tab.parts, m_pointsInstant.parts, sizeof(tab.parts));
@ -1303,7 +1303,7 @@ void CHARACTER::Disconnect(const char * c_pszReason)
// P2P Logout
TPacketGGLogout p;
p.bHeader = HEADER_GG_LOGOUT;
strncpy(p.szName, GetName(), sizeof(p.szName));
strlcpy(p.szName, GetName(), sizeof(p.szName));
P2P_MANAGER::instance().Send(&p, sizeof(TPacketGGLogout));
char buf[51];
snprintf(buf, sizeof(buf), "%s %d %d %d %d",
@ -1534,10 +1534,10 @@ void CHARACTER::MainCharacterPacket()
mainChrPacket.lz = GetZ();
mainChrPacket.empire = GetDesc()->GetEmpire();
mainChrPacket.skill_group = GetSkillGroup();
strncpy(mainChrPacket.szChrName, GetName(), sizeof(mainChrPacket.szChrName));
strlcpy(mainChrPacket.szChrName, GetName(), sizeof(mainChrPacket.szChrName));
mainChrPacket.fBGMVol = bgmInfo.vol;
strncpy(mainChrPacket.szBGMName, bgmInfo.name.c_str(), sizeof(mainChrPacket.szBGMName));
strlcpy(mainChrPacket.szBGMName, bgmInfo.name.c_str(), sizeof(mainChrPacket.szBGMName));
GetDesc()->Packet(&mainChrPacket, sizeof(TPacketGCMainCharacter4_BGM_VOL));
}
else
@ -1552,8 +1552,8 @@ void CHARACTER::MainCharacterPacket()
mainChrPacket.lz = GetZ();
mainChrPacket.empire = GetDesc()->GetEmpire();
mainChrPacket.skill_group = GetSkillGroup();
strncpy(mainChrPacket.szChrName, GetName(), sizeof(mainChrPacket.szChrName));
strncpy(mainChrPacket.szBGMName, bgmInfo.name.c_str(), sizeof(mainChrPacket.szBGMName));
strlcpy(mainChrPacket.szChrName, GetName(), sizeof(mainChrPacket.szChrName));
strlcpy(mainChrPacket.szBGMName, bgmInfo.name.c_str(), sizeof(mainChrPacket.szBGMName));
GetDesc()->Packet(&mainChrPacket, sizeof(TPacketGCMainCharacter3_BGM));
}
//if (m_stMobile.length())
@ -1573,7 +1573,7 @@ void CHARACTER::MainCharacterPacket()
pack.lz = GetZ();
pack.empire = GetDesc()->GetEmpire();
pack.skill_group = GetSkillGroup();
strncpy(pack.szName, GetName(), sizeof(pack.szName));
strlcpy(pack.szName, GetName(), sizeof(pack.szName));
GetDesc()->Packet(&pack, sizeof(TPacketGCMainCharacter));
if (m_stMobile.length())
@ -1951,7 +1951,7 @@ void CHARACTER::SetProto(const CMob * pkMob)
info->ch = this;
m_pkMiningEvent = event_create(kill_ore_load_event, info, PASSES_PER_SEC(number(7 * 60, 15 * 60)));
m_pkMiningEvent = event_create(kill_ore_load_event, info, PASSES_PER_SEC(Random::get(7 * 60, 15 * 60)));
}
// END_OF_MINING
}
@ -2411,7 +2411,7 @@ EVENTFUNC(recovery_event)
// 몬스터 회복
//
if (ch->IsAffectFlag(AFF_POISON))
return PASSES_PER_SEC(MAX(1, ch->GetMobTable().bRegenCycle));
return PASSES_PER_SEC(std::max<int>(1, ch->GetMobTable().bRegenCycle));
if (2493 == ch->GetMobTable().dwVnum)
{
@ -2432,12 +2432,12 @@ EVENTFUNC(recovery_event)
}
}
ch->PointChange(POINT_HP, MAX(1, (ch->GetMaxHP() * regenPct) / 100));
ch->PointChange(POINT_HP, std::max(1, (ch->GetMaxHP() * regenPct) / 100));
}
else if (!ch->IsDoor())
{
ch->MonsterLog("HP_REGEN +%d", MAX(1, (ch->GetMaxHP() * ch->GetMobTable().bRegenPercent) / 100));
ch->PointChange(POINT_HP, MAX(1, (ch->GetMaxHP() * ch->GetMobTable().bRegenPercent) / 100));
ch->MonsterLog("HP_REGEN +%d", std::max(1, (ch->GetMaxHP() * ch->GetMobTable().bRegenPercent) / 100));
ch->PointChange(POINT_HP, std::max(1, (ch->GetMaxHP() * ch->GetMobTable().bRegenPercent) / 100));
}
if (ch->GetHP() >= ch->GetMaxHP())
@ -2456,12 +2456,12 @@ EVENTFUNC(recovery_event)
size_t val = BlueDragon_GetIndexFactor("DragonStone", i, "val");
size_t cnt = SECTREE_MANAGER::instance().GetMonsterCountInMap( ch->GetMapIndex(), dwDragonStoneID );
return PASSES_PER_SEC(MAX(1, (ch->GetMobTable().bRegenCycle - (val*cnt))));
return PASSES_PER_SEC(std::max<int>(1, (ch->GetMobTable().bRegenCycle - (val*cnt))));
}
}
}
return PASSES_PER_SEC(MAX(1, ch->GetMobTable().bRegenCycle));
return PASSES_PER_SEC(std::max<int>(1, ch->GetMobTable().bRegenCycle));
}
else
{
@ -2492,7 +2492,7 @@ EVENTFUNC(recovery_event)
int iAmount = 0;
{
iPercent = aiRecoveryPercents[MIN(9, iSec)];
iPercent = aiRecoveryPercents[std::min(9, iSec)];
iAmount = 15 + (ch->GetMaxHP() * iPercent) / 100;
}
@ -2520,7 +2520,7 @@ void CHARACTER::StartRecoveryEvent()
info->ch = this;
int iSec = IsPC() ? 3 : (MAX(1, GetMobTable().bRegenCycle));
int iSec = IsPC() ? 3 : (std::max<int>(1, GetMobTable().bRegenCycle));
m_pkRecoveryEvent = event_create(recovery_event, info, PASSES_PER_SEC(iSec));
}
@ -3155,8 +3155,8 @@ void CHARACTER::PointChange(BYTE type, int amount, bool bAmount, bool bBroadcast
case 4:
{
int iHP = number(JobInitialPoints[GetJob()].hp_per_lv_begin, JobInitialPoints[GetJob()].hp_per_lv_end);
int iSP = number(JobInitialPoints[GetJob()].sp_per_lv_begin, JobInitialPoints[GetJob()].sp_per_lv_end);
int iHP = Random::get(JobInitialPoints[GetJob()].hp_per_lv_begin, JobInitialPoints[GetJob()].hp_per_lv_end);
int iSP = Random::get(JobInitialPoints[GetJob()].sp_per_lv_begin, JobInitialPoints[GetJob()].sp_per_lv_end);
m_points.iRandomHP += iHP;
m_points.iRandomSP += iSP;
@ -3210,7 +3210,7 @@ void CHARACTER::PointChange(BYTE type, int amount, bool bAmount, bool bBroadcast
int prev_hp = GetHP();
amount = MIN(GetMaxHP() - GetHP(), amount);
amount = std::min(GetMaxHP() - GetHP(), amount);
SetHP(GetHP() + amount);
val = GetHP();
@ -3226,7 +3226,7 @@ void CHARACTER::PointChange(BYTE type, int amount, bool bAmount, bool bBroadcast
if (IsDead() || IsStun())
return;
amount = MIN(GetMaxSP() - GetSP(), amount);
amount = std::min(GetMaxSP() - GetSP(), amount);
SetSP(GetSP() + amount);
val = GetSP();
}
@ -3238,7 +3238,7 @@ void CHARACTER::PointChange(BYTE type, int amount, bool bAmount, bool bBroadcast
return;
int prev_val = GetStamina();
amount = MIN(GetMaxStamina() - GetStamina(), amount);
amount = std::min(GetMaxStamina() - GetStamina(), amount);
SetStamina(GetStamina() + amount);
val = GetStamina();
@ -3265,7 +3265,7 @@ void CHARACTER::PointChange(BYTE type, int amount, bool bAmount, bool bBroadcast
//SetMaxHP(GetMaxHP() + amount);
// 최대 생명력 = (기본 최대 생명력 + 추가) * 최대생명력%
int hp = GetRealPoint(POINT_MAX_HP);
int add_hp = MIN(3500, hp * GetPoint(POINT_MAX_HP_PCT) / 100);
int add_hp = std::min(3500, hp * GetPoint(POINT_MAX_HP_PCT) / 100);
add_hp += GetPoint(POINT_MAX_HP);
add_hp += GetPoint(POINT_PARTY_TANKER_BONUS);
@ -3282,7 +3282,7 @@ void CHARACTER::PointChange(BYTE type, int amount, bool bAmount, bool bBroadcast
//SetMaxSP(GetMaxSP() + amount);
// 최대 정신력 = (기본 최대 정신력 + 추가) * 최대정신력%
int sp = GetRealPoint(POINT_MAX_SP);
int add_sp = MIN(800, sp * GetPoint(POINT_MAX_SP_PCT) / 100);
int add_sp = std::min(800, sp * GetPoint(POINT_MAX_SP_PCT) / 100);
add_sp += GetPoint(POINT_MAX_SP);
add_sp += GetPoint(POINT_PARTY_SKILL_MASTER_BONUS);
@ -3951,7 +3951,7 @@ void CHARACTER::mining(LPCHARACTER chLoad)
return;
}
int count = number(5, 15); // µ¿ÀÛ È½¼ö, ÇÑ µ¿ÀÛ´ç 2ÃÊ
int count = Random::get(5, 15); // µ¿ÀÛ È½¼ö, ÇÑ µ¿ÀÛ´ç 2ÃÊ
// 채광 동작을 보여줌
TPacketGCDigMotion p;
@ -5105,7 +5105,7 @@ void CHARACTER::SetTarget(LPCHARACTER pkChrTarget)
int iHorseMaxHealth = owner->GetHorseMaxHealth();
if (iHorseMaxHealth)
p.bHPPercent = MINMAX(0, iHorseHealth * 100 / iHorseMaxHealth, 100);
p.bHPPercent = std::clamp(iHorseHealth * 100 / iHorseMaxHealth, 0, 100);
else
p.bHPPercent = 100;
}
@ -5113,7 +5113,7 @@ void CHARACTER::SetTarget(LPCHARACTER pkChrTarget)
p.bHPPercent = 100;
}
else
p.bHPPercent = MINMAX(0, (m_pkChrTarget->GetHP() * 100) / m_pkChrTarget->GetMaxHP(), 100);
p.bHPPercent = std::clamp((m_pkChrTarget->GetHP() * 100) / m_pkChrTarget->GetMaxHP(), 0, 100);
}
}
else
@ -5138,7 +5138,7 @@ void CHARACTER::BroadcastTargetPacket()
if (IsPC())
p.bHPPercent = 0;
else
p.bHPPercent = MINMAX(0, (GetHP() * 100) / GetMaxHP(), 100);
p.bHPPercent = std::clamp((GetHP() * 100) / GetMaxHP(), 0, 100);
CHARACTER_SET::iterator it = m_set_pkChrTargetedBy.begin();
@ -5306,7 +5306,7 @@ void CHARACTER::WarpEnd()
TPacketGGLogin p;
p.bHeader = HEADER_GG_LOGIN;
strncpy(p.szName, GetName(), sizeof(p.szName));
strlcpy(p.szName, GetName(), sizeof(p.szName));
p.dwPID = GetPlayerID();
p.bEmpire = GetEmpire();
p.lMapIndex = SECTREE_MANAGER::instance().GetMapIndex(GetX(), GetY());
@ -5465,9 +5465,9 @@ bool CHARACTER::Follow(LPCHARACTER pkChr, float fMinDistance)
while (--retry)
{
if (fDist < 500.0f)
GetDeltaByDegree((rot + number(-90, 90) + number(-90, 90)) % 360, fMinDistance, &fx, &fy);
GetDeltaByDegree((rot + Random::get(-90, 90) + Random::get(-90, 90)) % 360, fMinDistance, &fx, &fy);
else
GetDeltaByDegree(number(0, 359), fMinDistance, &fx, &fy);
GetDeltaByDegree(Random::get(0, 359), fMinDistance, &fx, &fy);
dx = x + (int) fx;
dy = y + (int) fy;
@ -5552,8 +5552,8 @@ void CHARACTER::ReqSafeboxLoad(const char* pszPassword)
TSafeboxLoadPacket p;
p.dwID = GetDesc()->GetAccountTable().id;
strncpy(p.szLogin, GetDesc()->GetAccountTable().login, sizeof(p.szLogin));
strncpy(p.szPassword, pszPassword, sizeof(p.szPassword));
strlcpy(p.szLogin, GetDesc()->GetAccountTable().login, sizeof(p.szLogin));
strlcpy(p.szPassword, pszPassword, sizeof(p.szPassword));
db_clientdesc->DBPacket(HEADER_GD_SAFEBOX_LOAD, GetDesc()->GetHandle(), &p, sizeof(p));
}
@ -5727,7 +5727,7 @@ bool CHARACTER::BuildUpdatePartyPacket(TPacketGCPartyUpdate & out)
out.header = HEADER_GC_PARTY_UPDATE;
out.pid = GetPlayerID();
out.percent_hp = MINMAX(0, GetHP() * 100 / GetMaxHP(), 100);
out.percent_hp = std::clamp(GetHP() * 100 / GetMaxHP(), 0, 100);
out.role = GetParty()->GetRole(GetPlayerID());
sys_log(1, "PARTY %s role is %d", GetName(), out.role);
@ -5878,11 +5878,11 @@ void CHARACTER::ResetPoint(int iLv)
SetRealPoint(POINT_IQ, JobInitialPoints[bJob].iq);
SetPoint(POINT_IQ, GetRealPoint(POINT_IQ));
SetRandomHP((iLv - 1) * number(JobInitialPoints[GetJob()].hp_per_lv_begin, JobInitialPoints[GetJob()].hp_per_lv_end));
SetRandomSP((iLv - 1) * number(JobInitialPoints[GetJob()].sp_per_lv_begin, JobInitialPoints[GetJob()].sp_per_lv_end));
SetRandomHP((iLv - 1) * Random::get(JobInitialPoints[GetJob()].hp_per_lv_begin, JobInitialPoints[GetJob()].hp_per_lv_end));
SetRandomSP((iLv - 1) * Random::get(JobInitialPoints[GetJob()].sp_per_lv_begin, JobInitialPoints[GetJob()].sp_per_lv_end));
//PointChange(POINT_STAT, ((MINMAX(1, iLv, 99) - 1) * 3) + GetPoint(POINT_LEVEL_STEP) - GetPoint(POINT_STAT));
PointChange(POINT_STAT, ((MINMAX(1, iLv, 90) - 1) * 3) + GetPoint(POINT_LEVEL_STEP) - GetPoint(POINT_STAT));
//PointChange(POINT_STAT, ((std::clamp(iLv, 1, 99) - 1) * 3) + GetPoint(POINT_LEVEL_STEP) - GetPoint(POINT_STAT));
PointChange(POINT_STAT, ((std::clamp(iLv, 1, 90) - 1) * 3) + GetPoint(POINT_LEVEL_STEP) - GetPoint(POINT_STAT));
ComputePoints();
@ -5917,14 +5917,14 @@ void CHARACTER::GiveRandomSkillBook()
{
BYTE bJob = 0;
if (!number(0, 1))
if (!Random::get<bool>())
bJob = GetJob() + 1;
DWORD dwSkillVnum = 0;
do
{
dwSkillVnum = number(1, 111);
dwSkillVnum = Random::get(1, 111);
const CSkillProto* pkSk = CSkillManager::instance().Get(dwSkillVnum);
if (NULL == pkSk)
@ -6014,12 +6014,12 @@ void CHARACTER::MonsterChat(BYTE bMonsterChatType)
if (IsMonster())
{
if (number(0, 60))
if (Random::get(0, 60))
return;
snprintf(sbuf, sizeof(sbuf),
"(locale.monster_chat[%i] and locale.monster_chat[%i][%d] or '')",
GetRaceNum(), GetRaceNum(), bMonsterChatType*3 + number(1, 3));
GetRaceNum(), GetRaceNum(), bMonsterChatType*3 + Random::get(1, 3));
}
else
{
@ -6028,12 +6028,12 @@ void CHARACTER::MonsterChat(BYTE bMonsterChatType)
if (IsGuardNPC())
{
if (number(0, 6))
if (Random::get(0, 6))
return;
}
else
{
if (number(0, 30))
if (Random::get(0, 30))
return;
}
@ -6126,7 +6126,7 @@ int CHARACTER::GetPolymorphPower() const
if (value)
return value;
}
return aiPolymorphPowerByLevel[MINMAX(0, GetSkillLevel(SKILL_POLYMORPH), 40)];
return aiPolymorphPowerByLevel[std::clamp(GetSkillLevel(SKILL_POLYMORPH), 0, 40)];
}
void CHARACTER::SetPolymorph(DWORD dwRaceNum, bool bMaintainStat)
@ -6219,8 +6219,8 @@ void CHARACTER::DetermineDropMetinStone()
const SStoneDropInfo & info = aStoneDrop[idx];
m_bDropMetinStonePct = info.iDropPct;
{
m_dwDropMetinStone = c_adwMetin[number(0, METIN_STONE_NUM - 1)];
int iGradePct = number(1, 100);
m_dwDropMetinStone = c_adwMetin[Random::get(0, METIN_STONE_NUM - 1)];
int iGradePct = Random::get(1, 100);
for (int iStoneLevel = 0; iStoneLevel < STONE_LEVEL_MAX_NUM; iStoneLevel ++)
{
int iLevelGradePortion = info.iLevelPct[iStoneLevel];
@ -6327,7 +6327,7 @@ namespace {
if (3 != sscanf(pkWarp->GetName(), " %s %d %d ", szTmp, &m_lTargetX, &m_lTargetY))
{
if (number(1, 100) < 5)
if (Random::get(1, 100) < 5)
sys_err("Warp NPC name wrong : vnum(%d) name(%s)", pkWarp->GetRaceNum(), pkWarp->GetName());
m_bInvalid = true;
@ -6500,7 +6500,7 @@ void CHARACTER::ConfirmWithMsg(const char* szMsg, int iTimeout, DWORD dwRequestP
p.header = HEADER_GC_QUEST_CONFIRM;
p.requestPID = dwRequestPID;
p.timeout = iTimeout;
strncpy(p.msg, szMsg, sizeof(p.msg));
strlcpy(p.msg, szMsg, sizeof(p.msg));
GetDesc()->Packet(&p, sizeof(p));
}
@ -6889,7 +6889,7 @@ void CHARACTER::SetGodSpeed(bool mode)
bool CHARACTER::IsDeathBlow() const
{
if (number(1, 100) <= m_pkMobData->m_table.bDeathBlowPoint)
if (Random::get(1, 100) <= m_pkMobData->m_table.bDeathBlowPoint)
{
return true;
}
@ -6916,7 +6916,7 @@ struct FFindReviver
if (ch->IsReviver() == true && pChar != ch && ch->IsDead() != true)
{
if (number(1, 100) <= ch->GetMobTable().bRevivePoint)
if (Random::get(1, 100) <= ch->GetMobTable().bRevivePoint)
{
HasReviver = true;
pChar = ch;
@ -7127,7 +7127,7 @@ void CHARACTER::IncreaseComboHackCount(int k)
if (m_iComboHackCount >= 10)
{
if (GetDesc())
if (GetDesc()->DelayedDisconnect(number(2, 7)))
if (GetDesc()->DelayedDisconnect(Random::get(2, 7)))
{
sys_log(0, "COMBO_HACK_DISCONNECT: %s count: %d", GetName(), m_iComboHackCount);
LogManager::instance().HackLog("Combo", this);
@ -7204,5 +7204,5 @@ DWORD CHARACTER::GetNextExp() const
int CHARACTER::GetSkillPowerByLevel(int level, bool bMob) const
{
return CTableBySkill::instance().GetSkillPowerByLevelFromType(GetJob(), GetSkillGroup(), MINMAX(0, level, SKILL_MAX_LEVEL), bMob);
return CTableBySkill::instance().GetSkillPowerByLevelFromType(GetJob(), GetSkillGroup(), std::clamp<int>(level, 0, SKILL_MAX_LEVEL), bMob);
}

View File

@ -1982,8 +1982,8 @@ class CHARACTER : public CEntity, public CFSM, public CHorseRider
//독일 선물 기능 패킷 임시 저장
private:
unsigned int itemAward_vnum;
char itemAward_cmd[20];
unsigned int itemAward_vnum = 0;
char itemAward_cmd[20] = "";
//bool itemAward_flag;
public:
unsigned int GetItemAward_vnum() { return itemAward_vnum; }

View File

@ -103,11 +103,11 @@ bool CHARACTER::UpdateAffect()
if (LC_IsYMIR())
{
iVal = MIN(GetPoint(POINT_HP_RECOVERY), GetMaxHP() * 9 / 100);
iVal = std::min(GetPoint(POINT_HP_RECOVERY), GetMaxHP() * 9 / 100);
}
else
{
iVal = MIN(GetPoint(POINT_HP_RECOVERY), GetMaxHP() * 7 / 100);
iVal = std::min(GetPoint(POINT_HP_RECOVERY), GetMaxHP() * 7 / 100);
}
PointChange(POINT_HP, iVal);
@ -124,9 +124,9 @@ bool CHARACTER::UpdateAffect()
int iVal;
if (!g_iUseLocale)
iVal = MIN(GetPoint(POINT_SP_RECOVERY), GetMaxSP() * 7 / 100);
iVal = std::min(GetPoint(POINT_SP_RECOVERY), GetMaxSP() * 7 / 100);
else
iVal = MIN(GetPoint(POINT_SP_RECOVERY), GetMaxSP() * 7 / 100);
iVal = std::min(GetPoint(POINT_SP_RECOVERY), GetMaxSP() * 7 / 100);
PointChange(POINT_SP, iVal);
PointChange(POINT_SP_RECOVERY, -iVal);

View File

@ -108,7 +108,7 @@ void CHARACTER::DistributeSP(LPCHARACTER pkKiller, int iMethod)
if (iMethod == 1)
{
int num = number(0, 3);
int num = Random::get(0, 3);
if (!num)
{
@ -294,7 +294,7 @@ void CHARACTER::DeathPenalty(BYTE bTown)
return;
}
if (number(0, 2))
if (Random::get(0, 2))
{
sys_log(0, "NO_DEATH_PENALTY_LUCK(%s)", GetName());
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("용신의 가호로 경험치가 떨어지지 않았습니다."));
@ -328,22 +328,22 @@ void CHARACTER::DeathPenalty(BYTE bTown)
}
// END_OF_NO_DEATH_PENALTY_BUG_FIX
int iLoss = ((GetNextExp() * aiExpLossPercents[MINMAX(1, GetLevel(), PLAYER_EXP_TABLE_MAX)]) / 100);
int iLoss = ((GetNextExp() * aiExpLossPercents[std::clamp<int>(GetLevel(), 1, PLAYER_EXP_TABLE_MAX)]) / 100);
if (true == LC_IsYMIR())
{
if (PLAYER_EXP_TABLE_MAX < GetLevel())
{
iLoss = MIN(500000, iLoss);
iLoss = std::min(500000, iLoss);
}
else
{
iLoss = MIN(200000, iLoss);
iLoss = std::min(200000, iLoss);
}
}
else if (true == LC_IsEurope())
{
iLoss = MIN(800000, iLoss);
iLoss = std::min(800000, iLoss);
}
if (bTown)
@ -361,7 +361,7 @@ void CHARACTER::DeathPenalty(BYTE bTown)
if (IsEquipUniqueItem(UNIQUE_ITEM_TEARDROP_OF_GODNESS))
iLoss /= 2;
sys_log(0, "DEATH_PENALTY(%s) EXP_LOSS: %d percent %d%%", GetName(), iLoss, aiExpLossPercents[MIN(gPlayerMaxLevel, GetLevel())]);
sys_log(0, "DEATH_PENALTY(%s) EXP_LOSS: %d percent %d%%", GetName(), iLoss, aiExpLossPercents[std::min(gPlayerMaxLevel, GetLevel())]);
PointChange(POINT_EXP, -iLoss, true);
}
@ -579,19 +579,19 @@ void CHARACTER::RewardGold(LPCHARACTER pkAttacker)
iPercent = ((iGoldPercent * PERCENT_LVDELTA(pkAttacker->GetLevel(), GetLevel())) / 100);
//int iPercent = CALCULATE_VALUE_LVDELTA(pkAttacker->GetLevel(), GetLevel(), iGoldPercent);
if (number(1, 100) > iPercent)
if (Random::get(1, 100) > iPercent)
return;
int iGoldMultipler = GetGoldMultipler();
if (1 == number(1, 50000)) // 1/50000 확률로 돈이 10배
if (1 == Random::get(1, 50000)) // 1/50000 확률로 돈이 10배
iGoldMultipler *= 10;
else if (1 == number(1, 10000)) // 1/10000 확률로 돈이 5배
else if (1 == Random::get(1, 10000)) // 1/10000 확률로 돈이 5배
iGoldMultipler *= 5;
// 개인 적용
if (pkAttacker->GetPoint(POINT_GOLD_DOUBLE_BONUS))
if (number(1, 100) <= pkAttacker->GetPoint(POINT_GOLD_DOUBLE_BONUS))
if (Random::get(1, 100) <= pkAttacker->GetPoint(POINT_GOLD_DOUBLE_BONUS))
iGoldMultipler *= 2;
//
@ -611,14 +611,14 @@ void CHARACTER::RewardGold(LPCHARACTER pkAttacker)
// MOB_RANK가 BOSS보다 높으면 무조건 돈폭탄
if (GetMobRank() >= MOB_RANK_BOSS && !IsStone() && GetMobTable().dwGoldMax != 0)
{
if (1 == number(1, iGold10DropPct))
if (1 == Random::get(1, iGold10DropPct))
iGoldMultipler *= 10; // 1% 확률로 돈 10배
int iSplitCount = number(25, 35);
int iSplitCount = Random::get(25, 35);
for (int i = 0; i < iSplitCount; ++i)
{
int iGold = number(GetMobTable().dwGoldMin, GetMobTable().dwGoldMax) / iSplitCount;
int iGold = Random::get(GetMobTable().dwGoldMin, GetMobTable().dwGoldMax) / iSplitCount;
if (test_server)
sys_log(0, "iGold %d", iGold);
iGold = iGold * CHARACTER_MANAGER::instance().GetMobGoldAmountRate(pkAttacker) / 100;
@ -638,8 +638,8 @@ void CHARACTER::RewardGold(LPCHARACTER pkAttacker)
// NOTE: 돈 폭탄은 제 3의 손 처리를 하지 않음
if ((item = ITEM_MANAGER::instance().CreateItem(1, iGold)))
{
pos.x = GetX() + ((number(-14, 14) + number(-14, 14)) * 23);
pos.y = GetY() + ((number(-14, 14) + number(-14, 14)) * 23);
pos.x = GetX() + ((Random::get(-14, 14) + Random::get(-14, 14)) * 23);
pos.y = GetY() + ((Random::get(-14, 14) + Random::get(-14, 14)) * 23);
item->AddToGround(GetMapIndex(), pos);
item->StartDestroyEvent();
@ -649,14 +649,14 @@ void CHARACTER::RewardGold(LPCHARACTER pkAttacker)
}
}
// 1% 확률로 돈을 10개 떨어 뜨린다. (10배 드롭임)
else if (1 == number(1, iGold10DropPct))
else if (1 == Random::get(1, iGold10DropPct))
{
//
// 돈 폭탄식 드롭
//
for (int i = 0; i < 10; ++i)
{
int iGold = number(GetMobTable().dwGoldMin, GetMobTable().dwGoldMax);
int iGold = Random::get(GetMobTable().dwGoldMin, GetMobTable().dwGoldMax);
iGold = iGold * CHARACTER_MANAGER::instance().GetMobGoldAmountRate(pkAttacker) / 100;
iGold *= iGoldMultipler;
@ -668,8 +668,8 @@ void CHARACTER::RewardGold(LPCHARACTER pkAttacker)
// NOTE: 돈 폭탄은 제 3의 손 처리를 하지 않음
if ((item = ITEM_MANAGER::instance().CreateItem(1, iGold)))
{
pos.x = GetX() + (number(-7, 7) * 20);
pos.y = GetY() + (number(-7, 7) * 20);
pos.x = GetX() + (Random::get(-7, 7) * 20);
pos.y = GetY() + (Random::get(-7, 7) * 20);
item->AddToGround(GetMapIndex(), pos);
item->StartDestroyEvent();
@ -683,17 +683,17 @@ void CHARACTER::RewardGold(LPCHARACTER pkAttacker)
//
// 일반적인 방식의 돈 드롭
//
int iGold = number(GetMobTable().dwGoldMin, GetMobTable().dwGoldMax);
int iGold = Random::get(GetMobTable().dwGoldMin, GetMobTable().dwGoldMax);
iGold = iGold * CHARACTER_MANAGER::instance().GetMobGoldAmountRate(pkAttacker) / 100;
iGold *= iGoldMultipler;
int iSplitCount;
if (iGold >= 3 && !LC_IsYMIR())
iSplitCount = number(1, 3);
iSplitCount = Random::get(1, 3);
else if (GetMobRank() >= MOB_RANK_BOSS)
{
iSplitCount = number(3, 10);
iSplitCount = Random::get(3, 10);
if ((iGold / iSplitCount) == 0)
iSplitCount = 1;
@ -713,8 +713,8 @@ void CHARACTER::RewardGold(LPCHARACTER pkAttacker)
}
else if ((item = ITEM_MANAGER::instance().CreateItem(1, iGold / iSplitCount)))
{
pos.x = GetX() + (number(-7, 7) * 20);
pos.y = GetY() + (number(-7, 7) * 20);
pos.x = GetX() + (Random::get(-7, 7) * 20);
pos.y = GetY() + (Random::get(-7, 7) * 20);
item->AddToGround(GetMapIndex(), pos);
item->StartDestroyEvent();
@ -736,10 +736,10 @@ void CHARACTER::Reward(bool bItemDrop)
return;
LPITEM item;
int iGold = number(GetMobTable().dwGoldMin, GetMobTable().dwGoldMax);
int iGold = Random::get(GetMobTable().dwGoldMin, GetMobTable().dwGoldMax);
iGold = iGold * CHARACTER_MANAGER::instance().GetMobGoldAmountRate(NULL) / 100;
iGold *= GetGoldMultipler();
int iSplitCount = number(25, 35);
int iSplitCount = Random::get(25, 35);
sys_log(0, "WAEGU Dead gold %d split %d", iGold, iSplitCount);
@ -749,8 +749,8 @@ void CHARACTER::Reward(bool bItemDrop)
{
if (i != 0)
{
pos.x = number(-7, 7) * 20;
pos.y = number(-7, 7) * 20;
pos.x = Random::get(-7, 7) * 20;
pos.y = Random::get(-7, 7) * 20;
pos.x += GetX();
pos.y += GetY();
@ -787,7 +787,7 @@ void CHARACTER::Reward(bool bItemDrop)
quest::CQuestManager::instance().Kill(pkAttacker->GetPlayerID(), GetRaceNum());
CHARACTER_MANAGER::instance().KillLog(GetRaceNum());
if (!number(0, 9))
if (!Random::get(0, 9))
{
if (pkAttacker->GetPoint(POINT_KILL_HP_RECOVERY))
{
@ -847,8 +847,8 @@ void CHARACTER::Reward(bool bItemDrop)
item->StartDestroyEvent();
pos.x = number(-7, 7) * 20;
pos.y = number(-7, 7) * 20;
pos.x = Random::get(-7, 7) * 20;
pos.y = Random::get(-7, 7) * 20;
pos.x += GetX();
pos.y += GetY();
@ -903,8 +903,8 @@ void CHARACTER::Reward(bool bItemDrop)
//item->SetOwnership(pkAttacker);
item->StartDestroyEvent();
pos.x = number(-7, 7) * 20;
pos.y = number(-7, 7) * 20;
pos.x = Random::get(-7, 7) * 20;
pos.y = Random::get(-7, 7) * 20;
pos.x += GetX();
pos.y += GetY();
@ -945,8 +945,8 @@ void CHARACTER::Reward(bool bItemDrop)
item->StartDestroyEvent();
pos.x = number(-7, 7) * 20;
pos.y = number(-7, 7) * 20;
pos.x = Random::get(-7, 7) * 20;
pos.y = Random::get(-7, 7) * 20;
pos.x += GetX();
pos.y += GetY();
@ -1031,8 +1031,8 @@ void CHARACTER::ItemDropPenalty(LPCHARACTER pkKiller)
TItemDropPenalty & r = table[iAlignIndex];
sys_log(0, "%s align %d inven_pct %d equip_pct %d", GetName(), iAlignIndex, r.iInventoryPct, r.iEquipmentPct);
bool bDropInventory = r.iInventoryPct >= number(1, 1000);
bool bDropEquipment = r.iEquipmentPct >= number(1, 100);
bool bDropInventory = r.iInventoryPct >= Random::get(1, 1000);
bool bDropEquipment = r.iEquipmentPct >= Random::get(1, 100);
bool bDropAntiDropUniqueItem = false;
if ((bDropInventory || bDropEquipment) && IsEquipUniqueItem(UNIQUE_ITEM_SKIP_ITEM_DROP_PENALTY))
@ -1054,10 +1054,10 @@ void CHARACTER::ItemDropPenalty(LPCHARACTER pkKiller)
{
random_shuffle(vec_bSlots.begin(), vec_bSlots.end());
int iQty = MIN(vec_bSlots.size(), r.iInventoryQty);
int iQty = std::min<int>(vec_bSlots.size(), r.iInventoryQty);
if (iQty)
iQty = number(1, iQty);
iQty = Random::get(1, iQty);
for (i = 0; i < iQty; ++i)
{
@ -1090,10 +1090,10 @@ void CHARACTER::ItemDropPenalty(LPCHARACTER pkKiller)
if (isDropAllEquipments)
iQty = vec_bSlots.size();
else
iQty = MIN(vec_bSlots.size(), number(1, r.iEquipmentQty));
iQty = std::min<int>(vec_bSlots.size(), Random::get(1, r.iEquipmentQty));
if (iQty)
iQty = number(1, iQty);
iQty = Random::get(1, iQty);
for (i = 0; i < iQty; ++i)
{
@ -1147,8 +1147,8 @@ void CHARACTER::ItemDropPenalty(LPCHARACTER pkKiller)
sys_log(0, "DROP_ITEM_PK: %s %d %d from %s", item->GetName(), pos.x, pos.y, GetName());
LogManager::instance().ItemLog(this, item, "DEAD_DROP", (window == INVENTORY) ? "INVENTORY" : ((window == EQUIPMENT) ? "EQUIPMENT" : ""));
pos.x = GetX() + number(-7, 7) * 20;
pos.y = GetY() + number(-7, 7) * 20;
pos.x = GetX() + Random::get(-7, 7) * 20;
pos.y = GetY() + Random::get(-7, 7) * 20;
}
}
}
@ -1306,7 +1306,7 @@ void CHARACTER::Dead(LPCHARACTER pkKiller, bool bImmediateDead)
if (GetEmpire() != pkKiller->GetEmpire())
{
int iEP = MIN(GetPoint(POINT_EMPIRE_POINT), pkKiller->GetPoint(POINT_EMPIRE_POINT));
int iEP = std::min(GetPoint(POINT_EMPIRE_POINT), pkKiller->GetPoint(POINT_EMPIRE_POINT));
PointChange(POINT_EMPIRE_POINT, -(iEP / 10));
pkKiller->PointChange(POINT_EMPIRE_POINT, iEP / 5);
@ -1338,7 +1338,7 @@ void CHARACTER::Dead(LPCHARACTER pkKiller, bool bImmediateDead)
iNoPenaltyProb = 20;
}
if (number(1, 100) < iNoPenaltyProb)
if (Random::get(1, 100) < iNoPenaltyProb)
pkKiller->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("용신의 보호로 아이템이 떨어지지 않았습니다."));
else
{
@ -1639,7 +1639,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
if (bDropMoney)
{
DWORD dwGold = 1000;
int iSplitCount = number(10, 13);
int iSplitCount = Random::get(10, 13);
sys_log(0, "WAEGU DropGoldOnHit %d times", GetMaxSP());
@ -1652,8 +1652,8 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
{
if (i != 0)
{
pos.x = (number(-14, 14) + number(-14, 14)) * 20;
pos.y = (number(-14, 14) + number(-14, 14)) * 20;
pos.x = (Random::get(-14, 14) + Random::get(-14, 14)) * 20;
pos.y = (Random::get(-14, 14) + Random::get(-14, 14)) * 20;
pos.x += GetX();
pos.y += GetY();
@ -1673,7 +1673,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
{
int pct = GetSkillPower(SKILL_TERROR) / 400;
if (number(1, 100) <= pct)
if (Random::get(1, 100) <= pct)
return false;
}
}
@ -1726,7 +1726,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
//크리티컬 저항 값 적용.
iCriticalPct -= GetPoint(POINT_RESIST_CRITICAL);
if (number(1, 100) <= iCriticalPct)
if (Random::get(1, 100) <= iCriticalPct)
{
IsCritical = true;
dam *= 2;
@ -1773,7 +1773,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
//관통타격 저항 값 적용.
iPenetratePct -= GetPoint(POINT_RESIST_PENETRATE);
if (number(1, 100) <= iPenetratePct)
if (Random::get(1, 100) <= iPenetratePct)
{
IsPenetrate = true;
@ -1798,7 +1798,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
if (type == DAMAGE_TYPE_NORMAL)
{
// 근접 평타일 경우 막을 수 있음
if (GetPoint(POINT_BLOCK) && number(1, 100) <= GetPoint(POINT_BLOCK))
if (GetPoint(POINT_BLOCK) && Random::get(1, 100) <= GetPoint(POINT_BLOCK))
{
if (test_server)
{
@ -1813,7 +1813,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
else if (type == DAMAGE_TYPE_NORMAL_RANGE)
{
// 원거리 평타의 경우 피할 수 있음
if (GetPoint(POINT_DODGE) && number(1, 100) <= GetPoint(POINT_DODGE))
if (GetPoint(POINT_DODGE) && Random::get(1, 100) <= GetPoint(POINT_DODGE))
{
if (test_server)
{
@ -1867,7 +1867,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
//크리티컬 저항 값 적용.
iCriticalPct -= GetPoint(POINT_RESIST_CRITICAL);
if (number(1, 100) <= iCriticalPct)
if (Random::get(1, 100) <= iCriticalPct)
{
IsCritical = true;
dam *= 2;
@ -1899,7 +1899,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
//관통타격 저항 값 적용.
iPenetratePct -= GetPoint(POINT_RESIST_PENETRATE);
if (number(1, 100) <= iPenetratePct)
if (Random::get(1, 100) <= iPenetratePct)
{
IsPenetrate = true;
@ -1914,9 +1914,9 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
{
int pct = 1;
if (number(1, 10) <= pct)
if (Random::get(1, 10) <= pct)
{
int iHP = MIN(dam, MAX(0, iCurHP)) * pAttacker->GetPoint(POINT_STEAL_HP) / 100;
int iHP = std::min(dam, std::max(0, iCurHP)) * pAttacker->GetPoint(POINT_STEAL_HP) / 100;
if (iHP > 0 && GetHP() >= iHP)
{
@ -1932,7 +1932,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
{
int pct = 1;
if (number(1, 10) <= pct)
if (Random::get(1, 10) <= pct)
{
int iCur;
@ -1941,7 +1941,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
else
iCur = iCurHP;
int iSP = MIN(dam, MAX(0, iCur)) * pAttacker->GetPoint(POINT_STEAL_SP) / 100;
int iSP = std::min(dam, std::max(0, iCur)) * pAttacker->GetPoint(POINT_STEAL_SP) / 100;
if (iSP > 0 && iCur >= iSP)
{
@ -1957,18 +1957,18 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
// 돈 스틸
if (pAttacker->GetPoint(POINT_STEAL_GOLD))
{
if (number(1, 100) <= pAttacker->GetPoint(POINT_STEAL_GOLD))
if (Random::get(1, 100) <= pAttacker->GetPoint(POINT_STEAL_GOLD))
{
int iAmount = number(1, GetLevel());
int iAmount = Random::get(1, GetLevel());
pAttacker->PointChange(POINT_GOLD, iAmount);
DBManager::instance().SendMoneyLog(MONEY_LOG_MISC, 1, iAmount);
}
}
// 칠 때마다 HP회복
if (pAttacker->GetPoint(POINT_HIT_HP_RECOVERY) && number(0, 4) > 0) // 80% 확률
if (pAttacker->GetPoint(POINT_HIT_HP_RECOVERY) && Random::get(0, 4) > 0) // 80% 확률
{
int i = MIN(dam, iCurHP) * pAttacker->GetPoint(POINT_HIT_HP_RECOVERY) / 100;
int i = std::min(dam, iCurHP) * pAttacker->GetPoint(POINT_HIT_HP_RECOVERY) / 100;
if (i)
{
@ -1978,9 +1978,9 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
}
// 칠 때마다 SP회복
if (pAttacker->GetPoint(POINT_HIT_SP_RECOVERY) && number(0, 4) > 0) // 80% 확률
if (pAttacker->GetPoint(POINT_HIT_SP_RECOVERY) && Random::get(0, 4) > 0) // 80% 확률
{
int i = MIN(dam, iCurHP) * pAttacker->GetPoint(POINT_HIT_SP_RECOVERY) / 100;
int i = std::min(dam, iCurHP) * pAttacker->GetPoint(POINT_HIT_SP_RECOVERY) / 100;
if (i)
{
@ -1992,7 +1992,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
// 상대방의 마나를 없앤다.
if (pAttacker->GetPoint(POINT_MANA_BURN_PCT))
{
if (number(1, 100) <= pAttacker->GetPoint(POINT_MANA_BURN_PCT))
if (Random::get(1, 100) <= pAttacker->GetPoint(POINT_MANA_BURN_PCT))
PointChange(POINT_SP, -50);
}
}
@ -2009,7 +2009,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
if (pAttacker->GetPoint(POINT_NORMAL_HIT_DAMAGE_BONUS))
dam = dam * (100 + pAttacker->GetPoint(POINT_NORMAL_HIT_DAMAGE_BONUS)) / 100;
dam = dam * (100 - MIN(99, GetPoint(POINT_NORMAL_HIT_DEFEND_BONUS))) / 100;
dam = dam * (100 - std::min(99, GetPoint(POINT_NORMAL_HIT_DEFEND_BONUS))) / 100;
break;
case DAMAGE_TYPE_MELEE:
@ -2022,7 +2022,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
if (pAttacker->GetPoint(POINT_SKILL_DAMAGE_BONUS))
dam = dam * (100 + pAttacker->GetPoint(POINT_SKILL_DAMAGE_BONUS)) / 100;
dam = dam * (100 - MIN(99, GetPoint(POINT_SKILL_DEFEND_BONUS))) / 100;
dam = dam * (100 - std::min(99, GetPoint(POINT_SKILL_DEFEND_BONUS))) / 100;
break;
default:
@ -2049,7 +2049,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
{
// 정신력이 모자라서 피가 더 깍여야할??
PointChange(POINT_SP, -GetSP());
dam -= iSP * 100 / MAX(GetPoint(POINT_MANASHIELD), 1);
dam -= iSP * 100 / std::max(GetPoint(POINT_MANASHIELD), 1);
}
}
@ -2058,7 +2058,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
//
if (GetPoint(POINT_MALL_DEFBONUS) > 0)
{
int dec_dam = MIN(200, dam * GetPoint(POINT_MALL_DEFBONUS) / 100);
int dec_dam = std::min(200, dam * GetPoint(POINT_MALL_DEFBONUS) / 100);
dam -= dec_dam;
}
@ -2069,7 +2069,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
//
if (pAttacker->GetPoint(POINT_MALL_ATTBONUS) > 0)
{
int add_dam = MIN(300, dam * pAttacker->GetLimitPoint(POINT_MALL_ATTBONUS) / 100);
int add_dam = std::min(300, dam * pAttacker->GetLimitPoint(POINT_MALL_ATTBONUS) / 100);
dam += add_dam;
}
@ -2211,7 +2211,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu
{
if (pAttacker->IsDeathBlow())
{
if (number(1, 4) == GetJob())
if (Random::get(1, 4) == GetJob())
{
IsDeathBlow = true;
dam = dam * 4;
@ -2357,7 +2357,7 @@ static void GiveExp(LPCHARACTER from, LPCHARACTER to, int iExp)
// 아이템 경험치 두배 속성
if (to->GetPoint(POINT_EXP_DOUBLE_BONUS))
if (number(1, 100) <= to->GetPoint(POINT_EXP_DOUBLE_BONUS))
if (Random::get(1, 100) <= to->GetPoint(POINT_EXP_DOUBLE_BONUS))
iExp += iExp * 30 / 100; // 1.3배 (30%)
// 경험의 반지 (2시간짜리)
@ -2484,7 +2484,7 @@ static void GiveExp(LPCHARACTER from, LPCHARACTER to, int iExp)
iExp = iExp * CHARACTER_MANAGER::instance().GetMobExpRate(to) / 100;
// 경험치 한번 획득량 제한
iExp = MIN(to->GetNextExp() / 10, iExp);
iExp = std::min<int>(to->GetNextExp() / 10, iExp);
if (test_server)
{
@ -2821,7 +2821,7 @@ int CHARACTER::GetArrowAndBow(LPITEM * ppkBow, LPITEM * ppkArrow, int iArrowCoun
return 0;
}
iArrowCount = MIN(iArrowCount, pkArrow->GetCount());
iArrowCount = std::min<int>(iArrowCount, pkArrow->GetCount());
*ppkBow = pkBow;
*ppkArrow = pkArrow;
@ -2833,7 +2833,7 @@ void CHARACTER::UseArrow(LPITEM pkArrow, DWORD dwArrowCount)
{
int iCount = pkArrow->GetCount();
DWORD dwVnum = pkArrow->GetVnum();
iCount = iCount - MIN(iCount, dwArrowCount);
iCount = iCount - std::min<int>(iCount, dwArrowCount);
pkArrow->SetCount(iCount);
if (iCount == 0)
@ -3303,7 +3303,7 @@ void CHARACTER::UpdateAlignment(int iAmount)
int i = m_iAlignment / 10;
m_iRealAlignment = MINMAX(-200000, m_iRealAlignment + iAmount, 200000);
m_iRealAlignment = std::clamp(m_iRealAlignment + iAmount, -200000, 200000);
if (bShow)
{
@ -3406,7 +3406,7 @@ struct FuncAggregateMonster
if (ch->GetVictim())
return;
if (number(1, 100) <= 50) // 임시로 50% 확률로 적을 끌어온다
if (Random::get(1, 100) <= 50) // 임시로 50% 확률로 적을 끌어온다
if (DISTANCE_APPROX(ch->GetX() - m_ch->GetX(), ch->GetY() - m_ch->GetY()) < 5000)
if (ch->CanBeginFight())
ch->BeginFight(m_ch);

View File

@ -161,13 +161,13 @@ void CHARACTER::HorseSummon(bool bSummon, bool bFromFar, DWORD dwVnum, const cha
if (bFromFar)
{
x += (number(0, 1) * 2 - 1) * number(2000, 2500);
y += (number(0, 1) * 2 - 1) * number(2000, 2500);
x += (Random::get(0, 1) * 2 - 1) * Random::get(2000, 2500);
y += (Random::get(0, 1) * 2 - 1) * Random::get(2000, 2500);
}
else
{
x += number(-100, 100);
y += number(-100, 100);
x += Random::get(-100, 100);
y += Random::get(-100, 100);
}
m_chHorse = CHARACTER_MANAGER::instance().SpawnMob(

View File

@ -909,7 +909,7 @@ bool CHARACTER::DoRefine(LPITEM item, bool bMoneyOnly)
RemoveSpecifyItem(prt->materials[i].vnum, prt->materials[i].count);
}
int prob = number(1, 100);
int prob = Random::get(1, 100);
if (IsRefineThroughGuild() || bMoneyOnly)
prob -= 10;
@ -1110,7 +1110,7 @@ bool CHARACTER::DoRefineWithScroll(LPITEM item)
for (int i = 0; i < prt->material_count; ++i)
RemoveSpecifyItem(prt->materials[i].vnum, prt->materials[i].count);
int prob = number(1, 100);
int prob = Random::get(1, 100);
int success_prob = prt->prob;
bool bDestroyWhenFail = false;
@ -1129,16 +1129,16 @@ bool CHARACTER::DoRefineWithScroll(LPITEM item)
if (pkItemScroll->GetValue(0) == YONGSIN_SCROLL)
{
if (LC_IsYMIR() == true || LC_IsKorea() == true)
success_prob = hyuniron_prob_euckr[MINMAX(0, item->GetRefineLevel(), 8)];
success_prob = hyuniron_prob_euckr[std::clamp(item->GetRefineLevel(), 0, 8)];
else
success_prob = hyuniron_prob[MINMAX(0, item->GetRefineLevel(), 8)];
success_prob = hyuniron_prob[std::clamp(item->GetRefineLevel(), 0, 8)];
}
else if (pkItemScroll->GetValue(0) == YAGONG_SCROLL)
{
if (LC_IsYMIR() == true || LC_IsKorea() == true)
success_prob = yagong_prob_euckr[MINMAX(0, item->GetRefineLevel(), 8)];
success_prob = yagong_prob_euckr[std::clamp(item->GetRefineLevel(), 0, 8)];
else
success_prob = yagong_prob[MINMAX(0, item->GetRefineLevel(), 8)];
success_prob = yagong_prob[std::clamp(item->GetRefineLevel(), 0, 8)];
}
else
{
@ -1777,7 +1777,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
return false;
}
LPCHARACTER campfire = CHARACTER_MANAGER::instance().SpawnMob(fishing::CAMPFIRE_MOB, GetMapIndex(), (int)(GetX()+fx), (int)(GetY()+fy), 0, false, number(0, 359));
LPCHARACTER campfire = CHARACTER_MANAGER::instance().SpawnMob(fishing::CAMPFIRE_MOB, GetMapIndex(), (int)(GetX()+fx), (int)(GetY()+fy), 0, false, Random::get(0, 359));
char_event_info* info = AllocEventInfo<char_event_info>();
@ -2148,7 +2148,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
{
ITEM_MANAGER::instance().RemoveItem(item);
int iReadDelay = number(SKILLBOOK_DELAY_MIN, SKILLBOOK_DELAY_MAX);
int iReadDelay = Random::get<int>(SKILLBOOK_DELAY_MIN, SKILLBOOK_DELAY_MAX);
if (distribution_test_server)
iReadDelay /= 3;
@ -2634,7 +2634,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
else
bi = b1;
int pct = number(1, 1000);
int pct = Random::get(1, 1000);
int i;
for (i=0;i<MAX_BAG_INFO;i++)
@ -2780,7 +2780,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
else
info = info_10;
int prob = number(1, 100);
int prob = Random::get(1, 100);
for (int i = 0; i < EVENT_STONE_MAX_INFO; ++i)
{
@ -2952,7 +2952,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
else
{
// 독다루기가 없으면 50% 즉사 50% 공격력 +2
if (number(0, 1))
if (Random::get(0, 1))
{
if (GetHP() > 100)
PointChange(POINT_HP, -(GetHP() - 1));
@ -2973,7 +2973,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
{
item->SetCount(item->GetCount() - 1);
int r = number(1, 100);
int r = Random::get(1, 100);
if (r <= 50)
{
@ -3018,7 +3018,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
break;
case 71013: // 축제용폭죽
CreateFly(number(FLY_FIREWORK1, FLY_FIREWORK6), this);
CreateFly(Random::get<int>(FLY_FIREWORK1, FLY_FIREWORK6), this);
item->SetCount(item->GetCount() - 1);
break;
@ -3084,7 +3084,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
{
ITEM_MANAGER::instance().RemoveItem(item);
int iReadDelay = number(SKILLBOOK_DELAY_MIN, SKILLBOOK_DELAY_MAX);
int iReadDelay = Random::get<int>(SKILLBOOK_DELAY_MIN, SKILLBOOK_DELAY_MAX);
if (distribution_test_server) iReadDelay /= 3;
SetSkillNextReadTime(SKILL_LEADERSHIP, get_global_time() + iReadDelay);
@ -3126,7 +3126,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
{
ITEM_MANAGER::instance().RemoveItem(item);
int iReadDelay = number(SKILLBOOK_DELAY_MIN, SKILLBOOK_DELAY_MAX);
int iReadDelay = Random::get<int>(SKILLBOOK_DELAY_MIN, SKILLBOOK_DELAY_MAX);
if (distribution_test_server) iReadDelay /= 3;
SetSkillNextReadTime(SKILL_COMBO, get_global_time() + iReadDelay);
@ -3144,7 +3144,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
}
DWORD dwSkillVnum = item->GetValue(0);
int iPct = MINMAX(0, item->GetValue(1), 100);
int iPct = std::clamp(item->GetValue(1), 0, 100);
if (GetSkillLevel(dwSkillVnum)>=20 || dwSkillVnum-SKILL_LANGUAGE1+1 == GetEmpire())
{
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("이미 완벽하게 알아들을 수 있는 언어이다."));
@ -3155,7 +3155,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
{
ITEM_MANAGER::instance().RemoveItem(item);
int iReadDelay = number(SKILLBOOK_DELAY_MIN, SKILLBOOK_DELAY_MAX);
int iReadDelay = Random::get<int>(SKILLBOOK_DELAY_MIN, SKILLBOOK_DELAY_MAX);
if (distribution_test_server) iReadDelay /= 3;
SetSkillNextReadTime(dwSkillVnum, get_global_time() + iReadDelay);
@ -3172,7 +3172,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
}
DWORD dwSkillVnum = item->GetValue(0);
int iPct = MINMAX(0, item->GetValue(1), 100);
int iPct = std::clamp(item->GetValue(1), 0, 100);
if (GetSkillLevel(dwSkillVnum) >= 10)
{
@ -3184,7 +3184,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
{
ITEM_MANAGER::instance().RemoveItem(item);
int iReadDelay = number(SKILLBOOK_DELAY_MIN, SKILLBOOK_DELAY_MAX);
int iReadDelay = Random::get<int>(SKILLBOOK_DELAY_MIN, SKILLBOOK_DELAY_MAX);
if (distribution_test_server) iReadDelay /= 3;
SetSkillNextReadTime(dwSkillVnum, get_global_time() + iReadDelay);
@ -3204,7 +3204,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
int iSkillLevelLowLimit = item->GetValue(0);
int iSkillLevelHighLimit = item->GetValue(1);
int iPct = MINMAX(0, item->GetValue(2), 100);
int iPct = std::clamp(item->GetValue(2), 0, 100);
int iLevelLimit = item->GetValue(3);
DWORD dwSkillVnum = 0;
@ -3257,7 +3257,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
{
ITEM_MANAGER::instance().RemoveItem(item);
int iReadDelay = number(SKILLBOOK_DELAY_MIN, SKILLBOOK_DELAY_MAX);
int iReadDelay = Random::get<int>(SKILLBOOK_DELAY_MIN, SKILLBOOK_DELAY_MAX);
if (distribution_test_server) iReadDelay /= 3;
SetSkillNextReadTime(dwSkillVnum, get_global_time() + iReadDelay);
@ -3276,7 +3276,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
}
DWORD dwSkillVnum = SKILL_CREATE;
int iPct = MINMAX(0, item->GetValue(1), 100);
int iPct = std::clamp(item->GetValue(1), 0, 100);
if (GetSkillLevel(dwSkillVnum)>=40)
{
@ -3288,7 +3288,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
{
ITEM_MANAGER::instance().RemoveItem(item);
int iReadDelay = number(SKILLBOOK_DELAY_MIN, SKILLBOOK_DELAY_MAX);
int iReadDelay = Random::get<int>(SKILLBOOK_DELAY_MIN, SKILLBOOK_DELAY_MAX);
if (distribution_test_server) iReadDelay /= 3;
SetSkillNextReadTime(dwSkillVnum, get_global_time() + iReadDelay);
@ -3318,7 +3318,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
}
DWORD dwSkillVnum = SKILL_MINING;
int iPct = MINMAX(0, item->GetValue(1), 100);
int iPct = std::clamp(item->GetValue(1), 0, 100);
if (GetSkillLevel(dwSkillVnum)>=40)
{
@ -3330,7 +3330,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
{
ITEM_MANAGER::instance().RemoveItem(item);
int iReadDelay = number(SKILLBOOK_DELAY_MIN, SKILLBOOK_DELAY_MAX);
int iReadDelay = Random::get<int>(SKILLBOOK_DELAY_MIN, SKILLBOOK_DELAY_MAX);
if (distribution_test_server) iReadDelay /= 3;
SetSkillNextReadTime(dwSkillVnum, get_global_time() + iReadDelay);
@ -3348,7 +3348,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
}
DWORD dwSkillVnum = SKILL_HORSE;
int iPct = MINMAX(0, item->GetValue(1), 100);
int iPct = std::clamp(item->GetValue(1), 0, 100);
if (GetLevel() < 50)
{
@ -3379,13 +3379,13 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
return false;
}
if (number(1, 100) <= iPct)
if (Random::get(1, 100) <= iPct)
{
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("승마 수련서를 읽어 승마 스킬 포인트를 얻었습니다."));
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("얻은 포인트로는 승마 스킬의 레벨을 올릴 수 있습니다."));
PointChange(POINT_HORSE_SKILL, 1);
int iReadDelay = number(SKILLBOOK_DELAY_MIN, SKILLBOOK_DELAY_MAX);
int iReadDelay = Random::get<int>(SKILLBOOK_DELAY_MIN, SKILLBOOK_DELAY_MAX);
if (distribution_test_server) iReadDelay /= 3;
if (!test_server)
@ -3406,7 +3406,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
if (GetAlignment() >= 0)
return false;
int delta = MIN(-GetAlignment(), item->GetValue(0));
int delta = std::min(-GetAlignment(), item->GetValue(0));
sys_log(0, "%s ALIGNMENT ITEM %d", GetName(), delta);
@ -4232,7 +4232,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
return false;
}
PointChange(POINT_SP_RECOVERY, item->GetValue(1) * MIN(200, (100 + GetPoint(POINT_POTION_BONUS))) / 100);
PointChange(POINT_SP_RECOVERY, item->GetValue(1) * std::min(200, (100 + GetPoint(POINT_POTION_BONUS))) / 100);
StartAffectEvent();
EffectPacket(SE_SPUP_BLUE);
}
@ -4244,7 +4244,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
return false;
}
PointChange(POINT_HP_RECOVERY, item->GetValue(0) * MIN(200, (100 + GetPoint(POINT_POTION_BONUS))) / 100);
PointChange(POINT_HP_RECOVERY, item->GetValue(0) * std::min(200, (100 + GetPoint(POINT_POTION_BONUS))) / 100);
StartAffectEvent();
EffectPacket(SE_HPUP_RED);
}
@ -4678,7 +4678,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
char buf[21];
snprintf(buf, sizeof(buf), "%u", item2->GetID());
if (number(1, 100) <= aiItemAttributeAddPercent[item2->GetAttributeCount()])
if (Random::get(1, 100) <= aiItemAttributeAddPercent[item2->GetAttributeCount()])
{
item2->AddAttribute();
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("속성 추가에 성공하였습니다."));
@ -4723,7 +4723,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
char buf[21];
snprintf(buf, sizeof(buf), "%u", item2->GetID());
if (number(1, 100) <= aiItemAttributeAddPercent[item2->GetAttributeCount()])
if (Random::get(1, 100) <= aiItemAttributeAddPercent[item2->GetAttributeCount()])
{
item2->AddAttribute();
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("속성 추가에 성공하였습니다."));
@ -4771,7 +4771,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
{
if (item2->GetAccessorySocketMaxGrade() < ITEM_ACCESSORY_SOCKET_MAX_NUM)
{
if (number(1, 100) <= 50)
if (Random::get(1, 100) <= 50)
{
item2->SetAccessorySocketMaxGrade(item2->GetAccessorySocketMaxGrade() + 1);
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("소켓이 성공적으로 추가되었습니다."));
@ -4806,7 +4806,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
if (item2->GetAccessorySocketGrade() < item2->GetAccessorySocketMaxGrade())
{
if (number(1, 100) <= aiAccessorySocketPutPct[item2->GetAccessorySocketGrade()])
if (Random::get(1, 100) <= aiAccessorySocketPutPct[item2->GetAccessorySocketGrade()])
{
item2->SetAccessorySocketGrade(item2->GetAccessorySocketGrade() + 1);
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("장착에 성공하였습니다."));
@ -4908,7 +4908,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
break;
case USE_CREATE_STONE:
AutoGiveItem(number(28000, 28013));
AutoGiveItem(Random::get(28000, 28013));
item->SetCount(item->GetCount() - 1);
break;
@ -4971,7 +4971,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
pBottle->SetCount(pBottle->GetCount() - 1);
if (number(1, 100) > item->GetValue(5))
if (Random::get(1, 100) > item->GetValue(5))
{
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("물약 제조에 실패했습니다."));
return false;
@ -5044,7 +5044,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell)
if (item2->GetSocket(i) >= 1 && item2->GetSocket(i) <= 2 && item2->GetSocket(i) >= item->GetValue(2))
{
// 석 확률
if (number(1, 100) <= 30)
if (Random::get(1, 100) <= 30)
{
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("메틴석 부착에 성공하였습니다."));
item2->SetSocket(i, item->GetVnum());
@ -5597,7 +5597,7 @@ bool CHARACTER::MoveItem(TItemPos Cell, TItemPos DestCell, BYTE count)
sys_log(0, "%s: ITEM_STACK %s (window: %d, cell : %d) -> (window:%d, cell %d) count %d", GetName(), item->GetName(), Cell.window_type, Cell.cell,
DestCell.window_type, DestCell.cell, count);
count = MIN(200 - item2->GetCount(), count);
count = std::min<BYTE>(200 - item2->GetCount(), count);
item->SetCount(item->GetCount() - count);
item2->SetCount(item2->GetCount() + count);
@ -5815,7 +5815,7 @@ bool CHARACTER::PickupItem(DWORD dwVID)
if (j != ITEM_SOCKET_MAX_NUM)
continue;
BYTE bCount2 = MIN(200 - item2->GetCount(), bCount);
BYTE bCount2 = std::min<BYTE>(200 - item2->GetCount(), bCount);
bCount -= bCount2;
item2->SetCount(item2->GetCount() + bCount2);
@ -6541,7 +6541,7 @@ LPITEM CHARACTER::AutoGiveItem(DWORD dwItemVnum, BYTE bCount, int iRarePct, bool
bCount = p->alValues[1];
}
BYTE bCount2 = MIN(200 - item->GetCount(), bCount);
BYTE bCount2 = std::min<BYTE>(200 - item->GetCount(), bCount);
bCount -= bCount2;
item->SetCount(item->GetCount() + bCount2);
@ -7017,8 +7017,8 @@ bool CHARACTER::GiveItemFromSpecialItemGroup(DWORD dwGroupNum, std::vector<DWORD
case CSpecialItemGroup::MOB:
{
sys_log(0, "CSpecialItemGroup::MOB %d", dwCount);
int x = GetX() + number(-500, 500);
int y = GetY() + number(-500, 500);
int x = GetX() + Random::get(-500, 500);
int y = GetY() + Random::get(-500, 500);
LPCHARACTER ch = CHARACTER_MANAGER::instance().SpawnMob(dwCount, GetMapIndex(), x, y, 0, true, -1);
if (ch)
@ -7037,7 +7037,7 @@ bool CHARACTER::GiveItemFromSpecialItemGroup(DWORD dwGroupNum, std::vector<DWORD
{
int iDropHP = GetMaxHP()*dwCount/100;
sys_log(0, "CSpecialItemGroup::DRAIN_HP %d", -iDropHP);
iDropHP = MIN(iDropHP, GetHP()-1);
iDropHP = std::min(iDropHP, GetHP()-1);
sys_log(0, "CSpecialItemGroup::DRAIN_HP %d", -iDropHP);
PointChange(POINT_HP, -iDropHP);
bSuccess = true;
@ -7052,10 +7052,10 @@ bool CHARACTER::GiveItemFromSpecialItemGroup(DWORD dwGroupNum, std::vector<DWORD
case CSpecialItemGroup::MOB_GROUP:
{
int sx = GetX() - number(300, 500);
int sy = GetY() - number(300, 500);
int ex = GetX() + number(300, 500);
int ey = GetY() + number(300, 500);
int sx = GetX() - Random::get(300, 500);
int sy = GetY() - Random::get(300, 500);
int ex = GetX() + Random::get(300, 500);
int ey = GetY() + Random::get(300, 500);
CHARACTER_MANAGER::instance().SpawnGroup(dwCount, GetMapIndex(), sx, sy, ex, ey, NULL, true);
bSuccess = true;
@ -7183,7 +7183,7 @@ bool CHARACTER::ItemProcess_Polymorph(LPITEM item)
sys_log(0, "USE_POLYMORPH_BALL PID(%d) vnum(%d)", GetPlayerID(), dwVnum);
// 레벨 제한 체크
int iPolymorphLevelLimit = MAX(0, 20 - GetLevel() * 3 / 10);
int iPolymorphLevelLimit = std::max(0, 20 - GetLevel() * 3 / 10);
if (pMob->m_table.bLevel >= GetLevel() + iPolymorphLevelLimit)
{
ChatPacket(CHAT_TYPE_INFO, LC_TEXT("나보다 너무 높은 레벨의 몬스터로는 변신 할 수 없습니다."));

View File

@ -280,8 +280,8 @@ LPCHARACTER CHARACTER_MANAGER::SpawnMobRandomPosition(DWORD dwVnum, int lMapInde
int x, y;
for (i=0; i<2000; i++)
{
x = number(1, (pkSectreeMap->m_setting.iWidth / 100) - 1) * 100 + pkSectreeMap->m_setting.iBaseX;
y = number(1, (pkSectreeMap->m_setting.iHeight / 100) - 1) * 100 + pkSectreeMap->m_setting.iBaseY;
x = Random::get(1, (pkSectreeMap->m_setting.iWidth / 100) - 1) * 100 + pkSectreeMap->m_setting.iBaseX;
y = Random::get(1, (pkSectreeMap->m_setting.iHeight / 100) - 1) * 100 + pkSectreeMap->m_setting.iBaseY;
//LPSECTREE tree = SECTREE_MANAGER::instance().Get(lMapIndex, x, y);
LPSECTREE tree = pkSectreeMap->Find(x, y);
@ -328,7 +328,7 @@ LPCHARACTER CHARACTER_MANAGER::SpawnMobRandomPosition(DWORD dwVnum, int lMapInde
if (ch->GetEmpire() == 0)
ch->SetEmpire(SECTREE_MANAGER::instance().GetEmpireFromMapIndex(lMapIndex));
ch->SetRotation(number(0, 360));
ch->SetRotation(Random::get(0, 360));
if (!ch->Show(lMapIndex, x, y, 0, false))
{
@ -420,7 +420,7 @@ LPCHARACTER CHARACTER_MANAGER::SpawnMob(DWORD dwVnum, int lMapIndex, int x, int
}
if (iRot == -1)
iRot = number(0, 360);
iRot = Random::get(0, 360);
ch->SetProto(pkMob);
@ -455,8 +455,8 @@ LPCHARACTER CHARACTER_MANAGER::SpawnMobRange(DWORD dwVnum, int lMapIndex, int sx
while (i--)
{
int x = number(sx, ex);
int y = number(sy, ey);
int x = Random::get(sx, ex);
int y = Random::get(sy, ey);
/*
if (bIsException)
if (is_regen_exception(x, y))
@ -518,10 +518,10 @@ bool CHARACTER_MANAGER::SpawnMoveGroup(DWORD dwVnum, int lMapIndex, int sx, int
continue;
}
sx = tch->GetX() - number(300, 500);
sy = tch->GetY() - number(300, 500);
ex = tch->GetX() + number(300, 500);
ey = tch->GetY() + number(300, 500);
sx = tch->GetX() - Random::get(300, 500);
sy = tch->GetY() - Random::get(300, 500);
ex = tch->GetX() + Random::get(300, 500);
ey = tch->GetY() + Random::get(300, 500);
if (m_pkChrSelectedStone)
tch->SetStone(m_pkChrSelectedStone);
@ -607,10 +607,10 @@ LPCHARACTER CHARACTER_MANAGER::SpawnGroup(DWORD dwVnum, int lMapIndex, int sx, i
tch->SetDungeon(pDungeon);
sx = tch->GetX() - number(300, 500);
sy = tch->GetY() - number(300, 500);
ex = tch->GetX() + number(300, 500);
ey = tch->GetY() + number(300, 500);
sx = tch->GetX() - Random::get(300, 500);
sy = tch->GetY() - Random::get(300, 500);
ex = tch->GetX() + Random::get(300, 500);
ey = tch->GetY() + Random::get(300, 500);
if (m_pkChrSelectedStone)
tch->SetStone(m_pkChrSelectedStone);
@ -915,7 +915,7 @@ LPCHARACTER CHARACTER_MANAGER::FindSpecifyPC(unsigned int uiJobFlag, int lMapInd
continue;
}
if (!chFind || number(1, ++n) == 1)
if (!chFind || Random::get(1, ++n) == 1)
chFind = ch;
}

View File

@ -26,7 +26,7 @@ int GetPoisonDamageRate(LPCHARACTER ch)
else
iRate = poison_damage_rate[ch->GetMobRank()];
iRate = MAX(0, iRate - ch->GetPoint(POINT_POISON_REDUCE));
iRate = std::max(0, iRate - ch->GetPoint(POINT_POISON_REDUCE));
return iRate;
}
@ -194,7 +194,7 @@ void CHARACTER::AttackedByPoison(LPCHARACTER pkAttacker)
if (delta > 8)
delta = 8;
if (number(1, 100) > poison_level_adjust[delta])
if (Random::get(1, 100) > poison_level_adjust[delta])
return;
}
@ -254,7 +254,7 @@ bool CHARACTER::IsImmune(DWORD dwImmuneFlag)
if (IS_SET(m_pointsInstant.dwImmuneFlag, dwImmuneFlag))
{
int immune_pct = 90;
int percent = number(1, 100);
int percent = Random::get(1, 100);
if (percent <= immune_pct) // 90% Immune
{

View File

@ -125,7 +125,7 @@ bool TSkillUseInfo::UseSkill(bool isGrandMaster, DWORD vid, DWORD dwCooltime, in
int CHARACTER::GetChainLightningMaxCount() const
{
return aiChainLightningCountBySkillLevel[MIN(SKILL_MAX_LEVEL, GetSkillLevel(SKILL_CHAIN))];
return aiChainLightningCountBySkillLevel[std::min<int>(SKILL_MAX_LEVEL, GetSkillLevel(SKILL_CHAIN))];
}
void CHARACTER::SetAffectedEunhyung()
@ -178,7 +178,7 @@ void CHARACTER::SetSkillLevel(DWORD dwVnum, BYTE bLev)
return;
}
m_pSkillLevels[dwVnum].bLevel = MIN(40, bLev);
m_pSkillLevels[dwVnum].bLevel = std::min<BYTE>(40, bLev);
if (bLev >= 40)
m_pSkillLevels[dwVnum].bMasterType = SKILL_PERFECT_MASTER;
@ -320,7 +320,7 @@ bool CHARACTER::LearnGrandMasterSkill(DWORD dwSkillVnum)
// 여기서 확률을 계산합니다.
BYTE bLastLevel = GetSkillLevel(dwSkillVnum);
int idx = MIN(9, GetSkillLevel(dwSkillVnum) - 30);
int idx = std::min(9, GetSkillLevel(dwSkillVnum) - 30);
sys_log(0, "LearnGrandMasterSkill %s table idx %d value %d", GetName(), idx, aiGrandMasterSkillBookCountForLevelUp[idx]);
@ -364,10 +364,10 @@ bool CHARACTER::LearnGrandMasterSkill(DWORD dwSkillVnum)
RemoveAffect(AFFECT_SKILL_BOOK_BONUS);
}
int n = number(1, iBookCount);
int n = Random::get(1, iBookCount);
sys_log(0, "Number(%d)", n);
DWORD nextTime = get_global_time() + number(28800, 43200);
DWORD nextTime = get_global_time() + Random::get(28800, 43200);
sys_log(0, "GrandMaster SkillBookCount min %d cur %d max %d (next_time=%d)", iMinReadCount, iTotalReadCount, iMaxReadCount, nextTime);
@ -485,7 +485,7 @@ bool CHARACTER::LearnSkillByBook(DWORD dwSkillVnum, BYTE bProb)
sys_log(0, "LearnSkillByBook Pct %u prob %d", dwSkillVnum, bProb);
if (number(1, 100) <= bProb)
if (Random::get(1, 100) <= bProb)
{
if (test_server)
sys_log(0, "LearnSkillByBook %u SUCC", dwSkillVnum);
@ -500,7 +500,7 @@ bool CHARACTER::LearnSkillByBook(DWORD dwSkillVnum, BYTE bProb)
}
else
{
int idx = MIN(9, GetSkillLevel(dwSkillVnum) - 20);
int idx = std::min(9, GetSkillLevel(dwSkillVnum) - 20);
sys_log(0, "LearnSkillByBook %s table idx %d value %d", GetName(), idx, aiSkillBookCountForLevelUp[idx]);
@ -528,7 +528,7 @@ bool CHARACTER::LearnSkillByBook(DWORD dwSkillVnum, BYTE bProb)
RemoveAffect(AFFECT_SKILL_BOOK_BONUS);
}
if (number(1, 100) > percent)
if (Random::get(1, 100) > percent)
{
// 책읽기에 성공
if (read_count >= need_bookcount)
@ -544,7 +544,7 @@ bool CHARACTER::LearnSkillByBook(DWORD dwSkillVnum, BYTE bProb)
{
pPC->SetFlag(flag, read_count + 1);
switch (number(1, 3))
switch (Random::get(1, 3))
{
case 1:
ChatPacket(CHAT_TYPE_TALKING, LC_TEXT("어느정도 이 기술에 대해 이해가 되었지만 조금 부족한듯 한데.."));
@ -597,7 +597,7 @@ bool CHARACTER::LearnSkillByBook(DWORD dwSkillVnum, BYTE bProb)
RemoveAffect(AFFECT_SKILL_BOOK_BONUS);
}
if (number(1, iBookCount) == 2)
if (Random::get(1, iBookCount) == 2)
SkillLevelUp(dwSkillVnum, SKILL_UP_BY_BOOK);
}
// END_OF_INTERNATIONAL_VERSION
@ -818,7 +818,7 @@ void CHARACTER::SkillLevelUp(DWORD dwVnum, BYTE bMethod)
}
else
{
if (number(1, 21 - MIN(20, GetSkillLevel(pkSk->dwVnum))) == 1)
if (Random::get(1, 21 - std::min(20, GetSkillLevel(pkSk->dwVnum))) == 1)
SetSkillLevel(pkSk->dwVnum, 20);
}
}
@ -827,7 +827,7 @@ void CHARACTER::SkillLevelUp(DWORD dwVnum, BYTE bMethod)
case SKILL_MASTER:
if (GetSkillLevel(pkSk->dwVnum) >= 30)
{
if (number(1, 31 - MIN(30, GetSkillLevel(pkSk->dwVnum))) == 1)
if (Random::get(1, 31 - std::min(30, GetSkillLevel(pkSk->dwVnum))) == 1)
SetSkillLevel(pkSk->dwVnum, 30);
}
break;
@ -948,7 +948,7 @@ struct FFindNearVictim
{
++m_count;
if ((m_count == 1) || number(1, m_count) == 1)
if ((m_count == 1) || Random::get(1, m_count) == 1)
m_pkChrNextTarget = pkChr;
}
}
@ -1000,7 +1000,7 @@ EVENTFUNC(ChainLightningEvent)
if (pkChrVictim->GetParty()) // 파티 먼저
{
pkTarget = pkChrVictim->GetParty()->GetNextOwnership(NULL, pkChrVictim->GetX(), pkChrVictim->GetY());
if (pkTarget == pkChrVictim || !number(0, 2) || pkChr->GetChainLightingExcept().find(pkTarget) != pkChr->GetChainLightingExcept().end())
if (pkTarget == pkChrVictim || !Random::get(0, 2) || pkChr->GetChainLightingExcept().find(pkTarget) != pkChr->GetChainLightingExcept().end())
pkTarget = NULL;
}
@ -1037,10 +1037,10 @@ void SetPolyVarForAttack(LPCHARACTER ch, CSkillProto * pkSk, LPITEM pkWeapon)
{
if (pkWeapon && pkWeapon->GetType() == ITEM_WEAPON)
{
int iWep = number(pkWeapon->GetValue(3), pkWeapon->GetValue(4));
int iWep = Random::get(pkWeapon->GetValue(3), pkWeapon->GetValue(4));
iWep += pkWeapon->GetValue(5);
int iMtk = number(pkWeapon->GetValue(1), pkWeapon->GetValue(2));
int iMtk = Random::get(pkWeapon->GetValue(1), pkWeapon->GetValue(2));
iMtk += pkWeapon->GetValue(5);
pkSk->SetPointVar("wep", iWep);
@ -1056,7 +1056,7 @@ void SetPolyVarForAttack(LPCHARACTER ch, CSkillProto * pkSk, LPITEM pkWeapon)
}
else
{
int iWep = number(ch->GetMobDamageMin(), ch->GetMobDamageMax());
int iWep = Random::get(ch->GetMobDamageMin(), ch->GetMobDamageMax());
pkSk->SetPointVar("wep", iWep);
pkSk->SetPointVar("mwep", iWep);
pkSk->SetPointVar("mtk", iWep);
@ -1129,7 +1129,7 @@ struct FuncSplashDamage
{
int iPenetratePct = (int) m_pkSk->kPointPoly2.Eval();
if (number(1, 100) <= iPenetratePct)
if (Random::get(1, 100) <= iPenetratePct)
bIgnoreDefense = true;
}
@ -1139,7 +1139,7 @@ struct FuncSplashDamage
{
int iPct = (int) m_pkSk->kPointPoly2.Eval();
if (number(1, 100) <= iPct)
if (Random::get(1, 100) <= iPct)
bIgnoreTargetRating = true;
}
@ -1405,7 +1405,7 @@ struct FuncSplashDamage
int iDur2 = (int) m_pkSk->kDurationPoly2.Eval();
iDur2 += m_pkChr->GetPoint(POINT_PARTY_BUFFER_BONUS);
if (number(1, 100) <= iAmount2)
if (Random::get(1, 100) <= iAmount2)
{
pkChrVictim->RemoveGoodAffect();
pkChrVictim->AddAffect(m_pkSk->dwVnum, POINT_NONE, 0, AFF_PABEOP, iDur2, 0, true);
@ -1440,14 +1440,14 @@ struct FuncSplashDamage
iDur += bonus / 2;
}
if (number(1, 100) <= iDur)
if (Random::get(1, 100) <= iDur)
{
pkChrVictim->AttackedByFire(m_pkChr, iPct, 5);
}
}
else if (IS_SET(m_pkSk->dwFlag, SKILL_FLAG_POISON))
{
if (number(1, 100) <= iPct)
if (Random::get(1, 100) <= iPct)
pkChrVictim->AttackedByPoison(m_pkChr);
}
}
@ -1634,7 +1634,7 @@ EVENTFUNC(skill_gwihwan_event)
int percent = 20 * sklv - 1;
if (number(1, 100) <= percent)
if (Random::get(1, 100) <= percent)
{
PIXEL_POSITION pos;
@ -1773,7 +1773,7 @@ int CHARACTER::ComputeSkillAtPosition(DWORD dwVnum, const PIXEL_POSITION& posTar
if (IS_SET(pkSk->dwFlag, SKILL_FLAG_REMOVE_BAD_AFFECT))
{
if (number(1, 100) <= iAmount2)
if (Random::get(1, 100) <= iAmount2)
{
RemoveBadAffect();
}
@ -2122,7 +2122,7 @@ int CHARACTER::ComputeSkill(DWORD dwVnum, LPCHARACTER pkVictim, BYTE bSkillLevel
// REMOVE_BAD_AFFECT_BUG_FIX
if (IS_SET(pkSk->dwFlag, SKILL_FLAG_REMOVE_BAD_AFFECT))
{
if (number(1, 100) <= iAmount2)
if (Random::get(1, 100) <= iAmount2)
{
pkVictim->RemoveBadAffect();
}
@ -2648,7 +2648,7 @@ int CHARACTER::GetUsedSkillMasterType(DWORD dwVnum)
if (rInfo.isGrandMaster)
return GetSkillMasterType(dwVnum);
return MIN(GetSkillMasterType(dwVnum), SKILL_MASTER);
return std::min<int>(GetSkillMasterType(dwVnum), SKILL_MASTER);
}
int CHARACTER::GetSkillMasterType(DWORD dwVnum) const
@ -2708,7 +2708,7 @@ int CHARACTER::GetSkillLevel(DWORD dwVnum) const
return 0;
}
return MIN(SKILL_MAX_LEVEL, m_pSkillLevels ? m_pSkillLevels[dwVnum].bLevel : 0);
return std::min<int>(SKILL_MAX_LEVEL, m_pSkillLevels ? m_pSkillLevels[dwVnum].bLevel : 0);
}
EVENTFUNC(skill_muyoung_event)
@ -2866,7 +2866,7 @@ bool CHARACTER::CanUseMobSkill(unsigned int idx) const
if (m_adwMobSkillCooltime[idx] > get_dword_time())
return false;
if (number(0, 1))
if (Random::get(0, 1))
return false;
return true;

View File

@ -285,10 +285,10 @@ void CHARACTER::CowardEscape()
for (int iDistIdx = 2; iDistIdx >= 0; --iDistIdx)
for (int iTryCount = 0; iTryCount < 8; ++iTryCount)
{
SetRotation(number(0, 359)); // 방향은 랜덤으로 설정
SetRotation(Random::get(0, 359)); // 방향은 랜덤으로 설정
float fx, fy;
float fDist = number(iDist[iDistIdx], iDist[iDistIdx+1]);
float fDist = Random::get(iDist[iDistIdx], iDist[iDistIdx+1]);
GetDeltaByDegree(GetRotation(), fDist, &fx, &fy);
@ -390,7 +390,7 @@ void CHARACTER::__StateIdle_Stone()
m_dwStateDuration = PASSES_PER_SEC(1);
int iPercent = (GetHP() * 100) / GetMaxHP();
DWORD dwVnum = number(MIN(GetMobTable().sAttackSpeed, GetMobTable().sMovingSpeed ), MAX(GetMobTable().sAttackSpeed, GetMobTable().sMovingSpeed));
DWORD dwVnum = Random::get(std::min(GetMobTable().sAttackSpeed, GetMobTable().sMovingSpeed ), std::max(GetMobTable().sAttackSpeed, GetMobTable().sMovingSpeed));
if (iPercent <= 10 && GetMaxSP() < 10)
{
@ -549,7 +549,7 @@ void CHARACTER::__StateIdle_NPC()
const int WARP_MAP_INDEX_NUM = 7;
static const int c_lWarpMapIndexs[WARP_MAP_INDEX_NUM] = { 61, 62, 63, 64, 3, 23, 43 };
int lNextMapIndex;
lNextMapIndex = c_lWarpMapIndexs[number(1, WARP_MAP_INDEX_NUM) - 1];
lNextMapIndex = c_lWarpMapIndexs[Random::get(1, WARP_MAP_INDEX_NUM) - 1];
if (map_allow_find(lNextMapIndex))
{
@ -587,17 +587,17 @@ void CHARACTER::__StateIdle_NPC()
{
if (DISTANCE_APPROX(GetX() - pkChrProtege->GetX(), GetY() - pkChrProtege->GetY()) > 500)
{
if (Follow(pkChrProtege, number(100, 300)))
if (Follow(pkChrProtege, Random::get(100, 300)))
return;
}
}
if (!number(0, 6))
if (!Random::get(0, 6))
{
SetRotation(number(0, 359)); // 방향은 랜덤으로 설정
SetRotation(Random::get(0, 359)); // 방향은 랜덤으로 설정
float fx, fy;
float fDist = number(200, 400);
float fDist = Random::get(200, 400);
GetDeltaByDegree(GetRotation(), fDist, &fx, &fy);
@ -677,9 +677,9 @@ void CHARACTER::__StateIdle_Monster()
}
if (IsAggressive() && !victim)
m_dwStateDuration = PASSES_PER_SEC(number(1, 3));
m_dwStateDuration = PASSES_PER_SEC(Random::get(1, 3));
else
m_dwStateDuration = PASSES_PER_SEC(number(3, 5));
m_dwStateDuration = PASSES_PER_SEC(Random::get(3, 5));
LPCHARACTER pkChrProtege = GetProtege();
@ -688,7 +688,7 @@ void CHARACTER::__StateIdle_Monster()
{
if (DISTANCE_APPROX(GetX() - pkChrProtege->GetX(), GetY() - pkChrProtege->GetY()) > 1000)
{
if (Follow(pkChrProtege, number(150, 400)))
if (Follow(pkChrProtege, Random::get(150, 400)))
{
MonsterLog("[IDLE] 리더로부터 너무 멀리 떨어졌다! 복귀한다.");
return;
@ -701,12 +701,12 @@ void CHARACTER::__StateIdle_Monster()
//
if (!no_wander && !IS_SET(m_pointsInstant.dwAIFlag, AIFLAG_NOMOVE))
{
if (!number(0, 6))
if (!Random::get(0, 6))
{
SetRotation(number(0, 359)); // 방향은 랜덤으로 설정
SetRotation(Random::get(0, 359)); // 방향은 랜덤으로 설정
float fx, fy;
float fDist = number(300, 700);
float fDist = Random::get(300, 700);
GetDeltaByDegree(GetRotation(), fDist, &fx, &fy);
@ -719,7 +719,7 @@ void CHARACTER::__StateIdle_Monster()
// 그래픽 팀에서 몬스터가 걷는 모습도 보고싶다고 해서 임시로 특정확률로 걷거나 뛰게 함. (게임의 전반적인 느낌이 틀려지기 때문에 일단 테스트 모드에서만 작동)
if (g_test_server)
{
if (number(0, 100) < 60)
if (Random::get(0, 100) < 60)
SetNowWalking(false);
else
SetNowWalking(true);
@ -848,7 +848,7 @@ void CHARACTER::StateMove()
LPCHARACTER victim = GetVictim();
// 거대 거북
if (GetRaceNum() == 2191 && number(1, 20) == 1 && get_dword_time() - m_pkMobInst->m_dwLastWarpTime > 1000)
if (GetRaceNum() == 2191 && Random::get(1, 20) == 1 && get_dword_time() - m_pkMobInst->m_dwLastWarpTime > 1000)
{
// 워프 테스트
float fx, fy;
@ -865,7 +865,7 @@ void CHARACTER::StateMove()
}
// TODO 방향전환을 해서 덜 바보가 되자!
if (number(0, 3) == 0)
if (Random::get(0, 3) == 0)
{
if (__CHARACTER_GotoNearTarget(this, victim))
return;
@ -900,7 +900,7 @@ void CHARACTER::StateMove()
LPCHARACTER rider = GetRider();
m_dwStateDuration = PASSES_PER_SEC(number(1, 3));
m_dwStateDuration = PASSES_PER_SEC(Random::get(1, 3));
}
}
}
@ -932,7 +932,7 @@ void CHARACTER::StateBattle()
SetVictim(NULL);
if (number(1, 50) != 1)
if (Random::get(1, 50) != 1)
{
GotoState(m_stateIdle);
m_dwStateDuration = 1;
@ -964,9 +964,9 @@ void CHARACTER::StateBattle()
case BATTLE_TYPE_TANKER:
{
float fx, fy;
float fDist = number(400, 1500);
float fDist = Random::get(400, 1500);
GetDeltaByDegree(number(0, 359), fDist, &fx, &fy);
GetDeltaByDegree(Random::get(0, 359), fDist, &fx, &fy);
if (SECTREE_MANAGER::instance().IsMovablePosition(victim->GetMapIndex(),
victim->GetX() + (int) fx,
@ -1010,7 +1010,7 @@ void CHARACTER::StateBattle()
}
LPPARTY pParty = GetParty();
bool bPct = !number(0, 3);
bool bPct = !Random::get(0, 3);
if (bPct && pParty->CountMemberByVnum(GetSummonVnum()) < SUMMON_MONSTER_COUNT)
{
@ -1043,7 +1043,7 @@ void CHARACTER::StateBattle()
// 보호할 것(돌, 파티장) 주변으로 간다.
if (pkChrProtege)
if (DISTANCE_APPROX(GetX() - pkChrProtege->GetX(), GetY() - pkChrProtege->GetY()) > 1000)
Follow(pkChrProtege, number(150, 400));
Follow(pkChrProtege, Random::get(150, 400));
return;
}
@ -1069,7 +1069,7 @@ void CHARACTER::StateBattle()
if ((dwCurTime - m_dwLastAttackTime) < dwDuration) // 2초 마다 공격해야 한다.
{
m_dwStateDuration = MAX(1, (passes_per_sec * (dwDuration - (dwCurTime - m_dwLastAttackTime)) / 1000));
m_dwStateDuration = std::max<int>(1, (passes_per_sec * (dwDuration - (dwCurTime - m_dwLastAttackTime)) / 1000));
return;
}
@ -1200,19 +1200,19 @@ void CHARACTER::StateHorse()
if (fDist > START_RUN_DISTANCE)
SetNowWalking(!bRun); // NOTE: 함수 이름보고 멈추는건줄 알았는데 SetNowWalking(false) 하면 뛰는거임.. -_-;
Follow(victim, number(MIN_APPROACH, MAX_APPROACH));
Follow(victim, Random::get(MIN_APPROACH, MAX_APPROACH));
m_dwStateDuration = STATE_DURATION;
}
else if (bDoMoveAlone && (get_dword_time() > m_dwLastAttackTime))
{
// wondering-.-
m_dwLastAttackTime = get_dword_time() + number(5000, 12000);
m_dwLastAttackTime = get_dword_time() + Random::get(5000, 12000);
SetRotation(number(0, 359)); // 방향은 랜덤으로 설정
SetRotation(Random::get(0, 359)); // 방향은 랜덤으로 설정
float fx, fy;
float fDist = number(200, 400);
float fDist = Random::get(200, 400);
GetDeltaByDegree(GetRotation(), fDist, &fx, &fy);

View File

@ -129,7 +129,6 @@ ACMD(do_attract_ranger);
ACMD(do_pull_monster);
ACMD(do_setblockmode);
ACMD(do_priv_empire);
ACMD(do_priv_guild);
ACMD(do_mount_test);
ACMD(do_unmount);
ACMD(do_observer);
@ -411,7 +410,6 @@ struct command_info cmd_info[] =
{ "polymorph", do_polymorph, 0, POS_DEAD, GM_LOW_WIZARD },
{ "polyitem", do_polymorph_item, 0, POS_DEAD, GM_HIGH_WIZARD },
{ "priv_empire", do_priv_empire, 0, POS_DEAD, GM_HIGH_WIZARD },
{ "priv_guild", do_priv_guild, 0, POS_DEAD, GM_HIGH_WIZARD },
{ "mount_test", do_mount_test, 0, POS_DEAD, GM_IMPLEMENTOR },
{ "unmount", do_unmount, 0, POS_DEAD, GM_PLAYER },
{ "private", do_private, 0, POS_DEAD, GM_IMPLEMENTOR },

View File

@ -384,7 +384,7 @@ ACMD(do_cmd)
info->ch = ch;
info->subcmd = subcmd;
strncpy(info->szReason, argument, sizeof(info->szReason));
strlcpy(info->szReason, argument, sizeof(info->szReason));
ch->m_pkTimedEvent = event_create(timed_event, info, 1);
}
@ -922,8 +922,8 @@ ACMD(do_safebox_change_password)
TSafeboxChangePasswordPacket p;
p.dwID = ch->GetDesc()->GetAccountTable().id;
strncpy(p.szOldPassword, arg1, sizeof(p.szOldPassword));
strncpy(p.szNewPassword, arg2, sizeof(p.szNewPassword));
strlcpy(p.szOldPassword, arg1, sizeof(p.szOldPassword));
strlcpy(p.szNewPassword, arg2, sizeof(p.szNewPassword));
db_clientdesc->DBPacket(HEADER_GD_SAFEBOX_CHANGE_PASSWORD, ch->GetDesc()->GetHandle(), &p, sizeof(p));
}
@ -957,8 +957,8 @@ ACMD(do_mall_password)
TSafeboxLoadPacket p;
p.dwID = ch->GetDesc()->GetAccountTable().id;
strncpy(p.szLogin, ch->GetDesc()->GetAccountTable().login, sizeof(p.szLogin));
strncpy(p.szPassword, arg1, sizeof(p.szPassword));
strlcpy(p.szLogin, ch->GetDesc()->GetAccountTable().login, sizeof(p.szLogin));
strlcpy(p.szPassword, arg1, sizeof(p.szPassword));
db_clientdesc->DBPacket(HEADER_GD_MALL_LOAD, ch->GetDesc()->GetHandle(), &p, sizeof(p));
}
@ -1629,7 +1629,7 @@ ACMD(do_monarch_transfer)
TPacketGGTransfer pgg;
pgg.bHeader = HEADER_GG_TRANSFER;
strncpy(pgg.szName, arg1, sizeof(pgg.szName));
strlcpy(pgg.szName, arg1, sizeof(pgg.szName));
pgg.lX = ch->GetX();
pgg.lY = ch->GetY();
@ -1906,10 +1906,10 @@ ACMD(do_monarch_mob)
tch = CHARACTER_MANAGER::instance().SpawnMobRange(vnum,
ch->GetMapIndex(),
ch->GetX() - number(200, 750),
ch->GetY() - number(200, 750),
ch->GetX() + number(200, 750),
ch->GetY() + number(200, 750),
ch->GetX() - Random::get(200, 750),
ch->GetY() - Random::get(200, 750),
ch->GetX() + Random::get(200, 750),
ch->GetY() + Random::get(200, 750),
true,
pkMob->m_table.bType == CHAR_TYPE_STONE,
true);
@ -2133,8 +2133,8 @@ ACMD(do_inventory)
}
else
{
str_to_number(index, arg1); index = MIN(index, INVENTORY_MAX_NUM);
str_to_number(count, arg2); count = MIN(count, INVENTORY_MAX_NUM);
str_to_number(index, arg1); index = std::min<int>(index, INVENTORY_MAX_NUM);
str_to_number(count, arg2); count = std::min<int>(count, INVENTORY_MAX_NUM);
}
for (int i = 0; i < count; ++i)
@ -2374,10 +2374,10 @@ ACMD(do_dice)
end = atoi(arg1);
}
end = MAX(start, end);
start = MIN(start, end);
end = std::max(start, end);
start = std::min(start, end);
int n = number(start, end);
int n = Random::get(start, end);
if (ch->GetParty())
ch->GetParty()->ChatPacketToAllMember(CHAT_TYPE_INFO, LC_TEXT("%s님이 주사위를 굴려 %d가 나왔습니다. (%d-%d)"), ch->GetName(), n, start, end);

View File

@ -165,7 +165,7 @@ ACMD(do_transfer)
TPacketGGTransfer pgg;
pgg.bHeader = HEADER_GG_TRANSFER;
strncpy(pgg.szName, arg1, sizeof(pgg.szName));
strlcpy(pgg.szName, arg1, sizeof(pgg.szName));
pgg.lX = ch->GetX();
pgg.lY = ch->GetY();
@ -258,7 +258,7 @@ bool FindInString(const char * c_pszFind, const char * c_pszIn)
do
{
strncpy(sz, c, MIN(sizeof(sz), (p - c) + 1));
strlcpy(sz, c, std::min<size_t>(sizeof(sz), (p - c) + 1));
if (!strncasecmp(c_pszFind, sz, strlen(c_pszFind)))
return true;
@ -266,7 +266,7 @@ bool FindInString(const char * c_pszFind, const char * c_pszIn)
c = p + 1;
} while ((p = strchr(c, '|')));
strncpy(sz, c, sizeof(sz));
strlcpy(sz, c, sizeof(sz));
if (!strncasecmp(c_pszFind, sz, strlen(c_pszFind)))
return true;
@ -391,7 +391,7 @@ ACMD(do_goto)
if (*arg2 && isdigit(*arg2))
{
str_to_number(empire, arg2);
empire = MINMAX(1, empire, 3);
empire = std::clamp<BYTE>(empire, 1, 3);
}
else
empire = ch->GetEmpire();
@ -513,7 +513,7 @@ ACMD(do_item)
if (*arg2)
{
str_to_number(iCount, arg2);
iCount = MINMAX(1, iCount, ITEM_MAX_COUNT);
iCount = std::clamp<int>(iCount, 1, ITEM_MAX_COUNT);
}
DWORD dwVnum;
@ -655,16 +655,16 @@ ACMD(do_mob_coward)
else
iCount = 1;
iCount = MIN(20, iCount);
iCount = std::min(20, iCount);
while (iCount--)
{
tch = CHARACTER_MANAGER::instance().SpawnMobRange(vnum,
ch->GetMapIndex(),
ch->GetX() - number(200, 750),
ch->GetY() - number(200, 750),
ch->GetX() + number(200, 750),
ch->GetY() + number(200, 750),
ch->GetX() - Random::get(200, 750),
ch->GetY() - Random::get(200, 750),
ch->GetX() + Random::get(200, 750),
ch->GetY() + Random::get(200, 750),
true,
pkMob->m_table.bType == CHAR_TYPE_STONE);
if (tch)
@ -737,16 +737,16 @@ ACMD(do_mob_aggresive)
else
iCount = 1;
iCount = MIN(20, iCount);
iCount = std::min(20, iCount);
while (iCount--)
{
tch = CHARACTER_MANAGER::instance().SpawnMobRange(vnum,
ch->GetMapIndex(),
ch->GetX() - number(200, 750),
ch->GetY() - number(200, 750),
ch->GetX() + number(200, 750),
ch->GetY() + number(200, 750),
ch->GetX() - Random::get(200, 750),
ch->GetY() - Random::get(200, 750),
ch->GetX() + Random::get(200, 750),
ch->GetY() + Random::get(200, 750),
true,
pkMob->m_table.bType == CHAR_TYPE_STONE);
if (tch)
@ -798,18 +798,18 @@ ACMD(do_mob)
iCount = 1;
if (test_server)
iCount = MIN(40, iCount);
iCount = std::min(40, iCount);
else
iCount = MIN(20, iCount);
iCount = std::min(20, iCount);
while (iCount--)
{
CHARACTER_MANAGER::instance().SpawnMobRange(vnum,
ch->GetMapIndex(),
ch->GetX() - number(200, 750),
ch->GetY() - number(200, 750),
ch->GetX() + number(200, 750),
ch->GetY() + number(200, 750),
ch->GetX() - Random::get(200, 750),
ch->GetY() - Random::get(200, 750),
ch->GetX() + Random::get(200, 750),
ch->GetY() + Random::get(200, 750),
true,
pkMob->m_table.bType == CHAR_TYPE_STONE);
}
@ -974,17 +974,17 @@ ACMD(do_state)
snprintf(buf, sizeof(buf), "%s's State: ", tch->GetName());
if (tch->IsPosition(POS_FIGHTING))
strncat(buf, "Battle", sizeof(buf) - strlen(buf) - 1);
strlcat(buf, "Battle", sizeof(buf) - strlen(buf) - 1);
else if (tch->IsPosition(POS_DEAD))
strncat(buf, "Dead", sizeof(buf) - strlen(buf) - 1);
strlcat(buf, "Dead", sizeof(buf) - strlen(buf) - 1);
else
strncat(buf, "Standing", sizeof(buf) - strlen(buf) - 1);
strlcat(buf, "Standing", sizeof(buf) - strlen(buf) - 1);
if (ch->GetShop())
strncat(buf, ", Shop", sizeof(buf) - strlen(buf) - 1);
strlcat(buf, ", Shop", sizeof(buf) - strlen(buf) - 1);
if (ch->GetExchange())
strncat(buf, ", Exchange", sizeof(buf) - strlen(buf) - 1);
strlcat(buf, ", Exchange", sizeof(buf) - strlen(buf) - 1);
ch->ChatPacket(CHAT_TYPE_INFO, "%s", buf);
@ -1547,7 +1547,7 @@ ACMD(do_advance)
int level = 0;
str_to_number(level, arg2);
tch->ResetPoint(MINMAX(0, level, PLAYER_MAX_LEVEL_CONST));
tch->ResetPoint(std::clamp<int>(level, 0, PLAYER_MAX_LEVEL_CONST));
}
ACMD(do_respawn)
@ -1599,7 +1599,7 @@ ACMD(do_makeguild)
memset(&cp, 0, sizeof(cp));
cp.master = ch;
strncpy(cp.name, arg1, sizeof(cp.name));
strlcpy(cp.name, arg1, sizeof(cp.name));
if (!check_name(cp.name))
{
@ -1730,7 +1730,7 @@ ACMD(do_event_flag)
!strcmp(arg1, "mob_gold_buyer") ||
!strcmp(arg1, "mob_gold_pct_buyer")
)
value = MINMAX(0, value, 1000);
value = std::clamp(value, 0, 1000);
//quest::CQuestManager::instance().SetEventFlag(arg1, atoi(arg2));
quest::CQuestManager::instance().RequestSetEventFlag(arg1, value);
@ -1820,11 +1820,11 @@ ACMD(do_b1)
for (int i = 0; i < 30; ++i)
{
int rot = number(0, 359);
int rot = Random::get(0, 359);
float fx, fy;
GetDeltaByDegree(rot, 800, &fx, &fy);
LPCHARACTER tch = CHARACTER_MANAGER::instance().SpawnMobRange(number(701, 706),
LPCHARACTER tch = CHARACTER_MANAGER::instance().SpawnMobRange(Random::get(701, 706),
ch->GetMapIndex(),
304222 + (int)fx,
742858 + (int)fy,
@ -1837,7 +1837,7 @@ ACMD(do_b1)
for (int i = 0; i < 5; ++i)
{
int rot = number(0, 359);
int rot = Random::get(0, 359);
float fx, fy;
GetDeltaByDegree(rot, 800, &fx, &fy);
@ -1889,11 +1889,11 @@ ACMD(do_b4)
for (int i = 0; i < 30; ++i)
{
int rot = number(0, 359);
int rot = Random::get(0, 359);
float fx, fy;
GetDeltaByDegree(rot, 1200, &fx, &fy);
LPCHARACTER tch = CHARACTER_MANAGER::instance().SpawnMobRange(number(701, 706),
LPCHARACTER tch = CHARACTER_MANAGER::instance().SpawnMobRange(Random::get(701, 706),
ch->GetMapIndex(),
307900 + (int)fx,
744500 + (int)fy,
@ -1906,7 +1906,7 @@ ACMD(do_b4)
for (int i = 0; i < 5; ++i)
{
int rot = number(0, 359);
int rot = Random::get(0, 359);
float fx, fy;
GetDeltaByDegree(rot, 1200, &fx, &fy);
@ -2158,7 +2158,7 @@ ACMD(do_level)
int level = 0;
str_to_number(level, arg2);
ch->ResetPoint(MINMAX(1, level, PLAYER_MAX_LEVEL_CONST));
ch->ResetPoint(std::clamp<int>(level, 1, PLAYER_MAX_LEVEL_CONST));
ch->ClearSkill();
ch->ClearSubSkill();
@ -2513,7 +2513,7 @@ ACMD(do_priv_empire)
str_to_number(empire, arg1);
str_to_number(type, arg2);
str_to_number(value, arg3);
value = MINMAX(0, value, 1000);
value = std::clamp(value, 0, 1000);
str_to_number(duration, arg4);
if (empire < 0 || 3 < empire)
@ -2544,53 +2544,6 @@ USAGE:
ch->ChatPacket(CHAT_TYPE_INFO, " <duration> hour");
}
/**
* @version 05/06/08 Bang2ni - .( .)
* quest/priv_guild.quest
*/
ACMD(do_priv_guild)
{
static const char msg[] = { '\0' };
char arg1[256];
one_argument(argument, arg1, sizeof(arg1));
if (*arg1)
{
CGuild * g = CGuildManager::instance().FindGuildByName(arg1);
if (!g)
{
DWORD guild_id = 0;
str_to_number(guild_id, arg1);
g = CGuildManager::instance().FindGuild(guild_id);
}
if (!g)
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("그런 이름 또는 번호의 길드가 없습니다."));
else
{
char buf[1024+1];
snprintf(buf, sizeof(buf), msg, g->GetID());
using namespace quest;
PC * pc = CQuestManager::instance().GetPC(ch->GetPlayerID());
QuestState qs = CQuestManager::instance().OpenState("ADMIN_QUEST", QUEST_FISH_REFINE_STATE_INDEX);
luaL_loadbuffer(qs.co, buf, strlen(buf), "ADMIN_QUEST");
pc->SetQuest("ADMIN_QUEST", qs);
QuestState & rqs = *pc->GetRunningQuestState();
if (!CQuestManager::instance().RunState(rqs))
{
CQuestManager::instance().CloseState(rqs);
pc->EndRunning();
return;
}
}
}
}
ACMD(do_mount_test)
{
char arg1[256];
@ -2719,7 +2672,7 @@ ACMD(do_vote_block_chat)
TPacketGGBlockChat p;
p.bHeader = HEADER_GG_BLOCK_CHAT;
strncpy(p.szName, name, sizeof(p.szName));
strlcpy(p.szName, name, sizeof(p.szName));
p.lBlockDuration = lBlockDuration;
P2P_MANAGER::instance().Send(&p, sizeof(TPacketGGBlockChat));
}
@ -2727,7 +2680,7 @@ ACMD(do_vote_block_chat)
{
TPacketBlockChat p;
strncpy(p.szName, name, sizeof(p.szName));
strlcpy(p.szName, name, sizeof(p.szName));
p.lDuration = lBlockDuration;
db_clientdesc->DBPacket(HEADER_GD_BLOCK_CHAT, ch ? ch->GetDesc()->GetHandle() : 0, &p, sizeof(p));
@ -2789,7 +2742,7 @@ ACMD(do_block_chat)
TPacketGGBlockChat p;
p.bHeader = HEADER_GG_BLOCK_CHAT;
strncpy(p.szName, name, sizeof(p.szName));
strlcpy(p.szName, name, sizeof(p.szName));
p.lBlockDuration = lBlockDuration;
P2P_MANAGER::instance().Send(&p, sizeof(TPacketGGBlockChat));
}
@ -2797,7 +2750,7 @@ ACMD(do_block_chat)
{
TPacketBlockChat p;
strncpy(p.szName, name, sizeof(p.szName));
strlcpy(p.szName, name, sizeof(p.szName));
p.lDuration = lBlockDuration;
db_clientdesc->DBPacket(HEADER_GD_BLOCK_CHAT, ch ? ch->GetDesc()->GetHandle() : 0, &p, sizeof(p));
}
@ -3159,7 +3112,7 @@ ACMD(do_horse_level)
}
str_to_number(level, arg2);
level = MINMAX(0, level, HORSE_MAX_LEVEL);
level = std::clamp(level, 0, HORSE_MAX_LEVEL);
ch->ChatPacket(CHAT_TYPE_INFO, "horse level set (%s: %d)", victim->GetName(), level);
@ -3172,7 +3125,7 @@ ACMD(do_horse_level)
char arg1[256];
one_argument(argument, arg1, sizeof(arg1));
int level = MINMAX(0, atoi(arg1), HORSE_MAX_LEVEL);
int level = std::clamp<int>(atoi(arg1), 0, HORSE_MAX_LEVEL);
ch->ChatPacket(CHAT_TYPE_INFO, "horse level set to %d.", level);
ch->SetHorseLevel(level);
@ -3712,8 +3665,8 @@ ACMD(do_siege)
int empire = strtol(arg1, NULL, 10);
int tower_count = strtol(arg2, NULL, 10);
if (empire == 0) empire = number(1, 3);
if (tower_count < 5 || tower_count > 10) tower_count = number(5, 10);
if (empire == 0) empire = Random::get(1, 3);
if (tower_count < 5 || tower_count > 10) tower_count = Random::get(5, 10);
TPacketGGSiege packet;
packet.bHeader = HEADER_GG_SIEGE;
@ -3842,7 +3795,7 @@ ACMD(do_weeklyevent)
}
else
{
CBattleArena::instance().Start(rand()%3 + 1);
CBattleArena::instance().Start(Random::get(1, 3));
}
ch->ChatPacket(CHAT_TYPE_INFO, "Weekly Event Start");
}

View File

@ -250,7 +250,7 @@ bool GetIPInfo()
if (!strncmp(netip, "192.168", 7)) // ignore if address is starting with 192
{
strncpy(g_szInternalIP, netip, sizeof(g_szInternalIP));
strlcpy(g_szInternalIP, netip, sizeof(g_szInternalIP));
#ifndef __WIN32__
fprintf(stderr, "INTERNAL_IP: %s interface %s\n", netip, ifap->ifa_name);
#else
@ -259,7 +259,7 @@ bool GetIPInfo()
}
else if (!strncmp(netip, "10.", 3))
{
strncpy(g_szInternalIP, netip, sizeof(g_szInternalIP));
strlcpy(g_szInternalIP, netip, sizeof(g_szInternalIP));
#ifndef __WIN32__
fprintf(stderr, "INTERNAL_IP: %s interface %s\n", netip, ifap->ifa_name);
#else
@ -268,7 +268,7 @@ bool GetIPInfo()
}
else if (g_szPublicIP[0] == '0')
{
strncpy(g_szPublicIP, netip, sizeof(g_szPublicIP));
strlcpy(g_szPublicIP, netip, sizeof(g_szPublicIP));
#ifndef __WIN32__
fprintf(stderr, "PUBLIC_IP: %s interface %s\n", netip, ifap->ifa_name);
#else
@ -695,7 +695,7 @@ void config_init(const string& st_localeServiceName)
TOKEN("mark_min_level")
{
str_to_number(guild_mark_min_level, value_string);
guild_mark_min_level = MINMAX(0, guild_mark_min_level, GUILD_MAX_LEVEL);
guild_mark_min_level = std::clamp<BYTE>(guild_mark_min_level, 0, GUILD_MAX_LEVEL);
continue;
}
@ -709,7 +709,7 @@ void config_init(const string& st_localeServiceName)
{
int i = 0;
str_to_number(i, value_string);
log_set_expiration_days(MINMAX(1, i, 90));
log_set_expiration_days(std::clamp(i, 1, 90));
continue;
}
@ -733,7 +733,7 @@ void config_init(const string& st_localeServiceName)
TOKEN("db_addr")
{
strncpy(db_addr, value_string, sizeof(db_addr));
strlcpy(db_addr, value_string, sizeof(db_addr));
for (int n =0; n < ADDRESS_MAX_LEN; ++n)
{
@ -929,7 +929,7 @@ void config_init(const string& st_localeServiceName)
TOKEN("teen_addr")
{
strncpy(teen_addr, value_string, sizeof(teen_addr));
strlcpy(teen_addr, value_string, sizeof(teen_addr));
for (int n =0; n < ADDRESS_MAX_LEN; ++n)
{
@ -972,7 +972,7 @@ void config_init(const string& st_localeServiceName)
TOKEN("bind_ip")
{
strncpy(g_szPublicIP, value_string, sizeof(g_szPublicIP));
strlcpy(g_szPublicIP, value_string, sizeof(g_szPublicIP));
}
TOKEN("view_range")
@ -988,13 +988,13 @@ void config_init(const string& st_localeServiceName)
TOKEN("spam_block_score")
{
str_to_number(g_uiSpamBlockScore, value_string);
g_uiSpamBlockScore = MAX(1, g_uiSpamBlockScore);
g_uiSpamBlockScore = std::max<int>(1, g_uiSpamBlockScore);
}
TOKEN("spam_block_reload_cycle")
{
str_to_number(g_uiSpamReloadCycle, value_string);
g_uiSpamReloadCycle = MAX(60, g_uiSpamReloadCycle); // ĂÖźŇ 1şĐ
g_uiSpamReloadCycle = std::max<int>(60, g_uiSpamReloadCycle); // ÃÖ¼Ò 1ºÐ
}
TOKEN("check_multihack")
@ -1025,7 +1025,7 @@ void config_init(const string& st_localeServiceName)
{
str_to_number(gPlayerMaxLevel, value_string);
gPlayerMaxLevel = MINMAX(1, gPlayerMaxLevel, PLAYER_MAX_LEVEL_CONST);
gPlayerMaxLevel = std::clamp<int>(gPlayerMaxLevel, 1, PLAYER_MAX_LEVEL_CONST);
fprintf(stderr, "PLAYER_MAX_LEVEL: %d\n", gPlayerMaxLevel);
}

View File

@ -107,8 +107,8 @@ extern const DWORD guild_exp_table[GUILD_MAX_LEVEL + 1];
extern const DWORD guild_exp_table2[GUILD_MAX_LEVEL + 1];
#define MAX_EXP_DELTA_OF_LEV 31
#define PERCENT_LVDELTA(me, victim) aiPercentByDeltaLev[MINMAX(0, (victim + 15) - me, MAX_EXP_DELTA_OF_LEV - 1)]
#define PERCENT_LVDELTA_BOSS(me, victim) aiPercentByDeltaLevForBoss[MINMAX(0, (victim + 15) - me, MAX_EXP_DELTA_OF_LEV - 1)]
#define PERCENT_LVDELTA(me, victim) aiPercentByDeltaLev[std::clamp<int>((victim + 15) - me, 0, MAX_EXP_DELTA_OF_LEV - 1)]
#define PERCENT_LVDELTA_BOSS(me, victim) aiPercentByDeltaLevForBoss[std::clamp<int>((victim + 15) - me, 0, MAX_EXP_DELTA_OF_LEV - 1)]
#define CALCULATE_VALUE_LVDELTA(me, victim, val) ((val * PERCENT_LVDELTA(me, victim)) / 100)
extern const int aiPercentByDeltaLev_euckr[MAX_EXP_DELTA_OF_LEV];
extern const int aiPercentByDeltaLevForBoss_euckr[MAX_EXP_DELTA_OF_LEV];

View File

@ -243,8 +243,8 @@ CUBE_VALUE* CUBE_DATA::reward_value ()
DWORD reward_index = 0;
end_index = this->reward.size();
reward_index = number(0, end_index);
reward_index = number(0, end_index-1);
reward_index = Random::get(0, end_index);
reward_index = Random::get(0, end_index-1);
return &this->reward[reward_index];
}
@ -556,7 +556,7 @@ bool Cube_make (LPCHARACTER ch)
if (0 < cube_proto->gold)
ch->PointChange(POINT_GOLD, -(cube_proto->gold), false);
percent_number = number(1,100);
percent_number = Random::get(1,100);
if ( percent_number<=cube_proto->percent)
{
// ¼º°ø

View File

@ -209,7 +209,7 @@ void DBManager::PushBilling(CLoginData * pkLD)
pkLD->SetLogonTime();
int lRemainSecs = pkLD->GetRemainSecs() - t.dwUseSec;
pkLD->SetRemainSecs(MAX(0, lRemainSecs));
pkLD->SetRemainSecs(std::max(0, lRemainSecs));
t.dwLoginKey = pkLD->GetKey();
t.bBillType = pkLD->GetBillType();
@ -219,9 +219,9 @@ void DBManager::PushBilling(CLoginData * pkLD)
if (t.bBillType == BILLING_IP_FREE || t.bBillType == BILLING_IP_TIME || t.bBillType == BILLING_IP_DAY)
snprintf(t.szLogin, sizeof(t.szLogin), "%u", pkLD->GetBillID());
else
strncpy(t.szLogin, pkLD->GetLogin(), sizeof(t.szLogin));
strlcpy(t.szLogin, pkLD->GetLogin(), sizeof(t.szLogin));
strncpy(t.szIP, pkLD->GetIP(), sizeof(t.szIP));
strlcpy(t.szIP, pkLD->GetIP(), sizeof(t.szIP));
m_vec_kUseTime.push_back(t);
}
@ -426,7 +426,7 @@ void DBManager::SendLoginPing(const char * c_pszLogin)
TPacketGGLoginPing ptog;
ptog.bHeader = HEADER_GG_LOGIN_PING;
strncpy(ptog.szLogin, c_pszLogin, sizeof(ptog.szLogin));
strlcpy(ptog.szLogin, c_pszLogin, sizeof(ptog.szLogin));
if (!g_pkAuthMasterDesc) // If I am master, broadcast to others
{
@ -451,7 +451,7 @@ void DBManager::SendAuthLogin(LPDESC d)
ptod.dwID = r.id;
trim_and_lower(r.login, ptod.szLogin, sizeof(ptod.szLogin));
strncpy(ptod.szSocialID, r.social_id, sizeof(ptod.szSocialID));
strlcpy(ptod.szSocialID, r.social_id, sizeof(ptod.szSocialID));
ptod.dwLoginKey = d->GetLoginKey();
ptod.bBillType = pkLD->GetBillType();
ptod.dwBillID = pkLD->GetBillID();
@ -542,7 +542,7 @@ bool GetGameTimeIP(MYSQL_RES * pRes, BYTE & bBillType, DWORD & dwBillID, int & s
str_to_number(day_seconds, row[col++]);
char szIP[MAX_HOST_LENGTH + 1];
strncpy(szIP, c_pszIP, sizeof(szIP));
strlcpy(szIP, c_pszIP, sizeof(szIP));
char * p = strrchr(szIP, '.');
++p;
@ -612,9 +612,9 @@ void SendBillingExpire(const char * c_pszLogin, BYTE bBillType, int iSecs, CLogi
{
TPacketBillingExpire ptod;
strncpy(ptod.szLogin, c_pszLogin, sizeof(ptod.szLogin));
strlcpy(ptod.szLogin, c_pszLogin, sizeof(ptod.szLogin));
ptod.bBillType = bBillType;
ptod.dwRemainSeconds = MAX(0, iSecs);
ptod.dwRemainSeconds = std::max(0, iSecs);
db_clientdesc->DBPacket(HEADER_GD_BILLING_EXPIRE, 0, &ptod, sizeof(TPacketBillingExpire));
sys_log(0, "BILLING: EXPIRE %s type %d sec %d ptr %p", c_pszLogin, bBillType, iSecs, pkLD);
}
@ -666,7 +666,7 @@ void DBManager::AnalyzeReturnQuery(SQLMsg * pMsg)
break;
}
strncpy(szEncrytPassword, row[col++], sizeof(szEncrytPassword));
strlcpy(szEncrytPassword, row[col++], sizeof(szEncrytPassword));
if (!row[col])
{
@ -675,7 +675,7 @@ void DBManager::AnalyzeReturnQuery(SQLMsg * pMsg)
break;
}
strncpy(szPassword, row[col++], sizeof(szPassword));
strlcpy(szPassword, row[col++], sizeof(szPassword));
if (!row[col])
{
@ -684,7 +684,7 @@ void DBManager::AnalyzeReturnQuery(SQLMsg * pMsg)
}
else
{
strncpy(szMatrixCode, row[col++], sizeof(szMatrixCode));
strlcpy(szMatrixCode, row[col++], sizeof(szMatrixCode));
}
if (!row[col])
@ -694,7 +694,7 @@ void DBManager::AnalyzeReturnQuery(SQLMsg * pMsg)
break;
}
strncpy(szSocialID, row[col++], sizeof(szSocialID));
strlcpy(szSocialID, row[col++], sizeof(szSocialID));
if (!row[col])
{
@ -712,7 +712,7 @@ void DBManager::AnalyzeReturnQuery(SQLMsg * pMsg)
break;
}
strncpy(szStatus, row[col++], sizeof(szStatus));
strlcpy(szStatus, row[col++], sizeof(szStatus));
BYTE bNotAvail = 0;
str_to_number(bNotAvail, row[col++]);
@ -810,8 +810,8 @@ void DBManager::AnalyzeReturnQuery(SQLMsg * pMsg)
r.id = dwID;
trim_and_lower(pinfo->login, r.login, sizeof(r.login));
strncpy(r.passwd, pinfo->passwd, sizeof(r.passwd));
strncpy(r.social_id, szSocialID, sizeof(r.social_id));
strlcpy(r.passwd, pinfo->passwd, sizeof(r.passwd));
strlcpy(r.social_id, szSocialID, sizeof(r.social_id));
DESC_MANAGER::instance().ConnectAccount(r.login, d);
d->SetMatrixCode(szMatrixCode);
@ -927,7 +927,7 @@ void DBManager::AnalyzeReturnQuery(SQLMsg * pMsg)
}
}
SendBillingExpire(pinfo->szLogin, pinfo->bBillType, MAX(0, iRemainSecs), pkLD);
SendBillingExpire(pinfo->szLogin, pinfo->bBillType, std::max(0, iRemainSecs), pkLD);
M2_DELETE(pinfo);
}
break;
@ -1178,10 +1178,10 @@ void VCardUse(LPCHARACTER CardOwner, LPCHARACTER CardTaker, LPITEM item)
TPacketGDVCard p;
p.dwID = item->GetSocket(0);
strncpy(p.szSellCharacter, CardOwner->GetName(), sizeof(p.szSellCharacter));
strncpy(p.szSellAccount, CardOwner->GetDesc()->GetAccountTable().login, sizeof(p.szSellAccount));
strncpy(p.szBuyCharacter, CardTaker->GetName(), sizeof(p.szBuyCharacter));
strncpy(p.szBuyAccount, CardTaker->GetDesc()->GetAccountTable().login, sizeof(p.szBuyAccount));
strlcpy(p.szSellCharacter, CardOwner->GetName(), sizeof(p.szSellCharacter));
strlcpy(p.szSellAccount, CardOwner->GetDesc()->GetAccountTable().login, sizeof(p.szSellAccount));
strlcpy(p.szBuyCharacter, CardTaker->GetName(), sizeof(p.szBuyCharacter));
strlcpy(p.szBuyAccount, CardTaker->GetDesc()->GetAccountTable().login, sizeof(p.szBuyAccount));
db_clientdesc->DBPacket(HEADER_GD_VCARD, 0, &p, sizeof(TPacketGDVCard));
@ -1209,7 +1209,7 @@ void DBManager::RequestBlockException(const char *login, int cmd)
TPacketBlockException packet;
packet.cmd = cmd;
strncpy(packet.login, login, sizeof(packet.login));
strlcpy(packet.login, login, sizeof(packet.login));
db_clientdesc->DBPacket(HEADER_GD_BLOCK_EXCEPTION, 0, &packet, sizeof(packet));
}

View File

@ -175,8 +175,8 @@ void DESC::Destroy()
{
TLogoutPacket pack;
strncpy(pack.login, m_accountTable.login, sizeof(pack.login));
strncpy(pack.passwd, m_accountTable.passwd, sizeof(pack.passwd));
strlcpy(pack.login, m_accountTable.login, sizeof(pack.login));
strlcpy(pack.passwd, m_accountTable.passwd, sizeof(pack.passwd));
db_clientdesc->DBPacket(HEADER_GD_LOGOUT, m_dwHandle, &pack, sizeof(TLogoutPacket));
}
@ -345,7 +345,7 @@ void DESC::Packet(const void * c_pvData, int iSize)
TPacketGGRelay p;
p.bHeader = HEADER_GG_RELAY;
strncpy(p.szName, m_stRelayName.c_str(), sizeof(p.szName));
strlcpy(p.szName, m_stRelayName.c_str(), sizeof(p.szName));
p.lSize = iSize;
if (!RawPacket(&p, sizeof(p)))
@ -649,7 +649,7 @@ void DESC::SendLoginSuccessPacket()
if (g)
{
p.guild_id[i] = g->GetID();
strncpy(p.guild_name[i], g->GetName(), sizeof(p.guild_name[i]));
strlcpy(p.guild_name[i], g->GetName(), sizeof(p.guild_name[i]));
}
else
{

View File

@ -172,7 +172,7 @@ void CLIENT_DESC::SetPhase(int iPhase)
TPacketGDSetup p;
memset(&p, 0, sizeof(p));
strncpy(p.szPublicIP, g_szPublicIP, sizeof(p.szPublicIP));
strlcpy(p.szPublicIP, g_szPublicIP, sizeof(p.szPublicIP));
if (!g_bAuthServer)
{
@ -208,9 +208,9 @@ void CLIENT_DESC::SetPhase(int iPhase)
if (r.id != 0)
{
pck.dwID = r.id;
strncpy(pck.szLogin, r.login, sizeof(pck.szLogin));
strncpy(pck.szSocialID, r.social_id, sizeof(pck.szSocialID));
strncpy(pck.szHost, d->GetHostName(), sizeof(pck.szHost));
strlcpy(pck.szLogin, r.login, sizeof(pck.szLogin));
strlcpy(pck.szSocialID, r.social_id, sizeof(pck.szSocialID));
strlcpy(pck.szHost, d->GetHostName(), sizeof(pck.szHost));
pck.dwLoginKey = d->GetLoginKey();
buf.write(&pck, sizeof(TPacketLoginOnSetup));

View File

@ -129,7 +129,7 @@ DWORD DESC_MANAGER::CreateHandshake()
RETRY:
do
{
DWORD val = thecore_random() % (1024 * 1024);
DWORD val = Random::get(0, 1024 * 1024 - 1);
*(DWORD *) (crc_buf ) = val;
*((DWORD *) crc_buf + 1) = get_global_time();
@ -411,7 +411,7 @@ void DESC_MANAGER::GetUserCount(int & iTotal, int ** paiEmpireUserCount, int & i
DWORD DESC_MANAGER::MakeRandomKey(DWORD dwHandle)
{
DWORD random_key = thecore_random();
DWORD random_key = Random::get<int>();
m_map_handle_random_key.insert(std::make_pair(dwHandle, random_key));
return random_key;
}
@ -444,7 +444,7 @@ DWORD DESC_MANAGER::CreateLoginKey(LPDESC d)
do
{
dwKey = number(1, INT_MAX);
dwKey = Random::get(1, INT_MAX);
if (m_map_pkLoginKey.find(dwKey) != m_map_pkLoginKey.end())
continue;

View File

@ -517,7 +517,7 @@ void CDungeon::SpawnMoveUnique(const char* key, DWORD vnum, const char* pos_from
TAreaInfo & ai_to = it_to->second;
int dir = ai.dir;
if (dir==-1)
dir = number(0,359);
dir = Random::get(0,359);
LPSECTREE_MAP pkSectreeMap = SECTREE_MANAGER::instance().GetMap(m_lMapIndex);
if (pkSectreeMap == NULL) {
@ -526,10 +526,10 @@ void CDungeon::SpawnMoveUnique(const char* key, DWORD vnum, const char* pos_from
}
for (int i=0;i<100;i++)
{
int dx = number(ai.sx, ai.ex);
int dy = number(ai.sy, ai.ey);
int tx = number(ai_to.sx, ai_to.ex);
int ty = number(ai_to.sy, ai_to.ey);
int dx = Random::get(ai.sx, ai.ex);
int dy = Random::get(ai.sy, ai.ey);
int tx = Random::get(ai_to.sx, ai_to.ex);
int ty = Random::get(ai_to.sy, ai_to.ey);
LPCHARACTER ch = CHARACTER_MANAGER::instance().SpawnMob(vnum, m_lMapIndex, pkSectreeMap->m_setting.iBaseX+dx, pkSectreeMap->m_setting.iBaseY+dy, 0, false, dir);
@ -562,7 +562,7 @@ void CDungeon::SpawnUnique(const char* key, DWORD vnum, const char* pos)
TAreaInfo & ai = it->second;
int dir = ai.dir;
if (dir==-1)
dir = number(0,359);
dir = Random::get(0,359);
LPSECTREE_MAP pkSectreeMap = SECTREE_MANAGER::instance().GetMap(m_lMapIndex);
if (pkSectreeMap == NULL) {
@ -571,8 +571,8 @@ void CDungeon::SpawnUnique(const char* key, DWORD vnum, const char* pos)
}
for (int i=0;i<100;i++)
{
int dx = number(ai.sx, ai.ex);
int dy = number(ai.sy, ai.ey);
int dx = Random::get(ai.sx, ai.ex);
int dy = Random::get(ai.sy, ai.ey);
LPCHARACTER ch = CHARACTER_MANAGER::instance().SpawnMob(vnum, m_lMapIndex, pkSectreeMap->m_setting.iBaseX+dx, pkSectreeMap->m_setting.iBaseY+dy, 0, false, dir);
@ -707,7 +707,7 @@ void CDungeon::Spawn(DWORD vnum, const char* pos)
TAreaInfo & ai = it->second;
int dir = ai.dir;
if (dir==-1)
dir = number(0,359);
dir = Random::get(0,359);
LPSECTREE_MAP pkSectreeMap = SECTREE_MANAGER::instance().GetMap(m_lMapIndex);
if (pkSectreeMap == NULL)
@ -715,8 +715,8 @@ void CDungeon::Spawn(DWORD vnum, const char* pos)
sys_err("cannot find map by index %d", m_lMapIndex);
return;
}
int dx = number(ai.sx, ai.ex);
int dy = number(ai.sy, ai.ey);
int dx = Random::get(ai.sx, ai.ex);
int dy = Random::get(ai.sy, ai.ey);
LPCHARACTER ch = CHARACTER_MANAGER::instance().SpawnMob(vnum, m_lMapIndex, pkSectreeMap->m_setting.iBaseX+dx, pkSectreeMap->m_setting.iBaseY+dy, 0, false, dir);
if (ch)
@ -900,7 +900,7 @@ void CDungeon::SpawnMoveGroup(DWORD vnum, const char* pos_from, const char* pos_
int dir = ai.dir;
if (dir == -1)
dir = number(0,359);
dir = Random::get(0,359);
LPSECTREE_MAP pkSectreeMap = SECTREE_MANAGER::instance().GetMap(m_lMapIndex);
if (pkSectreeMap == NULL) {
@ -910,8 +910,8 @@ void CDungeon::SpawnMoveGroup(DWORD vnum, const char* pos_from, const char* pos_
while (count--)
{
int tx = number(ai_to.sx, ai_to.ex)+pkSectreeMap->m_setting.iBaseX;
int ty = number(ai_to.sy, ai_to.ey)+pkSectreeMap->m_setting.iBaseY;
int tx = Random::get(ai_to.sx, ai_to.ex)+pkSectreeMap->m_setting.iBaseX;
int ty = Random::get(ai_to.sy, ai_to.ey)+pkSectreeMap->m_setting.iBaseY;
CHARACTER_MANAGER::instance().SpawnMoveGroup(vnum, m_lMapIndex, pkSectreeMap->m_setting.iBaseX+ai.sx, pkSectreeMap->m_setting.iBaseY+ai.sy, pkSectreeMap->m_setting.iBaseX+ai.ex, pkSectreeMap->m_setting.iBaseY+ai.ey, tx, ty, NULL, true);
}
}

View File

@ -50,14 +50,14 @@ void ConvertEmpireText(DWORD dwEmpireID, char* szText, size_t len, int iPct)
for (BYTE* pbText = reinterpret_cast<BYTE*>(szText) ; len > 0 && *pbText != '\0' ; --len, ++pbText)
{
if (number(1,100) > iPct)
if (Random::get(1,100) > iPct)
{
if (*pbText & 0x80)
{
if (g_iUseLocale)
{
static char s_cChinaTable[][3] = {"¡ò","££","£¤","¡ù","¡ð" };
int n = number(0, 4);
int n = Random::get(0, 4);
pbText[0] = s_cChinaTable[n][0];
pbText[1] = s_cChinaTable[n][1];
}

View File

@ -248,7 +248,7 @@ void Initialize()
do
{
strncpy(szCol2, start, MIN(sizeof(szCol2), (tab - start) + 1));
strlcpy(szCol2, start, std::min<size_t>(sizeof(szCol2), (tab - start) + 1));
szCol2[tab-start] = '\0';
trim_and_lower(szCol2, szCol, sizeof(szCol));
@ -259,7 +259,7 @@ void Initialize()
{
switch (iColCount++)
{
case 0: strncpy(fish_info[idx].name, szCol, sizeof(fish_info[idx].name)); break;
case 0: strlcpy(fish_info[idx].name, szCol, sizeof(fish_info[idx].name)); break;
case 1: str_to_number(fish_info[idx].vnum, szCol); break;
case 2: str_to_number(fish_info[idx].dead_vnum, szCol); break;
case 3: str_to_number(fish_info[idx].grill_vnum, szCol); break;
@ -328,7 +328,7 @@ void Initialize()
int DetermineFishByProbIndex(int prob_idx)
{
int rv = number(1, g_prob_sum[prob_idx]);
int rv = Random::get(1, g_prob_sum[prob_idx]);
int * p = std::lower_bound(g_prob_accumulate[prob_idx], g_prob_accumulate[prob_idx]+ MAX_FISH, rv);
int fish_idx = p - g_prob_accumulate[prob_idx];
return fish_idx;
@ -378,11 +378,11 @@ int DetermineFish(LPCHARACTER ch)
int adjust = 0;
if (quest::CQuestManager::instance().GetEventFlag("fish_miss_pct") != 0)
{
int fish_pct_value = MINMAX(0, quest::CQuestManager::instance().GetEventFlag("fish_miss_pct"), 200);
int fish_pct_value = std::clamp(quest::CQuestManager::instance().GetEventFlag("fish_miss_pct"), 0, 200);
adjust = (100-fish_pct_value) * fish_info[0].prob[prob_idx] / 100;
}
int rv = number(adjust + 1, g_prob_sum[prob_idx]);
int rv = Random::get(adjust + 1, g_prob_sum[prob_idx]);
int * p = std::lower_bound(g_prob_accumulate[prob_idx], g_prob_accumulate[prob_idx] + MAX_FISH, rv);
int fish_idx = p - g_prob_accumulate[prob_idx];
@ -438,7 +438,7 @@ void FishingPractice(LPCHARACTER ch)
if (rod && rod->GetType() == ITEM_ROD)
{
// 최대 수련도가 아닌 경우 낚시대 수련
if ( rod->GetRefinedVnum()>0 && rod->GetSocket(0) < rod->GetValue(2) && number(1,rod->GetValue(1))==1 )
if ( rod->GetRefinedVnum()>0 && rod->GetSocket(0) < rod->GetValue(2) && Random::get(1,rod->GetValue(1))==1 )
{
rod->SetSocket(0, rod->GetSocket(0) + 1);
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("낚시대의 수련도가 증가하였습니다! (%d/%d)"),rod->GetSocket(0), rod->GetValue(2));
@ -529,7 +529,7 @@ LPEVENT CreateFishingEvent(LPCHARACTER ch)
info->step = 0;
info->hang_time = 0;
int time = number(10, 40);
int time = Random::get(10, 40);
TPacketGCFishing p;
p.header = HEADER_GC_FISHING;
@ -565,11 +565,11 @@ int Compute(DWORD fish_id, DWORD ms, DWORD* item, int level)
if (ms > 6000)
return -1;
int time_step = MINMAX(0,((ms + 99) / 200), MAX_FISHING_TIME_COUNT - 1);
int time_step = std::clamp<int>(((ms + 99) / 200), 0, MAX_FISHING_TIME_COUNT - 1);
if (number(1, 100) <= aFishingTime[fish_info[fish_id].time_type][time_step])
if (Random::get(1, 100) <= aFishingTime[fish_info[fish_id].time_type][time_step])
{
if (number(1, fish_info[fish_id].difficulty) <= level)
if (Random::get(1, fish_info[fish_id].difficulty) <= level)
{
*item = fish_info[fish_id].vnum;
return 0;
@ -582,19 +582,19 @@ int Compute(DWORD fish_id, DWORD ms, DWORD* item, int level)
int GetFishLength(int fish_id)
{
if (number(0,99))
if (Random::get(0,99))
{
// 99% : normal size
return (int)(fish_info[fish_id].length_range[0] +
(fish_info[fish_id].length_range[1] - fish_info[fish_id].length_range[0])
* (number(0,2000)+number(0,2000)+number(0,2000)+number(0,2000)+number(0,2000))/10000);
* (Random::get(0,2000)+Random::get(0,2000)+Random::get(0,2000)+Random::get(0,2000)+Random::get(0,2000))/10000);
}
else
{
// 1% : extra LARGE size
return (int)(fish_info[fish_id].length_range[1] +
(fish_info[fish_id].length_range[2] - fish_info[fish_id].length_range[1])
* 2 * asin(number(0,10000)/10000.) / M_PI);
* 2 * asin(Random::get(0,10000)/10000.) / M_PI);
}
}
@ -660,11 +660,11 @@ void Take(fishing_event_info* info, LPCHARACTER ch)
if (info->fish_id == 5)
{
strncpy(p.szBoard, LC_TEXT("낚시이벤트월척붕어"), sizeof(p.szBoard));
strlcpy(p.szBoard, LC_TEXT("낚시이벤트월척붕어"), sizeof(p.szBoard));
}
else if (info->fish_id == 6)
{
strncpy(p.szBoard, LC_TEXT("낚시이벤트잉어"), sizeof(p.szBoard));
strlcpy(p.szBoard, LC_TEXT("낚시이벤트잉어"), sizeof(p.szBoard));
}
db_clientdesc->DBPacket(HEADER_GD_HIGHSCORE_REGISTER, 0, &p, sizeof(TPacketGDHighscore));
@ -739,7 +739,7 @@ void Simulation(int level, int count, int prob_idx, LPCHARACTER ch)
{
int fish_id = DetermineFishByProbIndex(prob_idx);
DWORD item = 0;
Compute(fish_id, (number(2000, 4000) + number(2000,4000)) / 2, &item, level);
Compute(fish_id, (Random::get(2000, 4000) + Random::get(2000,4000)) / 2, &item, level);
if (item)
{
@ -763,7 +763,7 @@ void UseFish(LPCHARACTER ch, LPITEM item)
if (idx<=1 || idx >= MAX_FISH)
return;
int r = number(1, 10000);
int r = Random::get(1, 10000);
item->SetCount(item->GetCount()-1);
@ -794,7 +794,7 @@ void UseFish(LPCHARACTER ch, LPITEM item)
case USED_SHELLFISH: // 1
if ( LC_IsCanada() == true )
{
if ( number(0, 2) != 2 ) return;
if ( Random::get(0, 2) != 2 ) return;
}
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("배 속에서 조개가 나왔습니다."));
@ -869,7 +869,7 @@ int RealRefineRod(LPCHARACTER ch, LPITEM item)
int iAdv = rod->GetValue(0) / 10;
if (number(1,100) <= rod->GetValue(3))
if (Random::get(1,100) <= rod->GetValue(3))
{
LogManager::instance().RefineLog(ch->GetPlayerID(), rod->GetName(), rod->GetID(), iAdv, 1, "ROD");

View File

@ -61,14 +61,14 @@ CGuild::CGuild(TGuildCreateParameter & cp)
m_iMemberCountBonus = 0;
strncpy(m_data.name, cp.name, sizeof(m_data.name));
strlcpy(m_data.name, cp.name, sizeof(m_data.name));
m_data.master_pid = cp.master->GetPlayerID();
strncpy(m_data.grade_array[0].grade_name, LC_TEXT("±æµåÀå"), sizeof(m_data.grade_array[0].grade_name));
strlcpy(m_data.grade_array[0].grade_name, LC_TEXT("±æµåÀå"), sizeof(m_data.grade_array[0].grade_name));
m_data.grade_array[0].auth_flag = GUILD_AUTH_ADD_MEMBER | GUILD_AUTH_REMOVE_MEMBER | GUILD_AUTH_NOTICE | GUILD_AUTH_USE_SKILL;
for (int i = 1; i < GUILD_GRADE_COUNT; ++i)
{
strncpy(m_data.grade_array[i].grade_name, LC_TEXT("±æµå¿ø"), sizeof(m_data.grade_array[i].grade_name));
strlcpy(m_data.grade_array[i].grade_name, LC_TEXT("±æµå¿ø"), sizeof(m_data.grade_array[i].grade_name));
m_data.grade_array[i].auth_flag = 0;
}
@ -446,7 +446,7 @@ void CGuild::SendListPacket(LPCHARACTER ch)
buf.write(&(it->second), sizeof(DWORD)*3+1);
strncpy(c, it->second.name.c_str(), MIN(sizeof(c), it->second.name.length() + 1));
strlcpy(c, it->second.name.c_str(), std::min(sizeof(c), it->second.name.length() + 1));
buf.write(c, CHARACTER_NAME_MAX_LEN+1 );
@ -579,7 +579,7 @@ void CGuild::LoadGuildGradeData(SQLMsg* pmsg)
if (grade >= 1 && grade <= 15)
{
//sys_log(0, "GuildGradeLoad %s", name);
strncpy(m_data.grade_array[grade-1].grade_name, name, sizeof(m_data.grade_array[grade-1].grade_name));
strlcpy(m_data.grade_array[grade-1].grade_name, name, sizeof(m_data.grade_array[grade-1].grade_name));
m_data.grade_array[grade-1].auth_flag = auth;
}
}
@ -596,7 +596,7 @@ void CGuild::LoadGuildData(SQLMsg* pmsg)
m_data.master_pid = strtoul(row[0], (char **)NULL, 10);
m_data.level = (BYTE)strtoul(row[1], (char **)NULL, 10);
m_data.exp = strtoul(row[2], (char **)NULL, 10);
strncpy(m_data.name, row[3], sizeof(m_data.name));
strlcpy(m_data.name, row[3], sizeof(m_data.name));
m_data.skill_point = (BYTE) strtoul(row[4], (char **) NULL, 10);
if (row[5])
@ -604,7 +604,7 @@ void CGuild::LoadGuildData(SQLMsg* pmsg)
else
memset(m_data.abySkill, 0, sizeof(BYTE) * GUILD_SKILL_COUNT);
m_data.power = MAX(0, strtoul(row[6], (char **) NULL, 10));
m_data.power = std::max<int>(0, strtoul(row[6], (char **) NULL, 10));
str_to_number(m_data.ladder_point, row[7]);
@ -703,7 +703,7 @@ void CGuild::__P2PUpdateGrade(SQLMsg* pmsg)
// 등급 명칭이 현재와 다르다면 업데이트
if (0 != strcmp(m_data.grade_array[grade].grade_name, name))
{
strncpy(m_data.grade_array[grade].grade_name, name, sizeof(m_data.grade_array[grade].grade_name));
strlcpy(m_data.grade_array[grade].grade_name, name, sizeof(m_data.grade_array[grade].grade_name));
TPacketGCGuild pack;
@ -715,7 +715,7 @@ void CGuild::__P2PUpdateGrade(SQLMsg* pmsg)
pack.size += sizeof(pack2);
pack2.grade = grade + 1;
strncpy(pack2.grade_name, name, sizeof(pack2.grade_name));
strlcpy(pack2.grade_name, name, sizeof(pack2.grade_name));
TEMP_BUFFER buf;
@ -810,7 +810,7 @@ void CGuild::ChangeGradeName(BYTE grade, const char* grade_name)
DBManager::instance().FuncAfterQuery(FSendChangeGrade(GetID(), grade), "UPDATE guild_grade%s SET name = '%s' where guild_id = %u and grade = %d", get_table_postfix(), text, m_data.guild_id, grade);
grade--;
strncpy(m_data.grade_array[grade].grade_name, grade_name, sizeof(m_data.grade_array[grade].grade_name));
strlcpy(m_data.grade_array[grade].grade_name, grade_name, sizeof(m_data.grade_array[grade].grade_name));
TPacketGCGuild pack;
pack.header = HEADER_GC_GUILD;
@ -820,7 +820,7 @@ void CGuild::ChangeGradeName(BYTE grade, const char* grade_name)
TOneGradeNamePacket pack2;
pack.size+=sizeof(pack2);
pack2.grade = grade+1;
strncpy(pack2.grade_name,grade_name, sizeof(pack2.grade_name));
strlcpy(pack2.grade_name,grade_name, sizeof(pack2.grade_name));
TEMP_BUFFER buf;
buf.write(&pack,sizeof(pack));
@ -896,7 +896,7 @@ void CGuild::SendGuildInfoPacket(LPCHARACTER ch)
pack_sub.master_pid = m_data.master_pid;
pack_sub.exp = m_data.exp;
pack_sub.level = m_data.level;
strncpy(pack_sub.name, m_data.name, sizeof(pack_sub.name));
strlcpy(pack_sub.name, m_data.name, sizeof(pack_sub.name));
pack_sub.gold = m_data.gold;
pack_sub.has_land = HasLand();
@ -1079,8 +1079,8 @@ void CGuild::RefreshCommentForce(DWORD player_id)
MYSQL_ROW row = mysql_fetch_row(pmsg->Get()->pSQLResult);
DWORD id = strtoul(row[0], NULL, 10);
strncpy(szName, row[1], sizeof(szName));
strncpy(szContent, row[2], sizeof(szContent));
strlcpy(szName, row[1], sizeof(szName));
strlcpy(szContent, row[2], sizeof(szContent));
d->RawPacket(&id, sizeof(id));
d->RawPacket(szName, sizeof(szName));
@ -1411,7 +1411,7 @@ void CGuild::ComputeGuildPoints()
{
m_data.max_power = GUILD_BASE_POWER + (m_data.level-1) * GUILD_POWER_PER_LEVEL;
m_data.power = MINMAX(0, m_data.power, m_data.max_power);
m_data.power = std::clamp(m_data.power, 0, m_data.max_power);
}
int CGuild::GetSkillLevel(DWORD vnum)
@ -1489,7 +1489,7 @@ void CGuild::GuildPointChange(BYTE type, int amount, bool save)
case POINT_SP:
m_data.power += amount;
m_data.power = MINMAX(0, m_data.power, m_data.max_power);
m_data.power = std::clamp(m_data.power, 0, m_data.max_power);
if (save)
{
@ -1679,7 +1679,7 @@ void CGuild::Chat(const char* c_pszText)
p1.bHeader = HEADER_GG_GUILD;
p1.bSubHeader = GUILD_SUBHEADER_GG_CHAT;
p1.dwGuild = GetID();
strncpy(p2.szText, c_pszText, sizeof(p2.szText));
strlcpy(p2.szText, c_pszText, sizeof(p2.szText));
P2P_MANAGER::instance().Send(&p1, sizeof(TPacketGGGuild));
P2P_MANAGER::instance().Send(&p2, sizeof(TPacketGGGuildChat));
@ -1800,7 +1800,7 @@ void CGuild::AdvanceLevel(int iLevel)
if (m_data.level == iLevel)
return;
m_data.level = MIN(GUILD_MAX_LEVEL, iLevel);
m_data.level = std::min<BYTE>(GUILD_MAX_LEVEL, iLevel);
}
void CGuild::RequestDepositMoney(LPCHARACTER ch, int iGold)

View File

@ -166,7 +166,7 @@ void CHorseRider::UpdateHorseStamina(int iStamina, bool bSend)
{
int level = GetHorseLevel();
m_Horse.sStamina = MINMAX(0, m_Horse.sStamina + iStamina, c_aHorseStat[level].iMaxStamina);
m_Horse.sStamina = std::clamp(m_Horse.sStamina + iStamina, 0, c_aHorseStat[level].iMaxStamina);
if (GetHorseStamina() == 0 && IsHorseRiding())
{
@ -347,7 +347,7 @@ void CHorseRider::UpdateHorseHealth(int iHealth, bool bSend)
{
int level = GetHorseLevel();
m_Horse.sHealth = MINMAX(0, m_Horse.sHealth + iHealth, c_aHorseStat[level].iMaxHealth);
m_Horse.sHealth = std::clamp(m_Horse.sHealth + iHealth, 0, c_aHorseStat[level].iMaxHealth);
if (level && m_Horse.sHealth == 0)
HorseDie();
@ -366,7 +366,7 @@ void CHorseRider::HorseDie()
void CHorseRider::SetHorseLevel(int iLevel)
{
m_Horse.bLevel = iLevel = MINMAX(0, iLevel, HORSE_MAX_LEVEL);
m_Horse.bLevel = iLevel = std::clamp(iLevel, 0, HORSE_MAX_LEVEL);
m_Horse.sStamina = c_aHorseStat[iLevel].iMaxStamina;
m_Horse.sHealth = c_aHorseStat[iLevel].iMaxHealth;

View File

@ -50,7 +50,7 @@ void CHorseNameManager::BroadcastHorseName(DWORD dwPlayerID, const char* szHorse
{
TPacketUpdateHorseName packet;
packet.dwPlayerID = dwPlayerID;
strncpy(packet.szHorseName, szHorseName, sizeof(packet.szHorseName));
strlcpy(packet.szHorseName, szHorseName, sizeof(packet.szHorseName));
db_clientdesc->DBPacket(HEADER_GD_UPDATE_HORSE_NAME, 0, &packet, sizeof(TPacketUpdateHorseName));
}

View File

@ -220,7 +220,7 @@ void LoginFailure(LPDESC d, const char * c_pszStatus)
TPacketGCLoginFailure failurePacket;
failurePacket.header = HEADER_GC_LOGIN_FAILURE;
strncpy(failurePacket.szStatus, c_pszStatus, sizeof(failurePacket.szStatus));
strlcpy(failurePacket.szStatus, c_pszStatus, sizeof(failurePacket.szStatus));
d->Packet(&failurePacket, sizeof(failurePacket));
}
@ -367,7 +367,7 @@ int CInputHandshake::Analyze(LPDESC d, BYTE bHeader, const char * c_pData)
p.dwID = (DWORD)(atoi(msg.c_str()));
snprintf(szTmp,sizeof(szTmp),"Sent to DB cache to delete ItemAward, id: %d",p.dwID);
//sys_log(0,"%d",p.dwID);
// strncpy(p.login, msg.c_str(), sizeof(p.login));
// strlcpy(p.login, msg.c_str(), sizeof(p.login));
db_clientdesc->DBPacket(HEADER_GD_DELETE_AWARDID, 0, &p, sizeof(p));
stResult += szTmp;
}
@ -408,14 +408,14 @@ dev_log(LOG_DEB0, "DC : '%s'", msg.c_str());
TPacketGGDisconnect pgg;
pgg.bHeader = HEADER_GG_DISCONNECT;
strncpy(pgg.szLogin, msg.c_str(), sizeof(pgg.szLogin));
strlcpy(pgg.szLogin, msg.c_str(), sizeof(pgg.szLogin));
P2P_MANAGER::instance().Send(&pgg, sizeof(TPacketGGDisconnect));
// delete login key
{
TPacketDC p;
strncpy(p.login, msg.c_str(), sizeof(p.login));
strlcpy(p.login, msg.c_str(), sizeof(p.login));
db_clientdesc->DBPacket(HEADER_GD_DC, 0, &p, sizeof(p));
}
}
@ -526,7 +526,7 @@ dev_log(LOG_DEB0, "DC : '%s'", msg.c_str());
is >> strPrivEmpire >> empire >> type >> value >> duration;
// ÃÖ´ëÄ¡ 10¹è
value = MINMAX(0, value, 1000);
value = std::clamp(value, 0, 1000);
stResult = "PRIV_EMPIRE FAIL";
if (!is.fail())

View File

@ -116,7 +116,7 @@ void CInputAuth::Login(LPDESC d, const char * c_pData)
trim_and_lower(pinfo->login, login, sizeof(login));
char passwd[PASSWD_MAX_LEN + 1];
strncpy(passwd, pinfo->passwd, sizeof(passwd));
strlcpy(passwd, pinfo->passwd, sizeof(passwd));
sys_log(0, "InputAuth::Login : %s(%d) desc %p",
login, strlen(login), get_pointer(d));
@ -135,7 +135,7 @@ void CInputAuth::Login(LPDESC d, const char * c_pData)
TPacketGCLoginFailure failurePacket;
failurePacket.header = HEADER_GC_LOGIN_FAILURE;
strncpy(failurePacket.szStatus, "SHUTDOWN", sizeof(failurePacket.szStatus));
strlcpy(failurePacket.szStatus, "SHUTDOWN", sizeof(failurePacket.szStatus));
d->Packet(&failurePacket, sizeof(failurePacket));
return;

View File

@ -131,7 +131,7 @@ void CInputDB::LoginSuccess(DWORD dwHandle, const char *data)
TLogoutPacket pack;
strncpy(pack.login, pTab->login, sizeof(pack.login));
strlcpy(pack.login, pTab->login, sizeof(pack.login));
db_clientdesc->DBPacket(HEADER_GD_LOGOUT, dwHandle, &pack, sizeof(pack));
return;
}
@ -142,7 +142,7 @@ void CInputDB::LoginSuccess(DWORD dwHandle, const char *data)
TLogoutPacket pack;
strncpy(pack.login, pTab->login, sizeof(pack.login));
strlcpy(pack.login, pTab->login, sizeof(pack.login));
db_clientdesc->DBPacket(HEADER_GD_LOGOUT, dwHandle, &pack, sizeof(pack));
LoginFailure(d, pTab->status);
@ -163,7 +163,7 @@ void CInputDB::LoginSuccess(DWORD dwHandle, const char *data)
{
TPacketGCEmpire pe;
pe.bHeader = HEADER_GC_EMPIRE;
pe.bEmpire = number(1, 3);
pe.bEmpire = Random::get(1, 3);
d->Packet(&pe, sizeof(pe));
}
else
@ -320,14 +320,14 @@ void CInputDB::ChangeName(LPDESC d, const char * data)
for (size_t i = 0; i < PLAYER_PER_ACCOUNT; ++i)
if (r.players[i].dwID == p->pid)
{
strncpy(r.players[i].szName, p->name, sizeof(r.players[i].szName));
strlcpy(r.players[i].szName, p->name, sizeof(r.players[i].szName));
r.players[i].bChangeName = 0;
TPacketGCChangeName pgc;
pgc.header = HEADER_GC_CHANGE_NAME;
pgc.pid = p->pid;
strncpy(pgc.name, p->name, sizeof(pgc.name));
strlcpy(pgc.name, p->name, sizeof(pgc.name));
d->Packet(&pgc, sizeof(TPacketGCChangeName));
break;
@ -405,7 +405,7 @@ void CInputDB::PlayerLoad(LPDESC d, const char * data)
TPacketGGLogin p;
p.bHeader = HEADER_GG_LOGIN;
strncpy(p.szName, ch->GetName(), sizeof(p.szName));
strlcpy(p.szName, ch->GetName(), sizeof(p.szName));
p.dwPID = ch->GetPlayerID();
p.bEmpire = ch->GetEmpire();
p.lMapIndex = SECTREE_MANAGER::instance().GetMapIndex(ch->GetX(), ch->GetY());
@ -1265,7 +1265,7 @@ void CInputDB::LoginAlready(LPDESC d, const char * c_pData)
TPacketGGDisconnect pgg;
pgg.bHeader = HEADER_GG_DISCONNECT;
strncpy(pgg.szLogin, p->szLogin, sizeof(pgg.szLogin));
strlcpy(pgg.szLogin, p->szLogin, sizeof(pgg.szLogin));
P2P_MANAGER::instance().Send(&pgg, sizeof(TPacketGGDisconnect));
}
@ -1875,7 +1875,7 @@ void CInputDB::BillingExpire(const char * c_pData)
if (p->dwRemainSeconds <= 60)
{
int i = MAX(5, p->dwRemainSeconds);
int i = std::max<int>(5, p->dwRemainSeconds);
sys_log(0, "BILLING_EXPIRE: %s %u", p->szLogin, p->dwRemainSeconds);
d->DelayedDisconnect(i);
}
@ -1929,7 +1929,7 @@ void CInputDB::Notice(const char * c_pData)
extern void SendNotice(const char * c_pszBuf);
char szBuf[256+1];
strncpy(szBuf, c_pData, sizeof(szBuf));
strlcpy(szBuf, c_pData, sizeof(szBuf));
sys_log(0, "InputDB:: Notice: %s", szBuf);
@ -2533,7 +2533,7 @@ void CInputDB::AddMonarchMoney(LPDESC d, const char * data )
if (ch)
{
if (number(1, 100) > 95)
if (Random::get(1, 100) > 95)
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("현재 %s 국고에는 %u 의 돈이 있습니다"), EMPIRE_NAME(Empire), CMonarch::instance().GetMoney(Empire));
}
}

View File

@ -96,7 +96,7 @@ void CInputLogin::Login(LPDESC d, const char * data)
if (g_iUseLocale && !test_server)
{
failurePacket.header = HEADER_GC_LOGIN_FAILURE;
strncpy(failurePacket.szStatus, "VERSION", sizeof(failurePacket.szStatus));
strlcpy(failurePacket.szStatus, "VERSION", sizeof(failurePacket.szStatus));
d->Packet(&failurePacket, sizeof(TPacketGCLoginFailure));
return;
}
@ -104,7 +104,7 @@ void CInputLogin::Login(LPDESC d, const char * data)
if (g_bNoMoreClient)
{
failurePacket.header = HEADER_GC_LOGIN_FAILURE;
strncpy(failurePacket.szStatus, "SHUTDOWN", sizeof(failurePacket.szStatus));
strlcpy(failurePacket.szStatus, "SHUTDOWN", sizeof(failurePacket.szStatus));
d->Packet(&failurePacket, sizeof(TPacketGCLoginFailure));
return;
}
@ -120,7 +120,7 @@ void CInputLogin::Login(LPDESC d, const char * data)
if (g_iUserLimit <= iTotal)
{
failurePacket.header = HEADER_GC_LOGIN_FAILURE;
strncpy(failurePacket.szStatus, "FULL", sizeof(failurePacket.szStatus));
strlcpy(failurePacket.szStatus, "FULL", sizeof(failurePacket.szStatus));
d->Packet(&failurePacket, sizeof(TPacketGCLoginFailure));
return;
}
@ -128,8 +128,8 @@ void CInputLogin::Login(LPDESC d, const char * data)
TLoginPacket login_packet;
strncpy(login_packet.login, login, sizeof(login_packet.login));
strncpy(login_packet.passwd, pinfo->passwd, sizeof(login_packet.passwd));
strlcpy(login_packet.login, login, sizeof(login_packet.login));
strlcpy(login_packet.passwd, pinfo->passwd, sizeof(login_packet.passwd));
db_clientdesc->DBPacket(HEADER_GD_LOGIN, d->GetHandle(), &login_packet, sizeof(TLoginPacket));
}
@ -160,7 +160,7 @@ void CInputLogin::LoginByKey(LPDESC d, const char * data)
TPacketGCLoginFailure failurePacket;
failurePacket.header = HEADER_GC_LOGIN_FAILURE;
strncpy(failurePacket.szStatus, "SHUTDOWN", sizeof(failurePacket.szStatus));
strlcpy(failurePacket.szStatus, "SHUTDOWN", sizeof(failurePacket.szStatus));
d->Packet(&failurePacket, sizeof(TPacketGCLoginFailure));
return;
}
@ -178,7 +178,7 @@ void CInputLogin::LoginByKey(LPDESC d, const char * data)
TPacketGCLoginFailure failurePacket;
failurePacket.header = HEADER_GC_LOGIN_FAILURE;
strncpy(failurePacket.szStatus, "FULL", sizeof(failurePacket.szStatus));
strlcpy(failurePacket.szStatus, "FULL", sizeof(failurePacket.szStatus));
d->Packet(&failurePacket, sizeof(TPacketGCLoginFailure));
return;
@ -191,10 +191,10 @@ void CInputLogin::LoginByKey(LPDESC d, const char * data)
TPacketGDLoginByKey ptod;
strncpy(ptod.szLogin, login, sizeof(ptod.szLogin));
strlcpy(ptod.szLogin, login, sizeof(ptod.szLogin));
ptod.dwLoginKey = pinfo->dwLoginKey;
memcpy(ptod.adwClientKey, pinfo->adwClientKey, sizeof(DWORD) * 4);
strncpy(ptod.szIP, d->GetHostName(), sizeof(ptod.szIP));
strlcpy(ptod.szIP, d->GetHostName(), sizeof(ptod.szIP));
db_clientdesc->DBPacket(HEADER_GD_LOGIN_BY_KEY, d->GetHandle(), &ptod, sizeof(TPacketGDLoginByKey));
}
@ -225,7 +225,7 @@ void CInputLogin::ChangeName(LPDESC d, const char * data)
TPacketGDChangeName pdb;
pdb.pid = c_r.players[p->index].dwID;
strncpy(pdb.name, p->name, sizeof(pdb.name));
strlcpy(pdb.name, p->name, sizeof(pdb.name));
db_clientdesc->DBPacket(HEADER_GD_CHANGE_NAME, d->GetHandle(), &pdb, sizeof(TPacketGDChangeName));
}
@ -279,7 +279,7 @@ bool NewPlayerTable(TPlayerTable * table,
memset(table, 0, sizeof(TPlayerTable));
strncpy(table->name, name, sizeof(table->name));
strlcpy(table->name, name, sizeof(table->name));
table->level = 1;
table->job = job;
@ -295,8 +295,8 @@ bool NewPlayerTable(TPlayerTable * table,
table->sp = JobInitialPoints[job].max_sp + table->iq * JobInitialPoints[job].sp_per_iq;
table->stamina = JobInitialPoints[job].max_stamina;
table->x = CREATE_START_X(bEmpire) + number(-300, 300);
table->y = CREATE_START_Y(bEmpire) + number(-300, 300);
table->x = CREATE_START_X(bEmpire) + Random::get(-300, 300);
table->y = CREATE_START_Y(bEmpire) + Random::get(-300, 300);
table->z = 0;
table->dir = 0;
table->playtime = 0;
@ -310,8 +310,8 @@ bool NewPlayerTable(TPlayerTable * table,
for (int i = 1; i < 35; ++i)
{
int iHP = number(JobInitialPoints[job].hp_per_lv_begin, JobInitialPoints[job].hp_per_lv_end);
int iSP = number(JobInitialPoints[job].sp_per_lv_begin, JobInitialPoints[job].sp_per_lv_end);
int iHP = Random::get(JobInitialPoints[job].hp_per_lv_begin, JobInitialPoints[job].hp_per_lv_end);
int iSP = Random::get(JobInitialPoints[job].sp_per_lv_begin, JobInitialPoints[job].sp_per_lv_end);
table->sRandomHP += iHP;
table->sRandomSP += iSP;
table->stat_point += 3;
@ -395,7 +395,7 @@ bool NewPlayerTable2(TPlayerTable * table, const char * name, BYTE race, BYTE sh
memset(table, 0, sizeof(TPlayerTable));
strncpy(table->name, name, sizeof(table->name));
strlcpy(table->name, name, sizeof(table->name));
table->level = 1;
table->job = race; // Á÷¾÷´ë½Å Á¾Á·À» ³Ö´Â´Ù
@ -411,8 +411,8 @@ bool NewPlayerTable2(TPlayerTable * table, const char * name, BYTE race, BYTE sh
table->sp = JobInitialPoints[job].max_sp + table->iq * JobInitialPoints[job].sp_per_iq;
table->stamina = JobInitialPoints[job].max_stamina;
table->x = CREATE_START_X(bEmpire) + number(-300, 300);
table->y = CREATE_START_Y(bEmpire) + number(-300, 300);
table->x = CREATE_START_X(bEmpire) + Random::get(-300, 300);
table->y = CREATE_START_Y(bEmpire) + Random::get(-300, 300);
table->z = 0;
table->dir = 0;
table->playtime = 0;
@ -488,7 +488,7 @@ void CInputLogin::CharacterCreate(LPDESC d, const char * data)
const TAccountTable & c_rAccountTable = d->GetAccountTable();
trim_and_lower(c_rAccountTable.login, player_create_packet.login, sizeof(player_create_packet.login));
strncpy(player_create_packet.passwd, c_rAccountTable.passwd, sizeof(player_create_packet.passwd));
strlcpy(player_create_packet.passwd, c_rAccountTable.passwd, sizeof(player_create_packet.passwd));
player_create_packet.account_id = c_rAccountTable.id;
player_create_packet.account_index = pinfo->index;
@ -533,7 +533,7 @@ void CInputLogin::CharacterDelete(LPDESC d, const char * data)
trim_and_lower(c_rAccountTable.login, player_delete_packet.login, sizeof(player_delete_packet.login));
player_delete_packet.player_id = c_rAccountTable.players[pinfo->index].dwID;
player_delete_packet.account_index = pinfo->index;
strncpy(player_delete_packet.private_code, pinfo->private_code, sizeof(player_delete_packet.private_code));
strlcpy(player_delete_packet.private_code, pinfo->private_code, sizeof(player_delete_packet.private_code));
db_clientdesc->DBPacket(HEADER_GD_PLAYER_DELETE, d->GetHandle(), &player_delete_packet, sizeof(TPlayerDeletePacket));
}

View File

@ -146,7 +146,7 @@ bool SpamBlockCheck(LPCHARACTER ch, const char* const buf, const size_t buflen)
if (it->second.first >= g_uiSpamBlockScore)
{
spam_event_info* info = AllocEventInfo<spam_event_info>();
strncpy(info->host, ch->GetDesc()->GetHostName(), sizeof(info->host));
strlcpy(info->host, ch->GetDesc()->GetHostName(), sizeof(info->host));
it->second.second = event_create(block_chat_by_ip_event, info, PASSES_PER_SEC(g_uiSpamBlockDuration));
sys_log(0, "SPAM_IP: %s for %u seconds", info->host, g_uiSpamBlockDuration);
@ -324,7 +324,7 @@ int CInputMain::Whisper(LPCHARACTER ch, const char * data, size_t uiBytes)
pack.bHeader = HEADER_GC_WHISPER;
pack.bType = WHISPER_TYPE_SENDER_BLOCKED;
pack.wSize = sizeof(TPacketGCWhisper);
strncpy(pack.szNameFrom, pinfo->szNameTo, sizeof(pack.szNameFrom));
strlcpy(pack.szNameFrom, pinfo->szNameTo, sizeof(pack.szNameFrom));
ch->GetDesc()->Packet(&pack, sizeof(pack));
}
return iExtraLen;
@ -359,7 +359,7 @@ int CInputMain::Whisper(LPCHARACTER ch, const char * data, size_t uiBytes)
pack.bHeader = HEADER_GC_WHISPER;
pack.bType = WHISPER_TYPE_NOT_EXIST;
pack.wSize = sizeof(TPacketGCWhisper);
strncpy(pack.szNameFrom, pinfo->szNameTo, sizeof(pack.szNameFrom));
strlcpy(pack.szNameFrom, pinfo->szNameTo, sizeof(pack.szNameFrom));
ch->GetDesc()->Packet(&pack, sizeof(TPacketGCWhisper));
sys_log(0, "WHISPER: no player");
}
@ -374,7 +374,7 @@ int CInputMain::Whisper(LPCHARACTER ch, const char * data, size_t uiBytes)
pack.bHeader = HEADER_GC_WHISPER;
pack.bType = WHISPER_TYPE_SENDER_BLOCKED;
pack.wSize = sizeof(TPacketGCWhisper);
strncpy(pack.szNameFrom, pinfo->szNameTo, sizeof(pack.szNameFrom));
strlcpy(pack.szNameFrom, pinfo->szNameTo, sizeof(pack.szNameFrom));
ch->GetDesc()->Packet(&pack, sizeof(pack));
}
}
@ -386,7 +386,7 @@ int CInputMain::Whisper(LPCHARACTER ch, const char * data, size_t uiBytes)
pack.bHeader = HEADER_GC_WHISPER;
pack.bType = WHISPER_TYPE_TARGET_BLOCKED;
pack.wSize = sizeof(TPacketGCWhisper);
strncpy(pack.szNameFrom, pinfo->szNameTo, sizeof(pack.szNameFrom));
strlcpy(pack.szNameFrom, pinfo->szNameTo, sizeof(pack.szNameFrom));
ch->GetDesc()->Packet(&pack, sizeof(pack));
}
}
@ -395,7 +395,7 @@ int CInputMain::Whisper(LPCHARACTER ch, const char * data, size_t uiBytes)
BYTE bType = WHISPER_TYPE_NORMAL;
char buf[CHAT_MAX_LEN + 1];
strncpy(buf, data + sizeof(TPacketCGWhisper), MIN(iExtraLen + 1, sizeof(buf)));
strlcpy(buf, data + sizeof(TPacketCGWhisper), std::min<size_t>(iExtraLen + 1, sizeof(buf)));
const size_t buflen = strlen(buf);
if (true == SpamBlockCheck(ch, buf, buflen))
@ -462,7 +462,7 @@ int CInputMain::Whisper(LPCHARACTER ch, const char * data, size_t uiBytes)
pack.bHeader = HEADER_GC_WHISPER;
pack.bType = WHISPER_TYPE_ERROR;
pack.wSize = sizeof(TPacketGCWhisper) + len;
strncpy(pack.szNameFrom, pinfo->szNameTo, sizeof(pack.szNameFrom));
strlcpy(pack.szNameFrom, pinfo->szNameTo, sizeof(pack.szNameFrom));
ch->GetDesc()->RawPacket(&pack, sizeof(pack));
ch->GetDesc()->Packet(buf, len);
@ -486,7 +486,7 @@ int CInputMain::Whisper(LPCHARACTER ch, const char * data, size_t uiBytes)
pack.bHeader = HEADER_GC_WHISPER;
pack.wSize = sizeof(TPacketGCWhisper) + buflen;
pack.bType = bType;
strncpy(pack.szNameFrom, ch->GetName(), sizeof(pack.szNameFrom));
strlcpy(pack.szNameFrom, ch->GetName(), sizeof(pack.szNameFrom));
// desc->BufferedPacket을 하지 않고 버퍼에 써야하는 이유는
// P2P relay되어 패킷이 캡슐화 될 수 있기 때문이다.
@ -565,7 +565,7 @@ struct FEmpireChatPacket
else
{
// 사람마다 스킬레벨이 다르니 매번 해야합니다
strncpy(converted_msg, orig_msg, sizeof(converted_msg));
strlcpy(converted_msg, orig_msg, sizeof(converted_msg));
ConvertEmpireText(bEmpire, converted_msg + namelen, sizeof(converted_msg) - namelen, 10 + 2 * d->GetCharacter()->GetSkillPower(SKILL_LANGUAGE1 + bEmpire - 1));
d->Packet(converted_msg, orig_len);
@ -654,7 +654,7 @@ int CInputMain::Chat(LPCHARACTER ch, const char * data, size_t uiBytes)
}
char buf[CHAT_MAX_LEN - (CHARACTER_NAME_MAX_LEN + 3) + 1];
strncpy(buf, data + sizeof(TPacketCGChat), MIN(iExtraLen + 1, sizeof(buf)));
strlcpy(buf, data + sizeof(TPacketCGChat), std::min<size_t>(iExtraLen + 1, sizeof(buf)));
const size_t buflen = strlen(buf);
if (buflen > 1 && *buf == '/')
@ -740,7 +740,7 @@ int CInputMain::Chat(LPCHARACTER ch, const char * data, size_t uiBytes)
p.bHeader = HEADER_GG_SHOUT;
p.bEmpire = ch->GetEmpire();
strncpy(p.szText, chatbuf, sizeof(p.szText));
strlcpy(p.szText, chatbuf, sizeof(p.szText));
P2P_MANAGER::instance().Send(&p, sizeof(TPacketGGShout));
@ -960,7 +960,7 @@ int CInputMain::Messenger(LPCHARACTER ch, const char* c_pData, size_t uiBytes)
return -1;
char name[CHARACTER_NAME_MAX_LEN + 1];
strncpy(name, c_pData, sizeof(name));
strlcpy(name, c_pData, sizeof(name));
if (ch->GetGMLevel() == GM_PLAYER && gm_get_level(name) != GM_PLAYER)
{
@ -997,7 +997,7 @@ int CInputMain::Messenger(LPCHARACTER ch, const char* c_pData, size_t uiBytes)
return -1;
char char_name[CHARACTER_NAME_MAX_LEN + 1];
strncpy(char_name, c_pData, sizeof(char_name));
strlcpy(char_name, c_pData, sizeof(char_name));
MessengerManager::instance().RemoveFromList(ch->GetName(), char_name);
}
return CHARACTER_NAME_MAX_LEN;
@ -1359,7 +1359,7 @@ bool CheckComboHack(LPCHARACTER ch, BYTE bArg, DWORD dwTime, bool CheckSpeedHack
}
else if (bArg > 14 && bArg < 22)
{
int idx = MIN(2, ch->GetComboIndex());
int idx = std::min<int>(2, ch->GetComboIndex());
if (ch->GetComboSequence() > 5) // 현재 6콤보 이상은 없다.
{
@ -1463,7 +1463,7 @@ bool CheckComboHack(LPCHARACTER ch, BYTE bArg, DWORD dwTime, bool CheckSpeedHack
else
{
// 말이 안되는 콤보가 왔다 해커일 가능성?
//if (ch->GetDesc()->DelayedDisconnect(number(2, 9)))
//if (ch->GetDesc()->DelayedDisconnect(Random::get(2, 9)))
//{
// LogManager::instance().HackLog("Hacker", ch);
// sys_log(0, "HACKER: %s arg %u", ch->GetName(), bArg);
@ -1488,7 +1488,7 @@ bool CheckComboHack(LPCHARACTER ch, BYTE bArg, DWORD dwTime, bool CheckSpeedHack
else
{
// 말이 안되는 콤보가 왔다 해커일 가능성?
if (ch->GetDesc()->DelayedDisconnect(number(2, 9)))
if (ch->GetDesc()->DelayedDisconnect(Random::get(2, 9)))
{
LogManager::instance().HackLog("Hacker", ch);
sys_log(0, "HACKER: %s arg %u", ch->GetName(), bArg);
@ -1627,12 +1627,12 @@ void CInputMain::Move(LPCHARACTER ch, const char * data)
if (test_server)
{
ch->GetDesc()->DelayedDisconnect(number(2, 8));
ch->GetDesc()->DelayedDisconnect(Random::get(2, 8));
ch->ChatPacket(CHAT_TYPE_INFO, szBuf);
}
else
{
ch->GetDesc()->DelayedDisconnect(number(150, 500));
ch->GetDesc()->DelayedDisconnect(Random::get(150, 500));
}
}
@ -1663,13 +1663,13 @@ void CInputMain::Move(LPCHARACTER ch, const char * data)
/*
if (pinfo->dwTime == 10653691) // 디버거 발견
{
if (ch->GetDesc()->DelayedDisconnect(number(15, 30)))
if (ch->GetDesc()->DelayedDisconnect(Random::get(15, 30)))
LogManager::instance().HackLog("Debugger", ch);
}
else if (pinfo->dwTime == 10653971) // Softice 발견
{
if (ch->GetDesc()->DelayedDisconnect(number(15, 30)))
if (ch->GetDesc()->DelayedDisconnect(Random::get(15, 30)))
LogManager::instance().HackLog("Softice", ch);
}
*/
@ -1997,7 +1997,7 @@ void CInputMain::QuestInputString(LPCHARACTER ch, const void* c_pData)
TPacketCGQuestInputString * p = (TPacketCGQuestInputString*) c_pData;
char msg[65];
strncpy(msg, p->msg, sizeof(msg));
strlcpy(msg, p->msg, sizeof(msg));
sys_log(0, "QUEST InputString pid %u msg %s", ch->GetPlayerID(), msg);
quest::CQuestManager::Instance().Input(ch->GetPlayerID(), msg);
@ -2424,7 +2424,7 @@ void CInputMain::AnswerMakeGuild(LPCHARACTER ch, const char* c_pData)
memset(&cp, 0, sizeof(cp));
cp.master = ch;
strncpy(cp.name, p->guild_name, sizeof(cp.name));
strlcpy(cp.name, p->guild_name, sizeof(cp.name));
if (cp.name[0] == 0 || !check_name(cp.name))
{
@ -2561,7 +2561,7 @@ int CInputMain::Guild(LPCHARACTER ch, const char * data, size_t uiBytes)
// by mhh : 길드자금은 당분간 넣을 수 없다.
return SubPacketLen;
const int gold = MIN(*reinterpret_cast<const int*>(c_pData), __deposit_limit());
const int gold = std::min(*reinterpret_cast<const int*>(c_pData), __deposit_limit());
if (gold < 0)
{
@ -2584,7 +2584,7 @@ int CInputMain::Guild(LPCHARACTER ch, const char * data, size_t uiBytes)
// by mhh : 길드자금은 당분간 뺄 수 없다.
return SubPacketLen;
const int gold = MIN(*reinterpret_cast<const int*>(c_pData), 500000);
const int gold = std::min(*reinterpret_cast<const int*>(c_pData), 500000);
if (gold < 0)
{
@ -2680,7 +2680,7 @@ int CInputMain::Guild(LPCHARACTER ch, const char * data, size_t uiBytes)
case GUILD_SUBHEADER_CG_CHANGE_GRADE_NAME:
{
char gradename[GUILD_GRADE_NAME_MAX_LEN + 1];
strncpy(gradename, c_pData + 1, sizeof(gradename));
strlcpy(gradename, c_pData + 1, sizeof(gradename));
const TGuildMember * m = pGuild->GetMember(ch->GetPlayerID());

View File

@ -73,7 +73,7 @@ int CInputP2P::Relay(LPDESC d, const char * c_pData, size_t uiBytes)
}
char buf[1024];
memcpy(buf, c_pbData, MIN(p->lSize, sizeof(buf)));
memcpy(buf, c_pbData, std::min<size_t>(p->lSize, sizeof(buf)));
TPacketGCWhisper* p2 = (TPacketGCWhisper*) buf;
// bType 상위 4비트: Empire 번호
@ -117,7 +117,7 @@ int CInputP2P::Notice(LPDESC d, const char * c_pData, size_t uiBytes)
}
char szBuf[256+1];
strncpy(szBuf, c_pData + sizeof(TPacketGGNotice), MIN(p->lSize + 1, sizeof(szBuf)));
strlcpy(szBuf, c_pData + sizeof(TPacketGGNotice), std::min<size_t>(p->lSize + 1, sizeof(szBuf)));
SendNotice(szBuf);
return (p->lSize);
}
@ -137,7 +137,7 @@ int CInputP2P::MonarchNotice(LPDESC d, const char * c_pData, size_t uiBytes)
}
char szBuf[256+1];
strncpy(szBuf, c_pData + sizeof(TPacketGGMonarchNotice), MIN(p->lSize + 1, sizeof(szBuf)));
strlcpy(szBuf, c_pData + sizeof(TPacketGGMonarchNotice), std::min<size_t>(p->lSize + 1, sizeof(szBuf)));
SendMonarchNotice(p->bEmpire, szBuf);
return (p->lSize);
}

View File

@ -151,7 +151,7 @@ void CItem::EncodeInsertPacket(LPENTITY ent)
p.bHeader = HEADER_GC_ITEM_OWNERSHIP;
p.dwVID = m_dwVID;
strncpy(p.szName, info->szOwnerName, sizeof(p.szName));
strlcpy(p.szName, info->szOwnerName, sizeof(p.szName));
d->Packet(&p, sizeof(TPacketGCItemOwnership));
}
@ -224,10 +224,10 @@ void CItem::UpdatePacket()
DWORD CItem::GetCount()
{
if (GetType() == ITEM_ELK) return MIN(m_dwCount, INT_MAX);
if (GetType() == ITEM_ELK) return std::min<DWORD>(m_dwCount, INT_MAX);
else
{
return MIN(m_dwCount, 200);
return std::min<DWORD>(m_dwCount, 200);
}
}
@ -235,11 +235,11 @@ bool CItem::SetCount(DWORD count)
{
if (GetType() == ITEM_ELK)
{
m_dwCount = MIN(count, INT_MAX);
m_dwCount = std::min<DWORD>(count, INT_MAX);
}
else
{
m_dwCount = MIN(count, ITEM_MAX_COUNT);
m_dwCount = std::min<DWORD>(count, ITEM_MAX_COUNT);
}
if (count == 0 && m_pOwner)
@ -630,7 +630,7 @@ void CItem::ModifyPoints(bool bAdd)
}
else
{
accessoryGrade = MIN(GetAccessorySocketGrade(), ITEM_ACCESSORY_SOCKET_MAX_NUM);
accessoryGrade = std::min<int>(GetAccessorySocketGrade(), ITEM_ACCESSORY_SOCKET_MAX_NUM);
}
for (int i = 0; i < ITEM_APPLY_MAX_NUM; ++i)
@ -647,7 +647,7 @@ void CItem::ModifyPoints(bool bAdd)
else
{
if (0 != accessoryGrade)
value += MAX(accessoryGrade, value * aiAccessorySocketEffectivePct[accessoryGrade] / 100);
value += std::max(accessoryGrade, value * aiAccessorySocketEffectivePct[accessoryGrade] / 100);
m_pOwner->ApplyPoint(m_pProto->aApplies[i].bType, bAdd ? value : -value);
}
@ -1095,7 +1095,7 @@ void CItem::SetOwnership(LPCHARACTER ch, int iSec)
m_dwOwnershipPID = ch->GetPlayerID();
item_event_info* info = AllocEventInfo<item_event_info>();
strncpy(info->szOwnerName, ch->GetName(), sizeof(info->szOwnerName));
strlcpy(info->szOwnerName, ch->GetName(), sizeof(info->szOwnerName));
info->item = this;
SetOwnershipEvent(event_create(ownership_event, info, PASSES_PER_SEC(iSec)));
@ -1104,7 +1104,7 @@ void CItem::SetOwnership(LPCHARACTER ch, int iSec)
p.bHeader = HEADER_GC_ITEM_OWNERSHIP;
p.dwVID = m_dwVID;
strncpy(p.szName, ch->GetName(), sizeof(p.szName));
strlcpy(p.szName, ch->GetName(), sizeof(p.szName));
PacketAround(&p, sizeof(p));
}
@ -1213,10 +1213,10 @@ void CItem::AlterToMagicItem()
// 100% È®·ü·Î ÁÁÀº ¼Ó¼º Çϳª
PutAttribute(aiItemMagicAttributePercentHigh);
if (number(1, 100) <= iSecondPct)
if (Random::get(1, 100) <= iSecondPct)
PutAttribute(aiItemMagicAttributePercentLow);
if (number(1, 100) <= iThirdPct)
if (Random::get(1, 100) <= iThirdPct)
PutAttribute(aiItemMagicAttributePercentLow);
}
@ -1340,7 +1340,7 @@ EVENTFUNC(timer_based_on_wear_expire_event)
return 0;
}
pkItem->SetSocket(ITEM_SOCKET_REMAIN_SEC, remain_time);
return PASSES_PER_SEC (MIN (60, remain_time));
return PASSES_PER_SEC (std::min<int>(60, remain_time));
}
void CItem::SetUniqueExpireEvent(LPEVENT pkEvent)
@ -1433,7 +1433,7 @@ void CItem::StartUniqueExpireEvent()
if (iSec == 0)
iSec = 60;
else
iSec = MIN(iSec, 60);
iSec = std::min(iSec, 60);
SetSocket(ITEM_SOCKET_UNIQUE_SAVE_TIME, 0);
@ -1525,7 +1525,7 @@ bool CItem::IsAccessoryForSocket()
void CItem::SetAccessorySocketGrade(int iGrade)
{
SetSocket(0, MINMAX(0, iGrade, GetAccessorySocketMaxGrade()));
SetSocket(0, std::clamp(iGrade, 0, GetAccessorySocketMaxGrade()));
int iDownTime = aiAccessorySocketDegradeTime[GetAccessorySocketGrade()];
@ -1537,7 +1537,7 @@ void CItem::SetAccessorySocketGrade(int iGrade)
void CItem::SetAccessorySocketMaxGrade(int iMaxGrade)
{
SetSocket(1, MINMAX(0, iMaxGrade, ITEM_ACCESSORY_SOCKET_MAX_NUM));
SetSocket(1, std::clamp<int>(iMaxGrade, 0, ITEM_ACCESSORY_SOCKET_MAX_NUM));
}
void CItem::SetAccessorySocketDownGradeTime(DWORD time)
@ -1603,7 +1603,7 @@ void CItem::StartAccessorySocketExpireEvent()
if (iSec <= 1)
iSec = 5;
else
iSec = MIN(iSec, 60);
iSec = std::min(iSec, 60);
item_vid_event_info* info = AllocEventInfo<item_vid_event_info>();
info->item_vid = GetVID();
@ -1881,17 +1881,17 @@ void CItem::CopySocketTo(LPITEM pItem)
int CItem::GetAccessorySocketGrade()
{
return MINMAX(0, GetSocket(0), GetAccessorySocketMaxGrade());
return std::clamp<int>(GetSocket(0), 0, GetAccessorySocketMaxGrade());
}
int CItem::GetAccessorySocketMaxGrade()
{
return MINMAX(0, GetSocket(1), ITEM_ACCESSORY_SOCKET_MAX_NUM);
return std::clamp<int>(GetSocket(1), 0, ITEM_ACCESSORY_SOCKET_MAX_NUM);
}
int CItem::GetAccessorySocketDownGradeTime()
{
return MINMAX(0, GetSocket(2), aiAccessorySocketDegradeTime[GetAccessorySocketGrade()]);
return std::clamp<int>(GetSocket(2), 0, aiAccessorySocketDegradeTime[GetAccessorySocketGrade()]);
}
void CItem::AttrLog()

View File

@ -22,12 +22,12 @@ void CItemAddonManager::ApplyAddonTo(int iAddonType, LPITEM pItem)
// TODO 일단 하드코딩으로 평타 스킬 수치 변경만 경우만 적용받게한다.
int iSkillBonus = MINMAX(-30, (int) (gauss_random(0, 5) + 0.5f), 30);
int iSkillBonus = std::clamp((int) (Random::get<std::normal_distribution<>>(0, 5) + 0.5f), -30, 30);
int iNormalHitBonus = 0;
if (abs(iSkillBonus) <= 20)
iNormalHitBonus = -2 * iSkillBonus + abs(number(-8, 8) + number(-8, 8)) + number(1, 4);
iNormalHitBonus = -2 * iSkillBonus + abs(Random::get(-8, 8) + Random::get(-8, 8)) + Random::get(1, 4);
else
iNormalHitBonus = -2 * iSkillBonus + number(1, 5);
iNormalHitBonus = -2 * iSkillBonus + Random::get(1, 5);
pItem->RemoveAttributeType(APPLY_SKILL_DAMAGE_BONUS);
pItem->RemoveAttributeType(APPLY_NORMAL_HIT_DAMAGE_BONUS);

View File

@ -104,7 +104,7 @@ void CItem::AddAttr(BYTE bApply, BYTE bLevel)
else
{
const TItemAttrTable & r = g_map_itemAttr[bApply];
int lVal = r.lValues[MIN(4, bLevel - 1)];
int lVal = r.lValues[std::min(4, bLevel - 1)];
if (lVal)
SetAttribute(i, bApply, lVal);
@ -138,7 +138,7 @@ void CItem::PutAttributeWithLevel(BYTE bLevel)
}
// 구축된 배열로 확률 계산을 통해 붙일 속성 선정
unsigned int prob = number(1, total);
unsigned int prob = Random::get(1, total);
int attr_idx = APPLY_NONE;
for (DWORD i = 0; i < avail.size(); ++i)
@ -171,7 +171,7 @@ void CItem::PutAttributeWithLevel(BYTE bLevel)
void CItem::PutAttribute(const int * aiAttrPercentTable)
{
int iAttrLevelPercent = number(1, 100);
int iAttrLevelPercent = Random::get(1, 100);
int i;
for (i = 0; i < ITEM_ATTRIBUTE_MAX_LEVEL; ++i)
@ -397,7 +397,7 @@ bool CItem::AddRareAttribute()
}
}
const TItemAttrTable& r = g_map_itemRare[avail[number(0, avail.size() - 1)]];
const TItemAttrTable& r = g_map_itemRare[avail[Random::get<int>(0, avail.size() - 1)]];
int nAttrLevel = 5;
if (nAttrLevel > r.bMaxLevelBySet[nAttrSet])

View File

@ -164,7 +164,7 @@ LPITEM ITEM_MANAGER::CreateItem(DWORD vnum, DWORD count, DWORD id, bool bTryMagi
do
{
dwSkillVnum = number(1, 111);
dwSkillVnum = Random::get(1, 111);
CSkillProto * pkSk = CSkillManager::instance().Get(dwSkillVnum);
@ -263,7 +263,7 @@ LPITEM ITEM_MANAGER::CreateItem(DWORD vnum, DWORD count, DWORD id, bool bTryMagi
;
else if (item->IsStackable()) // 합칠 수 있는 아이템의 경우
{
count = MINMAX(1, count, ITEM_MAX_COUNT);
count = std::clamp<int>(count, 1, ITEM_MAX_COUNT);
if (bTryMagic && count <= 1 && IS_SET(item->GetFlag(), ITEM_FLAG_MAKECOUNT))
count = item->GetValue(1);
@ -349,7 +349,7 @@ LPITEM ITEM_MANAGER::CreateItem(DWORD vnum, DWORD count, DWORD id, bool bTryMagi
if (iRarePct == -1)
iRarePct = table->bAlterToMagicItemPct;
if (number(1, 100) <= iRarePct)
if (Random::get(1, 100) <= iRarePct)
item->AlterToMagicItem();
}
@ -363,7 +363,7 @@ LPITEM ITEM_MANAGER::CreateItem(DWORD vnum, DWORD count, DWORD id, bool bTryMagi
do
{
dwSkillVnum = number(1, 111);
dwSkillVnum = Random::get(1, 111);
if (NULL != CSkillManager::instance().Get(dwSkillVnum))
break;
@ -377,7 +377,7 @@ LPITEM ITEM_MANAGER::CreateItem(DWORD vnum, DWORD count, DWORD id, bool bTryMagi
do
{
dwSkillVnum = number(112, 119);
dwSkillVnum = Random::get(112, 119);
if (NULL != CSkillManager::instance().Get(dwSkillVnum))
break;
@ -720,7 +720,7 @@ DWORD lotto()
do
{
for (int i = 0; i < 6; ++i)
szBuf[i] = 48 + number(1, 9);
szBuf[i] = 48 + Random::get(1, 9);
szBuf[6] = '\0';
@ -805,9 +805,9 @@ bool ITEM_MANAGER::GetDropPct(LPCHARACTER pkChr, LPCHARACTER pkKiller, OUT int&
BYTE bRank = pkChr->GetMobRank();
if (1 == number(1, 50000))
if (1 == Random::get(1, 50000))
iDeltaPercent += 1000;
else if (1 == number(1, 10000))
else if (1 == Random::get(1, 10000))
iDeltaPercent += 500;
sys_log(3, "CreateDropItem for level: %d rank: %u pct: %d", iLevel, bRank, iDeltaPercent);
@ -864,7 +864,7 @@ bool ITEM_MANAGER::CreateDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller, std::
int iPercent = (c_rInfo.m_iPercent * iDeltaPercent) / 100;
sys_log(3, "CreateDropItem %d ~ %d %d(%d)", c_rInfo.m_iLevelStart, c_rInfo.m_iLevelEnd, c_rInfo.m_dwVnum, iPercent, c_rInfo.m_iPercent);
if (iPercent >= number(1, iRandRange))
if (iPercent >= Random::get(1, iRandRange))
{
TItemTable * table = GetTable(c_rInfo.m_dwVnum);
@ -903,7 +903,7 @@ bool ITEM_MANAGER::CreateDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller, std::
{
int iPercent = (v[i].dwPct * iDeltaPercent) / 100;
if (iPercent >= number(1, iRandRange))
if (iPercent >= Random::get(1, iRandRange))
{
item = CreateItem(v[i].dwVnum, v[i].iCount, 0, true);
@ -938,7 +938,7 @@ bool ITEM_MANAGER::CreateDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller, std::
if (pGroup && !pGroup->IsEmpty())
{
int iPercent = 40000 * iDeltaPercent / pGroup->GetKillPerDrop();
if (iPercent >= number(1, iRandRange))
if (iPercent >= Random::get(1, iRandRange))
{
const CMobItemGroup::SMobItemGroupInfo& info = pGroup->GetOne();
item = CreateItem(info.dwItemVnum, info.iCount, 0, true, info.iRarePct);
@ -963,7 +963,7 @@ bool ITEM_MANAGER::CreateDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller, std::
for ( DWORD i=0; i < v.size(); i++ )
{
if ( v[i].dwPct >= (DWORD)number(1, 1000000/*iRandRange*/) )
if ( v[i].dwPct >= Random::get(1, 1000000) )
{
DWORD dwVnum = v[i].dwVNum;
item = CreateItem(dwVnum, v[i].iCount, 0, true);
@ -990,7 +990,7 @@ bool ITEM_MANAGER::CreateDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller, std::
{
int iPercent = (v[i].dwPct * iDeltaPercent) / 100;
if (iPercent >= number(1, iRandRange))
if (iPercent >= Random::get(1, iRandRange))
{
DWORD dwVnum = v[i].dwVnum;
item = CreateItem(dwVnum, v[i].iCount, 0, true);
@ -1010,7 +1010,7 @@ bool ITEM_MANAGER::CreateDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller, std::
{
int iPercent = (it->second * iDeltaPercent) / 100;
if (iPercent >= number(1, iRandRange))
if (iPercent >= Random::get(1, iRandRange))
{
item = CreateItem(pkChr->GetMobDropItemVnum(), 1, 0, true);
if (item) vec_item.push_back(item);
@ -1024,7 +1024,7 @@ bool ITEM_MANAGER::CreateDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller, std::
{
int iPercent = (pkChr->GetDropMetinStonePct() * iDeltaPercent) * 400;
if (iPercent >= number(1, iRandRange))
if (iPercent >= Random::get(1, iRandRange))
{
item = CreateItem(pkChr->GetDropMetinStoneVnum(), 1, 0, true);
if (item) vec_item.push_back(item);
@ -1033,7 +1033,7 @@ bool ITEM_MANAGER::CreateDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller, std::
}
if (pkKiller->IsHorseRiding() &&
GetDropPerKillPct(1000, 1000000, iDeltaPercent, "horse_skill_book_drop") >= number(1, iRandRange))
GetDropPerKillPct(1000, 1000000, iDeltaPercent, "horse_skill_book_drop") >= Random::get(1, iRandRange))
{
sys_log(0, "EVENT HORSE_SKILL_BOOK_DROP");
@ -1042,7 +1042,7 @@ bool ITEM_MANAGER::CreateDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller, std::
}
if (GetDropPerKillPct(100, 1000, iDeltaPercent, "lotto_drop") >= number(1, iRandRange))
if (GetDropPerKillPct(100, 1000, iDeltaPercent, "lotto_drop") >= Random::get(1, iRandRange))
{
DWORD * pdw = M2_NEW DWORD[3];
@ -1075,7 +1075,7 @@ bool ITEM_MANAGER::CreateDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller, std::
if (73 == pkKiller->GetMapIndex())
{
int per = 25; // 0.25%
if (number(1, 10000) <= per)
if (Random::get(1, 10000) <= per)
{
LPITEM item = 0;
if ((item = CreateItem(71122, 1, 0, true)))
@ -1104,7 +1104,7 @@ bool ITEM_MANAGER::CreateDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller, std::
break;
int per = 5; // 0.05%
if (number(1, 10000) <= per)
if (Random::get(1, 10000) <= per)
{
LPITEM item = 0;
item = CreateItem(vnum, 1, 0, true);
@ -1190,7 +1190,7 @@ static void __DropEvent_CharStone_DropItem(CHARACTER & killer, CHARACTER & victi
if (LC_IsCanada() == true)
MaxRange = 20000;
if (number(1, MaxRange) <= dropPercent)
if (Random::get(1, MaxRange) <= dropPercent)
{
int log_level = (test_server || killer.GetGMLevel() >= GM_LOW_WIZARD) ? 0 : 1;
int victim_level = victim.GetLevel();
@ -1205,7 +1205,7 @@ static void __DropEvent_CharStone_DropItem(CHARACTER & killer, CHARACTER & victi
}
static const int Stones[] = { 30210, 30211, 30212, 30213, 30214, 30215, 30216, 30217, 30218, 30219, 30258, 30259, 30260, 30261, 30262, 30263 };
int item_vnum = Stones[number(0, _countof(Stones))];
int item_vnum = Stones[Random::get<int>(0, _countof(Stones))];
LPITEM p_item = NULL;
@ -1307,23 +1307,23 @@ static LPITEM __DropEvent_RefineBox_GetDropItem(CHARACTER & killer, CHARACTER &
if (killer_level <= gs_dropEvent_refineBox.low)
{
if (number (1, gs_dropEvent_refineBox.percent_low) == 1)
if (Random::get(1, gs_dropEvent_refineBox.percent_low) == 1)
{
return itemMgr.CreateItem(lowerBox [number (1,lowerBox_range) - 1], 1, 0, true);
return itemMgr.CreateItem(lowerBox[Random::get(1, lowerBox_range) - 1], 1, 0, true);
}
}
else if (killer_level <= gs_dropEvent_refineBox.mid)
{
if (number (1, gs_dropEvent_refineBox.percent_mid) == 1)
if (Random::get(1, gs_dropEvent_refineBox.percent_mid) == 1)
{
return itemMgr.CreateItem(midderBox [number (1,midderBox_range) - 1], 1, 0, true);
return itemMgr.CreateItem(midderBox[Random::get(1, midderBox_range) - 1], 1, 0, true);
}
}
else
{
if (number (1, gs_dropEvent_refineBox.percent_high) == 1)
if (Random::get(1, gs_dropEvent_refineBox.percent_high) == 1)
{
return itemMgr.CreateItem(higherBox [number (1,higherBox_range) - 1], 1, 0, true);
return itemMgr.CreateItem(higherBox[Random::get(1, higherBox_range) - 1], 1, 0, true);
}
}
return NULL;
@ -1406,7 +1406,7 @@ void ITEM_MANAGER::CreateQuestDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller,
DWORD SOCK_ITEM_VNUM = 0;
if (LC_IsKorea() || LC_IsYMIR())
{
SOCK_ITEM_VNUM = (number(1,100)<=50) ? 50010 : 71111;
SOCK_ITEM_VNUM = (Random::get(1,100)<=50) ? 50010 : 71111;
}
else
{
@ -1433,7 +1433,7 @@ void ITEM_MANAGER::CreateQuestDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller,
}
sys_log(0, "SOCK DROP %d %d", iPercent, iRandRange);
if (iPercent >= number(1, iRandRange))
if (iPercent >= Random::get(1, iRandRange))
{
if ((item = CreateItem(SOCK_ITEM_VNUM, 1, 0, true)))
vec_item.push_back(item);
@ -1460,7 +1460,7 @@ void ITEM_MANAGER::CreateQuestDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller,
{
int iPercent = 40000 * iDeltaPercent / iDropPerKill[pkChr->GetMobRank()];
if (iPercent >= number(1, iRandRange))
if (iPercent >= Random::get(1, iRandRange))
{
if ((item = CreateItem(ITEM_VNUM, 1, 0, true)))
vec_item.push_back(item);
@ -1478,7 +1478,7 @@ void ITEM_MANAGER::CreateQuestDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller,
{
const DWORD ITEM_VNUM = 30178;
if (number(1,100) <= pct)
if (Random::get(1,100) <= pct)
{
if ((item = CreateItem(ITEM_VNUM, 1, 0, true)))
vec_item.push_back(item);
@ -1488,7 +1488,7 @@ void ITEM_MANAGER::CreateQuestDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller,
}
//육각보합
if (GetDropPerKillPct(100, g_iUseLocale ? 2000 : 800, iDeltaPercent, "2006_drop") >= number(1, iRandRange))
if (GetDropPerKillPct(100, g_iUseLocale ? 2000 : 800, iDeltaPercent, "2006_drop") >= Random::get(1, iRandRange))
{
sys_log(0, "육각보합 DROP EVENT ");
@ -1500,7 +1500,7 @@ void ITEM_MANAGER::CreateQuestDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller,
}
//육각보합+
if (GetDropPerKillPct(100, g_iUseLocale ? 2000 : 800, iDeltaPercent, "2007_drop") >= number(1, iRandRange))
if (GetDropPerKillPct(100, g_iUseLocale ? 2000 : 800, iDeltaPercent, "2007_drop") >= Random::get(1, iRandRange))
{
sys_log(0, "육각보합 DROP EVENT ");
@ -1511,7 +1511,7 @@ void ITEM_MANAGER::CreateQuestDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller,
}
// 새해 폭죽 이벤트
if (GetDropPerKillPct(/* minimum */ 100, /* default */ 1000, iDeltaPercent, "newyear_fire") >= number(1, iRandRange))
if (GetDropPerKillPct(/* minimum */ 100, /* default */ 1000, iDeltaPercent, "newyear_fire") >= Random::get(1, iRandRange))
{
// 중국은 폭죽, 한국 팽이
const DWORD ITEM_VNUM_FIRE = g_iUseLocale ? 50107 : 50108;
@ -1521,31 +1521,31 @@ void ITEM_MANAGER::CreateQuestDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller,
}
// 새해 대보름 원소 이벤트
if (GetDropPerKillPct(100, 500, iDeltaPercent, "newyear_moon") >= number(1, iRandRange))
if (GetDropPerKillPct(100, 500, iDeltaPercent, "newyear_moon") >= Random::get(1, iRandRange))
{
sys_log(0, "EVENT NEWYEAR_MOON DROP");
const static DWORD wonso_items[6] = { 50016, 50017, 50018, 50019, 50019, 50019, };
DWORD dwVnum = wonso_items[number(0,5)];
DWORD dwVnum = wonso_items[Random::get(0, 5)];
if ((item = CreateItem(dwVnum, 1, 0, true)))
vec_item.push_back(item);
}
// 발렌타인 데이 이벤트. OGE의 요구에 따라 event 최소값을 1로 변경.(다른 이벤트는 일단 그대로 둠.)
if (GetDropPerKillPct(1, g_iUseLocale ? 2000 : 800, iDeltaPercent, "valentine_drop") >= number(1, iRandRange))
if (GetDropPerKillPct(1, g_iUseLocale ? 2000 : 800, iDeltaPercent, "valentine_drop") >= Random::get(1, iRandRange))
{
sys_log(0, "EVENT VALENTINE_DROP");
const static DWORD valentine_items[2] = { 50024, 50025 };
DWORD dwVnum = valentine_items[number(0, 1)];
DWORD dwVnum = valentine_items[Random::get(0, 1)];
if ((item = CreateItem(dwVnum, 1, 0, true)))
vec_item.push_back(item);
}
// 아이스크림 이벤트
if (GetDropPerKillPct(100, g_iUseLocale ? 2000 : 800, iDeltaPercent, "icecream_drop") >= number(1, iRandRange))
if (GetDropPerKillPct(100, g_iUseLocale ? 2000 : 800, iDeltaPercent, "icecream_drop") >= Random::get(1, iRandRange))
{
const static DWORD icecream = 50123;
@ -1555,26 +1555,26 @@ void ITEM_MANAGER::CreateQuestDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller,
// new 크리스마스 이벤트
// 53002 : 아기 순록 소환권
if ((pkKiller->CountSpecifyItem(53002) > 0) && (GetDropPerKillPct(50, 100, iDeltaPercent, "new_xmas_event") >= number(1, iRandRange)))
if ((pkKiller->CountSpecifyItem(53002) > 0) && (GetDropPerKillPct(50, 100, iDeltaPercent, "new_xmas_event") >= Random::get(1, iRandRange)))
{
const static DWORD xmas_sock = 50010;
pkKiller->AutoGiveItem (xmas_sock, 1);
}
if ((pkKiller->CountSpecifyItem(53007) > 0) && (GetDropPerKillPct(50, 100, iDeltaPercent, "new_xmas_event") >= number(1, iRandRange)))
if ((pkKiller->CountSpecifyItem(53007) > 0) && (GetDropPerKillPct(50, 100, iDeltaPercent, "new_xmas_event") >= Random::get(1, iRandRange)))
{
const static DWORD xmas_sock = 50010;
pkKiller->AutoGiveItem (xmas_sock, 1);
}
//if (pkChr->GetLevel() >= 30 && (GetDropPerKillPct(50, 100, iDeltaPercent, "ds_drop") >= number(1, iRandRange)))
//if (pkChr->GetLevel() >= 30 && (GetDropPerKillPct(50, 100, iDeltaPercent, "ds_drop") >= Random::get(1, iRandRange)))
//{
// const static DWORD dragon_soul_gemstone = 30270;
// if ((item = CreateItem(dragon_soul_gemstone, 1, 0, true)))
// vec_item.push_back(item);
//}
if ( GetDropPerKillPct(100, g_iUseLocale ? 2000 : 800, iDeltaPercent, "halloween_drop") >= number(1, iRandRange) )
if ( GetDropPerKillPct(100, g_iUseLocale ? 2000 : 800, iDeltaPercent, "halloween_drop") >= Random::get(1, iRandRange) )
{
const static DWORD halloween_item = 30321;
@ -1582,7 +1582,7 @@ void ITEM_MANAGER::CreateQuestDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller,
vec_item.push_back(item);
}
if ( GetDropPerKillPct(100, g_iUseLocale ? 2000 : 800, iDeltaPercent, "ramadan_drop") >= number(1, iRandRange) )
if ( GetDropPerKillPct(100, g_iUseLocale ? 2000 : 800, iDeltaPercent, "ramadan_drop") >= Random::get(1, iRandRange) )
{
const static DWORD ramadan_item = 30315;
@ -1590,16 +1590,16 @@ void ITEM_MANAGER::CreateQuestDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller,
vec_item.push_back(item);
}
if ( GetDropPerKillPct(100, g_iUseLocale ? 2000 : 800, iDeltaPercent, "easter_drop") >= number(1, iRandRange) )
if ( GetDropPerKillPct(100, g_iUseLocale ? 2000 : 800, iDeltaPercent, "easter_drop") >= Random::get(1, iRandRange) )
{
const static DWORD easter_item_base = 50160;
if ( (item=CreateItem(easter_item_base+number(0,19), 1, 0, true)) )
if ( (item=CreateItem(easter_item_base + Random::get(0, 19), 1, 0, true)) )
vec_item.push_back(item);
}
// 월드컵 이벤트
if ( GetDropPerKillPct(100, g_iUseLocale ? 2000 : 800, iDeltaPercent, "football_drop") >= number(1, iRandRange) )
if ( GetDropPerKillPct(100, g_iUseLocale ? 2000 : 800, iDeltaPercent, "football_drop") >= Random::get(1, iRandRange) )
{
const static DWORD football_item = 50096;
@ -1608,11 +1608,11 @@ void ITEM_MANAGER::CreateQuestDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller,
}
// 화이트 데이 이벤트
if (GetDropPerKillPct(100, g_iUseLocale ? 2000 : 800, iDeltaPercent, "whiteday_drop") >= number(1, iRandRange))
if (GetDropPerKillPct(100, g_iUseLocale ? 2000 : 800, iDeltaPercent, "whiteday_drop") >= Random::get(1, iRandRange))
{
sys_log(0, "EVENT WHITEDAY_DROP");
const static DWORD whiteday_items[2] = { ITEM_WHITEDAY_ROSE, ITEM_WHITEDAY_CANDY };
DWORD dwVnum = whiteday_items[number(0,1)];
DWORD dwVnum = whiteday_items[Random::get(0, 1)];
if ((item = CreateItem(dwVnum, 1, 0, true)))
vec_item.push_back(item);
@ -1621,7 +1621,7 @@ void ITEM_MANAGER::CreateQuestDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller,
// 어린이날 수수께끼 상자 이벤트
if (pkKiller->GetLevel()>=50)
{
if (GetDropPerKillPct(100, 1000, iDeltaPercent, "kids_day_drop_high") >= number(1, iRandRange))
if (GetDropPerKillPct(100, 1000, iDeltaPercent, "kids_day_drop_high") >= Random::get(1, iRandRange))
{
DWORD ITEM_QUIZ_BOX = 50034;
@ -1631,7 +1631,7 @@ void ITEM_MANAGER::CreateQuestDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller,
}
else
{
if (GetDropPerKillPct(100, 1000, iDeltaPercent, "kids_day_drop") >= number(1, iRandRange))
if (GetDropPerKillPct(100, 1000, iDeltaPercent, "kids_day_drop") >= Random::get(1, iRandRange))
{
DWORD ITEM_QUIZ_BOX = 50034;
@ -1641,10 +1641,10 @@ void ITEM_MANAGER::CreateQuestDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller,
}
// 올림픽 드롭 이벤트
if (pkChr->GetLevel() >= 30 && GetDropPerKillPct(50, 100, iDeltaPercent, "medal_part_drop") >= number(1, iRandRange))
if (pkChr->GetLevel() >= 30 && GetDropPerKillPct(50, 100, iDeltaPercent, "medal_part_drop") >= Random::get(1, iRandRange))
{
const static DWORD drop_items[] = { 30265, 30266, 30267, 30268, 30269 };
int i = number (0, 4);
int i = Random::get(0, 4);
item = CreateItem(drop_items[i]);
if (item != NULL)
vec_item.push_back(item);
@ -1652,7 +1652,7 @@ void ITEM_MANAGER::CreateQuestDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller,
// ADD_GRANDMASTER_SKILL
// 혼석 아이템 드롭
if (pkChr->GetLevel() >= 40 && pkChr->GetMobRank() >= MOB_RANK_BOSS && GetDropPerKillPct(/* minimum */ 1, /* default */ 1000, iDeltaPercent, "three_skill_item") / GetThreeSkillLevelAdjust(pkChr->GetLevel()) >= number(1, iRandRange))
if (pkChr->GetLevel() >= 40 && pkChr->GetMobRank() >= MOB_RANK_BOSS && GetDropPerKillPct(/* minimum */ 1, /* default */ 1000, iDeltaPercent, "three_skill_item") / GetThreeSkillLevelAdjust(pkChr->GetLevel()) >= Random::get(1, iRandRange))
{
const DWORD ITEM_VNUM = 50513;
@ -1664,7 +1664,7 @@ void ITEM_MANAGER::CreateQuestDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller,
//
// 종자 아이템 drop
//
if (GetDropPerKillPct(100, 1000, iDeltaPercent, "dragon_boat_festival_drop") >= number(1, iRandRange))
if (GetDropPerKillPct(100, 1000, iDeltaPercent, "dragon_boat_festival_drop") >= Random::get(1, iRandRange))
{
const DWORD ITEM_SEED = 50085;
@ -1687,7 +1687,7 @@ void ITEM_MANAGER::CreateQuestDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller,
};
if (iDropMultiply[pkChr->GetMobRank()] &&
GetDropPerKillPct(1000, 1500, iDeltaPercent, "mars_drop") >= number(1, iRandRange) * iDropMultiply[pkChr->GetMobRank()])
GetDropPerKillPct(1000, 1500, iDeltaPercent, "mars_drop") >= Random::get(1, iRandRange) * iDropMultiply[pkChr->GetMobRank()])
{
if ((item = CreateItem(ITEM_HANIRON, 1, 0, true)))
vec_item.push_back(item);

View File

@ -89,14 +89,14 @@ class CSpecialItemGroup
if (m_bType == PCT)
{
int count = 0;
if (number(1,100) <= m_vecProbs[0])
if (Random::get(1,100) <= m_vecProbs[0])
{
idx_vec.push_back(0);
count++;
}
for (uint i = 1; i < m_vecProbs.size(); i++)
{
if (number(1,100) <= m_vecProbs[i] - m_vecProbs[i-1])
if (Random::get(1,100) <= m_vecProbs[i] - m_vecProbs[i-1])
{
idx_vec.push_back(i);
count++;
@ -113,7 +113,7 @@ class CSpecialItemGroup
int GetOneIndex() const
{
int n = number(1, m_vecProbs.back());
int n = Random::get(1, m_vecProbs.back());
itertype(m_vecProbs) it = lower_bound(m_vecProbs.begin(), m_vecProbs.end(), n);
return std::distance(m_vecProbs.begin(), it);
}
@ -211,7 +211,7 @@ class CMobItemGroup
int GetOneIndex() const
{
int n = number(1, m_vecProbs.back());
int n = Random::get(1, m_vecProbs.back());
itertype(m_vecProbs) it = lower_bound(m_vecProbs.begin(), m_vecProbs.end(), n);
return std::distance(m_vecProbs.begin(), it);
}

View File

@ -60,7 +60,7 @@ bool ITEM_MANAGER::ReadCommonDropItemFile(const char * c_pszFileName)
if (!p2)
break;
strncpy(szTemp, p, MIN(sizeof(szTemp), (p2 - p) + 1));
strlcpy(szTemp, p, std::min<size_t>(sizeof(szTemp), (p2 - p) + 1));
p = p2 + 1;
switch (j)
@ -69,7 +69,7 @@ bool ITEM_MANAGER::ReadCommonDropItemFile(const char * c_pszFileName)
case 1: str_to_number(d[i].iLvStart, szTemp); break;
case 2: str_to_number(d[i].iLvEnd, szTemp); break;
case 3: d[i].fPercent = atof(szTemp); break;
case 4: strncpy(d[i].szItemName, szTemp, sizeof(d[i].szItemName)); break;
case 4: strlcpy(d[i].szItemName, szTemp, sizeof(d[i].szItemName)); break;
case 5: str_to_number(d[i].iCount, szTemp); break;
}
}
@ -451,7 +451,7 @@ bool ITEM_MANAGER::ReadEtcDropItemFile(const char * c_pszFileName)
char szItemName[256];
float fProb = 0.0f;
strncpy(szItemName, buf, sizeof(szItemName));
strlcpy(szItemName, buf, sizeof(szItemName));
char * cpTab = strrchr(szItemName, '\t');
if (!cpTab)
@ -610,7 +610,7 @@ bool ITEM_MANAGER::ReadMonsterDropItemGroup(const char * c_pszFileName)
int iRarePct = 0;
str_to_number(iRarePct, pTok->at(3).c_str());
iRarePct = MINMAX(0, iRarePct, 100);
iRarePct = std::clamp(iRarePct, 0, 100);
sys_log(0," %s count %d rare %d", name.c_str(), iCount, iRarePct);
pkGroup->AddItem(dwVnum, iCount, iPartPct, iRarePct);
@ -626,7 +626,7 @@ bool ITEM_MANAGER::ReadMonsterDropItemGroup(const char * c_pszFileName)
{
CDropItemGroup* pkGroup;
bool bNew = true;
itertype(m_map_pkDropItemGroup) it = m_map_pkDropItemGroup.find (iMobVnum);
auto it = m_map_pkDropItemGroup.find(iMobVnum);
if (it == m_map_pkDropItemGroup.end())
{
pkGroup = M2_NEW CDropItemGroup(0, iMobVnum, stName);
@ -634,7 +634,7 @@ bool ITEM_MANAGER::ReadMonsterDropItemGroup(const char * c_pszFileName)
else
{
bNew = false;
CDropItemGroup* pkGroup = it->second;
pkGroup = it->second;
}
for (int k = 1; k < 256; ++k)

View File

@ -30,7 +30,7 @@ const char * locale_find(const char *string)
if( iter == localeString.end() )
{
static char s_line[1024] = "@0949";
strncpy(s_line + 5, string, sizeof(s_line) - 5);
strlcpy(s_line + 5, string, sizeof(s_line) - 5);
sys_err("LOCALE_ERROR: \"%s\";", string);
return s_line;

View File

@ -427,14 +427,14 @@ static void __LocaleService_Init_JAPAN()
static void __LocaleService_Init_English()
{
g_stLocale = "";
g_stLocale = "latin1";
g_stServiceBasePath = "locale/english";
g_stQuestDir = "locale/english/quest";
g_stServiceMapPath = "locale/english/map";
g_setQuestObjectDir.clear();
g_setQuestObjectDir.insert("locale/english/quest/object");
g_stLocaleFilename = "locale/english/eng_string.txt";
g_stLocaleFilename = "locale/english/locale_string.txt";
g_iUseLocale = true;
check_name = check_name_alphabet;
@ -1300,6 +1300,7 @@ bool LC_IsEurope()
switch ((int) val)
{
case LC_ENGLISH:
case LC_GERMANY:
case LC_FRANCE:
case LC_ITALY:

View File

@ -81,7 +81,7 @@ DWORD CLoginData::GetLogonTime()
void CLoginData::SetIP(const char * c_pszIP)
{
strncpy(m_szIP, c_pszIP, sizeof(m_szIP));
strlcpy(m_szIP, c_pszIP, sizeof(m_szIP));
}
const char * CLoginData::GetIP()

View File

@ -166,11 +166,11 @@ void ShutdownOnFatalError()
{
char buf[256];
strncpy(buf, LC_TEXT("서버에 치명적인 오류가 발생하여 자동으로 재부팅됩니다."), sizeof(buf));
strlcpy(buf, LC_TEXT("서버에 치명적인 오류가 발생하여 자동으로 재부팅됩니다."), sizeof(buf));
SendNotice(buf);
strncpy(buf, LC_TEXT("10초후 자동으로 접속이 종료되며,"), sizeof(buf));
strlcpy(buf, LC_TEXT("10초후 자동으로 접속이 종료되며,"), sizeof(buf));
SendNotice(buf);
strncpy(buf, LC_TEXT("5분 후에 정상적으로 접속하실수 있습니다."), sizeof(buf));
strlcpy(buf, LC_TEXT("5분 후에 정상적으로 접속하실수 있습니다."), sizeof(buf));
SendNotice(buf);
}
@ -268,7 +268,7 @@ void heartbeat(LPHEART ht, int pulse)
if (save_idx < g_vec_save.size())
{
count = MIN(100, g_vec_save.size() - save_idx);
count = std::min<int>(100, g_vec_save.size() - save_idx);
for (int i = 0; i < count; ++i, ++save_idx)
db_clientdesc->DBPacket(HEADER_GD_PLAYER_SAVE, 0, &g_vec_save[save_idx], sizeof(TPlayerTable));
@ -523,7 +523,7 @@ int start(int argc, char **argv)
switch (ch)
{
case 'I': // IP
strncpy(g_szPublicIP, optarg, sizeof(g_szPublicIP));
strlcpy(g_szPublicIP, optarg, sizeof(g_szPublicIP));
printf("IP %s\n", g_szPublicIP);

View File

@ -45,7 +45,7 @@ namespace marriage
TPacketGCLoverInfo p;
p.header = HEADER_GC_LOVER_INFO;
strncpy(p.name, lover_name.c_str(), sizeof(p.name));
strlcpy(p.name, lover_name.c_str(), sizeof(p.name));
p.love_point = love_point;
ch->GetDesc()->Packet(&p, sizeof(p));
}
@ -64,7 +64,7 @@ namespace marriage
int TMarriage::GetMarriageGrade()
{
int point = MINMAX(50, GetMarriagePoint(), 100);
int point = std::clamp(GetMarriagePoint(), 50, 100);
if (point < 65)
return 0;
else if (point < 80)
@ -80,7 +80,7 @@ namespace marriage
{
int value = quest::CQuestManager::instance().GetEventFlag("lovepoint");
if (value)
return MINMAX(0, value, 100);
return std::clamp(value, 0, 100);
}
int point_per_day = MARRIAGE_POINT_PER_DAY;
@ -112,7 +112,7 @@ namespace marriage
// 날짜에 의한 영향 60% 하루당 6%
// 전투에 의한 영향 60%
// 토탈 100%
return MIN(50 + MIN(days * point_per_day, max_limit) + MIN(love_point / 1000000, max_limit), 100);
return std::min(50 + std::min(days * point_per_day, max_limit) + std::min(love_point / 1000000, max_limit), 100);
}
bool TMarriage::IsNear()
@ -433,7 +433,7 @@ namespace marriage
bSave = true;
love_point += point;
love_point = MIN( love_point, 2000000000 );
love_point = std::min( love_point, 2000000000 );
if (test_server)
{
@ -552,8 +552,8 @@ namespace marriage
p.dwPID1 = dwPID1;
p.dwPID2 = dwPID2;
strncpy(p.szName1, szName1, sizeof(p.szName1));
strncpy(p.szName2, szName2, sizeof(p.szName2));
strlcpy(p.szName1, szName1, sizeof(p.szName1));
strlcpy(p.szName2, szName2, sizeof(p.szName2));
db_clientdesc->DBPacket(HEADER_GD_MARRIAGE_ADD, 0, &p, sizeof(p));
}

View File

@ -8,7 +8,6 @@
#include <time.h>
#include <unistd.h>
#define thecore_random random
#define sys_err printf
#define sys_log printf
@ -42,7 +41,7 @@ bool EncodeMatrix(const char* szsrc, const char* szpwd, char* lpdes, const unsig
char dc = sc ^ pc;
char szhex[3];
snprintf(szhex, sizeof(szhex), "%02X", dc);
strncat(lpdes, szhex, usize);
strlcat(lpdes, szhex, usize);
}
return (i == nlen) ? true : false;
@ -76,10 +75,10 @@ bool DecodeMatrix(const char* szsrc, const char* szpwd, char* lpdes, const unsig
void MatrixCardRndCoordinate(unsigned int & rows, unsigned int & cols)
{
for (register unsigned int i = 0; i < (ASLENGTH >> 1); i++)
for (unsigned int i = 0; i < (ASLENGTH >> 1); i++)
{
rows |= ((thecore_random() % MAX_ROWS) & 0x000000FF) << ((4 - i - 1) * 8);
cols |= ((thecore_random() % MAX_COLS) & 0x000000FF) << ((4 - i - 1) * 8);
rows |= ((Random::get(0, MAX_ROWS - 1)) & 0x000000FF) << ((4 - i - 1) * 8);
cols |= ((Random::get(0, MAX_COLS - 1)) & 0x000000FF) << ((4 - i - 1) * 8);
}
}
@ -99,7 +98,7 @@ bool ChkCoordinate(const unsigned int rows, const unsigned int cols, const char*
unsigned short * pmatrix = (unsigned short *)matrix;
unsigned short * panswer = (unsigned short *)answer;
for (register unsigned int i = 0; i < (ASLENGTH >> 1); i++)
for (unsigned int i = 0; i < (ASLENGTH >> 1); i++)
{
if (*(pmatrix + (ROW(rows, i) * MAX_COLS + COL(cols, i))) != *(panswer + i))
{
@ -144,11 +143,11 @@ void GetRightAnswer(const unsigned int rows, const unsigned int cols, const char
memset(answer, 0, nsize);
for (register unsigned int i = 0; i < (ASLENGTH >> 1); i++)
for (unsigned int i = 0; i < (ASLENGTH >> 1); i++)
{
char sztemp[3] = { 0, 0, 0 };
memcpy(sztemp, (char*)(pmatrix + (ROW(rows, i) * MAX_COLS + COL(cols, i))), 2);
strncat(answer, sztemp, nsize);
strlcat(answer, sztemp, nsize);
}
}

View File

@ -200,8 +200,8 @@ void MessengerManager::AddToList(MessengerManager::keyA account, MessengerManage
TPacketGGMessenger p2ppck;
p2ppck.bHeader = HEADER_GG_MESSENGER_ADD;
strncpy(p2ppck.szAccount, account.c_str(), sizeof(p2ppck.szAccount));
strncpy(p2ppck.szCompanion, companion.c_str(), sizeof(p2ppck.szCompanion));
strlcpy(p2ppck.szAccount, account.c_str(), sizeof(p2ppck.szAccount));
strlcpy(p2ppck.szCompanion, companion.c_str(), sizeof(p2ppck.szCompanion));
P2P_MANAGER::instance().Send(&p2ppck, sizeof(TPacketGGMessenger));
}
@ -231,8 +231,8 @@ void MessengerManager::RemoveFromList(MessengerManager::keyA account, MessengerM
TPacketGGMessenger p2ppck;
p2ppck.bHeader = HEADER_GG_MESSENGER_REMOVE;
strncpy(p2ppck.szAccount, account.c_str(), sizeof(p2ppck.szAccount));
strncpy(p2ppck.szCompanion, companion.c_str(), sizeof(p2ppck.szCompanion));
strlcpy(p2ppck.szAccount, account.c_str(), sizeof(p2ppck.szAccount));
strlcpy(p2ppck.szCompanion, companion.c_str(), sizeof(p2ppck.szCompanion));
P2P_MANAGER::instance().Send(&p2ppck, sizeof(TPacketGGMessenger));
}

View File

@ -103,12 +103,12 @@ namespace mining
int GetFractionCount()
{
int r = number(1, 100);
int r = Random::get(1, 100);
for (int i = 0; i < MAX_FRACTION_COUNT; ++i)
{
if (r <= fraction_info[i][0])
return number(fraction_info[i][1], fraction_info[i][2]);
return Random::get(fraction_info[i][1], fraction_info[i][2]);
else
r -= fraction_info[i][0];
}
@ -137,8 +137,8 @@ namespace mining
}
PIXEL_POSITION pos;
pos.x = ch->GetX() + number(-200, 200);
pos.y = ch->GetY() + number(-200, 200);
pos.x = ch->GetX() + Random::get(-200, 200);
pos.y = ch->GetY() + Random::get(-200, 200);
item->AddToGround(ch->GetMapIndex(), pos);
item->StartDestroyEvent();
@ -157,7 +157,7 @@ namespace mining
if (!pick || pick->GetType() != ITEM_PICK)
return 0;
return defaultPct + SkillLevelAddPct[MINMAX(0, iSkillLevel, 40)] + PickGradeAddPct[MINMAX(0, pick->GetRefineLevel(), 9)];
return defaultPct + SkillLevelAddPct[std::clamp(iSkillLevel, 0, 40)] + PickGradeAddPct[std::clamp(pick->GetRefineLevel(), 0, 9)];
}
EVENTINFO(mining_event_info)
@ -213,12 +213,12 @@ namespace mining
bool Pick_IsPracticeSuccess(CItem& pick)
{
return (number(1,pick.GetValue(1))==1);
return (Random::get(1,pick.GetValue(1))==1);
}
bool Pick_IsRefineSuccess(CItem& pick)
{
return (number(1,100) <= pick.GetValue(3));
return (Random::get(1,100) <= pick.GetValue(3));
}
int RealRefinePick(LPCHARACTER ch, LPITEM item)
@ -368,7 +368,7 @@ namespace mining
int iPct = GetOrePct(ch);
if (number(1, 100) <= iPct)
if (Random::get(1, 100) <= iPct)
{
OreDrop(ch, load->GetRaceNum());
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("䱤¿¡ ¼º°øÇÏ¿´½À´Ï´Ù."));
@ -426,7 +426,7 @@ namespace mining
if (metinstone_item)
ITEM_MANAGER::instance().RemoveItem(metinstone_item, "REMOVE (MELT)");
if (number(1, 100) <= pct)
if (Random::get(1, 100) <= pct)
{
ch->AutoGiveItem(dwRefinedVnum, 1);
return true;

View File

@ -74,7 +74,7 @@ class CMobGroupGroup
return 0;
// ADD_MOB_GROUP_GROUP_PROB
int n = number(1, m_vec_iProbs.back());
int n = Random::get(1, m_vec_iProbs.back());
itertype(m_vec_iProbs) it = lower_bound(m_vec_iProbs.begin(), m_vec_iProbs.end(), n);
return m_vec_dwMemberVnum[std::distance(m_vec_iProbs.begin(), it)];

View File

@ -41,7 +41,7 @@ void P2P_MANAGER::Boot(LPDESC d)
it++;
p.bHeader = HEADER_GG_LOGIN;
strncpy(p.szName, ch->GetName(), sizeof(p.szName));
strlcpy(p.szName, ch->GetName(), sizeof(p.szName));
p.dwPID = ch->GetPlayerID();
p.bEmpire = ch->GetEmpire();
p.lMapIndex = SECTREE_MANAGER::instance().GetMapIndex(ch->GetX(), ch->GetY());
@ -142,7 +142,7 @@ void P2P_MANAGER::Login(LPDESC d, const TPacketGGLogin * p)
pkCCI = M2_NEW CCI;
if (false == LC_IsBrazil())
strncpy(pkCCI->szName, p->szName, sizeof(pkCCI->szName));
strlcpy(pkCCI->szName, p->szName, sizeof(pkCCI->szName));
else
trim_and_lower(p->szName, pkCCI->szName, sizeof(pkCCI->szName));

View File

@ -77,7 +77,7 @@ void SendPanamaList(LPDESC d)
while (it != s_panamaVector.end())
{
strncpy(pack.szPackName, it->first.c_str(), sizeof(pack.szPackName));
strlcpy(pack.szPackName, it->first.c_str(), sizeof(pack.szPackName));
memcpy(pack.abIV, it->second, sizeof(pack.abIV));

View File

@ -689,7 +689,7 @@ void CParty::SendPartyJoinOneToAll(DWORD pid)
p.header = HEADER_GC_PARTY_ADD;
p.pid = pid;
strncpy(p.name, r.strName.c_str(), sizeof(p.name));
strlcpy(p.name, r.strName.c_str(), sizeof(p.name));
for (TMemberMap::iterator it = m_memberMap.begin(); it != m_memberMap.end(); ++it)
{
@ -711,7 +711,7 @@ void CParty::SendPartyJoinAllToOne(LPCHARACTER ch)
for (TMemberMap::iterator it = m_memberMap.begin();it!= m_memberMap.end(); ++it)
{
p.pid = it->first;
strncpy(p.name, it->second.strName.c_str(), sizeof(p.name));
strlcpy(p.name, it->second.strName.c_str(), sizeof(p.name));
ch->GetDesc()->Packet(&p, sizeof(p));
}
}
@ -883,8 +883,8 @@ void CParty::SendMessage(LPCHARACTER ch, BYTE bMsg, DWORD dwArg1, DWORD dwArg2)
if ((pkChr = rMember.pCharacter) && ch != pkChr)
{
DWORD x = dwArg1 + number(-500, 500);
DWORD y = dwArg2 + number(-500, 500);
DWORD x = dwArg1 + Random::get(-500, 500);
DWORD y = dwArg2 + Random::get(-500, 500);
pkChr->SetVictim(NULL);
pkChr->SetRotationToXY(x, y);
@ -1157,7 +1157,7 @@ void CParty::SummonToLeader(DWORD pid)
l->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 파티원을 현재 위치로 소환할 수 없습니다."));
else
{
int i = number(0, n - 1);
int i = Random::get(0, n - 1);
ch->Show(l->GetMapIndex(), x[i], y[i]);
ch->Stop();
}
@ -1220,8 +1220,8 @@ void CParty::ComputeRolePoint(LPCHARACTER ch, BYTE bRole, bool bAdd)
}
//SKILL_POWER_BY_LEVEL
float k = (float) ch->GetSkillPowerByLevel( MIN(SKILL_MAX_LEVEL, m_iLeadership ) )/ 100.0f;
//float k = (float) aiSkillPowerByLevel[MIN(SKILL_MAX_LEVEL, m_iLeadership)] / 100.0f;
float k = (float) ch->GetSkillPowerByLevel(std::min<int>(SKILL_MAX_LEVEL, m_iLeadership)) / 100.0f;
//float k = (float) aiSkillPowerByLevel[std::min<int>(SKILL_MAX_LEVEL, m_iLeadership)] / 100.0f;
//
//sys_log(0,"ComputeRolePoint %fi %d, %d ", k, SKILL_MAX_LEVEL, m_iLeadership );
//END_SKILL_POWER_BY_LEVEL
@ -1441,7 +1441,7 @@ void CParty::UpdateOnlineState(DWORD dwPID, const char* name)
p.header = HEADER_GC_PARTY_ADD;
p.pid = dwPID;
r.strName = name;
strncpy(p.name, name, sizeof(p.name));
strlcpy(p.name, name, sizeof(p.name));
for (TMemberMap::iterator it = m_memberMap.begin(); it != m_memberMap.end(); ++it)
{
@ -1646,7 +1646,7 @@ BYTE CParty::GetMemberMaxLevel()
if (!bMax)
bMax = it->second.bLevel;
else if (it->second.bLevel)
bMax = MAX(bMax, it->second.bLevel);
bMax = std::max(bMax, it->second.bLevel);
++it;
}
return bMax;
@ -1668,7 +1668,7 @@ BYTE CParty::GetMemberMinLevel()
if (!bMin)
bMin = it->second.bLevel;
else if (it->second.bLevel)
bMin = MIN(bMin, it->second.bLevel);
bMin = std::min(bMin, it->second.bLevel);
++it;
}
return bMin;
@ -1684,7 +1684,7 @@ int CParty::ComputePartyBonusExpPercent()
int iBonusPartyExpFromItem = 0;
// UPGRADE_PARTY_BONUS
int iMemberCount=MIN(8, GetNearMemberCount());
int iMemberCount = std::min<int>(8, GetNearMemberCount());
if (leader && (leader->IsEquipUniqueItem(UNIQUE_ITEM_PARTY_BONUS_EXP) || leader->IsEquipUniqueItem(UNIQUE_ITEM_PARTY_BONUS_EXP_MALL)
|| leader->IsEquipUniqueItem(UNIQUE_ITEM_PARTY_BONUS_EXP_GIFT) || leader->IsEquipUniqueGroup(10010)))

View File

@ -74,7 +74,7 @@ bool CPolymorphUtils::PolymorphCharacter(LPCHARACTER pChar, LPITEM pItem, const
}
else
{
if (number(1, 100) > iPolyPercent)
if (Random::get(1, 100) > iPolyPercent)
{
pChar->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("둔갑에 실패 하였습니다"));
return false;

View File

@ -32,8 +32,8 @@ void CPrivManager::RequestGiveGuildPriv(DWORD guild_id, BYTE type, int value, ti
return;
}
value = MINMAX(0, value, 50);
duration_sec = MINMAX(0, duration_sec, 60*60*24*7);
value = std::clamp(value, 0, 50);
duration_sec = std::clamp<time_t>(duration_sec, 0, 60*60*24*7);
TPacketGiveGuildPriv p;
p.type = type;
@ -52,8 +52,8 @@ void CPrivManager::RequestGiveEmpirePriv(BYTE empire, BYTE type, int value, time
return;
}
value = MINMAX(0, value, 200);
duration_sec = MINMAX(0, duration_sec, 60*60*24*7);
value = std::clamp(value, 0, 200);
duration_sec = std::clamp<time_t>(duration_sec, 0, 60*60*24*7);
TPacketGiveEmpirePriv p;
p.type = type;
@ -72,7 +72,7 @@ void CPrivManager::RequestGiveCharacterPriv(DWORD pid, BYTE type, int value)
return;
}
value = MINMAX(0, value, 100);
value = std::clamp(value, 0, 100);
TPacketGiveCharacterPriv p;
p.type = type;
@ -92,8 +92,8 @@ void CPrivManager::GiveGuildPriv(DWORD guild_id, BYTE type, int value, BYTE bLog
sys_log(0,"Set Guild Priv: guild_id(%u) type(%d) value(%d) duration_sec(%d)", guild_id, type, value, end_time_sec - get_global_time());
value = MINMAX(0, value, 50);
end_time_sec = MINMAX(0, end_time_sec, get_global_time()+60*60*24*7);
value = std::clamp(value, 0, 50);
end_time_sec = std::clamp<time_t>(end_time_sec, 0, get_global_time()+60*60*24*7);
m_aPrivGuild[type][guild_id].value = value;
m_aPrivGuild[type][guild_id].end_time_sec = end_time_sec;
@ -132,7 +132,7 @@ void CPrivManager::GiveCharacterPriv(DWORD pid, BYTE type, int value, BYTE bLog)
sys_log(0,"Set Character Priv %u %d %d", pid, type, value);
value = MINMAX(0, value, 100);
value = std::clamp(value, 0, 100);
m_aPrivChar[type][pid] = value;
@ -150,8 +150,8 @@ void CPrivManager::GiveEmpirePriv(BYTE empire, BYTE type, int value, BYTE bLog,
sys_log(0, "Set Empire Priv: empire(%d) type(%d) value(%d) duration_sec(%d)", empire, type, value, end_time_sec-get_global_time());
value = MINMAX(0, value, 200);
end_time_sec = MINMAX(0, end_time_sec, get_global_time()+60*60*24*7);
value = std::clamp(value, 0, 200);
end_time_sec = std::clamp<time_t>(end_time_sec, 0, get_global_time()+60*60*24*7);
SPrivEmpireData& rkPrivEmpireData=m_aakPrivEmpireData[type][empire];
rkPrivEmpireData.m_value = value;
@ -235,11 +235,11 @@ int CPrivManager::GetPriv(LPCHARACTER ch, BYTE type)
int val;
// 개인, 제국, 길드, 전체 중 큰 값을 취한다.
val = MAX(val_ch, GetPrivByEmpire(0, type));
val = MAX(val, GetPrivByEmpire(ch->GetEmpire(), type));
val = std::max(val_ch, GetPrivByEmpire(0, type));
val = std::max(val, GetPrivByEmpire(ch->GetEmpire(), type));
if (ch->GetGuild())
val = MAX(val, GetPrivByGuild(ch->GetGuild()->GetID(), type));
val = std::max(val, GetPrivByGuild(ch->GetGuild()->GetID(), type));
return val;
}

View File

@ -213,12 +213,12 @@ void CPVPManager::Insert(LPCHARACTER pkChr, LPCHARACTER pkVictim)
{
TPacketGCWhisper pack;
int len = MIN(CHAT_MAX_LEN, strlen(msg) + 1);
int len = std::min<int>(CHAT_MAX_LEN, strlen(msg) + 1);
pack.bHeader = HEADER_GC_WHISPER;
pack.wSize = sizeof(TPacketGCWhisper) + len;
pack.bType = WHISPER_TYPE_SYSTEM;
strncpy(pack.szNameFrom, pkChr->GetName(), sizeof(pack.szNameFrom));
strlcpy(pack.szNameFrom, pkChr->GetName(), sizeof(pack.szNameFrom));
TEMP_BUFFER buf;

View File

@ -97,7 +97,7 @@ END_OF_TIMER_EVENT:
info->name = M2_NEW char[nameCapacity];
if (info->name)
strncpy(info->name, name, nameCapacity);
strlcpy(info->name, name, nameCapacity);
return event_create(quest_server_timer_event, info, ltime_cycle);
}
@ -115,7 +115,7 @@ END_OF_TIMER_EVENT:
info->name = M2_NEW char[nameCapacity];
if (info->name)
strncpy(info->name, name, nameCapacity);
strlcpy(info->name, name, nameCapacity);
sys_log(0, "QUEST timer name %s cycle %d pc %u npc %u loop? %d", name ? name : "<noname>", ltime_cycle, player_id, npc_id, loop ? 1 : 0);

View File

@ -226,7 +226,7 @@ namespace quest
THighscoreRegisterQueryInfo * qi = M2_NEW THighscoreRegisterQueryInfo;
strncpy(qi->szBoard, lua_tostring(L, 1), sizeof(qi->szBoard));
strlcpy(qi->szBoard, lua_tostring(L, 1), sizeof(qi->szBoard));
qi->dwPID = q.GetCurrentCharacterPtr()->GetPlayerID();
qi->iValue = (int) lua_tonumber(L, 2);
qi->bOrder = (int) lua_tonumber(L, 3);
@ -298,8 +298,8 @@ namespace quest
{
for (int loop = 0; loop < 8; ++loop)
{
float angle = number(0, 999) * M_PI * 2 / 1000;
float r = number(0, 999) * radius / 1000;
float angle = Random::get(0, 999) * M_PI * 2 / 1000;
float r = Random::get(0, 999) * radius / 1000;
int x = local_x + pMap->m_setting.iBaseX + (int)(r * cos(angle));
int y = local_y + pMap->m_setting.iBaseY + (int)(r * sin(angle));
@ -370,8 +370,8 @@ namespace quest
{
for (int loop = 0; loop < 8; ++loop)
{
float angle = number(0, 999) * M_PI * 2 / 1000;
float r = number(0, 999)*radius/1000;
float angle = Random::get(0, 999) * M_PI * 2 / 1000;
float r = Random::get(0, 999)*radius/1000;
int x = local_x + pMap->m_setting.iBaseX + (int)(r * cos(angle));
int y = local_y + pMap->m_setting.iBaseY + (int)(r * sin(angle));

View File

@ -834,8 +834,8 @@ namespace quest
}
else
{
float angle = number(0, 999) * M_PI * 2 / 1000;
float r = number(0, 999) * radius / 1000;
float angle = Random::get(0, 999) * M_PI * 2 / 1000;
float r = Random::get(0, 999) * radius / 1000;
int nx = x + (int)(r * cos(angle));
int ny = y + (int)(r * sin(angle));

View File

@ -153,7 +153,7 @@ namespace quest
LPCHARACTER ch = (LPCHARACTER) ent;
if (ch->IsPC())
{
ch->WarpSet( m_x+(number(0,5)*100), m_y+(number(0,5)*100), m_iMapIndexTo);
ch->WarpSet( m_x+(Random::get(0,5)*100), m_y+(Random::get(0,5)*100), m_iMapIndexTo);
}
}
}

View File

@ -113,8 +113,8 @@ namespace quest
}
PIXEL_POSITION pos;
pos.x = x + number(-200, 200);
pos.y = y + number(-200, 200);
pos.x = x + Random::get(-200, 200);
pos.y = y + Random::get(-200, 200);
item->AddToGround(ch->GetMapIndex(), pos);
item->StartDestroyEvent();
@ -161,8 +161,8 @@ namespace quest
item->SetOwnership( ch );
PIXEL_POSITION pos;
pos.x = ch->GetX() + number(-200, 200);
pos.y = ch->GetY() + number(-200, 200);
pos.x = ch->GetX() + Random::get(-200, 200);
pos.y = ch->GetY() + Random::get(-200, 200);
item->AddToGround(ch->GetMapIndex(), pos);
item->StartDestroyEvent();

View File

@ -47,7 +47,7 @@ namespace quest
if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2))
lua_pushnumber(L, 0);
else
lua_pushnumber(L, number((int)lua_tonumber(L, 1), (int)lua_tonumber(L, 2)));
lua_pushnumber(L, Random::get((int)lua_tonumber(L, 1), (int)lua_tonumber(L, 2)));
return 1;
}
@ -1133,7 +1133,7 @@ namespace quest
}
const DWORD dwVnum = static_cast<DWORD>(lua_tonumber(L, 1));
const size_t count = MINMAX(1, static_cast<size_t>(lua_tonumber(L, 2)), 10);
const size_t count = std::clamp<size_t>(static_cast<size_t>(lua_tonumber(L, 2)), 1, 10);
const bool isAggresive = static_cast<bool>(lua_toboolean(L, 3));
size_t SpawnCount = 0;
@ -1147,10 +1147,10 @@ namespace quest
{
const LPCHARACTER pSpawnMonster = CHARACTER_MANAGER::instance().SpawnMobRange( dwVnum,
pChar->GetMapIndex(),
pChar->GetX() - number(200, 750),
pChar->GetY() - number(200, 750),
pChar->GetX() + number(200, 750),
pChar->GetY() + number(200, 750),
pChar->GetX() - Random::get(200, 750),
pChar->GetY() - Random::get(200, 750),
pChar->GetX() + Random::get(200, 750),
pChar->GetY() + Random::get(200, 750),
true,
pMonster->m_table.bType == CHAR_TYPE_STONE,
isAggresive );
@ -1269,7 +1269,7 @@ namespace quest
{
++warpCount;
pChar->WarpSet( number(to_x1, to_x2), number(to_y1, to_y2) );
pChar->WarpSet( Random::get(to_x1, to_x2), Random::get(to_y1, to_y2) );
}
}
}

View File

@ -191,7 +191,7 @@ namespace quest
TPacketGDGuildWarBet p;
p.dwWarID = (DWORD) lua_tonumber(L, 1);
strncpy(p.szLogin, ch->GetDesc()->GetAccountTable().login, sizeof(p.szLogin));
strlcpy(p.szLogin, ch->GetDesc()->GetAccountTable().login, sizeof(p.szLogin));
p.dwGuild = (DWORD) lua_tonumber(L, 2);
p.dwGold = (DWORD) lua_tonumber(L, 3);

View File

@ -102,7 +102,7 @@ namespace quest
if (!lua_isnumber(L, 1))
return 0;
int newlevel = MINMAX(0, (int)lua_tonumber(L, 1), HORSE_MAX_LEVEL);
int newlevel = std::clamp((int)lua_tonumber(L, 1), 0, HORSE_MAX_LEVEL);
ch->SetHorseLevel(newlevel);
ch->ComputePoints();
ch->SkillLevelPacket();
@ -145,7 +145,7 @@ namespace quest
{
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
int pct = MINMAX(0, ch->GetHorseHealth() * 100 / ch->GetHorseMaxHealth(), 100);
int pct = std::clamp(ch->GetHorseHealth() * 100 / ch->GetHorseMaxHealth(), 0, 100);
sys_log(1, "horse.get_health_pct %d", pct);
if (ch->GetHorseLevel())
@ -171,7 +171,7 @@ namespace quest
int horse_get_stamina_pct(lua_State* L)
{
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
int pct = MINMAX(0, ch->GetHorseStamina() * 100 / ch->GetHorseMaxStamina(), 100);
int pct = std::clamp(ch->GetHorseStamina() * 100 / ch->GetHorseMaxStamina(), 0, 100);
sys_log(1, "horse.get_stamina_pct %d", pct);
if (ch->GetHorseLevel())

View File

@ -706,7 +706,7 @@ namespace quest
TPacketGGTransfer pgg;
pgg.bHeader = HEADER_GG_TRANSFER;
strncpy(pgg.szName, name.c_str(), sizeof(pgg.szName));
strlcpy(pgg.szName, name.c_str(), sizeof(pgg.szName));
pgg.lX = ch->GetX();
pgg.lY = ch->GetY();
@ -793,7 +793,7 @@ namespace quest
return 0;
char vnum[256];
strncpy(vnum, lua_tostring(L, 1), sizeof(vnum));
strlcpy(vnum, lua_tostring(L, 1), sizeof(vnum));
do_monarch_mob(ch, vnum, 0, 0);
return 0;
}

View File

@ -77,7 +77,7 @@ namespace quest
lua_pushnumber(L, 0);
return 1;
}
lua_pushnumber(L, MAX(0, npc->GetPoint(POINT_ATT_GRADE_BONUS)));
lua_pushnumber(L, std::max(0, npc->GetPoint(POINT_ATT_GRADE_BONUS)));
return 1;
}
@ -88,7 +88,7 @@ namespace quest
{
return 0;
}
npc->SetPoint(POINT_ATT_GRADE_BONUS, MAX(0, npc->GetPoint(POINT_ATT_GRADE_BONUS)-1));
npc->SetPoint(POINT_ATT_GRADE_BONUS, std::max(0, npc->GetPoint(POINT_ATT_GRADE_BONUS)-1));
return 0;
}
@ -100,7 +100,7 @@ namespace quest
lua_pushnumber(L, 0);
return 1;
}
lua_pushnumber(L, MAX(0, npc->GetPoint(POINT_DEF_GRADE_BONUS)));
lua_pushnumber(L, std::max(0, npc->GetPoint(POINT_DEF_GRADE_BONUS)));
return 1;
}
@ -111,7 +111,7 @@ namespace quest
{
return 0;
}
npc->SetPoint(POINT_DEF_GRADE_BONUS, MAX(0, npc->GetPoint(POINT_DEF_GRADE_BONUS)-1));
npc->SetPoint(POINT_DEF_GRADE_BONUS, std::max(0, npc->GetPoint(POINT_DEF_GRADE_BONUS)-1));
return 0;
}

View File

@ -865,13 +865,13 @@ namespace quest
//포인트 : 스킬, 서브스킬, 스탯
ch->PointChange(POINT_SKILL, newLevel - ch->GetLevel());
ch->PointChange(POINT_SUB_SKILL, newLevel < 10 ? 0 : newLevel - MAX(ch->GetLevel(), 9));
ch->PointChange(POINT_STAT, ((MINMAX(1, newLevel, 90) - ch->GetLevel()) * 3) + ch->GetPoint(POINT_LEVEL_STEP));
ch->PointChange(POINT_SUB_SKILL, newLevel < 10 ? 0 : newLevel - std::max(ch->GetLevel(), 9));
ch->PointChange(POINT_STAT, ((std::clamp(newLevel, 1, 90) - ch->GetLevel()) * 3) + ch->GetPoint(POINT_LEVEL_STEP));
//레벨
ch->PointChange(POINT_LEVEL, newLevel - ch->GetLevel());
//HP, SP
ch->SetRandomHP((newLevel - 1) * number(JobInitialPoints[ch->GetJob()].hp_per_lv_begin, JobInitialPoints[ch->GetJob()].hp_per_lv_end));
ch->SetRandomSP((newLevel - 1) * number(JobInitialPoints[ch->GetJob()].sp_per_lv_begin, JobInitialPoints[ch->GetJob()].sp_per_lv_end));
ch->SetRandomHP((newLevel - 1) * Random::get(JobInitialPoints[ch->GetJob()].hp_per_lv_begin, JobInitialPoints[ch->GetJob()].hp_per_lv_end));
ch->SetRandomSP((newLevel - 1) * Random::get(JobInitialPoints[ch->GetJob()].sp_per_lv_begin, JobInitialPoints[ch->GetJob()].sp_per_lv_end));
// 회복
@ -1149,7 +1149,7 @@ namespace quest
sys_log(0, "QUEST [REWARD] %s give exp %s lev %d percent %g%%", ch->GetName(), lua_tostring(L, 1), lev, proc);
DWORD exp = (DWORD)((exp_table[MINMAX(0, lev, PLAYER_EXP_TABLE_MAX)] * proc) / 100);
DWORD exp = (DWORD)((exp_table[std::clamp<int>(lev, 0, PLAYER_EXP_TABLE_MAX)] * proc) / 100);
PC * pPC = CQuestManager::instance().GetCurrentPC();
LogManager::instance().QuestRewardLog(pPC->GetCurrentQuestName().c_str(), ch->GetPlayerID(), ch->GetLevel(), exp, 0);
@ -1530,7 +1530,7 @@ namespace quest
return 1;
}
if (pct == 100 || number(1, 100) <= pct)
if (pct == 100 || Random::get(1, 100) <= pct)
{
// 개량 성공
lua_pushboolean(L, 1);
@ -2183,12 +2183,12 @@ teleport_area:
if ( point == POINT_HT )
{
BYTE job = ch->GetJob();
ch->SetRandomHP((ch->GetLevel()-1) * number(JobInitialPoints[job].hp_per_lv_begin, JobInitialPoints[job].hp_per_lv_end));
ch->SetRandomHP((ch->GetLevel()-1) * Random::get(JobInitialPoints[job].hp_per_lv_begin, JobInitialPoints[job].hp_per_lv_end));
}
else if ( point == POINT_IQ )
{
BYTE job = ch->GetJob();
ch->SetRandomSP((ch->GetLevel()-1) * number(JobInitialPoints[job].sp_per_lv_begin, JobInitialPoints[job].sp_per_lv_end));
ch->SetRandomSP((ch->GetLevel()-1) * Random::get(JobInitialPoints[job].sp_per_lv_begin, JobInitialPoints[job].sp_per_lv_end));
}
ch->ComputePoints();

Some files were not shown because too many files have changed in this diff Show More