From ace87b438b63166cc71251e5b6dc2b203ec30013 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 16 Nov 2014 22:53:11 +1100 Subject: [PATCH] Began working changes into lobby --- client/client_utilities/makefile | 37 --------------------------- client/makefile | 5 ++-- client/scenes/in_world.hpp | 1 - client/scenes/lobby_menu.cpp | 37 +++++++++++++++++++++++++-- client/scenes/lobby_menu.hpp | 3 +++ client/scenes/makefile | 2 +- common/network/serial_packet_type.hpp | 1 + common/network/serial_utility.cpp | 2 ++ todo.txt | 5 ++++ 9 files changed, 49 insertions(+), 44 deletions(-) delete mode 100644 client/client_utilities/makefile diff --git a/client/client_utilities/makefile b/client/client_utilities/makefile deleted file mode 100644 index 4a01dcd..0000000 --- a/client/client_utilities/makefile +++ /dev/null @@ -1,37 +0,0 @@ -#config -INCLUDES+=. -LIBS+= -CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) - -#source -CXXSRC=$(wildcard *.cpp) - -#objects -OBJDIR=obj -OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) - -#output -OUTDIR=.. -OUT=$(addprefix $(OUTDIR)/,client.a) - -#targets -all: $(OBJ) $(OUT) - ar -crs $(OUT) $(OBJ) - -$(OBJ): | $(OBJDIR) - -$(OUT): | $(OUTDIR) - -$(OBJDIR): - mkdir $(OBJDIR) - -$(OUTDIR): - mkdir $(OUTDIR) - -$(OBJDIR)/%.o: %.cpp - $(CXX) $(CXXFLAGS) -c -o $@ $< - -clean: - $(RM) *.o *.a *.exe - -rebuild: clean all diff --git a/client/makefile b/client/makefile index 39c104f..d7adf5a 100644 --- a/client/makefile +++ b/client/makefile @@ -1,5 +1,5 @@ #include directories -INCLUDES+=. client_utilities renderable scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet_types ../common/ui ../common/utilities +INCLUDES+=. entities scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet_types ../common/ui ../common/utilities #libraries #the order of the $(LIBS) is important, at least for MinGW @@ -25,9 +25,8 @@ OUT=$(addprefix $(OUTDIR)/,client) #targets all: $(OBJ) $(OUT) - $(MAKE) -C client_utilities + $(MAKE) -C entities $(MAKE) -C scenes - $(MAKE) -C renderable $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) $(OBJ): | $(OBJDIR) diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index 7f2e078..e995868 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -40,7 +40,6 @@ #include "base_character.hpp" #include "base_monster.hpp" -#include "local_character.hpp" //client #include "base_scene.hpp" diff --git a/client/scenes/lobby_menu.cpp b/client/scenes/lobby_menu.cpp index c679f96..3fbc1c1 100644 --- a/client/scenes/lobby_menu.cpp +++ b/client/scenes/lobby_menu.cpp @@ -190,15 +190,25 @@ void LobbyMenu::KeyUp(SDL_KeyboardEvent const& key) { void LobbyMenu::HandlePacket(SerialPacket* const argPacket) { switch(argPacket->type) { + //responses case SerialPacketType::BROADCAST_RESPONSE: HandleBroadcastResponse(static_cast(argPacket)); break; case SerialPacketType::JOIN_RESPONSE: HandleJoinResponse(static_cast(argPacket)); break; + case SerialPacketType::LOGIN_RESPONSE: + HandleLoginResponse(static_cast(argPacket)); + break; + + //rejections case SerialPacketType::JOIN_REJECTION: HandleJoinRejection(static_cast(argPacket)); break; + case SerialPacketType::LOGIN_REJECTION: + HandleLoginRejection(static_cast(argPacket)); + break; + //handle errors default: throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in LobbyMenu: " + to_string_custom(static_cast(argPacket->type)) )); @@ -222,9 +232,19 @@ void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) { } void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) { + //save the server's data clientIndex = argPacket->clientIndex; - accountIndex = argPacket->accountIndex; network.Bind(argPacket->srcAddress, Channels::SERVER); + + //request login data + SendLoginRequest(); +} + +void LobbyMenu::HandleLoginResponse(ClientPacket* const argPacket) { + if (argPacket->clientIndex != clientIndex) { + throw(std::runtime_error("Client index invalid during login")); + } + accountIndex = argPacket->accountIndex; SetNextScene(SceneList::INWORLD); } @@ -232,6 +252,10 @@ void LobbyMenu::HandleJoinRejection(TextPacket* const argPacket) { //TODO: Better output for join rejection } +void LobbyMenu::HandleLoginRejection(TextPacket* const argPacket) { + //TODO: Better output for login rejection +} + //------------------------- //server control //------------------------- @@ -251,9 +275,18 @@ void LobbyMenu::SendJoinRequest() { //pack the packet ClientPacket packet; packet.type = SerialPacketType::JOIN_REQUEST; - strncpy(packet.username, config["client.username"].c_str(), PACKET_STRING_SIZE); //join the selected server network.SendTo(selection->address, &packet); selection = nullptr; } + +void LobbyMenu::SendLoginRequest() { + //NOTE: high cohesion + ClientPacket packet; + packet.type = SerialPacketType::LOGIN_REQUEST; + packet.clientIndex = clientIndex; + strncpy(packet.username, config["client.username"].c_str(), PACKET_STRING_SIZE); + + network.SendTo(Channels::SERVER, &packet); +} diff --git a/client/scenes/lobby_menu.hpp b/client/scenes/lobby_menu.hpp index 1959c56..b8e5347 100644 --- a/client/scenes/lobby_menu.hpp +++ b/client/scenes/lobby_menu.hpp @@ -63,11 +63,14 @@ protected: void HandlePacket(SerialPacket* const); void HandleBroadcastResponse(ServerPacket* const); void HandleJoinResponse(ClientPacket* const); + void HandleLoginResponse(ClientPacket* const); void HandleJoinRejection(TextPacket* const); + void HandleLoginRejection(TextPacket* const); //server control void SendBroadcastRequest(); void SendJoinRequest(); + void SendLoginRequest(); //shared parameters ConfigUtility& config = ConfigUtility::GetSingleton(); diff --git a/client/scenes/makefile b/client/scenes/makefile index 7a59128..73a4950 100644 --- a/client/scenes/makefile +++ b/client/scenes/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. .. ../renderable ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities +INCLUDES+=. .. ../entities ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/common/network/serial_packet_type.hpp b/common/network/serial_packet_type.hpp index e6637af..d40a264 100644 --- a/common/network/serial_packet_type.hpp +++ b/common/network/serial_packet_type.hpp @@ -115,6 +115,7 @@ enum class SerialPacketType { //rejection/error messages JOIN_REJECTION, + LOGIN_REJECTION, CHARACTER_REJECTION, SHUTDOWN_REJECTION, diff --git a/common/network/serial_utility.cpp b/common/network/serial_utility.cpp index fe2e87e..ddad0e7 100644 --- a/common/network/serial_utility.cpp +++ b/common/network/serial_utility.cpp @@ -81,6 +81,7 @@ void serializePacket(void* buffer, SerialPacketBase* packet) { break; case SerialPacketType::TEXT_BROADCAST: case SerialPacketType::JOIN_REJECTION: + case SerialPacketType::LOGIN_REJECTION: case SerialPacketType::CHARACTER_REJECTION: case SerialPacketType::SHUTDOWN_REJECTION: serializeText(buffer, static_cast(packet)); @@ -129,6 +130,7 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) { break; case SerialPacketType::TEXT_BROADCAST: case SerialPacketType::JOIN_REJECTION: + case SerialPacketType::LOGIN_REJECTION: case SerialPacketType::CHARACTER_REJECTION: case SerialPacketType::SHUTDOWN_REJECTION: deserializeText(buffer, static_cast(packet)); diff --git a/todo.txt b/todo.txt index b31ad34..7fd4030 100644 --- a/todo.txt +++ b/todo.txt @@ -24,3 +24,8 @@ The Entity base class handles position (including room) and motion, so something entity: +------------------------- + +Lobby: + JOIN_REQUEST -> JOIN_RESPONSE, JOIN_REJECTION + LOGIN_REQUEST -> LOGIN_RESPONSE, LOGIN_REJECTION \ No newline at end of file