mirror of
https://github.com/EQEmu/Server.git
synced 2026-09-03 09:26:36 +00:00
Rewrite VarCache_Struct
Basically just remove manual memory management
This commit is contained in:
+14
-15
@@ -687,25 +687,25 @@ void Mob::MeleeMitigation(Mob *attacker, int32 &damage, int32 minhit, ExtraAttac
|
||||
|
||||
if (damage > 0 && myac > 0) {
|
||||
int acfail=1000;
|
||||
char tmp[10];
|
||||
std::string tmp;
|
||||
|
||||
if (database.GetVariable("ACfail", tmp, 9)) {
|
||||
acfail = (int) (atof(tmp) * 100);
|
||||
if (database.GetVariable("ACfail", tmp)) {
|
||||
acfail = (int) (atof(tmp.c_str()) * 100);
|
||||
if (acfail>100) acfail=100;
|
||||
}
|
||||
|
||||
if (acfail<=0 || zone->random.Int(0, 100)>acfail) {
|
||||
float acreduction=1;
|
||||
int acrandom=300;
|
||||
if (database.GetVariable("ACreduction", tmp, 9))
|
||||
if (database.GetVariable("ACreduction", tmp))
|
||||
{
|
||||
acreduction=atof(tmp);
|
||||
acreduction=atof(tmp.c_str());
|
||||
if (acreduction>100) acreduction=100;
|
||||
}
|
||||
|
||||
if (database.GetVariable("ACrandom", tmp, 9))
|
||||
if (database.GetVariable("ACrandom", tmp))
|
||||
{
|
||||
acrandom = (int) ((atof(tmp)+1) * 100);
|
||||
acrandom = (int) ((atof(tmp.c_str())+1) * 100);
|
||||
if (acrandom>10100) acrandom=10100;
|
||||
}
|
||||
|
||||
@@ -1497,15 +1497,14 @@ bool Client::Death(Mob* killerMob, int32 damage, uint16 spell, SkillUseTypes att
|
||||
// creating the corpse takes the cash/items off the player too
|
||||
Corpse *new_corpse = new Corpse(this, exploss);
|
||||
|
||||
char tmp[20];
|
||||
database.GetVariable("ServerType", tmp, 9);
|
||||
if(atoi(tmp)==1 && killerMob != nullptr && killerMob->IsClient()){
|
||||
char tmp2[10] = {0};
|
||||
database.GetVariable("PvPreward", tmp, 9);
|
||||
int reward = atoi(tmp);
|
||||
std::string tmp;
|
||||
database.GetVariable("ServerType", tmp);
|
||||
if(tmp[0] == '1' && tmp[1] == '\0' && killerMob != nullptr && killerMob->IsClient()){
|
||||
database.GetVariable("PvPreward", tmp);
|
||||
int reward = atoi(tmp.c_str());
|
||||
if(reward==3){
|
||||
database.GetVariable("PvPitem", tmp2, 9);
|
||||
int pvpitem = atoi(tmp2);
|
||||
database.GetVariable("PvPitem", tmp);
|
||||
int pvpitem = atoi(tmp.c_str());
|
||||
if(pvpitem>0 && pvpitem<200000)
|
||||
new_corpse->SetPlayerKillItemID(pvpitem);
|
||||
}
|
||||
|
||||
+8
-17
@@ -3598,10 +3598,8 @@ void Client::GetRaidAAs(RaidLeadershipAA_Struct *into) const {
|
||||
void Client::EnteringMessages(Client* client)
|
||||
{
|
||||
//server rules
|
||||
char *rules;
|
||||
rules = new char [4096];
|
||||
|
||||
if(database.GetVariable("Rules", rules, 4096))
|
||||
std::string rules;
|
||||
if(database.GetVariable("Rules", rules))
|
||||
{
|
||||
uint8 flag = database.GetAgreementFlag(client->AccountID());
|
||||
if(!flag)
|
||||
@@ -3612,25 +3610,18 @@ void Client::EnteringMessages(Client* client)
|
||||
client->SendAppearancePacket(AT_Anim, ANIM_FREEZE);
|
||||
}
|
||||
}
|
||||
safe_delete_array(rules);
|
||||
}
|
||||
|
||||
void Client::SendRules(Client* client)
|
||||
{
|
||||
char *rules;
|
||||
rules = new char [4096];
|
||||
char *ptr;
|
||||
std::string rules;
|
||||
|
||||
database.GetVariable("Rules", rules, 4096);
|
||||
if (!database.GetVariable("Rules", rules))
|
||||
return;
|
||||
|
||||
ptr = strtok(rules, "\n");
|
||||
while(ptr != nullptr)
|
||||
{
|
||||
|
||||
client->Message(0,"%s",ptr);
|
||||
ptr = strtok(nullptr, "\n");
|
||||
}
|
||||
safe_delete_array(rules);
|
||||
auto lines = SplitString(rules, '\n');
|
||||
for (auto&& e : lines)
|
||||
client->Message(0, "%s", e.c_str());
|
||||
}
|
||||
|
||||
void Client::SetEndurance(int32 newEnd)
|
||||
|
||||
+14
-16
@@ -856,9 +856,9 @@ char buffer[255];
|
||||
|
||||
void command_getvariable(Client *c, const Seperator *sep)
|
||||
{
|
||||
char tmp[512];
|
||||
if (database.GetVariable(sep->argplus[1], tmp, sizeof(tmp)))
|
||||
c->Message(0, "%s = %s", sep->argplus[1], tmp);
|
||||
std::string tmp;
|
||||
if (database.GetVariable(sep->argplus[1], tmp))
|
||||
c->Message(0, "%s = %s", sep->argplus[1], tmp.c_str());
|
||||
else
|
||||
c->Message(0, "GetVariable(%s) returned false", sep->argplus[1]);
|
||||
}
|
||||
@@ -10735,12 +10735,11 @@ void command_reloadaa(Client *c, const Seperator *sep) {
|
||||
}
|
||||
|
||||
void command_hotfix(Client *c, const Seperator *sep) {
|
||||
char hotfix[256] = { 0 };
|
||||
database.GetVariable("hotfix_name", hotfix, 256);
|
||||
std::string current_hotfix = hotfix;
|
||||
std::string hotfix;
|
||||
database.GetVariable("hotfix_name", hotfix);
|
||||
|
||||
std::string hotfix_name;
|
||||
if(!strcasecmp(current_hotfix.c_str(), "hotfix_")) {
|
||||
if(!strcasecmp(hotfix.c_str(), "hotfix_")) {
|
||||
hotfix_name = "";
|
||||
} else {
|
||||
hotfix_name = "hotfix_";
|
||||
@@ -10762,7 +10761,7 @@ void command_hotfix(Client *c, const Seperator *sep) {
|
||||
system(StringFormat("./shared_memory").c_str());
|
||||
}
|
||||
#endif
|
||||
database.SetVariable("hotfix_name", hotfix_name.c_str());
|
||||
database.SetVariable("hotfix_name", hotfix_name);
|
||||
|
||||
ServerPacket pack(ServerOP_ChangeSharedMem, hotfix_name.length() + 1);
|
||||
if(hotfix_name.length() > 0) {
|
||||
@@ -10777,12 +10776,11 @@ void command_hotfix(Client *c, const Seperator *sep) {
|
||||
}
|
||||
|
||||
void command_load_shared_memory(Client *c, const Seperator *sep) {
|
||||
char hotfix[256] = { 0 };
|
||||
database.GetVariable("hotfix_name", hotfix, 256);
|
||||
std::string current_hotfix = hotfix;
|
||||
std::string hotfix;
|
||||
database.GetVariable("hotfix_name", hotfix);
|
||||
|
||||
std::string hotfix_name;
|
||||
if(strcasecmp(current_hotfix.c_str(), sep->arg[1]) == 0) {
|
||||
if(strcasecmp(hotfix.c_str(), sep->arg[1]) == 0) {
|
||||
c->Message(0, "Cannot attempt to load this shared memory segment as it is already loaded.");
|
||||
return;
|
||||
}
|
||||
@@ -10811,12 +10809,12 @@ void command_load_shared_memory(Client *c, const Seperator *sep) {
|
||||
}
|
||||
|
||||
void command_apply_shared_memory(Client *c, const Seperator *sep) {
|
||||
char hotfix[256] = { 0 };
|
||||
database.GetVariable("hotfix_name", hotfix, 256);
|
||||
std::string hotfix;
|
||||
database.GetVariable("hotfix_name", hotfix);
|
||||
std::string hotfix_name = sep->arg[1];
|
||||
|
||||
|
||||
c->Message(0, "Applying shared memory segment %s", hotfix_name.c_str());
|
||||
database.SetVariable("hotfix_name", hotfix_name.c_str());
|
||||
database.SetVariable("hotfix_name", hotfix_name);
|
||||
|
||||
ServerPacket pack(ServerOP_ChangeSharedMem, hotfix_name.length() + 1);
|
||||
if(hotfix_name.length() > 0) {
|
||||
|
||||
+3
-3
@@ -883,7 +883,6 @@ void Corpse::AllowPlayerLoot(Mob *them, uint8 slot) {
|
||||
|
||||
void Corpse::MakeLootRequestPackets(Client* client, const EQApplicationPacket* app) {
|
||||
// Added 12/08. Started compressing loot struct on live.
|
||||
char tmp[10];
|
||||
if(player_corpse_depop) {
|
||||
SendLootReqErrorPacket(client, 0);
|
||||
return;
|
||||
@@ -914,8 +913,9 @@ void Corpse::MakeLootRequestPackets(Client* client, const EQApplicationPacket* a
|
||||
|
||||
uint8 Loot_Request_Type = 1;
|
||||
bool loot_coin = false;
|
||||
if(database.GetVariable("LootCoin", tmp, 9))
|
||||
loot_coin = (atoi(tmp) == 1);
|
||||
std::string tmp;
|
||||
if(database.GetVariable("LootCoin", tmp))
|
||||
loot_coin = tmp[0] == 1 && tmp[1] == '\0';
|
||||
|
||||
if (this->being_looted_by != 0xFFFFFFFF && this->being_looted_by != client->GetID()) {
|
||||
SendLootReqErrorPacket(client, 0);
|
||||
|
||||
+12
-8
@@ -1406,8 +1406,9 @@ bool GuildApproval::ProcessApproval()
|
||||
|
||||
GuildApproval::GuildApproval(const char* guildname, Client* owner,uint32 id)
|
||||
{
|
||||
database.GetVariable("GuildCreation", founders, 3);
|
||||
uint8 tmp = atoi(founders);
|
||||
std::string founders;
|
||||
database.GetVariable("GuildCreation", founders);
|
||||
uint8 tmp = atoi(founders.c_str());
|
||||
deletion_timer = new Timer(1800000);
|
||||
strcpy(guild,guildname);
|
||||
this->owner = owner;
|
||||
@@ -1425,8 +1426,9 @@ GuildApproval::~GuildApproval()
|
||||
|
||||
bool GuildApproval::AddMemberApproval(Client* addition)
|
||||
{
|
||||
database.GetVariable("GuildCreation", founders, 3);
|
||||
uint8 tmp = atoi(founders);
|
||||
std::string founders;
|
||||
database.GetVariable("GuildCreation", founders);
|
||||
uint8 tmp = atoi(founders.c_str());
|
||||
for(int i=0;i<tmp;i++)
|
||||
{
|
||||
if(members[i] && members[i] == addition)
|
||||
@@ -1455,8 +1457,9 @@ bool GuildApproval::AddMemberApproval(Client* addition)
|
||||
|
||||
void GuildApproval::ApprovedMembers(Client* requestee)
|
||||
{
|
||||
database.GetVariable("GuildCreation", founders, 3);
|
||||
uint8 tmp = atoi(founders);
|
||||
std::string founders;
|
||||
database.GetVariable("GuildCreation", founders);
|
||||
uint8 tmp = atoi(founders.c_str());
|
||||
for(int i=0;i<tmp;i++)
|
||||
{
|
||||
if(members[i])
|
||||
@@ -1471,8 +1474,9 @@ void GuildApproval::GuildApproved()
|
||||
|
||||
if(!owner)
|
||||
return;
|
||||
database.GetVariable("GuildCreation", founders, 3);
|
||||
uint8 tmp = atoi(founders);
|
||||
std::string founders;
|
||||
database.GetVariable("GuildCreation", founders);
|
||||
uint8 tmp = atoi(founders.c_str());
|
||||
uint32 tmpeq = guild_mgr.CreateGuild(guild, owner->CharacterID());
|
||||
guild_mgr.SetGuild(owner->CharacterID(),tmpeq,2);
|
||||
owner->SendAppearancePacket(AT_GuildID,true,false);
|
||||
|
||||
@@ -61,7 +61,6 @@ public:
|
||||
private:
|
||||
Timer* deletion_timer;
|
||||
char guild[16];
|
||||
char founders[3];
|
||||
Client* owner;
|
||||
Client* members[6];
|
||||
uint32 refid;
|
||||
|
||||
+13
-13
@@ -254,20 +254,20 @@ int main(int argc, char** argv) {
|
||||
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "Mapping Incoming Opcodes");
|
||||
MapOpcodes();
|
||||
|
||||
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "Loading Variables");
|
||||
database.LoadVariables();
|
||||
|
||||
char hotfix_name[256] = { 0 };
|
||||
if(database.GetVariable("hotfix_name", hotfix_name, 256)) {
|
||||
if(strlen(hotfix_name) > 0) {
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "Current hotfix in use: '%s'", hotfix_name);
|
||||
|
||||
std::string hotfix_name;
|
||||
if(database.GetVariable("hotfix_name", hotfix_name)) {
|
||||
if(!hotfix_name.empty()) {
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "Current hotfix in use: '%s'", hotfix_name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "Loading zone names");
|
||||
database.LoadZoneNames();
|
||||
|
||||
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "Loading items");
|
||||
if(!database.LoadItems(hotfix_name)) {
|
||||
Log.Out(Logs::General, Logs::Error, "Loading items FAILED!");
|
||||
@@ -326,17 +326,17 @@ int main(int argc, char** argv) {
|
||||
|
||||
//rules:
|
||||
{
|
||||
char tmp[64];
|
||||
if (database.GetVariable("RuleSet", tmp, sizeof(tmp)-1)) {
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "Loading rule set '%s'", tmp);
|
||||
if(!RuleManager::Instance()->LoadRules(&database, tmp)) {
|
||||
Log.Out(Logs::General, Logs::Error, "Failed to load ruleset '%s', falling back to defaults.", tmp);
|
||||
std::string tmp;
|
||||
if (database.GetVariable("RuleSet", tmp)) {
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "Loading rule set '%s'", tmp.c_str());
|
||||
if(!RuleManager::Instance()->LoadRules(&database, tmp.c_str())) {
|
||||
Log.Out(Logs::General, Logs::Error, "Failed to load ruleset '%s', falling back to defaults.", tmp.c_str());
|
||||
}
|
||||
} else {
|
||||
if(!RuleManager::Instance()->LoadRules(&database, "default")) {
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "No rule set configured, using default rules");
|
||||
} else {
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "Loaded default rule set 'default'", tmp);
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "Loaded default rule set 'default'", tmp.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-5
@@ -104,10 +104,11 @@ bool Zone::Bootup(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone) {
|
||||
zone->watermap = WaterMap::LoadWaterMapfile(zone->map_name);
|
||||
zone->pathing = PathManager::LoadPathFile(zone->map_name);
|
||||
|
||||
char tmp[10];
|
||||
if (database.GetVariable("loglevel",tmp, 9)) {
|
||||
std::string tmp;
|
||||
if (database.GetVariable("loglevel", tmp)) {
|
||||
int log_levels[4];
|
||||
if (atoi(tmp)>9){ //Server is using the new code
|
||||
int tmp_i = atoi(tmp.c_str());
|
||||
if (tmp_i>9){ //Server is using the new code
|
||||
for(int i=0;i<4;i++){
|
||||
if (((int)tmp[i]>=48) && ((int)tmp[i]<=57))
|
||||
log_levels[i]=(int)tmp[i]-48; //get the value to convert it to an int from the ascii value
|
||||
@@ -124,12 +125,12 @@ bool Zone::Bootup(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone) {
|
||||
Log.Out(Logs::General, Logs::Status, "Loot logging level: %i", zone->lootvar);
|
||||
}
|
||||
else {
|
||||
zone->loglevelvar = uint8(atoi(tmp)); //continue supporting only command logging (for now)
|
||||
zone->loglevelvar = uint8(tmp_i); //continue supporting only command logging (for now)
|
||||
zone->merchantvar = 0;
|
||||
zone->tradevar = 0;
|
||||
zone->lootvar = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is_zone_loaded = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user