diff --git a/client/information_manager.hpp b/client/information_manager.hpp new file mode 100644 index 0000000..6d48546 --- /dev/null +++ b/client/information_manager.hpp @@ -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 diff --git a/client/lobby.cpp b/client/lobby.cpp index 87bbf09..5990e28 100644 --- a/client/lobby.cpp +++ b/client/lobby.cpp @@ -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(&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); } \ No newline at end of file diff --git a/client/lobby.hpp b/client/lobby.hpp index 8a83940..1fe27f6 100644 --- a/client/lobby.hpp +++ b/client/lobby.hpp @@ -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::Get(); SurfaceManager* surfaceMgr = ServiceLocator::Get(); UDPNetworkUtility* netUtil = ServiceLocator::Get(); + InformationManager* infoMgr = ServiceLocator::Get(); //members Button refreshButton; diff --git a/client/scene_manager.cpp b/client/scene_manager.cpp index 2d46ba4..a0e6294 100644 --- a/client/scene_manager.cpp +++ b/client/scene_manager.cpp @@ -92,6 +92,7 @@ void SceneManager::Init() { //instanciate the remaining services surfaceMgr = ServiceLocator::Set(new SurfaceManager()); netUtil = ServiceLocator::Set(new UDPNetworkUtility()); + infoMgr = ServiceLocator::Set(new InformationManager()); //initiate the remaining services netUtil->Open(0, sizeof(Packet)); @@ -144,6 +145,7 @@ void SceneManager::Quit() { configUtil = ServiceLocator::Set(nullptr); surfaceMgr = ServiceLocator::Set(nullptr); netUtil = ServiceLocator::Set(nullptr); + infoMgr = ServiceLocator::Set(nullptr); //clean up the scene UnloadScene(); diff --git a/client/scene_manager.hpp b/client/scene_manager.hpp index f6e23fc..cfcd532 100644 --- a/client/scene_manager.hpp +++ b/client/scene_manager.hpp @@ -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 diff --git a/libs/common/defines.hpp b/libs/common/defines.hpp index 321bd39..3765ced 100644 --- a/libs/common/defines.hpp +++ b/libs/common/defines.hpp @@ -3,6 +3,9 @@ #include +#define GAME_CHANNEL 0 +#define CHAT_CHANNEL 1 + typedef std::chrono::high_resolution_clock Clock; #endif diff --git a/libs/common/packet_type.hpp b/libs/common/packet_type.hpp index d8af71a..bd62515 100644 --- a/libs/common/packet_type.hpp +++ b/libs/common/packet_type.hpp @@ -52,14 +52,11 @@ struct BroadcastResponse { struct JoinRequest { Metadata meta; - char playerHandle[PACKET_STRING_SIZE]; - char playerAvatar[PACKET_STRING_SIZE]; - //TODO: player data }; struct JoinResponse { Metadata meta; - int playerIndex; + int clientIndex; //resource list }; diff --git a/server/server_application.cpp b/server/server_application.cpp index 92957ef..7fdf66c 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -173,32 +173,22 @@ void ServerApplication::HandleConnection(JoinRequest& request) { return; } //create the containers - 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; + ClientData client = { uniqueIndex++ }; //bind the address client.channel = netUtil->Bind(&request.meta.address); //push this information clients[client.index] = client; - players[player.index] = player; //send the player their information Packet p; 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)); - //send it out to new players - //TODO + //pretty + cout << "New connection" << endl; + cout << "number of clients: " << clients.size() << endl; } \ No newline at end of file