diff --git a/SQCSim-srv/connection.cpp b/SQCSim-srv/connection.cpp index 05c6a04..33d970c 100644 --- a/SQCSim-srv/connection.cpp +++ b/SQCSim-srv/connection.cpp @@ -21,7 +21,7 @@ uint64_t Connection::GetTeamHash() const { return m_loginfo.tid; } std::string Connection::GetName() const { return m_loginfo.name; } -void Connection::AddInput(Input in) { m_input_manifest.insert({ in.timestamp, in }); } +void Connection::AddInput(Input in) { m_input_manifest.insert({ in.timestamp, in }); m_input_vector.push_back(in); } Output* Connection::getOutput(Timestamp time) { auto out = m_output_manifest.find(time); @@ -52,7 +52,6 @@ void Connection::getPacks(SOCKET sock) { Input in; Sync sync; lsPck = recvPacksFrom(sock, &m_buf, m_addr); - std::cout << "a"; for (auto& pck : lsPck) { uint32_t bsize = m_buf.len - (pck - m_buf.ptr); switch (netprot::getType(pck, 1)) { @@ -79,7 +78,8 @@ void Connection::sendPacks(SOCKET sock, std::unordered_mapGetHash(false)) continue; - std::cout << "c"; + //std::cout << m_playinfo.id << ": " << m_playinfo.name << ": " << conn->GetName() << std::endl; + std::cout << out.id << ": " << out.position << std::endl; sendPackTo(sock, &out, &m_bufout, conn->getAddr()); } m_output_vector.pop_front(); diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index 60f2c9a..f21a334 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -149,6 +149,7 @@ int Server::Ready() { sendPack(sock, log, &m_buf); play.id = getUniqueId(); + play.tid = log->tid; strcpy(play.name, log->name); Log(str.append(play.name).append(" SID: [").append(std::to_string(log->sid)).append("]") @@ -205,10 +206,32 @@ void Server::Run() { while (!endgame) { for (auto& [key, conn] : m_players) { - conn->getPacks(m_sock_udp); + std::vector lsPck; + Input in; + Sync sync; + lsPck = recvPacks(m_sock_udp, &m_buf); + for (auto& pck : lsPck) { + uint32_t bsize = m_buf.len - (pck - m_buf.ptr); + switch (netprot::getType(pck, 1)) { + using enum netprot::PACKET_TYPE; + case INPUT: + if (Deserialize(&in, pck, &bsize)) { + m_players[in.sid]->AddInput(in); + //m_input_manifest[in.timestamp] = in; + //m_input_vector.push_back(in); + } + break; + case SYNC: + if (Deserialize(&sync, pck, &bsize)) {} + //m_nsync = true; + break; + default: break; + } + } + lsPck.clear(); + //conn->getPacks(conn->getSock()); if (conn->m_nsync) { conn->Run(m_world); - std::cout << "b"; conn->sendPacks(m_sock_udp, m_players); } } diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index c340e4d..7fd8f4f 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -871,7 +871,7 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) { fPosY = fPosYJump; fPosY -= charSize; - ss << " Velocity : " << m_otherplayerpos; + ss << " Velocity : " << m_player.GetVelocity(); PrintText(fPosX, fPosY, ss.str()); ss.str(""); fPosY -= charSize; @@ -881,7 +881,7 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) { ss.str(""); fPosY -= charSize; - ss << " Remote Position : " << m_remotePlayer.GetPosition();//m_player.GetPosition(); + ss << " Remote Position : " << m_otherplayerpos; PrintText(fPosX, fPosY, ss.str()); ss.str(""); fPosY -= charSize;