2020-12-13 17:11:55 +00:00
|
|
|
use common_net::msg::{ClientType, ServerGeneral, ServerMsg};
|
2021-03-25 11:22:31 +00:00
|
|
|
use network::{Message, Participant, Stream, StreamError, StreamParams};
|
2020-11-02 18:30:56 +00:00
|
|
|
use serde::{de::DeserializeOwned, Serialize};
|
2020-10-30 16:39:53 +00:00
|
|
|
use specs::Component;
|
2022-09-09 15:29:43 +00:00
|
|
|
use std::sync::atomic::AtomicBool;
|
2019-03-03 22:02:38 +00:00
|
|
|
|
2020-10-30 16:39:53 +00:00
|
|
|
/// Client handles ALL network related information of everything that connects
|
|
|
|
/// to the server Client DOES NOT handle game states
|
|
|
|
/// Client DOES NOT handle network information that is only relevant to some
|
|
|
|
/// "things" connecting to the server (there is currently no such case). First a
|
|
|
|
/// Client connects to the game, when it registers, it gets the `Player`
|
|
|
|
/// component, when he enters the game he gets the `InGame` component.
|
2019-03-03 22:02:38 +00:00
|
|
|
pub struct Client {
|
Redo Network Frontend.
Rather than having a single Stream to handle ALL data, seperate into multiple streams:
- Ping Stream, for seperate PINGS
- Register Stream, only used till the client is registered, then no longer used!
- General Stream, used for msg that can occur always
- NotInGame Stream, used for everything NOT ingame, e.g. Character Screen
- InGame Stream, used for all GAME data, players, terrain, entities, etc...
This version does compile, and gets the client registered (with auth too) but doesnt get to the char screen yet.
This fixes also the ignoring messages problem we had, as we are not sending data to the register stream!
This fixes also the problem that the server had to sleep for the Stream Creation, as the Server is now creating the streams and client has to sleep.
2020-10-04 18:20:18 +00:00
|
|
|
pub client_type: ClientType,
|
2020-10-07 11:59:14 +00:00
|
|
|
pub participant: Option<Participant>,
|
2022-09-09 15:29:43 +00:00
|
|
|
pub last_ping: f64,
|
2020-11-02 18:30:56 +00:00
|
|
|
pub login_msg_sent: AtomicBool,
|
|
|
|
|
2022-09-09 15:29:43 +00:00
|
|
|
//TODO: Consider splitting each of these out into their own components so all the message
|
|
|
|
//processing systems can run in parallel with each other (though it may turn out not to
|
|
|
|
//matter that much).
|
|
|
|
general_stream: Stream,
|
|
|
|
ping_stream: Stream,
|
|
|
|
register_stream: Stream,
|
|
|
|
character_screen_stream: Stream,
|
|
|
|
in_game_stream: Stream,
|
|
|
|
terrain_stream: Stream,
|
2021-03-25 11:22:31 +00:00
|
|
|
|
|
|
|
general_stream_params: StreamParams,
|
|
|
|
ping_stream_params: StreamParams,
|
|
|
|
register_stream_params: StreamParams,
|
|
|
|
character_screen_stream_params: StreamParams,
|
|
|
|
in_game_stream_params: StreamParams,
|
|
|
|
terrain_stream_params: StreamParams,
|
2020-11-02 18:30:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct PreparedMsg {
|
|
|
|
stream_id: u8,
|
|
|
|
message: Message,
|
2019-03-03 22:02:38 +00:00
|
|
|
}
|
2019-03-04 19:50:26 +00:00
|
|
|
|
2019-10-15 04:06:14 +00:00
|
|
|
impl Component for Client {
|
2022-08-08 04:38:20 +00:00
|
|
|
type Storage = specs::DenseVecStorage<Self>;
|
2019-10-06 17:35:47 +00:00
|
|
|
}
|
2020-11-02 18:30:56 +00:00
|
|
|
|
|
|
|
impl Client {
|
|
|
|
pub(crate) fn new(
|
|
|
|
client_type: ClientType,
|
|
|
|
participant: Participant,
|
|
|
|
last_ping: f64,
|
|
|
|
general_stream: Stream,
|
|
|
|
ping_stream: Stream,
|
|
|
|
register_stream: Stream,
|
|
|
|
character_screen_stream: Stream,
|
|
|
|
in_game_stream: Stream,
|
2021-03-11 12:07:03 +00:00
|
|
|
terrain_stream: Stream,
|
2020-11-02 18:30:56 +00:00
|
|
|
) -> Self {
|
2021-03-25 11:22:31 +00:00
|
|
|
let general_stream_params = general_stream.params();
|
|
|
|
let ping_stream_params = ping_stream.params();
|
|
|
|
let register_stream_params = register_stream.params();
|
|
|
|
let character_screen_stream_params = character_screen_stream.params();
|
|
|
|
let in_game_stream_params = in_game_stream.params();
|
|
|
|
let terrain_stream_params = terrain_stream.params();
|
2020-11-02 18:30:56 +00:00
|
|
|
Client {
|
|
|
|
client_type,
|
|
|
|
participant: Some(participant),
|
2022-09-09 15:29:43 +00:00
|
|
|
last_ping,
|
2020-11-02 18:30:56 +00:00
|
|
|
login_msg_sent: AtomicBool::new(false),
|
2022-09-09 15:29:43 +00:00
|
|
|
general_stream,
|
|
|
|
ping_stream,
|
|
|
|
register_stream,
|
|
|
|
character_screen_stream,
|
|
|
|
in_game_stream,
|
|
|
|
terrain_stream,
|
2021-03-25 11:22:31 +00:00
|
|
|
general_stream_params,
|
|
|
|
ping_stream_params,
|
|
|
|
register_stream_params,
|
|
|
|
character_screen_stream_params,
|
|
|
|
in_game_stream_params,
|
|
|
|
terrain_stream_params,
|
2020-11-02 18:30:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn send<M: Into<ServerMsg>>(&self, msg: M) -> Result<(), StreamError> {
|
2021-12-26 16:48:34 +00:00
|
|
|
// TODO: hack to avoid locking stream mutex while serializing the message,
|
|
|
|
// remove this when the mutexes on the Streams are removed
|
|
|
|
let prepared = self.prepare(msg);
|
|
|
|
self.send_prepared(&prepared)
|
|
|
|
/*match msg.into() {
|
2021-03-12 08:10:59 +00:00
|
|
|
ServerMsg::Info(m) => self.register_stream.lock().unwrap().send(m),
|
|
|
|
ServerMsg::Init(m) => self.register_stream.lock().unwrap().send(m),
|
|
|
|
ServerMsg::RegisterAnswer(m) => self.register_stream.lock().unwrap().send(m),
|
2020-11-02 18:30:56 +00:00
|
|
|
ServerMsg::General(g) => {
|
|
|
|
match g {
|
|
|
|
//Character Screen related
|
2022-09-16 00:11:10 +00:00
|
|
|
ServerGeneral::CharacterDataLoadResult(_)
|
2020-11-02 18:30:56 +00:00
|
|
|
| ServerGeneral::CharacterListUpdate(_)
|
|
|
|
| ServerGeneral::CharacterActionError(_)
|
2020-11-14 19:32:39 +00:00
|
|
|
| ServerGeneral::CharacterCreated(_)
|
2021-12-13 00:13:33 +00:00
|
|
|
| ServerGeneral::CharacterEdited(_)
|
2020-11-02 18:30:56 +00:00
|
|
|
| ServerGeneral::CharacterSuccess => {
|
2021-03-12 08:10:59 +00:00
|
|
|
self.character_screen_stream.lock().unwrap().send(g)
|
2020-11-02 18:30:56 +00:00
|
|
|
},
|
2022-07-15 16:59:37 +00:00
|
|
|
//In-game related
|
2020-11-02 18:30:56 +00:00
|
|
|
ServerGeneral::GroupUpdate(_)
|
2021-02-12 23:09:18 +00:00
|
|
|
| ServerGeneral::Invite { .. }
|
2020-11-02 18:30:56 +00:00
|
|
|
| ServerGeneral::InvitePending(_)
|
|
|
|
| ServerGeneral::InviteComplete { .. }
|
|
|
|
| ServerGeneral::ExitInGameSuccess
|
|
|
|
| ServerGeneral::InventoryUpdate(_, _)
|
|
|
|
| ServerGeneral::SetViewDistance(_)
|
Implement /price_list (work in progress), stub for /buy and /sell
remove outdated economic simulation code
remove old values, document
add natural resources to economy
Remove NaturalResources from Place (now in Economy)
find closest site to each chunk
implement natural resources (the distance scale is wrong)
cargo fmt
working distance calculation
this collection of natural resources seem to make sense, too much Wheat though
use natural resources and controlled area to replenish goods
increase the amount of chunks controlled by one guard to 50
add new professions and goods to the list
implement multiple products per worker
remove the old code and rename the new code to the previous name
correctly determine which goods guards will give you access to
correctly estimate the amount of natural resources controlled
adapt to new server API
instrument tooltips
Now I just need to figure out how to store a (reference to) a closure
closures for tooltip content generation
pass site/cave id to the client
Add economic information to the client structure
(not yet exchanged with the server)
Send SiteId to the client, prepare messages for economy request
Make client::sites a HashMap
Specialize the Crafter into Brewer,Bladesmith and Blacksmith
working server request for economic info from within tooltip
fully operational economic tooltips
I need to fix the id clash between caves and towns though
fix overlapping ids between caves and sites
display stock amount
correctly handle invalid (cave) ids in the request
some initial balancing, turn off most info logging
less intrusive way of implementing the dynamic tool tips in map
further tooltip cleanup
further cleanup, dynamic tooltip not fully working as intended
correctly working tooltip visibility logic
cleanup, display labor value
separate economy info request in a separate translation unit
display values as well
nicer display format for economy
add last_exports and coin to the new economy
do not allocate natural resources to Dungeons (making town so much larger)
balancing attempt
print town size statistics
cargo fmt (dead code)
resource tweaks, csv debugging
output a more interesting town (and then all sites)
fix the labor value logic (now we have meaningful prices)
load professions from ron (WIP)
use assets manager in economy
loading professions works
use professions from ron file
fix Labor debug logic
count chunks per type separately
(preparing for better resource control)
better structured resource data
traders, more professions (WIP)
fix exception when starting the simulation
fix replenish function
TODO:
- use area_ratio for resource usage (chunks should be added to stock, ratio on usage?)
- fix trading
documentation clean up
fix merge artifact
Revise trader mechanic
start Coin with a reasonable default
remove the outdated economy code
preserve documentation from removed old structure
output neighboring sites (preparation)
pass list of neighbors to economy
add trade structures
trading stub
Description of purpose by zesterer on Discord
remember prices (needed for planning)
avoid growing the order vector unboundedly
into_iter doesn't clear the Vec, so clear it manually
use drain to process Vecs, avoid clone
fix the test server
implement a test stub (I need to get it faster than 30 seconds to be more useful)
enable info output in test
debug missing and extra goods
use the same logging extension as water, activate feature
update dependencies
determine good prices, good exchange goods
a working set of revisions
a cozy world which economy tests in 2s
first order planning version
fun with package version
buy according to value/priority, not missing amount
introduce min price constant, fix order priority
in depth debugging
with a correct sign the trading plans start to make sense
move the trade planning to a separate function
rename new function
reorganize code into subroutines (much cleaner)
each trading step now has its own function
cut down the number of debugging output
introduce RoadSecurity and Transportation
transport capacity bookkeeping
only plan to pay with valuable goods, you can no longer stockpile unused options
(which interestingly shows a huge impact, to be investigated)
Coin is now listed as a payment (although not used)
proper transportation estimation (although 0)
remove more left overs uncovered by viewing the code in a merge request
use the old default values, handle non-pileable stocks directly before increasing it
(as economy is based on last year's products)
don't order the missing good multiple times
also it uses coin to buy things!
fix warnings and use the transportation from stock again
cargo fmt
prepare evaluation of trade
don't count transportation multiple times
fix merge artifact
operational trade planning
trade itself is still misleading
make clippy happy
clean up
correct labor ratio of merchants (no need to multiply with amount produced)
incomplete merchant labor_value computation
correct last commit
make economy of scale more explicit
make clippy happy (and code cleaner)
more merchant tweaks (more pop=better)
beginning of real trading code
revert the update of dependencies
remove stale comments/unused code
trading implementation complete (but untested)
something is still strange ...
fix sign in trading
another sign fix
some bugfixes and plenty of debugging code
another bug fixed, more to go
fix another invariant (rounding will lead to very small negative value)
introduce Terrain and Territory
fix merge mistakes
2021-03-14 03:18:32 +00:00
|
|
|
| ServerGeneral::SiteEconomy(_)
|
2020-11-02 18:30:56 +00:00
|
|
|
| ServerGeneral::Outcomes(_)
|
2021-02-11 04:54:31 +00:00
|
|
|
| ServerGeneral::Knockback(_)
|
2021-03-25 04:35:33 +00:00
|
|
|
| ServerGeneral::UpdatePendingTrade(_, _, _)
|
2021-11-17 17:09:51 +00:00
|
|
|
| ServerGeneral::FinishedTrade(_)
|
|
|
|
| ServerGeneral::WeatherUpdate(_) => {
|
2021-03-12 08:10:59 +00:00
|
|
|
self.in_game_stream.lock().unwrap().send(g)
|
2020-11-02 18:30:56 +00:00
|
|
|
},
|
2021-03-11 12:07:03 +00:00
|
|
|
//Ingame related, terrain
|
|
|
|
ServerGeneral::TerrainChunkUpdate { .. }
|
2022-05-08 23:53:19 +00:00
|
|
|
| ServerGeneral::LodZoneUpdate { .. }
|
2021-03-11 12:07:03 +00:00
|
|
|
| ServerGeneral::TerrainBlockUpdates(_) => {
|
2021-03-12 08:10:59 +00:00
|
|
|
self.terrain_stream.lock().unwrap().send(g)
|
2021-03-11 12:07:03 +00:00
|
|
|
},
|
2020-11-02 18:30:56 +00:00
|
|
|
// Always possible
|
|
|
|
ServerGeneral::PlayerListUpdate(_)
|
|
|
|
| ServerGeneral::ChatMsg(_)
|
2021-02-10 19:42:59 +00:00
|
|
|
| ServerGeneral::ChatMode(_)
|
2020-11-02 18:30:56 +00:00
|
|
|
| ServerGeneral::SetPlayerEntity(_)
|
2021-12-06 22:17:20 +00:00
|
|
|
| ServerGeneral::TimeOfDay(_, _)
|
2020-11-02 18:30:56 +00:00
|
|
|
| ServerGeneral::EntitySync(_)
|
|
|
|
| ServerGeneral::CompSync(_)
|
|
|
|
| ServerGeneral::CreateEntity(_)
|
|
|
|
| ServerGeneral::DeleteEntity(_)
|
|
|
|
| ServerGeneral::Disconnect(_)
|
2021-03-12 08:10:59 +00:00
|
|
|
| ServerGeneral::Notification(_) => self.general_stream.lock().unwrap().send(g),
|
2020-11-02 18:30:56 +00:00
|
|
|
}
|
|
|
|
},
|
2021-03-12 08:10:59 +00:00
|
|
|
ServerMsg::Ping(m) => self.ping_stream.lock().unwrap().send(m),
|
2021-12-26 16:48:34 +00:00
|
|
|
}*/
|
2020-11-02 18:30:56 +00:00
|
|
|
}
|
|
|
|
|
2022-08-20 21:21:46 +00:00
|
|
|
/// Like `send` but any errors are explicitly ignored.
|
2021-12-26 16:48:34 +00:00
|
|
|
pub(crate) fn send_fallible<M: Into<ServerMsg>>(&self, msg: M) { let _ = self.send(msg); }
|
2020-11-02 18:30:56 +00:00
|
|
|
|
|
|
|
pub(crate) fn send_prepared(&self, msg: &PreparedMsg) -> Result<(), StreamError> {
|
|
|
|
match msg.stream_id {
|
2022-09-09 15:29:43 +00:00
|
|
|
0 => self.register_stream.send_raw(&msg.message),
|
|
|
|
1 => self.character_screen_stream.send_raw(&msg.message),
|
|
|
|
2 => self.in_game_stream.send_raw(&msg.message),
|
|
|
|
3 => self.general_stream.send_raw(&msg.message),
|
|
|
|
4 => self.ping_stream.send_raw(&msg.message),
|
|
|
|
5 => self.terrain_stream.send_raw(&msg.message),
|
2020-11-02 18:30:56 +00:00
|
|
|
_ => unreachable!("invalid stream id"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn prepare<M: Into<ServerMsg>>(&self, msg: M) -> PreparedMsg {
|
|
|
|
match msg.into() {
|
2021-03-25 11:22:31 +00:00
|
|
|
ServerMsg::Info(m) => PreparedMsg::new(0, &m, &self.register_stream_params),
|
|
|
|
ServerMsg::Init(m) => PreparedMsg::new(0, &m, &self.register_stream_params),
|
|
|
|
ServerMsg::RegisterAnswer(m) => PreparedMsg::new(0, &m, &self.register_stream_params),
|
2020-11-02 18:30:56 +00:00
|
|
|
ServerMsg::General(g) => {
|
|
|
|
match g {
|
|
|
|
//Character Screen related
|
2022-09-16 00:11:10 +00:00
|
|
|
ServerGeneral::CharacterDataLoadResult(_)
|
2020-11-02 18:30:56 +00:00
|
|
|
| ServerGeneral::CharacterListUpdate(_)
|
|
|
|
| ServerGeneral::CharacterActionError(_)
|
2020-11-14 19:32:39 +00:00
|
|
|
| ServerGeneral::CharacterCreated(_)
|
2021-12-13 00:13:33 +00:00
|
|
|
| ServerGeneral::CharacterEdited(_)
|
2022-07-05 15:01:22 +00:00
|
|
|
| ServerGeneral::CharacterSuccess
|
|
|
|
| ServerGeneral::SpectatorSuccess(_) => {
|
2021-03-25 11:22:31 +00:00
|
|
|
PreparedMsg::new(1, &g, &self.character_screen_stream_params)
|
2020-11-02 18:30:56 +00:00
|
|
|
},
|
2022-07-15 16:59:37 +00:00
|
|
|
//In-game related
|
2020-11-02 18:30:56 +00:00
|
|
|
ServerGeneral::GroupUpdate(_)
|
2021-02-12 23:09:18 +00:00
|
|
|
| ServerGeneral::Invite { .. }
|
2020-11-02 18:30:56 +00:00
|
|
|
| ServerGeneral::InvitePending(_)
|
|
|
|
| ServerGeneral::InviteComplete { .. }
|
|
|
|
| ServerGeneral::ExitInGameSuccess
|
|
|
|
| ServerGeneral::InventoryUpdate(_, _)
|
2022-09-20 22:13:50 +00:00
|
|
|
| ServerGeneral::GroupInventoryUpdate(_, _, _)
|
2020-11-02 18:30:56 +00:00
|
|
|
| ServerGeneral::SetViewDistance(_)
|
|
|
|
| ServerGeneral::Outcomes(_)
|
2021-02-11 04:54:31 +00:00
|
|
|
| ServerGeneral::Knockback(_)
|
Implement /price_list (work in progress), stub for /buy and /sell
remove outdated economic simulation code
remove old values, document
add natural resources to economy
Remove NaturalResources from Place (now in Economy)
find closest site to each chunk
implement natural resources (the distance scale is wrong)
cargo fmt
working distance calculation
this collection of natural resources seem to make sense, too much Wheat though
use natural resources and controlled area to replenish goods
increase the amount of chunks controlled by one guard to 50
add new professions and goods to the list
implement multiple products per worker
remove the old code and rename the new code to the previous name
correctly determine which goods guards will give you access to
correctly estimate the amount of natural resources controlled
adapt to new server API
instrument tooltips
Now I just need to figure out how to store a (reference to) a closure
closures for tooltip content generation
pass site/cave id to the client
Add economic information to the client structure
(not yet exchanged with the server)
Send SiteId to the client, prepare messages for economy request
Make client::sites a HashMap
Specialize the Crafter into Brewer,Bladesmith and Blacksmith
working server request for economic info from within tooltip
fully operational economic tooltips
I need to fix the id clash between caves and towns though
fix overlapping ids between caves and sites
display stock amount
correctly handle invalid (cave) ids in the request
some initial balancing, turn off most info logging
less intrusive way of implementing the dynamic tool tips in map
further tooltip cleanup
further cleanup, dynamic tooltip not fully working as intended
correctly working tooltip visibility logic
cleanup, display labor value
separate economy info request in a separate translation unit
display values as well
nicer display format for economy
add last_exports and coin to the new economy
do not allocate natural resources to Dungeons (making town so much larger)
balancing attempt
print town size statistics
cargo fmt (dead code)
resource tweaks, csv debugging
output a more interesting town (and then all sites)
fix the labor value logic (now we have meaningful prices)
load professions from ron (WIP)
use assets manager in economy
loading professions works
use professions from ron file
fix Labor debug logic
count chunks per type separately
(preparing for better resource control)
better structured resource data
traders, more professions (WIP)
fix exception when starting the simulation
fix replenish function
TODO:
- use area_ratio for resource usage (chunks should be added to stock, ratio on usage?)
- fix trading
documentation clean up
fix merge artifact
Revise trader mechanic
start Coin with a reasonable default
remove the outdated economy code
preserve documentation from removed old structure
output neighboring sites (preparation)
pass list of neighbors to economy
add trade structures
trading stub
Description of purpose by zesterer on Discord
remember prices (needed for planning)
avoid growing the order vector unboundedly
into_iter doesn't clear the Vec, so clear it manually
use drain to process Vecs, avoid clone
fix the test server
implement a test stub (I need to get it faster than 30 seconds to be more useful)
enable info output in test
debug missing and extra goods
use the same logging extension as water, activate feature
update dependencies
determine good prices, good exchange goods
a working set of revisions
a cozy world which economy tests in 2s
first order planning version
fun with package version
buy according to value/priority, not missing amount
introduce min price constant, fix order priority
in depth debugging
with a correct sign the trading plans start to make sense
move the trade planning to a separate function
rename new function
reorganize code into subroutines (much cleaner)
each trading step now has its own function
cut down the number of debugging output
introduce RoadSecurity and Transportation
transport capacity bookkeeping
only plan to pay with valuable goods, you can no longer stockpile unused options
(which interestingly shows a huge impact, to be investigated)
Coin is now listed as a payment (although not used)
proper transportation estimation (although 0)
remove more left overs uncovered by viewing the code in a merge request
use the old default values, handle non-pileable stocks directly before increasing it
(as economy is based on last year's products)
don't order the missing good multiple times
also it uses coin to buy things!
fix warnings and use the transportation from stock again
cargo fmt
prepare evaluation of trade
don't count transportation multiple times
fix merge artifact
operational trade planning
trade itself is still misleading
make clippy happy
clean up
correct labor ratio of merchants (no need to multiply with amount produced)
incomplete merchant labor_value computation
correct last commit
make economy of scale more explicit
make clippy happy (and code cleaner)
more merchant tweaks (more pop=better)
beginning of real trading code
revert the update of dependencies
remove stale comments/unused code
trading implementation complete (but untested)
something is still strange ...
fix sign in trading
another sign fix
some bugfixes and plenty of debugging code
another bug fixed, more to go
fix another invariant (rounding will lead to very small negative value)
introduce Terrain and Territory
fix merge mistakes
2021-03-14 03:18:32 +00:00
|
|
|
| ServerGeneral::SiteEconomy(_)
|
2021-03-25 04:35:33 +00:00
|
|
|
| ServerGeneral::UpdatePendingTrade(_, _, _)
|
2022-02-20 10:10:18 +00:00
|
|
|
| ServerGeneral::FinishedTrade(_)
|
2021-11-17 17:09:51 +00:00
|
|
|
| ServerGeneral::MapMarker(_)
|
2022-07-05 15:01:22 +00:00
|
|
|
| ServerGeneral::WeatherUpdate(_)
|
|
|
|
| ServerGeneral::SpectatePosition(_) => {
|
2021-03-25 11:22:31 +00:00
|
|
|
PreparedMsg::new(2, &g, &self.in_game_stream_params)
|
2021-02-12 23:09:18 +00:00
|
|
|
},
|
2022-07-15 16:59:37 +00:00
|
|
|
//In-game related, terrain
|
2021-03-11 12:07:03 +00:00
|
|
|
ServerGeneral::TerrainChunkUpdate { .. }
|
2022-05-08 23:53:19 +00:00
|
|
|
| ServerGeneral::LodZoneUpdate { .. }
|
2021-03-11 12:07:03 +00:00
|
|
|
| ServerGeneral::TerrainBlockUpdates(_) => {
|
2021-03-25 11:22:31 +00:00
|
|
|
PreparedMsg::new(5, &g, &self.terrain_stream_params)
|
2021-03-11 12:07:03 +00:00
|
|
|
},
|
2020-11-02 18:30:56 +00:00
|
|
|
// Always possible
|
|
|
|
ServerGeneral::PlayerListUpdate(_)
|
|
|
|
| ServerGeneral::ChatMsg(_)
|
2021-02-10 19:42:59 +00:00
|
|
|
| ServerGeneral::ChatMode(_)
|
2020-11-02 18:30:56 +00:00
|
|
|
| ServerGeneral::SetPlayerEntity(_)
|
2023-06-03 22:14:18 +00:00
|
|
|
| ServerGeneral::TimeOfDay(_, _, _, _)
|
2020-11-02 18:30:56 +00:00
|
|
|
| ServerGeneral::EntitySync(_)
|
2022-07-31 21:01:10 +00:00
|
|
|
| ServerGeneral::CompSync(_, _)
|
2020-11-02 18:30:56 +00:00
|
|
|
| ServerGeneral::CreateEntity(_)
|
|
|
|
| ServerGeneral::DeleteEntity(_)
|
|
|
|
| ServerGeneral::Disconnect(_)
|
|
|
|
| ServerGeneral::Notification(_) => {
|
2021-03-25 11:22:31 +00:00
|
|
|
PreparedMsg::new(3, &g, &self.general_stream_params)
|
2020-11-02 18:30:56 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2021-03-25 11:22:31 +00:00
|
|
|
ServerMsg::Ping(m) => PreparedMsg::new(4, &m, &self.ping_stream_params),
|
2020-11-02 18:30:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-10 07:11:11 +00:00
|
|
|
pub(crate) fn terrain_params(&self) -> StreamParams { self.terrain_stream_params.clone() }
|
|
|
|
|
2022-05-11 19:50:14 +00:00
|
|
|
/// Only used for Serialize Chunks in a SlowJob.
|
|
|
|
/// TODO: find a more elegant version for this invariant
|
|
|
|
pub(crate) fn prepare_chunk_update_msg(
|
2022-05-10 07:11:11 +00:00
|
|
|
terrain_chunk_update: ServerGeneral,
|
|
|
|
params: &StreamParams,
|
|
|
|
) -> PreparedMsg {
|
|
|
|
if !matches!(
|
|
|
|
terrain_chunk_update,
|
|
|
|
ServerGeneral::TerrainChunkUpdate { .. }
|
|
|
|
) {
|
|
|
|
unreachable!("You must not call this function without a terrain chunk update!")
|
|
|
|
}
|
|
|
|
PreparedMsg::new(5, &terrain_chunk_update, params)
|
|
|
|
}
|
|
|
|
|
2020-11-02 18:30:56 +00:00
|
|
|
pub(crate) fn recv<M: DeserializeOwned>(
|
2022-09-09 15:29:43 +00:00
|
|
|
&mut self,
|
2020-11-02 18:30:56 +00:00
|
|
|
stream_id: u8,
|
|
|
|
) -> Result<Option<M>, StreamError> {
|
2021-03-13 08:57:06 +00:00
|
|
|
// TODO: are two systems using the same stream?? why is there contention here?
|
2020-11-02 18:30:56 +00:00
|
|
|
match stream_id {
|
2022-09-09 15:29:43 +00:00
|
|
|
0 => self.register_stream.try_recv(),
|
|
|
|
1 => self.character_screen_stream.try_recv(),
|
|
|
|
2 => self.in_game_stream.try_recv(),
|
|
|
|
3 => self.general_stream.try_recv(),
|
|
|
|
4 => self.ping_stream.try_recv(),
|
|
|
|
5 => self.terrain_stream.try_recv(),
|
2020-11-02 18:30:56 +00:00
|
|
|
_ => unreachable!("invalid stream id"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PreparedMsg {
|
2021-03-25 11:22:31 +00:00
|
|
|
fn new<M: Serialize + ?Sized>(id: u8, msg: &M, stream_params: &StreamParams) -> PreparedMsg {
|
2020-11-02 18:30:56 +00:00
|
|
|
Self {
|
|
|
|
stream_id: id,
|
2021-03-25 11:22:31 +00:00
|
|
|
message: Message::serialize(&msg, stream_params.clone()),
|
2020-11-02 18:30:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|