the client never receives individual commands in a battle - SectorManager has receiveSectorState, receiveCompressedSectorState and a heartbeat, and nothing else. so everything the opponent does has to reach the player inside server state, which means the server needs to be able to speak first. it could not: the rpc only ever answered. the gateway now runs a ticker for the length of a battle, calling a new battle_tick on the service five times a second and writing whatever it returns straight to the socket. the simulation stays in the service and the socket stays in the gateway. the first rider is emotes. the player's SendBattleEventMessage reaches the service instead of being logged and dropped, and the bot answers with a taunt of its own; it also sends one unprompted every twelve to thirty seconds, drawn from the rows of taunts.csv that TauntMenu marks as usable. the reply carries the opponent account so it renders on their side of the arena.
15 lines
398 B
Rust
15 lines
398 B
Rust
use service_rpc::{RpcError, RpcResult, WireMessage};
|
|
use titan::{Message, MessageMeta};
|
|
pub fn encode<M>(message: &M) -> RpcResult<WireMessage>
|
|
where
|
|
M: MessageMeta + Message,
|
|
{
|
|
let payload = message
|
|
.to_bytes()
|
|
.map_err(|error| RpcError::Rejected(error.to_string()))?;
|
|
Ok(WireMessage::new(
|
|
M::MESSAGE_TYPE,
|
|
M::MESSAGE_VERSION,
|
|
payload,
|
|
))
|
|
}
|