private void m_server_ReceivedFull(object sender, TcpReceivedEventArgs e) { Command command = null; try { command = CommandSerializer.DeserializeCommand(e.Data); } catch (EncoderFallbackException ex) { if (OnCommandError != null) { OnCommandError(this, new TcpErrorEventArgs(e.Client, ex)); } return; } if (OnCommandReceived != null) { OnCommandReceived(this, new CommandReceivedArgs(command, (User)e.Client.Tag)); } SendCommand(command); }
private void LoginFeedbackHandler(TcpReceivedEventArgs e) { m_isLoggedIn = e.Data[1] == 1; if (OnLogingFeedback != null) { OnLogingFeedback(this, new LoginFeedbackArgs(m_isLoggedIn)); } }
private void m_server_ReceivedFull(object sender, TcpReceivedEventArgs e) { var commandReceived = (CommandType)e.Data[0]; switch (commandReceived) { case CommandType.SaltRequest: SaltRequestReceived(e); break; case CommandType.Login: AuthenticationRequestReceived(e); break; } }
private void m_client_ReceivedFull(object sender, TcpReceivedEventArgs e) { var commandReceived = (CommandType)e.Data[0]; switch (commandReceived) { case CommandType.Notification: NotificationReceived(e.Data); break; case CommandType.Wallpaper: WallpaperReceived(e.Data); break; } }
private void SaltRequestReceived(TcpReceivedEventArgs e) { if (OnSaltRequested != null) { OnSaltRequested(this, null); } byte[] newSalt = GenerateRandomSalt(10); byte[] message = new byte[newSalt.Length + 2]; message[0] = (byte)CommandType.SaltRequest; message[1] = (byte)newSalt.Length; Array.Copy(newSalt, 0, message, 2, newSalt.Length); m_saltDictionnary.Add(e.Client, new SaltContainer(newSalt, DateTime.Now.AddSeconds(10))); m_server.Send(e.Client, message); }
void m_server_ReceivedFull(object sender, TcpReceivedEventArgs e) { var commandReceived = (CommandType)e.Data[0]; switch (commandReceived) { case CommandType.Notification: NotificationReceived(e.Data); break; case CommandType.Login: LoginRequest(e); break; case CommandType.Error: break; } }
private void m_client_ReceivedFull(object sender, TcpReceivedEventArgs e) { var commandReceived = (CommandType)e.Data[0]; switch (commandReceived) { case CommandType.SaltRequest: SessionSaltReceived(e.Data); break; case CommandType.Notification: NotificationReceived(e.Data); break; case CommandType.Login: LoginFeedbackHandler(e.Data); break; } }
private void AuthenticationRequestReceived(TcpReceivedEventArgs e) { byte passwordLenght = e.Data[1]; byte[] clientPassword = new byte[passwordLenght]; Array.Copy(e.Data, 2, clientPassword, 0, passwordLenght); var userInfo = (User)e.Client.Tag; userInfo.IsLoggedIn = false; AuthenticationResult result = AuthenticationResult.RequestExpired; if (m_saltDictionnary.ContainsKey(e.Client)) { SaltContainer clientSalt = m_saltDictionnary[e.Client]; if (clientSalt.Expiration > DateTime.Now) { //TODO: Put this in a method //Hash the server password with the correct salt if (HashString(m_serverPassword, clientSalt.Salt).SequenceEqual(clientPassword)) { userInfo.IsLoggedIn = true; result = AuthenticationResult.Success; } else { result = AuthenticationResult.Failed; } } } byte[] command = new byte[2]; command[0] = (byte)CommandType.Login; command[1] = (byte)result; m_server.Send(e.Client, command); if (OnAuthenticationRequest != null) { OnAuthenticationRequest(this, new AuthenticationFeedbackArgs(result, e.Client)); } }
private void LoginRequest(TcpReceivedEventArgs e) { var user = (UserInfo)e.Client.Tag; int usernameLength = e.Data[1]; string username = Encoding.UTF8.GetString(e.Data, 2, usernameLength); int passwordLenght = e.Data[usernameLength + 2]; string password = Encoding.UTF8.GetString(e.Data, usernameLength + 3, passwordLenght); bool success = TryLogIn(username, password); if (success) { user.Name = username; user.IsLoggedIn = true; } byte[] command = new byte[2]; command[0] = (byte)CommandType.Login; command[1] = (byte)(success ? 1 : 0); m_server.Send(e.Client, command); }
private void m_server_ReceivedFull(object sender, TcpReceivedEventArgs e) { var commandReceived = (CommandType)e.Data[0]; switch (commandReceived) { case CommandType.Wallpaper: byte[] imageArr = new byte[e.Data.Length - 1]; Array.Copy(e.Data, 2, imageArr, 0, e.Data.Length - 2); Image image = (Bitmap)((new ImageConverter()).ConvertFrom(imageArr)); if (OnWallPaperReceived != null) { OnWallPaperReceived(this, new WallpaperReceivedArgs(image, (Wallpaper.Style)e.Data[1])); } m_server.SendAllAsync(e.Data); break; } }
void m_client_ReceivedFull(object sender, TcpReceivedEventArgs e) { var commandReceived = (CommandType)e.Data[0]; switch (commandReceived) { case CommandType.Notification: NotificationReceived(e.Data); break; case CommandType.Broadcast: break; case CommandType.Login: LoginFeedbackHandler(e); break; case CommandType.Error: break; default: break; } }
private void LoginFeedbackHandler(TcpReceivedEventArgs e) { m_isLoggedIn = e.Data[1] == 1; if(OnLogingFeedback != null) { OnLogingFeedback(this, new LoginFeedbackArgs(m_isLoggedIn)); } }