The client is registering with the server

This commit is contained in:
Kayne Ruse
2013-06-17 19:53:22 +10:00
parent 69f03cd250
commit fd65fec5f7
8 changed files with 38 additions and 23 deletions
+12
View File
@@ -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
View File
@@ -160,7 +160,7 @@ int Lobby::HandlePacket(Packet p) {
// //
// break;
case PacketType::JOIN_RESPONSE:
//TODO
BeginGame(p.joinResponse);
break;
// case PacketType::DISCONNECT:
// //
@@ -204,7 +204,12 @@ void Lobby::ConnectToServer(ServerEntry* server) {
}
Packet p;
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));
}
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);
}
+4
View File
@@ -1,10 +1,12 @@
#ifndef LOBBY_HPP_
#define LOBBY_HPP_
#include "defines.hpp"
#include "base_scene.hpp"
#include "service_locator.hpp"
#include "packet_type.hpp"
#include "network_queue.hpp"
#include "information_manager.hpp"
#include "config_utility.hpp"
#include "surface_manager.hpp"
@@ -47,11 +49,13 @@ protected:
void BroadcastNetwork();
void PushServer(BroadcastResponse&);
void ConnectToServer(ServerEntry*);
void BeginGame(JoinResponse&);
//services
ConfigUtility* configUtil = ServiceLocator<ConfigUtility>::Get();
SurfaceManager* surfaceMgr = ServiceLocator<SurfaceManager>::Get();
UDPNetworkUtility* netUtil = ServiceLocator<UDPNetworkUtility>::Get();
InformationManager* infoMgr = ServiceLocator<InformationManager>::Get();
//members
Button refreshButton;
+2
View File
@@ -92,6 +92,7 @@ void SceneManager::Init() {
//instanciate the remaining services
surfaceMgr = ServiceLocator<SurfaceManager>::Set(new SurfaceManager());
netUtil = ServiceLocator<UDPNetworkUtility>::Set(new UDPNetworkUtility());
infoMgr = ServiceLocator<InformationManager>::Set(new InformationManager());
//initiate the remaining services
netUtil->Open(0, sizeof(Packet));
@@ -144,6 +145,7 @@ void SceneManager::Quit() {
configUtil = ServiceLocator<ConfigUtility>::Set(nullptr);
surfaceMgr = ServiceLocator<SurfaceManager>::Set(nullptr);
netUtil = ServiceLocator<UDPNetworkUtility>::Set(nullptr);
infoMgr = ServiceLocator<InformationManager>::Set(nullptr);
//clean up the scene
UnloadScene();
+2
View File
@@ -26,6 +26,7 @@
#include "base_scene.hpp"
#include "service_locator.hpp"
#include "packet_type.hpp"
#include "information_manager.hpp"
#include "config_utility.hpp"
#include "surface_manager.hpp"
@@ -53,6 +54,7 @@ private:
ConfigUtility* configUtil = nullptr;
SurfaceManager* surfaceMgr = nullptr;
UDPNetworkUtility* netUtil = nullptr;
InformationManager* infoMgr = nullptr;
};
#endif