connection?

This commit is contained in:
MarcEricMartel 2023-10-23 16:44:34 -04:00
parent eea6a30aa5
commit ecfe5b893b
3 changed files with 25 additions and 2 deletions

View File

@ -17,6 +17,9 @@ public:
//void SendInput();
//int Sync();
SOCKET m_sock_udp = 0,
m_sock_tcp = 0;
private:
#ifdef _WIN32
WSADATA m_wsaData;
@ -29,8 +32,7 @@ private:
netprot::GameInfo m_gameinfo;
sockaddr_in m_srvsockaddr;
SOCKET m_sock_udp = 0,
m_sock_tcp = 0;
};
#endif

View File

@ -285,6 +285,7 @@ void Engine::Init() {
std::cout << "ID recu du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl;
std::cout << "Seed recu du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl;
seed = m_conn.getSeed();
m_networkgame = true;
}
else std::cout << "Erreur de connexion." << std::endl;
}
@ -778,6 +779,24 @@ void Engine::Render(float elapsedTime) {
fell = false;
}
if (m_networkgame) {
static char* buf = new char[BUFFER_LENGTH];
uint32_t buflen = BUFFER_LENGTH;
netprot::Input input;
input.direction = m_player.GetDirection();
input.sid = m_conn.getId();
input.timestamp = 12345;
input.keys.forward = m_keyW;
input.keys.backward = m_keyS;
input.keys.left = m_keyA;
input.keys.right = m_keyD;
input.keys.jump = m_keySpace;
input.keys.block = m_mouseR;
input.keys.shoot = m_mouseL;
netprot::sendPack<netprot::Input>(m_conn.m_sock_udp, &input, &buf, &buflen);
}
}
else if (m_gamestate == GameState::MAIN_MENU || m_gamestate == GameState::OPTIONS)
{

View File

@ -120,6 +120,8 @@ private:
float m_mousemx = 0;
float m_mousemy = 0;
bool m_networkgame = false;
std::string m_messageNotification = "";
};