From 1beb7cbd5dcde77122281f63bc18f59847e02283 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 6 May 2014 21:35:07 +1000 Subject: [PATCH] Began adding basic authentication --- client/client_application.cpp | 4 ++-- client/client_application.hpp | 1 + client/scenes/in_world.cpp | 10 +++++++--- client/scenes/in_world.hpp | 3 ++- client/scenes/lobby_menu.cpp | 4 +++- client/scenes/lobby_menu.hpp | 3 ++- common/network/serial.cpp | 4 ++++ common/network/serial_packet.hpp | 5 +++-- 8 files changed, 24 insertions(+), 10 deletions(-) diff --git a/client/client_application.cpp b/client/client_application.cpp index 73a0ba1..297a903 100644 --- a/client/client_application.cpp +++ b/client/client_application.cpp @@ -119,10 +119,10 @@ void ClientApplication::LoadScene(SceneList sceneIndex) { activeScene = new OptionsMenu(&config); break; case SceneList::LOBBYMENU: - activeScene = new LobbyMenu(&config, &network, &clientIndex, &characterIndex); + activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex, &characterIndex); break; case SceneList::INWORLD: - activeScene = new InWorld(&config, &network, &clientIndex, &characterIndex); + activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex); break; case SceneList::INCOMBAT: activeScene = new InCombat(); diff --git a/client/client_application.hpp b/client/client_application.hpp index daf2c16..b6b3b31 100644 --- a/client/client_application.hpp +++ b/client/client_application.hpp @@ -48,6 +48,7 @@ private: ConfigUtility config; UDPNetworkUtility network; int clientIndex = -1; + int accountIndex = -1; int characterIndex = -1; }; diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 6d43e9d..614da3d 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -31,10 +31,11 @@ //Public access members //------------------------- -InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argCharacterIndex): +InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argAccountIndex, int* const argCharacterIndex): config(*argConfig), network(*argNetwork), clientIndex(*argClientIndex), + accountIndex(*argAccountIndex), characterIndex(*argCharacterIndex) { //setup the utility objects @@ -67,6 +68,7 @@ InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNet char buffer[PACKET_STRING_SIZE]; packet.meta.type = SerialPacket::Type::SYNCHRONIZE; packet.clientInfo.clientIndex = clientIndex; + packet.clientInfo.accountIndex = accountIndex; packet.clientInfo.characterIndex = characterIndex; serialize(&packet, buffer); network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE); @@ -271,6 +273,7 @@ void InWorld::HandlePacket(SerialPacket packet) { void InWorld::HandleDisconnect(SerialPacket packet) { network.Unbind(Channels::SERVER); clientIndex = -1; + accountIndex = -1; characterIndex = -1; SetNextScene(SceneList::MAINMENU); } @@ -347,6 +350,7 @@ void InWorld::SendPlayerUpdate() { //pack the packet packet.meta.type = SerialPacket::Type::CHARACTER_UPDATE; packet.characterInfo.clientIndex = clientIndex; + packet.characterInfo.accountIndex = accountIndex; packet.characterInfo.characterIndex = characterIndex; packet.characterInfo.position = localCharacter->GetPosition(); packet.characterInfo.motion = localCharacter->GetMotion(); @@ -361,7 +365,7 @@ void InWorld::RequestDisconnect() { //send a disconnect request packet.meta.type = SerialPacket::Type::DISCONNECT; - packet.clientInfo.clientIndex = clientIndex; + packet.clientInfo.accountIndex = accountIndex; serialize(&packet, buffer); network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE); } @@ -372,7 +376,7 @@ void InWorld::RequestShutDown() { //send a shutdown request packet.meta.type = SerialPacket::Type::SHUTDOWN; - packet.clientInfo.clientIndex = clientIndex; + packet.clientInfo.accountIndex = accountIndex; serialize(&packet, buffer); network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE); } diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index 3a9088e..0b30f5f 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -52,7 +52,7 @@ class InWorld : public BaseScene { public: //Public access members - InWorld(ConfigUtility* const, UDPNetworkUtility* const, int* const, int* const); + InWorld(ConfigUtility* const, UDPNetworkUtility* const, int* const, int* const, int* const); ~InWorld(); protected: @@ -92,6 +92,7 @@ protected: ConfigUtility& config; UDPNetworkUtility& network; int& clientIndex; + int& accountIndex; int& characterIndex; //graphics diff --git a/client/scenes/lobby_menu.cpp b/client/scenes/lobby_menu.cpp index bd92038..b1f8178 100644 --- a/client/scenes/lobby_menu.cpp +++ b/client/scenes/lobby_menu.cpp @@ -30,10 +30,11 @@ //Public access members //------------------------- -LobbyMenu::LobbyMenu(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argCharacterIndex): +LobbyMenu::LobbyMenu(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argAccountIndex, int* const argCharacterIndex): config(*argConfig), network(*argNetwork), clientIndex(*argClientIndex), + accountIndex(*argAccountIndex), characterIndex(*argCharacterIndex) { //setup the utility objects @@ -221,6 +222,7 @@ void LobbyMenu::HandlePacket(SerialPacket packet) { break; case SerialPacket::Type::JOIN_RESPONSE: clientIndex = packet.clientInfo.clientIndex; + accountIndex = packet.clientInfo.accountIndex; characterIndex = packet.clientInfo.characterIndex; network.Bind(&packet.meta.srcAddress, Channels::SERVER); SetNextScene(SceneList::INWORLD); diff --git a/client/scenes/lobby_menu.hpp b/client/scenes/lobby_menu.hpp index a74f3db..7b6c8a9 100644 --- a/client/scenes/lobby_menu.hpp +++ b/client/scenes/lobby_menu.hpp @@ -42,7 +42,7 @@ class LobbyMenu : public BaseScene { public: //Public access members - LobbyMenu(ConfigUtility* const, UDPNetworkUtility* const, int* const, int* const); + LobbyMenu(ConfigUtility* const, UDPNetworkUtility* const, int* const, int* const, int* const); ~LobbyMenu(); protected: @@ -65,6 +65,7 @@ protected: ConfigUtility& config; UDPNetworkUtility& network; int& clientIndex; + int& accountIndex; int& characterIndex; //members diff --git a/common/network/serial.cpp b/common/network/serial.cpp index 7df8793..af527ef 100644 --- a/common/network/serial.cpp +++ b/common/network/serial.cpp @@ -54,6 +54,7 @@ void serializeClient(SerialPacket* packet, char* buffer) { //indexes SERIALIZE(buffer, &packet->clientInfo.clientIndex, sizeof(int)); + SERIALIZE(buffer, &packet->clientInfo.accountIndex, sizeof(int)); SERIALIZE(buffer, &packet->clientInfo.characterIndex, sizeof(int)); //texts @@ -95,6 +96,7 @@ void serializeCharacter(SerialPacket* packet, char* buffer) { //indexes SERIALIZE(buffer, &packet->characterInfo.clientIndex, sizeof(int)); + SERIALIZE(buffer, &packet->characterInfo.accountIndex, sizeof(int)); SERIALIZE(buffer, &packet->characterInfo.characterIndex, sizeof(int)); //texts @@ -130,6 +132,7 @@ void deserializeClient(SerialPacket* packet, char* buffer) { //indexes DESERIALIZE(buffer, &packet->clientInfo.clientIndex, sizeof(int)); + DESERIALIZE(buffer, &packet->clientInfo.accountIndex, sizeof(int)); DESERIALIZE(buffer, &packet->clientInfo.characterIndex, sizeof(int)); //texts @@ -178,6 +181,7 @@ void deserializeCharacter(SerialPacket* packet, char* buffer) { //indexes DESERIALIZE(buffer, &packet->characterInfo.clientIndex, sizeof(int)); + DESERIALIZE(buffer, &packet->characterInfo.accountIndex, sizeof(int)); DESERIALIZE(buffer, &packet->characterInfo.characterIndex, sizeof(int)); //texts diff --git a/common/network/serial_packet.hpp b/common/network/serial_packet.hpp index 7da184a..29f4af1 100644 --- a/common/network/serial_packet.hpp +++ b/common/network/serial_packet.hpp @@ -27,7 +27,7 @@ #include "SDL/SDL_net.h" -#define NETWORK_VERSION 20140428 +#define NETWORK_VERSION 20140506 #define PACKET_STRING_SIZE 100 #pragma pack(push, 0) @@ -88,8 +88,8 @@ union SerialPacket { //information about the client struct ClientInformation { Metadata meta; - //TODO: change clientIndex to accountIndex for player ID int clientIndex; + int accountIndex; int characterIndex; char username[PACKET_STRING_SIZE]; char handle[PACKET_STRING_SIZE]; @@ -108,6 +108,7 @@ union SerialPacket { struct CharacterInformation { Metadata meta; int clientIndex; + int accountIndex; int characterIndex; char handle[PACKET_STRING_SIZE]; char avatar[PACKET_STRING_SIZE];