Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onConnectionRestoration event #4651

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ArturKnopik
Copy link
Contributor

@ArturKnopik ArturKnopik commented Apr 14, 2024

Pull Request Prelude

  • I have followed [proper The Forgotten Server code styling][code].
  • I have read and understood the [contribution guidelines][cont] before making this PR.
  • I am aware that this PR may be closed if the above-mentioned criteria are not fulfilled.

Changes Proposed

new CreatureEvent onConnectionRestoration
Handle switching game client without logout which is currently impossible.
example: call login CreatureEvent that will set bless icon status, after switching the client the icon will not be updated

local blessStatusLogin = CreatureEvent("blessStatusLogin")
function blessStatusLogin.onLogin(player)
	local blessCount = 0
	for b = 1, 5 do
		if player:hasBlessing(b) then
			blessCount = blessCount + 1
		end
	end

	local msg = NetworkMessage()
	msg:addByte(0x9C);
	if blessCount == 0 then
		msg:addU16(0)
		msg:addByte(1)
		msg:sendToPlayer(player)
		msg:delete()
		return true
	end

	local bits = bit.bor(4, 8, 16, 32, 64)
	if blessCount == 4 then
		msg:addU16(2)
		msg:addByte(2)
	elseif blessCount == 5 then
		msg:addU16(255)
		msg:addByte(3)
	end
	msg:sendToPlayer(player)
	msg:delete()
	return true
end
blessStatusLogin:register()

-- solution

local ce = CreatureEvent("blessStatusConnectionRestoration")
function ce.onConnectionRestoration(player)
	print("blessStatusConnectionRestoration")
	local blessCount = 0
	for b = 1, 5 do
		if player:hasBlessing(b) then
			blessCount = blessCount + 1
		end
	end

	local msg = NetworkMessage()
	msg:addByte(0x9C);
	if blessCount == 0 then
		msg:addU16(0)
		msg:addByte(1)
		msg:sendToPlayer(player)
		msg:delete()
		return true
	end

	local bits = bit.bor(4, 8, 16, 32, 64)
	if blessCount == 4 then
		msg:addU16(2)
		msg:addByte(2)
	elseif blessCount == 5 then
		msg:addU16(255)
		msg:addByte(3)
	end
	msg:sendToPlayer(player)
	msg:delete()
	return true
end
ce:register()

@@ -248,6 +248,10 @@ void ProtocolGame::login(uint32_t characterId, uint32_t accountId, OperatingSyst
eventConnect = g_scheduler.addEvent(
createSchedulerTask(1000, [=, thisPtr = getThis(), playerID = foundPlayer->getID()]() {
thisPtr->connect(playerID, operatingSystem);
Player* player = g_game.getPlayerByID(playerID);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably to remove and change to use if (thisPtr->player) instead
suggestion not tested

@EvilHero90 EvilHero90 added this to the 1.8 milestone May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants