Search in sources :

Example 76 with User

use of com.tvd12.example.lucky_wheel.entity.User in project ezyfox-server by youngmonkeys.

the class EzySocketUserRemovalHandler method processUserRemoval.

private void processUserRemoval(EzySocketUserRemoval removal) {
    try {
        EzyUser user = removal.getUser();
        try {
            EzyConstant reason = removal.getReason();
            EzyZoneContext zoneContext = removal.getZoneContext();
            EzyUserRemovedEvent event = newUserRemovedEvent(user, reason);
            removeUserFromApps(zoneContext, event);
            notifyUserRemovedToPlugins(zoneContext, event);
        } finally {
            user.destroy();
        }
        logger.debug("user {} has destroyed", user);
    } finally {
        removal.release();
    }
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) EzyUserRemovedEvent(com.tvd12.ezyfoxserver.event.EzyUserRemovedEvent)

Example 77 with User

use of com.tvd12.example.lucky_wheel.entity.User in project ezyfox-server by youngmonkeys.

the class EzySocketUserRemovalHandler method removeUserFromApp.

protected void removeUserFromApp(EzyAppContext appContext, EzyUserRemovedEvent event) {
    EzyUser user = event.getUser();
    EzyApplication app = appContext.getApp();
    EzyAppUserManager userManager = app.getUserManager();
    try {
        boolean contains = userManager.containsUser(user);
        if (contains) {
            userManager.removeUser(user, event.getReason());
        }
    } catch (Exception e) {
        String appName = app.getSetting().getName();
        logger.error("remove user: {} from app: {} error", event.getUser(), appName, e);
    }
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyProcessor.processWithLogException(com.tvd12.ezyfox.util.EzyProcessor.processWithLogException)

Example 78 with User

use of com.tvd12.example.lucky_wheel.entity.User in project ezyfox-server by youngmonkeys.

the class EzyAbstractUserManager method addUser.

@Override
public EzyUser addUser(EzyUser user) {
    EzyUser answer = doAddUser(user);
    logger.info("{} add user: {}, locks.size = {}, usersById.size = {}, usersByName.size = {}", getMessagePrefix(), user, locks.size(), usersById.size(), usersByName.size());
    return answer;
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser)

Example 79 with User

use of com.tvd12.example.lucky_wheel.entity.User in project ezyfox-server by youngmonkeys.

the class EzySimplePluginEntryTest 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 80 with User

use of com.tvd12.example.lucky_wheel.entity.User in project ezyfox-server by youngmonkeys.

the class EzyUserManagerImplTest method test.

@Test
public void test() {
    MyTestUserManager manager = MyTestUserManager.builder().build();
    MyTestSession session = new MyTestSession();
    session.setId(10);
    MyTestUser user = new MyTestUser();
    user.setId(1);
    user.setName("dungtv");
    session.setToken("123456");
    user.addSession(session);
    manager.addUser(session, user);
    assert manager.getUser(1) == user;
    assert manager.getUser("dungtv") == user;
    assert manager.containsUser(1);
    assert !manager.containsUser(-1);
    assert manager.containsUser(session);
    assert manager.containsUser(user);
    manager.removeUser(user.getId());
    assert manager.getUser(1) == null;
    manager.addUser(session, user);
    manager.removeUser(user.getName());
    assert manager.getUser("dungtv") == null;
    manager.addUser(session, user);
    manager.removeUser((EzyUser) null);
}
Also used : MyTestUser(com.tvd12.ezyfoxserver.testing.MyTestUser) MyTestSession(com.tvd12.ezyfoxserver.testing.MyTestSession) MyTestUserManager(com.tvd12.ezyfoxserver.testing.MyTestUserManager) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)42 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)33 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)28 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)25 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)20 EzyArray (com.tvd12.ezyfox.entity.EzyArray)16 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)16 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)15 BaseTest (com.tvd12.test.base.BaseTest)14 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)13 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)12 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)10 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)10 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)8 GreetResponse (com.tvd12.ezyfoxserver.support.test.data.GreetResponse)8 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)8 EzyDoHandle (com.tvd12.ezyfox.core.annotation.EzyDoHandle)7 EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)7 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)7 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)7