Skip to content

Commit

Permalink
better support for offline raids
Browse files Browse the repository at this point in the history
  • Loading branch information
Razzmatazzz committed Jul 14, 2024
1 parent 45db343 commit a49e76f
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 37 deletions.
26 changes: 24 additions & 2 deletions TarkovMonitor/Blazor/Components/MessageBoard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
</span>
</div>
<div class="d-flex align-center">
@foreach (MonitorMessageSelect select in message.Selects)
{

<MudSelect T="MonitorMessageSelectOption" Placeholder="@select.Placeholder" SelectedValuesChanged="@((e) => MessageSelectChanged(select, e) )">
@foreach (MonitorMessageSelectOption option in select.Options)
{
<MudSelectItem Value="@option">@option.Text</MudSelectItem>
}
</MudSelect>
}
@foreach (MonitorMessageButton button in message.Buttons)
{
<MudButton Variant="Variant.Filled" Color="@button.Color" StartIcon="@button.Icon" OnClick="@((e) => MessageButtonClick(button) )">@button.Text</MudButton>
Expand All @@ -38,8 +48,8 @@

</MudStack>

@code {
// Force refresh every minute to update timestamps
@code {
// Force refresh every minute to update timestamps
Timer? timer;

protected override void OnInitialized()
Expand Down Expand Up @@ -161,4 +171,16 @@
messageLog.AddMessage($"Error in message button: ${ex.Message} {ex.StackTrace}", "exception");
}
}

private async void MessageSelectChanged(MonitorMessageSelect select, IEnumerable<MonitorMessageSelectOption> selected)
{
try
{
select.ChangeSelection(selected.First());
}
catch (Exception ex)
{
messageLog.AddMessage($"Error in message select: ${ex.Message} {ex.StackTrace}", "exception");
}
}
}
98 changes: 69 additions & 29 deletions TarkovMonitor/MainBlazorUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private void Eft_RaidEnded(object? sender, RaidInfoEventArgs e)
}
messageLog.AddMessage(monMessage);
runthroughTimer.Stop();
if (e.RaidInfo.RaidType == RaidType.Scav && Properties.Settings.Default.scavCooldownAlert)
if (Properties.Settings.Default.scavCooldownAlert && (e.RaidInfo.RaidType == RaidType.Scav || e.RaidInfo.RaidType == RaidType.PVE))
{
scavCooldownTimer.Stop();
scavCooldownTimer.Interval = TimeSpan.FromSeconds(TarkovDev.ResetScavCoolDown()).TotalMilliseconds;
Expand Down Expand Up @@ -630,25 +630,40 @@ private async void Eft_RaidStart(object? sender, RaidInfoEventArgs e)
MonitorMessage monMessage = new($"Starting {e.RaidInfo.RaidType} raid on {mapName}");
if (map != null && e.RaidInfo.StartedTime != null && map.HasGoons())
{
MonitorMessageButton goonsButton = new($"Report Goons", Icons.Material.Filled.Groups);
goonsButton.OnClick = async () => {
try
AddGoonsButton(monMessage, e.RaidInfo);
}
else if (map == null)
{
monMessage.Message = $"Starting {e.RaidInfo.RaidType} raid on:";
MonitorMessageSelect select = new();
foreach (var gameMap in TarkovDev.Maps)
{
select.Options.Add(new(gameMap.name, gameMap.nameId));
}
select.Placeholder = "Select map";
monMessage.Selects.Add(select);
MonitorMessageButton mapButton = new("Set map", Icons.Material.Filled.Map);
mapButton.OnClick += () => {
if (select.Selected == null)
{
await TarkovDev.PostGoonsSighting(e.RaidInfo.Map, (DateTime)e.RaidInfo.StartedTime, eft.AccountId);
messageLog.AddMessage($"Goons reported on {mapName}", "info");
return;
}
catch (Exception ex) {
messageLog.AddMessage($"Error reporting goons: {ex.Message} {ex.StackTrace}", "exception");
e.RaidInfo.Map = select.Selected.Value;
monMessage.Message = $"Starting {e.RaidInfo.RaidType} raid on {select.Selected.Text}";
monMessage.Buttons.Clear();
monMessage.Selects.Clear();
//AddGoonsButton(monMessage, e.RaidInfo); // offline raids have goons on all goons maps
if (Properties.Settings.Default.autoNavigateMap)
{
var map = TarkovDev.Maps.Find(m => m.nameId == e.RaidInfo.Map);
if (map == null)
{
return;
}
SocketClient.NavigateToMap(map);
}
monMessage.Buttons.Remove(goonsButton);
};
goonsButton.Confirm = new(
$"Report Goons on {mapName}",
"<p>Please only submit a report if you saw the goons in this raid.</p><p><strong>Notice:</strong> By submitting a goons report, you consent to collection of your IP address and EFT account id for report verification purposes.</p>",
"Submit report", "Cancel"
);
goonsButton.Timeout = TimeSpan.FromMinutes(120).TotalMilliseconds;
monMessage.Buttons.Add(goonsButton);
monMessage.Buttons.Add(mapButton);
}
messageLog.AddMessage(monMessage);
if (Properties.Settings.Default.raidStartAlert && e.RaidInfo.StartingTime == null)
Expand All @@ -661,26 +676,51 @@ private async void Eft_RaidStart(object? sender, RaidInfoEventArgs e)
{
messageLog.AddMessage($"Re-entering raid on {mapName}");
}
if (e.RaidInfo.Reconnected || !e.RaidInfo.Online || e.RaidInfo.QueueTime == 0 || e.RaidInfo.RaidType == RaidType.Unknown)
{
return;
}
if (Properties.Settings.Default.runthroughAlert && e.RaidInfo.RaidType == RaidType.PMC)
if (Properties.Settings.Default.runthroughAlert && !e.RaidInfo.Reconnected && (e.RaidInfo.RaidType == RaidType.PMC || e.RaidInfo.RaidType == RaidType.PVE))
{
runthroughTimer.Stop();
runthroughTimer.Start();
}
if (!Properties.Settings.Default.submitQueueTime || e.Profile.Type == ProfileType.PVE)
if (Properties.Settings.Default.submitQueueTime && e.RaidInfo.QueueTime > 0 && e.RaidInfo.RaidType != RaidType.Unknown)
{
return;
}
try
{
await TarkovDev.PostQueueTime(e.RaidInfo.Map, (int)Math.Round(e.RaidInfo.QueueTime), e.RaidInfo.RaidType.ToString().ToLower());
try
{
await TarkovDev.PostQueueTime(e.RaidInfo.Map, (int)Math.Round(e.RaidInfo.QueueTime), e.RaidInfo.RaidType.ToString().ToLower(), eft.CurrentProfile.Type);
}
catch (Exception ex)
{
messageLog.AddMessage($"Error submitting queue time: {ex.Message}", "exception");
}
}
catch (Exception ex)
}

private void AddGoonsButton(MonitorMessage monMessage, RaidInfo raidInfo)
{
var mapName = raidInfo.Map;
var map = TarkovDev.Maps.Find(m => m.nameId == mapName);
if (map != null) mapName = map.name;
if (map != null && raidInfo.StartedTime != null && map.HasGoons())
{
messageLog.AddMessage($"Error submitting queue time: {ex.Message}", "exception");
MonitorMessageButton goonsButton = new($"Report Goons", Icons.Material.Filled.Groups);
goonsButton.OnClick = async () => {
try
{
await TarkovDev.PostGoonsSighting(raidInfo.Map, (DateTime)raidInfo.StartedTime, eft.AccountId, eft.CurrentProfile.Type);
messageLog.AddMessage($"Goons reported on {mapName}", "info");
}
catch (Exception ex)
{
messageLog.AddMessage($"Error reporting goons: {ex.Message} {ex.StackTrace}", "exception");
}
monMessage.Buttons.Remove(goonsButton);
};
goonsButton.Confirm = new(
$"Report Goons on {mapName}",
"<p>Please only submit a report if you saw the goons in this raid.</p><p><strong>Notice:</strong> By submitting a goons report, you consent to collection of your IP address and EFT account id for report verification purposes.</p>",
"Submit report", "Cancel"
);
goonsButton.Timeout = TimeSpan.FromMinutes(120).TotalMilliseconds;
monMessage.Buttons.Add(goonsButton);
}
}

Expand Down
34 changes: 34 additions & 0 deletions TarkovMonitor/MonitorMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class MonitorMessage
public string Url { get; set; } = "";
public Action? OnClick { get; set; } = null;
public ObservableCollection<MonitorMessageButton> Buttons { get; set; } = new();
public ObservableCollection<MonitorMessageSelect> Selects { get; set; } = new();
public MonitorMessage(string message)
{
Message = message;
Expand Down Expand Up @@ -142,4 +143,37 @@ public MonitorMessageButtonConfirm(string title, string message, string yesText,
CancelText = cancelText;
}
}

public class MonitorMessageSelect
{
public List<MonitorMessageSelectOption> Options { get; set; } = new();
public event EventHandler<MonitorMessageSelectChangedEventArgs>? SelectionChanged;
public MonitorMessageSelectOption? Selected { get; private set; }
public string Placeholder { get; set; } = "";
public void ChangeSelection(MonitorMessageSelectOption selected)
{
Selected = selected;
SelectionChanged?.Invoke(this, new MonitorMessageSelectChangedEventArgs() { Selected = selected });
}
}

public class MonitorMessageSelectOption
{
public string Text { get; set; }
public string Value { get; set; }
override public string ToString()
{
return Text;
}
public MonitorMessageSelectOption(string text, string value)
{
Text = text;
Value = value;
}
}

public class MonitorMessageSelectChangedEventArgs : EventArgs
{
public MonitorMessageSelectOption Selected { get; set; }
}
}
3 changes: 1 addition & 2 deletions TarkovMonitor/SocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private static string GetId(int length)
string characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

Random r = new Random();
int rInt = r.Next(0, characters.Length);
//int rInt = r.Next(0, characters.Length);

for (int i = 0; i < length; i++)
{
Expand Down Expand Up @@ -100,7 +100,6 @@ public static async Task Connect()
catch (Exception ex) {
ExceptionThrown?.Invoke(null, new(ex, $"Connecting with id {Properties.Settings.Default.remoteId}"));
}

}

private static void SettingChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
Expand Down
10 changes: 6 additions & 4 deletions TarkovMonitor/TarkovDev.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ query TarkovMonitorPlayerLevels {
return PlayerLevels;
}

public async static Task<DataSubmissionResponse> PostQueueTime(string mapNameId, int queueTime, string type)
public async static Task<DataSubmissionResponse> PostQueueTime(string mapNameId, int queueTime, string type, ProfileType gameMode)
{
try
{
return await api.SubmitQueueTime(new QueueTimeBody() { map = mapNameId, time = queueTime, type = type });
return await api.SubmitQueueTime(new QueueTimeBody() { map = mapNameId, time = queueTime, type = type, gameMode = gameMode.ToString().ToLower() });
}
catch (ApiException ex)
{
Expand All @@ -246,11 +246,11 @@ public async static Task<DataSubmissionResponse> PostQueueTime(string mapNameId,
}
}

public async static Task<DataSubmissionResponse> PostGoonsSighting(string mapNameId, DateTime date, int accountId)
public async static Task<DataSubmissionResponse> PostGoonsSighting(string mapNameId, DateTime date, int accountId, ProfileType profileType)
{
try
{
return await api.SubmitGoonsSighting(new GoonsBody() { map = mapNameId, timestamp = ((DateTimeOffset)date).ToUnixTimeMilliseconds(), accountId = accountId });
return await api.SubmitGoonsSighting(new GoonsBody() { map = mapNameId, gameMode = profileType.ToString().ToLower(), timestamp = ((DateTimeOffset)date).ToUnixTimeMilliseconds(), accountId = accountId });
}
catch (ApiException ex)
{
Expand Down Expand Up @@ -471,6 +471,7 @@ public class QueueTimeBody
public string map { get; set; }
public int time { get; set; }
public string type { get; set; }
public string gameMode { get; set; }
}

public class DataSubmissionResponse
Expand All @@ -481,6 +482,7 @@ public class DataSubmissionResponse
public class GoonsBody
{
public string map { get; set; }
public string gameMode { get; set; }
public long timestamp { get; set; }
public int accountId { get; set; }
}
Expand Down

0 comments on commit a49e76f

Please sign in to comment.