This commit is contained in:
MarcEricMartel
2023-12-07 15:14:16 -05:00
parent 8bfee4a9ff
commit 486c823da1
2 changed files with 13 additions and 5 deletions

View File

@@ -200,6 +200,10 @@ void Server::Run() {
m_world->BuildWorld();
for (auto& [key, conn] : m_conns) { // Creation des instances de joueurs et premier sync.
if (!conn) {
m_conns.erase(key);
continue;
}
int x = 0,// (rand() % (CHUNK_SIZE_X * WORLD_SIZE_X - 1)),// -(CHUNK_SIZE_X * WORLD_SIZE_X / 2),
y = 0;// (rand() % (CHUNK_SIZE_Y * WORLD_SIZE_Y - 1));// -(CHUNK_SIZE_Y * WORLD_SIZE_Y / 2);
conn->player = new Player(Vector3f(x + .5f, CHUNK_SIZE_Y + 1.8f, y + .5f));
@@ -247,7 +251,8 @@ void Server::Run() {
}
last = tstamp;
for (auto& [key, conn] : m_conns) {
for (auto& [key, conn] : m_conns) {
/* In */
@@ -260,8 +265,10 @@ void Server::Run() {
switch (netprot::getType(pck, 1)) {
using enum netprot::PACKET_TYPE;
case INPUT:
if (Deserialize(&in, pck, &bsize))
m_conns[in.sid]->AddInput(in);
if (Deserialize(&in, pck, &bsize)) {
if (m_conns.count(in.sid))
m_conns[in.sid]->AddInput(in);
}
break;
case SYNC:
if (Deserialize(&sync, pck, &bsize)) {}
@@ -298,6 +305,9 @@ void Server::Run() {
chunkdiffs.emplace_back(std::move(chmo));
conn->ChunkDiffs.clear();
std::string str = conn->player->GetUsername();
Log(str.append(" ").append(std::to_string(conn->player->GetHP())), false, false);
for (auto& bull : conn->Bullets) {
bullets.emplace_back(bull);
Log("POW!", false, false);