multiplayer 2.3.0__tar.gz → 3.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.
Files changed (25) hide show
  1. {multiplayer-2.3.0 → multiplayer-3.0.0}/PKG-INFO +65 -6
  2. {multiplayer-2.3.0 → multiplayer-3.0.0}/README.md +64 -5
  3. {multiplayer-2.3.0 → multiplayer-3.0.0}/pyproject.toml +1 -1
  4. {multiplayer-2.3.0 → multiplayer-3.0.0}/pyproject.toml.orig +1 -1
  5. {multiplayer-2.3.0 → multiplayer-3.0.0}/src/multiplayer/__init__.py +13 -2
  6. multiplayer-3.0.0/src/multiplayer/client.py +1263 -0
  7. multiplayer-3.0.0/src/multiplayer/exceptions.py +191 -0
  8. multiplayer-3.0.0/src/multiplayer/game.py +3052 -0
  9. {multiplayer-2.3.0 → multiplayer-3.0.0}/src/multiplayer/save.py +211 -24
  10. {multiplayer-2.3.0 → multiplayer-3.0.0}/src/multiplayer/server.py +1488 -92
  11. multiplayer-2.3.0/src/multiplayer/client.py +0 -686
  12. multiplayer-2.3.0/src/multiplayer/exceptions.py +0 -83
  13. multiplayer-2.3.0/src/multiplayer/game.py +0 -615
  14. {multiplayer-2.3.0 → multiplayer-3.0.0}/src/multiplayer/data/cities.csv +0 -0
  15. {multiplayer-2.3.0 → multiplayer-3.0.0}/src/multiplayer/data/countries.csv +0 -0
  16. {multiplayer-2.3.0 → multiplayer-3.0.0}/src/multiplayer/data/egyptian_gods.csv +0 -0
  17. {multiplayer-2.3.0 → multiplayer-3.0.0}/src/multiplayer/data/european_kings.csv +0 -0
  18. {multiplayer-2.3.0 → multiplayer-3.0.0}/src/multiplayer/data/european_queens.csv +0 -0
  19. {multiplayer-2.3.0 → multiplayer-3.0.0}/src/multiplayer/data/greek_gods.csv +0 -0
  20. {multiplayer-2.3.0 → multiplayer-3.0.0}/src/multiplayer/data/planets_moons.csv +0 -0
  21. {multiplayer-2.3.0 → multiplayer-3.0.0}/src/multiplayer/data/rivers.csv +0 -0
  22. {multiplayer-2.3.0 → multiplayer-3.0.0}/src/multiplayer/data/roman_gods.csv +0 -0
  23. {multiplayer-2.3.0 → multiplayer-3.0.0}/src/multiplayer/data/seas_oceans.csv +0 -0
  24. {multiplayer-2.3.0 → multiplayer-3.0.0}/src/multiplayer/py.typed +0 -0
  25. {multiplayer-2.3.0 → multiplayer-3.0.0}/src/multiplayer/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: multiplayer
3
- Version: 2.3.0
3
+ Version: 3.0.0
4
4
  Summary: Library that allows you to manage multiple players, locally, on a network, or on the Internet.
5
5
  Author: devfred78
6
6
  Author-email: devfred78 <devfred78@gmail.com>
@@ -21,7 +21,7 @@ Requires-Dist: msgpack>=1.2.1
21
21
  Requires-Python: >=3.10
22
22
  Description-Content-Type: text/markdown
23
23
 
24
- # Multiplayer Library V2
24
+ # Multiplayer Library
25
25
 
26
26
  A Python library for managing multiplayer game sessions, users, and groups.
27
27
 
@@ -30,7 +30,8 @@ A Python library for managing multiplayer game sessions, users, and groups.
30
30
  - **Player Management**: Create players with static and dynamic attributes.
31
31
  - **User Accounts**: Authentication and role-based permissions (Player, Group Admin, Server Admin).
32
32
  - **Game Sessions**: Support for turn-based and simultaneous games, private games with passwords, and observers.
33
- - **Game Groups**: Organize multiple games into manageable groups.
33
+ - **Game Groups**: Organize multiple games into manageable groups, optionally with a game factory that creates games and enforces unique option values.
34
+ - **Factories**: Define reusable player and game factory templates, with options, exclusions and proposed values exposed to clients.
34
35
  - **Persistence**: Save and restore your game state using JSON or SQLite formats.
