1 /*
2 * Copyright (c) 2017-2019 sel-project
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 *
22 */23 /**
24 * Copyright: Copyright (c) 2017-2019 sel-project
25 * License: MIT
26 * Authors: Kripth
27 * Source: $(HTTP github.com/sel-project/selery/source/selery/about.d, selery/about.d)
28 */29 moduleselery.about;
30 31 importstd.algorithm : sort, reverse, canFind;
32 importstd.conv : to;
33 importstd.json : JSONValue;
34 importstd..string : toLower, split, join, startsWith;
35 importstd.typetuple : TypeTuple;
36 37 aliassuuid_t = immutable(ubyte)[17];
38 39 aliastick_t = size_t;
40 41 aliasblock_t = ushort;
42 43 aliasitem_t = size_t;
44 45 /**
46 * Informations about the software, like name, codename,
47 * versions and protocols used.
48 */49 conststructSoftware {
50 51 @disablethis();
52 53 /**
54 * Formatted name of the software.
55 * It should be used for display and usage purposes.
56 * Example:
57 * ---
58 * writeln("You're running ", Software.name, " based on SEL");
59 * ---
60 */61 enumstringname = "Selery";
62 63 /**
64 * Lowercase name of the software.
65 * Example:
66 * ---
67 * assert(Software.name.toLower == Software.lname);
68 * ---
69 */70 enumstringlname = name.toLower;
71 72 /**
73 * Website of the software.
74 * Source code should be at website/source and downloads
75 * at website/downloads.
76 * Example:
77 * ---
78 * download("http://" ~ Software.website ~ "/downloads/1.0.0.sa", "1.0.0.sa");
79 * ---
80 */81 enumstringwebsite = "";
82 83 /**
84 * Codename and representations related to the version or
85 * the group of versions of the software.
86 * Used only for display purposes.
87 */88 enumstringcodename = "Cookie";
89 90 /// ditto91 enumstringcodenameEmoji = "🍪";
92 93 /// ditto94 enumstringfullCodename = codename ~ " (" ~ codenameEmoji ~ ")";
95 96 /**
97 * Version of the software.
98 */99 enumubytemajor = 0;
100 101 /// ditto102 enumubyteminor = 3;
103 104 /// ditto105 enumubytepatch = 0;
106 107 /// ditto108 enumubyte[3] versions = [major, minor, patch];
109 110 /**
111 * Version of the software in format major.minor.patch following the
112 * $(HTTP http://semver.org, Semantic Version 2.0.0) (for example
113 * `1.1.0`) for display purposes.
114 */115 enumstringdisplayVersion = to!string(major) ~ "." ~ to!string(minor) ~ "." ~ to!string(patch);
116 117 /**
118 * Full version of the software prefixed with a `v` and suffixed
119 * with a build version if the version is not stable.
120 */121 enumstringfullVersion = "v" ~ displayVersion;
122 123 /**
124 * Display name of the software that contains both the software name
125 * and the version in the format name/version (for example `Selery/0.0.1`).
126 */127 enumstringdisplay = name ~ "/" ~ displayVersion;
128 129 enumstringsimpleDisplay = name ~ " " ~ to!string(major) ~ "." ~ to!string(minor) ~ (patch != 0 ? "." ~ to!string(patch) : "");
130 131 /+/**
132 * Version of the api used by the software. It's used to check the
133 * compatibility with plugins.
134 */
135 enum ubyte api = 1;+/136 137 publicstaticJSONValuetoJSON() {
138 JSONValue[string] ret;
139 foreach(member ; TypeTuple!("name", /*"website",*/"displayVersion", "fullVersion", "codename", "display")) {
140 ret[member] = JSONValue(mixin(member));
141 }
142 ret["version"] = ["major": major, "minor": minor, "patch": patch];
143 returnJSONValue(ret);
144 }
145 146 }
147 148 /// Protocols supported by the software.149 enumuint[] supportedBedrockProtocols = [137, 141, 150, 160];
150 151 /// ditto152 enumuint[] supportedJavaProtocols = [210, 315, 316, 335, 338, 340];
153 154 /// Newest protocol supported.155 enumnewestBedrockProtocol = supportedBedrockProtocols[$-1];
156 157 /// ditto158 enumnewestJavaProtocol = supportedJavaProtocols[$-1];
159 160 /// Latest protocols (latest version e.g 1.2.*).161 enumuint[] latestBedrockProtocols = [137, 141, 150, 160];
162 163 /// ditto164 enumuint[] latestJavaProtocols = [335, 338, 340];
165 166 /// Tuples with the supported protocols.167 aliasSupportedBedrockProtocols = ProtocolsImpl!(supportedBedrockProtocols);
168 169 /// ditto170 aliasSupportedJavaProtocols = ProtocolsImpl!(supportedJavaProtocols);
171 172 privatetemplateProtocolsImpl(uint[] protocols, E...) {
173 staticif(protocols.length) {
174 aliasProtocolsImpl = ProtocolsImpl!(protocols[1..$], E, protocols[0]);
175 } else {
176 aliasProtocolsImpl = E;
177 }
178 }
179 180 uint[] validateProtocols(refuint[] protocols, uint[] accepted, uint[] default_) {
181 uint[] ret;
182 foreach(protocol ; protocols) {
183 if(accepted.canFind(protocol)) ret ~= protocol;
184 }
185 return (protocols = (ret.length ? ret : default_));
186 }
187 188 version(D_Ddoc) {
189 190 /// Indicates whether the software has been tested on the current OS191 enumbool__supported = true;
192 193 } else {
194 195 version(Windows) enumbool__supported = true;
196 elseversion(linux) enumbool__supported = true;
197 elseversion(FreeBSD) enumbool__supported = false;
198 elseversion(OSX) enumbool__supported = false;
199 elseversion(Android) enumbool__supported = false;
200 elseenumbool__supported = false;
201 202 }