Skip to content

Commit

Permalink
refactor: migrate to socketioxide v0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
Erb3 committed Nov 2, 2024
1 parent ae9e6d9 commit 77dc985
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 32 deletions.
82 changes: 59 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ authors = ["Erb3"]
description = "A multiplayer geography game inspired by Posio"

[dependencies]
socketioxide = {version = "0.14.1", features=["extensions", "state"]}
socketioxide = {version = "0.15.0", features=["extensions", "state"]}
tokio = {version = "1.41.0", features=["full"]}
tower-http = {version = "0.6.1", features=["cors", "fs", "timeout"]}
serde = {version = "1.0.214", features=["derive"]}
rand = {version = "0.8.5", features=["std_rng"]}
axum = "0.7.5"
axum = "0.7.7"
serde_json = "1.0.132"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
Expand Down
12 changes: 6 additions & 6 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub(crate) fn on_connect(socket: SocketRef) {
socket
.emit(
"kick",
packets::DisconnectPacket {
&packets::DisconnectPacket {
message: "Bad username".to_string(),
},
)
Expand All @@ -40,7 +40,7 @@ pub(crate) fn on_connect(socket: SocketRef) {
socket
.emit(
"kick",
packets::DisconnectPacket {
&packets::DisconnectPacket {
message: "Username taken".to_string(),
},
)
Expand All @@ -57,7 +57,7 @@ pub(crate) fn on_connect(socket: SocketRef) {
socket
.emit(
"game-metadata",
packets::GameMetadataMessage {
&packets::GameMetadataMessage {
guess_time: state.options.guess_time,
showcase_time: state.options.showcase_time,
},
Expand Down Expand Up @@ -106,7 +106,7 @@ pub(crate) async fn game_loop(opts: GameOptions, io: Arc<SocketIo>, state: state
state.clear_guesses().await;

io.to("PRIMARY")
.emit("newTarget", city.clone().anonymize())
.emit("newTarget", &city.clone().anonymize())
.expect("Unable to broadcast new target");

last_city = Some(city.to_owned());
Expand All @@ -117,7 +117,7 @@ pub(crate) async fn game_loop(opts: GameOptions, io: Arc<SocketIo>, state: state
socket
.emit(
"kick",
packets::DisconnectPacket {
&packets::DisconnectPacket {
message: "Automatically removed due to inactivity".to_string(),
},
)
Expand Down Expand Up @@ -146,7 +146,7 @@ pub(crate) async fn game_loop(opts: GameOptions, io: Arc<SocketIo>, state: state
}
}

let solution = packets::SolutionPacket {
let solution = &packets::SolutionPacket {
location: city,
guesses: state.get_guesses().await,
leaderboard: state.get_players().await,
Expand Down
2 changes: 1 addition & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async fn shutdown_signal(io: Arc<SocketIo>, should_kick: bool) {
socket
.emit(
"kick",
packets::DisconnectPacket {
&packets::DisconnectPacket {
message: "Server going down".to_string(),
},
)
Expand Down

0 comments on commit 77dc985

Please sign in to comment.