Skip to content

Commit

Permalink
fix: merge change from server
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Jul 14, 2019
2 parents 1a767b2 + 4436123 commit bf87c75
Show file tree
Hide file tree
Showing 16 changed files with 2,038 additions and 97 deletions.
47 changes: 47 additions & 0 deletions scripts/parse-wiki-protocol.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const parser = require('fast-html-parser');
const fs = require('fs');

const filename = process.argv[2];

if (!fs.existsSync(filename)) {
console.error(`Cannot find file ${filename}`);
return;
}

const outfile = process.argv[3] || `${filename}`;

const s = fs.readFileSync(filename).toString();
const parsed = parser.parse(s);


const map = {};
const rev = {};

for (const table of parsed.querySelectorAll('table')) {
const all = table.querySelectorAll('tr');

let current;
for (const r of all) {
const a = r.querySelector('a');
// eslint-disable-next-line no-continue
if (!a) continue;
const name = a.rawText.trim();
const protocolE = r.querySelectorAll('td')[1];
if (!protocolE) {
map[name] = current.trim();
} else {
current = protocolE.rawText.trim();
map[name] = current;
}
}
}

for (const [k, v] of Object.entries(map)) {
if (!rev[v]) {
rev[v] = [];
}
rev[v].push(k);
}

fs.writeFileSync(`${outfile}-mc-protocol`, JSON.stringify(map, null, 4));
fs.writeFileSync(`${outfile}-protocol`, JSON.stringify(rev, null, 4));
5 changes: 5 additions & 0 deletions src/main/store/modules/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,15 @@ const mod = {
maxMemory: profile.maxMemory || 1024,
version,
};

console.log('Launching a server');
if (profile.type === 'server') {
option.server = { ip: profile.host, port: profile.port };
}

const { mods, resourcepacks } = await context.dispatch('resolveProfileResources', context.rootState.profile.id);

