X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fnet%2Fnet.cpp;h=3f4bf7453eab78a0ac79b7f045026ec10114a8f0;hb=8507332e2d0c54aec4045fb6f0021bdc3bd57750;hp=13ea4d372784c1f177e404b63394a32d325c5be5;hpb=cf5ce8220483bb062740eeaedde6474928fd5e0e;p=blank.git diff --git a/src/net/net.cpp b/src/net/net.cpp index 13ea4d3..3f4bf74 100644 --- a/src/net/net.cpp +++ b/src/net/net.cpp @@ -29,6 +29,7 @@ constexpr size_t Packet::PlayerUpdate::MAX_LEN; constexpr size_t Packet::SpawnEntity::MAX_LEN; constexpr size_t Packet::DespawnEntity::MAX_LEN; constexpr size_t Packet::EntityUpdate::MAX_LEN; +constexpr size_t Packet::PlayerCorrection::MAX_LEN; namespace { @@ -187,6 +188,8 @@ void ClientConnection::Update(int dt) { SendDespawn(*local_iter); ++local_iter; } + + CheckPlayerFix(); } if (conn.ShouldPing()) { conn.SendPing(server.GetPacket(), server.GetSocket()); @@ -249,6 +252,14 @@ void ClientConnection::SendUpdate(SpawnStatus &status) { conn.Send(server.GetPacket(), server.GetSocket()); } +void ClientConnection::CheckPlayerFix() { + // check always succeeds for now ;) + auto pack = Packet::Make(server.GetPacket()); + pack.WritePacketSeq(player_update_pack); + pack.WritePlayer(Player()); + conn.Send(server.GetPacket(), server.GetSocket()); +} + void ClientConnection::AttachPlayer(Entity &new_player) { DetachPlayer(); player = &new_player; @@ -491,6 +502,8 @@ const char *Packet::Type2String(uint8_t t) noexcept { return "DespawnEntity"; case EntityUpdate::TYPE: return "EntityUpdate"; + case PlayerCorrection::TYPE: + return "PlayerCorrection"; default: return "Unknown"; } @@ -646,6 +659,22 @@ void Packet::EntityUpdate::ReadEntityState(EntityState &state, uint32_t num) con Read(state, off + 4); } +void Packet::PlayerCorrection::WritePacketSeq(std::uint16_t s) noexcept { + Write(s, 0); +} + +void Packet::PlayerCorrection::ReadPacketSeq(std::uint16_t &s) const noexcept { + Read(s, 0); +} + +void Packet::PlayerCorrection::WritePlayer(const Entity &player) noexcept { + Write(player.GetState(), 2); +} + +void Packet::PlayerCorrection::ReadPlayerState(EntityState &state) const noexcept { + Read(state, 2); +} + void ConnectionHandler::Handle(const UDPpacket &udp_pack) { const Packet &pack = *reinterpret_cast(udp_pack.data); @@ -674,6 +703,9 @@ void ConnectionHandler::Handle(const UDPpacket &udp_pack) { case Packet::EntityUpdate::TYPE: On(Packet::As(udp_pack)); break; + case Packet::PlayerCorrection::TYPE: + On(Packet::As(udp_pack)); + break; default: // drop unknown or unhandled packets break;