123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #include "server/entities/ServerPlayer.h"
- #include "common/network/toclient/EntityUpdatePacket.h"
- #include "server/Game.h"
- #include "server/GameServer.h"
- #include "utils/Logger.h"
- ServerPlayer::ServerPlayer(Server::Client& client) : client(client) {
- }
- void ServerPlayer::tick() {
- if(!history.canRead()) {
- return;
- }
- Entity::tick();
- PlayerUpdatePacket p = history.read();
- Vector3 move = p.position - position;
- Vector3 actualMove = Game::world.limitMove(*this, move);
- float diff = (move - actualMove).squareLength();
- if(diff > 0.1f) {
- EntityUpdatePacket e(*this);
- OutPacket out = OutPacket::sequenced(EntityUpdatePacket::getSize());
- e.write(out);
- GameServer::sendToAll(out);
- } else {
- this->move(actualMove);
- }
- }
- void ServerPlayer::onChat(InPacket& in) {
- (void)in;
- }
- void ServerPlayer::send(OutPacket& out) {
- client.send(out);
- }
- void ServerPlayer::onUpdatePacket(const PlayerUpdatePacket& p) {
- history.write(p);
- }
|