diff --git a/client/base_scene.cpp b/client/base_scene.cpp index 03d7f4c..85dda51 100644 --- a/client/base_scene.cpp +++ b/client/base_scene.cpp @@ -103,3 +103,7 @@ void BaseScene::KeyDown(SDL_KeyboardEvent const& event) { void BaseScene::KeyUp(SDL_KeyboardEvent const& event) { //EMPTY } + +void BaseScene::TextInput(SDL_TextInputEvent const& event) { + //EMPTY +} diff --git a/client/base_scene.hpp b/client/base_scene.hpp index 877af3a..f15f32d 100644 --- a/client/base_scene.hpp +++ b/client/base_scene.hpp @@ -47,8 +47,9 @@ public: virtual void MouseWheel(SDL_MouseWheelEvent const& event); virtual void KeyDown(SDL_KeyboardEvent const& event); virtual void KeyUp(SDL_KeyboardEvent const& event); + virtual void TextInput(SDL_TextInputEvent const& event); - //TODO: (9) joystick and controller events + //TODO: joystick and controller events protected: //control diff --git a/client/client_application.cpp b/client/client_application.cpp index 7009125..bcf2441 100644 --- a/client/client_application.cpp +++ b/client/client_application.cpp @@ -188,6 +188,12 @@ void ClientApplication::Init(int argc, char* argv[]) { DEBUG_INTERNAL_VAR(MAX_PACKET_SIZE); DEBUG_INTERNAL_VAR(static_cast(SerialPacketType::LAST)); + //------------------------- + //BUGFIX + //------------------------- + + SDL_StopTextInput(); + //------------------------- //finalize the startup //------------------------- @@ -298,6 +304,10 @@ void ClientApplication::ProcessEvents() { activeScene->KeyUp(event.key); break; + case SDL_TEXTINPUT: + activeScene->TextInput(event.text); + break; + //TODO: (9) joystick and controller events //window events are handled internally diff --git a/client/scenes/lobby_menu.cpp b/client/scenes/lobby_menu.cpp index 7c8e385..c7ff713 100644 --- a/client/scenes/lobby_menu.cpp +++ b/client/scenes/lobby_menu.cpp @@ -68,6 +68,26 @@ LobbyMenu::LobbyMenu(int* const argClientIndex, int* const argAccountIndex): backButton.SetX(50); backButton.SetY(90); + //setup the text fields + username.SetText(GetRenderer(), font, WHITE, config["client.username"]); + password.SetText(GetRenderer(), font, WHITE, config["client.password"]); + handle.SetText(GetRenderer(), font, WHITE, config["client.handle"]); + avatar.SetText(GetRenderer(), font, WHITE, config["client.avatar"]); + + username.SetBounds(BoundingBox{0, 0, 300, 20}); + password.SetBounds(BoundingBox{0, 0, 300, 20}); + handle.SetBounds(BoundingBox{0, 0, 300, 20}); + avatar.SetBounds(BoundingBox{0, 0, 300, 20}); + + username.SetX(50); + username.SetY(110); + password.SetX(50); + password.SetY(130); + handle.SetX(50); + handle.SetY(150); + avatar.SetX(50); + avatar.SetY(170); + //pseudo-list selection //TODO: move this into the UI library? boundingBox = {300, 50, 200, 12}; @@ -115,6 +135,11 @@ void LobbyMenu::RenderFrame(SDL_Renderer* renderer) { joinButton.DrawTo(renderer); backButton.DrawTo(renderer); + username.DrawTo(renderer); + password.DrawTo(renderer); + handle.DrawTo(renderer); + avatar.DrawTo(renderer); + //TODO: (3) draw headers for the server list //TODO: (3) ping/delay displayed in the server list for (int i = 0; i < serverVector.size(); i++) { @@ -148,6 +173,35 @@ void LobbyMenu::MouseButtonDown(SDL_MouseButtonEvent const& event) { searchButton.MouseButtonDown(event); joinButton.MouseButtonDown(event); backButton.MouseButtonDown(event); + + if (username.MouseButtonDown(event)) { + //GUI trick + if (!username.GetText().compare(config["client.username"])) { + username.SetText(GetRenderer(), font, WHITE, ""); + } + SDL_StartTextInput(); + } + if (password.MouseButtonDown(event)) { + //GUI trick + if (!password.GetText().compare(config["client.password"])) { + password.SetText(GetRenderer(), font, WHITE, ""); + } + SDL_StartTextInput(); + } + if (handle.MouseButtonDown(event)) { + //GUI trick + if (!handle.GetText().compare(config["client.handle"])) { + handle.SetText(GetRenderer(), font, WHITE, ""); + } + SDL_StartTextInput(); + } + if (avatar.MouseButtonDown(event)) { + //GUI trick + if (!avatar.GetText().compare(config["client.avatar"])) { + avatar.SetText(GetRenderer(), font, WHITE, ""); + } + SDL_StartTextInput(); + } } void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& event) { @@ -182,6 +236,22 @@ void LobbyMenu::KeyDown(SDL_KeyboardEvent const& event) { case SDLK_ESCAPE: SetSceneSignal(SceneSignal::MAINMENU); break; + + case SDLK_BACKSPACE: + //easier than mucking about with SDL_TextEditEvent + if (username.GetFocus()) { + username.PopChars(GetRenderer(), font, WHITE, 1); + } + if (password.GetFocus()) { + password.PopChars(GetRenderer(), font, WHITE, 1); + } + if (handle.GetFocus()) { + handle.PopChars(GetRenderer(), font, WHITE, 1); + } + if (avatar.GetFocus()) { + avatar.PopChars(GetRenderer(), font, WHITE, 1); + } + break; } } @@ -189,6 +259,21 @@ void LobbyMenu::KeyUp(SDL_KeyboardEvent const& event) { // } +void LobbyMenu::TextInput(SDL_TextInputEvent const& event) { + if (username.GetFocus()) { + username.PushText(GetRenderer(), font, WHITE, std::string(event.text)); + } + if (password.GetFocus()) { + password.PushText(GetRenderer(), font, WHITE, std::string(event.text)); + } + if (handle.GetFocus()) { + handle.PushText(GetRenderer(), font, WHITE, std::string(event.text)); + } + if (avatar.GetFocus()) { + avatar.PushText(GetRenderer(), font, WHITE, std::string(event.text)); + } +} + //------------------------- //Network handlers //------------------------- @@ -278,11 +363,19 @@ void LobbyMenu::HandleLoginResponse(ClientPacket* const argPacket) { } void LobbyMenu::HandleJoinRejection(TextPacket* const argPacket) { - //TODO: (9) LobbyMenu::HandleJoinRejection() + //NOTE: NEVER HAPPENS + throw(std::runtime_error("HandleJoinRejection")); } void LobbyMenu::HandleLoginRejection(TextPacket* const argPacket) { - //TODO: (9) LobbyMenu::HandleLoginRejection + config["client.disconnectMessage"] = std::string() + "Join request rejected: " + argPacket->text; + SetSceneSignal(SceneSignal::DISCONNECTEDSCREEN); + + //avoid crashes from the heartbeat system + ClientPacket newPacket; + newPacket.type = SerialPacketType::DISCONNECT_REQUEST; + newPacket.clientIndex = clientIndex; + network.SendTo(argPacket->srcAddress, &newPacket); } //------------------------- @@ -303,13 +396,14 @@ void LobbyMenu::SendBroadcastRequest() { } void LobbyMenu::SendJoinRequest() { + //BUG: 101 received in LobbyMenu on failed join //pack the packet - ClientPacket packet; - packet.type = SerialPacketType::JOIN_REQUEST; + ClientPacket packet; + packet.type = SerialPacketType::JOIN_REQUEST; - //join the selected server - network.SendTo(selection->address, &packet); - selection = nullptr; + //join the selected server + network.SendTo(selection->address, &packet); + selection = nullptr; } void LobbyMenu::SendLoginRequest() { @@ -318,7 +412,13 @@ void LobbyMenu::SendLoginRequest() { ClientPacket packet; packet.type = SerialPacketType::LOGIN_REQUEST; packet.clientIndex = clientIndex; - strncpy(packet.username, config["client.username"].c_str(), PACKET_STRING_SIZE+1); + strncpy(packet.username, username.GetText().c_str(), PACKET_STRING_SIZE+1); network.SendTo(Channels::SERVER, &packet); + + //TODO: remove + config["client.username"] = username.GetText(); + config["client.password"] = password.GetText(); + config["client.handle"] = handle.GetText(); + config["client.avatar"] = avatar.GetText(); } diff --git a/client/scenes/lobby_menu.hpp b/client/scenes/lobby_menu.hpp index a13b2da..4cb020d 100644 --- a/client/scenes/lobby_menu.hpp +++ b/client/scenes/lobby_menu.hpp @@ -25,6 +25,7 @@ #include "image.hpp" #include "button.hpp" #include "bounding_box.hpp" +#include "text_field.hpp" #include "text_line.hpp" #include "SDL2/SDL_ttf.h" @@ -61,6 +62,7 @@ protected: void MouseWheel(SDL_MouseWheelEvent const& event) override; void KeyDown(SDL_KeyboardEvent const& event) override; void KeyUp(SDL_KeyboardEvent const& event) override; + void TextInput(SDL_TextInputEvent const& event) override; //Network handlers void HandlePacket(SerialPacket* const); @@ -102,6 +104,10 @@ protected: Button searchButton; Button joinButton; Button backButton; + TextField username; + TextField password; + TextField handle; + TextField avatar; std::vector serverVector; ServerInfo* selection = nullptr; diff --git a/client/scenes/world.cpp b/client/scenes/world.cpp index b967d94..02682ea 100644 --- a/client/scenes/world.cpp +++ b/client/scenes/world.cpp @@ -154,7 +154,7 @@ void World::Update() { throw(e); } catch(std::exception& e) { - std::cerr << "HandlePacket Error: " << e.what() << std::endl; + std::cerr << "HandlePacket Error (" << (int)(reinterpret_cast(packetBuffer)->type) << "): " << e.what() << std::endl; } //free the buffer @@ -458,6 +458,10 @@ void World::HandlePacket(SerialPacket* const argPacket) { hCharacterMovement(static_cast(argPacket)); break; + case SerialPacketType::CHARACTER_REJECTION: + hCharacterRejection(static_cast(argPacket)); + break; + //creature management case SerialPacketType::CREATURE_UPDATE: hCreatureUpdate(static_cast(argPacket)); @@ -507,7 +511,6 @@ void World::HandlePacket(SerialPacket* const argPacket) { //general rejection messages case SerialPacketType::REGION_REJECTION: - case SerialPacketType::CHARACTER_REJECTION: case SerialPacketType::QUERY_REJECTION: throw(fatal_error(static_cast(argPacket)->text)); break; @@ -810,6 +813,18 @@ void World::hCharacterMovement(CharacterPacket* const argPacket) { } } +void World::hCharacterRejection(TextPacket* const argPacket) { + //NOTE: simply crap out + config["client.disconnectMessage"] = std::string() + "Character rejected: " + argPacket->text; + SetSceneSignal(SceneSignal::DISCONNECTEDSCREEN); + + //avoid crashes from the heartbeat system + ClientPacket newPacket; + newPacket.type = SerialPacketType::DISCONNECT_REQUEST; + newPacket.clientIndex = clientIndex; + network.SendTo(argPacket->srcAddress, &newPacket); +} + //------------------------- //creature management //------------------------- diff --git a/client/scenes/world.hpp b/client/scenes/world.hpp index 99e54c5..0e14249 100644 --- a/client/scenes/world.hpp +++ b/client/scenes/world.hpp @@ -102,6 +102,7 @@ private: void hCharacterUnload(CharacterPacket* const); void hQueryCharacterExists(CharacterPacket* const); void hCharacterMovement(CharacterPacket* const); + void hCharacterRejection(TextPacket* const); //creature management void hCreatureUpdate(CreaturePacket* const); diff --git a/common/network/makefile b/common/network/makefile index 6d8fa02..41a0042 100644 --- a/common/network/makefile +++ b/common/network/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. packet_types ../global_defines ../utilities ../../TurtleMap +INCLUDES+=. packet_types ../global_defines ../utilities ../../TurtleGUI ../../TurtleMap LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/common/network/packet_types/makefile b/common/network/packet_types/makefile index a4a8a85..c95abb2 100644 --- a/common/network/packet_types/makefile +++ b/common/network/packet_types/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. .. ../../global_defines ../../utilities ../../../TurtleMap +INCLUDES+=. .. ../../global_defines ../../utilities ../../../TurtleGUI ../../../TurtleMap LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/common/network/serial_packet.hpp b/common/network/serial_packet.hpp index 2f66e4b..9a1580d 100644 --- a/common/network/serial_packet.hpp +++ b/common/network/serial_packet.hpp @@ -34,7 +34,7 @@ typedef SerialPacketBase SerialPacket; //DOCS: NETWORK_VERSION is used to discern compatible servers and clients -constexpr int NETWORK_VERSION = 20160825; +constexpr int NETWORK_VERSION = 20161209; union MaxPacket { BarrierPacket a; diff --git a/common/utilities/bounding_box.hpp b/common/utilities/bounding_box.hpp deleted file mode 100644 index 06747b0..0000000 --- a/common/utilities/bounding_box.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2016 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#pragma once - -#include -#include - -class BoundingBox { -public: - //This is explicitly a POD - int x, y; - int w, h; - - BoundingBox() = default; - BoundingBox(int i, int j): x(i), y(j), w(0), h(0) {}; - BoundingBox(int i, int j, int k, int l): x(i), y(j), w(k), h(l) {}; - ~BoundingBox() = default; - BoundingBox& operator=(BoundingBox const&) = default; - - int Size() { - return std::max(w*h,0); - } - - bool CheckOverlap(BoundingBox rhs) { - return !( - x >= rhs.x + rhs.w || - y >= rhs.y + rhs.h || - rhs.x >= x + w || - rhs.y >= y + h); - } - - BoundingBox CalcOverlap(BoundingBox rhs) { - if (!CheckOverlap(rhs)) { - return {0, 0, 0, 0}; - } - BoundingBox ret; - ret.x = std::max(x, rhs.x); - ret.y = std::max(y, rhs.y); - ret.w = std::min(x+w, rhs.x+rhs.w) - ret.x; - ret.h = std::min(y+h, rhs.y+rhs.h) - ret.y; - return ret; - } -}; - -//This is explicitly a POD -static_assert(std::is_pod::value, "BoundingBox is not a POD"); - -#include "vector2.hpp" - -//operators -inline BoundingBox operator+(BoundingBox b, Vector2 v) { - return {b.x + (int)v.x, b.y + (int)v.y, b.w, b.h}; -} -inline BoundingBox operator+(Vector2 v, BoundingBox b) { - return b + v; -} diff --git a/common/utilities/file_hash.cpp b/common/utilities/file_hash.cpp new file mode 100644 index 0000000..c3fb203 --- /dev/null +++ b/common/utilities/file_hash.cpp @@ -0,0 +1,60 @@ +/* Copyright: (c) Kayne Ruse 2016 + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. +*/ +#include "file_hash.hpp" + +#include + +//hash a byte array into a 32-bit integer +unsigned fnv_hash_1a_32(void *key, int len) { + unsigned char *p = static_cast(key); + unsigned h = 0x811c9dc5; + for (int i = 0; i < len; i++) { + h = ( h ^ p[i] ) * 0x01000193; + } + return h; +} + +int getFileHash(std::string fname) { + std::ifstream is(fname, std::ios::in | std::ios::binary); + + //if the file doesn't exist, return a hash of -1 + if (!is.is_open()) { + return -1; + } + + //get the file size + is.seekg(0, std::ios_base::end); + int size = is.tellg(); + is.seekg(0); + + //create a buffer of that size + char buffer[size]; + + //load the data + is.read(buffer, size); + + //cleanup + is.close(); + + //finally, return the hash value + return fnv_hash_1a_32(buffer, size); +} diff --git a/common/utilities/file_hash.hpp b/common/utilities/file_hash.hpp new file mode 100644 index 0000000..06fa4db --- /dev/null +++ b/common/utilities/file_hash.hpp @@ -0,0 +1,26 @@ +/* Copyright: (c) Kayne Ruse 2016 + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. +*/ +#pragma once + +#include + +int getFileHash(std::string fname); \ No newline at end of file diff --git a/common/utilities/vector2.hpp b/common/utilities/vector2.hpp deleted file mode 100644 index ad0b17f..0000000 --- a/common/utilities/vector2.hpp +++ /dev/null @@ -1,111 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2016 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#pragma once - -#include -#include -#include - -class Vector2 { -public: - double x, y; - - Vector2() = default; - Vector2(double i, double j): x(i), y(j) {}; - ~Vector2() = default; - Vector2& operator=(Vector2 const&) = default; - - double Length() const { - return sqrt(x*x+y*y); - } - double SquaredLength() const { - return x*x+y*y; - } - void Normalize() { - double l = Length(); - if (l == 0) - throw(std::domain_error("Divide by zero")); - x /= l; - y /= l; - } - - //Arithmetic operators - Vector2 operator+(Vector2 v) const { - Vector2 ret; - ret.x = x + v.x; - ret.y = y + v.y; - return ret; - } - Vector2 operator-(Vector2 v) const { - Vector2 ret; - ret.x = x - v.x; - ret.y = y - v.y; - return ret; - } - Vector2 operator*(Vector2 v) const { - Vector2 ret; - ret.x = x * v.x; - ret.y = y * v.y; - return ret; - } - Vector2 operator*(double d) const { - Vector2 ret; - ret.x = x * d; - ret.y = y * d; - return ret; - } - - Vector2 operator/(Vector2 v) { - if (!v.x || !v.y) - throw(std::domain_error("Divide by zero")); - Vector2 ret; - ret.x = x / v.x; - ret.y = y / v.y; - return ret; - } - Vector2 operator/(double d) { - if (!d) - throw(std::domain_error("Divide by zero")); - Vector2 ret; - ret.x = x / d; - ret.y = y / d; - return ret; - } - - //unary operators - Vector2 operator-() { return {-x, -y}; } - - //comparison operators - bool operator==(Vector2 v) { return (x == v.x && y == v.y); } - bool operator!=(Vector2 v) { return (x != v.x || y != v.y); } - - //member templates (curry the above operators) - template Vector2 operator+=(T t) { return *this = *this + t; } - template Vector2 operator-=(T t) { return *this = *this - t; } - template Vector2 operator*=(T t) { return *this = *this * t; } - template Vector2 operator/=(T t) { return *this = *this / t; } - template bool operator==(T t) { return (x == t && y == t); } - template bool operator!=(T t) { return (x != t || y != t); } -}; - -//This is explicitly a POD -static_assert(std::is_pod::value, "Vector2 is not a POD"); diff --git a/instructions.txt b/instructions.txt index ef0103b..5878fc2 100644 --- a/instructions.txt +++ b/instructions.txt @@ -15,24 +15,16 @@ Instructions For Setup ------------------------- 1. To create a server, simply run server.exe - (a public server is provided by default) -2. To join a server, your player information must be input into rsc/config.cfg - (NOTE: This process will be streamlined later) -3. To change the config settings, open rsc/config.cfg -4. These settings must be unique for each player: + (a public server "Island Home" is provided by default) +2. To play, run client.exe +3. Your unique information should be inputted into the lobby screen, replacing + the default values. +4. There are currently two options for avatars: -* client.username -* client.handle +* character1.png #male +* character2.png #female -5. There are currently two options for 'client.avatar': - -* client.avatar = character1.png #male -* client.avatar = character2.png #female - -6. When you've correctly set these values, run client.exe, and select 'Start' - from the main menu; this displays the list of available servers. -7. Select the name of a server (default is 'Public') and select 'Join'. -8. Welcome to Tortuga, enjoy your stay. +5. Select a server, and click join. ------------------------- Linux Users diff --git a/rsc/config.cfg b/rsc/config.cfg index 1c2d90d..911f99a 100644 --- a/rsc/config.cfg +++ b/rsc/config.cfg @@ -15,6 +15,7 @@ server.dbname = database.db #client.screen.f = false #NOTE: fullscreen option is currently disabled client.username = username +client.password = password client.handle = handle client.avatar = character2.png diff --git a/server/barriers/makefile b/server/barriers/makefile index 46aa154..6e85c54 100644 --- a/server/barriers/makefile +++ b/server/barriers/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. .. ../characters ../creatures ../entities ../inventory ../../common/global_defines ../../common/utilities +INCLUDES+=. .. ../characters ../creatures ../entities ../inventory ../../common/global_defines ../../common/utilities ../../TurtleGUI LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/server/battles/makefile b/server/battles/makefile index 46aa154..6e85c54 100644 --- a/server/battles/makefile +++ b/server/battles/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. .. ../characters ../creatures ../entities ../inventory ../../common/global_defines ../../common/utilities +INCLUDES+=. .. ../characters ../creatures ../entities ../inventory ../../common/global_defines ../../common/utilities ../../TurtleGUI LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/server/characters/makefile b/server/characters/makefile index dc3efde..8898f30 100644 --- a/server/characters/makefile +++ b/server/characters/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. .. ../barriers ../battles ../creatures ../entities ../monsters ../inventory ../rooms ../triggers ../../common/global_defines ../../common/network ../../common/network/packet_types ../../common/utilities ../../TurtleMap +INCLUDES+=. .. ../barriers ../battles ../creatures ../entities ../monsters ../inventory ../rooms ../triggers ../../common/global_defines ../../common/network ../../common/network/packet_types ../../common/utilities ../../TurtleGUI ../../TurtleMap LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/server/creatures/makefile b/server/creatures/makefile index 872d58b..18a025e 100644 --- a/server/creatures/makefile +++ b/server/creatures/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. .. ../entities ../../common/global_defines ../../common/utilities +INCLUDES+=. .. ../entities ../../common/global_defines ../../common/utilities ../../TurtleGUI LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/server/entities/makefile b/server/entities/makefile index 1b92ad0..ba0f08e 100644 --- a/server/entities/makefile +++ b/server/entities/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. ../../common/utilities +INCLUDES+=. ../../common/utilities ../../TurtleGUI LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/server/rooms/makefile b/server/rooms/makefile index a226648..d0779e4 100644 --- a/server/rooms/makefile +++ b/server/rooms/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. .. ../barriers ../battles ../characters ../creatures ../entities ../inventory ../monsters ../triggers ../../common/global_defines ../../common/network ../../common/network/packet_types ../../common/utilities ../../TurtleMap +INCLUDES+=. .. ../barriers ../battles ../characters ../creatures ../entities ../inventory ../monsters ../triggers ../../common/global_defines ../../common/network ../../common/network/packet_types ../../common/utilities ../../TurtleGUI ../../TurtleMap LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/server/server_application.cpp b/server/server_application.cpp index 567393e..11d6e01 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -22,6 +22,7 @@ #include "server_application.hpp" //utility functions +#include "file_hash.hpp" #include "sql_tools.hpp" //std & STL @@ -181,7 +182,7 @@ void ServerApplication::Proc() { HandlePacket(packetBuffer); } catch(std::exception& e) { - std::cerr << "HandlePacket Error: " << e.what() << std::endl; + std::cerr << "HandlePacket Error (" << (int)(packetBuffer->type) << "): " << e.what() << std::endl; } //reset the buffer memset(packetBuffer, 0, MAX_PACKET_SIZE); @@ -607,8 +608,25 @@ void ServerApplication::hQueryCharacterExists(CharacterPacket* const argPacket) } void ServerApplication::hCharacterCreate(CharacterPacket* const argPacket) { + //check to see of the character's files are valid + if (getFileHash(config["dir.sprites"] + argPacket->avatar) == -1) { + //build the error message + std::ostringstream msg; + msg << "Character avatar is invalid on this server: " << argPacket->avatar; + + //build & send the packet + TextPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_REJECTION; + strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); + network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); + + return; + } + + //create the character int characterIndex = characterMgr.Create(argPacket->accountIndex, argPacket->handle, argPacket->avatar); + //check to see of the character already exists if (characterIndex < 0) { //build the error message std::ostringstream msg; @@ -683,8 +701,25 @@ void ServerApplication::hCharacterDelete(CharacterPacket* const argPacket) { } void ServerApplication::hCharacterLoad(CharacterPacket* const argPacket) { + //check to see of the character's files are valid + if (getFileHash(config["dir.sprites"] + argPacket->avatar) == -1) { + //build the error message + std::ostringstream msg; + msg << "Character avatar is invalid on this server: " << argPacket->avatar; + + //build & send the packet + TextPacket newPacket; + newPacket.type = SerialPacketType::CHARACTER_REJECTION; + strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); + network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); + + return; + } + + //load the character int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar); + //check to see if the character is already loaded if (characterIndex < 0) { //build the error message std::ostringstream msg; diff --git a/server/triggers/makefile b/server/triggers/makefile index 211a55a..8d6d386 100644 --- a/server/triggers/makefile +++ b/server/triggers/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. .. ../entities ../../common/utilities +INCLUDES+=. .. ../entities ../../common/utilities ../../TurtleGUI LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))