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/event/hub/server.d, selery/event/hub/server.d)
28  */
29 module selery.event.hub.server;
30 
31 import selery.event.event : Event;
32 import selery.hub.server : HubServer;
33 import selery.log : Message;
34 
35 /**
36  * Base class for every event that is triggered by the hub server.
37  */
38 abstract class HubServerEvent : Event {
39 	
40 	private shared HubServer _server;
41 	
42 	public this(shared HubServer server) pure nothrow @safe @nogc {
43 		this._server = server;
44 	}
45 
46 	/**
47 	 * Gets the hub server that has triggered the event.
48 	 */
49 	public final @property shared(HubServer) server() pure nothrow @safe @nogc {
50 		return this._server;
51 	}
52 	
53 }
54 
55 /**
56  * Event called when a message is logged to the console.
57  */
58 class LogEvent : HubServerEvent {
59 
60 	private Message[] _messages;
61 	int _commandId;
62 	int _worldId;
63 
64 	public this(shared HubServer server, Message[] messages, int commandId, int worldId) pure nothrow @safe @nogc {
65 		super(server);
66 		_messages = messages;
67 		_commandId = commandId;
68 		_worldId = worldId;
69 	}
70 
71 	/**
72 	 * Gets the log's message.
73 	 */
74 	public final @property Message[] messages() pure nothrow @safe @nogc {
75 		return _messages;
76 	}
77 
78 	/**
79 	 * Gets the command id, if the log is the result of an input given by
80 	 * an external application. Returns -1 if the log was not genearated by
81 	 * an external input.
82 	 */
83 	public final @property int commandId() pure nothrow @safe @nogc {
84 		return _commandId;
85 	}
86 
87 	/**
88 	 * Gets the id of the world that has generated the log or -1 if the log
89 	 * was not generated by a world.
90 	 */
91 	public final @property int worldId() pure nothrow @safe @nogc {
92 		return _worldId;
93 	}
94 
95 }