Skip to content

Commit eb0dc45

Browse files
committed
fix readme
1 parent 9579c1a commit eb0dc45

File tree

3 files changed

+4
-154
lines changed

3 files changed

+4
-154
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bevy_slinet"
3-
version = "0.16.0"
3+
version = "0.16.1"
44
authors = [
55
"Sliman4 <4sliman4@gmail.com>",
66
"aggyomfg <aggyomfg@yandex.com>"

README.md

Lines changed: 2 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -12,166 +12,16 @@ A simple networking plugin for bevy.
1212
- Multiple clients/servers with different configs (specifies a protocol, packet types, serializer, etc.)
1313
- De/serialization. You choose a serialization format, packet type (you probably want it to be `enum`), and receive events with deserialized packets.
1414

15-
> Note: Everything in bevy_slinet is feature-gated. Make sure to enable features you need (`client`, `server`, `protocol_tcp`, `protocol_udp`, `serializer_bincode`).
16-
17-
## Client example
18-
19-
```rust
20-
use bevy::prelude::*;
21-
use serde::{Deserialize, Serialize};
22-
23-
use bevy_slinet::client::{ClientPlugin, ConnectionEstablishEvent, PacketReceiveEvent};
24-
use bevy_slinet::packet_length_serializer::LittleEndian;
25-
use bevy_slinet::protocols::tcp::TcpProtocol;
26-
use bevy_slinet::serializers::bincode::{BincodeSerializer, DefaultOptions};
27-
use bevy_slinet::ClientConfig;
28-
29-
struct Config;
30-
31-
impl ClientConfig for Config {
32-
type ClientPacket = Packet;
33-
type ServerPacket = Packet;
34-
type Protocol = TcpProtocol;
35-
type EncodeError = bincode::error::EncodeError;
36-
type DecodeError = bincode::error::DecodeError;
37-
type LengthSerializer = LittleEndian<u32>;
38-
fn build_serializer() -> SerializerAdapter<
39-
Self::ServerPacket,
40-
Self::ClientPacket,
41-
Self::EncodeError,
42-
Self::DecodeError,
43-
> {
44-
SerializerAdapter::ReadOnly(Arc::new(
45-
BincodeSerializer::default(),
46-
))
47-
}
48-
}
49-
50-
#[derive(Serialize, Deserialize, Debug)]
51-
enum ClientPacket {
52-
String(String),
53-
}
54-
55-
#[derive(Serialize, Deserialize, Debug)]
56-
enum ServerPacket {
57-
String(String),
58-
}
59-
60-
fn main() {
61-
App::new()
62-
.add_plugins(MinimalPlugins)
63-
.add_plugins(ClientPlugin::<Config>::connect("127.0.0.1:3000"))
64-
.add_observer(connection_establish_system)
65-
.add_observer(packet_receive_system)
66-
.run()
67-
}
68-
69-
fn connection_establish_system(event: On<ConnectionEstablishEvent<Config>>) {
70-
println!("Connected!");
71-
}
72-
73-
fn packet_receive_system(event: On<PacketReceiveEvent<Config>>) {
74-
match &event.event().packet {
75-
ServerPacket::String(s) => println!("Got a message: {}", s),
76-
}
77-
event
78-
.event()
79-
.connection
80-
.send(ClientPacket::String("Hello, Server!".to_string()))
81-
.unwrap();
82-
}
83-
```
84-
85-
## Server Example
86-
87-
```rust
88-
use bevy::prelude::*;
89-
use serde::{Deserialize, Serialize};
90-
91-
use bevy_slinet::packet_length_serializer::LittleEndian;
92-
use bevy_slinet::protocols::tcp::TcpProtocol;
93-
use bevy_slinet::serializers::bincode::{BincodeSerializer, DefaultOptions};
94-
use bevy_slinet::server::{NewConnectionEvent, ServerPlugin, PacketReceiveEvent};
95-
use bevy_slinet::ServerConfig;
96-
97-
struct Config;
98-
99-
impl ServerConfig for Config {
100-
type ClientPacket = Packet;
101-
type ServerPacket = Packet;
102-
type Protocol = TcpProtocol;
103-
type EncodeError = bincode::error::EncodeError;
104-
type DecodeError = bincode::error::DecodeError;
105-
type LengthSerializer = LittleEndian<u32>;
106-
fn build_serializer() -> SerializerAdapter<
107-
Self::ClientPacket,
108-
Self::ServerPacket,
109-
Self::EncodeError,
110-
Self::DecodeError,
111-
> {
112-
SerializerAdapter::ReadOnly(Arc::new(
113-
BincodeSerializer::default(),
114-
))
115-
}
116-
}
117-
118-
#[derive(Serialize, Deserialize, Debug)]
119-
enum ClientPacket {
120-
String(String),
121-
}
122-
123-
#[derive(Serialize, Deserialize, Debug)]
124-
enum ServerPacket {
125-
String(String),
126-
}
127-
128-
fn main() {
129-
App::new()
130-
.add_plugins(MinimalPlugins)
131-
.add_plugins(ServerPlugin::<Config>::bind("127.0.0.1:3000").unwrap())
132-
.add_observer(new_connection_system)
133-
.add_observer(packet_receive_system)
134-
.run()
135-
}
136-
137-
fn new_connection_system(event: On<NewConnectionEvent<Config>>) {
138-
event
139-
.event()
140-
.connection
141-
.send(ServerPacket::String("Hello, Client!".to_string()))
142-
.unwrap();
143-
}
144-
145-
fn packet_receive_system(event: On<PacketReceiveEvent<Config>>) {
146-
match &event.event().packet {
147-
ClientPacket::String(s) => println!("Got a message from a client: {}", s),
148-
}
149-
event
150-
.event()
151-
.connection
152-
.send(ServerPacket::String("Hello, Client!".to_string()))
153-
.unwrap();
154-
}
155-
```
15+
> Note: Everything in bevy_slinet is feature-gated. Make sure to enable features you need (`client`, `server`, `protocol_tcp`, `protocol_udp`, `serializer_bincode`, `serializer_bincode_serde`).
15616
15717
Note: you should implement keep-alive and disconnection systems yourself, or look at [lobby_and_battle_servers example](examples/lobby_and_battle_servers.rs)
15818

159-
## More examples
160-
161-
[Examples](https://github.com/aggyomfg/bevy_slinet/tree/main/examples).
19+
## [More Examples](https://github.com/aggyomfg/bevy_slinet/tree/main/examples)
16220

16321
### Compatibility table
16422

16523
| Plugin Version | Bevy Version |
16624
|----------------|--------------|
167-
| `0.1` | `0.6` |
168-
| `0.2` | `0.6` |
169-
| `0.3` | `0.7` |
170-
| `0.4` | `0.8` |
171-
| `0.5` | `0.9` |
172-
| `0.6` | `0.10.1` |
173-
| `0.7` | `0.11` |
174-
| `0.8` | `0.12` |
17525
| `0.9` | `0.13` |
17626
| `0.10` | `0.13` |
17727
| `0.11` | `0.14` |

0 commit comments

Comments
 (0)