From 083a24c756dfdab650ba4336688c66b350530a1a Mon Sep 17 00:00:00 2001 From: Karl Essinger Date: Mon, 25 Jul 2022 13:59:18 +0200 Subject: [PATCH] Fixed NRE when RA commands are used through console --- .../EventListeners/AdminEventListener.cs | 50 ++++++++++++++----- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/SCPDiscordPlugin/EventListeners/AdminEventListener.cs b/SCPDiscordPlugin/EventListeners/AdminEventListener.cs index e596be23..e83b806a 100644 --- a/SCPDiscordPlugin/EventListeners/AdminEventListener.cs +++ b/SCPDiscordPlugin/EventListeners/AdminEventListener.cs @@ -21,21 +21,45 @@ public void OnAdminQuery(AdminQueryEvent ev) { return; } - Dictionary variables = new Dictionary + + if (ev.Admin == null) { - { "ipaddress", ev.Admin.IPAddress }, - { "name", ev.Admin.Name }, - { "playerid", ev.Admin.PlayerID.ToString() }, - { "steamid", ev.Admin.GetParsedUserID() }, - { "class", ev.Admin.PlayerRole.RoleID.ToString() }, - { "team", ev.Admin.PlayerRole.Team.ToString() }, - { "handled", ev.Handled.ToString() }, - { "output", ev.Output }, - { "query", ev.Query }, - { "successful", ev.Successful.ToString() } - }; + Dictionary variables = new Dictionary + { + { "ipaddress", "" }, + { "name", "Server" }, + { "playerid", "" }, + { "steamid", "" }, + { "class", "" }, + { "team", "" }, + { "handled", ev.Handled.ToString() }, + { "output", ev.Output }, + { "query", ev.Query }, + { "successful", ev.Successful.ToString() } + }; + + this.plugin.SendMessage(Config.GetArray("channels.onadminquery"), "admin.onadminquery", variables); + } + else + { + Dictionary variables = new Dictionary + { + { "ipaddress", ev.Admin.IPAddress }, + { "name", ev.Admin.Name }, + { "playerid", ev.Admin.PlayerID.ToString() }, + { "steamid", ev.Admin.GetParsedUserID() }, + { "class", ev.Admin.PlayerRole.RoleID.ToString() }, + { "team", ev.Admin.PlayerRole.Team.ToString() }, + { "handled", ev.Handled.ToString() }, + { "output", ev.Output }, + { "query", ev.Query }, + { "successful", ev.Successful.ToString() } + }; + + this.plugin.SendMessage(Config.GetArray("channels.onadminquery"), "admin.onadminquery", variables); + } + - this.plugin.SendMessage(Config.GetArray("channels.onadminquery"), "admin.onadminquery", variables); } public void OnBan(BanEvent ev)