internal void OnJoinMessage(MessageEventArgs <JoinMessage> e) { var join = e.Message; if (!e.Connection.IsConnected) { return; } if (join.Nickname.IsNullOrWhitespace()) { e.Connection.SendAsync(new JoinResultMessage(LoginResultState.FailedInvalidNickname, null)); return; } if (!String.IsNullOrEmpty(this.context.Settings.ServerPassword) && join.ServerPassword != this.context.Settings.ServerPassword) { e.Connection.SendAsync(new JoinResultMessage(LoginResultState.FailedServerPassword, null)); return; } IUserInfo info = GetJoiningUserInfo(e.Connection, join); if (info == null) { return; } LoginResultState result = LoginResultState.Success; if (Manager.GetIsNicknameInUse(join.Nickname)) { if (!AttemptNicknameRecovery(info, join.Nickname)) { result = LoginResultState.FailedNicknameInUse; } } var msg = new JoinResultMessage(result, info); if (result == LoginResultState.Success) { Manager.Join(e.Connection, info); e.Connection.SendAsync(msg); if (!Manager.GetIsLoggedIn(e.Connection)) { e.Connection.SendAsync(new PermissionsMessage(info.UserId, this.context.PermissionsProvider.GetPermissions(info.UserId))); } foreach (IConnection connection in this.context.Connections) { connection.SendAsync(new UserJoinedMessage(info)); } } else { e.Connection.SendAsync(msg); } }
public void Setup() { manager = new ServerUserManager(); permissions = new MockPermissionsProvider(); channels = new LobbyChannelProvider(); MockServerContext mcontext; context = mcontext = new MockServerContext { ChannelsProvider = channels, PermissionsProvider = permissions, UserManager = new ServerUserManager(), Settings = new ServerSettings { Name = "Test Server" } }; mcontext.Users = new ServerUserHandler(context, manager); mcontext.Channels = handler = new ServerChannelHandler(context); user = UserInfoTests.GetTestUser(1, 1, false); provider = new MockConnectionProvider(GablarskiProtocol.Instance); mcontext.AddConnectionProvider(provider); mcontext.Start(); var connections = provider.GetConnections(GablarskiProtocol.Instance); client = new ConnectionBuffer(connections.Item1); server = connections.Item2; manager.Connect(server); manager.Join(server, user); }
public void Setup() { permissions = new MockPermissionsProvider(); LobbyChannelProvider channels = new LobbyChannelProvider(); channels.SaveChannel(new ChannelInfo { Name = "Channel 2" }); this.provider = new MockConnectionProvider(GablarskiProtocol.Instance); this.provider.Start(MessageTypes.All); userManager = new ServerUserManager(); MockServerContext c; context = c = new MockServerContext(provider) { Settings = new ServerSettings { Name = "Server", DefaultAudioBitrate = defaultBitrate, MaximumAudioBitrate = maxBitrate, MinimumAudioBitrate = minBitrate }, UserManager = userManager, PermissionsProvider = permissions, ChannelsProvider = channels }; c.Users = new ServerUserHandler(context, userManager); manager = new ServerSourceManager(context); handler = new ServerSourceHandler(context, manager); user = UserInfoTests.GetTestUser(1, 1, false); var cs = provider.GetConnections(GablarskiProtocol.Instance); client = new ConnectionBuffer(cs.Item1); server = cs.Item2; userManager.Connect(server); userManager.Join(server, user); }
public void JoinChannelAtLimit() { permissions.EnablePermissions(user.UserId, PermissionName.ChangeChannel); Assert.AreEqual(ChannelEditResult.Success, channels.SaveChannel(new ChannelInfo { Name = "Channel 2", UserLimit = 1 })); client.DequeueAndAssertMessage <ChannelListMessage>(); var channel = channels.GetChannels().Single(c => c.Name == "Channel 2"); context.Users.Move(user, channel); var moved = client.DequeueAndAssertMessage <UserChangedChannelMessage>(); Assert.AreEqual(user.UserId, moved.ChangeInfo.TargetUserId); Assert.AreEqual(channel.ChannelId, moved.ChangeInfo.TargetChannelId); Assert.AreEqual(channels.DefaultChannel.ChannelId, moved.ChangeInfo.PreviousChannelId); Assert.AreEqual(0, moved.ChangeInfo.RequestingUserId); var secondUser = UserInfoTests.GetTestUser(2, 1, false); var cs = provider.GetConnections(GablarskiProtocol.Instance); var secondClient = new ConnectionBuffer(cs.Item1); var secondServer = cs.Item2; manager.Connect(secondServer); manager.Join(secondServer, secondUser); permissions.EnablePermissions(secondUser.UserId, PermissionName.ChangeChannel); context.Users.Move(secondServer, secondUser, channel); client.AssertNoMessage(); var result = secondClient.DequeueAndAssertMessage <ChannelChangeResultMessage>(); Assert.AreEqual(ChannelChangeResult.FailedFull, result.Result); }
public void RequestSourceNotification() { permissions.EnablePermissions(user.UserId, PermissionName.RequestSource); var cs = provider.GetConnections(GablarskiProtocol.Instance); var c = cs.Item2; var cl = new ConnectionBuffer(cs.Item1); userManager.Connect(c); userManager.Join(c, UserInfoTests.GetTestUser(2)); var audioArgs = AudioCodecArgsTests.GetTestArgs(); handler.RequestSourceMessage(new MessageEventArgs <RequestSourceMessage> (server, new RequestSourceMessage("Name", audioArgs))); var sourceAdded = cl.DequeueAndAssertMessage <SourceResultMessage>(); Assert.AreEqual(SourceResult.NewSource, sourceAdded.SourceResult); Assert.AreEqual("Name", sourceAdded.SourceName); AudioCodecArgsTests.AssertAreEqual(audioArgs, sourceAdded.Source.CodecSettings); cl.AssertNoMessage(); }
public void JoinNull() { Assert.Throws <ArgumentNullException> (() => manager.Join(server, null)); Assert.Throws <ArgumentNullException> (() => manager.Join(null, user)); }
public void Setup() { permissions = new MockPermissionsProvider(); LobbyChannelProvider channels = new LobbyChannelProvider(); channels.SaveChannel (new ChannelInfo { Name = "Channel 2" }); this.provider = new MockConnectionProvider (GablarskiProtocol.Instance); this.provider.Start (MessageTypes.All); userManager = new ServerUserManager(); MockServerContext c; context = c = new MockServerContext (provider) { Settings = new ServerSettings { Name = "Server", DefaultAudioBitrate = defaultBitrate, MaximumAudioBitrate = maxBitrate, MinimumAudioBitrate = minBitrate }, UserManager = userManager, PermissionsProvider = permissions, ChannelsProvider = channels }; c.Users = new ServerUserHandler (context, userManager); manager = new ServerSourceManager (context); handler = new ServerSourceHandler (context, manager); user = UserInfoTests.GetTestUser (1, 1, false); var cs = provider.GetConnections (GablarskiProtocol.Instance); client = new ConnectionBuffer (cs.Item1); server = cs.Item2; userManager.Connect (server); userManager.Join (server, user); }
public void Setup() { manager = new ServerUserManager(); permissions = new MockPermissionsProvider(); channels = new LobbyChannelProvider(); MockServerContext mcontext; context = mcontext = new MockServerContext { ChannelsProvider = channels, PermissionsProvider = permissions, UserManager = new ServerUserManager (), Settings = new ServerSettings { Name = "Test Server" } }; mcontext.Users = new ServerUserHandler (context, manager); mcontext.Channels = handler = new ServerChannelHandler (context); user = UserInfoTests.GetTestUser (1, 1, false); provider = new MockConnectionProvider (GablarskiProtocol.Instance); mcontext.AddConnectionProvider (provider); mcontext.Start(); var connections = provider.GetConnections (GablarskiProtocol.Instance); client = new ConnectionBuffer (connections.Item1); server = connections.Item2; manager.Connect (server); manager.Join (server, user); }