Skip to content

Latest commit

 

History

History
128 lines (81 loc) · 7.63 KB

DESIGN.md

File metadata and controls

128 lines (81 loc) · 7.63 KB

DESIGN.md

Backend

  1. CoveyTypes.ts

    • Added new types for payload such as ChatData, ReceivingPlayerID, SecretKeySet, and ChatType

  2. CoveyTownListener.ts

    • Added a new function ‘onMessageSent’ to send messages to all listeners. • The method takes in a ChatData type.

  3. CoveyTownController.ts

    • Added a new function 'sendChatMessage' to send the message to all the listeners connected to the room.

    • The method takes in a ChatData type that is passed to all the listeners connected to the room.

  4. CoveyTownRequestHandler.ts

    • The townSocketAdapter is extended to allow the soket to emit the chat message to all other users.

    • On receiving the 'newChatMessage' by the socket, the controller calls the sendChatMessage function to send the chat data to all the listeners connected to that controller.

  5. files.ts

    • Added this file containing REST endpoints for file upload & download

  6. db.ts

    • Added this file containing functions to create a shared, persistent connection to the Mongo Database and to cleanup and close the connection upon shutdown.

  7. server.ts

    • Added call to connect to MongoDB
    • Added call to add file upload/download REST routes
    • Added a cleanup function that is called when the server shuts down to close all open connections
    • Also changed the signal sent by nodemon when it restarts due to code changes to 'SIGINT' to avoid EADDRINUSE errors. With the default signal it would not wait for the server to close connections before starting a new instance.

  8. Dependencies Added

    • busboy
    • mongodb
    • supertest

Backend Tests

  1. CoveyTownController.test.ts

    Notifies added listeners that a new message is sent. • Does not notify removed listener when a new message is sent • Emits 'newChatMessage' to the socekt when a player sends a message. • Forwards player messages to subscribed listeners. • Dispatches message updates to all the clients in the same town.

  2. CoveyTownsSocket.test.ts

    Dispatches message updates to all the clients in the same town.

  3. CoveyTownsREST.test.ts

    File related testing

Frontend

  1. App.tsx

    • Moved CoveyAppState logic (unmodified) to components/Town/TownLogic.ts
    • Moved the town page to components/Town/TownPage.tsx
    • In the GameController function, added setup of a chatStateReducer similar to appStateReducer (ChatLogic.ts)

  2. TownPage.tsx

    • Pulled MenuBar component up out of VideoOverlay and moved it to the top of the page • Added collapisble chat window (ChatPanel.tsx) • Added a menu button for chat that gets passed to MenuBar as a prop

  3. WorldMap.ts

    • moved from components/world folder
    changed scaling of the game map so that it would be responsive to the chat opening or window resizing

  4. MenuBar.tsx

    • moved instantiation of this menu from VideoOverlay.tsx to TownPage.tsx
    • added a chat button
    • made the menu collapsible and responsive to chat opening and window resizing

  5. Snackbar.tsx

    • changed display location to top left so it doesn't cover up chat

  6. ChatLogic.ts

    • Added this file that handles communication with the socket for chat messages

  7. ChatPanel.tsx

    • Added this component that is the main chat window
    • Added a saveChat function that allows the user to save all messages and the people who sent them in the existing chat window into a textfile downloaded to their computer
    • Added logic to pause and unpause game whenever the Chat Input command is toggled in order to avoid player movement while typing out messages
    • Added logic to auto scroll to the bottom when a new message is received

  8. ChatCrypto.ts

    • Added this file that handles the encryption and decryption of private and proximity messages
    • Makes use of AES encryption as the encryption algorithm
    • For encryption, a random key is generated which is used to encrypt the message. The key is then concatenated with a key identifier, and the entity as a whole is encrypted using the receiving players player IDs. The encrypted entity is stored in the secretkey set of the payload
    • For decryption, the client uses their ID to decrypt the entities in the secretkey set from the payload. When the secretkey identifier is found, the secretkey from the decrypted entity is extracted and used to decrypt the message
    • This strategy of encryption, allows encryption of messages using multiple keys and decryption using any one of those keys

  9. Dependencies Added

    • buffer
    • crypto-js
    • http-status-codes

Frontend Tests

  1. ChatCryptoTest.test.ts

    • Verifies whether encryption and decryption works through test messages.

Sequence Diagram for Text Messages

textchat_sequencediagram

Sequence Diagram for File Uploads

fileupload_sequencediagram

State Diagram for Chat Feature

chatfeature_statediagram