Beispiel #1
0
        private void EnterChatResponseHandler(string responseInJson)
        {
            EnterChatResponse response = JsonSerializer.Deserialize <EnterChatResponse>(responseInJson);

            if (response.Code != StatusCode.Ok)
            {
                Console.WriteLine(response.Message);
                chatName = null;
                return;
            }

            chatKey   = response.Key;
            userState = UserState.InChat;
        }
Beispiel #2
0
        private void EnterChatHandler(string requestInJson)
        {
            EnterChatRequest request = JsonSerializer.Deserialize <EnterChatRequest>(requestInJson);

            var response = new EnterChatResponse
            {
                RequestId = request.Id
            };

            try
            {
                User  storedUser = server.UserRepository.GetByName(request.Sender);
                IChat chat       = server.ChatRepository.GetChat(request.ChatName);
                if (chat == null)
                {
                    throw new ChatNotFoundException(request.ChatName);
                }

                if (storedUser.State != UserState.Authorized)
                {
                    throw new NotEnoughRightsException(request.Sender, storedUser.State, request.Action);
                }

                chat.AddUser(storedUser);
                storedUser.CurrentChat = chat;

                storedUser.State = UserState.InChat;

                response.Key  = chat.Key;
                response.Code = StatusCode.Ok;
            }
            catch (NedoGramException customException)
            {
                response.Message = customException.Message;
                response.Code    = StatusCode.ClientError;
            }
            catch (Exception)
            {
                response.Message = "Internal error";
                response.Code    = StatusCode.ServerError;
            }
            finally
            {
                SendMessageAesEncrypted(response, ClientAesKey);
            }
        }