BUG: some quests are triggering a SaveCharacterQuests

Post in this forum if you found any bugs with server functionality.

Moderator: Team Members

Forum rules
READ THE STICKY ON PROPER BUG SUBMISSION FORMAT BEFORE POSTING.
Post Reply
User avatar
Ememjr
Team Member
Posts: 975
Joined: Wed Mar 15, 2017 9:41 am
EQ2Emu Server: Perseverance

BUG: some quests are triggering a SaveCharacterQuests

Post by Ememjr » Tue Mar 26, 2019 3:14 pm

when it should not, since it is crashing my server, since at the time i havent even accepted the quest yet

in the following code quests has my current non completed quests and the quest # for the quest waiting to be accepted but its contents are null

am doing a trace to find out why its even in the list

Code: Select all

void WorldDatabase::SaveCharacterQuests(Client* client){
	Query query;
	map<int32, Quest*>::iterator itr;
	master_quest_list.LockQuests(); //prevent reloading until we are done
	client->GetPlayer()->LockQuests(); //prevent all quest modifications until we are done
	map<int32, Quest*>* quests = client->GetPlayer()->GetPlayerQuests();
	for(itr = quests->begin(); itr != quests->end(); itr++){
		if(client->GetCurrentQuestID() == itr->first){
			query.RunQuery2(Q_UPDATE, "update character_quests set current_quest = 0 where char_id = %u", client->GetCharacterID());
			query.RunQuery2(Q_UPDATE, "update character_quests set current_quest = 1 where char_id = %u and quest_id = %u", client->GetCharacterID(), itr->first);
		}
		if(itr->second->GetSaveNeeded()){
			query.RunQuery2(Q_INSERT, "insert ignore into character_quests (char_id, quest_id, given_date, quest_giver) values(%u, %u, now(), %u)", client->GetCharacterID(), itr->first, itr->second->GetQuestGiver());
			query.RunQuery2(Q_UPDATE, "update character_quests set tracked = %i, quest_flags = %u, hidden = %i, complete_count = %u where char_id = %u and quest_id = %u", itr->second->IsTracked() ? 1 : 0, itr->second->GetQuestFlags(), itr->second->IsHidden() ? 1 : 0, itr->second->GetCompleteCount(), client->GetCharacterID(), itr->first);
			SaveCharacterQuestProgress(client, itr->second);
			itr->second->SetSaveNeeded(false);
		}
	}
	if(query.GetErrorNumber() && query.GetError() && query.GetErrorNumber() < 0xFFFFFFFF)
		LogWrite(WORLD__ERROR, 0, "World", "Error in SaveCharacterQuests query '%s': %s", query.GetQuery(), query.GetError());
	quests = client->GetPlayer()->GetCompletedPlayerQuests();
	for(itr = quests->begin(); itr != quests->end(); itr++){
		if(itr->second->GetSaveNeeded()){
			query.RunQuery2(Q_DELETE, "delete FROM character_quest_progress where char_id = %u and quest_id = %u", client->GetCharacterID(), itr->first);

			/* incase the quest is completed before the quest could be inserted in the PlayerQuests loop, we first try to insert it.  If it already exists then we can just update
			 * the completed_date */
			query.RunQuery2(Q_INSERT, "INSERT INTO character_quests (char_id, quest_id, quest_giver, current_quest, given_date, completed_date, complete_count) values (%u,%u,%u,0, now(),now(), %u) ON DUPLICATE KEY UPDATE completed_date = now(), complete_count = %u, current_quest = 0", client->GetCharacterID(), itr->first, itr->second->GetQuestGiver(), itr->second->GetCompleteCount(), itr->second->GetCompleteCount());
			itr->second->SetSaveNeeded(false);
		}
	}
	client->GetPlayer()->UnlockQuests();
	master_quest_list.UnlockQuests();

}

User avatar
Ememjr
Team Member
Posts: 975
Joined: Wed Mar 15, 2017 9:41 am
EQ2Emu Server: Perseverance

Re: BUG: some quests are triggering a SaveCharacterQuests

Post by Ememjr » Tue Mar 26, 2019 3:51 pm

here is the quest causing the issue

Code: Select all

function Init(Quest)
	AddQuestStepLocation(Quest, 1, "I need to visit Glade of the Coven.", 10, "I would like to visit the Glade of the Coven in Antonica.", 11, 160, -24, 441)
	AddQuestStepCompleteAction(Quest, 1, "Step1Complete")
end

