Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady authored Nov 15, 2023
2 parents 0e02f76 + 99f6e40 commit 679f621
Show file tree
Hide file tree
Showing 14 changed files with 1,140 additions and 167 deletions.
645 changes: 641 additions & 4 deletions src-tauri/Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ runas = "1.1.0"
sysinfo = "0.29.10"
simple-logging = "2.0.2"
log = "0.4.20"
charset-normalizer-rs = "1.0.6"

[target.'cfg(target_os = "windows")'.dependencies]
dll-syringe = "0.15.2"
Expand Down
48 changes: 34 additions & 14 deletions src-tauri/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,50 @@
use chardet::{charset2encoding, detect};
use charset_normalizer_rs::from_bytes;
use encoding::label::encoding_from_whatwg_label;
use encoding::DecoderTrap;

pub fn decode_buffer(buf: Vec<u8>) -> String {
let result = detect(&buf);
let mut str_encoding = charset2encoding(&result.0);
// let's just say it's cp1251 if encoding is not detected
// FIXME: find a way to actually detect cp1251 and cp1252 from together
pub fn decode_buffer(buf: Vec<u8>) -> (String, String, String) {
let buff_output: String;
let first_encoding: String;
let second_encoding: String;
let mut str_encoding: String;

if result.0 == "MacCyrillic"
|| (result.0 == "KOI8-R" && result.1 < 0.7 && result.2 == "Russian")
// chardet
first_encoding = charset2encoding(&detect(&buf).0).to_string();

// charset_normalizer_rs
second_encoding = match from_bytes(&buf, None).get_best() {
Some(cd) => cd.encoding().to_string(),
None => "not_found".to_string(),
};

str_encoding = first_encoding.clone();

if first_encoding == "KOI8-R"
|| first_encoding == "MacCyrillic"
|| first_encoding == "x-mac-cyrillic"
{
str_encoding = "cp1251";
str_encoding = "cp1251".to_string();
}

if str_encoding.len() < 1 {
str_encoding = "cp1251";
if second_encoding == "koi8-r" || second_encoding == "macintosh" || second_encoding == "ibm866"
{
str_encoding = "cp1251".to_string();
}

let coder = encoding_from_whatwg_label(str_encoding);
// if str_encoding.len() < 1 {
// str_encoding = "cp1251".to_string();
// }

let coder = encoding_from_whatwg_label(str_encoding.as_str());
if coder.is_some() {
coder
buff_output = coder
.unwrap()
.decode(&buf, DecoderTrap::Ignore)
.expect("Error")
.expect("Error");
} else {
String::from_utf8_lossy(buf.as_slice()).to_string()
buff_output = String::from_utf8_lossy(buf.as_slice()).to_string();
}

(buff_output, first_encoding, second_encoding)
}
4 changes: 2 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ async fn ping_server(ip: &str, port: i32) -> Result<u32, String> {
let before = Instant::now();
match q.recv().await {
Ok(_p) => Ok(before.elapsed().as_millis() as u32),
Err(_) => Ok(0),
Err(_) => Ok(9999),
}
}
Err(_) => Ok(0),
Err(_) => Ok(9999),
}
}

