Esempio n. 1
0
        /// <summary>
        /// Verarbeitet Nachrichten, die an den Server von der Verbindung gesendet werden.
        /// </summary>
        /// <param name="Message">Aufbau: Befehle:Parameter</param>
        /// <returns></returns>
        void ProcessMessage(string Content)
        {
            Message receivedMessage = MessageSerializer.Deserialize(Content);
            Command command         = (Command)receivedMessage.content;

            switch (command.type)
            {
            case CommandType.Login:
                StreamRW streamRW = new StreamRW(tcpClient.GetStream());
                if (command.parameter[0] == command.parameter[1])
                {
                    streamRW.WriteLine("Login successfull");
                    username = command.parameter[0];
                    Console.WriteLine("[Server][{0}]{1} logged in", DateTime.Now, username);
                }
                else
                {
                    streamRW.WriteLine("Login failed");
                    Console.WriteLine("[Server][{0}{1}] failed to log in", DateTime.Now, username);
                }
                break;

            case CommandType.Message:
                Console.WriteLine("[Server][{0}]{1}: {2}", receivedMessage.sendTime, receivedMessage.sender, command.parameter[0]);
                break;

            case CommandType.Disconnect:
                Console.WriteLine("[Server][{0}]{1}: Disconnected: {2}", receivedMessage.sendTime, receivedMessage.sender, command.parameter[0]);
                break;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Verbindet mit dem Server und meldet sich mit den Nutzerdaten an.
        /// </summary>
        /// <param name="Username"></param>
        /// <param name="Password"></param>
        /// <returns>Gibt an ob die Verbindung und der Login erfolgreich waren.</returns>
        public bool Connect(string Username, string Password)
        {
            tcpClient = new TcpClient("localhost", 1337);

            streamRW = new StreamRW(tcpClient.GetStream());
            Message message = new Message()
            {
                content  = new Command(CommandType.Login, Username, Password),
                sender   = Username,
                sendTime = DateTime.Now
            };

            Send(message);
            username = Username;
            return((streamRW.ReadLine() == "Login successfull") ? true : false);
        }
Esempio n. 3
0
 public Connection(TcpClient TcpClient)
 {
     tcpClient = TcpClient;
     streamRW  = new StreamRW(tcpClient.GetStream());
 }