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));
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations