public async Task HandleMessage(SocketUserMessage message, SocketDMChannel channel) { if (serverService.IsPasswordRequestInProgress(message.Author.Id)) { var nsp = serverService.RemoveNewPasswordRequest(message.Author.Id); var server = await serverService.Get(nsp.GuildId, nsp.ServerName); if (server == null) { await channel.SendMessageAsync("Server was removed in the meantime - request invalid"); return; } IAdminPortClient client = adminPortClientFactory.Create(new ServerInfo(server.ServerIp, server.ServerPort, message.Content)); try { await client.Join(); } catch { await channel.SendMessageAsync("Password was incorrect or connection to server was impossible"); return; } finally { await client.Disconnect(); } await this.serverService.ChangePassword(server.Id, message.Content); await channel.SendMessageAsync("Password has been changed."); } }
public AdminPortClientShould() { tcpClientMock.CallBase = true; client = new AdminPortClient(tcpClientMock.Object, messageProcessorMock.Object, new ServerInfo("127.0.0.1", 123, "LubiePlacki")); }
public async Task AfterRegister_YouShouldBeAbleToGetClient() { Server server = new ServerFixture().WithPassword("myPassword").Build(); await provider.Register(DefaultUser, server); IAdminPortClient client = provider.GetClient(DefaultUser, server); Assert.Equal(client.ServerInfo.ServerIp, server.ServerIp); Assert.Equal(client.ServerInfo.ServerPort, server.ServerPort); Assert.Equal(client.ServerInfo.Password, server.ServerPassword); }
public async Task AfterPasswordChange_ServerShouldReceiveServerWithNewPassword_OnGetClient() { var sFixture = new ServerFixture().WithPassword("123"); Server server = sFixture; await provider.Register(DefaultUser, server); serverService.Raise(x => x.PasswordChanged += null, serverService.Object, sFixture.BasedOn(server).WithPassword("333").Build()); IAdminPortClient client = provider.GetClient(DefaultUser, server); Assert.Equal("333", client.ServerInfo.Password); Assert.Equal(server.ServerIp, client.ServerInfo.ServerIp); Assert.Equal(server.ServerPort, client.ServerInfo.ServerPort); }
public async Task Register(IAdminPortClientUser owner, Server server) { AdminClientRegisterInfo info = RegisterInfo.GetOrAdd(server.GetUniqueKey(), (_) => { IAdminPortClient client = this.adminPortClientFactory.Create( new ServerInfo(server.ServerIp, server.ServerPort, server.ServerPassword) ); client.EventReceived += Client_EventReceived; return(new AdminClientRegisterInfo(server, client)); }); if (info.Client.ConnectionState == AdminConnectionState.Idle) { await info.Client.Join(); } info.AddUser(owner); }
public AdminClientRegisterInfo(Server server, IAdminPortClient client) { this.Server = server; this.Client = client; }