Skip to content

Commit 37def2f

Browse files
committedFeb 23, 2024
Grammar and stylistic fixes
1 parent 3003d96 commit 37def2f

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed
 

‎client/main.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import logging
12
import os
23
import sys
3-
import logging
44
import traceback
55

66
# Add the parent directory of the current script to sys.path
@@ -9,7 +9,6 @@
99

1010
import asyncio
1111

12-
from shared.utils.concurent_task_group import ConcurentTasksGroup
1312
from shared.utils.logging_setup import configure_logging
1413
from shared.validators import valid_username
1514
from shared.errors import NetworkError
@@ -82,7 +81,7 @@ async def stop(self, err=None):
8281
self.networking.disconnect()
8382
self.ui.exit()
8483
if err:
85-
await self.ui.alert(title="ChatClient", text=f"Well, something baad happend :(.\nError: {err}")
84+
await self.ui.alert(title="ChatClient", text=f"Well, something bad happened :(.\nError: {err}")
8685

8786
async def display_message(self, username: str | None, message: str):
8887
"""

‎protocol.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The EchoSphere Chat Protocol, version 1 (ESCP in short) is a simple binary proto
1010
+----------+----------+--------------+----------------------------------------+
1111
```
1212

13-
The header consists of 3 fields in the following order: protocol version, packet type, payload length. The protocol version is an unsigned number that helps with identifying a newer versions of this protocol in the future. For now, the only acceptable protocol version is 1. Newer versions do not guarantee backwards compatibility! The packet type field is also an unsigned number and it distinguishes between different kinds of packets (more in the packet types section). The payload length is an unsigned number of bytes of payload that follows the header.
13+
The header consists of 3 fields in the following order: protocol version, packet type, payload length. The protocol version is an unsigned number that helps with identifying a newer versions of this protocol in the future. For now, the only acceptable protocol version is 1. Newer versions do not guarantee backwards compatibility! The packet type field is also an unsigned number, and it distinguishes between different kinds of packets (more in the packet types section). The payload length is an unsigned number of bytes of payload that follows the header.
1414

1515
The payload is a sequence of bytes that are interpreted differently based on the packet type specified in the header. Currently, the maximum length of any payload is 4096 bytes. Each packet type can subsequently define this limit to be lower. A packet can also have a payload length of 0, effectively having a packet without any payload. Such an example is the Heartbeat packet.
1616

@@ -24,7 +24,7 @@ When either the client or server sends a request packet, that side of the commun
2424
2. Response packets
2525
These types of packets are sent as a response to an appropriate request packet that was received. In the current protocol version, there is only a single response packet type to every request packet and that is the Response packet (more in packet types section).
2626
3. Meta packets
27-
They serve as a spontanious information that was not requested and therefore does not need to be responded to. An example of such packet is the Heartbeat packet.
27+
They serve as spontaneous information that was not requested and therefore does not need to be responded to. An example of such packet is the Heartbeat packet.
2828

2929
# Packet Types
3030
The protocol defines a set of different packet types, which determines how will be the payload handled and parsed.
@@ -42,7 +42,7 @@ Max Payload Len: 0
4242
```
4343

4444
## 2. Login packet (request packet)
45-
The login packet is sent by the client after a successful estabilisment of a TCP connection with the server. It acts as an introduction of a client to the server and includes required information for the server such as the client's username and the password to the server.
45+
The login packet is sent by the client after a successful establishment of a TCP connection with the server. It acts as an introduction of a client to the server and includes required information for the server such as the client's username and the password to the server.
4646

4747
```
4848
+--------+---------+--------------+------------------------------+
@@ -52,9 +52,9 @@ Type: 2
5252
Max Payload Len: 256 bytes
5353
```
5454

55-
The payload is an UTF-8 string that consists of client's username and a server's password, separated by the character `"|"`.
56-
The username must be at least 3 characters long and at most 12 characters long. It can only includes alphanumeric characters.
57-
The server's password length can range from 0 to 48 characters. If the server's password is 0, then it has no password set. All characters are permited.
55+
The payload is a UTF-8 string that consists of client's username and a server's password, separated by the character `"|"`.
56+
The username must be at least 3 characters long and at most 12 characters long. It can only include alphanumeric characters.
57+
The server's password length can range from 0 to 48 characters. If the server's password is 0, then it has no password set. All characters are permitted.
5858

5959
Payload format: `"<username>|<password>"`. In case logging into a server that has not set a password, then the payload would look like: `"<username>|"`.
6060

@@ -65,7 +65,7 @@ Server responds to this packet by sending a Response packet with the response co
6565
- 0: When the login was successful
6666

6767
## 3. Message packet (request/meta packet)
68-
The purpose of this packet is to deliver messages between communication parties. Both server and client send this type of packet. However, when the client sends this packet, it is considered to be a request packet and therefore the client must wait for a response. This allows the server to reject some of the client messages because of formating issues, etc.
68+
The purpose of this packet is to deliver messages between communication parties. Both server and client send this type of packet. However, when the client sends this packet, it is considered to be a request packet and therefore the client must wait for a response. This allows the server to reject some of the client messages because of formatting issues, etc.
6969
In the other case, when server is sending this packet, it is considered to be a meta packet and clients that receive it do not respond to it, but rather display it in client's UI.
7070

7171
```
@@ -76,7 +76,7 @@ Type: 3
7676
Max Payload Len: 4096
7777
```
7878

79-
The payload is an UTF-8 encoded string in the following format: `"<sender's username>|<message>"`. The message needs to be at least 1 and at most 1000 characters long.
79+
The payload is a UTF-8 encoded string in the following format: `"<sender's username>|<message>"`. The message needs to be at least 1 and at most 1000 characters long.
8080

8181
There are 2 types of messages:
8282
- User messages - These are sent by user to be received by other clients
@@ -103,14 +103,14 @@ Different kinds of responses are distinguished based on the response code which
103103

104104
### Valid response codes:
105105

106-
| Response Code | Meaning | Description |
107-
|---------------|-------------------|---------------------------------------------------------------------------|
108-
| 0 | OK | The request was valid, there were no issues |
109-
| 1 | INVALID_USERNAME | The provided username is invalid (formatting, etc) |
110-
| 2 | TAKEN_USERNAME | The username is being used by another user |
111-
| 3 | INVALID_MESSAGE | The message format is invalid or breaches content rules of the server |
112-
| 4 | WRONG_PASSWORD | The provided password for the server is incorrect |
113-
| 5 | GENERIC_ERROR | An unexpected error occured, which is not covered by other codes |
106+
| Response Code | Meaning | Description |
107+
|---------------|------------------|-----------------------------------------------------------------------|
108+
| 0 | OK | The request was valid, there were no issues |
109+
| 1 | INVALID_USERNAME | The provided username is invalid (formatting, etc) |
110+
| 2 | TAKEN_USERNAME | The username is being used by another user |
111+
| 3 | INVALID_MESSAGE | The message format is invalid or breaches content rules of the server |
112+
| 4 | WRONG_PASSWORD | The provided password for the server is incorrect |
113+
| 5 | GENERIC_ERROR | An unexpected error occurred, which is not covered by other codes |
114114

115115
## 5. Logout packet (meta packet)
116116
Sent only by the clients to indicate to the server that the user is leaving and soon will close the connection as well.
@@ -134,4 +134,4 @@ Max Payload Len: 0 byte
134134
9. Client closes the TCP connection.
135135

136136
# Other information
137-
When a user joins or leaves the server, the server must send a system message to all of the other clients notifying them of such an event. Most of the time, user messages sent to the server will be broadcaster to all other clients, however the server may handle special types of messages as commands and may consequently send a system message to one or more clients, however that is not part of the specification.
137+
When a user joins or leaves the server, the server must send a system message to all the other clients notifying them of such an event. Most of the time, user messages sent to the server will be broadcaster to all other clients, however the server may handle special types of messages as commands and may consequently send a system message to one or more clients, however that is not part of the specification.

0 commit comments

Comments
 (0)
Please sign in to comment.