added change_lobby
This commit is contained in:
parent
c28adcd7e5
commit
d206814394
@ -47,7 +47,7 @@ fn setup_logger() {
|
|||||||
.chain(std::io::stdout());
|
.chain(std::io::stdout());
|
||||||
let fileout = fern::Dispatch::new()
|
let fileout = fern::Dispatch::new()
|
||||||
.level(log::LevelFilter::Trace)
|
.level(log::LevelFilter::Trace)
|
||||||
.chain(fern::log_file(format!("elseware-{}.log", chrono::Local::now().format("%Y-%m-%d_%H:%M:%S"))).unwrap());
|
.chain(fern::log_file(format!("elseware-{}.log", chrono::Local::now().format("%Y-%m-%d"))).unwrap());
|
||||||
fern::Dispatch::new()
|
fern::Dispatch::new()
|
||||||
.chain(stdio)
|
.chain(stdio)
|
||||||
.chain(fileout)
|
.chain(fileout)
|
||||||
|
@ -61,3 +61,15 @@ pub fn add_to_lobby(id: ClientId,
|
|||||||
playerinfo: player_info(0x100, &client, &area_client, level_table),
|
playerinfo: player_info(0x100, &client, &area_client, level_table),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn remove_from_lobby(id: ClientId,
|
||||||
|
client_location: &ClientLocation)
|
||||||
|
-> Result<LeaveLobby, ShipError> {
|
||||||
|
let prev_area_index = client_location.get_local_client(id).unwrap().local_client.id();
|
||||||
|
let prev_area_leader_index = client_location.get_area_leader(client_location.get_area(id).unwrap()).unwrap().local_client.id();
|
||||||
|
Ok(LeaveLobby {
|
||||||
|
client: prev_area_index,
|
||||||
|
leader: prev_area_leader_index,
|
||||||
|
_padding: 0,
|
||||||
|
})
|
||||||
|
}
|
@ -35,6 +35,7 @@ pub fn block_selected(id: ClientId,
|
|||||||
character: fc,
|
character: fc,
|
||||||
}),
|
}),
|
||||||
SendShipPacket::CharDataRequest(CharDataRequest {}),
|
SendShipPacket::CharDataRequest(CharDataRequest {}),
|
||||||
|
SendShipPacket::LobbyList(LobbyList::new()),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,10 +48,41 @@ pub fn send_player_to_lobby(id: ClientId,
|
|||||||
let lobby = client_location.add_client_to_next_available_lobby(id, LobbyId(0)).map_err(|_| ShipError::TooManyClients)?;
|
let lobby = client_location.add_client_to_next_available_lobby(id, LobbyId(0)).map_err(|_| ShipError::TooManyClients)?;
|
||||||
let join_lobby = packet::builder::lobby::join_lobby(id, lobby, client_location, clients, level_table)?;
|
let join_lobby = packet::builder::lobby::join_lobby(id, lobby, client_location, clients, level_table)?;
|
||||||
let addto = packet::builder::lobby::add_to_lobby(id, lobby, client_location, clients, level_table)?;
|
let addto = packet::builder::lobby::add_to_lobby(id, lobby, client_location, clients, level_table)?;
|
||||||
|
|
||||||
let neighbors = client_location.get_client_neighbors(id).unwrap();
|
let neighbors = client_location.get_client_neighbors(id).unwrap();
|
||||||
Ok(vec![(id, SendShipPacket::JoinLobby(join_lobby))]
|
Ok(vec![(id, SendShipPacket::JoinLobby(join_lobby))]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.chain(neighbors.into_iter()
|
.chain(neighbors.into_iter()
|
||||||
.map(|c| (c.client, SendShipPacket::AddToLobby(addto.clone())))).collect())
|
.map(|c| (c.client, SendShipPacket::AddToLobby(addto.clone())))).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn change_lobby(id: ClientId,
|
||||||
|
requested_lobby: u32,
|
||||||
|
client_location: &mut ClientLocation,
|
||||||
|
clients: &Clients,
|
||||||
|
level_table: &CharacterLevelTable)
|
||||||
|
-> Result<Vec<(ClientId, SendShipPacket)>, ShipError> {
|
||||||
|
let leave_lobby = packet::builder::lobby::remove_from_lobby(id, client_location).unwrap();
|
||||||
|
let old_neighbors = client_location.get_client_neighbors(id).unwrap();
|
||||||
|
let lobby = LobbyId(requested_lobby as usize);
|
||||||
|
match client_location.add_client_to_lobby(id, lobby) {
|
||||||
|
Ok(lobby) => {
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
let dialog = SmallDialog {
|
||||||
|
padding: [0, 0],
|
||||||
|
msg: String::from("Lobby is full."),
|
||||||
|
};
|
||||||
|
return Ok(vec![(id, SendShipPacket::SmallDialog(dialog))])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let join_lobby = packet::builder::lobby::join_lobby(id, lobby, client_location, clients, level_table)?;
|
||||||
|
let addto = packet::builder::lobby::add_to_lobby(id, lobby, client_location, clients, level_table)?;
|
||||||
|
let neighbors = client_location.get_client_neighbors(id).unwrap();
|
||||||
|
Ok(vec![(id, SendShipPacket::JoinLobby(join_lobby))]
|
||||||
|
.into_iter()
|
||||||
|
.chain(neighbors.into_iter()
|
||||||
|
.map(|c| (c.client, SendShipPacket::AddToLobby(addto.clone()))))
|
||||||
|
.chain(old_neighbors.into_iter()
|
||||||
|
.map(|c| (c.client, SendShipPacket::LeaveLobby(leave_lobby.clone()))))
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
|
@ -64,6 +64,7 @@ pub enum RecvShipPacket {
|
|||||||
Like62ButCooler(Like62ButCooler),
|
Like62ButCooler(Like62ButCooler),
|
||||||
ClientCharacterData(ClientCharacterData),
|
ClientCharacterData(ClientCharacterData),
|
||||||
DoneBursting(DoneBursting),
|
DoneBursting(DoneBursting),
|
||||||
|
LobbySelect(LobbySelect),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RecvServerPacket for RecvShipPacket {
|
impl RecvServerPacket for RecvShipPacket {
|
||||||
@ -84,6 +85,7 @@ impl RecvServerPacket for RecvShipPacket {
|
|||||||
0x6D => Ok(RecvShipPacket::Like62ButCooler(Like62ButCooler::from_bytes(data)?)),
|
0x6D => Ok(RecvShipPacket::Like62ButCooler(Like62ButCooler::from_bytes(data)?)),
|
||||||
0x98 => Ok(RecvShipPacket::ClientCharacterData(ClientCharacterData::from_bytes(data)?)),
|
0x98 => Ok(RecvShipPacket::ClientCharacterData(ClientCharacterData::from_bytes(data)?)),
|
||||||
0x6F => Ok(RecvShipPacket::DoneBursting(DoneBursting::from_bytes(data)?)),
|
0x6F => Ok(RecvShipPacket::DoneBursting(DoneBursting::from_bytes(data)?)),
|
||||||
|
0x84 => Ok(RecvShipPacket::LobbySelect(LobbySelect::from_bytes(data)?)),
|
||||||
_ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec()))
|
_ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,6 +114,7 @@ pub enum SendShipPacket {
|
|||||||
Like62ButCooler(Like62ButCooler),
|
Like62ButCooler(Like62ButCooler),
|
||||||
BurstDone72(BurstDone72),
|
BurstDone72(BurstDone72),
|
||||||
DoneBursting(DoneBursting),
|
DoneBursting(DoneBursting),
|
||||||
|
LobbyList(LobbyList),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SendServerPacket for SendShipPacket {
|
impl SendServerPacket for SendShipPacket {
|
||||||
@ -138,6 +141,7 @@ impl SendServerPacket for SendShipPacket {
|
|||||||
SendShipPacket::Like62ButCooler(pkt) => pkt.as_bytes(),
|
SendShipPacket::Like62ButCooler(pkt) => pkt.as_bytes(),
|
||||||
SendShipPacket::BurstDone72(pkt) => pkt.as_bytes(),
|
SendShipPacket::BurstDone72(pkt) => pkt.as_bytes(),
|
||||||
SendShipPacket::DoneBursting(pkt) => pkt.as_bytes(),
|
SendShipPacket::DoneBursting(pkt) => pkt.as_bytes(),
|
||||||
|
SendShipPacket::LobbyList(pkt) => pkt.as_bytes(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -300,6 +304,9 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
|
|||||||
},
|
},
|
||||||
RecvShipPacket::DoneBursting(_) => {
|
RecvShipPacket::DoneBursting(_) => {
|
||||||
handler::room::done_bursting(id, &self.client_location, &mut self.rooms)
|
handler::room::done_bursting(id, &self.client_location, &mut self.rooms)
|
||||||
|
},
|
||||||
|
RecvShipPacket::LobbySelect(pkt) => {
|
||||||
|
Box::new(handler::lobby::change_lobby(id, pkt.lobby, &mut self.client_location, &self.clients, &self.level_table)?.into_iter())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user