From a384ef5e631e1758ae559a4428106c3b0683778b Mon Sep 17 00:00:00 2001 From: Kostya Betenya Date: Fri, 20 Dec 2024 14:32:05 +0300 Subject: [PATCH 1/2] fet: add server error handler --- File/Log/Log.inc | 3 ++- Server/SendRequest/Methods/Player.asm | 18 ++++++++++++++++++ Server/SendRequest/Methods/Score.asm | 18 ++++++++++++++++++ Server/SendRequest/REST/GET.asm | 24 ++++++++++++------------ Server/SendRequest/REST/POST.asm | 24 ++++++++++++------------ 5 files changed, 62 insertions(+), 25 deletions(-) diff --git a/File/Log/Log.inc b/File/Log/Log.inc index 9a86f5a..fb1235e 100644 --- a/File/Log/Log.inc +++ b/File/Log/Log.inc @@ -17,4 +17,5 @@ getScoresCountSignal LogString 10, '===================================', 10, 'G currentPointsSignal LogString 10, 'Current Points = ' addNewScoreSignal LogString 10, '===================================', 10, 'Add new score', 10 getUserScoreSignal LogString 10, '===================================', 10, 'Get user scores', 10 -getBestScoreSignal LogString 10, '===================================', 10, 'Get best scores', 10 \ No newline at end of file +getBestScoreSignal LogString 10, '===================================', 10, 'Get best scores', 10 +errorSignal LogString 10, '===================================', 10, 'ERROR FROM SERVER!', 10 \ No newline at end of file diff --git a/Server/SendRequest/Methods/Player.asm b/Server/SendRequest/Methods/Player.asm index 0a5bde8..fd9f030 100644 --- a/Server/SendRequest/Methods/Player.asm +++ b/Server/SendRequest/Methods/Player.asm @@ -13,6 +13,8 @@ proc Server.Methods.Player.IsExist uses eax ebx stdcall Log.Console, sendString, sendString.size stdcall Log.Console, playerJSON.loginStart, sizeof.PlayerJSON stdcall Server.SendRequest.GetIsPlayerExist, playerJSON.loginStart, sizeof.PlayerJSON, idResponseBuffer, [idResponseBufferLength] + cmp eax, -1 + je .serverError stdcall Log.Console, serverAnswer, serverAnswer.size mov ebx, eax stdcall File.IniFile.StrLen, eax @@ -35,6 +37,10 @@ proc Server.Methods.Player.IsExist uses eax ebx jmp .exit @@: mov eax, 1 + jmp .exit + .serverError: + stdcall Log.Console, errorSignal, errorSignal.size + ; process error .exit: stdcall ClearBuffer, [jsonLink] ret @@ -67,6 +73,8 @@ proc Server.Methods.Player.AddNewPlayer stdcall Log.Console, sendString, sendString.size stdcall Log.Console, playerJSON.loginStart, sizeof.PlayerJSON stdcall Server.SendRequest.PostAddPlayers, playerJSON.loginStart, sizeof.PlayerJSON, idResponseBuffer, [idResponseBufferLength] + cmp eax, -1 + je .serverError stdcall Log.Console, serverAnswer, serverAnswer.size mov ebx, eax stdcall File.IniFile.StrLen, eax @@ -106,6 +114,10 @@ proc Server.Methods.Player.AddNewPlayer mov [str_error], str_nullerror stdcall Server.ErrorPayloadUpdate ; null error stdcall Page.ChangePage, LoadingPage + jmp .exit + .serverError: + stdcall Log.Console, errorSignal, errorSignal.size + ; process error .exit: stdcall ClearBuffer, [jsonLink] ret @@ -124,6 +136,8 @@ proc Server.Methods.Player.ScoresCount stdcall Log.Console, sendString, sendString.size stdcall Log.Console, idJSON.idStart, sizeof.IdJSON stdcall Server.SendRequest.GetUserScoresCount, idJSON.idStart, sizeof.IdJSON, idResponseBuffer, [idResponseBufferLength] + cmp eax, -1 + je .serverError stdcall Log.Console, serverAnswer, serverAnswer.size mov ebx, eax stdcall File.IniFile.StrLen, eax @@ -143,6 +157,10 @@ proc Server.Methods.Player.ScoresCount jmp .exit @@: stdcall Server.JSON.GetScoresCount, [jsonLink] + jmp .exit + .serverError: + stdcall Log.Console, errorSignal, errorSignal.size + ; process error .exit: stdcall ClearBuffer, [jsonLink] ret diff --git a/Server/SendRequest/Methods/Score.asm b/Server/SendRequest/Methods/Score.asm index b77f008..28a6f1f 100644 --- a/Server/SendRequest/Methods/Score.asm +++ b/Server/SendRequest/Methods/Score.asm @@ -13,12 +13,18 @@ proc Server.Methods.Score.Add stdcall Log.Console, sendString, sendString.size stdcall Log.Console, scoreJSON.pointsStart, sizeof.ScoreJSON stdcall Server.SendRequest.PostAddScores, scoreJSON.pointsStart, sizeof.ScoreJSON, idResponseBuffer, [idResponseBufferLength] + cmp eax, -1 + je .serverError stdcall Log.Console, serverAnswer, serverAnswer.size mov ebx, eax stdcall File.IniFile.StrLen, eax stdcall Log.Console, ebx, eax xchg eax, ebx mov [jsonLink], eax + jmp .exit + .serverError: + stdcall Log.Console, errorSignal, errorSignal.size + ; process error .exit: stdcall ClearBuffer, [jsonLink] ret @@ -37,6 +43,8 @@ proc Server.Methods.Score.UserScores stdcall Log.Console, sendString, sendString.size stdcall Log.Console, idJSON.idStart, sizeof.IdJSON stdcall Server.SendRequest.GetAllUserScores, idJSON.idStart, sizeof.IdJSON, scoresUserRespBuffer, [scoresUserRespBufferLength] + cmp eax, -1 + je .serverError stdcall Log.Console, serverAnswer, serverAnswer.size mov ebx, eax stdcall File.IniFile.StrLen, eax @@ -59,6 +67,10 @@ proc Server.Methods.Score.UserScores @@: stdcall Server.JSON.ParseUserScore, [jsonLink], [UserScores] mov [UserScoresLen], eax + jmp .exit + .serverError: + stdcall Log.Console, errorSignal, errorSignal.size + ; process error .exit: stdcall ClearBuffer, [jsonLink] ret @@ -71,6 +83,8 @@ proc Server.Methods.Score.BestScores stdcall Log.Console, getBestScoreSignal, getBestScoreSignal.size stdcall Log.Console, sendString, sendString.size stdcall Server.SendRequest.GetBestScores, 0, 0, scoresGlobRespBuffer, [scoresGlobRespBufferLength] + cmp eax, -1 + je .serverError stdcall Log.Console, serverAnswer, serverAnswer.size mov ebx, eax stdcall File.IniFile.StrLen, eax @@ -92,6 +106,10 @@ proc Server.Methods.Score.BestScores @@: stdcall Server.JSON.ParseBestScore, [jsonLink], [BestScores] mov [BestScoresLen], eax + jmp .exit + .serverError: + stdcall Log.Console, errorSignal, errorSignal.size + ; process error .exit: stdcall ClearBuffer, [jsonLink] ret diff --git a/Server/SendRequest/REST/GET.asm b/Server/SendRequest/REST/GET.asm index eb95910..846d3a0 100644 --- a/Server/SendRequest/REST/GET.asm +++ b/Server/SendRequest/REST/GET.asm @@ -34,26 +34,26 @@ proc Server.SendRequest.GET,\ mov eax, [buffer] mov [result], eax - ;invoke MessageBox, 0, eax, ErrorTitle, MB_OK jmp .exit .error: - invoke GetLastError - invoke MessageBox, 0, ErrorMessage, ErrorTitle, MB_OK + mov [result], -1 + invoke GetLastError + invoke MessageBox, 0, ErrorMessage, ErrorTitle, MB_OK .exit: - cmp [hRequest], 0 - jz .skipRequest - invoke WinHttpCloseHandle, [hRequest] + cmp [hRequest], 0 + jz .skipRequest + invoke WinHttpCloseHandle, [hRequest] .skipRequest: - cmp [hConnect], 0 - jz .skipConnect - invoke WinHttpCloseHandle, [hConnect] + cmp [hConnect], 0 + jz .skipConnect + invoke WinHttpCloseHandle, [hConnect] .skipConnect: - cmp [hSession], 0 - jz .skipSession - invoke WinHttpCloseHandle, [hSession] + cmp [hSession], 0 + jz .skipSession + invoke WinHttpCloseHandle, [hSession] .skipSession: mov eax, [result] ret diff --git a/Server/SendRequest/REST/POST.asm b/Server/SendRequest/REST/POST.asm index 5ee0ade..c662390 100644 --- a/Server/SendRequest/REST/POST.asm +++ b/Server/SendRequest/REST/POST.asm @@ -34,26 +34,26 @@ proc Server.SendRequest.POST,\ mov eax, [buffer] mov [result], eax - ;invoke MessageBox, 0, eax, ErrorTitle, MB_OK jmp .exit .error: - invoke GetLastError - invoke MessageBox, 0, ErrorMessage, ErrorTitle, MB_OK + mov [result], -1 + invoke GetLastError + invoke MessageBox, 0, ErrorMessage, ErrorTitle, MB_OK .exit: - cmp [hRequest], 0 - jz .skipRequest - invoke WinHttpCloseHandle, [hRequest] + cmp [hRequest], 0 + jz .skipRequest + invoke WinHttpCloseHandle, [hRequest] .skipRequest: - cmp [hConnect], 0 - jz .skipConnect - invoke WinHttpCloseHandle, [hConnect] + cmp [hConnect], 0 + jz .skipConnect + invoke WinHttpCloseHandle, [hConnect] .skipConnect: - cmp [hSession], 0 - jz .skipSession - invoke WinHttpCloseHandle, [hSession] + cmp [hSession], 0 + jz .skipSession + invoke WinHttpCloseHandle, [hSession] .skipSession: mov eax, [result] ret From 8b3b716502b7b3322a9d072d2be5e3cc04bac23a Mon Sep 17 00:00:00 2001 From: Kostya Betenya Date: Sun, 22 Dec 2024 18:41:15 +0300 Subject: [PATCH 2/2] fix: application work after error --- Server/SendRequest/Methods/Player.asm | 3 --- Server/SendRequest/Methods/Score.asm | 5 +---- Server/SendRequest/REST/GET.asm | 2 +- Server/SendRequest/REST/POST.asm | 2 +- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/Server/SendRequest/Methods/Player.asm b/Server/SendRequest/Methods/Player.asm index fd9f030..b8a39fe 100644 --- a/Server/SendRequest/Methods/Player.asm +++ b/Server/SendRequest/Methods/Player.asm @@ -40,7 +40,6 @@ proc Server.Methods.Player.IsExist uses eax ebx jmp .exit .serverError: stdcall Log.Console, errorSignal, errorSignal.size - ; process error .exit: stdcall ClearBuffer, [jsonLink] ret @@ -117,7 +116,6 @@ proc Server.Methods.Player.AddNewPlayer jmp .exit .serverError: stdcall Log.Console, errorSignal, errorSignal.size - ; process error .exit: stdcall ClearBuffer, [jsonLink] ret @@ -160,7 +158,6 @@ proc Server.Methods.Player.ScoresCount jmp .exit .serverError: stdcall Log.Console, errorSignal, errorSignal.size - ; process error .exit: stdcall ClearBuffer, [jsonLink] ret diff --git a/Server/SendRequest/Methods/Score.asm b/Server/SendRequest/Methods/Score.asm index 28a6f1f..d3886dc 100644 --- a/Server/SendRequest/Methods/Score.asm +++ b/Server/SendRequest/Methods/Score.asm @@ -24,7 +24,6 @@ proc Server.Methods.Score.Add jmp .exit .serverError: stdcall Log.Console, errorSignal, errorSignal.size - ; process error .exit: stdcall ClearBuffer, [jsonLink] ret @@ -70,7 +69,6 @@ proc Server.Methods.Score.UserScores jmp .exit .serverError: stdcall Log.Console, errorSignal, errorSignal.size - ; process error .exit: stdcall ClearBuffer, [jsonLink] ret @@ -108,8 +106,7 @@ proc Server.Methods.Score.BestScores mov [BestScoresLen], eax jmp .exit .serverError: - stdcall Log.Console, errorSignal, errorSignal.size - ; process error + stdcall Log.Console, errorSignal, errorSignal.size .exit: stdcall ClearBuffer, [jsonLink] ret diff --git a/Server/SendRequest/REST/GET.asm b/Server/SendRequest/REST/GET.asm index 846d3a0..831426c 100644 --- a/Server/SendRequest/REST/GET.asm +++ b/Server/SendRequest/REST/GET.asm @@ -39,7 +39,7 @@ proc Server.SendRequest.GET,\ .error: mov [result], -1 invoke GetLastError - invoke MessageBox, 0, ErrorMessage, ErrorTitle, MB_OK + ;invoke MessageBox, 0, ErrorMessage, ErrorTitle, MB_OK .exit: cmp [hRequest], 0 jz .skipRequest diff --git a/Server/SendRequest/REST/POST.asm b/Server/SendRequest/REST/POST.asm index c662390..aab4748 100644 --- a/Server/SendRequest/REST/POST.asm +++ b/Server/SendRequest/REST/POST.asm @@ -39,7 +39,7 @@ proc Server.SendRequest.POST,\ .error: mov [result], -1 invoke GetLastError - invoke MessageBox, 0, ErrorMessage, ErrorTitle, MB_OK + ;invoke MessageBox, 0, ErrorMessage, ErrorTitle, MB_OK .exit: cmp [hRequest], 0 jz .skipRequest