Update README and main.py to support bible-only mode and improve command formatting
This commit is contained in:
parent
b2f4f69937
commit
a4d7279c22
16
README.md
16
README.md
|
@ -10,24 +10,25 @@
|
||||||
|
|
||||||
Python 3.10 or greater is recommended.
|
Python 3.10 or greater is recommended.
|
||||||
|
|
||||||
In the root of the repo run this command.
|
In the root of the repo run this command to install the required python modules.
|
||||||
```pip install -r requirements.txt```
|
|
||||||
|
```$ pip install -r requirements.txt```
|
||||||
|
|
||||||
## Running
|
## Running
|
||||||
|
|
||||||
The following command with run the server.
|
The following command to run the server.
|
||||||
|
|
||||||
```python3 main.py -s```
|
```$ python3 main.py -s```
|
||||||
|
|
||||||
The following command with run the client.
|
The following command to run the client.
|
||||||
|
|
||||||
```python3 main.py```
|
```$ python3 main.py```
|
||||||
|
|
||||||
Here are the options for running.
|
Here are the options for running.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ python3 main.py -h
|
$ python3 main.py -h
|
||||||
usage: main.py [-h] [-s] [-H HOST] [-p PORT] [-n PLAYERNAME]
|
usage: main.py [-h] [-s] [-H HOST] [-p PORT] [-n PLAYERNAME] [-b]
|
||||||
|
|
||||||
Run the server or client.
|
Run the server or client.
|
||||||
|
|
||||||
|
@ -38,4 +39,5 @@ options:
|
||||||
-p PORT, --port PORT Port number (default: 7788)
|
-p PORT, --port PORT Port number (default: 7788)
|
||||||
-n PLAYERNAME, --playername PLAYERNAME
|
-n PLAYERNAME, --playername PLAYERNAME
|
||||||
Player name (for client)
|
Player name (for client)
|
||||||
|
-b, --bible-only Run in bible-only mode (for server)
|
||||||
```
|
```
|
||||||
|
|
|
@ -35,6 +35,7 @@ class Library:
|
||||||
def serve_forever(self):
|
def serve_forever(self):
|
||||||
try:
|
try:
|
||||||
print(f"Starting server at {self.__host}:{self.__port}")
|
print(f"Starting server at {self.__host}:{self.__port}")
|
||||||
|
if self.__bible_only: print("Bible-only mode active.")
|
||||||
with self.__socket as s:
|
with self.__socket as s:
|
||||||
s.bind((self.__host, self.__port))
|
s.bind((self.__host, self.__port))
|
||||||
s.listen(1)
|
s.listen(1)
|
||||||
|
|
9
main.py
9
main.py
|
@ -47,9 +47,9 @@ def name_gen():
|
||||||
|
|
||||||
return random.choice(adjectives).capitalize() + random.choice(animals).capitalize()
|
return random.choice(adjectives).capitalize() + random.choice(animals).capitalize()
|
||||||
|
|
||||||
def server(host: str='', port: int=7788):
|
def server(host: str='', port: int=7788, bible_only: bool=False):
|
||||||
from library import Library
|
from library import Library
|
||||||
lib = Library(host, port)
|
lib = Library(host, port, bible_only=bible_only)
|
||||||
lib.serve_forever()
|
lib.serve_forever()
|
||||||
|
|
||||||
def client(playername: str = "", host: str='localhost', port: int=7788):
|
def client(playername: str = "", host: str='localhost', port: int=7788):
|
||||||
|
@ -72,10 +72,13 @@ def main(argv):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-n", "--playername", type=str, default="", help="Player name (for client)"
|
"-n", "--playername", type=str, default="", help="Player name (for client)"
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-b", "--bible-only", action="store_true", help="Run in bible-only mode (for server)"
|
||||||
|
)
|
||||||
args = parser.parse_args(argv[1:])
|
args = parser.parse_args(argv[1:])
|
||||||
|
|
||||||
if args.server:
|
if args.server:
|
||||||
server(host=args.host, port=args.port)
|
server(host=args.host, port=args.port, bible_only=args.bible_only)
|
||||||
else:
|
else:
|
||||||
client(playername=args.playername, host=args.host or 'localhost', port=args.port)
|
client(playername=args.playername, host=args.host or 'localhost', port=args.port)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue