private void Register(Client client, string[] parameters) { if (parameters.Length != 2) { client.DisplayString("Incorrect syntax. Use /register [username] [password]"); return; } if (client.Authenticated == true) { client.DisplayString("You are already logged in."); return; } var username = parameters[0]; var password = parameters[1]; var isRegisterSuccessful = ClientAuthenticator.Register(client, username, password); if (!isRegisterSuccessful) { client.DisplayString($"Username '{username}' already exists. Please choose another one."); return; } ClientAuthenticator.Authenticate(client, username, password); client.DisplayString($"Registered new user '{username}'. You are now logged in."); Server.GetServer().BroadcastMessage($"{username} has joined the chat."); BetterConsole.WriteLog($"New user registered: {username}"); }
public ClientUserManager(NetClient netClient, ClientAuthenticator authenticator) { this.netClient = netClient; this.authenticator = authenticator; this.userStore = new UserStore(); netClient.OnDisconnect += disconnectHandler; netClient.RegisterPacketHandler(MODULE_NAME, packetHandler); }
public ClientTrading(NetClient netClient, ClientAuthenticator authenticator, ClientUserManager userManager) { this.netClient = netClient; this.authenticator = authenticator; this.userManager = userManager; this.activeTrades = new Dictionary <string, Trade>(); netClient.RegisterPacketHandler(MODULE_NAME, packetHandler); netClient.OnDisconnect += disconnectHandler; }
public ClientChat(NetClient netClient, ClientAuthenticator authenticator, ClientUserManager userManager) { this.netClient = netClient; this.authenticator = authenticator; this.userManager = userManager; this.messageHistory = new List <ClientChatMessage>(); this.messageCountAtLastCheck = 0; netClient.RegisterPacketHandler(MODULE_NAME, packetHandler); netClient.OnDisconnect += disconnectHandler; }
private void LoginCommandMethod() { authenticator = new ClientAuthenticator(); /*--Проверка username и password--*/ bool auth = authenticator.Authenticate(this._usernameString, this._passwordString); if (Identifying == null) { return; } Identifying(this, new EventArgs()); }
private async Task MakeRequestAsync(IAbpMethodInvocation invocation) { // 获取Actor配置 var actorProxyConfig = DaprActorProxyOptions.ActorProxies.GetOrDefault(typeof(TService)) ?? throw new AbpException($"Could not get DynamicDaprActorProxyConfig for {typeof(TService).FullName}."); var remoteServiceConfig = DaprServiceOptions.RemoteServices.GetConfigurationOrDefault(actorProxyConfig.RemoteServiceName); // Actors的定义太多, 可以考虑使用默认的 BaseUrl 作为远程地址 if (remoteServiceConfig.BaseUrl.IsNullOrWhiteSpace()) { throw new AbpException($"Could not get BaseUrl for {actorProxyConfig.RemoteServiceName} Or Default."); } var actorProxyOptions = new ActorProxyOptions { HttpEndpoint = remoteServiceConfig.BaseUrl }; // 自定义请求处理器 // 添加请求头用于传递状态 // TODO: Actor一次只能处理一个请求,使用状态管理来传递状态的可行性? var httpClientHandler = new DaprHttpClientHandler(); AddHeaders(httpClientHandler); httpClientHandler.PreConfigure(async(requestMessage) => { // 占位 var httpClient = HttpClientFactory.Create(AbpDaprActorsModule.DaprHttpClient); await ClientAuthenticator.Authenticate( new RemoteServiceHttpClientAuthenticateContext( httpClient, requestMessage, remoteServiceConfig, actorProxyConfig.RemoteServiceName)); // 标头 if (requestMessage.Headers.Authorization == null && httpClient.DefaultRequestHeaders.Authorization != null) { requestMessage.Headers.Authorization = httpClient.DefaultRequestHeaders.Authorization; } }); // 代理工厂 var proxyFactory = new ActorProxyFactory(actorProxyOptions, (HttpMessageHandler)httpClientHandler); await MakeRequestAsync(invocation, proxyFactory); }
private async Task <HttpContent> MakeRequestAsync(IAbpMethodInvocation invocation) { var clientConfig = ClientOptions.HttpClientProxies.GetOrDefault(typeof(TService)) ?? throw new AbpException($"Could not get DynamicHttpClientProxyConfig for {typeof(TService).FullName}."); var remoteServiceConfig = AbpRemoteServiceOptions.RemoteServices.GetConfigurationOrDefault(clientConfig.RemoteServiceName); var client = HttpClientFactory.Create(clientConfig.RemoteServiceName); var action = await ApiDescriptionFinder.FindActionAsync(client, remoteServiceConfig.BaseUrl, typeof(TService), invocation.Method); var apiVersion = GetApiVersionInfo(action); var url = remoteServiceConfig.BaseUrl.EnsureEndsWith('/') + UrlBuilder.GenerateUrlWithParameters(action, invocation.ArgumentsDictionary, apiVersion); var requestMessage = new HttpRequestMessage(action.GetHttpMethod(), url) { Content = RequestPayloadBuilder.BuildContent(action, invocation.ArgumentsDictionary, JsonSerializer, apiVersion) }; AddHeaders(invocation, action, requestMessage, apiVersion); await ClientAuthenticator.Authenticate( new RemoteServiceHttpClientAuthenticateContext( client, requestMessage, remoteServiceConfig, clientConfig.RemoteServiceName ) ); var response = await client.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead /*this will buffer only the headers, the content will be used as a stream*/, GetCancellationToken()); if (!response.IsSuccessStatusCode) { await ThrowExceptionForResponseAsync(response); } return(response.Content); }
private void Login(Client client, string[] parameters) { if (parameters.Length != 2) { client.DisplayString("Incorrect syntax. Use /login [username] [password]"); return; } if (client.Authenticated == true) { client.DisplayString("You are already logged in."); return; } var username = parameters[0]; var password = parameters[1]; if (Server.GetServer().IsUserOnline(username)) { client.DisplayString("The user account is already in use."); return; } var isLoginSuccessful = ClientAuthenticator.Authenticate(client, username, password); if (!isLoginSuccessful) { client.DisplayString("Username and password do not match."); return; } client.DisplayString($"Logged in as {username}."); Server.GetServer().BroadcastMessage($"{username} has joined the chat."); BetterConsole.WriteLog($"{username} logged in."); }
static void Main(string[] args) { //if (!ConfigurationHelper.Import("NordicConf.json")) { // Console.WriteLine("Configuration import failed, using default values and writing configuration file \"NordicConf.json\"."); // ConfigurationHelper.Export("NordicConf.json"); //} var _hardcodedChallenge = "miner_test"; ServerAuthenticator.Initialize("pubKey.pem", "privKey.pem", ""); ClientAuthenticator.Initialize("pubKey.pem", "privKey.pem", ""); ClientAuthenticator.Add(_hardcodedChallenge, File.ReadAllText("miner_pubKey.pem")); Console.WriteLine("---------- BLOCKCHAIN ----------\n"); Blockchain _nbStructure = new Blockchain(); var gBlock = _nbStructure.GetBlock(0); Console.WriteLine(gBlock.ToString()); //_nbStructure.Add(new BlockData("", IOperation.OPERATION_TYPE.SECURITY_BC_COMPROMISE_NOTICE, "Lol")); Console.WriteLine(_nbStructure.LastBlock().ToString()); Console.WriteLine("Fork Validity: " + _nbStructure.Validity()); Console.WriteLine("\n---------- NODE VAULT ----------\n"); Console.WriteLine("Importing current node credentials..."); TrustVault _vault = new TrustVault(File.ReadAllText("privKey.pem"), File.ReadAllText("pubKey.pem")); Console.WriteLine(_vault.ToJson()); Console.WriteLine("\n----------- NETWORK ------------\n"); Console.WriteLine("Setting up network for 127.0.0.1:1337 (LOCAL ONLY BINDING!)."); Network _net = new Network("127.0.0.1", 1337); if (_net.Setup()) { _net.Start(); Console.WriteLine("Network started on 127.0.0.1:1337."); } else Console.WriteLine("Network setup failed."); Console.WriteLine("\n---------- SHAREDCACHE ---------\n"); Console.WriteLine("Building Shared Node Cache for online nodes..."); Console.WriteLine("\tOnly 1 node online."); SharedCache _cache = new SharedCache(); _cache.AddAddress("127.0.0.1"); Console.WriteLine(_cache.ToJson()); Console.WriteLine("\n-------------- RSA -------------\n"); RSA _rsa = new RSA(File.ReadAllText("privKey.pem"), File.ReadAllText("pubKey.pem")); var _signature = _rsa.Sign("makeAwish"); var _verify = _rsa.VerifySignature("makeAwish", _signature, null); var _verify2 = _rsa.VerifySignature("makeAwisha", _signature, null); Console.WriteLine("Signed: " + _signature + "\n\n"); Console.WriteLine("Verify: " + _verify); Console.WriteLine("Verify fake one: " + _verify2); Client cl = new Client(); cl.Connect("ws://127.0.0.1:1337/blt"); bool _sent = false; while (true) { if (WaitOrBreak(_nbStructure.LastBlock())) break; if (!_nbStructure.Validity()) { Console.WriteLine("Blockchain violation detected!"); break; } //try { // if (!_sent) { // IOperation _op = new OperationTransaction("d3vil401", "13.2", "none"); // ClmManager _clm = new ClmManager(_op); // var _buffer = _clm.GetBuffer().Result.ToBase64(); // // cl.Send("ws://127.0.0.1:1337/blt", _buffer); // _sent = true; // } // //} catch (Exception ex) { // Console.WriteLine(ex.Message); //} } }