console.log(`Deploy ${mods.length} Mods`);
try {
await context.dispatch('deployResources', {
resources: resourcepacks,
Expand All @@ -107,6 +110,8 @@ const mod = {
console.error(e);
}

console.log(`Deploy ${resourcepacks.length} Resource Packs`);

if (profile.forge.version || profile.liteloader.version) {
try {
const modsDir = join(option.gamePath, 'mods');
Expand Down
40 changes: 4 additions & 36 deletions src/main/store/modules/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,8 @@ import { fitin, willBaselineChange } from 'universal/utils/object';
import uuid from 'uuid';
import { createExtractStream } from 'yauzlw';
import { ZipFile } from 'yazl';

const PINGING_STATUS = Object.freeze({
version: {
name: 'Unknown',
protocol: -1,
},
players: {
max: -1,
online: -1,
},
description: 'Ping...',
favicon: '',
ping: 0,
});
/**
*
* @param {string} description
*/
function createFailureServerStatus(description) {
return Object.freeze({
version: {
name: 'Unknown',
protocol: -1,
},
players: {
max: -1,
online: -1,
},
description,
favicon: '',
ping: -1,
});
}

import { PINGING_STATUS, createFailureServerStatus } from 'universal/utils/server-status';

/**
* @type {import('universal/store/modules/profile').ProfileModule}
*/
Expand Down Expand Up @@ -226,13 +194,13 @@ const mod = {
async createAndSelectProfile(context, payload) {
const id = await context.dispatch('createProfile', payload);
await context.commit('selectProfile', id);
await context.dispatch('diagnoseProfile');
},


async deleteProfile(context, id = context.state.id) {
if (context.state.id === id) {
const allIds = Object.keys(context.state.all);
if (allIds.length - 1 === 0) {
if (allIds.length === 1) {
await context.dispatch('createAndSelectProfile', { type: 'modpack' });
} else {
context.commit('selectProfile', allIds[0]);
Expand Down
17 changes: 13 additions & 4 deletions src/renderer/windows/main/BaseSettingPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,23 @@
<v-text-field outline hide-details dark readonly :value="$repo.getters.currentVersion.id"
:label="$t('profile.version')" @click="goVersionPage" @focus="goVersionPage" />
</v-flex>
<v-flex d-flex xs6>
<v-flex v-if="!isServer" d-flex xs6>
<v-text-field v-model="author" outline hide-details dark :label="$t('profile.modpack.author')"
:placeholder="$repo.state.user.name" required />
</v-flex>
<v-flex d-flex xs6>
<v-flex v-if="isServer" d-flex xs6>
<v-text-field v-model="host" outline hide-details dark :label="$t('profile.server.host')" placeholder="www.whatever.com"
required />
</v-flex>
<v-flex v-if="isServer" d-flex xs6>
<v-text-field v-model="port" outline hide-details dark :label="$t('profile.server.port')" placeholder="25565"
required />
</v-flex>
<v-flex v-if="!isServer" d-flex xs6>
<v-text-field v-model="url" outline hide-details dark :label="$t('profile.url')" placeholder="www.whatever.com"
required />
</v-flex>
<v-flex d-flex xs12>
<v-flex v-if="!isServer" d-flex xs12>
<v-text-field v-model="description" outline hide-details dark :label="$t('profile.modpack.description')" />
</v-flex>

Expand Down Expand Up @@ -78,6 +86,7 @@ export default {
};
},
computed: {
isServer() { return this.$repo.getters.selectedProfile.type === 'server'; },
mcversion: {
get() { return this.$repo.getters.selectedProfile.mcversion; },
set(v) { this.$repo.dispatch('editProfile', { mcversion: v }); },
Expand Down Expand Up @@ -138,7 +147,7 @@ export default {
this.$repo.dispatch('editProfile', {
...payload,
host: this.host,
port: this.port,
port: Number.parseInt(this.port, 10),
});
}
},
Expand Down
77 changes: 64 additions & 13 deletions src/renderer/windows/main/HomePage.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<v-layout fill-height column>
<v-layout row wrap>
<v-icon v-ripple style="position: absolute; right: 0; top: 0; z-index: 2; margin: 0; padding: 10px; cursor: pointer; border-radius: 2px; user-select: none;"
dark @click="quitLauncher">
close
Expand Down Expand Up @@ -73,18 +73,59 @@
</v-list>
</v-menu>

<div class="display-1 white--text" style="padding-top: 50px; padding-left: 50px">
<span style="margin-right: 10px;">
{{ profile.name || `Minecraft ${profile.mcversion}` }}
</span>
<v-chip v-if="profile.author" label color="green" outline small :selected="true" style="margin-right: 5px;">
{{ profile.author }}
</v-chip>
<v-flex d-flex xs12>
<div class="display-1 white--text" style="padding-top: 50px; padding-left: 50px">
<span style="margin-right: 10px;">
{{ profile.name || `Minecraft ${profile.mcversion}` }}
</span>
<v-chip v-if="profile.author" label color="green" outline small :selected="true" style="margin-right: 5px;">
{{ profile.author }}
</v-chip>

<v-chip label color="green" outline small :selected="true">
Version: {{ $repo.getters['currentVersion'].id }}
</v-chip>
</div>
</v-flex>

<v-flex d-flex xs6 style="margin: 40px 0 0 40px;">
<v-card v-if="isServer" class="white--text">
<v-layout>
<v-flex xs5 style=" padding: 5px 0">
<v-card-title>
<v-img :src="icon" height="125px" style="max-height: 125px;" contain />
</v-card-title>
</v-flex>
<v-flex xs7>
<v-card-title>
<div>
<div style="font-size: 20px;">
{{ $t(profile.status.version.name) }}
</div>
<text-component :source="profile.status.description" />

<div> {{ $t('profile.server.players') }} : {{ profile.status.players.online + '/' + profile.status.players.max }} </div>
</div>
</v-card-title>
</v-flex>
</v-layout>
<v-divider light />
<v-card-actions class="pa-3">
<v-icon left>
signal_cellular_alt
</v-icon>
<div> {{ $t('profile.server.pings') }} : {{ profile.status.ping }} ms </div>

<v-spacer />
<v-btn v-if="isServer" flat dark large @click="refreshServer">
<v-icon>
refresh
</v-icon>
</v-btn>
</v-card-actions>
</v-card>
</v-flex>

<v-chip label color="green" outline small :selected="true">
Version: {{ $repo.getters['currentVersion'].id }}
</v-chip>
</div>

<v-btn color="primary" style="position: absolute; right: 10px; bottom: 10px; " dark large
:disabled="refreshingProfile || missingJava"
Expand Down Expand Up @@ -118,6 +159,9 @@
</template>

<script>
import unknownServer from 'static/unknown_server.png';
import { PINGING_STATUS, createFailureServerStatus } from 'universal/utils/server-status';
export default {
data: () => ({
taskDialog: false,
Expand All @@ -130,6 +174,8 @@ export default {
tempDialogText: '',
}),
computed: {
icon() { return this.profile.status.favicon || unknownServer; },
isServer() { return this.profile.type === 'server'; },
problems() { return this.profile.problems; },
launchStatus() { return this.$repo.state.launch.status; },
refreshingProfile() { return this.profile.refreshing; },
Expand Down Expand Up @@ -180,7 +226,9 @@ export default {
return;
}
const success = await this.$repo.dispatch('launch').catch((e) => { console.error(e); });
const success = await this.$repo.dispatch('launch').catch((e) => {
console.error(e);
});
if (!success) {
const problems = this.$repo.getters.selectedProfile.problems;
if (problems.length !== 0) {
Expand Down Expand Up @@ -261,6 +309,9 @@ export default {
async handleAutoFix() {
await this.$repo.dispatch('fixProfile', this.problems);
},
async refreshServer() {
await this.$repo.dispatch('refreshProfile');
},
quitLauncher() {
setTimeout(() => {
this.$store.dispatch('quit');
Expand Down
21 changes: 16 additions & 5 deletions src/renderer/windows/main/ProfilesPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
<v-text-field v-model="filter" hide-details append-icon="filter_list" :label="$t('filter')" solo dark color="green darken-1" />
</v-flex>
<v-flex xs1>
<v-tooltip :close-delay="0" left>
<v-tooltip v-model="creatingTooltip" :close-delay="0" left>
<template v-slot:activator="{ on }">
<v-speed-dial open-on-hover style="z-index: 1" direction="bottom" transition="slide-y-reverse-transition">
<template v-slot:activator>
<v-btn flat fab dark small style="margin-left: 5px; margin-top: 5px;" @click="goWizard"
<v-btn flat fab dark small style="margin-left: 5px; margin-top: 5px;" @click="createProfile"
v-on="on">
<v-icon dark style="font-size: 28px">
add
</v-icon>
</v-btn>
</template>
<v-btn style="z-index: 20;" fab small v-on="on" @mouseenter="enterAltCreate" @mouseleave="leaveAltCreate">
<v-btn style="z-index: 20;" fab small v-on="on" @mouseenter="enterAltCreate" @mouseleave="leaveAltCreate"
@click="createServer">
<v-icon>storage</v-icon>
</v-btn>
</v-speed-dial>
Expand Down Expand Up @@ -90,7 +91,8 @@
<v-flex d-flex xs12 style="height: 10px;" />
</v-layout>
<v-dialog v-model="wizard" persistent>
<add-profile-wizard :show="wizard" @quit="wizard=false" />
<add-profile-wizard v-if="!creatingServer" :show="wizard" @quit="wizard=false" />
<add-server-wizard v-else :show="wizard" @quit="wizard=false" />
</v-dialog>
</v-container>
</template>
Expand All @@ -104,6 +106,8 @@ export default {
wizard: false,
hoverTextOnCreate: this.$t('profile.add'),
hoverTextOnImport: this.$t('profile.importZip'),
creatingServer: false,
creatingTooltip: false,
};
},
computed: {
Expand All @@ -118,7 +122,14 @@ export default {
mounted() {
},
methods: {
goWizard() {
createProfile() {
this.creatingTooltip = false;
this.creatingServer = false;
this.wizard = true;
},
createServer() {
this.creatingTooltip = false;
this.creatingServer = true;
this.wizard = true;
},
doImport(fromFolder) {
Expand Down
Loading

0 comments on commit bf87c75

Please sign in to comment.