35
36
  - **Networking**: Client-Server architecture using TCP with optional TLS 1.3 encryption, automatic server discovery, and real-time notifications.
36
37
  - **Name Suggestions**: Built-in utility to suggest random names for players and games from various categories.
@@ -46,7 +47,7 @@ pip install multiplayer
46
47
  Alternatively, you can install it by downloading the `.whl` file from the [Releases](https://github.com/devfred78/multiplayer/releases) section of the GitHub repository:
47
48
 
48
49
  ```bash
49
- pip install multiplayer-2.0.0-py3-none-any.whl
50
+ pip install multiplayer-3.0.0-py3-none-any.whl
50
51
  ```
51
52
 
52
53
  ## Quick Start
@@ -60,7 +61,7 @@ from multiplayer import ParameterFamily
60
61
  # Create a player with attributes
61
62
  player = Player("Alice", score=(ParameterFamily.DYNAMIC, 0), team=(ParameterFamily.STATIC, "Red"))
62
63
 
63
- # Create a user account associated with its own player profile
64
+ # Create a user account (credentials and permissions, distinct from players)
64
65
  user = User(username="alice_92", password="secret_password", email="alice@example.com")
65
66
  ```
66
67
 
@@ -86,7 +87,63 @@ from multiplayer.game import GameGroup
86
87
 
87
88
  # Organize multiple games
88
89
  group = GameGroup(name="Summer Tournament")
89
- group.add_game(game)
90
+ group.add_game(game) # or group.add_game(game.ID)
91
+ print(group.games) # tuple of game IDs
92
+ ```
93
+
94
+ ### Using Game Factories
95
+
96
+ A `GameFactoryTemplate` defines how the games of a group are created. The group factory copies its options and computes the values already taken by the games of the group.
97
+
98
+ ```python
99
+ from multiplayer import OptionType
100
+ from multiplayer.game import GameFactoryTemplate, GameGroup, Option
101
+
102
+ template = GameFactoryTemplate("Tournament")
103
+ template.add_option(
104
+ Option("Game name", OptionType.TEXT, default="Game_%%RANDOM_NUMBER%%"),
105
+ "name",
106
+ unicity=True,
107
+ )
108
+ template.add_option(
109
+ Option("Max players", OptionType.RANGE, min_value=2, max_value=4, default=4),
110
+ "max_players",
111
+ )
112
+
113
+ group = GameGroup("Summer Tournament", password="secret")
114
+ group.create_game_factory(template)
115
+
116
+ factory = group.game_factory
117
+ name_option_id = factory.options[0][0]
118
+ info = factory.get_option(name_option_id) # entry, exclusions, proposed_value
119
+ print(info["exclusions"], info["proposed_value"])
120
+
121
+ game = group.create_and_add_game({name_option_id: "Final_1"}, password="secret")
122
+ print(game.name, group.games) # unique names are enforced when games join the group
123
+ ```
124
+
125
+ Over a network, the server can announce the `game_factory` feature. An administrator creates a game factory template, applies it to a group (`GROUP_FACTORY_SET` is also available), then clients build their creation form from `get_group_game_factory` and call `create_game(..., game_factory_values=...)`. They can subscribe to `GAME_CREATION_FACTORY_UPDATED` to refresh their form when other games take a value.
126
+
127
+ ```python
128
+ # Administrator (client is a connected GameClient logged in as admin)
129
+ options = [
130
+ {"type": "TEXT", "name": "Game name", "default": "Game_%%RANDOM_NUMBER%%",
131
+ "unicity": True, "target": "ATTRIBUTE", "attribute": "name"},
132
+ {"type": "RANGE", "name": "Max players", "min": 2, "max": 4, "default": 4,
133
+ "target": "ATTRIBUTE", "attribute": "max_players"},
134
+ ]
135
+ template_id = client.create_game_factory_template("Tournament", options)["template_id"]
136
+ group_id = client.send_request(
137
+ "GROUP_CREATE", name="Summer Tournament", game_factory_template_id=template_id
138
+ )["group_id"]
139
+
140
+ # Player preparing a game
141
+ client.on_notification("GAME_CREATION_FACTORY_UPDATED", lambda n: print(n["payload"]))
142
+ form = client.get_group_game_factory(group_id)
143
+ option_id = form["options"][0]["option_id"]
144
+ game_id = client.create_game(
145
+ "Tournament", group_id=group_id, game_factory_values={option_id: "Final_1"}
146
+ )
90
147
  ```
91
148
 
92
149
  ### Persistence
@@ -158,6 +215,8 @@ Press `CTRL+C` to stop it cleanly.
158
215
 
159
216
  For more detailed information, please refer to:
160
217
  - [REFERENCE.md](REFERENCE.md): Full API reference.
218
+ - [SPECIFICATIONS.md](SPECIFICATIONS.md): Detailed design of the library classes.
219
+ - [PROTOCOLE.md](PROTOCOLE.md): Client-server protocol, including the `game_factory` feature.
161
220
  - [INSTALL_DOCKER_CONTAINER_SYNOLOGY_DSM71.md](INSTALL_DOCKER_CONTAINER_SYNOLOGY_DSM71.md): Install the Docker image on Synology DSM 7.1, including data and TLS certificate volume mappings.
162
221
 
163
222
  ## Development
@@ -1,4 +1,4 @@
1
- # Multiplayer Library V2
1
+ # Multiplayer Library
2
2
 
3
3
  A Python library for managing multiplayer game sessions, users, and groups.
4
4
 
@@ -7,7 +7,8 @@ A Python library for managing multiplayer game sessions, users, and groups.
7
7
  - **Player Management**: Create players with static and dynamic attributes.
8
8
  - **User Accounts**: Authentication and role-based permissions (Player, Group Admin, Server Admin).
9
9
  - **Game Sessions**: Support for turn-based and simultaneous games, private games with passwords, and observers.
10
- - **Game Groups**: Organize multiple games into manageable groups.
10
+ - **Game Groups**: Organize multiple games into manageable groups, optionally with a game factory that creates games and enforces unique option values.
11
+ - **Factories**: Define reusable player and game factory templates, with options, exclusions and proposed values exposed to clients.
11
12
  - **Persistence**: Save and restore your game state using JSON or SQLite formats.
12
13
  - **Networking**: Client-Server architecture using TCP with optional TLS 1.3 encryption, automatic server discovery, and real-time notifications.
13
14
  - **Name Suggestions**: Built-in utility to suggest random names for players and games from various categories.
@@ -23,7 +24,7 @@ pip install multiplayer
23
24
  Alternatively, you can install it by downloading the `.whl` file from the [Releases](https://github.com/devfred78/multiplayer/releases) section of the GitHub repository:
24
25
 
25
26
  ```bash
26
- pip install multiplayer-2.0.0-py3-none-any.whl
27
+ pip install multiplayer-3.0.0-py3-none-any.whl
27
28
  ```
28
29
 
29
30
  ## Quick Start
@@ -37,7 +38,7 @@ from multiplayer import ParameterFamily
37
38
  # Create a player with attributes
38
39
  player = Player("Alice", score=(ParameterFamily.DYNAMIC, 0), team=(ParameterFamily.STATIC, "Red"))
39
40
 
40
- # Create a user account associated with its own player profile
41
+ # Create a user account (credentials and permissions, distinct from players)
41
42
  user = User(username="alice_92", password="secret_password", email="alice@example.com")
42
43
  ```
43
44
 
@@ -63,7 +64,63 @@ from multiplayer.game import GameGroup
63
64
 
64
65
  # Organize multiple games
65
66
  group = GameGroup(name="Summer Tournament")
66
- group.add_game(game)
67
+ group.add_game(game) # or group.add_game(game.ID)
68
+ print(group.games) # tuple of game IDs
69
+ ```
70
+
71
+ ### Using Game Factories
72
+
73
+ A `GameFactoryTemplate` defines how the games of a group are created. The group factory copies its options and computes the values already taken by the games of the group.
74
+
75
+ ```python
76
+ from multiplayer import OptionType
77
+ from multiplayer.game import GameFactoryTemplate, GameGroup, Option
78
+
79
+ template = GameFactoryTemplate("Tournament")
80
+ template.add_option(
81
+ Option("Game name", OptionType.TEXT, default="Game_%%RANDOM_NUMBER%%"),
82
+ "name",
83
+ unicity=True,
84
+ )
85
+ template.add_option(
86
+ Option("Max players", OptionType.RANGE, min_value=2, max_value=4, default=4),
87
+ "max_players",
88
+ )
89
+
90
+ group = GameGroup("Summer Tournament", password="secret")
91
+ group.create_game_factory(template)
92
+
93
+ factory = group.game_factory
94
+ name_option_id = factory.options[0][0]
95
+ info = factory.get_option(name_option_id) # entry, exclusions, proposed_value
96
+ print(info["exclusions"], info["proposed_value"])
97
+
98
+ game = group.create_and_add_game({name_option_id: "Final_1"}, password="secret")
99
+ print(game.name, group.games) # unique names are enforced when games join the group
100
+ ```
101
+
102
+ Over a network, the server can announce the `game_factory` feature. An administrator creates a game factory template, applies it to a group (`GROUP_FACTORY_SET` is also available), then clients build their creation form from `get_group_game_factory` and call `create_game(..., game_factory_values=...)`. They can subscribe to `GAME_CREATION_FACTORY_UPDATED` to refresh their form when other games take a value.
103
+
104
+ ```python
105
+ # Administrator (client is a connected GameClient logged in as admin)
106
+ options = [
107
+ {"type": "TEXT", "name": "Game name", "default": "Game_%%RANDOM_NUMBER%%",
108
+ "unicity": True, "target": "ATTRIBUTE", "attribute": "name"},
109
+ {"type": "RANGE", "name": "Max players", "min": 2, "max": 4, "default": 4,
110
+ "target": "ATTRIBUTE", "attribute": "max_players"},
111
+ ]
112
+ template_id = client.create_game_factory_template("Tournament", options)["template_id"]
113
+ group_id = client.send_request(
114
+ "GROUP_CREATE", name="Summer Tournament", game_factory_template_id=template_id
115
+ )["group_id"]
116
+
117
+ # Player preparing a game
118
+ client.on_notification("GAME_CREATION_FACTORY_UPDATED", lambda n: print(n["payload"]))
119
+ form = client.get_group_game_factory(group_id)
120
+ option_id = form["options"][0]["option_id"]
121
+ game_id = client.create_game(
122
+ "Tournament", group_id=group_id, game_factory_values={option_id: "Final_1"}
123
+ )
67
124
  ```
68
125
 
69
126
  ### Persistence
@@ -135,6 +192,8 @@ Press `CTRL+C` to stop it cleanly.
135
192
 
136
193
  For more detailed information, please refer to:
137
194
  - [REFERENCE.md](REFERENCE.md): Full API reference.
195
+ - [SPECIFICATIONS.md](SPECIFICATIONS.md): Detailed design of the library classes.
196
+ - [PROTOCOLE.md](PROTOCOLE.md): Client-server protocol, including the `game_factory` feature.
138
197
  - [INSTALL_DOCKER_CONTAINER_SYNOLOGY_DSM71.md](INSTALL_DOCKER_CONTAINER_SYNOLOGY_DSM71.md): Install the Docker image on Synology DSM 7.1, including data and TLS certificate volume mappings.
139
198
 
140
199
  ## Development
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "multiplayer"
3
- version = "2.3.0"
3
+ version = "3.0.0"
4
4
  description = "Library that allows you to manage multiple players, locally, on a network, or on the Internet."
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "multiplayer"
3
- version = "2.3.0"
3
+ version = "3.0.0"
4
4
  description = "Library that allows you to manage multiple players, locally, on a network, or on the Internet."
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -1,8 +1,8 @@
1
1
  """Multiplayer package initialization."""
2
2
  from enum import Enum
3
3
 
4
- class PlayerRole(Enum):
5
- """Enumeration for player account roles."""
4
+ class UserRole(Enum):
5
+ """Enumeration for user account roles."""
6
6
  PLAYER = "player"
7
7
  GROUP_ADMIN = "group_admin"
8
8
  SERVER_ADMIN = "server_admin"
@@ -23,3 +23,14 @@ class SaveFormat(Enum):
23
23
  """Enumeration for the supported persistence formats of a save file."""
24
24
  JSON = "json"
25
25
  SQLITE = "sqlite"
26
+
27
+ class OptionType(Enum):
28
+ """Enumeration for the types of the player customization options.
29
+
30
+ These types are typically used by a client process to build the widgets
31
+ of a player customization form.
32
+ """
33
+ CHECK = "check"
34
+ RANGE = "range"
35
+ LIST = "list"
36
+ TEXT = "text"