Skip to content

Commit

Permalink
add raw socket option for vpn support
Browse files Browse the repository at this point in the history
  • Loading branch information
snoww committed Apr 28, 2023
1 parent 7974bad commit 58a6bc8
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 54 deletions.
Binary file modified src-tauri/lib/meter-core-x86_64-pc-windows-msvc.exe
Binary file not shown.
15 changes: 14 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@ fn main() {
{
meter_window.open_devtools();
}

let mut packet_mode = "pcap".to_string();

#[cfg(target_os = "windows")]
{
if let Some(settings) = settings {
if settings.general.blur {
apply_blur(&meter_window, Some((10, 10, 10, 50))).ok();
}
if settings.general.raw_socket {
packet_mode = "raw".to_string();
}
} else {
apply_blur(&meter_window, Some((10, 10, 10, 50))).ok();
}
Expand All @@ -64,7 +69,8 @@ fn main() {

tauri::async_runtime::spawn(async move {
let (mut rx, _child) = Command::new_sidecar("meter-core")
.expect("failed to start `meter-core` ")
.expect("failed to start `meter-core`")
.args(["--mode", &packet_mode])
.spawn()
.expect("Failed to spawn sidecar");
let mut parser = Parser::new(&meter_window);
Expand Down Expand Up @@ -102,6 +108,13 @@ fn main() {
});
}
last_time = Instant::now();
} else if let CommandEvent::Stderr(line) = event {
if line == "not admin" {
std::thread::sleep(Duration::from_secs(3));
let window = meter_window.clone();
window.emit("admin", "")
.expect("failed to emit admin error");
}
}
}
});
Expand Down
81 changes: 32 additions & 49 deletions src-tauri/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,28 +307,8 @@ impl Parser<'_> {
npc.current_hp = new_npc.current_hp;
npc.max_hp = new_npc.max_hp;
npc.last_update = timestamp;
if let Some((_, npc_info)) = NPC_DATA.get_key_value(&new_npc.npc_id) {
if npc_info.grade == "boss"
|| npc_info.grade == "raid"
|| npc_info.grade == "epic_raid"
|| npc_info.grade == "commander"
{
npc.entity_type = EntityType::BOSS;
} else {
npc.entity_type = EntityType::NPC;
}
}
npc.entity_type = get_npc_entity_type(new_npc.npc_id);
} else {
let mut entity_type = EntityType::NPC;
if let Some((_, npc_info)) = NPC_DATA.get_key_value(&new_npc.npc_id) {
if npc_info.grade == "boss"
|| npc_info.grade == "raid"
|| npc_info.grade == "epic_raid"
|| npc_info.grade == "commander"
{
entity_type = EntityType::BOSS;
}
}
self.encounter.entities.insert(
new_npc.name.to_string(),
Entity {
Expand All @@ -337,43 +317,29 @@ impl Parser<'_> {
name: new_npc.name.to_string(),
current_hp: new_npc.current_hp,
max_hp: new_npc.max_hp,
entity_type,
entity_type: get_npc_entity_type(new_npc.npc_id),
last_update: timestamp,
..Default::default()
},
);
}

if self.encounter.current_boss_name.is_empty() {
if let Some((_, npc)) = NPC_DATA.get_key_value(&new_npc.npc_id) {
if npc.grade == "boss"
|| npc.grade == "raid"
|| npc.grade == "epic_raid"
|| npc.grade == "commander"
// get the npc that we just added
if let Some(npc) = self.encounter.entities.get(new_npc.name) {
if npc.entity_type == EntityType::BOSS {
if self.encounter.current_boss_name.is_empty() {
self.encounter.current_boss_name = npc.name.to_string();
} else if let Some(boss) = self
.encounter
.entities
.get(&self.encounter.current_boss_name.to_string())
{
self.encounter.current_boss_name = new_npc.name.to_string();
}
}
} else if !self.encounter.current_boss_name.is_empty() {
// if for some reason current_boss_name is not in the entities list, reset it
if let Some(boss) = self
.encounter
.entities
.get(&self.encounter.current_boss_name.to_string())
{
if new_npc.max_hp >= boss.max_hp && boss.is_dead {
if let Some((_, npc)) = NPC_DATA.get_key_value(&new_npc.npc_id) {
if npc.grade == "boss"
|| npc.grade == "raid"
|| npc.grade == "epic_raid"
|| npc.grade == "commander"
{
self.encounter.current_boss_name = new_npc.name.to_string();
}
if npc.max_hp >= boss.max_hp && boss.is_dead {
self.encounter.current_boss_name = npc.name.to_string();
}
} else {
self.encounter.current_boss_name = npc.name.to_string();
}
} else {
self.encounter.current_boss_name = "".to_string();
}
}
}
Expand Down Expand Up @@ -985,6 +951,23 @@ impl Parser<'_> {
}
}