function Accepted(Quest, QuestGiver, Player)
	Item = GetTempVariable(Player, "Q474")
	conversation = CreateConversation()
	AddConversationOption(conversation, "Continue Story 1","ContStory1")
	AddConversationOption(conversation, "Close")
	StartDialogConversation(conversation, 2, Item, Player, "Q My name is Trinni Mellosius and I'm a half-elf.  I guess that's why my teacher asked me to write a research paper about our history.  As if we have a history of our own!  But since I need to pass this class, I guess I'll write one.")
end
function ContStory1(QuestGiver, Player)
	Item = GetTempVariable(Player, "Q474")
    conversation = CreateConversation()
	AddConversationOption(conversation, "Close")
	StartDialogConversation(conversation, 2, Item, Player, "Q So you're walking around Qeynos, or maybe even Freeport (I live in Willow Wood, so I just have to guess about you-know-where) and you see someone who has pointy ears like an elf, is taller than an elf, but not so tall as a human and what have you got?  Ayr'Dal!")
end

function Declined(Quest, QuestGiver, Player)
	Item = GetTempVariable(Player, "Q474")
	CloseItemConversation(Item, Player)
end
here is the book that calls the offerquest in ReadStory1 after i offer quest, and have not yet accepted, the next if statement is evaluating to true

Code: Select all

function examined(Item, Player)
	conversation = CreateConversation()
	AddConversationOption(conversation, "Continue Story","ContinueStory")
	AddConversationOption(conversation, "Close")
	StartDialogConversation(conversation, 2, Item, Player, "This is a three-part history of the Ayr'Dal.  Its pages cannot be completed at one time, but must be gained through valor and experience.")
end
function ContinueStory(Item, Player)
	conversation = CreateConversation()
	AddConversationOption(conversation, "Read Story 1","ReadStory1")
	AddConversationOption(conversation, "Close")
	StartDialogConversation(conversation, 2, Item, Player, "Each part of this history tome can only be completed in its own time.")
end
function ReadStory1(Item, Player)
    if not HasQuest(Player, 474) then
	    SetTempVariable(Player, "Q474", Item)
        OfferQuest(nil, Player, 474)
	end
	if (HasQuest(Player, 474) or QuestIsComplete(Player,474)) then
	        Say(Player,"thinks i have completed quest 474")
	        Say(Player,"thinks i have quest 474")
	        conversation = CreateConversation()
	        AddConversationOption(conversation, "Continue Story 1","ContStory1")
	        AddConversationOption(conversation, "Close")
	        StartDialogConversation(conversation, 2, Item, Player, "B My name is Trinni Mellosius and I'm a half-elf.  I guess that's why my teacher asked me to write a research paper about our history.  As if we have a history of our own!  But since I need to pass this class, I guess I'll write one.")
    end
end

function ContStory1(Item, Player)
    conversation = CreateConversation()
	AddConversationOption(conversation, "Close")
	StartDialogConversation(conversation, 2, Item, Player, "B So you're walking around Qeynos, or maybe even Freeport (I live in Willow Wood, so I just have to guess about you-know-where) and you see someone who has pointy ears like an elf, is taller than an elf, but not so tall as a human and what have you got?  Ayr'Dal!")

end

User avatar
Ememjr
Team Member
Posts: 975
Joined: Wed Mar 15, 2017 9:41 am
EQ2Emu Server: Perseverance

Re: BUG: some quests are triggering a SaveCharacterQuests

Post by Ememjr » Tue Mar 26, 2019 4:18 pm

here is the quests the save character quests is trying to save
questnull.JPG
quest 474 has not been accepted yet, so why would it be in the list
You do not have the required permissions to view the files attached to this post.

User avatar
Ememjr
Team Member
Posts: 975
Joined: Wed Mar 15, 2017 9:41 am
EQ2Emu Server: Perseverance

Re: BUG: some quests are triggering a SaveCharacterQuests

Post by Ememjr » Wed Mar 27, 2019 2:35 am

after nearly 5 hours testing diffeerent ways of getting this to fail I finally figured it out
that is was the QuestIsComplete in my script that was the issue, once i figured that out i did a quick search on formums and found this

viewtopi ... ete#p30903

so basically QuestIsComplete will crash server if you call it and do not have the quest (my issue), so you should have the quest already to call it
so i will use HasCompletedQuest to see if i have completed the quest already
also as a side not HasQuest only returns true if the quest is active

I suggest a fix QuestIsComplete function to at a minimum spit out an error either in console, or chat window(prefered since most of the script writers can see that) that you dont have the quest if you call this prior to having the quest

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests