Merge branch 'SQC-15_online' of https://github.com/CegepSTH/SQCSim2023 into SQC-15_online
This commit is contained in:
commit
2596a35af4
@ -181,8 +181,6 @@ void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + 1, ammo8, sizeof(uint16_t));
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t) + 1, &sync->hp, sizeof(uint8_t));
|
||||
|
||||
uint32_t vec[3];
|
||||
memcpy(vec, &sync->position, sizeof(Vector3f)); // Pour d<>naturer les floats.
|
||||
|
||||
@ -202,7 +200,17 @@ void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t) + 2, vec8, sizeof(uint32_t) * 3);
|
||||
|
||||
*buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + 2;
|
||||
uint32_t hp;
|
||||
|
||||
memcpy(&hp, &sync->hp, sizeof(float));
|
||||
|
||||
uint8_t hp8[4] = {
|
||||
(uint8_t)((hp >> 24) & 0xFF),
|
||||
(uint8_t)((hp >> 16) & 0xFF),
|
||||
(uint8_t)((hp >> 8) & 0xFF),
|
||||
(uint8_t)(hp & 0xFF) };
|
||||
|
||||
*buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float) + 1;
|
||||
}
|
||||
|
||||
void netprot::Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen) {
|
||||
@ -691,7 +699,6 @@ bool netprot::Deserialize(Sync* sync, char* buf, uint32_t *buflen) {
|
||||
(uint16_t)diff[0] << 8 |
|
||||
(uint16_t)diff[1];
|
||||
|
||||
memcpy(&sync->hp, &buf[1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t)], sizeof(uint8_t));
|
||||
|
||||
uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
|
||||
memcpy(subvec, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t)], sizeof(uint8_t) * 12);
|
||||
@ -711,7 +718,18 @@ bool netprot::Deserialize(Sync* sync, char* buf, uint32_t *buflen) {
|
||||
|
||||
memcpy(&sync->position, vec, sizeof(uint32_t) * 3);
|
||||
|
||||
*buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + 2;
|
||||
uint8_t hp8[4];
|
||||
|
||||
memcpy(&hp8, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t)], sizeof(uint32_t));
|
||||
|
||||
uint32_t hp = (uint32_t)hp8[0] << 24 |
|
||||
(uint32_t)hp8[1] << 16 |
|
||||
(uint32_t)hp8[2] << 8 |
|
||||
(uint32_t)hp8[3];
|
||||
|
||||
memcpy(&sync->hp, &hp, sizeof(float));
|
||||
|
||||
*buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ namespace netprot {
|
||||
uint64_t sid = 0;
|
||||
uint32_t timer = 0;
|
||||
uint16_t ammo = 0;
|
||||
uint8_t hp = 0;
|
||||
float hp = 0;
|
||||
Vector3f position;
|
||||
Sync() {}
|
||||
Sync(Sync* sync) : timestamp(sync->timestamp), sid(sync->sid), timer(sync->timer), ammo(sync->ammo), hp(sync->hp), position(sync->position) {}
|
||||
@ -125,9 +125,11 @@ namespace netprot {
|
||||
uint64_t src_id = 0,
|
||||
dest_id = 0,
|
||||
dest_team_id = 0;
|
||||
char mess[140]; // Good 'nough for twitr, good 'nough for me.
|
||||
char* mess = new char[140]; // Good 'nough for twitr, good 'nough for me.
|
||||
Chat() {}
|
||||
Chat(Chat* cha) : src_id(cha->src_id), dest_id(cha->dest_id), dest_team_id(cha->dest_team_id) { strcpy(cha->mess, mess); }
|
||||
Chat(Chat* cha) : src_id(cha->src_id), dest_id(cha->dest_id), dest_team_id(cha->dest_team_id) {
|
||||
strcpy(mess, 140, cha->mess); }
|
||||
~Chat() { delete[] mess; }
|
||||
};
|
||||
|
||||
struct ChunkMod {
|
||||
|
@ -80,9 +80,6 @@ void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*
|
||||
for (auto& [key, conn] : conns) {
|
||||
if (m_playinfo.id == conn->GetHash(false))
|
||||
continue;
|
||||
//std::cout << m_playinfo.id << ": " << m_playinfo.name << ": " << conn->GetName() << std::endl;
|
||||
//std::cout << out.id << ": " << out.position << std::endl;
|
||||
|
||||
sendPackTo<Output>(sock, &out, &m_bufout, conn->getAddr());
|
||||
}
|
||||
++outs;
|
||||
@ -142,8 +139,8 @@ Timestamp Connection::Run(World* world) {
|
||||
in.keys.right,
|
||||
in.keys.jump, false, el), world, el);
|
||||
|
||||
if (player->GetPosition().y < -10.) {
|
||||
player->InflictDamage(9000);
|
||||
if (player->GetPosition().y < -20.) {
|
||||
player->InflictDamage(9000.);
|
||||
player->Killer = GetHash(true);
|
||||
}
|
||||
|
||||
|
@ -276,16 +276,14 @@ void Server::Run() {
|
||||
Chat* chat = new Chat();
|
||||
chat->dest_id = chat->dest_team_id = chat->src_id = 0;
|
||||
|
||||
std::string killer = m_conns.at(key)->player->GetUsername();
|
||||
std::string killer = m_conns.at(conn->player->Killer)->player->GetUsername();
|
||||
|
||||
std::string mess = getDeathMessage(conn->player->GetUsername(), killer);
|
||||
|
||||
strcpy(chat->mess, 140, mess.c_str());
|
||||
Log(mess, false, false);
|
||||
|
||||
chatlog.emplace_back(chat);
|
||||
++deadplayers;
|
||||
conn->m_nsync == false;
|
||||
conn->m_nsync = false;
|
||||
}
|
||||
else {
|
||||
for (auto& chmo : conn->ChunkDiffs)
|
||||
@ -342,12 +340,6 @@ void Server::Run() {
|
||||
delete chmo;
|
||||
}
|
||||
|
||||
//for (auto& bull : outbox_bullets)
|
||||
//delete bull;
|
||||
|
||||
//for (auto& bull : netbull)
|
||||
//delete bull;
|
||||
|
||||
outbox_bullets.clear();
|
||||
netbull.clear();
|
||||
chunkdiffs.clear();
|
||||
@ -358,7 +350,7 @@ void Server::Run() {
|
||||
end.src_id = 0;
|
||||
char endmess[] = "Game over, mothereffers.";
|
||||
|
||||
strcpy(end.mess, endmess);
|
||||
strcpy(end.mess, 140, endmess);
|
||||
|
||||
for (auto& [key, conn] : m_conns)
|
||||
sendPackTo<Chat>(m_sock_udp, &end, &m_buf, conn->getAddr());
|
||||
@ -451,6 +443,7 @@ std::string Server::getDeathMessage(std::string username, std::string killer) co
|
||||
mess.append(killer);
|
||||
mess.append(temp.substr(indk + 1));
|
||||
}
|
||||
else mess.append(temp.substr(ind + 1));
|
||||
}
|
||||
else {
|
||||
mess.append(temp.substr(0, indk));
|
||||
|
@ -1332,8 +1332,6 @@ void Engine::Render(float elapsedTime) {
|
||||
|
||||
if (m_isSkybox) m_skybox.Render(skybox);
|
||||
|
||||
DrawHud(elapsedTime, bloc);
|
||||
DisplayPovGun();
|
||||
ProcessNotificationQueue();
|
||||
if (m_damage) {
|
||||
InstantDamage();
|
||||
@ -1420,8 +1418,9 @@ void Engine::Render(float elapsedTime) {
|
||||
}
|
||||
if (m_syncs.count(sync.timestamp)) {
|
||||
Sync comp = m_syncs[sync.timestamp];
|
||||
m_player.InflictDamage(sync.hp - comp.hp);
|
||||
|
||||
|
||||
std::cout << "HP: " << sync.hp << std::endl;
|
||||
//m_player.InflictDamage(sync.hp - comp.hp);
|
||||
|
||||
Vector3f diff = sync.position - comp.position;
|
||||
|
||||
@ -1502,6 +1501,9 @@ void Engine::Render(float elapsedTime) {
|
||||
glEnable(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
DrawHud(elapsedTime, bloc);
|
||||
DisplayPovGun();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user