From c0210325125fd0298e00300e0ae5e258e3476c9b Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 14 Jun 2014 22:37:21 +1000 Subject: [PATCH 1/3] The character is visible, fixed a database issue --- client/in_world.cpp | 1 - client/lobby_menu.cpp | 8 +++++++- client/main_menu.cpp | 10 ++++++++++ common/network/packet/serial_packet_base.hpp | 4 ++-- common/network/serial/serial_client.cpp | 8 ++++---- server/server_application.cpp | 17 +++++++++++++---- 6 files changed, 36 insertions(+), 12 deletions(-) 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; From a23fbbfb381df6f68321eafc7d8eb3fc32327110 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 14 Jun 2014 23:13:11 +1000 Subject: [PATCH 2/3] Characters are working correctly again --- client/in_world.cpp | 13 +++++++++++-- client/main_menu.cpp | 9 +-------- makefile | 2 +- server/server_application.cpp | 8 -------- todo.txt | 1 + 5 files changed, 14 insertions(+), 19 deletions(-) diff --git a/client/in_world.cpp b/client/in_world.cpp index b5cc028..76435c8 100644 --- a/client/in_world.cpp +++ b/client/in_world.cpp @@ -128,7 +128,7 @@ void InWorld::RenderFrame() { } void InWorld::Render(SDL_Surface* const screen) { - //draw the map0 + //draw the map for (std::list::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); it++) { tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y); } @@ -185,6 +185,7 @@ void InWorld::KeyDown(SDL_KeyboardEvent const& key) { case SDLK_LEFT: if (localCharacter) { localCharacter->motion.x -= CHARACTER_WALKING_SPEED; + localCharacter->CorrectSprite(); SendPlayerUpdate(); } break; @@ -192,6 +193,7 @@ void InWorld::KeyDown(SDL_KeyboardEvent const& key) { case SDLK_RIGHT: if (localCharacter) { localCharacter->motion.x += CHARACTER_WALKING_SPEED; + localCharacter->CorrectSprite(); SendPlayerUpdate(); } break; @@ -199,6 +201,7 @@ void InWorld::KeyDown(SDL_KeyboardEvent const& key) { case SDLK_UP: if (localCharacter) { localCharacter->motion.y -= CHARACTER_WALKING_SPEED; + localCharacter->CorrectSprite(); SendPlayerUpdate(); } break; @@ -206,6 +209,7 @@ void InWorld::KeyDown(SDL_KeyboardEvent const& key) { case SDLK_DOWN: if (localCharacter) { localCharacter->motion.y += CHARACTER_WALKING_SPEED; + localCharacter->CorrectSprite(); SendPlayerUpdate(); } break; @@ -218,6 +222,7 @@ void InWorld::KeyUp(SDL_KeyboardEvent const& key) { case SDLK_LEFT: if (localCharacter) { localCharacter->motion.x += CHARACTER_WALKING_SPEED; + localCharacter->CorrectSprite(); SendPlayerUpdate(); } break; @@ -225,6 +230,7 @@ void InWorld::KeyUp(SDL_KeyboardEvent const& key) { case SDLK_RIGHT: if (localCharacter) { localCharacter->motion.x -= CHARACTER_WALKING_SPEED; + localCharacter->CorrectSprite(); SendPlayerUpdate(); } break; @@ -232,6 +238,7 @@ void InWorld::KeyUp(SDL_KeyboardEvent const& key) { case SDLK_UP: if (localCharacter) { localCharacter->motion.y += CHARACTER_WALKING_SPEED; + localCharacter->CorrectSprite(); SendPlayerUpdate(); } break; @@ -239,6 +246,7 @@ void InWorld::KeyUp(SDL_KeyboardEvent const& key) { case SDLK_DOWN: if (localCharacter) { localCharacter->motion.y -= CHARACTER_WALKING_SPEED; + localCharacter->CorrectSprite(); SendPlayerUpdate(); } break; @@ -297,7 +305,8 @@ void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) { character.CorrectSprite(); //catch this client's player object - if (argPacket->characterIndex == characterIndex && !localCharacter) { + if (argPacket->accountIndex == accountIndex && !localCharacter) { + characterIndex = argPacket->characterIndex; localCharacter = &character; //setup the camera diff --git a/client/main_menu.cpp b/client/main_menu.cpp index c33766c..457bd12 100644 --- a/client/main_menu.cpp +++ b/client/main_menu.cpp @@ -21,11 +21,6 @@ */ #include "main_menu.hpp" -#include - -using std::cout; -using std::endl; - //------------------------- //Public access members //------------------------- @@ -60,9 +55,7 @@ MainMenu::MainMenu(ConfigUtility* const argConfig): quitButton.SetText("Quit"); //debug - cout << config["client.username"] << endl; - cout << config["client.handle"] << endl; - cout << config["client.avatar"] << endl; + // } MainMenu::~MainMenu() { diff --git a/makefile b/makefile index aaf0418..080a22d 100644 --- a/makefile +++ b/makefile @@ -3,7 +3,7 @@ #MKDIR=mkdir #RM=del /y -CXXFLAGS+=-static-libgcc -static-libstdc++ -g +CXXFLAGS+=-static-libgcc -static-libstdc++ export diff --git a/server/server_application.cpp b/server/server_application.cpp index 9aee4c8..4bc1644 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -29,9 +29,6 @@ #include #include -using std::cout; -using std::endl; - //------------------------- //public methods //------------------------- @@ -244,8 +241,6 @@ 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; @@ -273,7 +268,6 @@ 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 @@ -287,10 +281,8 @@ 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; }); diff --git a/todo.txt b/todo.txt index 4feb30b..d9279d1 100644 --- a/todo.txt +++ b/todo.txt @@ -1,3 +1,4 @@ +TODO: rename restart scene to cleanup scene TODO: encapsulate the data structures TODO: Get the rooms working From bd5e57401e1a5321fb6c852a8b391e3662286015 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 14 Jun 2014 23:27:33 +1000 Subject: [PATCH 3/3] Minor comment tweaks --- client/in_world.cpp | 2 +- common/gameplay/combat_data.hpp | 2 +- common/network/serial/serial.cpp | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/client/in_world.cpp b/client/in_world.cpp index 76435c8..abd311e 100644 --- a/client/in_world.cpp +++ b/client/in_world.cpp @@ -338,7 +338,7 @@ void InWorld::HandleCharacterUpdate(CharacterPacket* const argPacket) { CharacterData& character = characterMap[argPacket->characterIndex]; - //TODO: review this + //other characters moving if (argPacket->characterIndex != characterIndex) { character.roomIndex = argPacket->roomIndex; character.origin = argPacket->origin; diff --git a/common/gameplay/combat_data.hpp b/common/gameplay/combat_data.hpp index 3c45b78..b170e5f 100644 --- a/common/gameplay/combat_data.hpp +++ b/common/gameplay/combat_data.hpp @@ -43,7 +43,7 @@ struct CombatData { enum class Terrain { - //TODO: types of terrains + //TODO: types of combat terrains NONE = 0, GRASSLANDS, }; diff --git a/common/network/serial/serial.cpp b/common/network/serial/serial.cpp index 1e76e4b..791da27 100644 --- a/common/network/serial/serial.cpp +++ b/common/network/serial/serial.cpp @@ -73,7 +73,6 @@ void serializePacket(SerialPacketBase* packet, void* buffer) { case SerialPacketType::COMBAT_DELETE: case SerialPacketType::COMBAT_UPDATE: - //TODO: is this the best fit? case SerialPacketType::COMBAT_ENTER_REQUEST: case SerialPacketType::COMBAT_ENTER_RESPONSE: case SerialPacketType::COMBAT_EXIT_REQUEST: