Skip to content

Commit 8471d9e

Browse files
committed
A bit more debugging
1 parent 456e8be commit 8471d9e

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

addons/sourcemod/scripting/offstyledb.sp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,10 @@ public void OnReplayUploaded(HTTPStatus status, any value)
678678

679679
void ProcessNextBatch()
680680
{
681+
DebugPrint("[OSdb] ProcessNextBatch called - gB_IsProcessingBatches: %s, gS_BulkCode length: %d",
682+
gB_IsProcessingBatches ? "true" : "false", strlen(gS_BulkCode));
683+
DebugPrint("[OSdb] Current bulk code value: %s", gS_BulkCode);
684+
681685
if (gA_AllRecords == null || gA_AllRecords.Length == 0)
682686
{
683687
PrintToServer("[osdb] No more records to process, finishing batch operation.");
@@ -711,7 +715,10 @@ void ProcessNextBatch()
711715
hArray.Push(hJSON);
712716
}
713717

718+
DebugPrint("[OSdb] Created JSON array with %d records", hArray.Length);
719+
714720
HTTPRequest hHTTPRequest = new HTTPRequest(API_BASE_URL... "/bulk_records");
721+
DebugPrint("[OSdb] Created HTTP request to %s/bulk_records", API_BASE_URL);
715722
AddHeaders(hHTTPRequest);
716723

717724
JSONObject hRecordsList = new JSONObject();
@@ -721,6 +728,7 @@ void ProcessNextBatch()
721728
pack.WriteCell(gI_CurrentBatch);
722729
pack.WriteCell(hArray.Length);
723730

731+
DebugPrint("[OSdb] Sending batch %d with %d records", gI_CurrentBatch + 1, hArray.Length);
724732
hHTTPRequest.Post(hRecordsList, Callback_OnBatchSent, pack);
725733

726734
delete hRecordsList;
@@ -734,34 +742,64 @@ public void Callback_OnBatchSent(HTTPResponse resp, any value)
734742
int batchSize = pack.ReadCell();
735743
delete pack;
736744

745+
DebugPrint("[OSdb] Callback_OnBatchSent received - Status: %d", resp.Status);
746+
737747
if (resp.Status != HTTPStatus_OK)
738748
{
739749
LogError("[osdb] Batch %d failed to send: status = %d", batchNumber + 1, resp.Status);
750+
DebugPrint("[OSdb] Batch %d failed with HTTP status %d", batchNumber + 1, resp.Status);
751+
752+
// Try to extract error message from response
753+
if (resp.Data != null)
754+
{
755+
JSONObject errorData = view_as<JSONObject>(resp.Data);
756+
char errorMsg[256];
757+
if (errorData.GetString("error", errorMsg, sizeof(errorMsg)))
758+
{
759+
DebugPrint("[OSdb] Server error message: %s", errorMsg);
760+
LogError("[osdb] Server error: %s", errorMsg);
761+
}
762+
if (errorData.GetString("message", errorMsg, sizeof(errorMsg)))
763+
{
764+
DebugPrint("[OSdb] Server message: %s", errorMsg);
765+
LogError("[osdb] Server message: %s", errorMsg);
766+
}
767+
}
768+
else
769+
{
770+
DebugPrint("[OSdb] No response data available");
771+
}
772+
740773
PrintToServer("[osdb] Batch %d failed, stopping batch processing.", batchNumber + 1);
741774
FinishBatchProcessing();
742775
return;
743776
}
744777

745778
PrintToServer("[osdb] Batch %d (%d records) sent successfully.", batchNumber + 1, batchSize);
779+
DebugPrint("[OSdb] Batch %d completed successfully", batchNumber + 1);
746780

747781
gI_CurrentBatch++;
748782
ProcessNextBatch();
749783
}
750784

751785
void FinishBatchProcessing()
752786
{
787+
DebugPrint("[OSdb] FinishBatchProcessing called - clearing bulk code: %s", gS_BulkCode);
788+
753789
gB_IsProcessingBatches = false;
754790
gI_CurrentBatch = 0;
755791
gI_TotalRecords = 0;
756792

757793
if (gA_AllRecords != null)
758794
{
795+
DebugPrint("[OSdb] Cleaning up %d records from ArrayList", gA_AllRecords.Length);
759796
delete gA_AllRecords;
760797
gA_AllRecords = null;
761798
}
762799

763800
gS_BulkCode[0] = '\0';
764801

802+
DebugPrint("[OSdb] Batch processing state reset complete");
765803
PrintToServer("[osdb] Batch processing completed.");
766804
}
767805

@@ -998,6 +1036,7 @@ void AddHeaders(HTTPRequest req)
9981036

9991037
if (gB_IsProcessingBatches && strlen(gS_BulkCode) > 0)
10001038
{
1039+
DebugPrint("[OSdb] Adding bulk_verify header: %s", gS_BulkCode);
10011040
req.SetHeader("bulk_verify", gS_BulkCode);
10021041
}
10031042
}

0 commit comments

Comments
 (0)