Skip to content

Commit

Permalink
fix: add official server bool
Browse files Browse the repository at this point in the history
  • Loading branch information
Jibbajabbafic committed Oct 27, 2023
1 parent 122a821 commit 21cd295
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ pub struct GameServer {
ip: IpAddr,
tls: bool,
port: u16,
official: bool,
pub players: u32,
}

impl GameServer {
pub fn new(name: String, ip: IpAddr, tls: bool, port: u16) -> GameServer {
pub fn new(name: String, ip: IpAddr, tls: bool, port: u16, official: bool) -> GameServer {
GameServer {
name,
ip,
tls,
port,
official,
players: 0,
}
}
Expand Down Expand Up @@ -114,6 +116,7 @@ mod tests {
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
false,
12345,
false,
);
let mut server_list = ServerList::new();
assert_eq!(server_list.len(), 0);
Expand All @@ -128,6 +131,7 @@ mod tests {
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
false,
12345,
false,
);
let mut server_list = ServerList::new();
let uuid = server_list.add(server);
Expand All @@ -143,6 +147,7 @@ mod tests {
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
false,
12345,
false,
);
let expected = server.clone();
let mut server_list = ServerList::new();
Expand All @@ -159,6 +164,7 @@ mod tests {
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
false,
12345,
false,
);
let mut server_list = ServerList::new();
let server_id = server_list.add(server);
Expand Down
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,15 @@ async fn handle_socket(
{
// if this IP is local then it's on the same host so
// replace the it with the server's public IP
let ip = if is_local_ipv4(ip) { server_ip } else { ip };
let mut official = false;
let ip = if is_local_ipv4(ip) {
official = true;
server_ip
} else {
ip
};

let server = GameServer::new(name, ip, tls, port);
let server = GameServer::new(name, ip, tls, port, official);
tracing::info!("created new game server: {:?}", server);
game_id = server_list.add(server);
break;
Expand Down

0 comments on commit 21cd295

Please sign in to comment.