Skip to content

Commit 58a6bc8

Browse files
committed
add raw socket option for vpn support
1 parent 7974bad commit 58a6bc8

File tree

8 files changed

+77
-54
lines changed

8 files changed

+77
-54
lines changed
-960 Bytes
Binary file not shown.

src-tauri/src/main.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,18 @@ fn main() {
4343
{
4444
meter_window.open_devtools();
4545
}
46+
47+
let mut packet_mode = "pcap".to_string();
4648

4749
#[cfg(target_os = "windows")]
4850
{
4951
if let Some(settings) = settings {
5052
if settings.general.blur {
5153
apply_blur(&meter_window, Some((10, 10, 10, 50))).ok();
5254
}
55+
if settings.general.raw_socket {
56+
packet_mode = "raw".to_string();
57+
}
5358
} else {
5459
apply_blur(&meter_window, Some((10, 10, 10, 50))).ok();
5560
}
@@ -64,7 +69,8 @@ fn main() {
6469

6570
tauri::async_runtime::spawn(async move {
6671
let (mut rx, _child) = Command::new_sidecar("meter-core")
67-
.expect("failed to start `meter-core` ")
72+
.expect("failed to start `meter-core`")
73+
.args(["--mode", &packet_mode])
6874
.spawn()
6975
.expect("Failed to spawn sidecar");
7076
let mut parser = Parser::new(&meter_window);
@@ -102,6 +108,13 @@ fn main() {
102108
});
103109
}
104110
last_time = Instant::now();
111+
} else if let CommandEvent::Stderr(line) = event {
112+
if line == "not admin" {
113+
std::thread::sleep(Duration::from_secs(3));
114+
let window = meter_window.clone();
115+
window.emit("admin", "")
116+
.expect("failed to emit admin error");
117+
}
105118
}
106119
}
107120
});

src-tauri/src/parser/mod.rs

Lines changed: 32 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -307,28 +307,8 @@ impl Parser<'_> {
307307
npc.current_hp = new_npc.current_hp;
308308
npc.max_hp = new_npc.max_hp;
309309
npc.last_update = timestamp;
310-
if let Some((_, npc_info)) = NPC_DATA.get_key_value(&new_npc.npc_id) {
311-
if npc_info.grade == "boss"
312-
|| npc_info.grade == "raid"
313-
|| npc_info.grade == "epic_raid"
314-
|| npc_info.grade == "commander"
315-
{
316-
npc.entity_type = EntityType::BOSS;
317-
} else {
318-
npc.entity_type = EntityType::NPC;
319-
}
320-
}
310+
npc.entity_type = get_npc_entity_type(new_npc.npc_id);
321311
} else {
322-
let mut entity_type = EntityType::NPC;
323-
if let Some((_, npc_info)) = NPC_DATA.get_key_value(&new_npc.npc_id) {
324-
if npc_info.grade == "boss"
325-
|| npc_info.grade == "raid"
326-
|| npc_info.grade == "epic_raid"
327-
|| npc_info.grade == "commander"
328-
{
329-
entity_type = EntityType::BOSS;
330-
}
331-
}
332312
self.encounter.entities.insert(
333313
new_npc.name.to_string(),
334314
Entity {
@@ -337,43 +317,29 @@ impl Parser<'_> {
337317
name: new_npc.name.to_string(),
338318
current_hp: new_npc.current_hp,
339319
max_hp: new_npc.max_hp,
340-
entity_type,
320+
entity_type: get_npc_entity_type(new_npc.npc_id),
341321
last_update: timestamp,
342322
..Default::default()
343323
},
344324
);
345325
}
346326

347-
if self.encounter.current_boss_name.is_empty() {
348-
if let Some((_, npc)) = NPC_DATA.get_key_value(&new_npc.npc_id) {
349-
if npc.grade == "boss"
350-
|| npc.grade == "raid"
351-
|| npc.grade == "epic_raid"
352-
|| npc.grade == "commander"
327+
// get the npc that we just added
328+
if let Some(npc) = self.encounter.entities.get(new_npc.name) {
329+
if npc.entity_type == EntityType::BOSS {
330+
if self.encounter.current_boss_name.is_empty() {
331+
self.encounter.current_boss_name = npc.name.to_string();
332+
} else if let Some(boss) = self
333+
.encounter
334+
.entities
335+
.get(&self.encounter.current_boss_name.to_string())
353336
{
354-
self.encounter.current_boss_name = new_npc.name.to_string();
355-
}
356-
}
357-
} else if !self.encounter.current_boss_name.is_empty() {
358-
// if for some reason current_boss_name is not in the entities list, reset it
359-
if let Some(boss) = self
360-
.encounter
361-
.entities
362-
.get(&self.encounter.current_boss_name.to_string())
363-
{
364-
if new_npc.max_hp >= boss.max_hp && boss.is_dead {
365-
if let Some((_, npc)) = NPC_DATA.get_key_value(&new_npc.npc_id) {
366-
if npc.grade == "boss"
367-
|| npc.grade == "raid"
368-
|| npc.grade == "epic_raid"
369-
|| npc.grade == "commander"
370-
{
371-
self.encounter.current_boss_name = new_npc.name.to_string();
372-
}
337+
if npc.max_hp >= boss.max_hp && boss.is_dead {
338+
self.encounter.current_boss_name = npc.name.to_string();
373339
}
340+
} else {
341+
self.encounter.current_boss_name = npc.name.to_string();
374342
}
375-
} else {
376-
self.encounter.current_boss_name = "".to_string();
377343
}
378344
}
379345
}
@@ -985,6 +951,23 @@ impl Parser<'_> {
985951
}
986952
}
987953

