diff --git a/client/in_world.cpp b/client/in_world.cpp index 3acad2f..b5cc028 100644 --- a/client/in_world.cpp +++ b/client/in_world.cpp @@ -301,7 +301,6 @@ void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) { localCharacter = &character; //setup the camera - //TODO: can't change the screen size? camera.width = GetScreen()->w; camera.height = GetScreen()->h; diff --git a/client/lobby_menu.cpp b/client/lobby_menu.cpp index facfa9f..8cbf55a 100644 --- a/client/lobby_menu.cpp +++ b/client/lobby_menu.cpp @@ -238,5 +238,11 @@ void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) { network.Bind(&argPacket->srcAddress, Channels::SERVER); SetNextScene(SceneList::INWORLD); - //TODO: send this player's character info + //send this player's character info + CharacterPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_NEW; + strncpy(newPacket.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE); + strncpy(newPacket.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE); + newPacket.accountIndex = accountIndex; + network.SendTo(Channels::SERVER, &newPacket); } \ No newline at end of file diff --git a/client/main_menu.cpp b/client/main_menu.cpp index b5d633e..c33766c 100644 --- a/client/main_menu.cpp +++ b/client/main_menu.cpp @@ -21,6 +21,11 @@ */ #include "main_menu.hpp" +#include + +using std::cout; +using std::endl; + //------------------------- //Public access members //------------------------- @@ -53,6 +58,11 @@ MainMenu::MainMenu(ConfigUtility* const argConfig): startButton.SetText("Start"); optionsButton.SetText("Options"); quitButton.SetText("Quit"); + + //debug + cout << config["client.username"] << endl; + cout << config["client.handle"] << endl; + cout << config["client.avatar"] << endl; } MainMenu::~MainMenu() { diff --git a/common/network/packet/serial_packet_base.hpp b/common/network/packet/serial_packet_base.hpp index b84816e..156d1e5 100644 --- a/common/network/packet/serial_packet_base.hpp +++ b/common/network/packet/serial_packet_base.hpp @@ -30,8 +30,8 @@ #include "SDL/SDL_net.h" -#define NETWORK_VERSION 20140607 -#define PACKET_STRING_SIZE 100 +constexpr int NETWORK_VERSION = 20140607; +constexpr int PACKET_STRING_SIZE = 100; struct SerialPacketBase { //members diff --git a/common/network/serial/serial_client.cpp b/common/network/serial/serial_client.cpp index c96449d..96bc881 100644 --- a/common/network/serial/serial_client.cpp +++ b/common/network/serial/serial_client.cpp @@ -28,8 +28,8 @@ void serializeClient(ClientPacket* packet, void* buffer) { SERIALIZE(buffer, &packet->clientIndex, sizeof(int)); SERIALIZE(buffer, &packet->accountIndex, sizeof(int)); - SERIALIZE(buffer, &packet->username, sizeof(PACKET_STRING_SIZE)); -// SERIALIZE(buffer, &packet->password, sizeof(PACKET_STRING_SIZE)); + SERIALIZE(buffer, &packet->username, PACKET_STRING_SIZE); +// SERIALIZE(buffer, &packet->password, PACKET_STRING_SIZE); } void deserializeClient(ClientPacket* packet, void* buffer) { @@ -37,6 +37,6 @@ void deserializeClient(ClientPacket* packet, void* buffer) { DESERIALIZE(buffer, &packet->clientIndex, sizeof(int)); DESERIALIZE(buffer, &packet->accountIndex, sizeof(int)); - DESERIALIZE(buffer, &packet->username, sizeof(PACKET_STRING_SIZE)); -// DESERIALIZE(buffer, &packet->password, sizeof(PACKET_STRING_SIZE)); + DESERIALIZE(buffer, &packet->username, PACKET_STRING_SIZE); +// DESERIALIZE(buffer, &packet->password, PACKET_STRING_SIZE); } diff --git a/server/server_application.cpp b/server/server_application.cpp index 4c576f5..9aee4c8 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -29,6 +29,9 @@ #include #include +using std::cout; +using std::endl; + //------------------------- //public methods //------------------------- @@ -233,7 +236,7 @@ void ServerApplication::HandleBroadcastRequest(SerialPacket* const argPacket) { ServerPacket newPacket; newPacket.type = SerialPacketType::BROADCAST_RESPONSE; - snprintf(newPacket.name, PACKET_STRING_SIZE, "%s", config["server.name"].c_str()); + strncpy(newPacket.name, config["server.name"].c_str(), PACKET_STRING_SIZE); newPacket.playerCount = characterMgr.GetContainer()->size(); newPacket.version = NETWORK_VERSION; @@ -241,6 +244,8 @@ void ServerApplication::HandleBroadcastRequest(SerialPacket* const argPacket) { } void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) { + cout << "Attempting connection: " << argPacket->username << endl; + //create the new client ClientData newClient; newClient.address = argPacket->srcAddress; @@ -268,6 +273,7 @@ void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) { } void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) { + cout << "Trying to disconnect account " << argPacket->accountIndex << endl; //TODO: authenticate who is disconnecting/kicking //forward to the specified client @@ -281,8 +287,10 @@ void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) { characterMgr.UnloadCharacterIf([&](std::map::iterator it) -> bool { if (argPacket->accountIndex == it->second.owner) { PumpCharacterUnload(it->first); + cout << "Deleting character " << it->first << endl; return true; } + cout << "Not deleting character " << it->first << endl; return false; }); @@ -338,7 +346,8 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) { //------------------------- void ServerApplication::HandleCharacterNew(CharacterPacket* const argPacket) { - int characterIndex = characterMgr.CreateCharacter(argPacket->accountIndex, argPacket->handle, argPacket->avatar); + //NOTE: misnomer, try to load the character first + int characterIndex = characterMgr.LoadCharacter(argPacket->accountIndex, argPacket->handle, argPacket->avatar); if (characterIndex == -1) { //TODO: rejection packet @@ -478,8 +487,8 @@ void ServerApplication::CopyCharacterToPacket(CharacterPacket* const packet, int //TODO: keep this up to date when the character changes packet->characterIndex = characterIndex; - snprintf(packet->handle, PACKET_STRING_SIZE, "%s", character->handle.c_str()); - snprintf(packet->avatar, PACKET_STRING_SIZE, "%s", character->avatar.c_str()); + strncpy(packet->handle, character->handle.c_str(), PACKET_STRING_SIZE); + strncpy(packet->avatar, character->avatar.c_str(), PACKET_STRING_SIZE); packet->accountIndex = character->owner; packet->roomIndex = character->roomIndex; packet->origin = character->origin;