fn get_npc_entity_type(npc_id: i32) -> EntityType {
if let Some((_, npc_info)) = NPC_DATA.get_key_value(&npc_id) {
if npc_info.grade == "boss"
|| npc_info.grade == "raid"
|| npc_info.grade == "epic_raid"
|| npc_info.grade == "commander"
&& !npc_info.name.contains('_')
{
EntityType::BOSS
} else {
EntityType::NPC
}
} else {
EntityType::NPC
}
}

fn is_support_class_id(class_id: i32) -> bool {
class_id == 105 || class_id == 204 || class_id == 602
}
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/parser/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ pub struct Settings {
pub struct GeneralSettings {
pub show_names: bool,
pub accent_color: String,
pub raw_socket: bool,
pub port: i32,
pub blur: bool,
}

Expand Down
11 changes: 10 additions & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@
"open": true,
"sidecar": true,
"scope": [
{ "name": "lib/meter-core", "sidecar": true }
{
"name": "lib/meter-core",
"sidecar": true,
"args": [
"--mode",
{
"validator": "\\S+"
}
]
}
]
},
"process": {
Expand Down
19 changes: 16 additions & 3 deletions src/lib/components/DamageMeter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
let phaseTransitionAlert = false;
let bossDeadAlert = false;
let raidInProgress = true;
let adminAlert = false;
onMount(() => {
setInterval(() => {
Expand Down Expand Up @@ -62,21 +63,24 @@
setTimeout(() => {
bossDeadAlert = false;
}, 3000);
}
else if (phaseCode === 2 && raidInProgress) {
} else if (phaseCode === 2 && raidInProgress) {
phaseTransitionAlert = true;
setTimeout(() => {
phaseTransitionAlert = false;
}, 3000);
}
raidInProgress = false;
});
let adminError = await listen('admin', (_) => {
adminAlert = true;
});
events.push(
encounterUpdateEvent,
zoneChangeEvent,
phaseTransitionEvent,
raidStartEvent
raidStartEvent,
adminError
);
})();
});
Expand Down Expand Up @@ -254,4 +258,13 @@
</Alert>
</div>
{/if}
{#if adminAlert}
<div transition:fade>
<Alert color="none" class="bg-red-700 w-56 mx-auto absolute inset-x-0 bottom-8 py-2 z-50">
<span slot="icon"><svg aria-hidden="true" class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"></path></svg>
</span>
Please restart as Admin
</Alert>
</div>
{/if}
<Footer bind:tab={tab}/>
2 changes: 2 additions & 0 deletions src/lib/utils/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export const defaultSettings = {
"general": {
"showNames": true,
"accentColor": "theme-pink",
"rawSocket": false,
"port": 6040,
"blur": true,
},
"shortcuts": {
Expand Down
1 change: 1 addition & 0 deletions src/routes/settings/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
</div>
</label>
</div>
<SettingItem name="VPN Support (beta)" description="Enables raw socket capture. (manually restart as ADMIN)" bind:setting={$settings.general.rawSocket} />
<div class="pt-2" on:focusout={handleDropdownFocusLoss}>
<div class="flex font-medium items-center">
<button id="" class="font-medium rounded-lg text-sm px-2 py-2 text-center inline-flex items-center bg-accent-800" type="button" on:click={handleDropdownClick}>
Expand Down

0 comments on commit 58a6bc8

Please sign in to comment.