Search in sources :

Example 6 with EzyZoneContext

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

the class EzyPluginSendResponseImplTest method test.

@Test
public void test() {
    EzyPluginContext pluginContext = mock(EzyPluginContext.class);
    EzyPlugin plugin = mock(EzyPlugin.class);
    when(pluginContext.getPlugin()).thenReturn(plugin);
    EzySimplePluginSetting pluginSetting = new EzySimplePluginSetting();
    pluginSetting.setName("test");
    when(plugin.getSetting()).thenReturn(pluginSetting);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(pluginContext.getParent()).thenReturn(zoneContext);
    EzyServerContext serverContext = mock(EzyServerContext.class);
    when(zoneContext.getParent()).thenReturn(serverContext);
    EzyPluginSendResponseImpl cmd = new EzyPluginSendResponseImpl(pluginContext);
    EzyObject data = EzyEntityFactory.newObjectBuilder().build();
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    cmd.execute(data, session, false);
    cmd.execute(data, Lists.newArrayList(session), false);
}
Also used : EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyPluginSendResponseImpl(com.tvd12.ezyfoxserver.command.impl.EzyPluginSendResponseImpl) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyPlugin(com.tvd12.ezyfoxserver.EzyPlugin) EzyObject(com.tvd12.ezyfox.entity.EzyObject) EzySimplePluginSetting(com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 7 with EzyZoneContext

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

the class EzyBroadcastAppsEventImplTest method test.

@Test
public void test() {
    EzyEvent event2 = new EzySimpleServerInitializingEvent();
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    List<EzyAppContext> appContexts = Lists.newArrayList(newAppContext("1", event2), newAppContext("2", event2), newAppContext("3", event2));
    when(zoneContext.getAppContexts()).thenReturn(appContexts);
    EzyZone zone = mock(EzyZone.class);
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    zoneSetting.setName("test");
    when(zone.getSetting()).thenReturn(zoneSetting);
    when(zoneContext.getZone()).thenReturn(zone);
    EzyBroadcastAppsEventImpl cmd = new EzyBroadcastAppsEventImpl(zoneContext);
    EzyEvent event = new EzySimpleServerInitializingEvent();
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, true);
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, false);
    EzySimpleUser user = new EzySimpleUser();
    user.setName("user1");
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, user, true);
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, "user1", true);
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event2, true);
}
Also used : EzySimpleServerInitializingEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerInitializingEvent) EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyEvent(com.tvd12.ezyfoxserver.event.EzyEvent) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyBroadcastAppsEventImpl(com.tvd12.ezyfoxserver.command.impl.EzyBroadcastAppsEventImpl) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 8 with EzyZoneContext

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

the class EzyLoginProcessor method apply.

public void apply(EzyZoneContext zoneContext, EzyUserLoginEvent event) {
    EzyZone zone = zoneContext.getZone();
    EzyZoneSetting zoneSetting = zone.getSetting();
    EzyUserManagementSetting userManagementSetting = zoneSetting.getUserManagement();
    String username = checkUsername(event.getUsername(), userManagementSetting.getUserNamePattern(), userManagementSetting.isAllowGuestLogin(), userManagementSetting.getGuestNamePrefix());
    String password = event.getPassword();
    EzyZoneUserManager userManager = zone.getUserManager();
    EzyUser user;
    EzySession session = event.getSession();
    boolean alreadyLoggedIn;
    Lock lock = userManager.getLock(username);
    lock.lock();
    try {
        alreadyLoggedIn = userManager.containsUser(username);
        if (alreadyLoggedIn) {
            user = userManager.getUser(username);
        } else {
            user = newUser(zoneSetting, userManagementSetting, username, password, event.getUserProperties());
        }
        int maxSessionPerUser = userManagementSetting.getMaxSessionPerUser();
        boolean allowChangeSession = userManagementSetting.isAllowChangeSession();
        EzyStreamingSetting streamingSetting = zoneSetting.getStreaming();
        boolean streamingEnable = streamingSetting.isEnable() && event.isStreamingEnable();
        processUserSessions(user, session, maxSessionPerUser, allowChangeSession, streamingEnable);
        addUserToManager(userManager, user, session, alreadyLoggedIn);
    } finally {
        lock.unlock();
        userManager.removeLock(username);
    }
    fireUserAddedEvent(zoneContext, user, session, event.getData(), alreadyLoggedIn);
    EzyResponse response = newLoginResponse(zoneContext, user, event.getOutput());
    serverContext.send(response, session, false);
}
Also used : EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyStreamingSetting(com.tvd12.ezyfoxserver.setting.EzyStreamingSetting) EzyUserManagementSetting(com.tvd12.ezyfoxserver.setting.EzyUserManagementSetting) EzyZoneSetting(com.tvd12.ezyfoxserver.setting.EzyZoneSetting) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) Lock(java.util.concurrent.locks.Lock)

Example 9 with EzyZoneContext

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

the class EzyPluginInfoController method handle.

@Override
public void handle(EzyServerContext ctx, EzyPluginInfoRequest request) {
    EzyUser user = request.getUser();
    EzySession session = request.getSession();
    EzyPluginInfoParams params = request.getParams();
    EzyZoneContext zoneCtx = ctx.getZoneContext(user.getZoneId());
    EzyPluginContext pluginCtx = zoneCtx.getPluginContext(params.getPluginName());
    if (pluginCtx != null) {
        EzyPluginSetting setting = pluginCtx.getPlugin().getSetting();
        EzyResponse response = newPluginInfoResponse(setting);
        ctx.send(response, session, false);
    }
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyPluginInfoParams(com.tvd12.ezyfoxserver.request.EzyPluginInfoParams) EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyPluginSetting(com.tvd12.ezyfoxserver.setting.EzyPluginSetting)

Example 10 with EzyZoneContext

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

the class EzySimpleUserDelegate method onUserRemoved.

@Override
public void onUserRemoved(EzyUser user, EzyConstant reason) {
    EzyZoneContext zoneContext = serverContext.getZoneContext(user.getZoneId());
    EzySocketUserRemoval removal = new EzySimpleSocketUserRemoval(zoneContext, user, reason);
    userRemovalQueue.add(removal);
}
Also used : EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzySimpleSocketUserRemoval(com.tvd12.ezyfoxserver.socket.EzySimpleSocketUserRemoval) EzySocketUserRemoval(com.tvd12.ezyfoxserver.socket.EzySocketUserRemoval)

Aggregations

EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)77 Test (org.testng.annotations.Test)65 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)42 BaseTest (com.tvd12.test.base.BaseTest)26 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)24 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)23 EzyZone (com.tvd12.ezyfoxserver.EzyZone)21 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)21 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)20 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)20 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)18 EzySimpleZoneSetting (com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting)18 EzyArray (com.tvd12.ezyfox.entity.EzyArray)17 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)17 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)15 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)13 EzyPluginContext (com.tvd12.ezyfoxserver.context.EzyPluginContext)13 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)12 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)12 EzyServer (com.tvd12.ezyfoxserver.EzyServer)11