diff --git a/SQCSim-srv/connection.cpp b/SQCSim-srv/connection.cpp index 1e3ab99..941c7f1 100644 --- a/SQCSim-srv/connection.cpp +++ b/SQCSim-srv/connection.cpp @@ -136,6 +136,10 @@ Timestamp Connection::Run(World* world) { in.keys.left, in.keys.right, in.keys.jump, false, el), world, el); + + out.states.jumping = in.keys.jump; + out.states.running = player->GetVelocity().Length() > .3f; + out.states.dead = player->AmIDead(); if (in.keys.block) { bool block = false; @@ -147,14 +151,15 @@ Timestamp Connection::Run(World* world) { ChunkDiffs.emplace_back(cmod); } - if (in.keys.shoot && m_shoot_acc <= 0.) + if (in.keys.shoot && m_shoot_acc <= 0.) { Bullets.push_back(Bullet(player->GetPOV() + player->GetDirection(), player->GetDirection())); + out.states.shooting = true; + } out.position = player->GetPositionAbs(); out.direction = in.direction; out.timestamp = in.timestamp; out.id = m_playinfo.id; - m_output_manifest[out.timestamp] = out; m_output_vector.push_back(out); tstamp = out.timestamp; diff --git a/SQCSim-srv/define.h b/SQCSim-srv/define.h index e30bd49..2cb6378 100644 --- a/SQCSim-srv/define.h +++ b/SQCSim-srv/define.h @@ -11,4 +11,12 @@ #define ID_LIST_SIZE 127 #define SRV_MANUAL_SETUP true +std::vector DEATHMESSAGES = { "@ has gone to meet their maker.", + "@ has bit the dust, if you know what I mean.", + "@ has ceased to be.", + "@ is no more.", + "@ is like, super dead.", + "RIP, @.", + "So long, @, and thanks for all the lols!"}; + #endif diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index aeba450..5c27aa2 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -214,7 +214,7 @@ void Server::Run() { sendPackTo(m_sock_udp, &sync, &m_buf, conn->getAddr()); } - int timer = m_game.countdown, sync_acc = 0; + int timer = m_game.countdown, sync_acc = 0, deadplayers = 0; std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now(); Timestamp last = 0; std::vector chatlog; @@ -238,7 +238,6 @@ void Server::Run() { /* In */ - int deadplayers = 0; std::vector lsPck; Input in; Chat chat; Sync sync; @@ -266,13 +265,20 @@ void Server::Run() { /* Process */ if (conn->m_nsync) { + Timestamp tstamp = conn->Run(m_world); + if (conn->player->AmIDead()) { + Chat* chat = new Chat(); + chat->dest_id = chat->dest_team_id = chat->src_id = 0; + + strcpy(chat->mess, getDeathMessage(conn->player->GetUsername()).c_str()); + + m_chatlog[tstamp] = chat; + ++deadplayers; conn->m_nsync == false; } else { - Timestamp tstamp = conn->Run(m_world); - for (auto& chmo : conn->ChunkDiffs) chunkdiffs.emplace_back(chmo); conn->ChunkDiffs.clear(); @@ -298,10 +304,11 @@ void Server::Run() { endgame = true; } - for (auto& bull : netbull) { + for (auto& bull : netbull) for (auto& [key, conn] : m_conns) - sendPackTo(m_sock_udp, bull, &m_buf, conn->getAddr()); - } + if (bull->id != conn->GetHash(false)) // Pour pas repitcher au joueur sa propre balle. + sendPackTo(m_sock_udp, bull, &m_buf, conn->getAddr()); + for (auto& bull : bullets) { ChunkMod* cmod = nullptr; @@ -336,7 +343,7 @@ void Server::Run() { Chat end; end.src_id = 0; - char endmess[] = "Game over, motherfuckers."; + char endmess[] = "Game over, mothereffers."; strcpy(end.mess, endmess); @@ -385,9 +392,9 @@ void Server::Log(std::string str, bool is_error = false, bool is_fatal = false) closesocket(m_sock_udp); if (m_sock_tcp) closesocket(m_sock_tcp); - for (const auto& [key, player] : m_conns) { + for (const auto& [key, player] : m_conns) closesocket(player->getSock()); - } + delete m_world; m_conns.clear(); #ifdef _WIN32 @@ -412,3 +419,14 @@ uint64_t Server::getUniqueId() { m_ids.pop_back(); return id; } + +std::string Server::getDeathMessage(std::string username) const { + std::string mess; + std::string temp = DEATHMESSAGES.at(rand() % DEATHMESSAGES.size()); + size_t ind = temp.find('@'); + mess.append(temp.substr(0, ind)); + mess.append(username)); + mess.append(temp.substr(ind + 1)); + + return mess; +} diff --git a/SQCSim-srv/server.h b/SQCSim-srv/server.h index 33e78df..b4f2d55 100644 --- a/SQCSim-srv/server.h +++ b/SQCSim-srv/server.h @@ -50,6 +50,7 @@ private: void buildIdList(size_t size); uint64_t getUniqueId(); + std::string getDeathMessage(std::string username) const; }; diff --git a/SQCSim2021/connector.cpp b/SQCSim2021/connector.cpp index a35c790..eb1d754 100644 --- a/SQCSim2021/connector.cpp +++ b/SQCSim2021/connector.cpp @@ -69,11 +69,6 @@ int Connector::Connect(const char* srv_addr, std::string name) { netprot::sendPack(m_sock_tcp, &log, &bf); - //using namespace std::chrono_literals; - //std::this_thread::sleep_for(100ms); - - //memset(bf.ptr, '\0', BUFFER_LENGTH); - bool ready = false; int errors = 0; std::vector lsPck; diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index c188e97..3ab80e7 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -249,9 +249,9 @@ void Engine::LoadResource() { //TextureAtlas::TextureIndex JumpQuarterBackLeftShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueBackLeftJumpLeftShootingLeftShoot1.png"); //TextureAtlas::TextureIndex JumpQuarterBackRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueBackRightJumpRightShootingRightShoot1.png"); //TextureAtlas::TextureIndex JumpBackShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueBackJumpRightShootingRightShoot1.png"); - - - + + + if (!m_animeAtlas.Generate(TEXTURE_SIZE, false)) { std::cout << " Unable to generate texture atlas ..." << std::endl; abort(); @@ -1430,7 +1430,7 @@ void Engine::Render(float elapsedTime) { m_player.InflictDamage(sync.hp - comp.hp); Vector3f diff = sync.position - comp.position; - + if (diff.y < 1.) diff.y = 0; @@ -1449,7 +1449,7 @@ void Engine::Render(float elapsedTime) { case OUTPUT: if (Deserialize(&out, pck, &bsize)) { if (!m_players.contains(out.id)) { - + std::cout << out.id << " is id no good." << std::endl; break; }