😎
This commit is contained in:
parent
464ba131c4
commit
b11a484a5a
@ -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;
|
||||
|
@ -11,4 +11,12 @@
|
||||
#define ID_LIST_SIZE 127
|
||||
#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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ private:
|
||||
void buildIdList(size_t size);
|
||||
|
||||
uint64_t getUniqueId();
|
||||
std::string getDeathMessage(std::string username) const;
|
||||
|
||||
};
|
||||
|
||||
|
@ -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<char*> lsPck;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user