import axios from "axios"; import AdminApi from "@/api/AdminApi"; import PlayerApi from "@/api/PlayerApi"; import Stages from "@/api/Stages"; import VipAPI from "@/api/VipApi"; import {VERSION} from "@/api/version"; export default class GlobalApi { stats = { 'statistic':{ working_servers:0, player_now:0, player_max:0, total_servers:0 }, 'servers':{ "w":[], "e":[], "n":[] }, 'uniq': null, 'builddate':0 } loading = false; failed = false; admin = new AdminApi() player = new PlayerApi() vip = new VipAPI(); builddate = VERSION * 1000; current_window = location.hash.length > 1?location.hash.slice(1):'mainView'; load_stages = new Stages(); constructor() { document.title = "Факты 13"; } getHumanServerName(server) { for (const mode in this.stats['servers']) { for (const srv in this.stats['servers'][mode]) { if (this.stats['servers'][mode][srv]['key'] === server) return this.stats['servers'][mode][srv]['name']; } } return "неизвестный"; } async fillThis(value) { console.log(`[API] load: ${value}`); this.load_stages.add(value); return await axios.get(`/api/stats?filter=${value}`) .then(response => response.data) .then(response => { this.stats[value] = response[value]; }) .catch(err => { console.log(`[API] cannot request ${value}, err: ${err}`); throw new Error("BLYA"); }).finally(() => { this.load_stages.remove(value); }) } async fillOther() { console.log(`[API] load: other`); this.load_stages.add("other"); return await axios.get(`/api/stats?filter=other`) .then(response => response.data) .then(response => { this.stats["builddate"] = response["builddate"]; }) .catch(err => { console.log(`[API] cannot request other, err: ${err}`); throw new Error("BLYA"); }).finally(() => { this.load_stages.remove("other"); }) } async fillServers() { this.load_stages.add("servers") console.log(`[API] load: servers`); return axios.get("/api/stats?filter=servers") .then(response => response.data['servers']) .then(response => { let srvs = { 'w':[], "e":[], 'n':[] }; for (let srv in response) { response[srv]['key'] = srv; if (response[srv]['status'] == false) srvs.n.push(response[srv]); else if (response[srv]['player_count'] > 0) srvs.w.push(response[srv]); else srvs.e.push(response[srv]); } srvs['w'].sort((s1,s2) => s2.player_now - s1.player_now); this.stats['servers'] = srvs; }) .catch(err => { console.log(`[API] cannot request servers, err: ${err}`); throw new Error("BLYA SERVERS"); }) .finally(() => { this.load_stages.remove("servers"); }); } async load() { this.loading = true; document.title = `Загрузка - Факты 13`; await Promise.all( [this.fillThis('statistic'), this.fillThis('uniq'), this.fillServers(), this.admin.load(this.load_stages), this.player.load(this.load_stages), this.vip.getVipPrices(this.load_stages), this.vip.getVipStatistic(this.load_stages), this.fillOther()] ).then(() => { console.log("[Loader] success end"); this.loading = false; document.title = `Факты 13`; }).catch(() => { this.loading = false; this.failed = true; document.title = `Факты 13 УМЕРЛИ`; console.log("[Loader] some error in loading"); }); } getRandomBackground() { const backgrounds = [ require('../assets/images/backgrounds/1.png'), require('../assets/images/backgrounds/2.png'), require('../assets/images/backgrounds/3.png'), require('../assets/images/backgrounds/4.png') ]; return backgrounds[Math.floor(Math.random() * backgrounds.length)]; } getRules(){ return [ {"name":"Читы", "about":"Бан навсегда сука", "image": require('@/assets/images/rules/cheats.jpg')}, {"name":"Реклама серверов", "about":"Кроме мге, бан навсегда сука", "image": require('@/assets/images/rules/ads.jpg')}, {"name":"Багоюз", "about":"Пиздец тебе, бан навсегда", "image": require('@/assets/images/rules/bug_use.jpg')}, {"name":"Абуз команды !mir", "about":"Блокировка дверей, открытие спавна и т.д", "image":require('@/assets/images/rules/abuse.jpg')}, {"name":"Абуз випки на сервере", "about":"Модеры сам решат как и за что", "image":require('@/assets/images/rules/abuse_vip.jpg')}, {"name":"Делай короче чё хочешь", "about":":troll_face:", "image":require('@/assets/images/rules/make_everyone.jpg')} ]; } UNIX2FACTI_TIME(u_time) { const divmod = (x, y) => [Math.floor(x / y), x % y]; let s = divmod(u_time, 60)[1]; let m = divmod(u_time, 60)[0]; let h = divmod(m, 60)[0]; m = divmod(m, 60)[1]; let d = divmod(h, 24)[0]; let n = divmod(d, 7)[0]; h = divmod(h, 24)[1]; //бля простите я тупой let total_h = divmod(u_time, 60 * 60); if (!s & !m & !h & !d) { return "не играл"; } let time = `${h > 9 ? h : '0' + h}:${m > 9 ? m : '0' + m}:${s > 9 ? s : '0' + s}`; if (!d) { return time; } else if (d < 2) { return `${h} ч`; } else { return `${total_h[0]} ч (${n} н ${d} д ${h} ч)`; } } }