Expand Down
12 changes: 6 additions & 6 deletions src-tauri/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,17 @@ impl Query {
let hostname_len = packet.read_u32::<LittleEndian>().unwrap();
let mut hostname_buf = vec![0u8; hostname_len as usize];
packet.read_exact(&mut hostname_buf).unwrap();
data.hostname = helpers::decode_buffer(hostname_buf);
data.hostname = helpers::decode_buffer(hostname_buf).0;

let gamemode_len = packet.read_u32::<LittleEndian>().unwrap();
let mut gamemode_buf = vec![0u8; gamemode_len as usize];
packet.read_exact(&mut gamemode_buf).unwrap();
data.gamemode = helpers::decode_buffer(gamemode_buf);
data.gamemode = helpers::decode_buffer(gamemode_buf).0;

let language_len = packet.read_u32::<LittleEndian>().unwrap();
let mut language_buf = vec![0u8; language_len as usize];
packet.read_exact(&mut language_buf).unwrap();
data.language = helpers::decode_buffer(language_buf);
data.language = helpers::decode_buffer(language_buf).0;

Ok(serde_json::to_string(&data).unwrap())
}
Expand All @@ -184,7 +184,7 @@ impl Query {
let player_name_len = packet.read_u8().unwrap();
let mut player_name_buf = vec![0u8; player_name_len as usize];
packet.read_exact(&mut player_name_buf).unwrap();
player.name = helpers::decode_buffer(player_name_buf);
player.name = helpers::decode_buffer(player_name_buf).0;

player.score = packet.read_i32::<LittleEndian>().unwrap();
}
Expand All @@ -202,12 +202,12 @@ impl Query {
let rule_name_len = packet.read_u8().unwrap();
let mut rule_name_buf = vec![0u8; rule_name_len as usize];
packet.read_exact(&mut rule_name_buf).unwrap();
rule.push(helpers::decode_buffer(rule_name_buf));
rule.push(helpers::decode_buffer(rule_name_buf).0);

let rule_value_len = packet.read_u8().unwrap();
let mut rule_value_buf = vec![0u8; rule_value_len as usize];
packet.read_exact(&mut rule_value_buf).unwrap();
rule.push(helpers::decode_buffer(rule_value_buf));
rule.push(helpers::decode_buffer(rule_value_buf).0);

rules.push(rule);
}
Expand Down
8 changes: 4 additions & 4 deletions src-tauri/src/samp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,30 +120,30 @@ pub fn get_samp_favorite_list() -> String {
let ip_len = r.read_u32::<LittleEndian>().unwrap();
let mut pos: u32 = r.position().try_into().unwrap();
let server_ip = buffer[pos as usize..(pos + ip_len) as usize].to_vec();
server_info.ip = helpers::decode_buffer(server_ip);
server_info.ip = helpers::decode_buffer(server_ip).0;
r.set_position((pos + ip_len).try_into().unwrap());

server_info.port = r.read_u32::<LittleEndian>().unwrap();

let name_len = r.read_u32::<LittleEndian>().unwrap();
pos = r.position().try_into().unwrap();
let server_name = buffer[pos as usize..(pos + name_len) as usize].to_vec();
server_info.name = helpers::decode_buffer(server_name);
server_info.name = helpers::decode_buffer(server_name).0;
r.set_position((pos + name_len).try_into().unwrap());

let password_len = r.read_u32::<LittleEndian>().unwrap();
if password_len != 0 {
pos = r.position().try_into().unwrap();
let server_password = buffer[pos as usize..(pos + password_len) as usize].to_vec();
server_info.password = helpers::decode_buffer(server_password);
server_info.password = helpers::decode_buffer(server_password).0;
r.set_position((pos + password_len).try_into().unwrap());
}

let rcon_len = r.read_u32::<LittleEndian>().unwrap();
if rcon_len != 0 {
pos = r.position().try_into().unwrap();
let server_rcon = buffer[pos as usize..(pos + rcon_len) as usize].to_vec();
server_info.rcon = helpers::decode_buffer(server_rcon);
server_info.rcon = helpers::decode_buffer(server_rcon).0;
r.set_position((pos + rcon_len).try_into().unwrap());
}

Expand Down
22 changes: 3 additions & 19 deletions src/hooks/query.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { useEffect, useRef } from "react";
import { usePersistentServers, useServers } from "../states/servers";
import { useServers } from "../states/servers";
import { queryServer } from "../utils/query";
import { Server } from "../utils/types";

export const useQuery = () => {
const queryTimer = useRef<number | undefined>(undefined);

const { selected, updateServer, setSelected } = useServers();
const { updateInFavoritesList, updateInRecentlyJoinedList } =
usePersistentServers();
const { selected, setSelected } = useServers();
const selectedServer = useRef<Server | undefined>(selected);

useEffect(() => {
Expand Down Expand Up @@ -37,21 +35,7 @@ export const useQuery = () => {
};

const getServerInfo = (srv: Server) => {
queryServer(srv)
.then((server) => {
if (server && selectedServer.current) {
if (
server.ip == selectedServer.current.ip &&
server.port == selectedServer.current.port
) {
updateServer(server);
updateInFavoritesList(server);
updateInRecentlyJoinedList(server);
setSelected(server);
}
}
})
.catch((e) => console.log(e));
queryServer(srv);
};

return {
Expand Down
18 changes: 15 additions & 3 deletions src/locales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import English from "./translations/en";
import Spanish from "./translations/es";
import Farsi from "./translations/fa";
import Filipino from "./translations/fil";
import France from "./translations/fr";
import French from "./translations/fr";
import Hindi from "./translations/hi";
import Italian from "./translations/it";
import Portuguese from "./translations/pt";
import Romanian from "./translations/ro";
import Polish from "./translations/pl";
import Bosnian from "./translations/bs";

i18n.use(initReactI18next).init({
// we init with resources
Expand All @@ -24,18 +27,27 @@ i18n.use(initReactI18next).init({
fil: {
translations: Filipino,
},
fr: {
translations: French,
},
hi: {
translations: Hindi,
},
it: {
translations: Italian,
},
fr: {
translations: France,
pt: {
translations: Portuguese,
},
ro: {
translations: Romanian,
},
pl: {
translations: Polish,
},
bs: {
translations: Bosnian,
},
},
fallbackLng: "en",
debug: true,
Expand Down
79 changes: 79 additions & 0 deletions src/locales/translations/bs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
export default {
favorites: "Favoriti",
internet: "Internet",
partners: "Partneri",
recently_joined: "Nedavno posjećen",
nickname: "Nadimak",
settings: "Postavke",
minimize: "Minimiziraj",
maximize: "Maksimiziraj",
close: "Zatvori",
add_server_modal_description_1: "Dodaj server ručno na svoju listu favorita.",
add_server_modal_description_2: "Primjer: 127.0.0.1:7777",
add: "Dodaj",
server: "Server",
address: "Adresa",
players: "Igrači",
server_join_prompt_enter_password:
"Ovaj server je zaštićen, molimo da unesete lozinku.",
server_join_prompt_enter_password_input_placeholder: "Unesi lozinku...",
server_join_prompt_nickname_input_placeholder: "Unesi nadimak...",
connect: "Konektuj",
copy: "Kopiraj",
remove_from_favorites: "Izbriši iz Favorita",
add_to_favorites: "Dodaj u Favorite",
filters: "Filteri",
filter_only_omp_servers: "Samo open.mp serveri",
filter_non_empty_servers: "Neprazni Serveri",
filter_unpassworded_servers: "Serveri bez lozinke",
rule: "Pravilo",
value: "Vrijednost",
player: "Igrač",
score: "Rezultat",
locked: "Zaključano",
unlocked: "Otključano",
openmp_server: "open.mp server",
name: "Ime",
ping: "Ping",
mode: "Mode",
filter_servers: "Filtriraj Servere",
search_for_server_hostname_mode: "Pretraži za ime/mode servera",
clear_recently_joined_list: "Izbriši Nedavno Posjećene Servere",
refresh_servers: "Osvježi Server Listu",
play: "Igraj",
remove_selected_server_from_favorites:
"Ukloni Izabrani Server iz Favorita",
add_selected_server_to_favorites: "Dodaj Izabrani Server u Favorite",
add_server: "Dodaj Server",
hide_player_and_rule_list: "Sakrij listu igrača i pravila",
show_player_and_rule_list: "Prikaži listu igrača i pravila",
copy_server_info: "Kopiraj Server Info",
settings_gta_path_input_label:
"Lokacija GTA: San Andreas-a (gdje je SA-MP također instaliran)",
browse: "Pretraži",
settings_import_nickname_gta_path_from_samp:
"Prenesi nadimak i GTA SA lokaciju iz SA-MP postavki",
settings_import_samp_favorite_list: "Prenesi listu favorita iz SA-MP podataka",
settings_reset_application_data:
"Restartuj podatke aplikacije (očisti postavke i liste)",
settings_new_update_available: "⚠ Novo ažuriranje dostupno. Klikni da skineš! ⚠",
settings_credits_made_by: "Napravio s ❤️",
settings_credits_view_source_on_github: "Pogledaj izvorni kod na GitHub-u",
update_modal_update_available_title: "Dostupno ažuriranje!",
update_modal_update_available_description:
'Dostupan je novi build launcher-a!\nBuild verzija tvoga launhcer-a: {{ version }}\nTrenutna build verzija launcher-a: {{ newVersion }}\nKlikni "Skini" da otvorite stranicu izdanja',
download: "Skini",
update_modal_remind_me_next_time: "Podjseti Me Slijedeći Put",
update_modal_skip_this_update: "Preskoči Ovo Ažuriranje",
gta_path_modal_cant_find_game_title: "GTA San Andreas nije pronađen!",
gta_path_modal_cant_find_game_description:
'GTA San Andreas nije pronađen u ovom direktoriju:\n - "{{ path }}"\n"gta_sa.exe" nije pronađen u datom direktoriju.',
open_settings: "Otvori Postavke",
cancel: "Otkaži",
gta_path_modal_cant_find_samp_title: "SA-MP nije pronađen!",
gta_path_modal_cant_find_samp_description:
'SA-MP instalacija nije pronađena u ovom direktoriju:\n - "{{ path }}"\n"samp.dll" nije pronađen u datom direktoriju.\n\nAko nemaš instaliran SA-MP, možeš ga skinuti sa https://sa-mp.mp/ klikom na **Skini**',
notification_add_to_favorites_title: "Dodan u Favorite!",
notification_add_to_favorites_description:
"{{ server }} je dodan u tvoju listu favorita.",
};
Loading

0 comments on commit 679f621

Please sign in to comment.