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/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, logger and plugins.
38  */
39 interface Server {
40 
41 	/**
42 	 * Gets the server's configuration.
43 	 * Example:
44 	 * ---
45 	 * // server name
46 	 * writeln("Welcome to ", server.config.hub.displayName);
47 	 * 
48 	 * // game version
49 	 * if(server.config.node.java) writeln("Port for Java Edition: ", server.config.node.java.port); 
50 	 * ---
51 	 */
52 	shared nothrow @property @safe @nogc const(Config) config();
53 
54 	/**
55 	 * Gets the server's files (assets and temp files).
56 	 * Example:
57 	 * ---
58 	 * if(!server.files.hasTemp("test")) {
59 	 *    server.files.writeTemp("test", "Some content");
60 	 *    assert(server.files.readTemp("test" == "Some content");
61 	 * }
62 	 * ---
63 	 */
64 	final shared nothrow @property @safe @nogc const(Files) files() {
65 		return this.config.files;
66 	}
67 
68 	/**
69 	 * Gets the server's language manager.
70 	 */
71 	final shared nothrow @property @safe @nogc const(LanguageManager) lang() {
72 		return this.config.lang;
73 	}
74 
75 	/**
76 	 * Gets the server's logger.
77 	 * Example:
78 	 * ---
79 	 * server.logger.log("Hello");
80 	 * ---
81 	 */
82 	shared @property Logger logger();
83 
84 	/**
85 	 * Gets the plugins actived on the server.
86 	 * Example:
87 	 * ---
88 	 * writeln("There are ", server.plugins.filter!(a => a.author == "sel-plugins").length, " by sel-plugins");
89 	 * writeln("There are ", server.plugins.filter!(a => a.api).length, " plugins with APIs");
90 	 * ---
91 	 */
92 	shared nothrow @property @safe @nogc const(Plugin)[] plugins();
93 
94 }