954+
fn get_npc_entity_type(npc_id: i32) -> EntityType {
955+
if let Some((_, npc_info)) = NPC_DATA.get_key_value(&npc_id) {
956+
if npc_info.grade == "boss"
957+
|| npc_info.grade == "raid"
958+
|| npc_info.grade == "epic_raid"
959+
|| npc_info.grade == "commander"
960+
&& !npc_info.name.contains('_')
961+
{
962+
EntityType::BOSS
963+
} else {
964+
EntityType::NPC
965+
}
966+
} else {
967+
EntityType::NPC
968+
}
969+
}
970+
988971
fn is_support_class_id(class_id: i32) -> bool {
989972
class_id == 105 || class_id == 204 || class_id == 602
990973
}

src-tauri/src/parser/models.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ pub struct Settings {
377377
pub struct GeneralSettings {
378378
pub show_names: bool,
379379
pub accent_color: String,
380+
pub raw_socket: bool,
381+
pub port: i32,
380382
pub blur: bool,
381383
}
382384

src-tauri/tauri.conf.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@
3131
"open": true,
3232
"sidecar": true,
3333
"scope": [
34-
{ "name": "lib/meter-core", "sidecar": true }
34+
{
35+
"name": "lib/meter-core",
36+
"sidecar": true,
37+
"args": [
38+
"--mode",
39+
{
40+
"validator": "\\S+"
41+
}
42+
]
43+
}
3544
]
3645
},
3746
"process": {

src/lib/components/DamageMeter.svelte

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
let phaseTransitionAlert = false;
2424
let bossDeadAlert = false;
2525
let raidInProgress = true;
26+
let adminAlert = false;
2627
2728
onMount(() => {
2829
setInterval(() => {
@@ -62,21 +63,24 @@
6263
setTimeout(() => {
6364
bossDeadAlert = false;
6465
}, 3000);
65-
}
66-
else if (phaseCode === 2 && raidInProgress) {
66+
} else if (phaseCode === 2 && raidInProgress) {
6767
phaseTransitionAlert = true;
6868
setTimeout(() => {
6969
phaseTransitionAlert = false;
7070
}, 3000);
7171
}
7272
raidInProgress = false;
7373
});
74+
let adminError = await listen('admin', (_) => {
75+
adminAlert = true;
76+
});
7477
7578
events.push(
7679
encounterUpdateEvent,
7780
zoneChangeEvent,
7881
phaseTransitionEvent,
79-
raidStartEvent
82+
raidStartEvent,
83+
adminError
8084
);
8185
})();
8286
});
@@ -254,4 +258,13 @@
254258
</Alert>
255259
</div>
256260
{/if}
261+
{#if adminAlert}
262+
<div transition:fade>
263+
<Alert color="none" class="bg-red-700 w-56 mx-auto absolute inset-x-0 bottom-8 py-2 z-50">
264+
<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>
265+
</span>
266+
Please restart as Admin
267+
</Alert>
268+
</div>
269+
{/if}
257270
<Footer bind:tab={tab}/>

src/lib/utils/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export const defaultSettings = {
66
"general": {
77
"showNames": true,
88
"accentColor": "theme-pink",
9+
"rawSocket": false,
10+
"port": 6040,
911
"blur": true,
1012
},
1113
"shortcuts": {

src/routes/settings/+page.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
</div>
8383
</label>
8484
</div>
85+
<SettingItem name="VPN Support (beta)" description="Enables raw socket capture. (manually restart as ADMIN)" bind:setting={$settings.general.rawSocket} />
8586
<div class="pt-2" on:focusout={handleDropdownFocusLoss}>
8687
<div class="flex font-medium items-center">
8788
<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}>

0 commit comments

Comments
 (0)