mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 21:01:29 +00:00
[Bug Fix] Fix possible crash in ProcessSpecialAbilities. (#2630)
* [Bug Fix] Fix possible crash in ProcessSpecialAbilities. # Notes - Passing an invalid special ability along such as `4,1,,-1,100` currently causes a crash since every `,` assumes it's followed by a number. - Fixed by making sure first and second parameters are numbers and then when looping additional parameters we also check if they are numbers. * Update mob.cpp
This commit is contained in:
parent
d3fac8a0cb
commit
20efa83f73
55
zone/mob.cpp
55
zone/mob.cpp
@ -6283,37 +6283,44 @@ void Mob::ClearSpecialAbilities() {
|
||||
void Mob::ProcessSpecialAbilities(const std::string &str) {
|
||||
ClearSpecialAbilities();
|
||||
|
||||
std::vector<std::string> sp = Strings::Split(str, '^');
|
||||
for(auto iter = sp.begin(); iter != sp.end(); ++iter) {
|
||||
std::vector<std::string> sub_sp = Strings::Split((*iter), ',');
|
||||
if(sub_sp.size() >= 2) {
|
||||
int ability = std::stoi(sub_sp[0]);
|
||||
const auto& sp = Strings::Split(str, '^');
|
||||
for (const auto& s : sp) {
|
||||
const auto& sub_sp = Strings::Split(s, ',');
|
||||
if (
|
||||
sub_sp.size() >= 2 &&
|
||||
Strings::IsNumber(sub_sp[0]) &&
|
||||
Strings::IsNumber(sub_sp[1])
|
||||
) {
|
||||
int ability_id = std::stoi(sub_sp[0]);
|
||||
int value = std::stoi(sub_sp[1]);
|
||||
|
||||
SetSpecialAbility(ability, value);
|
||||
switch(ability) {
|
||||
case SPECATK_QUAD:
|
||||
if(value > 0) {
|
||||
SetSpecialAbility(SPECATK_TRIPLE, 1);
|
||||
}
|
||||
break;
|
||||
case DESTRUCTIBLE_OBJECT:
|
||||
if(value == 0) {
|
||||
SetDestructibleObject(false);
|
||||
} else {
|
||||
SetDestructibleObject(true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
SetSpecialAbility(ability_id, value);
|
||||
|
||||
switch (ability_id) {
|
||||
case SPECATK_QUAD:
|
||||
if (value > 0) {
|
||||
SetSpecialAbility(SPECATK_TRIPLE, 1);
|
||||
}
|
||||
break;
|
||||
case DESTRUCTIBLE_OBJECT:
|
||||
if (value == 0) {
|
||||
SetDestructibleObject(false);
|
||||
} else {
|
||||
SetDestructibleObject(true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for(size_t i = 2, p = 0; i < sub_sp.size(); ++i, ++p) {
|
||||
if(p >= MAX_SPECIAL_ATTACK_PARAMS) {
|
||||
for (size_t i = 2, param_id = 0; i < sub_sp.size(); ++i, ++param_id) {
|
||||
if (param_id >= MAX_SPECIAL_ATTACK_PARAMS) {
|
||||
break;
|
||||
}
|
||||
|
||||
SetSpecialAbilityParam(ability, p, std::stoi(sub_sp[i]));
|
||||
if (Strings::IsNumber(sub_sp[i])) {
|
||||
SetSpecialAbilityParam(ability_id, param_id, std::stoi(sub_sp[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user