Redressage des classes; seed est reçue du serveur
This commit is contained in:
@@ -1,29 +1,27 @@
|
||||
#include "connection.h"
|
||||
|
||||
Connection::Connection(in_addr addr,
|
||||
std::string name,
|
||||
uint64_t id,
|
||||
uint64_t self_id,
|
||||
uint64_t 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_t Connection::GetHash(bool self) const { return self? m_sid: m_id; }
|
||||
uint64_t Connection::GetTeamHash() const { return m_loginfo.tid; }
|
||||
|
||||
uint64_t Connection::GetTeamHash() const { return m_tid; }
|
||||
|
||||
std::string Connection::GetName() const { return m_name; }
|
||||
std::string Connection::GetName() const { return m_loginfo.name; }
|
||||
|
||||
void Connection::AddInput(netprot::Input in) {
|
||||
m_input_manifest.insert({ in.timestamp, in });
|
||||
@@ -42,7 +40,7 @@ netprot::Sync Connection::getSync(Timestamp 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;
|
||||
}
|
||||
|
@@ -10,16 +10,14 @@
|
||||
class Connection {
|
||||
public:
|
||||
Connection(
|
||||
in_addr addr,
|
||||
std::string name,
|
||||
uint64_t hash,
|
||||
uint64_t self_hash,
|
||||
uint64_t team_hash);
|
||||
SOCKET sock,
|
||||
sockaddr_in sockaddr,
|
||||
netprot::LoginInfo log,
|
||||
netprot::PlayerInfo play);
|
||||
~Connection();
|
||||
|
||||
Player* player = nullptr;
|
||||
|
||||
in_addr GetAddr() const;
|
||||
uint64_t GetHash(bool self = true) const;
|
||||
uint64_t GetTeamHash() const;
|
||||
std::string GetName() const;
|
||||
@@ -32,11 +30,12 @@ public:
|
||||
private:
|
||||
std::map<Timestamp, netprot::Input> m_input_manifest;
|
||||
std::map<Timestamp, netprot::Output> m_output_manifest;
|
||||
in_addr m_addr;
|
||||
uint64_t m_id,
|
||||
m_sid,
|
||||
m_tid;
|
||||
std::string m_name;
|
||||
std::map<Timestamp, netprot::Chat> m_chatlog;
|
||||
|
||||
SOCKET m_sock;
|
||||
sockaddr_in m_addr;
|
||||
netprot::LoginInfo m_loginfo;
|
||||
netprot::PlayerInfo m_playinfo;
|
||||
|
||||
};
|
||||
#endif
|
@@ -76,6 +76,7 @@ int Server::Ready() {
|
||||
char* buf = new char[150];
|
||||
uint32_t buflen = 150;
|
||||
bool readystart = false;
|
||||
srand(time(NULL));
|
||||
|
||||
Log("<EFBFBD> l'<27>coute sur le port: " + std::to_string(SRV_PORT), false, false);
|
||||
|
||||
@@ -87,23 +88,35 @@ int Server::Ready() {
|
||||
if (sock < 0)
|
||||
Log("Erreur de connexion", true, false);
|
||||
else if (sock > 0) {
|
||||
std::string str = "Nouvelle connection provenant de: ";
|
||||
char* strbuf = new char[150];
|
||||
uint32_t strbuflen = 150;
|
||||
|
||||
std::cout << inet_ntop(AF_INET, &sockad.sin_addr, strbuf, strbuflen) << ':' << std::to_string(sockad.sin_port) << std::endl;;
|
||||
|
||||
str.append(inet_ntop(AF_INET, &sockad.sin_addr, strbuf, strbuflen)).append(": ").append(std::to_string(sockad.sin_port));
|
||||
|
||||
if (recv(sock, buf, buflen, 0) > 0) {
|
||||
netprot::LoginInfo log;
|
||||
if (netprot::Deserialize(&log, buf, buflen)) {
|
||||
std::string str;
|
||||
log.sid = 8675309; // EIGHT SIX SEVENFIVE THREE AUGHT NIIIIIIIIIiiIIIIiINE!
|
||||
log.sid = ((uint64_t)rand() << 25) % 8675309; // EIGHT SIX SEVENFIVE THREE AUGHT NIIIIIIIIIiiIIIIiINE!
|
||||
log.tid = 123456789;
|
||||
str.append(" Nom: ").append(log.name);
|
||||
Log(str, false, false);
|
||||
str = "";
|
||||
|
||||
str.append(log.name).append(": ").append(std::to_string(log.sid));
|
||||
str.append(log.name).append(" SID: [").append(std::to_string(log.sid).append("]"));
|
||||
Log(str, false, false);
|
||||
|
||||
netprot::Serialize(&log, &buf, &buflen);
|
||||
send(sock, buf, buflen, 0);
|
||||
|
||||
std::cin.getline(nullptr, 1);
|
||||
buflen = 150;
|
||||
Sleep(300);
|
||||
netprot::GameInfo ginfo;
|
||||
ginfo.countdown = 360;
|
||||
ginfo.gameType = 1;
|
||||
ginfo.seed = 9370707;
|
||||
netprot::Serialize(&ginfo, &buf, &buflen);
|
||||
send(sock, buf, buflen, 0);
|
||||
Sleep(10000);
|
||||
readystart = true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user