ServerPlayer.cpp 1017 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "server/entities/ServerPlayer.h"
  2. #include "common/network/toclient/EntityUpdatePacket.h"
  3. #include "server/Game.h"
  4. #include "server/GameServer.h"
  5. #include "utils/Logger.h"
  6. ServerPlayer::ServerPlayer(Server::Client& client) : client(client) {
  7. }
  8. void ServerPlayer::tick() {
  9. if(!history.canRead()) {
  10. return;
  11. }
  12. Entity::tick();
  13. PlayerUpdatePacket p = history.read();
  14. Vector3 move = p.position - position;
  15. Vector3 actualMove = Game::world.limitMove(*this, move);
  16. float diff = (move - actualMove).squareLength();
  17. if(diff > 0.1f) {
  18. EntityUpdatePacket e(*this);
  19. OutPacket out = OutPacket::sequenced(EntityUpdatePacket::getSize());
  20. e.write(out);
  21. GameServer::sendToAll(out);
  22. } else {
  23. this->move(actualMove);
  24. }
  25. }
  26. void ServerPlayer::onChat(InPacket& in) {
  27. (void)in;
  28. }
  29. void ServerPlayer::send(OutPacket& out) {
  30. client.send(out);
  31. }
  32. void ServerPlayer::onUpdatePacket(const PlayerUpdatePacket& p) {
  33. history.write(p);
  34. }