Search in sources :

Example 1 with Message

use of cloud.timo.TimoCloud.common.protocol.Message in project TimoCloud by TimoCloud.

the class ServerTest method start.

@Test
public void start() throws Exception {
    mockStatic(HashUtil.class);
    when(HashUtil.getHashes(any(File.class))).thenReturn(null);
    when(coreFileManager.getServerGlobalDirectory()).thenReturn(new File("core/templates/server/Global/"));
    doAnswer(invocation -> {
        Message message = invocation.getArgument(0);
        getBaseStringHandler().handleMessage(message, message.toJson(), getBaseChannel());
        return null;
    }).when(getBaseObject()).sendMessage(any(Message.class));
    Server server = anyServer();
    server.start();
    ArgumentCaptor<BaseServerObject> argument = ArgumentCaptor.forClass(BaseServerObject.class);
    verify(TimoCloudBase.getInstance().getInstanceManager(), times(1)).addToServerQueue(argument.capture());
    BaseServerObject value = argument.getValue();
    assertEquals(server.getName(), value.getName());
    assertEquals(server.getId(), value.getId());
    assertEquals(server.getGroup().getName(), value.getGroup());
    assertEquals(server.isStatic(), value.isStatic());
    assertEquals(server.getMap(), value.getMap());
    assertEquals(server.getGroup().getRam(), value.getRam());
}
Also used : Message(cloud.timo.TimoCloud.common.protocol.Message) BaseServerObject(cloud.timo.TimoCloud.base.objects.BaseServerObject) File(java.io.File) CommunicationTest(cloud.timo.TimoCloud.communication.CommunicationTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with Message

use of cloud.timo.TimoCloud.common.protocol.Message in project TimoCloud by TimoCloud.

the class Server method requestPidStatus.

public void requestPidStatus() {
    if (getPid() == -1)
        return;
    Message message = Message.create().setType(MessageType.BASE_PID_EXIST_REQUEST).set("pid", getPid()).set("id", getId());
    getBase().sendMessage(message);
}
Also used : Message(cloud.timo.TimoCloud.common.protocol.Message)

Example 3 with Message

use of cloud.timo.TimoCloud.common.protocol.Message in project TimoCloud by TimoCloud.

the class Proxy method kill.

@Override
public void kill() {
    Message message = Message.create().setType(MessageType.BASE_INSTANCE_KILL).setData(getId());
    getBase().sendMessage(message);
    TimoCloudCore.getInstance().getCloudFlareManager().unregisterProxy(this);
    onShutdown();
}
Also used : Message(cloud.timo.TimoCloud.common.protocol.Message)

Example 4 with Message

use of cloud.timo.TimoCloud.common.protocol.Message in project TimoCloud by TimoCloud.

the class DebugCommandHandler method onCommand.

@Override
public void onCommand(String command, CommandSender sender, String... args) {
    try {
        Message jsonObject = DataCollector.collectData(TimoCloudCore.getInstance());
        TimoCloudCore.getInstance().getFileManager().saveJson(jsonObject, new File(TimoCloudCore.getInstance().getFileManager().getDebugDirectory(), DATE_FORMAT.format(new Date()) + ".json"));
    } catch (Exception e) {
        TimoCloudCore.getInstance().severe("An error occured while collecting debugging data: ");
        TimoCloudCore.getInstance().severe(e);
    }
}
Also used : Message(cloud.timo.TimoCloud.common.protocol.Message) File(java.io.File) Date(java.util.Date)

Example 5 with Message

use of cloud.timo.TimoCloud.common.protocol.Message in project TimoCloud by TimoCloud.

the class VelocityStringHandler method handleMessage.

@Override
public void handleMessage(Message message, String originalMessage, Channel channel) {
    if (message == null) {
        TimoCloudVelocity.getInstance().severe("Error while parsing json (json is null): " + originalMessage);
        return;
    }
    String server = (String) message.get("name");
    MessageType type = message.getType();
    Object data = message.getData();
    switch(type) {
        case PROXY_HANDSHAKE_SUCCESS:
            TimoCloudVelocity.getInstance().onHandshakeSuccess();
            break;
        case API_DATA:
            ((TimoCloudUniversalAPIVelocityImplementation) TimoCloudAPI.getUniversalAPI()).setData((Map<String, Object>) data);
            break;
        case EVENT_FIRED:
            try {
                EventType eventType = EnumUtil.valueOf(EventType.class, (String) message.get("eT"));
                ((EventManager) TimoCloudAPI.getEventAPI()).callEvent(((TimoCloudUniversalAPIBasicImplementation) TimoCloudAPI.getUniversalAPI()).getObjectMapper().readValue((String) data, EventUtil.getClassByEventType(eventType)));
            } catch (Exception e) {
                System.err.println("Error while parsing event from json: ");
                TimoCloudVelocity.getInstance().severe(e);
            }
            break;
        case CORE_SEND_MESSAGE_TO_COMMAND_SENDER:
            {
                TimoCloudVelocity.getInstance().getTimoCloudCommand().sendMessage((String) message.get("sender"), (String) data);
            }
        case PROXY_EXECUTE_COMMAND:
            TimoCloudVelocity.getInstance().getServer().getCommandManager().executeImmediatelyAsync(TimoCloudVelocity.getInstance().getServer().getConsoleCommandSource(), (String) data);
            break;
        case PROXY_SEND_PLAYER:
            {
                Map<String, Object> information = (Map<String, Object>) data;
                String playerUUID = (String) information.get("playerUUID");
                String serverObject = (String) information.get("serverObject");
                Optional<Player> player = TimoCloudVelocity.getInstance().getServer().getPlayer(UUID.fromString(playerUUID));
                player.ifPresent(it -> it.createConnectionRequest(TimoCloudVelocity.getInstance().getServer().getServer(serverObject).get()).fireAndForget());
                break;
            }
        case PROXY_SEND_MESSAGE:
            Map<String, Object> information = (Map<String, Object>) data;
            String playerUUID = (String) information.get("playerUUID");
            String chatMessage = (String) information.get("chatMessage");
            Optional<Player> player = TimoCloudVelocity.getInstance().getServer().getPlayer(UUID.fromString(playerUUID));
            player.ifPresent(it -> it.sendMessage(Component.text(chatMessage)));
            break;
        case PROXY_ADD_SERVER:
            TimoCloudVelocity.getInstance().getServer().registerServer(new ServerInfo(server, new InetSocketAddress((String) message.get("address"), ((Number) message.get("port")).intValue())));
            break;
        case PROXY_REMOVE_SERVER:
            TimoCloudVelocity.getInstance().getServer().unregisterServer(TimoCloudVelocity.getInstance().getServer().getServer(server).get().getServerInfo());
            break;
        case CORD_SET_IP:
            try {
                TimoCloudVelocity.getInstance().getIpManager().setAddresses(InetAddressUtil.getSocketAddressByName((String) message.get("CHANNEL_ADDRESS")), InetAddressUtil.getSocketAddressByName((String) message.get("CLIENT_ADDRESS")));
            } catch (Exception e) {
                TimoCloudVelocity.getInstance().severe("Error while parsing IP addresses (" + message.get("CHANNEL_ADDRESS") + ", " + message.get("CLIENT_ADDRESS") + "): ");
                TimoCloudVelocity.getInstance().severe(e);
            }
            break;
        case ON_PLUGIN_MESSAGE:
            {
                AddressedPluginMessage addressedPluginMessage = PluginMessageSerializer.deserialize((Map) data);
                ((TimoCloudMessageAPIBasicImplementation) TimoCloudAPI.getMessageAPI()).onMessage(addressedPluginMessage);
                break;
            }
        case PROXY_STOP:
            {
                TimoCloudVelocity.getInstance().stop();
                break;
            }
        default:
            TimoCloudVelocity.getInstance().severe("Could not categorize json message: " + message);
    }
}
Also used : Message(cloud.timo.TimoCloud.common.protocol.Message) EnumUtil(cloud.timo.TimoCloud.common.utils.EnumUtil) InetAddressUtil(cloud.timo.TimoCloud.common.utils.network.InetAddressUtil) EventManager(cloud.timo.TimoCloud.api.implementations.managers.EventManager) EventUtil(cloud.timo.TimoCloud.api.utils.EventUtil) UUID(java.util.UUID) InetSocketAddress(java.net.InetSocketAddress) TimoCloudUniversalAPIBasicImplementation(cloud.timo.TimoCloud.api.implementations.TimoCloudUniversalAPIBasicImplementation) TimoCloudAPI(cloud.timo.TimoCloud.api.TimoCloudAPI) Channel(io.netty.channel.Channel) TimoCloudUniversalAPIVelocityImplementation(cloud.timo.TimoCloud.velocity.api.TimoCloudUniversalAPIVelocityImplementation) ServerInfo(com.velocitypowered.api.proxy.server.ServerInfo) Component(net.kyori.adventure.text.Component) TimoCloudMessageAPIBasicImplementation(cloud.timo.TimoCloud.api.implementations.TimoCloudMessageAPIBasicImplementation) Player(com.velocitypowered.api.proxy.Player) Map(java.util.Map) BasicStringHandler(cloud.timo.TimoCloud.common.sockets.BasicStringHandler) Optional(java.util.Optional) PluginMessageSerializer(cloud.timo.TimoCloud.common.utils.PluginMessageSerializer) EventType(cloud.timo.TimoCloud.api.events.EventType) AddressedPluginMessage(cloud.timo.TimoCloud.api.messages.objects.AddressedPluginMessage) MessageType(cloud.timo.TimoCloud.common.protocol.MessageType) TimoCloudVelocity(cloud.timo.TimoCloud.velocity.TimoCloudVelocity) Player(com.velocitypowered.api.proxy.Player) TimoCloudUniversalAPIVelocityImplementation(cloud.timo.TimoCloud.velocity.api.TimoCloudUniversalAPIVelocityImplementation) EventManager(cloud.timo.TimoCloud.api.implementations.managers.EventManager) Optional(java.util.Optional) EventType(cloud.timo.TimoCloud.api.events.EventType) ServerInfo(com.velocitypowered.api.proxy.server.ServerInfo) InetSocketAddress(java.net.InetSocketAddress) AddressedPluginMessage(cloud.timo.TimoCloud.api.messages.objects.AddressedPluginMessage) TimoCloudUniversalAPIBasicImplementation(cloud.timo.TimoCloud.api.implementations.TimoCloudUniversalAPIBasicImplementation) Map(java.util.Map) MessageType(cloud.timo.TimoCloud.common.protocol.MessageType)

Aggregations

Message (cloud.timo.TimoCloud.common.protocol.Message)13 File (java.io.File)5 Channel (io.netty.channel.Channel)3 TimoCloudAPI (cloud.timo.TimoCloud.api.TimoCloudAPI)2 EventType (cloud.timo.TimoCloud.api.events.EventType)2 TimoCloudUniversalAPIBasicImplementation (cloud.timo.TimoCloud.api.implementations.TimoCloudUniversalAPIBasicImplementation)2 EventManager (cloud.timo.TimoCloud.api.implementations.managers.EventManager)2 AddressedPluginMessage (cloud.timo.TimoCloud.api.messages.objects.AddressedPluginMessage)2 EventUtil (cloud.timo.TimoCloud.api.utils.EventUtil)2 MessageType (cloud.timo.TimoCloud.common.protocol.MessageType)2 BasicStringHandler (cloud.timo.TimoCloud.common.sockets.BasicStringHandler)2 EnumUtil (cloud.timo.TimoCloud.common.utils.EnumUtil)2 PluginMessageSerializer (cloud.timo.TimoCloud.common.utils.PluginMessageSerializer)2 Base (cloud.timo.TimoCloud.core.objects.Base)2 InetSocketAddress (java.net.InetSocketAddress)2 CommandSender (cloud.timo.TimoCloud.api.core.commands.CommandSender)1 TimoCloudMessageAPIBasicImplementation (cloud.timo.TimoCloud.api.implementations.TimoCloudMessageAPIBasicImplementation)1 TimoCloud.api.objects (cloud.timo.TimoCloud.api.objects)1 BaseServerObject (cloud.timo.TimoCloud.base.objects.BaseServerObject)1 BaseStringHandler (cloud.timo.TimoCloud.base.sockets.BaseStringHandler)1