Search in sources :

Example 16 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class EzySocketResponseApiTest method normalResponseTest.

@Test
public void normalResponseTest() throws Exception {
    // given
    EzyArray data = EzyEntityFactory.EMPTY_ARRAY;
    EzyObjectToByteEncoder encoder = mock(EzyObjectToByteEncoder.class);
    byte[] bytes = RandomUtil.randomShortByteArray();
    when(encoder.encode(data)).thenReturn(bytes);
    EzySocketResponseApi sut = new EzySocketResponseApi(encoder);
    EzySimplePackage pack = new EzySimplePackage();
    pack.setData(data);
    pack.setEncrypted(false);
    pack.setTransportType(EzyTransportType.TCP);
    int sessionCount = RandomUtil.randomSmallInt() + 1;
    List<EzySession> sessions = RandomUtil.randomList(sessionCount, () -> {
        EzySession session = mock(EzySession.class);
        when(session.getConnectionType()).thenReturn(EzyConnectionType.SOCKET);
        return session;
    });
    pack.addRecipients(sessions);
    // when
    sut.response(pack);
    // then
    verify(encoder, times(1)).encode(data);
    verify(encoder, times(0)).toMessageContent(data);
    verify(encoder, times(0)).encryptMessageContent(any(byte[].class), any(byte[].class));
}
Also used : EzySimplePackage(com.tvd12.ezyfoxserver.socket.EzySimplePackage) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyObjectToByteEncoder(com.tvd12.ezyfox.codec.EzyObjectToByteEncoder) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzySocketResponseApi(com.tvd12.ezyfoxserver.api.EzySocketResponseApi) Test(org.testng.annotations.Test)

Example 17 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class EzyLoginController method responseLoginError.

protected void responseLoginError(EzyServerContext ctx, EzySession session, EzyILoginError error) {
    EzyResponse response = newLoginErrorResponse(error);
    ctx.send(response, session, false);
}
Also used : EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse)

Example 18 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession 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 19 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class EzyPingController method handle.

@Override
public void handle(EzyServerContext ctx, EzyPingRequest request) {
    EzyResponse response = EzyPongResponse.getInstance();
    EzySession session = request.getSession();
    ctx.send(response, session, false);
}
Also used : EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession)

Example 20 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession 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)

Aggregations

EzySession (com.tvd12.ezyfoxserver.entity.EzySession)112 Test (org.testng.annotations.Test)92 EzyArray (com.tvd12.ezyfox.entity.EzyArray)33 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)26 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)25 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)25 BaseTest (com.tvd12.test.base.BaseTest)25 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)15 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)14 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)13 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)13 EzySimpleLoginRequest (com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest)13 EzyLoginController (com.tvd12.ezyfoxserver.controller.EzyLoginController)12 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)11 EzySendResponseImpl (com.tvd12.ezyfoxserver.command.impl.EzySendResponseImpl)8 EzyHandshakeController (com.tvd12.ezyfoxserver.controller.EzyHandshakeController)8 EzyHandshakeParams (com.tvd12.ezyfoxserver.request.EzyHandshakeParams)8 EzySimpleResponse (com.tvd12.ezyfoxserver.response.EzySimpleResponse)8 GreetResponse (com.tvd12.ezyfoxserver.support.test.data.GreetResponse)8 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)8