From ac41dc912dbdee28a01a4db0404bdb363d5530dc Mon Sep 17 00:00:00 2001 From: fusion32 Date: Fri, 11 Jul 2025 12:30:22 -0300 Subject: add `TransactionScope` --- src/connections.cc | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src/connections.cc') diff --git a/src/connections.cc b/src/connections.cc index b2b3daf..cfb0a01 100644 --- a/src/connections.cc +++ b/src/connections.cc @@ -623,9 +623,11 @@ void ProcessInsertHousesQuery(TConnection *Connection, TReadBuffer *Buffer){ return; } - // TODO(fusion): Have some TransactionGuard type that will either commit or - // rollback a transaction when we leave its scope, based on whether some - // `Commit` function was called. + TransactionScope Tx("UpdateHouses"); + if(!Tx.Begin()){ + SendQueryStatusFailed(Connection); + return; + } if(!DeleteHouses(Connection->WorldID)){ SendQueryStatusFailed(Connection); @@ -654,6 +656,11 @@ void ProcessInsertHousesQuery(TConnection *Connection, TReadBuffer *Buffer){ } } + if(!Tx.Commit()){ + SendQueryStatusFailed(Connection); + return; + } + SendQueryStatusOk(Connection); } @@ -680,9 +687,12 @@ void ProcessCreatePlayerlistQuery(TConnection *Connection, TReadBuffer *Buffer){ return; } - // TODO(fusion): Have some TransactionGuard type that will either commit or - // rollback a transaction when we leave its scope, based on whether some - // `Commit` function was called. + + TransactionScope Tx("OnlineList"); + if(!Tx.Begin()){ + SendQueryStatusFailed(Connection); + return; + } if(!DeleteOnlineCharacters(Connection->WorldID)){ SendQueryStatusFailed(Connection); @@ -710,6 +720,11 @@ void ProcessCreatePlayerlistQuery(TConnection *Connection, TReadBuffer *Buffer){ } } + if(!Tx.Commit()){ + SendQueryStatusFailed(Connection); + return; + } + TWriteBuffer WriteBuffer = PrepareResponse(Connection, QUERY_STATUS_OK); WriteBuffer.WriteFlag(NewRecord); SendResponse(Connection, &WriteBuffer); -- cgit v1.2.3