shanter 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- shanter-1.0.0/LICENSE +21 -0
- shanter-1.0.0/PKG-INFO +225 -0
- shanter-1.0.0/README.md +182 -0
- shanter-1.0.0/client/__init__.py +0 -0
- shanter-1.0.0/client/auth.py +101 -0
- shanter-1.0.0/client/chat.py +33 -0
- shanter-1.0.0/client/cli.py +14 -0
- shanter-1.0.0/client/listener.py +25 -0
- shanter-1.0.0/client/main.py +164 -0
- shanter-1.0.0/client/response_manager.py +12 -0
- shanter-1.0.0/client/state.py +4 -0
- shanter-1.0.0/common/__init__.py +0 -0
- shanter-1.0.0/common/constants.py +5 -0
- shanter-1.0.0/common/protocol.py +35 -0
- shanter-1.0.0/common/utils.py +51 -0
- shanter-1.0.0/pyproject.toml +56 -0
- shanter-1.0.0/server/__init__.py +0 -0
- shanter-1.0.0/server/auth.py +78 -0
- shanter-1.0.0/server/client_handler.py +89 -0
- shanter-1.0.0/server/database.py +73 -0
- shanter-1.0.0/server/main.py +56 -0
- shanter-1.0.0/server/message_handler.py +50 -0
- shanter-1.0.0/server/models.py +12 -0
- shanter-1.0.0/server/router.py +0 -0
- shanter-1.0.0/server/session_manager.py +47 -0
- shanter-1.0.0/setup.cfg +4 -0
- shanter-1.0.0/shanter.egg-info/PKG-INFO +225 -0
- shanter-1.0.0/shanter.egg-info/SOURCES.txt +30 -0
- shanter-1.0.0/shanter.egg-info/dependency_links.txt +1 -0
- shanter-1.0.0/shanter.egg-info/entry_points.txt +2 -0
- shanter-1.0.0/shanter.egg-info/requires.txt +1 -0
- shanter-1.0.0/shanter.egg-info/top_level.txt +3 -0
shanter-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shreyash Dongare
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
shanter-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: shanter
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A cross-platform terminal-based real-time chat application built with Python.
|
|
5
|
+
Author: Shreyash Dongare
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Shreyash Dongare
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
Project-URL: Homepage, https://github.com/shreyash9999/shanter
|
|
28
|
+
Project-URL: Repository, https://github.com/shreyash9999/shanter
|
|
29
|
+
Project-URL: Issues, https://github.com/shreyash9999/shanter/issues
|
|
30
|
+
Keywords: chat,terminal,cli,messenger,tcp,socket,networking,python
|
|
31
|
+
Classifier: Development Status :: 4 - Beta
|
|
32
|
+
Classifier: Intended Audience :: Developers
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Operating System :: OS Independent
|
|
35
|
+
Classifier: Programming Language :: Python :: 3
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
37
|
+
Classifier: Topic :: Communications :: Chat
|
|
38
|
+
Requires-Python: >=3.11
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
License-File: LICENSE
|
|
41
|
+
Requires-Dist: bcrypt
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# SHANTER
|
|
45
|
+
|
|
46
|
+
<p align="center">
|
|
47
|
+
<strong>A cross-platform terminal-based real-time chat application built with Python.</strong>
|
|
48
|
+
</p>
|
|
49
|
+
|
|
50
|
+
SHANTER is a lightweight terminal chat application that enables users to communicate in real time over TCP. It provides a simple command-line interface for registering accounts, authenticating users, searching for other users, and exchanging messages across Windows, macOS, and Linux.
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## ✨ Features
|
|
55
|
+
|
|
56
|
+
- 🔐 Secure user registration with password hashing (`bcrypt`)
|
|
57
|
+
- 👤 User authentication (login/logout)
|
|
58
|
+
- 🔍 Search for registered users
|
|
59
|
+
- 💬 Real-time one-to-one messaging
|
|
60
|
+
- 🌍 Cross-platform support (Windows, macOS, Linux)
|
|
61
|
+
- 🖥️ Interactive command-line interface
|
|
62
|
+
- 📦 Installable as a Python package
|
|
63
|
+
- ⚡ Lightweight TCP socket-based architecture
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 📁 Project Structure
|
|
68
|
+
|
|
69
|
+
```text
|
|
70
|
+
shanter/
|
|
71
|
+
├── client/ # Client application
|
|
72
|
+
├── common/ # Shared protocol and utilities
|
|
73
|
+
├── server/ # Server implementation
|
|
74
|
+
├── tests/ # Tests
|
|
75
|
+
├── data/ # SQLite database
|
|
76
|
+
├── pyproject.toml
|
|
77
|
+
├── README.md
|
|
78
|
+
└── LICENSE
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 🚀 Installation
|
|
84
|
+
|
|
85
|
+
Clone the repository:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
git clone https://github.com/shreyash9999/shanter.git
|
|
89
|
+
cd shanter
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Create and activate a virtual environment:
|
|
93
|
+
|
|
94
|
+
### macOS / Linux
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
python3 -m venv .venv
|
|
98
|
+
source .venv/bin/activate
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Windows
|
|
102
|
+
|
|
103
|
+
```powershell
|
|
104
|
+
python -m venv .venv
|
|
105
|
+
.venv\Scripts\activate
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Install SHANTER:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
pip install -e .
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## ▶️ Running SHANTER
|
|
117
|
+
|
|
118
|
+
### Start the server
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
python3 -m server.main
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Start the client
|
|
125
|
+
|
|
126
|
+
Open another terminal and run:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
shanter
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## 💻 Available Commands
|
|
135
|
+
|
|
136
|
+
Once SHANTER starts, you can use the following commands:
|
|
137
|
+
|
|
138
|
+
| Command | Description |
|
|
139
|
+
|---------|-------------|
|
|
140
|
+
| `register` | Create a new account |
|
|
141
|
+
| `login` | Log in to an existing account |
|
|
142
|
+
| `search` | Search for registered users |
|
|
143
|
+
| `chat` | Start a conversation with another user |
|
|
144
|
+
| `whoami` | Display the currently logged-in user |
|
|
145
|
+
| `logout` | Log out of the current session |
|
|
146
|
+
| `help` | Show available commands |
|
|
147
|
+
| `exit` | Exit SHANTER |
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## 🏗️ Architecture
|
|
152
|
+
|
|
153
|
+
```text
|
|
154
|
+
+----------------------+
|
|
155
|
+
| Client CLI |
|
|
156
|
+
+----------+-----------+
|
|
157
|
+
|
|
|
158
|
+
|
|
|
159
|
+
TCP Socket
|
|
160
|
+
|
|
|
161
|
+
|
|
|
162
|
+
+----------v-----------+
|
|
163
|
+
| SHANTER Server |
|
|
164
|
+
+----------+-----------+
|
|
165
|
+
|
|
|
166
|
+
SQLite Database
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## 🛠️ Technologies Used
|
|
172
|
+
|
|
173
|
+
- Python 3.11+
|
|
174
|
+
- TCP Sockets
|
|
175
|
+
- SQLite
|
|
176
|
+
- bcrypt
|
|
177
|
+
- Threading
|
|
178
|
+
- JSON-based communication protocol
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## 🗺️ Roadmap
|
|
183
|
+
|
|
184
|
+
### Version 1.0
|
|
185
|
+
|
|
186
|
+
- ✅ User Registration
|
|
187
|
+
- ✅ User Login
|
|
188
|
+
- ✅ User Search
|
|
189
|
+
- ✅ Real-time One-to-One Messaging
|
|
190
|
+
- ✅ Interactive CLI
|
|
191
|
+
- ✅ Cross-platform Support
|
|
192
|
+
|
|
193
|
+
### Planned for Future Releases
|
|
194
|
+
|
|
195
|
+
- Group Chat
|
|
196
|
+
- File Transfer
|
|
197
|
+
- Online Presence
|
|
198
|
+
- Message History
|
|
199
|
+
- End-to-End Encryption
|
|
200
|
+
- Rich Terminal User Interface
|
|
201
|
+
- Notifications
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## 🤝 Contributing
|
|
206
|
+
|
|
207
|
+
Contributions, ideas, and bug reports are welcome.
|
|
208
|
+
|
|
209
|
+
If you discover a bug or have a feature request, please open an issue or submit a pull request.
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## 📄 License
|
|
214
|
+
|
|
215
|
+
This project is licensed under the MIT License.
|
|
216
|
+
|
|
217
|
+
See the `LICENSE` file for details.
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## 👨💻 Author
|
|
222
|
+
|
|
223
|
+
**Shreyash Dongare**
|
|
224
|
+
|
|
225
|
+
GitHub: https://github.com/shreyash9999
|
shanter-1.0.0/README.md
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# SHANTER
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<strong>A cross-platform terminal-based real-time chat application built with Python.</strong>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
SHANTER is a lightweight terminal chat application that enables users to communicate in real time over TCP. It provides a simple command-line interface for registering accounts, authenticating users, searching for other users, and exchanging messages across Windows, macOS, and Linux.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## ✨ Features
|
|
12
|
+
|
|
13
|
+
- 🔐 Secure user registration with password hashing (`bcrypt`)
|
|
14
|
+
- 👤 User authentication (login/logout)
|
|
15
|
+
- 🔍 Search for registered users
|
|
16
|
+
- 💬 Real-time one-to-one messaging
|
|
17
|
+
- 🌍 Cross-platform support (Windows, macOS, Linux)
|
|
18
|
+
- 🖥️ Interactive command-line interface
|
|
19
|
+
- 📦 Installable as a Python package
|
|
20
|
+
- ⚡ Lightweight TCP socket-based architecture
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 📁 Project Structure
|
|
25
|
+
|
|
26
|
+
```text
|
|
27
|
+
shanter/
|
|
28
|
+
├── client/ # Client application
|
|
29
|
+
├── common/ # Shared protocol and utilities
|
|
30
|
+
├── server/ # Server implementation
|
|
31
|
+
├── tests/ # Tests
|
|
32
|
+
├── data/ # SQLite database
|
|
33
|
+
├── pyproject.toml
|
|
34
|
+
├── README.md
|
|
35
|
+
└── LICENSE
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## 🚀 Installation
|
|
41
|
+
|
|
42
|
+
Clone the repository:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
git clone https://github.com/shreyash9999/shanter.git
|
|
46
|
+
cd shanter
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Create and activate a virtual environment:
|
|
50
|
+
|
|
51
|
+
### macOS / Linux
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
python3 -m venv .venv
|
|
55
|
+
source .venv/bin/activate
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Windows
|
|
59
|
+
|
|
60
|
+
```powershell
|
|
61
|
+
python -m venv .venv
|
|
62
|
+
.venv\Scripts\activate
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Install SHANTER:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install -e .
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## ▶️ Running SHANTER
|
|
74
|
+
|
|
75
|
+
### Start the server
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
python3 -m server.main
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Start the client
|
|
82
|
+
|
|
83
|
+
Open another terminal and run:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
shanter
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 💻 Available Commands
|
|
92
|
+
|
|
93
|
+
Once SHANTER starts, you can use the following commands:
|
|
94
|
+
|
|
95
|
+
| Command | Description |
|
|
96
|
+
|---------|-------------|
|
|
97
|
+
| `register` | Create a new account |
|
|
98
|
+
| `login` | Log in to an existing account |
|
|
99
|
+
| `search` | Search for registered users |
|
|
100
|
+
| `chat` | Start a conversation with another user |
|
|
101
|
+
| `whoami` | Display the currently logged-in user |
|
|
102
|
+
| `logout` | Log out of the current session |
|
|
103
|
+
| `help` | Show available commands |
|
|
104
|
+
| `exit` | Exit SHANTER |
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## 🏗️ Architecture
|
|
109
|
+
|
|
110
|
+
```text
|
|
111
|
+
+----------------------+
|
|
112
|
+
| Client CLI |
|
|
113
|
+
+----------+-----------+
|
|
114
|
+
|
|
|
115
|
+
|
|
|
116
|
+
TCP Socket
|
|
117
|
+
|
|
|
118
|
+
|
|
|
119
|
+
+----------v-----------+
|
|
120
|
+
| SHANTER Server |
|
|
121
|
+
+----------+-----------+
|
|
122
|
+
|
|
|
123
|
+
SQLite Database
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## 🛠️ Technologies Used
|
|
129
|
+
|
|
130
|
+
- Python 3.11+
|
|
131
|
+
- TCP Sockets
|
|
132
|
+
- SQLite
|
|
133
|
+
- bcrypt
|
|
134
|
+
- Threading
|
|
135
|
+
- JSON-based communication protocol
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## 🗺️ Roadmap
|
|
140
|
+
|
|
141
|
+
### Version 1.0
|
|
142
|
+
|
|
143
|
+
- ✅ User Registration
|
|
144
|
+
- ✅ User Login
|
|
145
|
+
- ✅ User Search
|
|
146
|
+
- ✅ Real-time One-to-One Messaging
|
|
147
|
+
- ✅ Interactive CLI
|
|
148
|
+
- ✅ Cross-platform Support
|
|
149
|
+
|
|
150
|
+
### Planned for Future Releases
|
|
151
|
+
|
|
152
|
+
- Group Chat
|
|
153
|
+
- File Transfer
|
|
154
|
+
- Online Presence
|
|
155
|
+
- Message History
|
|
156
|
+
- End-to-End Encryption
|
|
157
|
+
- Rich Terminal User Interface
|
|
158
|
+
- Notifications
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## 🤝 Contributing
|
|
163
|
+
|
|
164
|
+
Contributions, ideas, and bug reports are welcome.
|
|
165
|
+
|
|
166
|
+
If you discover a bug or have a feature request, please open an issue or submit a pull request.
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## 📄 License
|
|
171
|
+
|
|
172
|
+
This project is licensed under the MIT License.
|
|
173
|
+
|
|
174
|
+
See the `LICENSE` file for details.
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## 👨💻 Author
|
|
179
|
+
|
|
180
|
+
**Shreyash Dongare**
|
|
181
|
+
|
|
182
|
+
GitHub: https://github.com/shreyash9999
|
|
File without changes
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
from common.protocol import PacketType
|
|
2
|
+
from common.utils import send_packet
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def signup(client_socket, response_manager):
|
|
6
|
+
print("\n=== Sign Up ===")
|
|
7
|
+
|
|
8
|
+
username = input("Username: ").strip()
|
|
9
|
+
password = input("Password: ").strip()
|
|
10
|
+
|
|
11
|
+
packet = {
|
|
12
|
+
"type": PacketType.SIGNUP,
|
|
13
|
+
"payload": {
|
|
14
|
+
"username": username,
|
|
15
|
+
"password": password,
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
send_packet(client_socket, packet)
|
|
20
|
+
|
|
21
|
+
response = response_manager.wait()
|
|
22
|
+
|
|
23
|
+
print(f"\n{response['payload']['message']}\n")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def login(client_socket, response_manager):
|
|
27
|
+
print("\n=== Login ===")
|
|
28
|
+
|
|
29
|
+
username = input("Username: ").strip()
|
|
30
|
+
password = input("Password: ").strip()
|
|
31
|
+
|
|
32
|
+
packet = {
|
|
33
|
+
"type": PacketType.LOGIN,
|
|
34
|
+
"payload": {
|
|
35
|
+
"username": username,
|
|
36
|
+
"password": password,
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
send_packet(client_socket, packet)
|
|
41
|
+
|
|
42
|
+
response = response_manager.wait()
|
|
43
|
+
|
|
44
|
+
print(f"\n{response['payload']['message']}\n")
|
|
45
|
+
|
|
46
|
+
if response.get("type") == PacketType.SUCCESS:
|
|
47
|
+
response["payload"]["username"] = username
|
|
48
|
+
|
|
49
|
+
return response
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def search_users(client_socket, response_manager, query=None):
|
|
53
|
+
print("\n=== Search Users ===")
|
|
54
|
+
|
|
55
|
+
if query is None:
|
|
56
|
+
query = input("Search: ").strip()
|
|
57
|
+
|
|
58
|
+
packet = {
|
|
59
|
+
"type": PacketType.SEARCH_USER,
|
|
60
|
+
"payload": {
|
|
61
|
+
"query": query,
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
send_packet(client_socket, packet)
|
|
66
|
+
|
|
67
|
+
response = response_manager.wait()
|
|
68
|
+
|
|
69
|
+
payload = response.get("payload", {})
|
|
70
|
+
|
|
71
|
+
print(f"\n{payload.get('message', '')}")
|
|
72
|
+
|
|
73
|
+
users = payload.get("users", [])
|
|
74
|
+
|
|
75
|
+
if users:
|
|
76
|
+
print("\nUsers:")
|
|
77
|
+
for user in users:
|
|
78
|
+
print(f"- {user}")
|
|
79
|
+
else:
|
|
80
|
+
print("No users found.")
|
|
81
|
+
|
|
82
|
+
print()
|
|
83
|
+
|
|
84
|
+
send_packet(client_socket, packet)
|
|
85
|
+
|
|
86
|
+
response = response_manager.wait()
|
|
87
|
+
|
|
88
|
+
payload = response.get("payload", {})
|
|
89
|
+
|
|
90
|
+
print(f"\n{payload.get('message', '')}")
|
|
91
|
+
|
|
92
|
+
users = payload.get("users", [])
|
|
93
|
+
|
|
94
|
+
if users:
|
|
95
|
+
print("\nUsers:")
|
|
96
|
+
for user in users:
|
|
97
|
+
print(f"- {user}")
|
|
98
|
+
else:
|
|
99
|
+
print("No users found.")
|
|
100
|
+
|
|
101
|
+
print()
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from common.protocol import PacketType
|
|
2
|
+
from common.utils import send_packet
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def chat(client_socket, response_manager, recipient=None):
|
|
6
|
+
print("\n=== Chat ===")
|
|
7
|
+
|
|
8
|
+
if recipient is None:
|
|
9
|
+
recipient = input("Recipient: ").strip()
|
|
10
|
+
|
|
11
|
+
while True:
|
|
12
|
+
message = input("You> ").strip()
|
|
13
|
+
|
|
14
|
+
if message.lower() in {"exit", "quit", "back"}:
|
|
15
|
+
print("Leaving chat...\n")
|
|
16
|
+
break
|
|
17
|
+
|
|
18
|
+
if not message:
|
|
19
|
+
continue
|
|
20
|
+
|
|
21
|
+
packet = {
|
|
22
|
+
"type": PacketType.MESSAGE,
|
|
23
|
+
"payload": {
|
|
24
|
+
"to": recipient,
|
|
25
|
+
"message": message,
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
send_packet(client_socket, packet)
|
|
30
|
+
|
|
31
|
+
response = response_manager.wait()
|
|
32
|
+
|
|
33
|
+
print(response["payload"]["message"])
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from common.protocol import PacketType
|
|
2
|
+
from common.utils import receive_packet
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def start_listener(client_socket, response_manager):
|
|
6
|
+
while True:
|
|
7
|
+
packet = receive_packet(client_socket)
|
|
8
|
+
|
|
9
|
+
if packet is None:
|
|
10
|
+
print("\nDisconnected from server.")
|
|
11
|
+
break
|
|
12
|
+
|
|
13
|
+
packet_type = packet.get("type")
|
|
14
|
+
payload = packet.get("payload", {})
|
|
15
|
+
|
|
16
|
+
if packet_type == PacketType.MESSAGE:
|
|
17
|
+
sender = payload.get("from", "Unknown")
|
|
18
|
+
message = payload.get("message", "")
|
|
19
|
+
|
|
20
|
+
print("\n" + "=" * 40)
|
|
21
|
+
print(f"{sender}: {message}")
|
|
22
|
+
print("=" * 40)
|
|
23
|
+
|
|
24
|
+
else:
|
|
25
|
+
response_manager.put(packet)
|