Пример #1
0
        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);
        }
Пример #2
0
        public void SendCommand(Command pCommand, TcpClientInfo pClient)
        {
            if (!IsRunning)
            {
                throw new InvalidOperationException("Cannot send commands while server is not running");
            }

            m_server.Send(pClient, pCommand.ToByteArray());
        }
Пример #3
0
        /// <summary>
        /// Send a notification to a client
        /// </summary>
        /// <param name="pMessage">Message to be sent</param>
        /// <param name="pClient">Client to be notified</param>
        public void Notify(string pMessage, TcpClientInfo pClient)
        {
            if (!IsRunning)
            {
                throw new InvalidOperationException("Can't send a notification while server is not running");
            }

            byte[] data = Command.PrefixCommand(CommandType.Notification, pMessage);
            m_server.Send(pClient, data);
        }
Пример #4
0
        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);
        }