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

@@ -214,7 +214,7 @@ void Server::Run() {
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();
Timestamp last = 0;
std::vector<Chat> chatlog;
@@ -238,7 +238,6 @@ void Server::Run() {
/* In */
int deadplayers = 0;
std::vector<char*> 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<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) {
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;
}