Skip to content

Commit 381764a

Browse files
authored
Merge pull request #5 from tebexio/2.0.5
fix: cleanup log levels for certain errors
2 parents 4c08b55 + ebfe490 commit 381764a

3 files changed

Lines changed: 39 additions & 18 deletions

File tree

TebexOxide/BaseTebexAdapter.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ public void DeleteExecutedCommands(bool ignoreWaitCheck = false)
6060
ExecutedCommands.Clear();
6161
}, (error) =>
6262
{
63-
LogError($"Failed to flush completed commands: {error.ErrorMessage}");
63+
LogDebug($"Failed to flush completed commands: {error.ErrorMessage}");
6464
}, (code, body) =>
6565
{
66-
LogError($"Unexpected error while flushing completed commands. API response code {code}. Response body follows:");
67-
LogError(body);
66+
LogDebug($"Unexpected error while flushing completed commands. API response code {code}. Response body follows:");
67+
LogDebug(body);
6868
});
6969
}
7070

@@ -94,7 +94,7 @@ public void OnUserConnected(string steam64Id, string ip)
9494
_eventQueue.Add(joinEvent);
9595

9696
// If we're already over a threshold, go ahead and send the events.
97-
if (_eventQueue.Count > 10) //TODO make configurable?
97+
if (_eventQueue.Count > 10)
9898
{
9999
ProcessJoinQueue();
100100
}
@@ -215,7 +215,8 @@ public void FetchStoreInfo(FetchStoreInfoResponse response)
215215
var storeInfo = JsonConvert.DeserializeObject<TebexApi.TebexStoreInfo>(body);
216216
if (storeInfo == null)
217217
{
218-
LogError("Failed to parse fetched store information.");
218+
ReportAutoTriageEvent(new TebexTriage.AutoTriageEvent());
219+
LogError("Failed to parse fetched store information: ");
219220
LogError(body);
220221
return;
221222
}
@@ -263,7 +264,7 @@ public void RefreshListings(TebexApi.ApiSuccessCallback onSuccess = null)
263264
var response = JsonConvert.DeserializeObject<TebexApi.ListingsResponse>(body);
264265
if (response == null)
265266
{
266-
LogError("Could not get refresh all listings! Response body from API follows:");
267+
LogError("Could not get refresh all listings!:");
267268
LogError(body);
268269
return;
269270
}
@@ -282,7 +283,7 @@ public void RefreshListings(TebexApi.ApiSuccessCallback onSuccess = null)
282283
var response = JsonConvert.DeserializeObject<List<TebexApi.Package>>(body);
283284
if (response == null)
284285
{
285-
LogError("Could not get refresh package listings! Response body from API follows:");
286+
LogError("Could not get refresh package listings!");
286287
LogError(body);
287288
return;
288289
}
@@ -356,15 +357,15 @@ public void GetPackages(GetPackagesResponse onSuccess,
356357
});
357358
}
358359
}
359-
catch (Exception e) //FIXME reports of very infuriating NPE in this func
360+
catch (Exception e)
360361
{
361362
ReportAutoTriageEvent(TebexTriage.CreateAutoTriageEvent("Raised exception while refreshing packages", new Dictionary<string, string>
362363
{
363364
{"cacheHasValid", Cache.Instance.HasValid("packages").ToString()},
364365
{"error", e.Message},
365366
{"trace", e.StackTrace}
366367
}));
367-
LogError("An error occurred while getting your store's packages. This has been reported automatically.");
368+
LogError("An error occurred while getting your store's packages.");
368369
}
369370
}
370371

@@ -535,7 +536,7 @@ public void ProcessCommandQueue(bool ignoreWaitCheck = false)
535536
LogDebug($"Processing online commands for player {duePlayer.Name}...");
536537
if (!IsPlayerOnline(duePlayer.UUID))
537538
{
538-
LogDebug($"Player {duePlayer.Name} has online commands but is not connected. Skipping.");
539+
LogDebug($"> Player {duePlayer.Name} has online commands but is not connected. Skipping.");
539540
continue;
540541
}
541542

