Skip to content

Commit

Permalink
Merge pull request #42 from ekky-llc/raid-and-profile-manager
Browse files Browse the repository at this point in the history
Milestone: Enhance Fika Support and Refactor Code for Better Performance and Debugging
  • Loading branch information
ekky1328 authored Jun 28, 2024
2 parents 88f8424 + 29688a8 commit ed268e1
Show file tree
Hide file tree
Showing 46 changed files with 1,850 additions and 973 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ Server/src/Web/Server/public/assets/*
Server/src/Web/Server/public/assets/index-7f92f0ab.js
Server/src/Web/Server/public/assets/index-0c1a950b.css
Server/tmp
Tools/**/config.js
Tools/**/cloudflareDump/data/**
1 change: 0 additions & 1 deletion Client/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, int
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
Expand Down
4 changes: 2 additions & 2 deletions Client/RAID-REVIEW.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AssemblyName>RAID_REVIEW__0.0.6</AssemblyName>
<AssemblyName>RAID_REVIEW__0.1.0</AssemblyName>
<AssemblyTitle>RAID_REVIEW</AssemblyTitle>
<AssemblyDescription>A post raid review tool for SPT</AssemblyDescription>
<AssemblyCompany>EkkyLLC</AssemblyCompany>
<AssemblyProduct>RAID_REVIEW</AssemblyProduct>
<AssemblyVersion>0.0.6</AssemblyVersion>
<AssemblyVersion>0.1.0</AssemblyVersion>
<Copyright>2024 © Ekky</Copyright>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>D:\Games\SPT_3.8.1_DEV\BepInEx\plugins\</OutputPath>
Expand Down
21 changes: 10 additions & 11 deletions Client/mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

namespace RAID_REVIEW
{
[BepInPlugin("ekky.raidreview", "Raid Review", "0.0.6")]
[BepInPlugin("ekky.raidreview", "Raid Review", "0.1.0")]
[BepInDependency("me.sol.sain", BepInDependency.DependencyFlags.SoftDependency)]
public class RAID_REVIEW : BaseUnityPlugin
{
Expand All @@ -35,6 +35,7 @@ public class RAID_REVIEW : BaseUnityPlugin
public static float PlayerTrackingInterval = 5f;

// RAID_REVIEW
public static string sessionId = null;
public static bool inRaid = false;
public static bool tracking = false;
public static string RAID_REVIEW_WS_Server = "ws://127.0.0.1:7828";
Expand Down Expand Up @@ -69,10 +70,7 @@ public class RAID_REVIEW : BaseUnityPlugin

// Other Mods
public static bool MODS_SEARCHED = false;
public static bool SOLARINT_SAIN__DETECTED
{
get; set;
}
public static bool SOLARINT_SAIN__DETECTED { get; set; }
public static SAINBotController sainBotController { get; set; }
public static bool searchingForSainComponents = false;
public static Dictionary<string, TrackingPlayer> updatedBots = new Dictionary<string, TrackingPlayer>();
Expand Down Expand Up @@ -115,7 +113,7 @@ void Awake()
Logger.LogInfo("RAID_REVIEW :::: INFO :::: Connected to backend");

}
async void Update()
void Update()
{
try
{
Expand Down Expand Up @@ -146,9 +144,12 @@ async void Update()
if (gameWorld == null || myPlayer == null || gameWorld.LocationId == "hideout")
return;

if (sessionId == null && myPlayer != null) {
sessionId = myPlayer.ProfileId;
}

// PLAYER TRACKING LOOP
IEnumerable<Player> allPlayers = gameWorld.AllPlayersEverExisted;

long captureTime = stopwatch.ElapsedMilliseconds;
foreach (Player player in allPlayers)
{
Expand All @@ -158,12 +159,12 @@ async void Update()

TrackingPlayer trackingPlayer = new TrackingPlayer();
bool isBeingTracked = trackingPlayers.TryGetValue(player.ProfileId, out trackingPlayer);

if (!isBeingTracked)
{

trackingPlayer = new TrackingPlayer
{
sessionId = sessionId,
profileId = player.ProfileId,
name = player.Profile.Nickname,
level = player.Profile.Info.Level,
Expand Down Expand Up @@ -192,7 +193,6 @@ async void Update()


// Checks if a player / bot has died since the last check...

if (player.HealthController.IsAlive)
{

Expand Down Expand Up @@ -234,7 +234,7 @@ async void Update()
float angle = Mathf.Acos(dotProduct) * Mathf.Rad2Deg;
float dir = angle;

var trackingPlayerData = new TrackingPlayerData(player.ProfileId, captureTime, playerPosition.x, playerPosition.y, playerPosition.z, dir);
var trackingPlayerData = new TrackingPlayerData(sessionId, player.ProfileId, captureTime, playerPosition.x, playerPosition.y, playerPosition.z, dir);
_ = Telemetry.Send("POSITION", JsonConvert.SerializeObject(trackingPlayerData));
}

Expand All @@ -257,7 +257,6 @@ public static bool DetectMod(string modName)
{
if (Chainloader.PluginInfos.ContainsKey(modName)) return true;
return false;

}

public static bool MapLoaded() => Singleton<GameWorld>.Instantiated;
Expand Down
20 changes: 7 additions & 13 deletions Client/models/Tracking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ namespace RAID_REVIEW

public class TrackingRaid
{
public string id { get; set; }
public string sessionId { get; set; }
public string profileId { get; set; }
public string location { get; set; }
public string detectedMods { get; set; }
public DateTime time { get; set; }
public long timeInRaid { get; set; }

public string exitName { get; set; }
public ExitStatus exitStatus { get; set; }
}

public class TrackingPlayer
{
public int id { get; set; }
public string sessionId { get; set; }
public string profileId { get; set; }
public int level { get; set; }
public EPlayerSide team { get; set; }
Expand All @@ -35,19 +34,10 @@ public class TrackingPlayer
public string mod_SAIN_difficulty { get; set; }
}

public class TrackingExtractedPlayer
{
public string BotNickname { get; set; }
public string ProfileID { get; set; }
public string Reason { get; set; }
public string ExtractPoint { get; set; }
public float TimeExtracted { get; set; }

}

public class TrackingRaidKill
{
public long time { get; set; }
public string sessionId { get; set; }
public string profileId { get; set; }
public string killedId { get; set; }
public string weapon { get; set; }
Expand All @@ -60,6 +50,7 @@ public class TrackingRaidKill

public class TrackingLootItem
{
public string sessionId { get; set; }
public string profileId { get; set; }
public long time { get; set; }
public string itemId { get; set; }
Expand All @@ -71,6 +62,7 @@ public class TrackingLootItem

public class TrackingPlayerData
{
public string sessionId { get; set; }
public string profileId { get; set; }
public long time { get; set; }
public float x { get; set; }
Expand All @@ -79,13 +71,15 @@ public class TrackingPlayerData
public float dir { get; set; }

public TrackingPlayerData(
string sessionId,
string profileId,
long time,
float x,
float y,
float z,
float dir)
{
this.sessionId = sessionId;
this.profileId = profileId;
this.time = time;
this.x = x;
Expand Down
1 change: 1 addition & 0 deletions Client/patches/player_killpatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ private static void PatchPostFix(ref Player __instance, IPlayer aggressor, Damag
{
var newKill = new TrackingRaidKill
{
sessionId = RAID_REVIEW.sessionId,
time = RAID_REVIEW.stopwatch.ElapsedMilliseconds,
profileId = aggressor.ProfileId,
killedId = __instance.ProfileId,
Expand Down
1 change: 1 addition & 0 deletions Client/patches/player_onGameSessionEndPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ private static void PatchPostFix(ref Player __instance, ExitStatus exitStatus, f
RAID_REVIEW.sainBotController = null;

RAID_REVIEW.stopwatch.Stop();
RAID_REVIEW.trackingRaid.sessionId = RAID_REVIEW.sessionId;
RAID_REVIEW.trackingRaid.profileId = __instance.ProfileId;
RAID_REVIEW.trackingRaid.exitStatus = exitStatus;
RAID_REVIEW.trackingRaid.exitName = exitName;
Expand Down
3 changes: 2 additions & 1 deletion Client/patches/player_onGameStartedPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static void PatchPostFix(ref GameWorld __instance)

RAID_REVIEW.trackingRaid = new TrackingRaid
{
id = Guid.NewGuid().ToString("D"),
sessionId = RAID_REVIEW.sessionId,
profileId = RAID_REVIEW.myPlayer.ProfileId,
time = DateTime.Now,
detectedMods = RAID_REVIEW.RAID_REVIEW__DETECTED_MODS.Count > 0 ? string.Join(",", RAID_REVIEW.RAID_REVIEW__DETECTED_MODS) : "",
Expand All @@ -60,6 +60,7 @@ private static void PatchPostFix(ref GameWorld __instance)

var newTrackingPlayer = new TrackingPlayer
{
sessionId = RAID_REVIEW.sessionId,
profileId = RAID_REVIEW.myPlayer.ProfileId,
name = RAID_REVIEW.myPlayer.Profile.Nickname,
level = RAID_REVIEW.myPlayer.Profile.Info.Level,
Expand Down
20 changes: 11 additions & 9 deletions Client/patches/player_onItemAddedOrRemovedPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ private static void PatchPostFix(ref Player __instance, Item item, ItemAddress l
bool isPackingMagazine = location.Container.ID == "cartridges";
if (RAID_REVIEW.LootTracking.Value && !isPackingMagazine)
{
TrackingLootItem newLootItem = new TrackingLootItem();

newLootItem.profileId = __instance.ProfileId;
newLootItem.time = RAID_REVIEW.stopwatch.ElapsedMilliseconds;
newLootItem.itemId = item.Id;
newLootItem.itemName = item.ShortName;
newLootItem.qty = item.StackObjectsCount;
newLootItem.type = item.QuestItem ? "QUEST_ITEM" : "LOOT";
newLootItem.added = added;
TrackingLootItem newLootItem = new TrackingLootItem
{
sessionId = RAID_REVIEW.sessionId,
profileId = __instance.ProfileId,
time = RAID_REVIEW.stopwatch.ElapsedMilliseconds,
itemId = item.Id,
itemName = item.ShortName,
qty = item.StackObjectsCount,
type = item.QuestItem ? "QUEST_ITEM" : "LOOT",
added = added
};

if (!added)
{
Expand Down
7 changes: 7 additions & 0 deletions Server/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": true,
"printWidth": 250
}
65 changes: 33 additions & 32 deletions Server/config.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
{
"do_not_delete_1" : "[👇🏾 DO NOT MODIFY]",
"settings_schema_version" : 1,
"do_not_delete_2" : "[☝🏾 DO NOT MODIFY]",
"do_not_delete_1": "[👇🏾 DO NOT MODIFY]",
"settings_schema_version": 2,
"do_not_delete_2": "[☝🏾 DO NOT MODIFY]",


"00_comment" : "[SERVER] [DEFAULT: 7828] Changes Default Web Socket port, modify this if port is reserved in your environment.",
"web_socket_port" : 7828,
"01_comment" : "[SERVER] [DEFAULT: 7829] Changes Default HTTP port, modify this if port is reserved in your environment.",
"comment__enableDebugLogs": "[DEBUG] [DEFAULT: true] Enable debug logging.",
"enableDebugLogs": true,
"comment__enableLogFiles": "[DEBUG] [DEFAULT: true] If enabled, dumps normal logs `/logs` meant for support/debugging purposes.",
"enableLogFiles": true,
"comment__enableVerboseLogFiles": "[DEBUG] [DEFAULT: true] If enabled, dumps all logs `/logs` meant for support/debugging purposes.",
"enableVerboseLogFiles": true,
"comment__maximumLogFiles": "[DEBUG] [DEFAULT: 10] If 'LogFiles' are enabled, this is the maximum number of logs allowed to be stored; oldest logs will be deleted.",
"maximumLogFiles": 10,


"comment__web_socket_port": "[SERVER] [DEFAULT: 7828] Changes Default Web Socket port; modify this if the port is reserved in your environment.",
"web_socket_port": 7828,
"comment__web_client_port": "[SERVER] [DEFAULT: 7829] Changes Default HTTP port; modify this if the port is reserved in your environment.",
"web_client_port": 7829,


"02_comment" : "[TELEMETRY] [DEFAULT: true] Contribute end of raid statistics to the 'https://raid-review.online' server, more info here: https://github.com/ekky-llc/spt-raid-review/blob/main/TELEMETRY.md.",
"telemetry" : true,


"03_comment": "[AUTO-DELETE] [DEFAULT: true] Automatically delete old raids to save disk space, runs on start up.",
"autoDelete" : true,
"04_comment": "[AUTO-DELETE] [DEFAULT: true] Automatically delete unfinished raids (due to crash, alt+f4 etc), runs on start up.",
"autoDeleteUnfinishedRaids" : true,
"05_comment": "[AUTO-DELETE] [DEFAULT: false] If this is 'true', 'autoDelete' functions will run once an hour, helpful if you don't generally restart the SPT Server.",
"autoDeleteCronJob" : false,
"06_comment": "[AUTO-DELETE] [DEFAULT: 30] If this is 'true', this is the maximum number of raids allowed to be stored, oldest raid will be deleted.",
"autoDeleteLimit" : 30,


"07_comment": "[AUTH] [DEFAULT: false] Enable Basic Auth, use this setting if you'd like to password protect web server.",
"basic_auth" : false,
"08_comment" : "[AUTH] If Basic Auth Enabled, use this to register username/passwords.",
"users" : {
"admin" : "password",
"guest" : "password"
},
"09_comment" : "[AUTH] If Basic Auth Enabled, use this to mark user as an admin.",
"admin" : {
"admin" : true,
"guest" : false
}
"comment__telemetry": "[TELEMETRY] [DEFAULT: true] Contribute end of raid statistics to the 'https://raid-review.online' server. More info here: https://github.com/ekky-llc/spt-raid-review/blob/main/TELEMETRY.md.",
"telemetry": true,


"comment__autoDelete": "[AUTO-DELETE] [DEFAULT: true] Automatically delete old raids to save disk space; runs on startup.",
"autoDelete": true,
"comment__autoDeleteUnfinishedRaids": "[AUTO-DELETE] [DEFAULT: true] Automatically delete unfinished raids (due to crash, alt+f4, etc.); runs on startup.",
"autoDeleteUnfinishedRaids": true,
"comment__autoDeleteCronJob": "[AUTO-DELETE] [DEFAULT: false] If true, 'autoDelete' functions will run once an hour; helpful if you don't generally restart the SPT Server.",
"autoDeleteCronJob": false,
"comment__autoDeleteLimit": "[AUTO-DELETE] [DEFAULT: 30] Maximum number of raids allowed to be stored; oldest raid will be deleted.",
"autoDeleteLimit": 30,


"comment__authentication": "[AUTH] [DEFAULT: true] Enable Basic Authentication; use this setting if you'd like to password-protect the web server.",
"authentication": true,
"comment__authentication_extra_info": "The credentials is the username of the profile you use in SPT."
}
2 changes: 1 addition & 1 deletion Server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "raid-review",
"version": "0.0.6",
"version": "0.1.0",
"main": "src/mod.js",
"license": "MIT",
"author": "ekky",
Expand Down
11 changes: 6 additions & 5 deletions Server/src/Controllers/Collection/GetRaidData.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Database } from "sqlite";
import sqlite3 from 'sqlite3'
import { FileExists } from "../FileSystem/DataSaver";
import { Logger } from "../../Utils/logger";

export async function getRaidData(db: Database<sqlite3.Database, sqlite3.Statement>, raidId: string) {
export async function getRaidData(db: Database<sqlite3.Database, sqlite3.Statement>, logger: Logger, raidId: string) {

// Need to fix this; N+1 Problem
const sqlRaidQuery = `SELECT * FROM raid WHERE timeInRaid > 10 AND raidId = ?`;
const sqlRaidValues = [raidId];
const raid = await db
.get(sqlRaidQuery, sqlRaidValues)
.catch((e: Error) => console.error(e));
.catch((e: Error) => logger.error(`[ERR:GET_RAID_DATA_CORE] `, e));

const keys = ["kills", "looting", "player"];
for (let i = 0; i < keys.length; i++) {
Expand All @@ -21,13 +22,13 @@ export async function getRaidData(db: Database<sqlite3.Database, sqlite3.Stateme
}

const sqlKeyValues = [raidId];
const sqlResult = await db.all(sqlKeyQuery, sqlKeyValues).catch((e: Error) => console.error(e));
const sqlResult = await db.all(sqlKeyQuery, sqlKeyValues).catch((e: Error) => logger.error(`[ERR:GET_RAID_DATA_KEYS] `, e));
raid[key] = sqlResult || [];
}

// Positions check
const rawPositionData = FileExists("positions","","",`${raidId}_positions`);
const compiledPositionData = FileExists("positions","","",`${raidId}_V2_positions.json`);
const rawPositionData = FileExists(logger, "positions","","",`${raidId}_positions`);
const compiledPositionData = FileExists(logger, "positions","","",`${raidId}_V2_positions.json`);
raid.positionsTracked = compiledPositionData ? 'COMPILED' : rawPositionData ? 'RAW' : 'NOT_AVAILABLE';

// Quick Fix
Expand Down
Empty file.
Loading

0 comments on commit ed268e1

Please sign in to comment.