1 /* 2 * Copyright (c) 2017-2018 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: 2017-2018 sel-project 25 * License: MIT 26 * Authors: Kripth 27 * Source: $(HTTP github.com/sel-project/selery/source/selery/server.d, selery/server.d) 28 */ 29 module selery.server; 30 31 import selery.config : Config, Files; 32 import selery.lang : LanguageManager; 33 import selery.log : Logger; 34 import selery.plugin : Plugin; 35 36 /** 37 * Generic server with a configuration and plugins. 38 */ 39 interface Server { 40 41 /** 42 * Gets the server's configuration. 43 * Example: 44 * --- 45 * // server name 46 * log("Welcome to ", server.config.hub.displayName); 47 * 48 * // game version 49 * static if(__pocket) assert(server.config.node.pocket); 50 * static if(__minecraft) log("Port for Minecraft: ", server.config.node.minecraft.port); 51 * --- 52 */ 53 shared nothrow @property @safe @nogc const(Config) config(); 54 55 /** 56 * Gets the server's files (assets and temp files). 57 * Example: 58 * --- 59 * if(!server.files.hasTemp("test")) { 60 * server.files.writeTemp("test", "Some content"); 61 * assert(server.files.readTemp("test" == "Some content"); 62 * } 63 * --- 64 */ 65 final shared nothrow @property @safe @nogc const(Files) files() { 66 return this.config.files; 67 } 68 69 /** 70 * Gets the server's language manager. 71 */ 72 final shared nothrow @property @safe @nogc const(LanguageManager) lang() { 73 return this.config.lang; 74 } 75 76 /** 77 * Gets the server's logger. 78 * Example: 79 * --- 80 * server.logger.log("Hello"); 81 * --- 82 */ 83 shared @property Logger logger(); 84 85 /** 86 * Gets the plugins actived on the server. 87 * Example: 88 * --- 89 * log("There are ", server.plugins.filter!(a => a.author == "sel-plugins").length, " by sel-plugins"); 90 * log("There are ", server.plugins.filter!(a => a.api).length, " plugins with APIs"); 91 * --- 92 */ 93 shared nothrow @property @safe @nogc const(Plugin)[] plugins(); 94 95 }