diff --git a/.gitignore b/.gitignore
index f15149d..8ffde58 100644
--- a/.gitignore
+++ b/.gitignore
@@ -378,3 +378,5 @@ FodyWeavers.xsd
/SQCSim2021/cmake/*
!/SQCSim2021/cmake/CMakeLists.txt
/SQCSim2021/SQCSim-client
+SQCSim2021/SQCSim2021.vcxproj.filters
+SQCSim2021/SQCSim2021.vcxproj
diff --git a/SQCSim-common/SQCSim-common.vcxproj b/SQCSim-common/SQCSim-common.vcxproj
index 991cd1d..c618082 100644
--- a/SQCSim-common/SQCSim-common.vcxproj
+++ b/SQCSim-common/SQCSim-common.vcxproj
@@ -48,7 +48,7 @@
StaticLibrary
false
- v143
+ ClangCL
true
Unicode
@@ -76,6 +76,7 @@
true
WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
+ stdcpp20
Console
@@ -90,6 +91,7 @@
true
WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
+ stdcpp20
Console
@@ -104,6 +106,7 @@
true
_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
+ stdcpp20
Console
@@ -118,7 +121,7 @@
true
NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
- stdcpp17
+ stdcpp20
Console
@@ -131,6 +134,7 @@
+
@@ -144,6 +148,7 @@
+
diff --git a/SQCSim-common/SQCSim-common.vcxproj.filters b/SQCSim-common/SQCSim-common.vcxproj.filters
index 26c6c05..45814cf 100644
--- a/SQCSim-common/SQCSim-common.vcxproj.filters
+++ b/SQCSim-common/SQCSim-common.vcxproj.filters
@@ -54,6 +54,9 @@
Fichiers d%27en-tête
+
+ Fichiers d%27en-tête
+
@@ -80,5 +83,8 @@
Fichiers sources
+
+ Fichiers sources
+
\ No newline at end of file
diff --git a/SQCSim-common/boostinfo.cpp b/SQCSim-common/boostinfo.cpp
new file mode 100644
index 0000000..9b54626
--- /dev/null
+++ b/SQCSim-common/boostinfo.cpp
@@ -0,0 +1,32 @@
+#include "boostinfo.h"
+#include
+
+BoostInfo::BoostInfo(BoostType type, const std::string& name, float u, float v, float s, int dur) : m_type(type), m_name(name), m_u(u), m_v(v), m_s(s), m_durability(dur)
+{
+}
+
+BoostInfo::~BoostInfo()
+{
+}
+
+BoostType BoostInfo::GetType() const
+{
+ return m_type;
+}
+
+void BoostInfo::GetTexture(float& u, float& v, float& s)
+{
+ u = m_u;
+ v = m_v;
+ s = m_s;
+}
+
+void BoostInfo::Show() const
+{
+ std::cout << "Type: " << m_type << std::endl;
+ std::cout << "Nom: " << m_name << std::endl;
+ std::cout << "Durabilite: " << m_durability << std::endl;
+ std::cout << "Coordonnees Texture: " << m_u << ", " << m_v << ", " << m_s << std::endl;
+}
+
+
diff --git a/SQCSim-common/boostinfo.h b/SQCSim-common/boostinfo.h
new file mode 100644
index 0000000..e76d1ed
--- /dev/null
+++ b/SQCSim-common/boostinfo.h
@@ -0,0 +1,29 @@
+#ifndef BOOSTINFO_H__
+#define BOOSTINFO_H__
+
+#include
+#include "define.h"
+
+class BoostInfo
+{
+public:
+ BoostInfo(BoostType type, const std::string& name, float u, float v, float s, int dur);
+ ~BoostInfo();
+
+ BoostType GetType() const;
+
+ void GetTexture(float& u, float& v, float& s);
+
+ void Show() const;
+
+private:
+ BoostType m_type;
+ float m_u;
+ float m_v;
+ float m_s;
+ std::string m_name;
+ int m_durability;
+
+};
+
+#endif // BOOSTINFO_H__
diff --git a/SQCSim-common/bullet.cpp b/SQCSim-common/bullet.cpp
index 873879d..a489c55 100644
--- a/SQCSim-common/bullet.cpp
+++ b/SQCSim-common/bullet.cpp
@@ -3,24 +3,53 @@
Bullet::Bullet(Vector3f pos, Vector3f dir) : m_startpos(pos), m_currentpos(pos), m_velocity(dir) {}
-Bullet::Bullet(Vector3f pos, Vector3f dir, uint64_t tid): m_startpos(pos), m_currentpos(pos), m_velocity(dir), m_tid(tid) {}
+Bullet::Bullet(Vector3f pos, Vector3f dir, uint64_t shooter_id): m_startpos(pos), m_currentpos(pos), m_velocity(dir), m_shooter_id(shooter_id) {}
Bullet::~Bullet() {}
-bool Bullet::Update(World* world, float elapsedtime, int perframe) {
+bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordered_map mapPlayer, netprot::ChunkMod** chunkmod) {
int max = 100 / perframe;
+ float damage = 0.057f;
for (int x = 0; x < max; ++x) {
m_currentpos += m_velocity * elapsedtime;
+ for (auto& [key, player] : mapPlayer) {
+ bool hit = false;
+ if ((m_currentpos - player->GetPosition()).Length() < .6f) {
+ hit = true;
+ }
+ if ((m_currentpos - player->GetPOV()).Length() < .2f) {
+ damage *= 2; // HEADSHOT!
+ hit = true;
+ }
+ if (hit && !player->AmIDead()) {
+ player->InflictDamage(damage);
+ player->m_hit = true;
+
+ if (player->AmIDead())
+ player->Killer = m_shooter_id;
+
+ return true;
+ }
+ }
+
if (!world->ChunkAt(m_currentpos))
return true;
else if (world->BlockAt(m_currentpos) != BTYPE_AIR) {
+ if (chunkmod) {
+ using namespace netprot;
+ *chunkmod = new ChunkMod();
+ (*chunkmod)->old_b_type = world->BlockAt(m_currentpos);
+ (*chunkmod)->b_type = BTYPE_AIR;
+ (*chunkmod)->pos = m_currentpos;
+ }
+
world->ChangeBlockAtPosition(BTYPE_AIR, m_currentpos);
return true;
}
else if ((m_currentpos - m_startpos).Length() > VIEW_DISTANCE) return true;
}
-
+
return false;
}
@@ -39,6 +68,6 @@ Vector3f Bullet::getVel() const {
return m_velocity;
}
-uint64_t Bullet::getTeamID(){
- return m_tid;
-}
+//uint64_t Bullet::getTeamID(){
+// return m_tid;
+//}
diff --git a/SQCSim-common/bullet.h b/SQCSim-common/bullet.h
index 1b5e227..3f875d9 100644
--- a/SQCSim-common/bullet.h
+++ b/SQCSim-common/bullet.h
@@ -1,10 +1,14 @@
#ifndef BULLET_H__
#define BULLET_H__
+#include
#include "define.h"
#include "vector3.h"
+#include "player.h"
+#include "netprotocol.h"
class World;
+class Player;
class Bullet {
public:
@@ -12,17 +16,19 @@ public:
Bullet(Vector3f pos, Vector3f dir, uint64_t tid);
~Bullet();
- bool Update(World* world, float elapsedtime, int perframe);
+ bool Update(World* world, float elapsedtime, int perframe, std::unordered_map m_mapPlayer, netprot::ChunkMod** chunkmod);
void Transpose(int& x, int& z);
Vector3f getPos() const;
Vector3f getVel() const;
- uint64_t getTeamID();
+ //uint64_t getTeamID();
private:
Vector3f m_startpos,
m_currentpos,
m_velocity;
- uint64_t m_tid = 0;
+ uint64_t m_shooter_id = 0;
+
+
};
#endif // BULLET_H__
diff --git a/SQCSim-common/chunk.cpp b/SQCSim-common/chunk.cpp
index cb93218..0f30cb8 100644
--- a/SQCSim-common/chunk.cpp
+++ b/SQCSim-common/chunk.cpp
@@ -1,137 +1,312 @@
#include "chunk.h"
#include "world.h"
+#include
-Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y) {
- //std::ostringstream pos; // Vérifie l'existence d'un fichier .chunk avec sa position.
- //pos << CHUNK_PATH << x << '_' << y << ".chunk";
- //std::ifstream input(pos.str(), std::fstream::binary);
- //if (input.fail()) {
- OpenSimplexNoise::Noise simplex = OpenSimplexNoise::Noise(seed);
- m_blocks.Reset(BTYPE_AIR);
+Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y) {
+ //std::ostringstream pos; // V�rifie l'existence d'un fichier .chunk avec sa position.
+ //pos << CHUNK_PATH << x << '_' << y << ".chunk";
+ //std::ifstream input(pos.str(), std::fstream::binary);
- for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Montagnes
- for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
- float xnoiz, ynoiz;
- xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 4096.;
- ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 4096.;
- double height = 0;
- for (int x = 0; x < 39; ++x) {
- height += simplex.eval(xnoiz, ynoiz);
- height *= .79;
- xnoiz *= 1.139;
- ynoiz *= 1.139;
- }
- height = height * 2000. * simplex.eval((double)(ix + x * CHUNK_SIZE_X) / 512., (double)(iz + y * CHUNK_SIZE_Z) / 512.);
- height /= (CHUNK_SIZE_Y / 1.9);
- height += 15.;
- for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy)
- SetBlock(ix, iy, iz, BTYPE_METAL, nullptr);
- }
- for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Collines
- for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
- float xnoiz, ynoiz;
- xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 512.;
- ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 512.;
- float height = simplex.eval(xnoiz, ynoiz) * 50.f;// +1.f;
- for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) {
- if (GetBlock(ix, iy, iz) == BTYPE_AIR)
- SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr);
- }
- }
- for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Lacs"
- for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
- for (int iy = 0; iy < 13; ++iy) {
- if (GetBlock(ix, iy, iz) == BTYPE_AIR)
- SetBlock(ix, iy, iz, BTYPE_ICE, nullptr);
- }
- }
- //for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Arbres"
- // for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
- // float xnoiz, ynoiz;
- // xnoiz = (double)(iz * CHUNK_SIZE_Y + x * CHUNK_SIZE_X) / 256.;
- // ynoiz = (double)(ix * CHUNK_SIZE_Y + y * CHUNK_SIZE_Z) / 256.;
- // bool tree = (int)(abs(simplex.eval(xnoiz, ynoiz)) * 17933.f) % CHUNK_SIZE_Y > 126 ? true : false;
- // for (int iy = 0; iy < CHUNK_SIZE_Y - 10; ++iy)
- // if (GetBlock(ix, iy, iz) == BTYPE_AIR)
- // if (GetBlock(ix, iy - 1, iz) == BTYPE_GRASS)
- // if (tree) {
- // for (int i = 0; i < (int)(abs(simplex.eval(xnoiz, ynoiz) * 4)) % 42 + 1; ++i)
- // SetBlock(ix, iy + i, iz, BTYPE_DIRT, nullptr);
- // break;
- // }
- // }
- /* }
- else {
- input.seekg(0, std::ios_base::end);
- int size = input.tellg();
- input.seekg(0, std::ios_base::beg);
+ //if (input.fail()) {
+ OpenSimplexNoise::Noise simplex = OpenSimplexNoise::Noise(seed);
+ int ratio = 0;
- char data[CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z];
- input.read(data, size);
- input.close();
+ ratio = x * y % 7;
+ m_blocks.Reset(BTYPE_AIR);
+
+#pragma region Montagnes et Grass des montagnes
+ for (int ix = 0; ix < CHUNK_SIZE_X; ++ix)
+ for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
+ float xnoiz, ynoiz;
+ xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 4796.;
+ ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 4796.;
+ double height = 0;
+ for (int x = 0; x < 39; ++x) {
+ height += simplex.eval(xnoiz, ynoiz);
+ height *= .79;
+ xnoiz *= 1.1305;
+ ynoiz *= 1.1305;
+ }
+ height = height * 2000. * simplex.eval((double)(ix + x * CHUNK_SIZE_X) / 512., (double)(iz + y * CHUNK_SIZE_Z) / 512.);
+ height /= (CHUNK_SIZE_Y / 1.9);
+ height += 15.;
+ for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) {
+ if (iy < 20)
+ {
+ //std::cout << "" << ynoiz << std::endl;
+ SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr);
+ }
+ else if (iy == 20 || iy == 21) {
+ double fractionalPart = ynoiz - static_cast(ynoiz);
+
+ if (iy == 20) {
+ if (fractionalPart < 0.3) {
+ SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr);
+ }
+ else {
+ SetBlock(ix, iy, iz, BTYPE_METAL, nullptr);
+ }
+ }
+ else if (iy == 21) {
+ if (fractionalPart < 0.6) {
+ SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr);
+ }
+ else {
+ SetBlock(ix, iy, iz, BTYPE_METAL, nullptr);
+ }
+ }
+ }
+ else
+ {
+ SetBlock(ix, iy, iz, BTYPE_METAL, nullptr);
+ }
+ }
+ }
+#pragma endregion
+
+#pragma region Lacs
+ for (int ix = 0; ix < CHUNK_SIZE_X; ++ix)
+ for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
+ for (int iy = 0; iy < 13; ++iy) {
+ if (iy < 5 && GetBlock(ix, iy, iz) == BTYPE_AIR) {
+ SetBlock(ix, iy, iz, BTYPE_ICE, nullptr);
+ }
+ else if (iy >= 5 && GetBlock(ix, iy, iz) == BTYPE_AIR) {
+ SetBlock(ix, iy, iz, BTYPE_ICE, nullptr);
+ }
+ }
+ }
+#pragma endregion
+
+ //int rnd = rand() % 15;
+ if (ratio == 1)
+ for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // structure
+ for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
+ for (int iy = 0; iy < 14; ++iy) {
+ if (ix == 3)
+ if (GetBlock(ix, iy, iz) == BTYPE_AIR)
+ Structure(ix, iy, iz, 2);
+ }
+ }
+ if (ratio == 3)
+ for (int ix = 0; ix < CHUNK_SIZE_Z; ++ix) // structure
+ for (int iz = 0; iz < CHUNK_SIZE_X; ++iz) {
+ for (int iy = 0; iy < 14; ++iy) {
+ if (iz == 4)
+ if (GetBlock(ix, iy, iz) == BTYPE_AIR)
+ Structure(ix, iy, iz, 1);
+ }
+ }
+ if (ratio == 5)
+ for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // structure
+ for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
+ for (int iy = 0; iy < 14; ++iy) {
+ if (ix == 3)
+ if (GetBlock(ix, iy, iz) == BTYPE_AIR)
+ Structure(ix, iy, iz, 2);
+ }
+ }
+
+
+
+
+
+#pragma region Arbre
+ double valeurRnd = 0;
+ int treeheight = 10;
+ int lastTreeX = -1;
+ int lastTreeZ = -1;
+
+ int minDistanceBetweenTrees = 10; // Définir la distance minimale entre les arbres
+
+
+ for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) {
+ for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
+ if (GetBlock(ix, 0, iz) != BTYPE_ICE) {
+ float xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 4796.;
+ float ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 4796.;
+ double height = 0;
+ for (int i = 0; i < 39; ++i) {
+ height += simplex.eval(xnoiz, ynoiz);
+ height *= .79;
+ xnoiz *= 1.1305;
+ ynoiz *= 1.1305;
+ }
+ height = height * 2000. * simplex.eval((double)(ix + x * CHUNK_SIZE_X) / 512., (double)(iz + y * CHUNK_SIZE_Z) / 512.);
+ height /= (CHUNK_SIZE_Y / 1.9);
+ height += 15.;
+ if (GetBlock(ix, (int)height, iz) == BTYPE_GRASS || (GetBlock(ix, (int)height, iz) == BTYPE_METAL)) {
+ valeurRnd = simplex.eval(xnoiz, ynoiz);
+ int distanceThreshold = 20;
+ // Vérifie si l'emplacement n'est pas à l'intérieur des lacs
+ bool isInsideLake = false;
+ for (int iy = 0; iy < 13; ++iy) {
+ if (GetBlock(ix, iy, iz) == BTYPE_ICE) {
+ isInsideLake = true;
+ break;
+ }
+ }
+ if (!isInsideLake && ((valeurRnd > -0.4 && valeurRnd < -0.38) || (valeurRnd > -0.35 && valeurRnd < -0.31)
+ || (valeurRnd > 0.3 && valeurRnd < 0.32) || (valeurRnd > 0.37 && valeurRnd < 0.39))
+ ) {
+ if (lastTreeX == -1 || abs(ix - lastTreeX) > minDistanceBetweenTrees || abs(iz - lastTreeZ) > minDistanceBetweenTrees) {
+ if (valeurRnd < 0.1)
+ treeheight = 10;
+ else {
+ treeheight = valeurRnd * 20;
+ if (treeheight < 5)
+ treeheight = 5;
+ }
+ PlaceTree(ix, height, iz, treeheight);
+ lastTreeX = ix;
+ lastTreeZ = iz;
+ }
+ }
+ }
+ }
+ }
+ }
+#pragma endregion
+
+
+
+
+
+
+
+
+ //else {
+ // input.seekg(0, std::ios_base::end);
+ // int size = input.tellg();
+ // input.seekg(0, std::ios_base::beg);
+
+ // char data[CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z];
+ // input.read(data, size);
+ // input.close();
+
+ // for (int ix = 0; ix < CHUNK_SIZE_X; ++ix)
+ // for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz)
+ // for (int iy = 0; iy < CHUNK_SIZE_Y; ++iy)
+ // m_blocks.Set(ix, iy, iz, data[ix + (iz * CHUNK_SIZE_X) + (iy * CHUNK_SIZE_Z * CHUNK_SIZE_X)]);
+ //}*/
+
+
+
+
+ //for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Collines
+// for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
+// float xnoiz, ynoiz;
+// xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 512.;
+// ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 512.;
+// float height = simplex.eval(xnoiz, ynoiz) * 50.f;// +1.f;
+// for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) {
+// if (iy < 10 && GetBlock(ix, iy, iz) == BTYPE_AIR) {
+// SetBlock(ix, iy, iz, BTYPE_METAL, nullptr); // Collines
+// }
+// else if (iy >= 10 && GetBlock(ix, iy, iz) == BTYPE_AIR) {
+// SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr); // Grass des collines
+// }
+// }
+// }
- for (int ix = 0; ix < CHUNK_SIZE_X; ++ix)
- for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz)
- for (int iy = 0; iy < CHUNK_SIZE_Y; ++iy)
- m_blocks.Set(ix, iy, iz, data[ix + (iz * CHUNK_SIZE_X) + (iy * CHUNK_SIZE_Z * CHUNK_SIZE_X)]);
- }*/
}
+void Chunk::PlaceTree(int x, int y, int z, int height) {
+ // Vérifie si les coordonnées x, y, z sont dans les limites du chunk
+ if (x < 0 || x >= CHUNK_SIZE_X || y < 0 || y >= CHUNK_SIZE_Y || z < 0 || z >= CHUNK_SIZE_Z) {
+ // Coordonnées hors limites du chunk, sortie anticipée pour éviter tout accès non valide
+ return;
+ }
+
+ // Place la tige de l'arbre
+ for (int iy = 0; iy < height + 1; ++iy) {
+ if (y + iy < CHUNK_SIZE_Y) { // Vérifie si la hauteur est à l'intérieur des limites du chunk
+ SetBlock(x, y + iy, z, BTYPE_DIRT, nullptr);
+ }
+ }
+
+ // Place les feuilles de l'arbre
+ int foliageHeight = height / 2;
+ for (int dy = 0; dy < foliageHeight; ++dy) {
+ for (int dx = -4; dx <= 4; ++dx) {
+ for (int dz = -4; dz <= 4; ++dz) {
+ // Vérifie que les coordonnées se trouvent à l'intérieur des limites du chunk
+ if (x + dx >= 0 && x + dx < CHUNK_SIZE_X && y + height + dy >= 0 && y + height + dy < CHUNK_SIZE_Y &&
+ z + dz >= 0 && z + dz < CHUNK_SIZE_Z) {
+ // Vérifie si le bloc est à une distance acceptable du centre des feuilles pour les placer
+ double distanceSquared = dx * dx + dy * dy + dz * dz;
+ if (distanceSquared < 20) {
+ SetBlock(x + dx, y + height + dy, z + dz, BTYPE_GREENGRASS, nullptr);
+ }
+ }
+ }
+ }
+ }
+}
+
+
+
+
+
Chunk::~Chunk() {
- /*if (m_isModified) {
- char data[CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z];
+ /*if (m_isModified) {
+ char data[CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z];
- for (int x = 0; x < CHUNK_SIZE_X; ++x)
- for (int z = 0; z < CHUNK_SIZE_Z; ++z)
- for (int y = 0; y < CHUNK_SIZE_Y; ++y)
- data[x + (z * CHUNK_SIZE_X) + (y * CHUNK_SIZE_Z * CHUNK_SIZE_X)] = (char)GetBlock(x, y, z);
+ for (int x = 0; x < CHUNK_SIZE_X; ++x)
+ for (int z = 0; z < CHUNK_SIZE_Z; ++z)
+ for (int y = 0; y < CHUNK_SIZE_Y; ++y)
+ data[x + (z * CHUNK_SIZE_X) + (y * CHUNK_SIZE_Z * CHUNK_SIZE_X)] = (char)GetBlock(x, y, z);
- std::ostringstream pos;
- pos << CHUNK_PATH << m_posX << '_' << m_posY << ".chunk";
+ std::ostringstream pos;
+ pos << CHUNK_PATH << m_posX << '_' << m_posY << ".chunk";
- std::ofstream output(pos.str(), std::fstream::binary);
- output.write(data, sizeof(data));
- output.close();
- }*/
+ std::ofstream output(pos.str(), std::fstream::binary);
+ output.write(data, sizeof(data));
+ output.close();
+ }*/
}
void Chunk::RemoveBlock(int x, int y, int z, World* world) {
- m_blocks.Set(x, y, z, BTYPE_AIR);
- CheckNeighbors(x, y, world);
- m_isDirty = true;
+ m_blocks.Set(x, y, z, BTYPE_AIR);
+ CheckNeighbors(x, y, world);
+ m_isDirty = true;
}
void Chunk::SetBlock(int x, int y, int z, BlockType type, World* world) {
- m_blocks.Set(x, y, z, type);
- if (world) CheckNeighbors(x, z, world); // Si nullptr, ne pas vérifier les chunks voisines.
- m_isDirty = true;
+ m_blocks.Set(x, y, z, type);
+ if (world) CheckNeighbors(x, z, world); // Si nullptr, ne pas v�rifier les chunks voisines.
+ m_isDirty = true;
}
BlockType Chunk::GetBlock(int x, int y, int z) { return m_blocks.Get(x, y, z); }
void Chunk::CheckNeighbors(unsigned int x, unsigned int z, World* world) {
- unsigned int cx, cy;
+ unsigned int cx, cy;
- world->GetScope(cx, cy);
+ world->GetScope(cx, cy);
- if (x == 0 && m_posX - cx >= 0 &&
- world->ChunkAt((m_posX - cx - 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z))
- world->ChunkAt((m_posX - cx - 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)->MakeDirty();
- else if (x == CHUNK_SIZE_X - 1 && m_posX - cx < WORLD_SIZE_X &&
- world->ChunkAt((m_posX - cx + 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z))
- world->ChunkAt((m_posX - cx + 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)->MakeDirty();
+ if (x == 0 && m_posX - cx >= 0 &&
+ world->ChunkAt((m_posX - cx - 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z))
+ world->ChunkAt((m_posX - cx - 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)->MakeDirty();
+ else if (x == CHUNK_SIZE_X - 1 && m_posX - cx < WORLD_SIZE_X &&
+ world->ChunkAt((m_posX - cx + 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z))
+ world->ChunkAt((m_posX - cx + 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)->MakeDirty();
- if (z == 0 && m_posY - cy >= 0 &&
- world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy - 1) * CHUNK_SIZE_Z))
- world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy - 1) * CHUNK_SIZE_Z)->MakeDirty();
- else if (z == CHUNK_SIZE_X - 1 && m_posY - cy < WORLD_SIZE_Y &&
- world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy + 1) * CHUNK_SIZE_Z))
- world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy + 1) * CHUNK_SIZE_Z)->MakeDirty();
+ if (z == 0 && m_posY - cy >= 0 &&
+ world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy - 1) * CHUNK_SIZE_Z))
+ world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy - 1) * CHUNK_SIZE_Z)->MakeDirty();
+ else if (z == CHUNK_SIZE_X - 1 && m_posY - cy < WORLD_SIZE_Y &&
+ world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy + 1) * CHUNK_SIZE_Z))
+ world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy + 1) * CHUNK_SIZE_Z)->MakeDirty();
}
void Chunk::GetPosition(unsigned int& x, unsigned int& y) const { x = m_posX; y = m_posY; }
+
+
+
+
bool Chunk::IsDirty() const { return m_isDirty; }
void Chunk::MakeDirty() { m_isDirty = true; }
@@ -140,3 +315,11 @@ void Chunk::MakeClean() { m_isDirty = false; }
void Chunk::MakeModified() { m_isModified = true; }
+
+void Chunk::Structure(int x, int y, int z,int height)
+{
+ for (int i = 0; i < height; i++)
+ {
+ SetBlock(x, i + y, z, BTYPE_GRASS, nullptr);
+ }
+}
diff --git a/SQCSim-common/chunk.h b/SQCSim-common/chunk.h
index b053928..edda885 100644
--- a/SQCSim-common/chunk.h
+++ b/SQCSim-common/chunk.h
@@ -27,7 +27,9 @@ class Chunk {
BlockType GetBlock(int x, int y, int z);
void CheckNeighbors(unsigned int x, unsigned int z, World* world);
void GetPosition(unsigned int& x, unsigned int& y) const;
+ void PlaceTree(int x, int y, int z, int height);
+ void Structure(int x, int y, int z, int height);
bool IsDirty() const;
void MakeDirty();
void MakeClean();
diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h
index f65bc2b..685bf5d 100644
--- a/SQCSim-common/define.h
+++ b/SQCSim-common/define.h
@@ -4,12 +4,14 @@
#include
#include
-#define SRV_PORT 1025
-#define CLI_PORT 1026
+#define SRV_PORT 10000
+#define CLI_PORT 10001
-#define CHUNK_SIZE_X 4
+#define BUFFER_LENGTH 1500
+
+#define CHUNK_SIZE_X 6
#define CHUNK_SIZE_Y 64
-#define CHUNK_SIZE_Z 4
+#define CHUNK_SIZE_Z 6
#define MAX_SELECTION_DISTANCE 5
#define SEED 0
#define COUNTDOWN 300
@@ -25,23 +27,43 @@
#define THREADS_UPDATE_CHUNKS 6
#define THREADS_DELETE_CHUNKS 3
-#define VIEW_DISTANCE 512 // Si les chunks arrêtent de s'afficher pendant une game et qu'il y a un access violation quand tu quitte, il faut augmenter ce chiffre.
+#define VIEW_DISTANCE 512 // Si les chunks arr�tent de s'afficher pendant une game et qu'il y a un access violation quand tu quitte, il faut augmenter ce chiffre.
#define TEXTURE_SIZE 512
#define MAX_BULLETS 512
+#define TIME_SPEED_BOOST 10 //secondes
+#define TIME_DAMAGE_BOOST 10 //secondes
+#define TIME_INVINCIBLE_BOOST 4 //secondes
+#define STRENGTH_SPEED_BOOST 10 //Pourcentage
+#define BULLET_TIME .1
+
typedef uint8_t BlockType;
-enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_LAST };
+enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_GREENGRASS, BTYPE_LAST };
+typedef uint8_t BoostType;
+enum BOOST_TYPE { BTYPE_SPEED, BTYPE_HEAL, BTYPE_DAMAGE, BTYPE_INVINCIBLE, BTYPE_BOOST_LAST };
+
+//anim
+enum ANIM_TYPE { STILL = 0, SHOOTING = 8, JUMPING = 16, JUMPINGSHOOTING = 24, DEAD = 32, TYPE_LAST = 40};
+enum ANIM_POS {FRONT, QUARTER_FRONT_LEFT, QUATER_FRONT_RIGHT, PROFIL_LEFT, PROFIL_RIGHT, QUARTER_BACK_LEFT, QUARTER_BACK_RIGHT, BACK , POS_LAST};
+
typedef uint64_t Timestamp;
#ifdef _WIN32
#pragma comment(lib,"wsock32.lib") // Pour pouvoir faire fonctionner le linker sans le vcxproject
#pragma comment(lib,"ws2_32.lib")
+
#include
#include
#include
#include
+#define poll WSAPoll
+#define flag_t u_long
+#define addrlen_t int
+#define ioctl ioctlsocket
+#define SOCK_NONBLOCK FIONBIO
+#define strcpy strcpy_s
#define popen _popen
#define pclose _pclose
@@ -51,10 +73,14 @@ typedef uint64_t Timestamp;
#include
#include
#include
+#include
#include
#include
#include
+#include
+#define flag_t unsigned int
+#define addrlen_t unsigned int
#define SOCKET int
#define INVALID_SOCKET -1
#define closesocket close
diff --git a/SQCSim-common/netprotocol.cpp b/SQCSim-common/netprotocol.cpp
index d4edca2..68feda2 100644
--- a/SQCSim-common/netprotocol.cpp
+++ b/SQCSim-common/netprotocol.cpp
@@ -1,90 +1,237 @@
#include "netprotocol.h"
void netprot::Serialize(Input* in, char* buf[], uint32_t* buflen) {
- *buf[0] = netprot::PACKET_TYPE::INPUT;
+ *buf[0] = (char)netprot::PACKET_TYPE::INPUT;
uint64_t time = in->timestamp;
- uint8_t time8[sizeof(uint64_t)] = {(time >> 56) & 0xFF,
- (time >> 48) & 0xFF,
- (time >> 40) & 0xFF,
- (time >> 32) & 0xFF,
- (time >> 24) & 0xFF,
- (time >> 16) & 0xFF,
- (time >> 8 ) & 0xFF,
- time & 0xFF};
+ uint8_t time8[sizeof(uint64_t)] = { (uint8_t)((time >> 56) & 0xFF),
+ (uint8_t)((time >> 48) & 0xFF),
+ (uint8_t)((time >> 40) & 0xFF),
+ (uint8_t)((time >> 32) & 0xFF),
+ (uint8_t)((time >> 24) & 0xFF),
+ (uint8_t)((time >> 16) & 0xFF),
+ (uint8_t)((time >> 8) & 0xFF),
+ (uint8_t)(time & 0xFF) };
memcpy(*buf + 1, time8, sizeof(uint64_t));
uint64_t sid = in->sid;
- uint8_t sid8[sizeof(uint64_t)] = {(sid >> 56) & 0xFF,
- (sid >> 48) & 0xFF,
- (sid >> 40) & 0xFF,
- (sid >> 32) & 0xFF,
- (sid >> 24) & 0xFF,
- (sid >> 16) & 0xFF,
- (sid >> 8 ) & 0xFF,
- sid & 0xFF};
+ uint8_t sid8[sizeof(uint64_t)] = { (uint8_t)((sid >> 56) & 0xFF),
+ (uint8_t)((sid >> 48) & 0xFF),
+ (uint8_t)((sid >> 40) & 0xFF),
+ (uint8_t)((sid >> 32) & 0xFF),
+ (uint8_t)((sid >> 24) & 0xFF),
+ (uint8_t)((sid >> 16) & 0xFF),
+ (uint8_t)((sid >> 8) & 0xFF),
+ (uint8_t)(sid & 0xFF) };
memcpy(*buf + sizeof(uint64_t) + 1, sid8, sizeof(uint64_t));
Keys keys = in->keys;
uint8_t keys8 = // Reste un bit.
- keys.forward & 0b10000000 |
- keys.backward & 0b01000000 |
- keys.left & 0b00100000 |
- keys.right & 0b00010000 |
- keys.jump & 0b00001000 |
- keys.shoot & 0b00000100 |
- keys.block & 0b00000010 ;
+ (keys.forward ? 0b10000000 : 0) |
+ (keys.backward ? 0b01000000 : 0) |
+ (keys.left ? 0b00100000 : 0) |
+ (keys.right ? 0b00010000 : 0) |
+ (keys.jump ? 0b00001000 : 0) |
+ (keys.shoot ? 0b00000100 : 0) |
+ (keys.block ? 0b00000010 : 0);
- memcpy(*buf + sizeof(uint64_t) + 2, &keys8, sizeof(uint8_t));
+ memcpy(*buf + sizeof(uint64_t) * 2 + 1, &keys8, sizeof(uint8_t));
uint32_t vec[3];
- memcpy(vec, &in->direction, sizeof(Vector3f)); // Pour dénaturer les floats.
+ memcpy(vec, &in->direction, sizeof(Vector3f)); // Pour d�naturer les floats.
uint8_t vec8[3 * sizeof(uint32_t)] = {
- (vec[0] >> 24) & 0xFF,
- (vec[0] >> 16) & 0xFF,
- (vec[0] >> 8) & 0xFF,
- vec[0] & 0xFF,
- (vec[1] >> 24) & 0xFF,
- (vec[1] >> 16) & 0xFF,
- (vec[1] >> 8) & 0xFF,
- vec[1] & 0xFF,
- (vec[2] >> 24) & 0xFF,
- (vec[2] >> 16) & 0xFF,
- (vec[2] >> 8) & 0xFF,
- vec[2] & 0xFF};
+ (uint8_t)((vec[0] >> 24) & 0xFF),
+ (uint8_t)((vec[0] >> 16) & 0xFF),
+ (uint8_t)((vec[0] >> 8) & 0xFF),
+ (uint8_t)(vec[0] & 0xFF),
+ (uint8_t)((vec[1] >> 24) & 0xFF),
+ (uint8_t)((vec[1] >> 16) & 0xFF),
+ (uint8_t)((vec[1] >> 8) & 0xFF),
+ (uint8_t)(vec[1] & 0xFF),
+ (uint8_t)((vec[2] >> 24) & 0xFF),
+ (uint8_t)((vec[2] >> 16) & 0xFF),
+ (uint8_t)((vec[2] >> 8) & 0xFF),
+ (uint8_t)(vec[2] & 0xFF) };
- memcpy(*buf + sizeof(uint64_t) + 3, vec8, sizeof(uint32_t) * 3);
+ memcpy(*buf + sizeof(uint64_t) * 2 + 2, vec8, sizeof(uint32_t) * 3);
- *buflen = sizeof(uint64_t) + 3 + sizeof(uint32_t) * 3;
+ *buflen = sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 3;
}
void netprot::Serialize(Output* out, char* buf[], uint32_t* buflen) {
+ *buf[0] = (char)netprot::PACKET_TYPE::OUTPUT;
+ uint64_t time = out->timestamp;
+ uint8_t time8[sizeof(uint64_t)] = { (uint8_t)((time >> 56) & 0xFF),
+ (uint8_t)((time >> 48) & 0xFF),
+ (uint8_t)((time >> 40) & 0xFF),
+ (uint8_t)((time >> 32) & 0xFF),
+ (uint8_t)((time >> 24) & 0xFF),
+ (uint8_t)((time >> 16) & 0xFF),
+ (uint8_t)((time >> 8) & 0xFF),
+ (uint8_t)(time & 0xFF) };
+
+ memcpy(*buf + 1, time8, sizeof(uint64_t));
+
+ uint64_t sid = out->id;
+ uint8_t sid8[sizeof(uint64_t)] = { (uint8_t)((sid >> 56) & 0xFF),
+ (uint8_t)((sid >> 48) & 0xFF),
+ (uint8_t)((sid >> 40) & 0xFF),
+ (uint8_t)((sid >> 32) & 0xFF),
+ (uint8_t)((sid >> 24) & 0xFF),
+ (uint8_t)((sid >> 16) & 0xFF),
+ (uint8_t)((sid >> 8) & 0xFF),
+ (uint8_t)(sid & 0xFF) };
+
+ memcpy(*buf + sizeof(uint64_t) + 1, sid8, sizeof(uint64_t));
+
+ States states = out->states;
+ uint8_t states8 =
+ (states.jumping ? 0b10000000 : 0) |
+ (states.shooting ? 0b01000000 : 0) |
+ (states.hit ? 0b00100000 : 0) |
+ (states.powerup ? 0b00010000 : 0) |
+ (states.dead ? 0b00001000 : 0) |
+ (states.still ? 0b00000100 : 0) |
+ (states.jumpshot ? 0b00000010 : 0) |
+ (states.running ? 0b00000001 : 0);
+
+ memcpy(*buf + sizeof(uint64_t) * 2 + 1, &states8, sizeof(uint8_t));
+
+ uint32_t vec[3];
+ memcpy(vec, &out->direction, sizeof(Vector3f)); // Pour d�naturer les floats.
+
+ uint8_t vec8[3 * sizeof(uint32_t)] = {
+ (uint8_t)((vec[0] >> 24) & 0xFF),
+ (uint8_t)((vec[0] >> 16) & 0xFF),
+ (uint8_t)((vec[0] >> 8) & 0xFF),
+ (uint8_t)(vec[0] & 0xFF),
+ (uint8_t)((vec[1] >> 24) & 0xFF),
+ (uint8_t)((vec[1] >> 16) & 0xFF),
+ (uint8_t)((vec[1] >> 8) & 0xFF),
+ (uint8_t)(vec[1] & 0xFF),
+ (uint8_t)((vec[2] >> 24) & 0xFF),
+ (uint8_t)((vec[2] >> 16) & 0xFF),
+ (uint8_t)((vec[2] >> 8) & 0xFF),
+ (uint8_t)(vec[2] & 0xFF) };
+
+ memcpy(*buf + sizeof(uint64_t) * 2 + 2, vec8, sizeof(uint32_t) * 3);
+
+ memcpy(vec, &out->position, sizeof(Vector3f)); // Pour d�naturer les floats.
+
+ uint8_t vec82[3 * sizeof(uint32_t)] = {
+ (uint8_t)((vec[0] >> 24) & 0xFF),
+ (uint8_t)((vec[0] >> 16) & 0xFF),
+ (uint8_t)((vec[0] >> 8) & 0xFF),
+ (uint8_t)(vec[0] & 0xFF),
+ (uint8_t)((vec[1] >> 24) & 0xFF),
+ (uint8_t)((vec[1] >> 16) & 0xFF),
+ (uint8_t)((vec[1] >> 8) & 0xFF),
+ (uint8_t)(vec[1] & 0xFF),
+ (uint8_t)((vec[2] >> 24) & 0xFF),
+ (uint8_t)((vec[2] >> 16) & 0xFF),
+ (uint8_t)((vec[2] >> 8) & 0xFF),
+ (uint8_t)(vec[2] & 0xFF) };
+
+ memcpy(*buf + sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 3, vec82, sizeof(uint32_t) * 3);
+
+ *buflen = sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 6;
}
void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
-
+ *buf[0] = (char)netprot::PACKET_TYPE::SYNC;
+ uint64_t time = sync->timestamp;
+ uint8_t stamp8[sizeof(uint64_t)] = { (uint8_t)((time >> 56) & 0xFF),
+ (uint8_t)((time >> 48) & 0xFF),
+ (uint8_t)((time >> 40) & 0xFF),
+ (uint8_t)((time >> 32) & 0xFF),
+ (uint8_t)((time >> 24) & 0xFF),
+ (uint8_t)((time >> 16) & 0xFF),
+ (uint8_t)((time >> 8) & 0xFF),
+ (uint8_t)(time & 0xFF) };
+
+ memcpy(*buf + 1, stamp8, sizeof(uint64_t));
+
+ uint64_t sid = sync->sid;
+ uint8_t sid8[sizeof(uint64_t)] = { (uint8_t)((sid >> 56) & 0xFF),
+ (uint8_t)((sid >> 48) & 0xFF),
+ (uint8_t)((sid >> 40) & 0xFF),
+ (uint8_t)((sid >> 32) & 0xFF),
+ (uint8_t)((sid >> 24) & 0xFF),
+ (uint8_t)((sid >> 16) & 0xFF),
+ (uint8_t)((sid >> 8) & 0xFF),
+ (uint8_t)(sid & 0xFF) };
+
+ memcpy(*buf + sizeof(uint64_t) + 1, sid8, sizeof(uint64_t));
+
+ uint32_t timer = sync->timer;
+ uint8_t time8[sizeof(uint32_t)] = { (uint8_t)((timer >> 24) & 0xFF),
+ (uint8_t)((timer >> 16) & 0xFF),
+ (uint8_t)((timer >> 8) & 0xFF),
+ (uint8_t)(timer & 0xFF) };
+
+ memcpy(*buf + sizeof(uint64_t) * 2 + 1, time8, sizeof(uint32_t));
+
+ uint16_t ammo = sync->ammo;
+ uint8_t ammo8[sizeof(uint16_t)] = { (uint8_t)((ammo >> 8) & 0xFF),
+ (uint8_t)(ammo & 0xFF) };
+
+ memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + 1, ammo8, sizeof(uint16_t));
+
+ uint32_t vec[3];
+ memcpy(vec, &sync->position, sizeof(Vector3f)); // Pour d�naturer les floats.
+
+ uint8_t vec8[3 * sizeof(uint32_t)] = {
+ (uint8_t)((vec[0] >> 24) & 0xFF),
+ (uint8_t)((vec[0] >> 16) & 0xFF),
+ (uint8_t)((vec[0] >> 8) & 0xFF),
+ (uint8_t)(vec[0] & 0xFF),
+ (uint8_t)((vec[1] >> 24) & 0xFF),
+ (uint8_t)((vec[1] >> 16) & 0xFF),
+ (uint8_t)((vec[1] >> 8) & 0xFF),
+ (uint8_t)(vec[1] & 0xFF),
+ (uint8_t)((vec[2] >> 24) & 0xFF),
+ (uint8_t)((vec[2] >> 16) & 0xFF),
+ (uint8_t)((vec[2] >> 8) & 0xFF),
+ (uint8_t)(vec[2] & 0xFF) };
+
+ memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t) + 1, vec8, sizeof(uint32_t) * 3);
+
+ 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) };
+
+ memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + 1, hp8, sizeof(float));
+
+ *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) {
- *buf[0] = netprot::PACKET_TYPE::TEAMINF;
+ *buf[0] = (char)netprot::PACKET_TYPE::TEAMINF;
size_t namesize = std::strlen(tinfo->name) + 1;
- memcpy(*buf + 1, &tinfo->name, namesize);
+ strcpy(*buf + 1, namesize, tinfo->name);
+
uint64_t tid = tinfo->id;
uint8_t tid8[sizeof(uint64_t)] = {
- (tid >> 56) & 0xFF,
- (tid >> 48) & 0xFF,
- (tid >> 40) & 0xFF,
- (tid >> 32) & 0xFF,
- (tid >> 24) & 0xFF,
- (tid >> 16) & 0xFF,
- (tid >> 8) & 0xFF,
- tid & 0xFF
+ (uint8_t)((tid >> 56) & 0xFF),
+ (uint8_t)((tid >> 48) & 0xFF),
+ (uint8_t)((tid >> 40) & 0xFF),
+ (uint8_t)((tid >> 32) & 0xFF),
+ (uint8_t)((tid >> 24) & 0xFF),
+ (uint8_t)((tid >> 16) & 0xFF),
+ (uint8_t)((tid >> 8) & 0xFF),
+ (uint8_t)(tid & 0xFF)
};
memcpy(*buf + namesize + 2, tid8, sizeof(uint64_t));
@@ -93,35 +240,36 @@ void netprot::Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen) {
}
void netprot::Serialize(LoginInfo* linfo, char* buf[], uint32_t* buflen) {
- *buf[0] = netprot::PACKET_TYPE::LOGINF;
+ *buf[0] = (char)netprot::PACKET_TYPE::LOGINF;
size_t namesize = std::strlen(linfo->name) + 1;
-
- memcpy(*buf + 1, &linfo->name, namesize);
+
+ strcpy(*buf + 1, namesize, linfo->name);
+
uint64_t sid = linfo->sid;
- uint8_t sid8[sizeof(uint64_t)] = {
- (sid >> 56) & 0xFF,
- (sid >> 48) & 0xFF,
- (sid >> 40) & 0xFF,
- (sid >> 32) & 0xFF,
- (sid >> 24) & 0xFF,
- (sid >> 16) & 0xFF,
- (sid >> 8) & 0xFF,
- sid & 0xFF
+ uint8_t sid8[sizeof(uint64_t)] = {
+ (uint8_t)((sid >> 56) & 0xFF),
+ (uint8_t)((sid >> 48) & 0xFF),
+ (uint8_t)((sid >> 40) & 0xFF),
+ (uint8_t)((sid >> 32) & 0xFF),
+ (uint8_t)((sid >> 24) & 0xFF),
+ (uint8_t)((sid >> 16) & 0xFF),
+ (uint8_t)((sid >> 8) & 0xFF),
+ (uint8_t)(sid & 0xFF)
};
memcpy(*buf + namesize + 2, sid8, sizeof(uint64_t));
uint64_t tid = linfo->tid;
uint8_t tid8[sizeof(uint64_t)] = {
- (tid >> 56) & 0xFF,
- (tid >> 48) & 0xFF,
- (tid >> 40) & 0xFF,
- (tid >> 32) & 0xFF,
- (tid >> 24) & 0xFF,
- (tid >> 16) & 0xFF,
- (tid >> 8) & 0xFF,
- tid & 0xFF
+ (uint8_t)((tid >> 56) & 0xFF),
+ (uint8_t)((tid >> 48) & 0xFF),
+ (uint8_t)((tid >> 40) & 0xFF),
+ (uint8_t)((tid >> 32) & 0xFF),
+ (uint8_t)((tid >> 24) & 0xFF),
+ (uint8_t)((tid >> 16) & 0xFF),
+ (uint8_t)((tid >> 8) & 0xFF),
+ (uint8_t)(tid & 0xFF)
};
memcpy(*buf + namesize + 2 + sizeof(uint64_t), tid8, sizeof(uint64_t));
@@ -130,35 +278,36 @@ void netprot::Serialize(LoginInfo* linfo, char* buf[], uint32_t* buflen) {
}
void netprot::Serialize(PlayerInfo* pinfo, char* buf[], uint32_t* buflen) {
- *buf[0] = netprot::PACKET_TYPE::PLAYINF;
+ *buf[0] = (char)netprot::PACKET_TYPE::PLAYINF;
size_t namesize = std::strlen(pinfo->name) + 1;
- memcpy(*buf + 1, &pinfo->name, namesize);
+ strcpy(*buf + 1, namesize, pinfo->name);
+
uint64_t id = pinfo->id;
uint8_t id8[sizeof(uint64_t)] = {
- (id >> 56) & 0xFF,
- (id >> 48) & 0xFF,
- (id >> 40) & 0xFF,
- (id >> 32) & 0xFF,
- (id >> 24) & 0xFF,
- (id >> 16) & 0xFF,
- (id >> 8) & 0xFF,
- id & 0xFF
+ (uint8_t)((id >> 56) & 0xFF),
+ (uint8_t)((id >> 48) & 0xFF),
+ (uint8_t)((id >> 40) & 0xFF),
+ (uint8_t)((id >> 32) & 0xFF),
+ (uint8_t)((id >> 24) & 0xFF),
+ (uint8_t)((id >> 16) & 0xFF),
+ (uint8_t)((id >> 8) & 0xFF),
+ (uint8_t)(id & 0xFF)
};
memcpy(*buf + namesize + 2, id8, sizeof(uint64_t));
uint64_t tid = pinfo->tid;
uint8_t tid8[sizeof(uint64_t)] = {
- (tid >> 56) & 0xFF,
- (tid >> 48) & 0xFF,
- (tid >> 40) & 0xFF,
- (tid >> 32) & 0xFF,
- (tid >> 24) & 0xFF,
- (tid >> 16) & 0xFF,
- (tid >> 8) & 0xFF,
- tid & 0xFF
+ (uint8_t)((tid >> 56) & 0xFF),
+ (uint8_t)((tid >> 48) & 0xFF),
+ (uint8_t)((tid >> 40) & 0xFF),
+ (uint8_t)((tid >> 32) & 0xFF),
+ (uint8_t)((tid >> 24) & 0xFF),
+ (uint8_t)((tid >> 16) & 0xFF),
+ (uint8_t)((tid >> 8) & 0xFF),
+ (uint8_t)(tid & 0xFF)
};
memcpy(*buf + namesize + 2 + sizeof(uint64_t), tid8, sizeof(uint64_t));
@@ -167,46 +316,46 @@ void netprot::Serialize(PlayerInfo* pinfo, char* buf[], uint32_t* buflen) {
}
void netprot::Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen) {
- *buf[0] = netprot::PACKET_TYPE::GAMEINFO;
+ *buf[0] = (char)netprot::PACKET_TYPE::GAMEINFO;
uint64_t game = ginfo->seed;
uint8_t seed8[sizeof(uint64_t)] = {
- (game >> 56) & 0xFF,
- (game >> 48) & 0xFF,
- (game >> 40) & 0xFF,
- (game >> 32) & 0xFF,
- (game >> 24) & 0xFF,
- (game >> 16) & 0xFF,
- (game >> 8) & 0xFF,
- game & 0xFF
+ (uint8_t)((game >> 56) & 0xFF),
+ (uint8_t)((game >> 48) & 0xFF),
+ (uint8_t)((game >> 40) & 0xFF),
+ (uint8_t)((game >> 32) & 0xFF),
+ (uint8_t)((game >> 24) & 0xFF),
+ (uint8_t)((game >> 16) & 0xFF),
+ (uint8_t)((game >> 8) & 0xFF),
+ (uint8_t)(game & 0xFF)
};
memcpy(*buf + 1, seed8, sizeof(uint64_t));
game = ginfo->countdown;
uint8_t count8[sizeof(uint64_t)] = {
- (game >> 56) & 0xFF,
- (game >> 48) & 0xFF,
- (game >> 40) & 0xFF,
- (game >> 32) & 0xFF,
- (game >> 24) & 0xFF,
- (game >> 16) & 0xFF,
- (game >> 8) & 0xFF,
- game & 0xFF
+ (uint8_t)((game >> 56) & 0xFF),
+ (uint8_t)((game >> 48) & 0xFF),
+ (uint8_t)((game >> 40) & 0xFF),
+ (uint8_t)((game >> 32) & 0xFF),
+ (uint8_t)((game >> 24) & 0xFF),
+ (uint8_t)((game >> 16) & 0xFF),
+ (uint8_t)((game >> 8) & 0xFF),
+ (uint8_t)(game & 0xFF)
};
memcpy(*buf + sizeof(uint64_t) + 1, count8, sizeof(uint64_t));
game = ginfo->countdown;
uint8_t gtype8[sizeof(uint64_t)] = {
- (game >> 56) & 0xFF,
- (game >> 48) & 0xFF,
- (game >> 40) & 0xFF,
- (game >> 32) & 0xFF,
- (game >> 24) & 0xFF,
- (game >> 16) & 0xFF,
- (game >> 8) & 0xFF,
- game & 0xFF
+ (uint8_t)((game >> 56) & 0xFF),
+ (uint8_t)((game >> 48) & 0xFF),
+ (uint8_t)((game >> 40) & 0xFF),
+ (uint8_t)((game >> 32) & 0xFF),
+ (uint8_t)((game >> 24) & 0xFF),
+ (uint8_t)((game >> 16) & 0xFF),
+ (uint8_t)((game >> 8) & 0xFF),
+ (uint8_t)(game & 0xFF)
};
memcpy(*buf + sizeof(uint64_t) + 1, gtype8, sizeof(uint64_t));
@@ -215,59 +364,158 @@ void netprot::Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen) {
}
void netprot::Serialize(Chat* chat, char* buf[], uint32_t* buflen) {
- *buf[0] = netprot::PACKET_TYPE::CHAT;
+ *buf[0] = (char)netprot::PACKET_TYPE::CHAT;
uint64_t src = chat->src_id;
uint8_t src8[sizeof(uint64_t)] = {
- (src >> 56) & 0xFF,
- (src >> 48) & 0xFF,
- (src >> 40) & 0xFF,
- (src >> 32) & 0xFF,
- (src >> 24) & 0xFF,
- (src >> 16) & 0xFF,
- (src >> 8) & 0xFF,
- src & 0xFF
+ (uint8_t)((src >> 56) & 0xFF),
+ (uint8_t)((src >> 48) & 0xFF),
+ (uint8_t)((src >> 40) & 0xFF),
+ (uint8_t)((src >> 32) & 0xFF),
+ (uint8_t)((src >> 24) & 0xFF),
+ (uint8_t)((src >> 16) & 0xFF),
+ (uint8_t)((src >> 8) & 0xFF),
+ (uint8_t)(src & 0xFF)
};
memcpy(*buf + 1, src8, sizeof(uint64_t));
uint64_t dst = chat->dest_id;
uint8_t dst8[sizeof(uint64_t)] = {
- (dst >> 56) & 0xFF,
- (dst >> 48) & 0xFF,
- (dst >> 40) & 0xFF,
- (dst >> 32) & 0xFF,
- (dst >> 24) & 0xFF,
- (dst >> 16) & 0xFF,
- (dst >> 8) & 0xFF,
- dst & 0xFF
+ (uint8_t)((dst >> 56) & 0xFF),
+ (uint8_t)((dst >> 48) & 0xFF),
+ (uint8_t)((dst >> 40) & 0xFF),
+ (uint8_t)((dst >> 32) & 0xFF),
+ (uint8_t)((dst >> 24) & 0xFF),
+ (uint8_t)((dst >> 16) & 0xFF),
+ (uint8_t)((dst >> 8) & 0xFF),
+ (uint8_t)(dst & 0xFF)
};
memcpy(*buf + 1 + sizeof(uint64_t), dst8, sizeof(uint64_t));
uint64_t dstteam = chat->dest_id;
uint8_t dstt8[sizeof(uint64_t)] = {
- (dstteam >> 56) & 0xFF,
- (dstteam >> 48) & 0xFF,
- (dstteam >> 40) & 0xFF,
- (dstteam >> 32) & 0xFF,
- (dstteam >> 24) & 0xFF,
- (dstteam >> 16) & 0xFF,
- (dstteam >> 8) & 0xFF,
- dstteam & 0xFF
+ (uint8_t)((dstteam >> 56) & 0xFF),
+ (uint8_t)((dstteam >> 48) & 0xFF),
+ (uint8_t)((dstteam >> 40) & 0xFF),
+ (uint8_t)((dstteam >> 32) & 0xFF),
+ (uint8_t)((dstteam >> 24) & 0xFF),
+ (uint8_t)((dstteam >> 16) & 0xFF),
+ (uint8_t)((dstteam >> 8) & 0xFF),
+ (uint8_t)(dstteam & 0xFF)
};
-
+
memcpy(*buf + 1 + sizeof(uint64_t) * 2, dstt8, sizeof(uint64_t));
size_t messize = std::strlen(chat->mess) + 1;
- memcpy(*buf + 1 + sizeof(uint64_t) * 3, &chat->mess, messize);
+ strcpy(*buf + 1 + sizeof(uint64_t) * 3, messize, chat->mess);
*buflen = messize + sizeof(uint64_t) * 3 + 2;
}
+void netprot::Serialize(ChunkMod* chmod, char* buf[], uint32_t* buflen) {
+ *buf[0] = (char)netprot::PACKET_TYPE::CHUNKMOD;
+
+ uint32_t vec[3];
+ memcpy(vec, &chmod->pos, sizeof(Vector3f)); // Pour d�naturer les floats.
+
+ uint8_t vec8[3 * sizeof(uint32_t)] = {
+ (uint8_t)((vec[0] >> 24) & 0xFF),
+ (uint8_t)((vec[0] >> 16) & 0xFF),
+ (uint8_t)((vec[0] >> 8) & 0xFF),
+ (uint8_t)(vec[0] & 0xFF),
+ (uint8_t)((vec[1] >> 24) & 0xFF),
+ (uint8_t)((vec[1] >> 16) & 0xFF),
+ (uint8_t)((vec[1] >> 8) & 0xFF),
+ (uint8_t)(vec[1] & 0xFF),
+ (uint8_t)((vec[2] >> 24) & 0xFF),
+ (uint8_t)((vec[2] >> 16) & 0xFF),
+ (uint8_t)((vec[2] >> 8) & 0xFF),
+ (uint8_t)(vec[2] & 0xFF) };
+
+ memcpy(*buf + 1, vec8, sizeof(uint32_t) * 3);
+
+ memcpy(*buf + sizeof(uint32_t) * 3 + 1, &chmod->b_type, sizeof(BlockType));
+ memcpy(*buf + sizeof(uint32_t) * 3 + 2, &chmod->old_b_type, sizeof(BlockType));
+
+ *buflen = sizeof(uint32_t) * 3 + 3;
+}
+
+void netprot::Serialize(BulletAdd* bull, char* buf[], uint32_t* buflen) {
+ *buf[0] = (char)netprot::PACKET_TYPE::BULLET;
+
+ uint64_t tstamp = bull->tstamp;
+ uint8_t ts8[sizeof(uint64_t)] = {
+ (uint8_t)((tstamp >> 56) & 0xFF),
+ (uint8_t)((tstamp >> 48) & 0xFF),
+ (uint8_t)((tstamp >> 40) & 0xFF),
+ (uint8_t)((tstamp >> 32) & 0xFF),
+ (uint8_t)((tstamp >> 24) & 0xFF),
+ (uint8_t)((tstamp >> 16) & 0xFF),
+ (uint8_t)((tstamp >> 8) & 0xFF),
+ (uint8_t)(tstamp & 0xFF)
+ };
+
+ memcpy(*buf + 1, ts8, sizeof(uint64_t));
+
+ uint64_t tid = bull->id;
+ uint8_t tid8[sizeof(uint64_t)] = {
+ (uint8_t)((tid >> 56) & 0xFF),
+ (uint8_t)((tid >> 48) & 0xFF),
+ (uint8_t)((tid >> 40) & 0xFF),
+ (uint8_t)((tid >> 32) & 0xFF),
+ (uint8_t)((tid >> 24) & 0xFF),
+ (uint8_t)((tid >> 16) & 0xFF),
+ (uint8_t)((tid >> 8) & 0xFF),
+ (uint8_t)(tid & 0xFF)
+ };
+
+ memcpy(*buf + 1 + sizeof(uint64_t), tid8, sizeof(uint64_t));
+
+ uint32_t vec[3];
+ memcpy(vec, &bull->pos, sizeof(Vector3f)); // Pour d�naturer les floats.
+
+ uint8_t vec8[3 * sizeof(uint32_t)] = {
+ (uint8_t)((vec[0] >> 24) & 0xFF),
+ (uint8_t)((vec[0] >> 16) & 0xFF),
+ (uint8_t)((vec[0] >> 8) & 0xFF),
+ (uint8_t)(vec[0] & 0xFF),
+ (uint8_t)((vec[1] >> 24) & 0xFF),
+ (uint8_t)((vec[1] >> 16) & 0xFF),
+ (uint8_t)((vec[1] >> 8) & 0xFF),
+ (uint8_t)(vec[1] & 0xFF),
+ (uint8_t)((vec[2] >> 24) & 0xFF),
+ (uint8_t)((vec[2] >> 16) & 0xFF),
+ (uint8_t)((vec[2] >> 8) & 0xFF),
+ (uint8_t)(vec[2] & 0xFF) };
+
+ memcpy(*buf + 1 + sizeof(uint64_t) * 2, vec8, sizeof(uint32_t) * 3);
+
+ memcpy(vec, &bull->dir, sizeof(Vector3f)); // Pour d�naturer les floats.
+
+ uint8_t dir8[3 * sizeof(uint32_t)] = {
+ (uint8_t)((vec[0] >> 24) & 0xFF),
+ (uint8_t)((vec[0] >> 16) & 0xFF),
+ (uint8_t)((vec[0] >> 8) & 0xFF),
+ (uint8_t)(vec[0] & 0xFF),
+ (uint8_t)((vec[1] >> 24) & 0xFF),
+ (uint8_t)((vec[1] >> 16) & 0xFF),
+ (uint8_t)((vec[1] >> 8) & 0xFF),
+ (uint8_t)(vec[1] & 0xFF),
+ (uint8_t)((vec[2] >> 24) & 0xFF),
+ (uint8_t)((vec[2] >> 16) & 0xFF),
+ (uint8_t)((vec[2] >> 8) & 0xFF),
+ (uint8_t)(vec[2] & 0xFF) };
+
+ memcpy(*buf + 1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 3, dir8, sizeof(uint32_t) * 3);
+
+ *buflen = 1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 6;
+}
+
void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) {
- *buf[0] = netprot::PACKET_TYPE::ERRLOG;
+ *buf[0] = (char)netprot::PACKET_TYPE::ERRLOG;
size_t messize = std::strlen(errlog->mess) + 1;
@@ -280,20 +528,221 @@ void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) {
-bool netprot::Deserialize(Input* in, char* buf, const uint32_t buflen) {
- return false;
+bool netprot::Deserialize(Input* in, char* buf, uint32_t* buflen) {
+ if (*buflen <= sizeof(Input))
+ return false;
+
+ uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
+ memcpy(diff, &buf[1], sizeof(uint64_t));
+ in->timestamp =
+ (uint64_t)diff[0] << 56 |
+ (uint64_t)diff[1] << 48 |
+ (uint64_t)diff[2] << 40 |
+ (uint64_t)diff[3] << 32 |
+ (uint64_t)diff[4] << 24 |
+ (uint64_t)diff[5] << 16 |
+ (uint64_t)diff[6] << 8 |
+ (uint64_t)diff[7];
+
+ memcpy(diff, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t));
+ in->sid =
+ (uint64_t)diff[0] << 56 |
+ (uint64_t)diff[1] << 48 |
+ (uint64_t)diff[2] << 40 |
+ (uint64_t)diff[3] << 32 |
+ (uint64_t)diff[4] << 24 |
+ (uint64_t)diff[5] << 16 |
+ (uint64_t)diff[6] << 8 |
+ (uint64_t)diff[7];
+
+ uint8_t keys = 0;
+ memcpy(&keys, &buf[1 + sizeof(uint64_t) * 2], sizeof(uint8_t));
+ in->keys.forward = keys & 0b10000000;
+ in->keys.backward = keys & 0b01000000;
+ in->keys.left = keys & 0b00100000;
+ in->keys.right = keys & 0b00010000;
+ in->keys.jump = keys & 0b00001000;
+ in->keys.shoot = keys & 0b00000100;
+ in->keys.block = keys & 0b00000010;
+
+ 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(uint8_t) * 12);
+ uint32_t vec[3] = {
+ (uint32_t)subvec[0] << 24 |
+ (uint32_t)subvec[1] << 16 |
+ (uint32_t)subvec[2] << 8 |
+ (uint32_t)subvec[3],
+ (uint32_t)subvec[4] << 24 |
+ (uint32_t)subvec[5] << 16 |
+ (uint32_t)subvec[6] << 8 |
+ (uint32_t)subvec[7],
+ (uint32_t)subvec[8] << 24 |
+ (uint32_t)subvec[9] << 16 |
+ (uint32_t)subvec[10] << 8 |
+ (uint32_t)subvec[11] };
+
+ memcpy(&in->direction, vec, sizeof(uint32_t) * 3);
+
+ *buflen = sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 3;
+
+ return true;
}
-bool netprot::Deserialize(Output* out, char* buf, const uint32_t buflen) {
- return false;
+bool netprot::Deserialize(Output* out, char* buf, uint32_t* buflen) {
+ if (*buflen <= sizeof(Output))
+ return false;
+
+ uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
+ memcpy(diff, &buf[1], sizeof(uint64_t));
+ out->timestamp =
+ (uint64_t)diff[0] << 56 |
+ (uint64_t)diff[1] << 48 |
+ (uint64_t)diff[2] << 40 |
+ (uint64_t)diff[3] << 32 |
+ (uint64_t)diff[4] << 24 |
+ (uint64_t)diff[5] << 16 |
+ (uint64_t)diff[6] << 8 |
+ (uint64_t)diff[7];
+
+ memcpy(diff, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t));
+ out->id =
+ (uint64_t)diff[0] << 56 |
+ (uint64_t)diff[1] << 48 |
+ (uint64_t)diff[2] << 40 |
+ (uint64_t)diff[3] << 32 |
+ (uint64_t)diff[4] << 24 |
+ (uint64_t)diff[5] << 16 |
+ (uint64_t)diff[6] << 8 |
+ (uint64_t)diff[7];
+
+ uint8_t states = 0;
+ memcpy(&states, &buf[1 + sizeof(uint64_t) * 2], sizeof(uint8_t));
+ out->states.jumping = states & 0b10000000;
+ out->states.shooting = states & 0b01000000;
+ out->states.hit = states & 0b00100000;
+ out->states.powerup = states & 0b00010000;
+ out->states.dead = states & 0b00001000;
+ out->states.still = states & 0b00000100;
+ out->states.jumpshot = states & 0b00000010;
+ out->states.running = states & 0b00000001;
+
+
+ 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(uint8_t) * 12);
+ uint32_t vec[3] = {
+ (uint32_t)subvec[0] << 24 |
+ (uint32_t)subvec[1] << 16 |
+ (uint32_t)subvec[2] << 8 |
+ (uint32_t)subvec[3],
+ (uint32_t)subvec[4] << 24 |
+ (uint32_t)subvec[5] << 16 |
+ (uint32_t)subvec[6] << 8 |
+ (uint32_t)subvec[7],
+ (uint32_t)subvec[8] << 24 |
+ (uint32_t)subvec[9] << 16 |
+ (uint32_t)subvec[10] << 8 |
+ (uint32_t)subvec[11] };
+
+ memcpy(&out->direction, vec, sizeof(uint32_t) * 3);
+
+ memcpy(subvec, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 3], sizeof(uint8_t) * 12);
+ uint32_t vec2[3] = {
+ (uint32_t)subvec[0] << 24 |
+ (uint32_t)subvec[1] << 16 |
+ (uint32_t)subvec[2] << 8 |
+ (uint32_t)subvec[3],
+ (uint32_t)subvec[4] << 24 |
+ (uint32_t)subvec[5] << 16 |
+ (uint32_t)subvec[6] << 8 |
+ (uint32_t)subvec[7],
+ (uint32_t)subvec[8] << 24 |
+ (uint32_t)subvec[9] << 16 |
+ (uint32_t)subvec[10] << 8 |
+ (uint32_t)subvec[11] };
+
+ memcpy(&out->position, vec2, sizeof(uint32_t) * 3);
+
+ *buflen = sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 6;
+
+ return true;
}
-bool netprot::Deserialize(Sync* sync, char* buf, const uint32_t buflen) {
- return false;
+bool netprot::Deserialize(Sync* sync, char* buf, uint32_t* buflen) {
+ if (*buflen <= sizeof(Sync))
+ return false;
+
+ uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
+ memcpy(diff, &buf[1], sizeof(uint64_t));
+ sync->timestamp =
+ (uint64_t)diff[0] << 56 |
+ (uint64_t)diff[1] << 48 |
+ (uint64_t)diff[2] << 40 |
+ (uint64_t)diff[3] << 32 |
+ (uint64_t)diff[4] << 24 |
+ (uint64_t)diff[5] << 16 |
+ (uint64_t)diff[6] << 8 |
+ (uint64_t)diff[7];
+
+ memcpy(diff, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t));
+ sync->sid =
+ (uint64_t)diff[0] << 56 |
+ (uint64_t)diff[1] << 48 |
+ (uint64_t)diff[2] << 40 |
+ (uint64_t)diff[3] << 32 |
+ (uint64_t)diff[4] << 24 |
+ (uint64_t)diff[5] << 16 |
+ (uint64_t)diff[6] << 8 |
+ (uint64_t)diff[7];
+
+ memcpy(diff, &buf[1 + sizeof(uint64_t) * 2], sizeof(uint32_t));
+ sync->timer =
+ (uint32_t)diff[0] << 24 |
+ (uint32_t)diff[1] << 16 |
+ (uint32_t)diff[2] << 8 |
+ (uint32_t)diff[3];
+
+ memcpy(diff, &buf[1 + sizeof(uint64_t) * 2 + sizeof(uint32_t)], sizeof(uint16_t));
+ sync->ammo =
+ (uint16_t)diff[0] << 8 |
+ (uint16_t)diff[1];
+
+
+ uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
+ memcpy(subvec, &buf[1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t)], sizeof(uint8_t) * 12);
+ uint32_t vec[3] = {
+ (uint32_t)subvec[0] << 24 |
+ (uint32_t)subvec[1] << 16 |
+ (uint32_t)subvec[2] << 8 |
+ (uint32_t)subvec[3],
+ (uint32_t)subvec[4] << 24 |
+ (uint32_t)subvec[5] << 16 |
+ (uint32_t)subvec[6] << 8 |
+ (uint32_t)subvec[7],
+ (uint32_t)subvec[8] << 24 |
+ (uint32_t)subvec[9] << 16 |
+ (uint32_t)subvec[10] << 8 |
+ (uint32_t)subvec[11] };
+
+ memcpy(&sync->position, vec, sizeof(uint32_t) * 3);
+
+ uint8_t hp8[4];
+
+ memcpy(&hp8, &buf[1 + 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 = 1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float);
+
+ return true;
}
-bool netprot::Deserialize(TeamInfo* tinfo, char* buf, const uint32_t buflen) {
- if (buflen <= sizeof(LoginInfo))
+bool netprot::Deserialize(TeamInfo* tinfo, char* buf, uint32_t* buflen) {
+ if (*buflen <= sizeof(LoginInfo))
return false;
size_t namesize = std::strlen(buf) + 1;
@@ -301,7 +750,7 @@ bool netprot::Deserialize(TeamInfo* tinfo, char* buf, const uint32_t buflen) {
if (namesize > 32)
return false;
- memcpy(&tinfo->name, &buf[1], namesize);
+ strcpy(tinfo->name, namesize, &buf[1]);
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
memcpy(diff, &buf[namesize + 1], sizeof(uint64_t));
@@ -315,11 +764,13 @@ bool netprot::Deserialize(TeamInfo* tinfo, char* buf, const uint32_t buflen) {
(uint64_t)diff[6] << 8 |
(uint64_t)diff[7];
+ *buflen = namesize + sizeof(uint64_t) + 2;
+
return true;
}
-bool netprot::Deserialize(LoginInfo* linfo, char* buf, const uint32_t buflen) {
- if (buflen <= sizeof(LoginInfo))
+bool netprot::Deserialize(LoginInfo* linfo, char* buf, uint32_t* buflen) {
+ if (*buflen <= sizeof(LoginInfo))
return false;
size_t namesize = std::strlen(buf) + 1;
@@ -327,7 +778,7 @@ bool netprot::Deserialize(LoginInfo* linfo, char* buf, const uint32_t buflen) {
if (namesize > 32)
return false;
- memcpy(&linfo->name, &buf[1], namesize);
+ strcpy(linfo->name, namesize, &buf[1]);
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
memcpy(diff, &buf[namesize + 1], sizeof(uint64_t));
@@ -352,11 +803,13 @@ bool netprot::Deserialize(LoginInfo* linfo, char* buf, const uint32_t buflen) {
(uint64_t)diff[6] << 8 |
(uint64_t)diff[7];
+ *buflen = namesize + sizeof(uint64_t) * 2 + 2;
+
return true;
}
-bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, const uint32_t buflen) {
- if (buflen <= sizeof(PlayerInfo))
+bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, uint32_t* buflen) {
+ if (*buflen <= sizeof(PlayerInfo))
return false;
size_t namesize = std::strlen(buf) + 1;
@@ -364,7 +817,7 @@ bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, const uint32_t buflen) {
if (namesize > 32)
return false;
- memcpy(&pinfo->name, &buf[1], namesize);
+ strcpy(pinfo->name, namesize, &buf[1]);
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
memcpy(diff, &buf[namesize + 1], sizeof(uint64_t));
@@ -389,11 +842,13 @@ bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, const uint32_t buflen) {
(uint64_t)diff[6] << 8 |
(uint64_t)diff[7];
+ *buflen = namesize + sizeof(uint64_t) * 2 + 2;
+
return true;
}
-bool netprot::Deserialize(GameInfo* ginfo, char* buf, const uint32_t buflen) {
- if (buflen <= sizeof(GameInfo))
+bool netprot::Deserialize(GameInfo* ginfo, char* buf, uint32_t* buflen) {
+ if (*buflen <= sizeof(GameInfo))
return false;
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
@@ -430,11 +885,13 @@ bool netprot::Deserialize(GameInfo* ginfo, char* buf, const uint32_t buflen) {
(uint64_t)diff[6] << 8 |
(uint64_t)diff[7];
+ *buflen = sizeof(uint64_t) * 3 + 1;
+
return true;
}
-bool netprot::Deserialize(Chat* chat, char* buf, const uint32_t buflen) {
- if (buflen <= sizeof(Chat))
+bool netprot::Deserialize(Chat* chat, char* buf, uint32_t* buflen) {
+ if (*buflen <= sizeof(Chat))
return false;
uint8_t src[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
@@ -473,17 +930,120 @@ bool netprot::Deserialize(Chat* chat, char* buf, const uint32_t buflen) {
(uint64_t)dstt[6] << 8 |
(uint64_t)dstt[7];
- size_t messsize = std::strlen(buf + sizeof(uint64_t) * 3) + 1;
+ size_t messsize = std::strlen(&buf[sizeof(uint64_t) * 3]) + 1;
if (messsize > 140)
return false;
- memcpy(&chat->mess, &buf[1 + sizeof(uint64_t) * 3], messsize);
+ char* ciboire = &buf[1 + sizeof(uint64_t) * 3];
+
+ strcpy(chat->mess, 140, ciboire);
+
+ //*buflen = messsize + sizeof(uint64_t) * 3 + 1;
+
return true;
}
-bool netprot::Deserialize(ErrorLog* errlog, char* buf, const uint32_t buflen) {
- if (buflen <= sizeof(ErrorLog))
+bool netprot::Deserialize(ChunkMod* chmod, char* buf, uint32_t* buflen) {
+ if (*buflen <= sizeof(ChunkMod))
+ return false;
+
+ uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
+ memcpy(subvec, &buf[1], sizeof(uint8_t) * 12);
+ uint32_t vec[3] = {
+ (uint32_t)subvec[0] << 24 |
+ (uint32_t)subvec[1] << 16 |
+ (uint32_t)subvec[2] << 8 |
+ (uint32_t)subvec[3],
+ (uint32_t)subvec[4] << 24 |
+ (uint32_t)subvec[5] << 16 |
+ (uint32_t)subvec[6] << 8 |
+ (uint32_t)subvec[7],
+ (uint32_t)subvec[8] << 24 |
+ (uint32_t)subvec[9] << 16 |
+ (uint32_t)subvec[10] << 8 |
+ (uint32_t)subvec[11] };
+
+ memcpy(&chmod->pos, vec, sizeof(uint32_t) * 3);
+
+ memcpy(&chmod->b_type, &buf[1 + sizeof(uint8_t) * 12], sizeof(BlockType));
+ memcpy(&chmod->old_b_type, &buf[2 + sizeof(uint8_t) * 12], sizeof(BlockType));
+
+ *buflen = sizeof(uint32_t) * 3 + 3;
+
+ return true;
+}
+
+bool netprot::Deserialize(BulletAdd* bull, char* buf, uint32_t* buflen) {
+ if (*buflen <= sizeof(BulletAdd))
+ return false;
+
+ uint8_t tst[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
+ memcpy(tst, &buf[1], sizeof(uint64_t));
+ bull->tstamp =
+ (uint64_t)tst[0] << 56 |
+ (uint64_t)tst[1] << 48 |
+ (uint64_t)tst[2] << 40 |
+ (uint64_t)tst[3] << 32 |
+ (uint64_t)tst[4] << 24 |
+ (uint64_t)tst[5] << 16 |
+ (uint64_t)tst[6] << 8 |
+ (uint64_t)tst[7];
+
+ memcpy(tst, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t));
+ bull->id =
+ (uint64_t)tst[0] << 56 |
+ (uint64_t)tst[1] << 48 |
+ (uint64_t)tst[2] << 40 |
+ (uint64_t)tst[3] << 32 |
+ (uint64_t)tst[4] << 24 |
+ (uint64_t)tst[5] << 16 |
+ (uint64_t)tst[6] << 8 |
+ (uint64_t)tst[7];
+
+ uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
+ memcpy(subvec, &buf[1 + sizeof(uint64_t) * 2], sizeof(uint8_t) * 12);
+ uint32_t vec[3] = {
+ (uint32_t)subvec[0] << 24 |
+ (uint32_t)subvec[1] << 16 |
+ (uint32_t)subvec[2] << 8 |
+ (uint32_t)subvec[3],
+ (uint32_t)subvec[4] << 24 |
+ (uint32_t)subvec[5] << 16 |
+ (uint32_t)subvec[6] << 8 |
+ (uint32_t)subvec[7],
+ (uint32_t)subvec[8] << 24 |
+ (uint32_t)subvec[9] << 16 |
+ (uint32_t)subvec[10] << 8 |
+ (uint32_t)subvec[11] };
+
+ memcpy(&bull->pos, vec, sizeof(uint32_t) * 3);
+
+ memcpy(subvec, &buf[1 + sizeof(uint64_t) * 2 + sizeof(uint8_t) * 12], sizeof(uint8_t) * 12);
+
+ uint32_t dir[3] = {
+ (uint32_t)subvec[0] << 24 |
+ (uint32_t)subvec[1] << 16 |
+ (uint32_t)subvec[2] << 8 |
+ (uint32_t)subvec[3],
+ (uint32_t)subvec[4] << 24 |
+ (uint32_t)subvec[5] << 16 |
+ (uint32_t)subvec[6] << 8 |
+ (uint32_t)subvec[7],
+ (uint32_t)subvec[8] << 24 |
+ (uint32_t)subvec[9] << 16 |
+ (uint32_t)subvec[10] << 8 |
+ (uint32_t)subvec[11] };
+
+ memcpy(&bull->dir, dir, sizeof(uint32_t) * 3);
+
+ *buflen = 1 + sizeof(uint64_t) * 2 + sizeof(uint8_t) * 24;
+
+ return true;
+}
+
+bool netprot::Deserialize(ErrorLog* errlog, char* buf, uint32_t* buflen) {
+ if (*buflen <= sizeof(ErrorLog))
return false;
size_t messsize = std::strlen(buf) + 1;
@@ -494,13 +1054,346 @@ bool netprot::Deserialize(ErrorLog* errlog, char* buf, const uint32_t buflen) {
memcpy(&errlog->mess, &buf[1], messsize);
memcpy(&errlog->is_fatal, &buf[1 + messsize], sizeof(bool));
+ *buflen = messsize + sizeof(uint64_t) * 3 + 2;
+
return true;
}
-netprot::PacketType netprot::getType(char* buf, const uint32_t buflen) {
- if (buflen < 1 ||
- buf[0] >= netprot::PACKET_TYPE::LAST_PACK ||
- buf[0] <= netprot::PACKET_TYPE::ERR)
+
+
+netprot::PACKET_TYPE netprot::getType(char* buf, const uint32_t buflen) {
+ if (buflen < 1 ||
+ buf[0] >= (char)netprot::PACKET_TYPE::LAST_PACK ||
+ buf[0] <= (char)netprot::PACKET_TYPE::ERR)
return netprot::PACKET_TYPE::ERR;
- return buf[0];
+ return (netprot::PACKET_TYPE)buf[0];
+}
+
+netprot::Packet netprot::getPack(char* buf, uint32_t* buflen) {
+ Packet pck = { nullptr, PACKET_TYPE::ERR };
+ Input* in = nullptr;
+ Output* out = nullptr;
+ Sync* sync = nullptr;
+ Chat* chat = nullptr;
+ GameInfo* ginfo = nullptr;
+ ErrorLog* errlog = nullptr;
+ LoginInfo* loginf = nullptr;
+
+ switch (getType(buf, *buflen)) {
+ case PACKET_TYPE::INPUT:
+ in = new Input();
+ if (netprot::Deserialize(in, buf, buflen)) {
+ pck.type = PACKET_TYPE::INPUT;
+ pck.ptr = (void*)in;
+ }
+ break;
+ case PACKET_TYPE::OUTPUT:
+ out = new Output();
+ if (netprot::Deserialize(out, buf, buflen)) {
+ pck.type = PACKET_TYPE::OUTPUT;
+ pck.ptr = (void*)out;
+ }
+ break;
+ case PACKET_TYPE::SYNC:
+ sync = new Sync();
+ if (netprot::Deserialize(sync, buf, buflen)) {
+ pck.type = PACKET_TYPE::SYNC;
+ pck.ptr = (void*)sync;
+ }
+ break;
+ case PACKET_TYPE::CHAT:
+ chat = new Chat();
+ if (netprot::Deserialize(chat, buf, buflen)) {
+ pck.type = PACKET_TYPE::CHAT;
+ pck.ptr = (void*)chat;
+ }
+ break;
+ case PACKET_TYPE::GAMEINFO:
+ ginfo = new GameInfo();
+ if (netprot::Deserialize(ginfo, buf, buflen)) {
+ pck.type = PACKET_TYPE::GAMEINFO;
+ pck.ptr = (void*)ginfo;
+ }
+ break;
+ case PACKET_TYPE::ERRLOG:
+ errlog = new ErrorLog();
+ if (netprot::Deserialize(errlog, buf, buflen)) {
+ pck.type = PACKET_TYPE::ERRLOG;
+ pck.ptr = (void*)errlog;
+ }
+ break;
+ case PACKET_TYPE::LOGINF:
+ loginf = new LoginInfo();
+ if (netprot::Deserialize(loginf, buf, buflen)) {
+ pck.type = PACKET_TYPE::LOGINF;
+ pck.ptr = (void*)loginf;
+ }
+ break;
+ default:
+ break;
+ }
+ return pck;
+}
+
+netprot::Packet netprot::getPack(netprot::Buffer* buf) { return netprot::getPack(buf->ptr, &buf->len); }
+
+bool netprot::emptyPack(netprot::Packet pck) {
+ switch (pck.type) {
+ case PACKET_TYPE::INPUT:
+ delete (Input*)pck.ptr;
+ return true;
+ case PACKET_TYPE::OUTPUT:
+ delete (Output*)pck.ptr;
+ return true;
+ case PACKET_TYPE::SYNC:
+ delete (Sync*)pck.ptr;
+ return true;
+ case PACKET_TYPE::CHAT:
+ delete (Chat*)pck.ptr;
+ return true;
+ case PACKET_TYPE::GAMEINFO:
+ delete (GameInfo*)pck.ptr;
+ return true;
+ case PACKET_TYPE::ERRLOG:
+ delete (ErrorLog*)pck.ptr;
+ return true;
+ case PACKET_TYPE::LOGINF:
+ delete (LoginInfo*)pck.ptr;
+ return true;
+ default:
+ return false;
+ }
+}
+
+netprot::Packet netprot::makePack(void* ptr, PACKET_TYPE type) {
+ Packet pck;
+ pck.ptr = ptr;
+ pck.type = type;
+ return pck;
+}
+
+void netprot::recvPacks(SOCKET sock, Buffer* buf, std::vector* lsPck) {
+ int len = buf->tmp ? buf->tmp - buf->ptr : 0,
+ end = 0;
+ char* cursor = buf->tmp ? buf->tmp : nullptr,
+ * next = buf->tmp ? buf->tmp + 1 : buf->ptr,
+ * last = buf->tmp ? buf->tmp : buf->ptr;
+ bool ended = true;
+ struct pollfd fds[1];
+
+ fds[0].fd = sock;
+ fds[0].events = POLLIN;
+
+ while (true) {
+ if (!poll(fds, 1, 0)) {
+ if (ended)
+ buf->tmp = nullptr;
+ return;
+ }
+
+ int bytes = recv(sock, &buf->ptr[len], buf->len - len, 0);
+ if (bytes <= 0) { // si recv() retourne -1 ou 0; ça veut dire qu'il y a plus rien a lire qui n'a pas déjà été traité.
+ if (ended)
+ buf->tmp = nullptr;
+ return;
+ }
+ len += bytes;
+ end = len;
+
+ ended = false;
+
+ while (true) {
+ int cmp = 0;
+
+ if (cursor)
+ end -= (cursor - buf->ptr);
+
+ if (end < 0)
+ break;
+
+ cursor = (char*)memchr(next, '\r', end);
+
+ if (cursor) {
+ next = cursor;
+ cursor--;
+
+ cmp = memcmp(cursor, Footer, sizeof(uint32_t));
+ if (cmp == 0) {
+ lsPck->push_back(last);
+ cursor += sizeof(uint32_t);
+ last = cursor;
+ next = cursor + 1;
+ }
+ }
+ else {
+ buf->tmp = last;
+ cursor = &buf->ptr[len];
+ next = cursor + 1;
+ break;
+ };
+ }
+ }
+}
+
+void netprot::recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from, std::vector* lsPck) {
+ int len = buf->tmp ? buf->tmp - buf->ptr : 0,
+ end = 0;
+ char* cursor = buf->tmp ? buf->tmp : nullptr,
+ * next = buf->tmp ? buf->tmp + 1 : buf->ptr,
+ * last = buf->tmp ? buf->tmp : buf->ptr;
+ bool ended = true;
+ struct pollfd fds[1];
+ sockaddr_in sockad = from;
+ addrlen_t socklen = sizeof(sockad);
+
+ fds[0].fd = sock;
+ fds[0].events = POLLIN;
+
+ while (true) {
+ if (!poll(fds, 1, 0)) {
+ if (ended)
+ buf->tmp = nullptr;
+ return;
+ }
+
+ int bytes = recvfrom(sock, &buf->ptr[len], buf->len - len, 0, (sockaddr*)&sockad, &socklen);
+ if (bytes <= 0) { // si recv() retourne -1 ou 0; ça veut dire qu'il y a plus rien a lire qui n'a pas déjà été traité.
+ if (ended)
+ buf->tmp = nullptr;
+ return;
+ }
+ len += bytes;
+ end = len;
+
+ ended = false;
+
+ while (true) {
+ int cmp = 0;
+
+ if (cursor)
+ end -= (cursor - buf->ptr);
+
+ if (end < 0)
+ break;
+
+ cursor = (char*)memchr(next, '\r', end);
+
+ if (cursor) {
+ next = cursor;
+ cursor--;
+
+ cmp = memcmp(cursor, Footer, sizeof(uint32_t));
+ if (cmp == 0) {
+ lsPck->push_back(last);
+ cursor += sizeof(uint32_t);
+ last = cursor;
+ next = cursor + 1;
+ }
+ }
+ else {
+ buf->tmp = last;
+ cursor = &buf->ptr[len];
+ next = cursor + 1;
+ break;
+ };
+ }
+ }
+}
+
+template <>
+void netprot::sendPack(SOCKET sock, Packet* pack, Buffer* buf) {
+ switch (pack->type) {
+ case PACKET_TYPE::INPUT:
+ sendPack(sock, (Input*)pack->ptr, buf);
+ return;
+ case PACKET_TYPE::OUTPUT:
+ sendPack