mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-12-23 03:40:05 +00:00
Basic Anti rapidfire
This commit is contained in:
parent
6baa0c5b07
commit
ddc7caf959
@ -33,9 +33,6 @@ void GroupManager::requestGroup(CNSocket* sock, CNPacketData* data) {
|
||||
|
||||
otherPlr = PlayerManager::getPlayerFromID(otherPlr->iIDGroup);
|
||||
|
||||
if (otherPlr == nullptr)
|
||||
return;
|
||||
|
||||
if (otherPlr == nullptr)
|
||||
return;
|
||||
|
||||
|
@ -1074,6 +1074,7 @@ void ItemManager::setItemStats(Player* plr) {
|
||||
|
||||
plr->pointDamage = 8 + plr->level * 2;
|
||||
plr->groupDamage = 8 + plr->level * 2;
|
||||
plr->fireRate = 0;
|
||||
plr->defense = 16 + plr->level * 4;
|
||||
|
||||
Item* itemStatsDat;
|
||||
@ -1086,6 +1087,7 @@ void ItemManager::setItemStats(Player* plr) {
|
||||
}
|
||||
plr->pointDamage += itemStatsDat->pointDamage;
|
||||
plr->groupDamage += itemStatsDat->groupDamage;
|
||||
plr->fireRate += itemStatsDat->fireRate;
|
||||
plr->defense += itemStatsDat->defense;
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ namespace ItemManager {
|
||||
};
|
||||
struct Item {
|
||||
bool tradeable, sellable;
|
||||
int buyPrice, sellPrice, stackSize, level, rarity, pointDamage, groupDamage, defense, gender; // TODO: implement more as needed
|
||||
int buyPrice, sellPrice, stackSize, level, rarity, pointDamage, groupDamage, fireRate, defense, gender; // TODO: implement more as needed
|
||||
};
|
||||
// hopefully this is fine since it's never modified after load
|
||||
extern std::map<std::pair<int32_t, int32_t>, Item> ItemData; // <id, type> -> data
|
||||
|
@ -62,6 +62,21 @@ void MobManager::pcAttackNpcs(CNSocket *sock, CNPacketData *data) {
|
||||
return;
|
||||
}
|
||||
|
||||
// rapid fire anti-cheat
|
||||
time_t currTime = getTime();
|
||||
if (currTime - plr->lastShot < plr->fireRate * 80)
|
||||
plr->suspicionRating += plr->fireRate * 100 + plr->lastShot - currTime; // gain suspicion for rapid firing
|
||||
else if (currTime - plr->lastShot < plr->fireRate * 180 && plr->suspicionRating > 0)
|
||||
plr->suspicionRating += plr->fireRate * 100 + plr->lastShot - currTime; // lose suspicion for delayed firing
|
||||
|
||||
plr->lastShot = currTime;
|
||||
|
||||
if (pkt->iNPCCnt > 3) // 3+ targets should never be possible
|
||||
plr->suspicionRating += 10000;
|
||||
|
||||
if (plr->suspicionRating > 10000) // kill the socket when the player is too suspicious
|
||||
sock->kill();
|
||||
|
||||
// initialize response struct
|
||||
size_t resplen = sizeof(sP_FE2CL_PC_ATTACK_NPCs_SUCC) + pkt->iNPCCnt * sizeof(sAttackResult);
|
||||
uint8_t respbuf[CN_PACKET_BUFFER_SIZE];
|
||||
@ -1389,6 +1404,18 @@ void MobManager::projectileHit(CNSocket* sock, CNPacketData* data) {
|
||||
return;
|
||||
}
|
||||
|
||||
// rapid fire anti-cheat
|
||||
time_t currTime = getTime();
|
||||
if (currTime - plr->lastShot < plr->fireRate * 80)
|
||||
plr->suspicionRating += plr->fireRate * 100 + plr->lastShot - currTime; // gain suspicion for rapid firing
|
||||
else if (currTime - plr->lastShot < plr->fireRate * 180 && plr->suspicionRating > 0)
|
||||
plr->suspicionRating += plr->fireRate * 100 + plr->lastShot - currTime; // lose suspicion for delayed firing
|
||||
|
||||
plr->lastShot = currTime;
|
||||
|
||||
if (plr->suspicionRating > 10000) // kill the socket when the player is too suspicious
|
||||
sock->kill();
|
||||
|
||||
/*
|
||||
* initialize response struct
|
||||
* rocket style hit doesn't work properly, so we're always sending this one
|
||||
|
@ -57,6 +57,7 @@ struct Player {
|
||||
|
||||
int pointDamage;
|
||||
int groupDamage;
|
||||
int fireRate;
|
||||
int defense;
|
||||
|
||||
int64_t aQuestFlag[16];
|
||||
@ -85,4 +86,7 @@ struct Player {
|
||||
ChunkPos chunkPos;
|
||||
std::set<Chunk*>* viewableChunks;
|
||||
time_t lastHeartbeat;
|
||||
|
||||
int suspicionRating;
|
||||
time_t lastShot;
|
||||
};
|
||||
|
@ -157,6 +157,7 @@ void TableData::init() {
|
||||
itemData.level = item["m_iMinReqLev"];
|
||||
itemData.pointDamage = item["m_iPointRat"];
|
||||
itemData.groupDamage = item["m_iGroupRat"];
|
||||
itemData.fireRate = item["m_iDelayTime"];
|
||||
itemData.defense = item["m_iDefenseRat"];
|
||||
itemData.gender = item["m_iReqSex"];
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user