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/world/thread.d, selery/world/thread.d) 28 */ 29 module selery.world.thread; 30 31 import core.thread : Thread; 32 33 import std.concurrency : Tid, receiveTimeout; 34 import std.conv : to; 35 import std.datetime : dur; 36 import std.traits : isAbstractClass, Parameters; 37 38 import selery.config : Difficulty, Gamemode; 39 import selery.node.info : PlayerInfo, WorldInfo; 40 import selery.node.server : NodeServer; 41 import selery.player.player : PermissionLevel; 42 import selery.world.world : World; 43 44 void spawnWorld(T:World, E...)(shared NodeServer server, shared WorldInfo info, bool default_, E args) if(!isAbstractClass!T && __traits(compiles, new T(args))) { 45 46 Thread.getThis().name = "world#" ~ to!string(info.id); 47 48 T world = new T(args); 49 50 try { 51 52 //TODO register default events 53 //TODO register specific events 54 55 World.startWorld(server, info, world, null, default_); 56 world.startMainWorldLoop(); 57 //TODO stop 58 59 } catch(Throwable t) { 60 61 server.logger.logError(t); 62 throw t; 63 64 //TODO force the world to stop 65 66 } 67 68 } 69 70 // server to world 71 struct AddPlayer { 72 73 shared PlayerInfo player; 74 bool transferred; 75 76 } 77 78 // server to world 79 struct RemovePlayer { 80 81 uint playerId; 82 83 } 84 85 // server to world 86 struct GamePacket { 87 88 uint playerId; 89 immutable(ubyte)[] payload; 90 91 } 92 93 // server to world 94 struct Broadcast { 95 96 string message; 97 98 } 99 100 // server to world 101 struct UpdateDifficulty { 102 103 Difficulty difficulty; 104 105 } 106 107 // server to world 108 struct UpdatePlayerGamemode { 109 110 uint playerId; 111 Gamemode gamemode; 112 113 } 114 115 // server to world 116 struct UpdatePlayerPermissionLevel { 117 118 uint playerId; 119 PermissionLevel permissionLevel; 120 121 } 122 123 // server to world 124 struct Close {} 125 126 // world to server 127 struct CloseResult { 128 129 enum ubyte REMOVED = 0; 130 enum ubyte PLAYERS_ONLINE = 1; 131 132 uint worldId; 133 ubyte status; 134 135 }