The client is registering with the server
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef INFORMATIONMANAGER_HPP_
|
||||||
|
#define INFORMATIONMANAGER_HPP_
|
||||||
|
|
||||||
|
class InformationManager {
|
||||||
|
public:
|
||||||
|
int SetClientIndex(int i) { return clientIndex = i; }
|
||||||
|
int GetClientIndex() { return clientIndex; }
|
||||||
|
private:
|
||||||
|
int clientIndex = -1;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
+8
-3
@@ -160,7 +160,7 @@ int Lobby::HandlePacket(Packet p) {
|
|||||||
// //
|
// //
|
||||||
// break;
|
// break;
|
||||||
case PacketType::JOIN_RESPONSE:
|
case PacketType::JOIN_RESPONSE:
|
||||||
//TODO
|
BeginGame(p.joinResponse);
|
||||||
break;
|
break;
|
||||||
// case PacketType::DISCONNECT:
|
// case PacketType::DISCONNECT:
|
||||||
// //
|
// //
|
||||||
@@ -204,7 +204,12 @@ void Lobby::ConnectToServer(ServerEntry* server) {
|
|||||||
}
|
}
|
||||||
Packet p;
|
Packet p;
|
||||||
p.meta.type = PacketType::JOIN_REQUEST;
|
p.meta.type = PacketType::JOIN_REQUEST;
|
||||||
snprintf(p.joinRequest.playerHandle, PACKET_STRING_SIZE, "%s", configUtil->CString("handle"));
|
|
||||||
snprintf(p.joinRequest.playerAvatar, PACKET_STRING_SIZE, "%s", configUtil->CString("avatar"));
|
|
||||||
netUtil->Send(&server->address, reinterpret_cast<void*>(&p), sizeof(Packet));
|
netUtil->Send(&server->address, reinterpret_cast<void*>(&p), sizeof(Packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Lobby::BeginGame(JoinResponse& response) {
|
||||||
|
//should be downloading the resources here as well
|
||||||
|
infoMgr->SetClientIndex(response.clientIndex);
|
||||||
|
netUtil->Bind(&response.meta.address, GAME_CHANNEL);
|
||||||
|
SetNextScene(SceneList::INWORLD);
|
||||||
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
#ifndef LOBBY_HPP_
|
#ifndef LOBBY_HPP_
|
||||||
#define LOBBY_HPP_
|
#define LOBBY_HPP_
|
||||||
|
|
||||||
|
#include "defines.hpp"
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
#include "service_locator.hpp"
|
#include "service_locator.hpp"
|
||||||
#include "packet_type.hpp"
|
#include "packet_type.hpp"
|
||||||
#include "network_queue.hpp"
|
#include "network_queue.hpp"
|
||||||
|
#include "information_manager.hpp"
|
||||||
|
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
#include "surface_manager.hpp"
|
#include "surface_manager.hpp"
|
||||||
@@ -47,11 +49,13 @@ protected:
|
|||||||
void BroadcastNetwork();
|
void BroadcastNetwork();
|
||||||
void PushServer(BroadcastResponse&);
|
void PushServer(BroadcastResponse&);
|
||||||
void ConnectToServer(ServerEntry*);
|
void ConnectToServer(ServerEntry*);
|
||||||
|
void BeginGame(JoinResponse&);
|
||||||
|
|
||||||
//services
|
//services
|
||||||
ConfigUtility* configUtil = ServiceLocator<ConfigUtility>::Get();
|
ConfigUtility* configUtil = ServiceLocator<ConfigUtility>::Get();
|
||||||
SurfaceManager* surfaceMgr = ServiceLocator<SurfaceManager>::Get();
|
SurfaceManager* surfaceMgr = ServiceLocator<SurfaceManager>::Get();
|
||||||
UDPNetworkUtility* netUtil = ServiceLocator<UDPNetworkUtility>::Get();
|
UDPNetworkUtility* netUtil = ServiceLocator<UDPNetworkUtility>::Get();
|
||||||
|
InformationManager* infoMgr = ServiceLocator<InformationManager>::Get();
|
||||||
|
|
||||||
//members
|
//members
|
||||||
Button refreshButton;
|
Button refreshButton;
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ void SceneManager::Init() {
|
|||||||
//instanciate the remaining services
|
//instanciate the remaining services
|
||||||
surfaceMgr = ServiceLocator<SurfaceManager>::Set(new SurfaceManager());
|
surfaceMgr = ServiceLocator<SurfaceManager>::Set(new SurfaceManager());
|
||||||
netUtil = ServiceLocator<UDPNetworkUtility>::Set(new UDPNetworkUtility());
|
netUtil = ServiceLocator<UDPNetworkUtility>::Set(new UDPNetworkUtility());
|
||||||
|
infoMgr = ServiceLocator<InformationManager>::Set(new InformationManager());
|
||||||
|
|
||||||
//initiate the remaining services
|
//initiate the remaining services
|
||||||
netUtil->Open(0, sizeof(Packet));
|
netUtil->Open(0, sizeof(Packet));
|
||||||
@@ -144,6 +145,7 @@ void SceneManager::Quit() {
|
|||||||
configUtil = ServiceLocator<ConfigUtility>::Set(nullptr);
|
configUtil = ServiceLocator<ConfigUtility>::Set(nullptr);
|
||||||
surfaceMgr = ServiceLocator<SurfaceManager>::Set(nullptr);
|
surfaceMgr = ServiceLocator<SurfaceManager>::Set(nullptr);
|
||||||
netUtil = ServiceLocator<UDPNetworkUtility>::Set(nullptr);
|
netUtil = ServiceLocator<UDPNetworkUtility>::Set(nullptr);
|
||||||
|
infoMgr = ServiceLocator<InformationManager>::Set(nullptr);
|
||||||
|
|
||||||
//clean up the scene
|
//clean up the scene
|
||||||
UnloadScene();
|
UnloadScene();
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
#include "service_locator.hpp"
|
#include "service_locator.hpp"
|
||||||
#include "packet_type.hpp"
|
#include "packet_type.hpp"
|
||||||
|
#include "information_manager.hpp"
|
||||||
|
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
#include "surface_manager.hpp"
|
#include "surface_manager.hpp"
|
||||||
@@ -53,6 +54,7 @@ private:
|
|||||||
ConfigUtility* configUtil = nullptr;
|
ConfigUtility* configUtil = nullptr;
|
||||||
SurfaceManager* surfaceMgr = nullptr;
|
SurfaceManager* surfaceMgr = nullptr;
|
||||||
UDPNetworkUtility* netUtil = nullptr;
|
UDPNetworkUtility* netUtil = nullptr;
|
||||||
|
InformationManager* infoMgr = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
|
#define GAME_CHANNEL 0
|
||||||
|
#define CHAT_CHANNEL 1
|
||||||
|
|
||||||
typedef std::chrono::high_resolution_clock Clock;
|
typedef std::chrono::high_resolution_clock Clock;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -52,14 +52,11 @@ struct BroadcastResponse {
|
|||||||
|
|
||||||
struct JoinRequest {
|
struct JoinRequest {
|
||||||
Metadata meta;
|
Metadata meta;
|
||||||
char playerHandle[PACKET_STRING_SIZE];
|
|
||||||
char playerAvatar[PACKET_STRING_SIZE];
|
|
||||||
//TODO: player data
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct JoinResponse {
|
struct JoinResponse {
|
||||||
Metadata meta;
|
Metadata meta;
|
||||||
int playerIndex;
|
int clientIndex;
|
||||||
//resource list
|
//resource list
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -173,32 +173,22 @@ void ServerApplication::HandleConnection(JoinRequest& request) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//create the containers
|
//create the containers
|
||||||
ClientData client = { uniqueIndex };
|
ClientData client = { uniqueIndex++ };
|
||||||
PlayerData player = { uniqueIndex };
|
|
||||||
|
|
||||||
uniqueIndex++;
|
|
||||||
|
|
||||||
//link the containers
|
|
||||||
client.playerIndex = player.index;
|
|
||||||
player.clientIndex = client.index;
|
|
||||||
|
|
||||||
//fill the containers
|
|
||||||
player.handle = request.playerHandle;
|
|
||||||
player.avatar = request.playerAvatar;
|
|
||||||
|
|
||||||
//bind the address
|
//bind the address
|
||||||
client.channel = netUtil->Bind(&request.meta.address);
|
client.channel = netUtil->Bind(&request.meta.address);
|
||||||
|
|
||||||
//push this information
|
//push this information
|
||||||
clients[client.index] = client;
|
clients[client.index] = client;
|
||||||
players[player.index] = player;
|
|
||||||
|
|
||||||
//send the player their information
|
//send the player their information
|
||||||
Packet p;
|
Packet p;
|
||||||
p.meta.type = PacketType::JOIN_RESPONSE;
|
p.meta.type = PacketType::JOIN_RESPONSE;
|
||||||
p.joinResponse.playerIndex = player.index;
|
p.joinResponse.clientIndex = client.index;
|
||||||
|
//TODO: resource list
|
||||||
netUtil->Send(client.channel, &p, sizeof(Packet));
|
netUtil->Send(client.channel, &p, sizeof(Packet));
|
||||||
|
|
||||||
//send it out to new players
|
//pretty
|
||||||
//TODO
|
cout << "New connection" << endl;
|
||||||
|
cout << "number of clients: " << clients.size() << endl;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user