Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #172 from ferreira-tb/captcha-route
Browse files Browse the repository at this point in the history
fix: impede que o AS continue atacando após surgir captcha
  • Loading branch information
ferreira-tb authored Apr 24, 2023
2 parents 9d90f08 + 1768acf commit f604bf3
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 49 deletions.
2 changes: 1 addition & 1 deletion browser/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ watchImmediate(currentScreen, async (name) => {
whenever(isDeimosReady, async () => {
if (gameOriginRegex.test(location.origin)) {
const responseTime = await Deimos.invoke('get-response-time');
ipcSend('update-response-time', responseTime);
ipcSend('browser:update-response-time', responseTime);
aresStore.responseTime = responseTime;
};
});
Expand Down
2 changes: 1 addition & 1 deletion browser/components/TheCaptchaObserver.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const aresStore = useAresStore();
const { captcha } = storeToRefs(aresStore);
captcha.value = thereIsBotCheck();
watchSyncEffect(() => ipcSend('update-captcha-status', captcha.value));
watchSyncEffect(() => ipcSend('captcha:update-status', captcha.value));
const content = ref(document.querySelector<HTMLTableElement>('table#contentContainer'));
const options: UseMutationObserverOptions = {
Expand Down
6 changes: 6 additions & 0 deletions browser/events/plunder/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { ipcRenderer } from 'electron';
import { usePlunderConfigStore } from '$renderer/stores/plunder';
import { setPlunderConfigEvents } from '$browser/events/plunder/config';
import { setPlunderNavigationEvents } from '$browser/events/plunder/navigation';

export function setPlunderEvents() {
setPlunderConfigEvents();
setPlunderNavigationEvents();

const plunderConfigStore = usePlunderConfigStore();

ipcRenderer.on('plunder:stop', () => (plunderConfigStore.active = false));
};
21 changes: 0 additions & 21 deletions electron/events/browser.ts

This file was deleted.

38 changes: 38 additions & 0 deletions electron/events/browser/captcha.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ipcMain, webContents } from 'electron';
import { storeToRefs, watch } from 'mechanus';
import { isUserAlias } from '$global/guards';
import { MainProcessEventError } from '$electron/error';
import { useAresStore, useCacheStore, usePlunderHistoryStore, PlunderHistory } from '$electron/interface';

export function setCaptchaEvents() {
const aresStore = useAresStore();
const { captcha } = storeToRefs(aresStore);

const cacheStore = useCacheStore();
const plunderHistoryStore = usePlunderHistoryStore();

ipcMain.on('captcha:update-status', (e, status: boolean) => {
captcha.value = status;
for (const contents of webContents.getAllWebContents()) {
if (contents !== e.sender) {
contents.send('captcha:status-did-update', status);
};
};
});

watch(captcha, async (status) => {
try {
if (!status) return;
for (const contents of webContents.getAllWebContents()) {
contents.send('plunder:stop');
};

if (isUserAlias(cacheStore.userAlias)) {
await PlunderHistory.saveHistory(cacheStore.userAlias, plunderHistoryStore);
};

} catch (err) {
MainProcessEventError.catch(err);
};
});
};
18 changes: 18 additions & 0 deletions electron/events/browser/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ipcMain } from 'electron';
import { useAresStore } from '$electron/interface';
import { getMainWindow } from '$electron/utils/helpers';
import { setCaptchaEvents } from '$electron/events/browser/captcha';

export function setBrowserEvents() {
const mainWindow = getMainWindow();
const aresStore = useAresStore();

ipcMain.handle('browser:get-response-time', () => aresStore.responseTime);

ipcMain.on('browser:update-response-time', (_e, time: number) => {
aresStore.responseTime = time;
mainWindow.webContents.send('response-time-did-update', time);
});

setCaptchaEvents();
};
8 changes: 4 additions & 4 deletions panel/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export function setPanelEvents() {
const unitStore = useUnitsStore();
const groupsStore = useGroupsStore();

ipcRenderer.on('panel:visibility-did-change', (_e, isVisible: boolean) => {
panelStore.isVisible = isVisible;
ipcRenderer.on('captcha:status-did-update', (_e, thereIsCaptcha: boolean) => {
aresStore.captcha = thereIsCaptcha;
});

ipcRenderer.on('captcha-status-did-update', (_e, thereIsCaptcha: boolean) => {
aresStore.captcha = thereIsCaptcha;
ipcRenderer.on('panel:visibility-did-change', (_e, isVisible: boolean) => {
panelStore.isVisible = isVisible;
});

ipcRenderer.on('panel:patch-game-data', (_e, data: TribalWarsGameDataType) => {
Expand Down
2 changes: 2 additions & 0 deletions panel/events/plunder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export function setPlunderEvents() {
const plunderConfigStore = usePlunderConfigStore();
const plunderHistoryStore = usePlunderHistoryStore();

ipcRenderer.on('plunder:stop', () => (plunderConfigStore.active = false));

// Atualiza o estado local do Plunder sempre que ocorre uma mudança.
ipcRenderer.on('plunder:config-updated', <T extends keyof typeof plunderConfigStore>(
_e: unknown, key: T, value: typeof plunderConfigStore[T]
Expand Down
18 changes: 0 additions & 18 deletions panel/views/CaptchaView.vue
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
<script setup lang="ts">
import { storeToRefs } from 'pinia';
import { NResult } from 'naive-ui';
import { watchImmediate } from '@vueuse/core';
import { useAresStore } from '$renderer/stores/ares';
import { usePlunderConfigStore } from '$renderer/stores/plunder';
import { router } from '$panel/router';
import { ipcSend } from '$renderer/ipc';
const aresStore = useAresStore();
const plunderConfigStore = usePlunderConfigStore();
const { captcha } = storeToRefs(aresStore);
watchImmediate(captcha, (isActive) => {
if (isActive && router.currentRoute.value.name === 'am_farm') {
plunderConfigStore.active = false;
ipcSend('plunder:save-history');
};
});
</script>

<template>
Expand Down
6 changes: 3 additions & 3 deletions renderer/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function ipcInvoke(channel: 'user-alias'): Promise<UserAlias | null
export async function ipcInvoke(channel: 'user-data-path'): Promise<string>;
export async function ipcInvoke(channel: 'user-desktop-path'): Promise<string>;
export async function ipcInvoke(channel: 'is-dev'): Promise<boolean>;
export async function ipcInvoke(channel: 'get-response-time'): Promise<number>;
export async function ipcInvoke(channel: 'browser:get-response-time'): Promise<number>;
export async function ipcInvoke(channel: 'is-ignored-app-version', version: string): Promise<boolean>;

// Configurações
Expand Down Expand Up @@ -104,8 +104,8 @@ export function ipcSend(channel: 'open-github-issues'): void;
export function ipcSend(channel: 'open-app-update-window'): void;
export function ipcSend(channel: 'download-from-url', url: string): void;
export function ipcSend(channel: 'show-update-available-dialog', newVersion: string): void;
export function ipcSend(channel: 'update-captcha-status', status: boolean): void;
export function ipcSend(channel: 'update-response-time', time: number | null): void;
export function ipcSend(channel: 'captcha:update-status', status: boolean): void;
export function ipcSend(channel: 'browser:update-response-time', time: number | null): void;
export function ipcSend(channel: 'electron:show-message-box', options: ElectronMessageBoxOptions): void;

// Desenvolvedor
Expand Down
2 changes: 1 addition & 1 deletion ui/components/TheResponseTime.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { NTag } from 'naive-ui';
import { ipcInvoke } from '$renderer/ipc';
const responseTime = ref<number | null>(null);
responseTime.value = await ipcInvoke('get-response-time');
responseTime.value = await ipcInvoke('browser:get-response-time');
const responseTimeTagType = computed(() => {
if (responseTime.value) {
Expand Down

0 comments on commit f604bf3

Please sign in to comment.