]> git.localhorst.tv Git - blank.git/blobdiff - src/server/net.cpp
added simple command line
[blank.git] / src / server / net.cpp
index b681eec3f74c5d1f3ea576c48d9a2e7138073c7e..f7c874f665fb1fbc4f38e190e045b5ae4f96a255 100644 (file)
@@ -247,7 +247,6 @@ void ClientConnection::Update(int dt) {
                }
                SendUpdates();
 
-               input->Update(dt);
                CheckPlayerFix();
                CheckChunkQueue();
        }
@@ -550,21 +549,17 @@ void ClientConnection::On(const Packet::PlayerUpdate &pack) {
                return;
        }
        glm::vec3 movement(0.0f);
-       float pitch = 0.0f;
-       float yaw = 0.0f;
        uint8_t new_actions;
        uint8_t slot;
 
        player_update_pack = pack.Seq();
        pack.ReadPredictedState(player_update_state);
        pack.ReadMovement(movement);
-       pack.ReadPitch(pitch);
-       pack.ReadYaw(yaw);
        pack.ReadActions(new_actions);
        pack.ReadSlot(slot);
 
        input->SetMovement(movement);
-       input->TurnHead(pitch - input->GetPitch(), yaw - input->GetYaw());
+       input->TurnHead(player_update_state.pitch - input->GetPitch(), player_update_state.yaw - input->GetYaw());
        input->SelectInventory(slot);
 
        if ((new_actions & 0x01) && !(old_actions & 0x01)) {
@@ -598,7 +593,7 @@ void ClientConnection::On(const Packet::Message &pack) {
        pack.ReadMessage(msg);
 
        if (type == 1 && HasPlayer()) {
-               server.DistributeMessage(1, PlayerEntity().ID(), msg);
+               server.DispatchMessage(input->GetPlayer(), msg);
        }
 }
 
@@ -614,7 +609,8 @@ Server::Server(
 , world(world)
 , spawn_index(world.Chunks().MakeIndex(wc.spawn, 3))
 , save(save)
-, player_model(nullptr) {
+, player_model(nullptr)
+, cli(world) {
        serv_sock = SDLNet_UDP_Open(conf.port);
        if (!serv_sock) {
                throw NetError("SDLNet_UDP_Open");
@@ -729,6 +725,17 @@ void Server::SetBlock(Chunk &chunk, int index, const Block &block) {
        }
 }
 
+void Server::DispatchMessage(Player &player, const string &msg) {
+       if (msg.empty()) {
+               return;
+       }
+       if (msg[0] == '/' && msg.size() > 1 && msg[1] != '/') {
+               cli.Execute(player, msg.substr(1));
+       } else {
+               DistributeMessage(1, player.GetEntity().ID(), msg);
+       }
+}
+
 void Server::DistributeMessage(uint8_t type, uint32_t ref, const string &msg) {
        auto pack = Packet::Make<Packet::Message>(serv_pack);
        pack.WriteType(type);