diff --git a/SQCSim-common/SQCSim-common.vcxproj b/SQCSim-common/SQCSim-common.vcxproj
index 5db21d0..15265fb 100644
--- a/SQCSim-common/SQCSim-common.vcxproj
+++ b/SQCSim-common/SQCSim-common.vcxproj
@@ -137,6 +137,7 @@
+
@@ -144,6 +145,7 @@
+
diff --git a/SQCSim-common/SQCSim-common.vcxproj.filters b/SQCSim-common/SQCSim-common.vcxproj.filters
index af8b625..a98dd18 100644
--- a/SQCSim-common/SQCSim-common.vcxproj.filters
+++ b/SQCSim-common/SQCSim-common.vcxproj.filters
@@ -48,6 +48,9 @@
Fichiers d%27en-tête
+
+ Fichiers d%27en-tête
+
@@ -68,5 +71,8 @@
Fichiers sources
+
+ Fichiers sources
+
\ No newline at end of file
diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h
index 3501dd6..968b71d 100644
--- a/SQCSim-common/define.h
+++ b/SQCSim-common/define.h
@@ -2,51 +2,55 @@
#define DEFINE_H__
#include
-
-#define CHUNK_SIZE_X 16
-#define CHUNK_SIZE_Y 128
-#define CHUNK_SIZE_Z 16
-#define MAX_SELECTION_DISTANCE 5
-#define SEED 12345
+#include
#define SRV_PORT 1025
#define CLI_PORT 1026
-#ifdef _DEBUG
+#define CHUNK_SIZE_X 4
+#define CHUNK_SIZE_Y 64
+#define CHUNK_SIZE_Z 4
+#define MAX_SELECTION_DISTANCE 5
+#define SEED 12345
+#define COUNTDOWN 300
+
#define WORLD_SIZE_X 64
#define WORLD_SIZE_Y 64
-#define FRAMES_RENDER_CHUNKS 4
-#define FRAMES_UPDATE_CHUNKS 4
-#define FRAMES_DELETE_CHUNKS 4
-
-#define THREADS_GENERATE_CHUNKS 1
-#define THREADS_UPDATE_CHUNKS 1
-#define THREADS_DELETE_CHUNKS 1
-
-#define VIEW_DISTANCE 256
-#define TEXTURE_SIZE 128
-#define MAX_BULLETS 64
-#endif
-
-#ifdef NDEBUG
-#define WORLD_SIZE_X 16
-#define WORLD_SIZE_Y 16
-
-#define FRAMES_RENDER_CHUNKS 1
-#define FRAMES_UPDATE_CHUNKS 1
-#define FRAMES_DELETE_CHUNKS 1
-
-#define THREADS_GENERATE_CHUNKS 12
-#define THREADS_UPDATE_CHUNKS 5
-#define THREADS_DELETE_CHUNKS 2
-
-#define VIEW_DISTANCE 1024
+#define VIEW_DISTANCE 512
#define TEXTURE_SIZE 512
#define MAX_BULLETS 512
-#endif
typedef uint8_t BlockType;
enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_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 popen _popen
+#define pclose _pclose
+
+#else // Pas _WIN32
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define SOCKET int
+#define INVALID_SOCKET -1
+#define closesocket close
+
+#endif // _WIN32
+
#endif // DEFINE_H__
diff --git a/SQCSim-common/netprotocol.cpp b/SQCSim-common/netprotocol.cpp
new file mode 100644
index 0000000..d7f7675
--- /dev/null
+++ b/SQCSim-common/netprotocol.cpp
@@ -0,0 +1,230 @@
+#include "netprotocol.h"
+
+void netprot::Serialize(Input* in, char* buf[], uint32_t* buflen) {
+
+}
+
+void netprot::Serialize(Output* out, char* buf[], uint32_t* buflen) {
+
+}
+
+void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
+
+}
+
+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;
+
+ size_t namesize = std::strlen(linfo->name) + 1;
+
+ memcpy(*buf + 1, &linfo->name, namesize);
+ 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
+ };
+
+ 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
+ };
+
+ memcpy(*buf + namesize + 2 + sizeof(uint64_t), tid8, sizeof(uint64_t));
+
+ *buflen = namesize + sizeof(uint64_t) * 2 + 2;
+}
+
+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;
+
+ 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
+ };
+
+ 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
+ };
+
+ 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
+ };
+
+ memcpy(*buf + sizeof(uint64_t) + 1, gtype8, sizeof(uint64_t));
+
+ *buflen = sizeof(uint64_t) * 3 + 1;
+}
+
+void netprot::Serialize(Chat* chat, char* buf[], uint32_t* buflen) {
+
+}
+
+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(Output* out, char* buf, const uint32_t buflen) {
+ return false;
+}
+
+bool netprot::Deserialize(Sync* sync, char* buf, const uint32_t buflen) {
+ return false;
+}
+
+bool netprot::Deserialize(TeamInfo* tinfo, char* buf, const uint32_t buflen) {
+ return false;
+}
+
+bool netprot::Deserialize(LoginInfo* linfo, char* buf, const uint32_t buflen) {
+ if (buflen < sizeof(LoginInfo) + 3)
+ return false;
+
+ size_t namesize = std::strlen(buf) + 1;
+
+ if (namesize > 32)
+ return false;
+
+ memcpy(&linfo->name, &buf[1], namesize);
+
+ uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
+ memcpy(diff, &buf[namesize + 1], sizeof(uint64_t));
+ linfo->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[namesize + sizeof(uint64_t) + 1], sizeof(uint64_t));
+ linfo->tid =
+ (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];
+
+ return true;
+}
+
+bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, const uint32_t buflen) {
+ return false;
+}
+
+bool netprot::Deserialize(GameInfo* ginfo, char* buf, const uint32_t buflen) {
+ if (buflen < sizeof(GameInfo) + 1)
+ return false;
+
+ uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
+ memcpy(diff, &buf[1], sizeof(uint64_t));
+ ginfo->seed =
+ (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[sizeof(uint64_t) + 1], sizeof(uint64_t));
+ ginfo->countdown =
+ (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[sizeof(uint64_t) * 2 + 1], sizeof(uint64_t));
+ ginfo->gameType =
+ (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];
+
+ return true;
+}
+
+bool netprot::Deserialize(Chat* chat, char* buf, const uint32_t buflen) {
+ return false;
+}
+
+bool netprot::Deserialize(ErrorLog* errlog, char* buf, const uint32_t buflen) {
+ return false;
+}
+
+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)
+ return netprot::PACKET_TYPE::ERR;
+ return buf[0];
+}
diff --git a/SQCSim-common/netprotocol.h b/SQCSim-common/netprotocol.h
new file mode 100644
index 0000000..3e237f7
--- /dev/null
+++ b/SQCSim-common/netprotocol.h
@@ -0,0 +1,101 @@
+#ifndef NETPROTOCOL_H__
+#define NETPROTOCOL_H__
+#include "define.h"
+#include
+#include "vector3.h"
+
+/* Protocole Particulier de Partie à Plusieurs Personnes (PPPPP) */
+
+// Packet: packet[0] = PacketType, packet[1..n-1] = {packet}
+
+namespace netprot {
+ typedef uint8_t PacketType;
+ enum PACKET_TYPE {
+ ERR, INPUT, OUTPUT, SYNC,
+ TEAMINF, SELFINF, PLAYINF, LOGINF,
+ CHUNKMOD, PLAYERMOD, PICKUPMOD,
+ GAMEINFO, ENDINFO , CHAT, ERRLOG,
+ LAST_PACK
+ };
+
+ struct Input { // cli -> srv UDP ~frame
+ Timestamp timestamp;
+ uint8_t keys; // 0bFBLRJS__ bit-packing de bool.
+ Vector3f direction;
+ };
+
+ struct Output { // srv -> cli UDP ~frame
+ Timestamp timestamp;
+ uint64_t id = 0;
+ Vector3f position,
+ direction;
+ uint8_t states; // 0bJSH_____ bit-packing de bool.
+ };
+
+ struct Sync { // srv -> cli TCP ~second
+ Timestamp timestamp;
+ uint64_t sid = 0;
+ uint32_t timer = 0;
+ uint16_t ammo = 0;
+ uint8_t hp = 0;
+ Vector3f position;
+ };
+
+ struct TeamInfo { // cli <-> srv TCP once
+ char name[32];
+ uint64_t id = 0;
+ };
+
+ struct LoginInfo { // cli <-> srv TCP once
+ char name[32];
+ uint64_t sid = 0,
+ tid = 0;
+ };
+
+ struct PlayerInfo { // cli <-> srv TCP once
+ char name[32];
+ uint64_t id = 0,
+ tid = 0;
+ };
+
+ struct GameInfo { // cli <-> srv TCP event (before game start)/ once
+ uint64_t seed;
+ uint32_t countdown;
+ uint8_t gameType; // TOOD: enum.
+ };
+
+ struct Chat { // cli <-> srv TCP event
+ uint64_t src_id = 0,
+ dest_id = 0,
+ dest_team_id = 0;
+ char mess[140]; // Good 'nough for twitr, good 'nough for me.
+ };
+
+ struct ErrorLog { // srv -> cli TCP event
+ char mess[140];
+ bool is_fatal;
+ };
+
+ void Serialize(Input* in, char* buf[], uint32_t* buflen); // cli
+ void Serialize(Output* out, char* buf[], uint32_t* buflen); // srv
+ void Serialize(Sync* sync, char* buf[], uint32_t* buflen); // srv
+ void Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen); // cli/srv
+ void Serialize(LoginInfo* linfo, char* buf[], uint32_t* buflen); // cli/srv
+ void Serialize(PlayerInfo* pinfo, char* buf[], uint32_t* buflen); // srv
+ void Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen); // cli/srv
+ void Serialize(Chat* chat, char* buf[], uint32_t* buflen); // cli/srv
+ void Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen); // srv
+
+ bool Deserialize(Input* in, char* buf, const uint32_t buflen); // srv
+ bool Deserialize(Output* out, char* buf, const uint32_t buflen); // cli
+ bool Deserialize(Sync* sync, char* buf, const uint32_t buflen); // cli
+ bool Deserialize(TeamInfo* tinfo, char* buf, const uint32_t buflen); // cli/srv
+ bool Deserialize(LoginInfo* linfo, char* buf, const uint32_t buflen); // cli/srv
+ bool Deserialize(PlayerInfo* pinfo, char* buf, const uint32_t buflen); // cli
+ bool Deserialize(GameInfo* ginfo, char* buf, const uint32_t buflen); // cli
+ bool Deserialize(Chat* chat, char* buf, const uint32_t buflen); // srv/cli
+ bool Deserialize(ErrorLog* errlog, char* buf, const uint32_t buflen); // srv
+
+ PacketType getType(char* buf, uint32_t buflen); // srv/cli
+}
+#endif
diff --git a/SQCSim-srv/connection.cpp b/SQCSim-srv/connection.cpp
index 2b93114..356396f 100644
--- a/SQCSim-srv/connection.cpp
+++ b/SQCSim-srv/connection.cpp
@@ -1,48 +1,46 @@
#include "connection.h"
-Connection::Connection(in_addr addr,
- std::string name,
- UINT64 id,
- UINT64 self_id,
- UINT64 team_id):
- m_addr(addr),
- m_id(id),
- m_sid(self_id),
- m_tid(team_id),
- m_name(name) {
+
+
+Connection::Connection(SOCKET sock,
+ sockaddr_in sockaddr,
+ netprot::LoginInfo log,
+ netprot::PlayerInfo play):
+ m_sock(sock),
+ m_addr(sockaddr),
+ m_loginfo(log),
+ m_playinfo(play) {
}
Connection::~Connection() {
-
+ closesocket(m_sock);
}
-in_addr Connection::GetAddr() const { return m_addr; }
+uint64_t Connection::GetHash(bool self) const { return self? m_loginfo.sid: m_playinfo.id; }
-UINT64 Connection::GetHash(bool self) const { return self? m_sid: m_id; }
+uint64_t Connection::GetTeamHash() const { return m_loginfo.tid; }
-UINT64 Connection::GetTeamHash() const { return m_tid; }
+std::string Connection::GetName() const { return m_loginfo.name; }
-std::string Connection::GetName() const { return m_name; }
-
-void Connection::AddInput(Input in) {
- m_input_manifest.insert({in.timestamp, in});
+void Connection::AddInput(netprot::Input in) {
+ m_input_manifest.insert({ in.timestamp, in });
}
-Output* Connection::getOutput(Timestamp time) {
+netprot::Output* Connection::getOutput(Timestamp time) {
auto out = m_output_manifest.find(time);
if (out != m_output_manifest.end())
return &out->second;
return nullptr;
}
-Sync Connection::getSync(Timestamp time) {
- Sync sync;
+netprot::Sync Connection::getSync(Timestamp time) {
+ netprot::Sync sync;
auto out = m_output_manifest.find(time);
if (out != m_output_manifest.end()) {
sync.timestamp = out->second.timestamp;
sync.position = out->second.position;
- sync.sid = m_sid;
+ sync.sid = m_loginfo.sid;
}
return sync;
}
diff --git a/SQCSim-srv/connection.h b/SQCSim-srv/connection.h
index 5b0134d..dc1df11 100644
--- a/SQCSim-srv/connection.h
+++ b/SQCSim-srv/connection.h
@@ -4,57 +4,38 @@
#include