TebexOxide/Tebex.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Oxide.Plugins
99
{
10-
[Info("Tebex", "Tebex", "2.0.4")]
10+
[Info("Tebex", "Tebex", "2.0.5")]
1111
[Description("Official support for the Tebex server monetization platform")]
1212
public class Tebex : CovalencePlugin
1313
{
@@ -17,7 +17,7 @@ public class Tebex : CovalencePlugin
1717

1818
public static string GetPluginVersion()
1919
{
20-
return "2.0.4";
20+
return "2.0.5";
2121
}
2222

2323
private void Init()

TebexOxide/TebexOxideAdapter.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public override void MakeWebRequest(string endpoint, string body, TebexApi.HttpV
8080
Enum.TryParse<RequestMethod>(verb.ToString(), true, out method);
8181
if (method == null)
8282
{
83-
LogError($"Unknown HTTP method!: {verb.ToString()}");
84-
LogError($"Failed to interpret HTTP method on request {verb} {endpoint}| {body}");
83+
LogDebug($"Unknown HTTP method!: {verb.ToString()} {endpoint} | {body}");
84+
return;
8585
}
8686

8787
var headers = new Dictionary<string, string>
@@ -193,6 +193,12 @@ public override void MakeWebRequest(string endpoint, string body, TebexApi.HttpV
193193
LogDebug(response);
194194
onServerError?.Invoke(code, response);
195195
}
196+
else if (code == 530) // Cloudflare origin error
197+
{
198+
LogDebug("CDN reported error code, web request not completed: " + code);
199+
LogDebug(response);
200+
onServerError?.Invoke(code, response);
201+
}
196202
else if (code == 0)
197203
{
198204
ReportAutoTriageEvent(TebexTriage.CreateAutoTriageEvent("Request timeout to Plugin API",
@@ -201,7 +207,7 @@ public override void MakeWebRequest(string endpoint, string body, TebexApi.HttpV
201207
{ "request", logOutStr },
202208
{ "response", logInStr },
203209
}));
204-
LogError("Request Timeout from Tebex API. Please try again later.");
210+
LogDebug("Request Timeout from Tebex API. Please try again later.");
205211
}
206212
else // This should be a general failure error message with a JSON-formatted response from the API.
207213
{
@@ -226,7 +232,7 @@ public override void MakeWebRequest(string endpoint, string body, TebexApi.HttpV
226232
{ "request", logOutStr },
227233
{ "response", logInStr },
228234
}));
229-
LogError($"Failed to unmarshal an expected error response from API.");
235+
LogDebug($"Failed to unmarshal an expected error response from API.");
230236
onServerError?.Invoke(code, response);
231237
}
232238

@@ -316,13 +322,16 @@ private void ExecuteServerCommand(TebexApi.Command command, IPlayer player, stri
316322

317323
public override bool IsPlayerOnline(string playerRefId)
318324
{
325+
// Get a reference to the in-game player instance
319326
IPlayer iPlayer = GetPlayerRef(playerRefId) as IPlayer;
320-
if (iPlayer == null) //Ensure the lookup worked
327+
if (iPlayer == null) // Player is not connected
321328
{
322-
LogError($"Attempted to look up online player, but no reference found: {playerRefId}");
323329
return false;
324330
}
325331

332+
// IsConnected might indicate just a connection to the server, but unknown if it's possible to have an IPlayer
333+
// reference and for the player to not actually be connected. This would create a case where we can't
334+
// check inventory slots prior to package delivery.
326335
return iPlayer.IsConnected;
327336
}
328337

@@ -411,6 +420,11 @@ public override string ExpandUsernameVariables(string input, object playerObj)
411420
if (iPlayer == null)
412421
{
413422
LogError($"Could not cast player instance when expanding username variables: {playerObj}");
423+
ReportAutoTriageEvent(TebexTriage.CreateAutoTriageEvent("Could not cast player instance when expanding username variables", new Dictionary<string, string>
424+
{
425+
{"input", input},
426+
{"playerObj", playerObj?.ToString()},
427+
}));
414428
return input;
415429
}
416430

@@ -419,6 +433,12 @@ public override string ExpandUsernameVariables(string input, object playerObj)
419433
LogError($"Player ID or name is null while expanding username?!: {iPlayer}");
420434
LogError($"Base player object: {playerObj}");
421435
LogError($"Input command: {input}");
436+
ReportAutoTriageEvent(TebexTriage.CreateAutoTriageEvent("Player ID or name is null while expanding username?!: ", new Dictionary<string, string>
437+
{
438+
{"input", input},
439+
{"iPlayer.Id", iPlayer.Id},
440+
{"iPlayer.Name", iPlayer.Name}
441+
}));
422442
return input;
423443
}
424444

0 commit comments

Comments
 (0)