Search in sources :

Example 11 with EzyPluginContext

use of com.tvd12.ezyfoxserver.context.EzyPluginContext in project ezyfox-server by youngmonkeys.

the class EzyDefaultPluginEntryTest method handleClientRequest.

private void handleClientRequest(EzyPluginContext context) {
    EzySimplePlugin plugin = (EzySimplePlugin) context.getPlugin();
    EzyPluginRequestController requestController = plugin.getRequestController();
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    EzyArray data = EzyEntityFactory.newArrayBuilder().append("chat").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    EzyUserRequestPluginEvent event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("chat").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("no command").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noUser").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noSession").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noDataBinding").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestSend").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestNoSend").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("exception").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    try {
        requestController.handle(context, event);
    } catch (Exception e) {
        assert e instanceof IllegalStateException;
    }
    data = EzyEntityFactory.newArrayBuilder().append("plugin").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
}
Also used : EzySimpleUserRequestPluginEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserRequestPluginEvent) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyPluginRequestController(com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) EzyUserRequestPluginEvent(com.tvd12.ezyfoxserver.event.EzyUserRequestPluginEvent)

Example 12 with EzyPluginContext

use of com.tvd12.ezyfoxserver.context.EzyPluginContext in project ezyfox-server-example by tvd12.

the class UserLoginController method handle.

@Override
public void handle(EzyPluginContext ctx, EzyUserLoginEvent event) {
    logger.info("{} login in", event.getUsername());
    String username = event.getUsername();
    String password = encodePassword(event.getPassword());
    User user = userService.getUser(username);
    if (user == null) {
        logger.info("User doesn't exist in db, create a new one!");
        user = userService.createUser(username, password);
        userService.saveUser(user);
    }
    if (!user.getPassword().equals(password)) {
        throw new EzyLoginErrorException(EzyLoginError.INVALID_PASSWORD);
    }
    logger.info("user and password match, accept user: {}", username);
}
Also used : User(com.tvd12.example.lucky_wheel.entity.User) EzyLoginErrorException(com.tvd12.ezyfoxserver.exception.EzyLoginErrorException)

Example 13 with EzyPluginContext

use of com.tvd12.ezyfoxserver.context.EzyPluginContext in project ezyfox-server-example by tvd12.

the class PluginEntry method setupBeanContext.

@Override
protected void setupBeanContext(EzyPluginContext context, EzyBeanContextBuilder builder) {
    EzyPluginSetting setting = context.getPlugin().getSetting();
    String pluginConfigFile = getConfigFile(setting);
    builder.addProperties(pluginConfigFile);
    logger.info("hello-world plugin config file: {}", pluginConfigFile);
}
Also used : EzyPluginSetting(com.tvd12.ezyfoxserver.setting.EzyPluginSetting)

Example 14 with EzyPluginContext

use of com.tvd12.ezyfoxserver.context.EzyPluginContext in project ezyfox-server by youngmonkeys.

the class EzyRequestPluginControllerTest method test.

@Test
public void test() {
    EzyRequestPluginController controller = new EzyRequestPluginController();
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(serverContext.getZoneContext(1)).thenReturn(zoneContext);
    EzyPluginContext pluginContext = mock(EzyPluginContext.class);
    when(zoneContext.getPluginContext(1)).thenReturn(pluginContext);
    EzyPlugin plugin = mock(EzyPlugin.class);
    when(pluginContext.getPlugin()).thenReturn(plugin);
    EzyPluginRequestController requestController = mock(EzyPluginRequestController.class);
    when(plugin.getRequestController()).thenReturn(requestController);
    EzySimpleRequestPluginRequest request = new EzySimpleRequestPluginRequest();
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    user.setZoneId(1);
    user.setId(1);
    user.setName("test");
    request.setSession(session);
    request.setUser(user);
    EzyArray array = EzyEntityFactory.newArrayBuilder().append(1).append(EzyEntityFactory.newArrayBuilder()).build();
    request.deserializeParams(array);
    controller.handle(serverContext, request);
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzySimpleRequestPluginRequest(com.tvd12.ezyfoxserver.request.EzySimpleRequestPluginRequest) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyRequestPluginController(com.tvd12.ezyfoxserver.controller.EzyRequestPluginController) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext) EzyPluginRequestController(com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController) EzyPlugin(com.tvd12.ezyfoxserver.EzyPlugin) EzyArray(com.tvd12.ezyfox.entity.EzyArray) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 15 with EzyPluginContext

use of com.tvd12.ezyfoxserver.context.EzyPluginContext in project ezyfox-server by youngmonkeys.

the class EzyBroadcastPluginsEventImpl method fire.

@Override
public void fire(EzyConstant type, EzyEvent event, boolean catchException) {
    logger.debug("zone: {} broadcast to plugins event: {}", getZoneName(), type);
    Set<EzyPluginContext> pluginContexts = pluginContextMaps.get(type);
    if (pluginContexts != null) {
        for (EzyPluginContext pluginContext : pluginContexts) {
            firePluginEvent(pluginContext, type, event, catchException);
        }
    }
}
Also used : EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext)

Aggregations

EzyPluginContext (com.tvd12.ezyfoxserver.context.EzyPluginContext)16 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)13 Test (org.testng.annotations.Test)11 EzyPluginSetting (com.tvd12.ezyfoxserver.setting.EzyPluginSetting)8 BaseTest (com.tvd12.test.base.BaseTest)8 EzyPlugin (com.tvd12.ezyfoxserver.EzyPlugin)7 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)7 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)6 EzyPluginRequestController (com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController)6 EzyArray (com.tvd12.ezyfox.entity.EzyArray)5 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)5 EzySimplePlugin (com.tvd12.ezyfoxserver.EzySimplePlugin)4 EzyZone (com.tvd12.ezyfoxserver.EzyZone)4 EzyPluginSetup (com.tvd12.ezyfoxserver.command.EzyPluginSetup)4 EzyUserRequestPluginEvent (com.tvd12.ezyfoxserver.event.EzyUserRequestPluginEvent)4 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 EzyServerReadyEvent (com.tvd12.ezyfoxserver.event.EzyServerReadyEvent)3 EzySimpleServerReadyEvent (com.tvd12.ezyfoxserver.event.EzySimpleServerReadyEvent)3 EzySimpleUserRequestPluginEvent (com.tvd12.ezyfoxserver.event.EzySimpleUserRequestPluginEvent)3 EzySimplePluginSetting (com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting)3