Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: インスタンスの起動とメッセージやりとり機能の実装 #9

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions clocking-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
clap = { version = "4.5.15", features = ["derive", "env"] }
dotenvy = "0.15.7"
rustls-pemfile = "2.1.3"
servify = "0.1.1"
thiserror = "1.0.64"
tokio = { version = "1", features = ["full"] }
tokio-rustls = "0.26.0"
Expand Down
31 changes: 31 additions & 0 deletions clocking-server/src/instance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use servify;

#[derive(Debug, Clone, Copy)]
pub struct InstanceID(u32);

#[derive(Debug, Clone, Copy)]
pub struct PlayerID(u32);

#[derive(Debug)]
pub enum InstanceMessage {
JoinInstance(PlayerID),
}

#[servify::service(
impls = [
Instance_join,
]
)]
#[derive(Debug)]
pub struct Instance {
instance_id: InstanceID,
players: Vec<PlayerID>,
}

#[servify::export]
impl Instance {
fn join(&mut self, player_id: PlayerID) -> Vec<PlayerID> {
self.players.push(player_id);
self.players.clone()
}
}
26 changes: 26 additions & 0 deletions clocking-server/src/instance_manager.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use servify;

use crate::instance::{Instance, InstanceID, PlayerID};
use std::collections::HashMap;

#[derive(Debug)]
pub enum InstanceManagerMessage {
NewInstance(InstanceID),
JoinInstance(PlayerID),
}

#[servify::service(
impls = [
InstanceManager_new_instance,
]
)]
pub struct InstanceManager {
instances: HashMap<InstanceID, PlayerID>,
}

#[servify::export]
impl InstanceManager {
fn new_instance(&mut self, id: InstanceID) {
let instance = Instance::new(id);
}
}
2 changes: 2 additions & 0 deletions clocking-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod cert;
mod err;
mod instance;
mod instance_manager;

use cert::{read_cert_file, read_private_key_file};
use clap::Parser;
Expand Down
Loading