mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add a range limit to trading
Prevents initiating trades with client-side ghosts.
This commit is contained in:
parent
434913b946
commit
b0b90744cf
@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Falling through an airship in flight should no longer be possible (although many issues with airship physics remain)
|
- Falling through an airship in flight should no longer be possible (although many issues with airship physics remain)
|
||||||
- Avoided black hexagons when bloom is enabled by suppressing NaN/Inf pixels during the first bloom blur pass
|
- Avoided black hexagons when bloom is enabled by suppressing NaN/Inf pixels during the first bloom blur pass
|
||||||
- Many know water generation problems
|
- Many know water generation problems
|
||||||
|
- Trading over long distances using ghost characters or client-side exploits is no longer possible
|
||||||
|
|
||||||
## [0.11.0] - 2021-09-11
|
## [0.11.0] - 2021-09-11
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// The limit on distance between the entity and a collectible (squared)
|
// The limit on distance between the entity and a collectible (squared)
|
||||||
pub const MAX_PICKUP_RANGE: f32 = 5.0;
|
pub const MAX_PICKUP_RANGE: f32 = 5.0;
|
||||||
pub const MAX_MOUNT_RANGE: f32 = 14.0;
|
pub const MAX_MOUNT_RANGE: f32 = 14.0;
|
||||||
|
pub const MAX_TRADE_RANGE: f32 = 20.0;
|
||||||
|
|
||||||
pub const GRAVITY: f32 = 25.0;
|
pub const GRAVITY: f32 = 25.0;
|
||||||
pub const FRIC_GROUND: f32 = 0.15;
|
pub const FRIC_GROUND: f32 = 0.15;
|
||||||
|
@ -6,8 +6,9 @@ use common::{
|
|||||||
agent::{Agent, AgentEvent},
|
agent::{Agent, AgentEvent},
|
||||||
group::GroupManager,
|
group::GroupManager,
|
||||||
invite::{Invite, InviteKind, InviteResponse, PendingInvites},
|
invite::{Invite, InviteKind, InviteResponse, PendingInvites},
|
||||||
ChatType,
|
ChatType, Pos,
|
||||||
},
|
},
|
||||||
|
consts::MAX_TRADE_RANGE,
|
||||||
trade::{TradeResult, Trades},
|
trade::{TradeResult, Trades},
|
||||||
uid::Uid,
|
uid::Uid,
|
||||||
};
|
};
|
||||||
@ -63,6 +64,14 @@ pub fn handle_invite(
|
|||||||
let mut agents = state.ecs().write_storage::<comp::Agent>();
|
let mut agents = state.ecs().write_storage::<comp::Agent>();
|
||||||
let mut invites = state.ecs().write_storage::<Invite>();
|
let mut invites = state.ecs().write_storage::<Invite>();
|
||||||
|
|
||||||
|
if let InviteKind::Trade = kind {
|
||||||
|
// Check whether the inviter is in range of the invitee
|
||||||
|
let positions = state.ecs().read_storage::<comp::Pos>();
|
||||||
|
if !within_trading_range(positions.get(inviter), positions.get(invitee)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let InviteKind::Group = kind {
|
if let InviteKind::Group = kind {
|
||||||
if !group_manip::can_invite(
|
if !group_manip::can_invite(
|
||||||
state,
|
state,
|
||||||
@ -336,3 +345,10 @@ pub fn handle_invite_decline(server: &mut Server, entity: specs::Entity) {
|
|||||||
handle_invite_answer(state, inviter, entity, InviteAnswer::Declined, kind)
|
handle_invite_answer(state, inviter, entity, InviteAnswer::Declined, kind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn within_trading_range(requester_position: Option<&Pos>, invitee_position: Option<&Pos>) -> bool {
|
||||||
|
match (requester_position, invitee_position) {
|
||||||
|
(Some(rpos), Some(ipos)) => rpos.0.distance_squared(ipos.0) < MAX_TRADE_RANGE.powi(2),
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user