Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add server offline status #273

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/containers/MainBody/ServerList/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ const ServerItem = memo((props: IProps) => {
{ paddingLeft: server.usingOmp ? 0 : sc(10) },
]}
>
<Text style={{ fontSize: sc(17) }} color={theme.textPrimary}>
<Text style={{ fontSize: sc(17) }}
color={server.isOffline ? theme.textSecondary : theme.textPrimary}
>
{server.hostname}
</Text>
</View>
Expand Down
1 change: 1 addition & 0 deletions src/locales/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,5 @@ export default {
reconnect: "Reconnect",
settings_advanced_discord_status_requires_restart:
"(Requires restarting the game to take action)",
server_status: "Offline",
};
3 changes: 2 additions & 1 deletion src/locales/translations/pt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@ export default {
from_gtasa_folder: "Da pasta do GTASA",
gta_path_modal_cant_find_samp_description_2: "Escolha outra versão ou instale o SA-MP manualmente.",
add_or_play_external_server: "Adicionar aos favoritos ou jogar",
reconnect: "Reconectar"
reconnect: "Reconectar",
server_status: "Desligado",
};
11 changes: 9 additions & 2 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,14 @@ export const sortAndSearchInServerList = (
languages,
} = searchData;
let list = servers.filter((server) => {
const nonEmptyCheck = nonEmpty ?
(server.playerCount > 0 && !server.isOffline) : true;

const ompCheck = ompOnly ? server.usingOmp === true : true;

const partnershipCheck = checkForPartnership
? server.partner === true
: true;
const nonEmptyCheck = nonEmpty ? server.playerCount > 0 : true;
const unpasswordedCheck = unpassworded
? server.hasPassword === false
: true;
Expand Down Expand Up @@ -254,6 +257,10 @@ export const sortAndSearchInServerList = (

if (sortPing !== "none") {
list = list.sort((a, b) => {

if (a.ping === 9999 && b.ping !== 9999) return 1;
if (a.ping !== 9999 && b.ping === 9999) return -1;

if (sortPing === "descending") {
return a.ping - b.ping;
} else {
Expand Down Expand Up @@ -416,4 +423,4 @@ export const getSampVersionFromName = (name: string): SAMPDLLVersions => {
}
});
return ret;
};
};
40 changes: 35 additions & 5 deletions src/utils/query.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { t } from "i18next";
import { invoke_rpc } from "../api/rpc";
import { usePersistentServers, useServers } from "../states/servers";
import { Log } from "./logger";
Expand Down Expand Up @@ -42,14 +43,28 @@ const getServerInfo = async (ip: string, port: number, listType: ListType) => {
ip: ip,
port: port,
});

if (serverInfo === "no_data" || serverInfo == "timed out") {
let server = getServerFromList(ip, port, listType);
if (server && !server.isOffline) {

server = {
...server,
ping: 9999,
playerCount: 0,
maxPlayers: 0,
gameMode: "-",
hostname: `(${t("server_status")}) ${server.hostname}`,
language: "-",
isOffline: true
};
updateServerEveryWhere(server);
}
return Log.debug(
"[query.ts: getServerInfo]",
"There was a problem getting server main info"
);
}

let queryObj = JSON.parse(serverInfo);
const data = {
hasPassword: queryObj.password,
Expand All @@ -58,15 +73,30 @@ const getServerInfo = async (ip: string, port: number, listType: ListType) => {
hostname: queryObj.hostname,
gameMode: queryObj.gamemode,
language: queryObj.language,
isOffline: false
};

let server = getServerFromList(ip, port, listType);
if (server) {
server = { ...server, ...data };
updateServerEveryWhere(server);
}
} catch (e) {
Log.debug("[query.ts: getServerInfo]", e);
let server = getServerFromList(ip, port, listType);
if (server && !server.isOffline) {

server = {
...server,
ping: 9999,
playerCount: 0,
maxPlayers: 0,
gameMode: "-",
hostname: `(${t("server_status")}) ${server.hostname}`,
language: "-",
isOffline: true
};
updateServerEveryWhere(server);
Log.debug("[query.ts: getServerInfo]", e);
}
}
};

Expand Down Expand Up @@ -267,4 +297,4 @@ const updateServerEveryWhere = (server: Server) => {
setSelected(server);
}
}
};
};
3 changes: 2 additions & 1 deletion src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface Server {
ping: number;
players: Player[];
password: string;
isOffline: boolean;
omp?: {
bannerLight?: string;
bannerDark?: string;
Expand Down Expand Up @@ -93,4 +94,4 @@ export interface PerServerSettings {
ipPort: string;
nickname?: string;
sampVersion?: SAMPDLLVersions;
}
}
Loading