~xenrox/10man-ts3

dc5adcabbe8e96432719215a54a4b9cd86997b7c — Thorben Günther 2 years ago ef4ca9b
Move back clients if match is finished

Don't crash if a user moved manually.
1 files changed, 24 insertions(+), 7 deletions(-)

M app.ts
M app.ts => app.ts +24 -7
@@ 271,6 271,9 @@ async function finish_match(clid: string, teamspeakID: string, winner: string) {
        return;
    }

    // move clients back to main channel
    move_clients(true);

    const mutation = gql`
        mutation ($winner: String!) {
            finishMatch(winner: $winner)


@@ 314,7 317,7 @@ async function start_match() {
    }
}

async function move_clients() {
async function move_clients(back: boolean = false) {
    const query = gql`
        query {
            getTeams {


@@ 330,27 333,41 @@ async function move_clients() {

    try {
        const data = await request(query);

        const team1 = data.getTeams.team1;
        const channel1 = await teamspeak.channelFind("Team 1");
        const team2 = data.getTeams.team2;
        var channel = await teamspeak.channelFind("10 Man");

        if (!back) {
            channel = await teamspeak.channelFind("Team 1");
        }

        for (let i of team1) {
            const client = await teamspeak
                .getClientByUid(i.teamspeakID)
                .then((client) => {
                    teamspeak.clientMove(client!.clid, channel1[0].cid);
                    teamspeak
                        .clientMove(client!.clid, channel[0].cid)
                        .catch(function (e) {
                            console.error(e);
                        });
                })
                .catch(function (e) {
                    console.error(e);
                });
        }

        const team2 = data.getTeams.team2;
        const channel2 = await teamspeak.channelFind("Team 2");
        if (!back) {
            channel = await teamspeak.channelFind("Team 2");
        }
        for (let i of team2) {
            const client = await teamspeak
                .getClientByUid(i.teamspeakID)
                .then((client) => {
                    teamspeak.clientMove(client!.clid, channel2[0].cid);
                    teamspeak
                        .clientMove(client!.clid, channel[0].cid)
                        .catch(function (e) {
                            console.error(e);
                        });
                })
                .catch(function (e) {
                    console.error(e);