Merge remote-tracking branch 'origin/Networking' into Networking
# Conflicts: # src/Engine/Network/Client.cpp
This commit is contained in:
@@ -4,9 +4,9 @@
|
|||||||
struct SnapshotDefinitions
|
struct SnapshotDefinitions
|
||||||
{
|
{
|
||||||
// "+Forward" is 8 characters * sizeof(char) = 8
|
// "+Forward" is 8 characters * sizeof(char) = 8
|
||||||
char* InputForward = new char[8];
|
std::string InputForward;
|
||||||
// "+Right" is 6 characters * sizeof(char) = 6
|
// "+Right" is 6 characters * sizeof(char) = 6
|
||||||
char* InputRight = new char[6];
|
std::string InputRight;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IsWASDKeyDown
|
struct IsWASDKeyDown
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using namespace boost::asio::ip;
|
|||||||
Client::Client() : m_Socket(m_IOService)
|
Client::Client() : m_Socket(m_IOService)
|
||||||
{
|
{
|
||||||
// Set up network stream
|
// Set up network stream
|
||||||
m_ReceiverEndpoint = udp::endpoint(boost::asio::ip::address::from_string("192.168.1.2"), 13);
|
m_ReceiverEndpoint = udp::endpoint(boost::asio::ip::address::from_string("192.168.1.6"), 13);
|
||||||
m_NextSnapshot.InputForward = "";
|
m_NextSnapshot.InputForward = "";
|
||||||
m_NextSnapshot.InputRight = "";
|
m_NextSnapshot.InputRight = "";
|
||||||
}
|
}
|
||||||
@@ -77,19 +77,19 @@ void Client::SendSnapshotToServer()
|
|||||||
Package message(MessageType::Event, m_SendPacketID);
|
Package message(MessageType::Event, m_SendPacketID);
|
||||||
message.AddString(m_NextSnapshot.InputForward);
|
message.AddString(m_NextSnapshot.InputForward);
|
||||||
Send(message);
|
Send(message);
|
||||||
m_NextSnapshot.InputRight = "";
|
m_NextSnapshot.InputForward = "";
|
||||||
m_NextSnapshot.InputRight = "";
|
m_NextSnapshot.InputRight = "";
|
||||||
// See if any movement keys are down
|
// See if any movement keys are down
|
||||||
// We dont care if it's overwritten by later
|
// We dont care if it's overwritten by later
|
||||||
// if statement. Watcha gonna do, right!
|
// if statement. Watcha gonna do, right!
|
||||||
if (m_IsWASDKeyDown.W) {
|
if (m_IsWASDKeyDown.W) {
|
||||||
m_NextSnapshot.InputRight = "+Forward";
|
m_NextSnapshot.InputForward = "+Forward";
|
||||||
}
|
}
|
||||||
if (m_IsWASDKeyDown.A) {
|
if (m_IsWASDKeyDown.A) {
|
||||||
m_NextSnapshot.InputRight = "-Right";
|
m_NextSnapshot.InputRight = "-Right";
|
||||||
}
|
}
|
||||||
if (m_IsWASDKeyDown.S) {
|
if (m_IsWASDKeyDown.S) {
|
||||||
m_NextSnapshot.InputRight = "-Forward";
|
m_NextSnapshot.InputForward = "-Forward";
|
||||||
}
|
}
|
||||||
if (m_IsWASDKeyDown.D) {
|
if (m_IsWASDKeyDown.D) {
|
||||||
m_NextSnapshot.InputRight = "+Right";
|
m_NextSnapshot.InputRight = "+Right";
|
||||||
@@ -148,6 +148,9 @@ void Client::ParseConnect(char* data, size_t len)
|
|||||||
{
|
{
|
||||||
memcpy(&m_PacketID, data, sizeof(int));
|
memcpy(&m_PacketID, data, sizeof(int));
|
||||||
m_PreviousPacketID = m_PacketID;
|
m_PreviousPacketID = m_PacketID;
|
||||||
|
MoveMessageHead(data, len, sizeof(int));
|
||||||
|
memcpy(&m_PlayerID, data, sizeof(int));
|
||||||
|
MoveMessageHead(data, len, sizeof(int));
|
||||||
std::cout << m_PacketID << ": I am player: " << m_PlayerID << std::endl;
|
std::cout << m_PacketID << ": I am player: " << m_PlayerID << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,8 +335,6 @@ void Client::IdentifyPacketLoss()
|
|||||||
// if no packets lost, difference should be equal to 1
|
// if no packets lost, difference should be equal to 1
|
||||||
int difference = m_PacketID - m_PreviousPacketID;
|
int difference = m_PacketID - m_PreviousPacketID;
|
||||||
if (difference != 1) {
|
if (difference != 1) {
|
||||||
for (int i = m_PreviousPacketID + 1; i < m_PacketID; i++) {
|
LOG_INFO("%i Packet(s) were lost...", difference);
|
||||||
LOG_INFO("Packet %i was lost...", i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
#include "Network/Server.h"
|
#include "Network/Server.h"
|
||||||
|
|
||||||
Server::Server() : m_Socket(m_IOService, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 13))
|
Server::Server() : m_Socket(m_IOService, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 13))
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
Server::~Server()
|
Server::~Server()
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Server::Start(World* world)
|
void Server::Start(World* world)
|
||||||
@@ -310,7 +308,7 @@ void Server::ParseEvent(char * data, size_t length)
|
|||||||
void Server::ParseConnect(char * data, size_t length)
|
void Server::ParseConnect(char * data, size_t length)
|
||||||
{
|
{
|
||||||
std::cout << "Parsing connection." << std::endl;
|
std::cout << "Parsing connection." << std::endl;
|
||||||
|
// Check if player is already connected
|
||||||
for (int i = 0; i < MAXCONNECTIONS; i++) {
|
for (int i = 0; i < MAXCONNECTIONS; i++) {
|
||||||
if (m_PlayerDefinitions[i].Endpoint.address() == m_ReceiverEndpoint.address()) {
|
if (m_PlayerDefinitions[i].Endpoint.address() == m_ReceiverEndpoint.address()) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user