Example #1
0
        private void AwaitLoginInformationFromNewConnection(ConnectedUser connectedUser)
        {
            while (true)
            {
                if (!connectedUser.TcpClient.Connected)
                    continue;

                var stream = connectedUser.TcpClient.GetStream();
                if (!stream.CanRead || !stream.DataAvailable)
                    continue;

                var prefixBuffer = new byte[4];
                var messageTypeBuffer = new byte[1];

                stream.Read(prefixBuffer, 0, 4);
                stream.Read(messageTypeBuffer, 0, 1);

                var length = BitConverter.ToInt32(prefixBuffer, 0);
                var buffer = new byte[length];

                stream.Read(buffer, 0, length);

                var processor = _tcpMessageProcessorCache.GetApplicableProcessor((MessageType) messageTypeBuffer.First());
                processor.Execute(connectedUser, Encoding.ASCII.GetString(buffer));

                break;
            }
        }
Example #2
0
 private void HandshakeAndIdentify(TcpClient result)
 {
     var connectedUser = new ConnectedUser {TcpClient = result, Identifier = Guid.NewGuid()};
     AwaitLoginInformationFromNewConnection(connectedUser);
     _connectionService.AddConnection(connectedUser);
 }
Example #3
0
 public void RemoveConnection(ConnectedUser user)
 {
     lock (_connectionMutex)
         _connections.Remove(user);
 }
Example #4
0
 public void AddConnection(ConnectedUser user)
 {
     lock (_connectionMutex)
         _connections.Add(user);
 }
Example #5
0
 public void RemoveConnection(ConnectedUser user)
 {
     lock (_connectionMutex)
         _connections.Remove(user);
 }
Example #6
0
 public void AddConnection(ConnectedUser user)
 {
     lock (_connectionMutex)
         _connections.Add(user);
 }