Skip to content

Commit

Permalink
don't start game with password param if server is unlocked
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed Feb 10, 2024
1 parent 067701a commit a0976cf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
23 changes: 19 additions & 4 deletions src/containers/JoinServerPrompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import StaticModal from "../../components/StaticModal";
import Text from "../../components/Text";
import { images } from "../../constants/images";
import { useJoinServerPrompt } from "../../states/joinServerPrompt";
import { usePersistentServers } from "../../states/servers";
import { usePersistentServers, useServers } from "../../states/servers";
import { useSettings } from "../../states/settings";
import { useTheme } from "../../states/theme";
import { startGame } from "../../utils/game";
Expand All @@ -26,8 +26,14 @@ import { SAMPDLLVersions } from "../../utils/types";

const JoinServerPrompt = () => {
const { visible, server, showPrompt } = useJoinServerPrompt();
const { getServerSettings, setServerSettings, perServerSettings } =
usePersistentServers();
const {
getServerSettings,
setServerSettings,
updateInFavoritesList,
updateInRecentlyJoinedList,
perServerSettings,
} = usePersistentServers();
const { updateServer } = useServers();
const { height, width } = useWindowDimensions();
const { theme } = useTheme();
const [password, setPassword] = useState("");
Expand Down Expand Up @@ -199,11 +205,20 @@ const JoinServerPrompt = () => {
}}
onPress={() => {
if (server) {
if (server.hasPassword && password.length) {
const srvCpy = { ...server };
srvCpy.password = password;

updateServer(srvCpy);
updateInFavoritesList(srvCpy);
updateInRecentlyJoinedList(srvCpy);
}

startGame(
server,
perServerNickname.length ? perServerNickname : nickName,
gtasaPath,
password
server.hasPassword ? password : ""
);
showPrompt(false);
}
Expand Down
22 changes: 5 additions & 17 deletions src/utils/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { invoke_rpc } from "../api/rpc";
import { ResourceInfo, validFileChecksums } from "../constants/app";
import { useJoinServerPrompt } from "../states/joinServerPrompt";
import { useMessageBox } from "../states/messageModal";
import { usePersistentServers, useServers } from "../states/servers";
import { usePersistentServers } from "../states/servers";
import { useSettings } from "../states/settings";
import { useSettingsModal } from "../states/settingsModal";
import { Log } from "./logger";
Expand Down Expand Up @@ -60,26 +60,12 @@ export const startGame = async (
gtasaPath: string,
password: string
) => {
const {
addToRecentlyJoined,
updateInFavoritesList,
updateInRecentlyJoinedList,
} = usePersistentServers.getState();
const { updateServer } = useServers.getState();
const { addToRecentlyJoined } = usePersistentServers.getState();
const { showMessageBox, hideMessageBox } = useMessageBox.getState();
const { show: showSettings } = useSettingsModal.getState();
const { sampVersion } = useSettings.getState();
const { showPrompt, setServer } = useJoinServerPrompt.getState();

if (password.length) {
const srvCpy = { ...server };
srvCpy.password = password;

updateServer(srvCpy);
updateInFavoritesList(srvCpy);
updateInRecentlyJoinedList(srvCpy);
}

if (!gtasaPath || gtasaPath.length < 1) {
showMessageBox({
title: t("gta_path_modal_path_not_set_title"),
Expand Down Expand Up @@ -205,7 +191,9 @@ export const startGame = async (
{
title: t("download"),
onPress: () => {
shell.open("https://uifserver.net/download/sa-mp-0.3.7-R5-1-MP-install.exe")
shell.open(
"https://uifserver.net/download/sa-mp-0.3.7-R5-1-MP-install.exe"
);
},
},
],
Expand Down

0 comments on commit a0976cf

Please sign in to comment.