This commit is contained in:
MarcEricMartel 2023-12-05 14:25:21 -05:00
parent 464ba131c4
commit b11a484a5a
6 changed files with 49 additions and 22 deletions

View File

@ -137,6 +137,10 @@ Timestamp Connection::Run(World* world) {
in.keys.right, in.keys.right,
in.keys.jump, false, el), world, el); 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) { if (in.keys.block) {
bool block = false; bool block = false;
ChunkMod* cmod = world->ChangeBlockAtCursor(BLOCK_TYPE::BTYPE_METAL, ChunkMod* cmod = world->ChangeBlockAtCursor(BLOCK_TYPE::BTYPE_METAL,
@ -147,14 +151,15 @@ Timestamp Connection::Run(World* world) {
ChunkDiffs.emplace_back(cmod); 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())); Bullets.push_back(Bullet(player->GetPOV() + player->GetDirection(), player->GetDirection()));
out.states.shooting = true;
}
out.position = player->GetPositionAbs(); out.position = player->GetPositionAbs();
out.direction = in.direction; out.direction = in.direction;
out.timestamp = in.timestamp; out.timestamp = in.timestamp;
out.id = m_playinfo.id; out.id = m_playinfo.id;
m_output_manifest[out.timestamp] = out; m_output_manifest[out.timestamp] = out;
m_output_vector.push_back(out); m_output_vector.push_back(out);
tstamp = out.timestamp; tstamp = out.timestamp;

View File

@ -11,4 +11,12 @@
#define ID_LIST_SIZE 127 #define ID_LIST_SIZE 127
#define SRV_MANUAL_SETUP true #define SRV_MANUAL_SETUP true
std::vector<std::string> 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 #endif

View File

@ -214,7 +214,7 @@ void Server::Run() {
sendPackTo<Sync>(m_sock_udp, &sync, &m_buf, conn->getAddr()); sendPackTo<Sync>(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(); std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();
Timestamp last = 0; Timestamp last = 0;
std::vector<Chat> chatlog; std::vector<Chat> chatlog;
@ -238,7 +238,6 @@ void Server::Run() {
/* In */ /* In */
int deadplayers = 0;
std::vector<char*> lsPck; std::vector<char*> lsPck;
Input in; Chat chat; Sync sync; Input in; Chat chat; Sync sync;
@ -266,13 +265,20 @@ void Server::Run() {
/* Process */ /* Process */
if (conn->m_nsync) { if (conn->m_nsync) {
Timestamp tstamp = conn->Run(m_world);
if (conn->player->AmIDead()) { 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; ++deadplayers;
conn->m_nsync == false; conn->m_nsync == false;
} }
else { else {
Timestamp tstamp = conn->Run(m_world);
for (auto& chmo : conn->ChunkDiffs) for (auto& chmo : conn->ChunkDiffs)
chunkdiffs.emplace_back(chmo); chunkdiffs.emplace_back(chmo);
conn->ChunkDiffs.clear(); conn->ChunkDiffs.clear();
@ -298,10 +304,11 @@ void Server::Run() {
endgame = true; endgame = true;
} }
for (auto& bull : netbull) { for (auto& bull : netbull)
for (auto& [key, conn] : m_conns) for (auto& [key, conn] : m_conns)
sendPackTo<BulletAdd>(m_sock_udp, bull, &m_buf, conn->getAddr()); if (bull->id != conn->GetHash(false)) // Pour pas repitcher au joueur sa propre balle.
} sendPackTo<BulletAdd>(m_sock_udp, bull, &m_buf, conn->getAddr());
for (auto& bull : bullets) { for (auto& bull : bullets) {
ChunkMod* cmod = nullptr; ChunkMod* cmod = nullptr;
@ -336,7 +343,7 @@ void Server::Run() {
Chat end; Chat end;
end.src_id = 0; end.src_id = 0;
char endmess[] = "Game over, motherfuckers."; char endmess[] = "Game over, mothereffers.";
strcpy(end.mess, endmess); 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); closesocket(m_sock_udp);
if (m_sock_tcp) if (m_sock_tcp)
closesocket(m_sock_tcp); closesocket(m_sock_tcp);
for (const auto& [key, player] : m_conns) { for (const auto& [key, player] : m_conns)
closesocket(player->getSock()); closesocket(player->getSock());
}
delete m_world; delete m_world;
m_conns.clear(); m_conns.clear();
#ifdef _WIN32 #ifdef _WIN32
@ -412,3 +419,14 @@ uint64_t Server::getUniqueId() {
m_ids.pop_back(); m_ids.pop_back();
return id; 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;
}

View File

@ -50,6 +50,7 @@ private:
void buildIdList(size_t size); void buildIdList(size_t size);
uint64_t getUniqueId(); uint64_t getUniqueId();
std::string getDeathMessage(std::string username) const;
}; };

View File

@ -69,11 +69,6 @@ int Connector::Connect(const char* srv_addr, std::string name) {
netprot::sendPack(m_sock_tcp, &log, &bf); 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; bool ready = false;
int errors = 0; int errors = 0;
std::vector<char*> lsPck; std::vector<char*> lsPck;