diff --git a/README.md b/README.md index de55c5e..9bc9e84 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,5 @@ -## Outline - -Tortuga is a 2D MMORPG featuring permadeath, with an emphasis on multiplayer cooperation, exploration and customization. The game runs on customizable public and private servers. - -This game is inspired by classic 2D RPGs (Final Fantasy, The Legend of Zelda), as well as more modern sandboxes and MMOs (Minecraft, EVE Online). This project is currently independently created and funded, with the goal of creating a game that will engage the players and inspire a large community. - -## Releases - -* The most recent stable build for Windows can be found [here](https://dl.dropboxusercontent.com/u/46669050/Tortuga-win.rar). -* The most recent stable build for Linux can be found [here](https://dl.dropboxusercontent.com/u/46669050/Tortuga-linux.tar). - -## Documentation - -* [Tortuga Wiki](https://github.com/Ratstail91/Tortuga/wiki) - Full documentation (incomplete) -* [Tortuga Bug Tracker](https://github.com/Ratstail91/Tortuga/issues) - A list of all known bugs and issues - -## External Dependencies - -* [SDL 2.0](http://www.libsdl.org/) - Simple DirectMedia Layer API -* [SDL_image 2.0](https://www.libsdl.org/projects/SDL_image/) - An SDL Extension for loading multiple image file formats -* [SDL_net 2.0](http://www.libsdl.org/projects/SDL_net/) - SDL's networking extension -* [SDL_ttf 2.0](https://www.libsdl.org/projects/SDL_ttf/) - An SDL extention for rendering fonts -* [lua 5.2](http://www.lua.org/) - The lua programming language -* [SQLite3](http://www.sqlite.org/) - A lightweight SQL database engine - -## Tools - -* [WinRAR](http://www.rarlab.com/) - A free archive tool; needed for Windows distribution -* [tar](http://www.gnu.org/software/tar/manual/) - The GNU archive tool; needed for Linux distribution -* [Dropbox](https://www.dropbox.com/) - For hosting and distribution - ## Copyright -(Future versions (to be determined) may be released under a modified version of the [Uplink Developer's License](http://www.introversion.co.uk/uplink/developer/license.html).) - -The current version of Tortuga is released under the [zlib license](http://en.wikipedia.org/wiki/Zlib_License). - Copyright (c) 2013-2015 Kayne Ruse 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. diff --git a/client/base_scene.cpp b/client/base_scene.cpp deleted file mode 100644 index fc29fab..0000000 --- a/client/base_scene.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "base_scene.hpp" - -SDL_Renderer* BaseScene::rendererHandle = nullptr; - -BaseScene::BaseScene() { - //EMPTY -} - -BaseScene::~BaseScene() { - //EMPTY -} - -void BaseScene::RenderFrame(SDL_Renderer* renderer) { - //EMPTY -} - -void BaseScene::SetRenderer(SDL_Renderer* r) { - rendererHandle = r; -} - -SDL_Renderer* BaseScene::GetRenderer() { - return rendererHandle; -} - -void BaseScene::SetSceneSignal(SceneSignal signal) { - sceneSignal = signal; -} - -SceneSignal BaseScene::GetSceneSignal() { - return sceneSignal; -} - -//------------------------- -//frame phases -//------------------------- - -void BaseScene::FrameStart() { - //EMPTY -} - -void BaseScene::Update() { - //EMPTY -} - -void BaseScene::FrameEnd() { - //EMPTY -} - -//------------------------- -//input events -//------------------------- - -void BaseScene::QuitEvent() { - sceneSignal = SceneSignal::QUIT; -} - -void BaseScene::MouseMotion(SDL_MouseMotionEvent const& event) { - //EMPTY -} - -void BaseScene::MouseButtonDown(SDL_MouseButtonEvent const& event) { - //EMPTY -} - -void BaseScene::MouseButtonUp(SDL_MouseButtonEvent const& event) { - //EMPTY -} - -void BaseScene::MouseWheel(SDL_MouseWheelEvent const& event) { - //EMPTY -} - -void BaseScene::KeyDown(SDL_KeyboardEvent const& event) { - //preference as a default - switch(event.keysym.sym) { - case SDLK_ESCAPE: - QuitEvent(); - break; - } -} - -void BaseScene::KeyUp(SDL_KeyboardEvent const& event) { - //EMPTY -} diff --git a/client/base_scene.hpp b/client/base_scene.hpp deleted file mode 100644 index 0a7b225..0000000 --- a/client/base_scene.hpp +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "scene_signal.hpp" - -#include "SDL2/SDL.h" - -class BaseScene { -public: - BaseScene(); - virtual ~BaseScene(); - - virtual void RenderFrame(SDL_Renderer*); - static void SetRenderer(SDL_Renderer*); - SceneSignal GetSceneSignal(); - - //frame phases - virtual void FrameStart(); - virtual void Update(); - virtual void FrameEnd(); - - //input events - virtual void QuitEvent(); - virtual void MouseMotion(SDL_MouseMotionEvent const& event); - virtual void MouseButtonDown(SDL_MouseButtonEvent const& event); - virtual void MouseButtonUp(SDL_MouseButtonEvent const& event); - virtual void MouseWheel(SDL_MouseWheelEvent const& event); - virtual void KeyDown(SDL_KeyboardEvent const& event); - virtual void KeyUp(SDL_KeyboardEvent const& event); - - //TODO: joystick and controller events - -protected: - //control - static SDL_Renderer* GetRenderer(); - void SetSceneSignal(SceneSignal); - -private: - static SDL_Renderer* rendererHandle; - SceneSignal sceneSignal = SceneSignal::CONTINUE; -}; \ No newline at end of file diff --git a/client/channels.hpp b/client/channels.hpp deleted file mode 100644 index 362463a..0000000 --- a/client/channels.hpp +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 - -enum Channels { - SERVER = 0 -}; diff --git a/client/client_application.cpp b/client/client_application.cpp deleted file mode 100644 index a713248..0000000 --- a/client/client_application.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "client_application.hpp" - -#include "serial_packet.hpp" -#include "config_utility.hpp" - -#include -#include -#include -#include - -//------------------------- -//Public access members -//------------------------- - -void ClientApplication::Init(int argc, char* argv[]) { - std::cout << "Beginning " << argv[0] << std::endl; - - //load the prerequisites - ConfigUtility& config = ConfigUtility::GetSingleton(); - config.Load("rsc/config.cfg", false, argc, argv); - - //------------------------- - //create and check the window - //------------------------- - - int w = config.Int("client.screen.w"); - int h = config.Int("client.screen.h"); - int f = config.Bool("client.screen.f") ? SDL_WINDOW_FULLSCREEN : 0; - - window = SDL_CreateWindow(argv[0], SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w ? w : 800, h ? h : 600, f); - - if (!window) { - std::ostringstream msg; - msg << "Failed to create the window: " << SDL_GetError(); - throw(std::runtime_error(msg.str())); - } - - std::cout << "Initialized the window" << std::endl; - - //------------------------- - //create and check the renderer - //------------------------- - - renderer = SDL_CreateRenderer(window, -1, 0); - - if (!renderer) { - std::ostringstream msg; - msg << "Failed to create the renderer: " << SDL_GetError(); - throw(std::runtime_error(msg.str())); - } - - //screen scaling - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best"); - SDL_RenderSetLogicalSize(renderer, w, h); - - //set the hook for the renderer - BaseScene::SetRenderer(renderer); - - std::cout << "Initialized the renderer" << std::endl; - - //------------------------- - //Initialize the APIs - //------------------------- - - //initialize SDL_net - if (SDLNet_Init()) { - std::ostringstream msg; - msg << "Failed to initialize SDL_net: " << SDL_GetError(); - throw(std::runtime_error(msg.str())); - } - UDPNetworkUtility::GetSingleton().Open(0); - - std::cout << "Initialized SDL_net" << std::endl; - - //------------------------- - //debug output - //------------------------- - -#define DEBUG_OUTPUT_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl; - - std::cout << "Internal sizes:" << std::endl; - - DEBUG_OUTPUT_VAR(NETWORK_VERSION); - DEBUG_OUTPUT_VAR(sizeof(Region::type_t)); - DEBUG_OUTPUT_VAR(sizeof(Region)); - DEBUG_OUTPUT_VAR(REGION_WIDTH); - DEBUG_OUTPUT_VAR(REGION_HEIGHT); - DEBUG_OUTPUT_VAR(REGION_DEPTH); - DEBUG_OUTPUT_VAR(REGION_TILE_FOOTPRINT); - DEBUG_OUTPUT_VAR(REGION_SOLID_FOOTPRINT); - DEBUG_OUTPUT_VAR(PACKET_STRING_SIZE); - DEBUG_OUTPUT_VAR(PACKET_BUFFER_SIZE); - DEBUG_OUTPUT_VAR(MAX_PACKET_SIZE); - DEBUG_OUTPUT_VAR(static_cast(SerialPacketType::LAST)); - -#undef DEBUG_OUTPUT_VAR - - //------------------------- - //finalize the startup - //------------------------- - - std::cout << "Startup completed successfully" << std::endl; - - //------------------------- - //debugging - //------------------------- - - //... -} - -void ClientApplication::Proc() { - //load the first scene - ProcessSceneSignal(SceneSignal::FIRST); - - //fixed frame rate - typedef std::chrono::steady_clock Clock; - - Clock::time_point simTime = Clock::now(); - Clock::time_point realTime; - constexpr std::chrono::duration frameDelay(16); //~60FPS - - //the game loop continues until the scenes signal QUIT - while(activeScene->GetSceneSignal() != SceneSignal::QUIT) { - //switch scenes if necessary - if(activeScene->GetSceneSignal() != SceneSignal::CONTINUE) { - ProcessSceneSignal(activeScene->GetSceneSignal()); - continue; - } - - //update the current time - realTime = Clock::now(); - - //simulate the game or give the machine a break - if (simTime < realTime) { - while(simTime < realTime) { - //call the user defined functions - activeScene->FrameStart(); - ProcessEvents(); - activeScene->Update(); - activeScene->FrameEnd(); - - //step to the next frame - simTime += frameDelay; - } - } - else { - SDL_Delay(1); - } - - SDL_RenderClear(renderer); - activeScene->RenderFrame(renderer); - SDL_RenderPresent(renderer); - } - - //cleanup - ClearScene(); -} - -void ClientApplication::Quit() { - //clean up after the program - std::cout << "Shutting down" << std::endl; - UDPNetworkUtility::GetSingleton().Close(); - SDLNet_Quit(); - BaseScene::SetRenderer(nullptr); - SDL_DestroyRenderer(renderer); - SDL_DestroyWindow(window); - std::cout << "Clean exit" << std::endl; -} - -//------------------------- -//Scene management -//------------------------- - -void ClientApplication::ProcessEvents() { - SDL_Event event; - while(SDL_PollEvent(&event)) { - switch(event.type) { - case SDL_QUIT: - activeScene->QuitEvent(); - break; - - case SDL_MOUSEMOTION: - activeScene->MouseMotion(event.motion); - break; - - case SDL_MOUSEBUTTONDOWN: - activeScene->MouseButtonDown(event.button); - break; - - case SDL_MOUSEBUTTONUP: - activeScene->MouseButtonUp(event.button); - break; - - case SDL_MOUSEWHEEL: - activeScene->MouseWheel(event.wheel); - break; - - case SDL_KEYDOWN: - activeScene->KeyDown(event.key); - break; - - case SDL_KEYUP: - activeScene->KeyUp(event.key); - break; - - //TODO: joystick and controller events - - //window events are handled internally - case SDL_WINDOWEVENT: - switch(event.window.event) { - case SDL_WINDOWEVENT_RESIZED: - SDL_RenderSetLogicalSize(renderer, event.window.data1, event.window.data2); - break; - } - break; - } - } -} - -//Add the custom scene headers here -#include "splash_screen.hpp" -#include "main_menu.hpp" -#include "options_menu.hpp" -#include "lobby_menu.hpp" -#include "world.hpp" -#include "disconnected_screen.hpp" - -void ClientApplication::ProcessSceneSignal(SceneSignal signal) { - //BUG: #16 Resources are being reloaded between scenes - ClearScene(); - switch(signal) { - //add scene creation calls here - case SceneSignal::FIRST: - case SceneSignal::SPLASHSCREEN: - activeScene = new SplashScreen(); - break; - case SceneSignal::MAINMENU: - activeScene = new MainMenu(); - break; - case SceneSignal::OPTIONSMENU: - activeScene = new OptionsMenu(); - break; - case SceneSignal::LOBBYMENU: - activeScene = new LobbyMenu(&clientIndex, &accountIndex); - break; - case SceneSignal::WORLD: - activeScene = new World(&clientIndex, &accountIndex); - break; - case SceneSignal::DISCONNECTEDSCREEN: - activeScene = new DisconnectedScreen(); - break; - default: { - std::ostringstream msg; - msg << "Failed to recognize the scene signal: " << signal; - throw(std::logic_error(msg.str())); - } - } -} - -void ClientApplication::ClearScene() { - delete activeScene; - activeScene = nullptr; -} diff --git a/client/client_application.hpp b/client/client_application.hpp deleted file mode 100644 index 43c421d..0000000 --- a/client/client_application.hpp +++ /dev/null @@ -1,57 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "base_scene.hpp" -#include "scene_signal.hpp" -#include "singleton.hpp" -#include "udp_network_utility.hpp" - -#include "SDL2/SDL.h" - -class ClientApplication: public Singleton { -public: - void Init(int argc, char* argv[]); - void Proc(); - void Quit(); - -private: - friend Singleton; - - ClientApplication() = default; - ~ClientApplication() = default; - - //scene management - void ProcessEvents(); - void ProcessSceneSignal(SceneSignal); - void ClearScene(); - - BaseScene* activeScene = nullptr; - - //TODO: build a "window" class? - SDL_Window* window = nullptr; - SDL_Renderer* renderer = nullptr; - - //shared parameters - int clientIndex = -1; - int accountIndex = -1; -}; \ No newline at end of file diff --git a/client/client_utilities/terminal_error.cpp b/client/client_utilities/terminal_error.cpp deleted file mode 100644 index b113807..0000000 --- a/client/client_utilities/terminal_error.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "terminal_error.hpp" - diff --git a/client/client_utilities/terminal_error.hpp b/client/client_utilities/terminal_error.hpp deleted file mode 100644 index 0735247..0000000 --- a/client/client_utilities/terminal_error.hpp +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 terminal_error: public std::runtime_error { -public: - explicit terminal_error(const std::string& str): runtime_error(str) {} - explicit terminal_error(const char* cstr): runtime_error(cstr) {} -}; diff --git a/client/client_utilities/text_util.cpp b/client/client_utilities/text_util.cpp deleted file mode 100644 index 6094d20..0000000 --- a/client/client_utilities/text_util.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "text_util.hpp" - -#include - -SDL_Texture* renderPlainText(SDL_Renderer* renderer, TTF_Font* font, std::string str, SDL_Color color) { - //make the surface (from SDL_ttf) - SDL_Surface* surface = TTF_RenderText_Solid(font, str.c_str(), color); - if (!surface) { - throw(std::runtime_error("Failed to create a TTF surface")); - } - - //convert to texture - SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface); - if (!texture) { - SDL_FreeSurface(surface); - throw(std::runtime_error("Failed to create a TTF texture")); - } - - //cleanup - SDL_FreeSurface(surface); - - //NOTE: free the texture yourself - return texture; -} \ No newline at end of file diff --git a/client/client_utilities/text_util.hpp b/client/client_utilities/text_util.hpp deleted file mode 100644 index db62286..0000000 --- a/client/client_utilities/text_util.hpp +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "SDL2/SDL.h" -#include "SDL2/SDL_ttf.h" - -#include - -constexpr SDL_Color COLOR_WHITE = {255, 255, 255, 255}; - -//TODO: some kind of persistent display widget -//TODO: I need a full suite of widgets -SDL_Texture* renderPlainText(SDL_Renderer*, TTF_Font*, std::string, SDL_Color color); \ No newline at end of file diff --git a/client/entities/base_character.cpp b/client/entities/base_character.cpp deleted file mode 100644 index becb773..0000000 --- a/client/entities/base_character.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "base_character.hpp" - -#include "config_utility.hpp" - -//------------------------- -//graphics -//------------------------- - -void BaseCharacter::CorrectSprite() { - //NOTE: These must correspond to the sprite sheet in use - if (motion.y > 0) { - sprite.SetIndexY(0); - } - else if (motion.y < 0) { - sprite.SetIndexY(1); - } - else if (motion.x > 0) { - sprite.SetIndexY(3); - } - else if (motion.x < 0) { - sprite.SetIndexY(2); - } - - //animation - if (motion != 0) { - sprite.SetDelay(0.1); - } - else { - sprite.SetDelay(0); - sprite.SetIndexX(0); - } -} - -//------------------------- -//metadata -//------------------------- - -int BaseCharacter::SetOwner(int i) { - return owner = i; -} - -int BaseCharacter::GetOwner() { - return owner; -} - -std::string BaseCharacter::SetHandle(std::string s) { - return handle = s; -} - -std::string BaseCharacter::GetHandle() const { - return handle; -} - -std::string BaseCharacter::SetAvatar(SDL_Renderer* const renderer, std::string s) { - avatar = s; - sprite.Load(renderer, ConfigUtility::GetSingleton()["dir.sprites"] + avatar, CHARACTER_CELLS_X, CHARACTER_CELLS_Y); - return avatar; -} - -std::string BaseCharacter::GetAvatar() const { - return avatar; -} \ No newline at end of file diff --git a/client/entities/base_character.hpp b/client/entities/base_character.hpp deleted file mode 100644 index 4dca687..0000000 --- a/client/entities/base_character.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 - -//components -#include "character_defines.hpp" -#include "entity.hpp" - -//std namespace -#include - -class BaseCharacter: public Entity { -public: - BaseCharacter() = default; - virtual ~BaseCharacter() = default; - - //graphics - void CorrectSprite(); - - //metadata - int SetOwner(int i); - int GetOwner(); - std::string SetHandle(std::string s); - std::string GetHandle() const; - std::string SetAvatar(SDL_Renderer* const, std::string s); - std::string GetAvatar() const; - -protected: - //metadata - int owner; - std::string handle; - std::string avatar; -}; diff --git a/client/entities/base_monster.cpp b/client/entities/base_monster.cpp deleted file mode 100644 index cda27f8..0000000 --- a/client/entities/base_monster.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "base_monster.hpp" - -#include "config_utility.hpp" - -void BaseMonster::CorrectSprite() { - //TODO: (9) BaseMonster::CorrectSprite() -} - -std::string BaseMonster::SetHandle(std::string s) { - return handle = s; -} - -std::string BaseMonster::GetHandle() const { - return handle; -} - -std::string BaseMonster::SetAvatar(SDL_Renderer* const renderer, std::string s) { - avatar = s; - sprite.Load(renderer, ConfigUtility::GetSingleton()["dir.sprites"] + avatar, 4, 1); - return avatar; -} - -std::string BaseMonster::GetAvatar() const { - return avatar; -} \ No newline at end of file diff --git a/client/entities/base_monster.hpp b/client/entities/base_monster.hpp deleted file mode 100644 index d99ee55..0000000 --- a/client/entities/base_monster.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "entity.hpp" - -class BaseMonster: public Entity { -public: - BaseMonster() = default; - virtual ~BaseMonster() = default; - - void CorrectSprite(); - - std::string SetHandle(std::string s); - std::string GetHandle() const; - std::string SetAvatar(SDL_Renderer* const, std::string s); - std::string GetAvatar() const; - -protected: - //metadata - std::string handle; - std::string avatar; -}; diff --git a/client/entities/entity.cpp b/client/entities/entity.cpp deleted file mode 100644 index e44bc4f..0000000 --- a/client/entities/entity.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "entity.hpp" - -void Entity::Update() { - origin += motion; - sprite.Update(0.016); -} - -void Entity::DrawTo(SDL_Renderer* const renderer, int camX, int camY) { - sprite.DrawTo(renderer, origin.x - camX, origin.y - camY); -} - -SpriteSheet* Entity::GetSprite() { - return &sprite; -} - -//------------------------- -//accessors & mutators -//------------------------- - -Vector2 Entity::SetOrigin(Vector2 v) { - return origin = v; -} - -Vector2 Entity::SetMotion(Vector2 v) { - return motion = v; -} - -BoundingBox Entity::SetBounds(BoundingBox b) { - return bounds = b; -} - -Vector2 Entity::GetOrigin() { - return origin; -} - -Vector2 Entity::GetMotion() { - return motion; -} - -BoundingBox Entity::GetBounds() { - return bounds; -} \ No newline at end of file diff --git a/client/entities/entity.hpp b/client/entities/entity.hpp deleted file mode 100644 index d0f712a..0000000 --- a/client/entities/entity.hpp +++ /dev/null @@ -1,53 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "bounding_box.hpp" -#include "sprite_sheet.hpp" -#include "vector2.hpp" - -//The base class for all objects in the world -class Entity { -public: - virtual void Update(); - virtual void DrawTo(SDL_Renderer* const, int camX, int camY); - - SpriteSheet* GetSprite(); - - //accessors & mutators - Vector2 SetOrigin(Vector2 v); - Vector2 SetMotion(Vector2 v); - BoundingBox SetBounds(BoundingBox b); - - Vector2 GetOrigin(); - Vector2 GetMotion(); - BoundingBox GetBounds(); - -protected: - Entity() = default; - virtual ~Entity() = default; - - SpriteSheet sprite; - Vector2 origin; - Vector2 motion; - BoundingBox bounds; -}; diff --git a/client/entities/local_character.cpp b/client/entities/local_character.cpp deleted file mode 100644 index 16c1eff..0000000 --- a/client/entities/local_character.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "local_character.hpp" - -#include - -bool LocalCharacter::ProcessCollisionGrid(std::list boxList) { - for(auto& box : boxList) { - if (box.CheckOverlap(origin + bounds)) { - origin -= motion; - motion = {0, 0}; - return true; - } - } - return false; -} \ No newline at end of file diff --git a/client/entities/local_character.hpp b/client/entities/local_character.hpp deleted file mode 100644 index af7f5fa..0000000 --- a/client/entities/local_character.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "base_character.hpp" -#include "bounding_box.hpp" -#include "vector2.hpp" - -#include - -class LocalCharacter: public BaseCharacter { -public: - LocalCharacter() = default; - virtual ~LocalCharacter() = default; - - bool ProcessCollisionGrid(std::list); - -private: - //NOTE: NO MEMBERS -}; diff --git a/client/entities/makefile b/client/entities/makefile deleted file mode 100644 index 6d25c17..0000000 --- a/client/entities/makefile +++ /dev/null @@ -1,32 +0,0 @@ -#config -INCLUDES+=. .. ../../common/gameplay ../../common/graphics ../../common/utilities -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 $@ $< diff --git a/client/gameplay_scenes/makefile b/client/gameplay_scenes/makefile deleted file mode 100644 index 40fc4ee..0000000 --- a/client/gameplay_scenes/makefile +++ /dev/null @@ -1,32 +0,0 @@ -#config -INCLUDES+=. .. ../client_utilities ../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)) - -#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 $@ $< diff --git a/client/gameplay_scenes/world.hpp b/client/gameplay_scenes/world.hpp deleted file mode 100644 index 790cc2e..0000000 --- a/client/gameplay_scenes/world.hpp +++ /dev/null @@ -1,165 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 - -//maps -#include "region_pager_base.hpp" - -//utilities -#include "udp_network_utility.hpp" -#include "serial_packet.hpp" -#include "config_utility.hpp" - -//graphics -#include "image.hpp" -#include "button.hpp" -#include "tile_sheet.hpp" - -//common -#include "frame_rate.hpp" - -//client -#include "base_scene.hpp" -#include "base_monster.hpp" -#include "local_character.hpp" - -//STL -#include - -#include - -class World: public BaseScene { -public: - //Public access members - World(int* const argClientIndex, int* const argAccountIndex); - ~World(); - - void RenderFrame(SDL_Renderer* renderer) override; - -private: - //frame phases - void FrameStart() override; - void Update() override; - void FrameEnd() override; - - //input events - void MouseMotion(SDL_MouseMotionEvent const& event) override; - void MouseButtonDown(SDL_MouseButtonEvent const& event) override; - void MouseButtonUp(SDL_MouseButtonEvent const& event) override; - void MouseWheel(SDL_MouseWheelEvent const& event) override; - void KeyDown(SDL_KeyboardEvent const& event) override; - void KeyUp(SDL_KeyboardEvent const& event) override; - - //handle incoming traffic - void HandlePacket(SerialPacket* const); - - //heartbeat system - void hPing(ServerPacket* const); - void hPong(ServerPacket* const); - - void CheckHeartBeat(); - - //basic connections - void SendLogoutRequest(); - void SendDisconnectRequest(); - void SendAdminDisconnectForced(); - void SendAdminShutdownRequest(); - - void hLogoutResponse(ClientPacket* const); - void hDisconnectResponse(ClientPacket* const); - void hAdminDisconnectForced(ClientPacket* const); - - //map management - void SendRegionRequest(int roomIndex, int x, int y); - void hRegionContent(RegionPacket* const); - void UpdateMap(); - - //character management - void hCharacterUpdate(CharacterPacket* const); - void hCharacterCreate(CharacterPacket* const); - void hCharacterDelete(CharacterPacket* const); - void hQueryCharacterExists(CharacterPacket* const); - void hQueryCharacterStats(CharacterPacket* const); - void hQueryCharacterLocation(CharacterPacket* const); - void hCharacterMovement(CharacterPacket* const); - void hCharacterAttack(CharacterPacket* const); - void hCharacterDamage(CharacterPacket* const); - - //monster management - void hMonsterCreate(MonsterPacket* const); - void hMonsterDelete(MonsterPacket* const); - void hQueryMonsterExists(MonsterPacket* const); - void hQueryMonsterStats(MonsterPacket* const); - void hQueryMonsterLocation(MonsterPacket* const); - void hMonsterMovement(MonsterPacket* const); - void hMonsterAttack(MonsterPacket* const); - void hMonsterDamage(MonsterPacket* const); - - //chat - void hTextBroadcast(TextPacket* const); - void hTextSpeech(TextPacket* const); - void hTextWhisper(TextPacket* const); - - //general gameplay - void SendLocalCharacterMovement(); - std::list GenerateCollisionGrid(Entity*, int tileWidth, int tileHeight); - - //indexes - int& clientIndex; - int& accountIndex; - int characterIndex = -1; - int roomIndex = -1; - - //graphics - Image buttonImage; - TileSheet tileSheet; - - //map - RegionPagerBase regionPager; - - //UI - Button disconnectButton; - Button shutDownButton; - FrameRate fps; - - //the camera structure - struct { - int x = 0, y = 0; - int width = 0, height = 0; - int marginX = 0, marginY = 0; - } camera; - - //entities - std::map characterMap; - std::map monsterMap; - LocalCharacter* localCharacter = nullptr; - - //heartbeat - //TODO: (2) Heartbeat needs it's own utility - typedef std::chrono::steady_clock Clock; - Clock::time_point lastBeat = Clock::now(); - int attemptedBeats = 0; - - //ugly references; I hate this - ConfigUtility& config = ConfigUtility::GetSingleton(); - UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton(); -}; diff --git a/client/gameplay_scenes/world_characters.cpp b/client/gameplay_scenes/world_characters.cpp deleted file mode 100644 index 377bc05..0000000 --- a/client/gameplay_scenes/world_characters.cpp +++ /dev/null @@ -1,240 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "world.hpp" - -#include "channels.hpp" - -#include -#include -#include -#include - -//------------------------- -//character management -//------------------------- - -//DOCS: preexisting characters will result in query responses -//DOCS: new characters will result in create messages -//DOCS: this client's character will exist in both (skipped) - -void World::hCharacterUpdate(CharacterPacket* const argPacket) { - //TODO: (1) Authentication - //NOTE: applies to the local character too - - //check that this character exists - std::map::iterator characterIt = characterMap.find(argPacket->characterIndex); - if (characterIt != characterMap.end()) { - //update the origin and motion, if there's a difference - if (characterIt->second.GetOrigin() != argPacket->origin) { - characterIt->second.SetOrigin(argPacket->origin); - } - if (characterIt->second.GetMotion() != argPacket->motion) { - characterIt->second.SetMotion(argPacket->motion); - characterIt->second.CorrectSprite(); //only correct the sprite if the motion changes - } - } -} - -void World::hCharacterCreate(CharacterPacket* const argPacket) { - //prevent double message - if (characterMap.find(argPacket->characterIndex) != characterMap.end()) { - std::ostringstream msg; - msg << "Double character creation event; "; - msg << "Index: " << argPacket->characterIndex << "; "; - msg << "Handle: " << argPacket->handle; - throw(std::runtime_error(msg.str())); - } - - //implicity create and retrieve the entity - BaseCharacter* character = &characterMap[argPacket->characterIndex]; - - //fill the character's info - character->SetHandle(argPacket->handle); - character->SetAvatar(argPacket->avatar); - character->SetOwner(argPacket->accountIndex); - character->SetOrigin(argPacket->origin); - character->SetMotion(argPacket->motion); - character->SetBounds(argPacket->bounds); - - character->CorrectSprite(); - - //check for this player's character - if (character->GetOwner() == accountIndex) { - localCharacter = static_cast(character); - - //focus the camera on this character's sprite - camera.marginX = (camera.width / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2); - camera.marginY = (camera.height/ 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2); - - //focus on this character's info - characterIndex = argPacket->characterIndex; - roomIndex = argPacket->roomIndex; - - //query the world state (room) - CharacterPacket newPacket; - memset(&newPacket, 0, MAX_PACKET_SIZE); - newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS; - newPacket.roomIndex = roomIndex; - network.SendTo(Channels::SERVER, &newPacket); - newPacket.type = SerialPacketType::QUERY_MONSTER_EXISTS; - network.SendTo(Channels::SERVER, &newPacket); - } - - //debug - std::cout << "Character Create, total: " << characterMap.size() << std::endl; -} - -void World::hCharacterDelete(CharacterPacket* const argPacket) { - //ignore if this character doesn't exist - std::map::iterator characterIt = characterMap.find(argPacket->characterIndex); - if (characterIt == characterMap.end()) { - return; - } - - //check for this player's character - if ((*characterIt).second.GetOwner() == accountIndex) { - localCharacter = nullptr; - - //clear the camera - camera.marginX = 0; - camera.marginY = 0; - - //clear the room - roomIndex = -1; - regionPager.UnloadAll(); - characterMap.clear(); - monsterMap.clear(); - } - else { - //remove this character - characterMap.erase(characterIt); - } - - //debug - std::cout << "Character Delete, total: " << characterMap.size() << std::endl; -} - -void World::hQueryCharacterExists(CharacterPacket* const argPacket) { - //prevent a double message about this player's character -// if (argPacket->accountIndex == accountIndex) { -// return; -// } - - //ignore characters in a different room (sub-optimal) - if (argPacket->roomIndex != roomIndex) { - return; - } - - //implicitly construct the character if it doesn't exist - BaseCharacter* character = &characterMap[argPacket->characterIndex]; - - //set/update the character's info - character->SetOrigin(argPacket->origin); - character->SetMotion(argPacket->motion); - character->SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT}); - character->SetHandle(argPacket->handle); - character->SetAvatar(argPacket->avatar); - character->SetOwner(argPacket->accountIndex); - character->CorrectSprite(); - - //debug - std::cout << "Character Query, total: " << characterMap.size() << std::endl; -} - -void World::hQueryCharacterStats(CharacterPacket* const argPacket) { - //TODO: (9) World::hQueryCharacterStats() -} - -void World::hQueryCharacterLocation(CharacterPacket* const argPacket) { - //TODO: (9) World::hQueryCharacterLocation() -} - -void World::hCharacterMovement(CharacterPacket* const argPacket) { - //TODO: (1) Authentication - if (argPacket->characterIndex == characterIndex) { - return; - } - - //check that this character exists - std::map::iterator characterIt = characterMap.find(argPacket->characterIndex); - if (characterIt != characterMap.end()) { - //set the origin and motion - characterIt->second.SetOrigin(argPacket->origin); - characterIt->second.SetMotion(argPacket->motion); - characterIt->second.CorrectSprite(); - } -} - -void World::hCharacterAttack(CharacterPacket* const argPacket) { - //TODO: (9) World::hCharacterAttack() -} - -void World::hCharacterDamage(CharacterPacket* const argPacket) { - //TODO: (9) World::hCharacterDamage() -} - -//------------------------- -//player movement & collision -//------------------------- - -void World::SendLocalCharacterMovement() { - CharacterPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_MOVEMENT; - - newPacket.accountIndex = accountIndex; - newPacket.characterIndex = characterIndex; - newPacket.roomIndex = roomIndex; - newPacket.origin = localCharacter->GetOrigin(); - newPacket.motion = localCharacter->GetMotion(); - - network.SendTo(Channels::SERVER, &newPacket); -} - -std::list World::GenerateCollisionGrid(Entity* ptr, int tileWidth, int tileHeight) { - //prepare for collisions - BoundingBox wallBounds = {0, 0, tileWidth, tileHeight}; - std::list boxList; - - //NOTE: for loops were too dense to work with, so I've just used while loops - - //outer loop - wallBounds.x = snapToBase((double)wallBounds.w, ptr->GetOrigin().x); - while(wallBounds.x < (ptr->GetOrigin() + ptr->GetBounds()).x + ptr->GetBounds().w) { - //inner loop - wallBounds.y = snapToBase((double)wallBounds.h, ptr->GetOrigin().y); - while(wallBounds.y < (ptr->GetOrigin() + ptr->GetBounds()).y + ptr->GetBounds().h) { - //check to see if this tile is solid - if (regionPager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) { - //push onto the box set - boxList.push_front(wallBounds); - } - - //increment - wallBounds.y += wallBounds.h; - } - - //increment - wallBounds.x += wallBounds.w; - } - - return std::move(boxList); -} \ No newline at end of file diff --git a/client/gameplay_scenes/world_chat.cpp b/client/gameplay_scenes/world_chat.cpp deleted file mode 100644 index 09ac1bb..0000000 --- a/client/gameplay_scenes/world_chat.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "world.hpp" - -//------------------------- -//chat -//------------------------- - -void World::hTextBroadcast(TextPacket* const argPacket) { - //TODO: (9) World::hTextBroadcast() -} - -void World::hTextSpeech(TextPacket* const argPacket) { - //TODO: (9) World::hTextSpeech() -} - -void World::hTextWhisper(TextPacket* const argPacket) { - //TODO: (9) World::hTextWhisper() -} - diff --git a/client/gameplay_scenes/world_connections.cpp b/client/gameplay_scenes/world_connections.cpp deleted file mode 100644 index fb30f96..0000000 --- a/client/gameplay_scenes/world_connections.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "world.hpp" - -#include "channels.hpp" -#include "ip_operators.hpp" - -#include -#include -#include - -//------------------------- -//heartbeat system -//------------------------- - -void World::hPing(ServerPacket* const argPacket) { - ServerPacket newPacket; - newPacket.type = SerialPacketType::PONG; - network.SendTo(argPacket->srcAddress, &newPacket); -} - -void World::hPong(ServerPacket* const argPacket) { - if (*network.GetIPAddress(Channels::SERVER) != argPacket->srcAddress) { - throw(std::runtime_error("Heartbeat message received from an unknown source")); - } - attemptedBeats = 0; - lastBeat = Clock::now(); -} - -void World::CheckHeartBeat() { - //check the connection (heartbeat) - if (Clock::now() - lastBeat > std::chrono::seconds(3)) { - if (attemptedBeats > 2) { - //escape to the disconnect screen - SendDisconnectRequest(); - SetNextScene(SceneList::DISCONNECTEDSCREEN); - ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server"; - } - else { - ServerPacket newPacket; - newPacket.type = SerialPacketType::PING; - network.SendTo(Channels::SERVER, &newPacket); - - attemptedBeats++; - lastBeat = Clock::now(); - } - } -} - -//------------------------- -//Connection control -//------------------------- - -void World::SendLogoutRequest() { - ClientPacket newPacket; - - //send a logout request - newPacket.type = SerialPacketType::LOGOUT_REQUEST; - newPacket.accountIndex = accountIndex; - - network.SendTo(Channels::SERVER, &newPacket); -} - -void World::SendDisconnectRequest() { - ClientPacket newPacket; - - //send a disconnect request - newPacket.type = SerialPacketType::DISCONNECT_REQUEST; - newPacket.clientIndex = clientIndex; - - network.SendTo(Channels::SERVER, &newPacket); -} - -void World::SendAdminDisconnectForced() { - //TODO: (9) World::SendAdminDisconnectForced() -} - -void World::SendAdminShutdownRequest() { - ClientPacket newPacket; - - //send a shutdown request - newPacket.type = SerialPacketType::ADMIN_SHUTDOWN_REQUEST; - newPacket.accountIndex = accountIndex; - - network.SendTo(Channels::SERVER, &newPacket); -} - -void World::hLogoutResponse(ClientPacket* const argPacket) { - if (localCharacter) { - characterMap.erase(characterIndex); - localCharacter = nullptr; - } - - accountIndex = -1; - characterIndex = -1; - - //reset the camera - camera.marginX = camera.marginY = 0; - - //because, why not? I guess... - SendDisconnectRequest(); -} - -void World::hDisconnectResponse(ClientPacket* const argPacket) { - hLogoutResponse(argPacket);//shortcut - SetNextScene(SceneList::DISCONNECTEDSCREEN); - ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have successfully logged out"; -} - -void World::hAdminDisconnectForced(ClientPacket* const argPacket) { - hDisconnectResponse(argPacket);//shortcut - SetNextScene(SceneList::DISCONNECTEDSCREEN); - ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server"; -} - diff --git a/client/gameplay_scenes/world_logic.cpp b/client/gameplay_scenes/world_logic.cpp deleted file mode 100644 index a75833e..0000000 --- a/client/gameplay_scenes/world_logic.cpp +++ /dev/null @@ -1,428 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "world.hpp" - -#include "channels.hpp" -#include "terminal_error.hpp" - -#include -#include -#include -#include -#include -#include - -//------------------------- -//Public access members -//------------------------- - -World::World(int* const argClientIndex, int* const argAccountIndex): - clientIndex(*argClientIndex), - accountIndex(*argAccountIndex) -{ - //setup the utility objects - buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp"); - buttonImage.SetClipH(buttonImage.GetClipH()/3); - font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp"); - - //pass the utility objects - disconnectButton.SetImage(&buttonImage); - disconnectButton.SetFont(&font); - shutDownButton.SetImage(&buttonImage); - shutDownButton.SetFont(&font); - - //set the button positions - disconnectButton.SetX(50); - disconnectButton.SetY(50 + buttonImage.GetClipH() * 0); - shutDownButton.SetX(50); - shutDownButton.SetY(50 + buttonImage.GetClipH() * 1); - - //set the button texts - disconnectButton.SetText("Disconnect"); - shutDownButton.SetText("Shut Down"); - - //load the tilesheet - //TODO: (2) Tile size and tile sheet should be loaded elsewhere - tileSheet.Load(config["dir.tilesets"] + "overworld.bmp", 32, 32); - - //Send the character data - CharacterPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_LOAD; - 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); - - //set the camera's values - camera.width = GetScreen()->w; - camera.height = GetScreen()->h; - - //debug - // -} - -World::~World() { - //unload the local data - characterMap.clear(); - monsterMap.clear(); -} - -//------------------------- -//Frame loop -//------------------------- - -void World::FrameStart() { - // -} - -void World::Update() { - //create and zero the buffer - SerialPacket* packetBuffer = reinterpret_cast(new char[MAX_PACKET_SIZE]); - memset(packetBuffer, 0, MAX_PACKET_SIZE); - - try { - //suck in and process all waiting packets - while(network.Receive(packetBuffer)) { - HandlePacket(packetBuffer); - } - } - catch(terminal_error& e) { - throw(e); - } - catch(std::exception& e) { - std::cerr << "HandlePacket Error: " << e.what() << std::endl; - } - - //free the buffer - delete reinterpret_cast(packetBuffer); - - //heartbeat system - CheckHeartBeat(); - - //update all entities - for (auto& it : characterMap) { - it.second.Update(); - } - for (auto& it : monsterMap) { - it.second.Update(); - } - - try { - //update the map - UpdateMap(); - } - catch(terminal_error& e) { - throw(e); - } - catch(std::exception& e) { - std::cerr << "UpdateMap Error: " << e.what() << std::endl; - } - - //skip the rest without a local character - if (!localCharacter) { - return; - } - - //get the collidable boxes - std::list boxList = GenerateCollisionGrid(localCharacter, tileSheet.GetTileW(), tileSheet.GetTileH()); - - //process the collisions - if (localCharacter->ProcessCollisionGrid(boxList)) { - localCharacter->CorrectSprite(); - SendLocalCharacterMovement(); - } - - //update the camera - camera.x = localCharacter->GetOrigin().x - camera.marginX; - camera.y = localCharacter->GetOrigin().y - camera.marginY; -} - -void World::FrameEnd() { - // -} - -void World::RenderFrame() { -// SDL_FillRect(GetScreen(), 0, 0); - Render(GetScreen()); - SDL_Flip(GetScreen()); - fps.Calculate(); -} - -void World::Render(SDL_Surface* const screen) { - //draw the map - for (std::list::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); it++) { - tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y); - - //debugging -// std::ostringstream msg; -// msg << it->GetX() << ", " << it->GetY(); -// font.DrawStringTo(msg.str(), screen, it->GetX() * tileSheet.GetImage()->GetClipW() - camera.x, it->GetY() * tileSheet.GetImage()->GetClipH() - camera.y); - } - - //draw the entities - for (auto& it : characterMap) { - //BUG: #29 Characters (and other entities) are drawn out of order - it.second.DrawTo(screen, camera.x, camera.y); - } - for (auto& it : monsterMap) { - it.second.DrawTo(screen, camera.x, camera.y); - } - - //draw UI - disconnectButton.DrawTo(screen); - shutDownButton.DrawTo(screen); - std::ostringstream msg; - msg << fps.GetFrameRate(); - font.DrawStringTo(msg.str(), screen, 0, 0); -} - -//------------------------- -//Event handlers -//------------------------- - -void World::QuitEvent() { - //two-step logout - SendDisconnectRequest(); - SetNextScene(SceneList::QUIT); -} - -void World::MouseMotion(SDL_MouseMotionEvent const& motion) { - disconnectButton.MouseMotion(motion); - shutDownButton.MouseMotion(motion); -} - -void World::MouseButtonDown(SDL_MouseButtonEvent const& button) { - disconnectButton.MouseButtonDown(button); - shutDownButton.MouseButtonDown(button); -} - -void World::MouseButtonUp(SDL_MouseButtonEvent const& button) { - if (disconnectButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) { - SendLogoutRequest(); - } - if (shutDownButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) { - SendAdminShutdownRequest(); - } -} - -void World::KeyDown(SDL_KeyboardEvent const& key) { - //hotkeys - switch(key.keysym.sym) { - case SDLK_ESCAPE: - //TODO: (3) the escape key should actually control menus and stuff - SendLogoutRequest(); - return; - } - - //character movement - if (!localCharacter) { - return; - } - Vector2 motion = localCharacter->GetMotion(); - switch(key.keysym.sym) { - case SDLK_w: - motion.y -= CHARACTER_WALKING_SPEED; - break; - case SDLK_a: - motion.x -= CHARACTER_WALKING_SPEED; - break; - case SDLK_s: - motion.y += CHARACTER_WALKING_SPEED; - break; - case SDLK_d: - motion.x += CHARACTER_WALKING_SPEED; - break; - default: - //DOCS: prevents wrong keys screwing with character movement - return; - } - //handle diagonals - if (motion.x != 0 && motion.y != 0) { - motion *= CHARACTER_WALKING_MOD; - } - //set the info - localCharacter->SetMotion(motion); - localCharacter->CorrectSprite(); - SendLocalCharacterMovement(); -} - -void World::KeyUp(SDL_KeyboardEvent const& key) { - //character movement - if (!localCharacter) { - return; - } - Vector2 motion = localCharacter->GetMotion(); - switch(key.keysym.sym) { - case SDLK_w: - motion.y = std::min(0.0, motion.y += CHARACTER_WALKING_SPEED); - break; - case SDLK_a: - motion.x = std::min(0.0, motion.x += CHARACTER_WALKING_SPEED); - break; - case SDLK_s: - motion.y = std::max(0.0, motion.y -= CHARACTER_WALKING_SPEED); - break; - case SDLK_d: - motion.x = std::max(0.0, motion.x -= CHARACTER_WALKING_SPEED); - break; - default: - //DOCS: prevents wrong keys screwing with character movement - return; - } - //BUGFIX: reset cardinal direction speed on key release - if (motion.x > 0) { - motion.x = CHARACTER_WALKING_SPEED; - } - else if (motion.x < 0) { - motion.x = -CHARACTER_WALKING_SPEED; - } - if (motion.y > 0) { - motion.y = CHARACTER_WALKING_SPEED; - } - else if (motion.y < 0) { - motion.y = -CHARACTER_WALKING_SPEED; - } - //handle diagonals - if (motion.x != 0 && motion.y != 0) { - motion *= CHARACTER_WALKING_MOD; - } - //set the info - localCharacter->SetMotion(motion); - localCharacter->CorrectSprite(); - SendLocalCharacterMovement(); -} - -//------------------------- -//Direct incoming traffic -//------------------------- - -void World::HandlePacket(SerialPacket* const argPacket) { - switch(argPacket->type) { - //heartbeat system - case SerialPacketType::PING: - hPing(static_cast(argPacket)); - break; - case SerialPacketType::PONG: - hPong(static_cast(argPacket)); - break; - - //game server connections - case SerialPacketType::LOGOUT_RESPONSE: - hLogoutResponse(static_cast(argPacket)); - break; - case SerialPacketType::DISCONNECT_RESPONSE: - hDisconnectResponse(static_cast(argPacket)); - break; - case SerialPacketType::ADMIN_DISCONNECT_FORCED: - hAdminDisconnectForced(static_cast(argPacket)); - break; - - //map management - case SerialPacketType::REGION_CONTENT: - hRegionContent(static_cast(argPacket)); - break; - - //character management - case SerialPacketType::CHARACTER_UPDATE: - hCharacterUpdate(static_cast(argPacket)); - break; - case SerialPacketType::CHARACTER_CREATE: - hCharacterCreate(static_cast(argPacket)); - break; - case SerialPacketType::CHARACTER_DELETE: - hCharacterDelete(static_cast(argPacket)); - break; - case SerialPacketType::QUERY_CHARACTER_EXISTS: - hQueryCharacterExists(static_cast(argPacket)); - break; - case SerialPacketType::QUERY_CHARACTER_STATS: - hQueryCharacterStats(static_cast(argPacket)); - break; - case SerialPacketType::QUERY_CHARACTER_LOCATION: - hQueryCharacterLocation(static_cast(argPacket)); - break; - case SerialPacketType::CHARACTER_MOVEMENT: - hCharacterMovement(static_cast(argPacket)); - break; - case SerialPacketType::CHARACTER_ATTACK: - hCharacterAttack(static_cast(argPacket)); - break; - case SerialPacketType::CHARACTER_DAMAGE: - hCharacterDamage(static_cast(argPacket)); - break; - - //monster management - case SerialPacketType::MONSTER_CREATE: - hMonsterCreate(static_cast(argPacket)); - break; - case SerialPacketType::MONSTER_DELETE: - hMonsterDelete(static_cast(argPacket)); - break; - case SerialPacketType::QUERY_MONSTER_EXISTS: - hQueryMonsterExists(static_cast(argPacket)); - break; - case SerialPacketType::QUERY_MONSTER_STATS: - hQueryMonsterStats(static_cast(argPacket)); - break; - case SerialPacketType::QUERY_MONSTER_LOCATION: - hQueryMonsterLocation(static_cast(argPacket)); - break; - case SerialPacketType::MONSTER_MOVEMENT: - hMonsterMovement(static_cast(argPacket)); - break; - case SerialPacketType::MONSTER_ATTACK: - hMonsterAttack(static_cast(argPacket)); - break; - case SerialPacketType::MONSTER_DAMAGE: - hMonsterDamage(static_cast(argPacket)); - break; - - //chat - case SerialPacketType::TEXT_BROADCAST: - hTextBroadcast(static_cast(argPacket)); - break; - case SerialPacketType::TEXT_SPEECH: - hTextSpeech(static_cast(argPacket)); - break; - case SerialPacketType::TEXT_WHISPER: - hTextWhisper(static_cast(argPacket)); - break; - - //general rejection messages - case SerialPacketType::REGION_REJECTION: - case SerialPacketType::CHARACTER_REJECTION: - case SerialPacketType::QUERY_REJECTION: - throw(terminal_error(static_cast(argPacket)->text)); - break; - case SerialPacketType::SHUTDOWN_REJECTION: - throw(std::runtime_error(static_cast(argPacket)->text)); - break; - - //errors - default: { - std::ostringstream msg; - msg << "Unknown SerialPacketType encountered in World: " << static_cast(argPacket->type); - throw(std::runtime_error(msg.str())); - } - break; - } -} \ No newline at end of file diff --git a/client/gameplay_scenes/world_map.cpp b/client/gameplay_scenes/world_map.cpp deleted file mode 100644 index 1265281..0000000 --- a/client/gameplay_scenes/world_map.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "world.hpp" - -#include "channels.hpp" - -#include - -//------------------------- -//static functions -//------------------------- - -static int regionChecksum(Region* const region) { - int sum = 0; - for(int i = 0; i < REGION_WIDTH; i++) { - for (int j = 0; j < REGION_HEIGHT; j++) { - for (int k = 0; k < REGION_DEPTH; k++) { - sum += region->GetTile(i, j, k); - } - } - } - return sum; -} - -//------------------------- -//map management -//------------------------- - -void World::SendRegionRequest(int roomIndex, int x, int y) { - RegionPacket packet; - - //pack the region's data - packet.type = SerialPacketType::REGION_REQUEST; - packet.roomIndex = roomIndex; - packet.x = x; - packet.y = y; - - network.SendTo(Channels::SERVER, &packet); -} - -void World::hRegionContent(RegionPacket* const argPacket) { - //checksum - if (regionChecksum(argPacket->region) == 0) { - std::ostringstream msg; - msg << "Received region checksum failed: " << argPacket->x << ", " << argPacket->y; - throw(std::runtime_error(msg.str())); - } - - //replace existing regions - regionPager.UnloadIf([&](Region const& region) -> bool { - return region.GetX() == argPacket->x && region.GetY() == argPacket->y; - }); - regionPager.PushRegion(argPacket->region); - - //clean up after the serial code - delete argPacket->region; - argPacket->region = nullptr; -} - -void World::UpdateMap() { - if (roomIndex == -1) { - return; - } - - //these represent the zone of regions that the client needs loaded, including the mandatory buffers (+1/-1) - int xStart = snapToBase(REGION_WIDTH, camera.x/tileSheet.GetTileW()) - REGION_WIDTH; - int xEnd = snapToBase(REGION_WIDTH, (camera.x+camera.width)/tileSheet.GetTileW()) + REGION_WIDTH; - - int yStart = snapToBase(REGION_HEIGHT, camera.y/tileSheet.GetTileH()) - REGION_HEIGHT; - int yEnd = snapToBase(REGION_HEIGHT, (camera.y+camera.height)/tileSheet.GetTileH()) + REGION_HEIGHT; - - //prune distant regions - regionPager.GetContainer()->remove_if([&](Region const& region) -> bool { - return region.GetX() < xStart || region.GetX() > xEnd || region.GetY() < yStart || region.GetY() > yEnd; - }); - - //request empty regions within this zone - for (int i = xStart; i <= xEnd; i += REGION_WIDTH) { - for (int j = yStart; j <= yEnd; j += REGION_HEIGHT) { - Region* region = regionPager.FindRegion(i, j); - if (!region) { - //request absent region - SendRegionRequest(roomIndex, i, j); - } - else if (regionChecksum(region) == 0) { - //checksum failed - //NOTE: this patches bug #45, but does not resolve it - regionPager.UnloadIf([region](Region const& ref) -> bool { - //remove the erroneous region - return region == &ref; - }); - SendRegionRequest(roomIndex, i, j); - std::ostringstream msg; - msg << "Existing region checksum failed: " << roomIndex << ", " << i << ", " << j; - throw(std::runtime_error(msg.str())); - } - } - } -} \ No newline at end of file diff --git a/client/gameplay_scenes/world_monsters.cpp b/client/gameplay_scenes/world_monsters.cpp deleted file mode 100644 index ada5786..0000000 --- a/client/gameplay_scenes/world_monsters.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "world.hpp" - -#include "channels.hpp" - -#include -#include -#include - -//------------------------- -//monster management -//------------------------- - -void World::hMonsterCreate(MonsterPacket* const argPacket) { - //check for logic errors - if (monsterMap.find(argPacket->monsterIndex) != monsterMap.end()) { - std::ostringstream msg; - msg << "Double monster creation event; "; - msg << "Index: " << argPacket->monsterIndex << "; "; - msg << "Handle: " << argPacket->handle; - throw(std::runtime_error(msg.str())); - } - - //ignore monsters from other rooms - if (roomIndex != argPacket->roomIndex) { - //temporary error checking - std::ostringstream msg; - msg << "Monster from the wrong room received: "; - msg << "monsterIndex: " << argPacket->monsterIndex << ", roomIndex: " << argPacket->roomIndex; - throw(std::runtime_error(msg.str())); - } - - //implicitly create the element - BaseMonster* monster = &monsterMap[argPacket->monsterIndex]; - - //fill the monster's info - monster->SetHandle(argPacket->handle); - monster->SetAvatar(argPacket->avatar); - monster->SetBounds(argPacket->bounds); - monster->SetOrigin(argPacket->origin); - monster->SetMotion(argPacket->motion); - - //debug - std::cout << "Monster Create, total: " << monsterMap.size() << std::endl; -} - -void World::hMonsterDelete(MonsterPacket* const argPacket) { - //ignore if this monster doesn't exist - std::map::iterator monsterIt = monsterMap.find(argPacket->monsterIndex); - if (monsterIt == monsterMap.end()) { - return; - } - - //remove this monster - monsterMap.erase(monsterIt); - - //debug - std::cout << "Monster Delete, total: " << monsterMap.size() << std::endl; -} - -void World::hQueryMonsterExists(MonsterPacket* const argPacket) { - //ignore monsters in a different room (sub-optimal) - if (argPacket->roomIndex != roomIndex) { - return; - } - - //implicitly create the element - BaseMonster* monster = &monsterMap[argPacket->monsterIndex]; - - //fill the monster's info - monster->SetHandle(argPacket->handle); - monster->SetAvatar(argPacket->avatar); - monster->SetBounds(argPacket->bounds); - monster->SetOrigin(argPacket->origin); - monster->SetMotion(argPacket->motion); - - //debug - std::cout << "Monster Query, total: " << monsterMap.size() << std::endl; -} - -void World::hQueryMonsterStats(MonsterPacket* const argPacket) { - //TODO: (9) World::hQueryMonsterStats() -} - -void World::hQueryMonsterLocation(MonsterPacket* const argPacket) { - //TODO: (9) World::hQueryMonsterLocation() -} - -void World::hMonsterMovement(MonsterPacket* const argPacket) { - //ignore if this monster doesn't exist - std::map::iterator monsterIt = monsterMap.find(argPacket->monsterIndex); - if (monsterIt == monsterMap.end()) { - return; - } - - monsterIt->second.SetOrigin(argPacket->origin); - monsterIt->second.SetOrigin(argPacket->motion); -} - -void World::hMonsterAttack(MonsterPacket* const argPacket) { - //TODO: (9) World::hMonsterAttack() -} - -void World::hMonsterDamage(MonsterPacket* const argPacket) { - //TODO: (9) World::hMonsterDamage() -} \ No newline at end of file diff --git a/client/main.cpp b/client/main.cpp deleted file mode 100644 index 5afbd6e..0000000 --- a/client/main.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "client_application.hpp" - -//singletons -#include "config_utility.hpp" -#include "udp_network_utility.hpp" - -#include -#include - -using namespace std; - -int main(int argc, char* argv[]) { - try { - //create the singletons - ConfigUtility::CreateSingleton(); - UDPNetworkUtility::CreateSingleton(); - - //call the client's routines - ClientApplication::CreateSingleton(); - ClientApplication& app = ClientApplication::GetSingleton(); - - app.Init(argc, argv); - app.Proc(); - app.Quit(); - - //control the position of the app's destructor - ClientApplication::DeleteSingleton(); - - //delete the singletons - ConfigUtility::DeleteSingleton(); - UDPNetworkUtility::DeleteSingleton(); - } - catch(exception& e) { - cerr << "Fatal exception thrown: " << e.what() << endl; - return 1; - } - return 0; -} \ No newline at end of file diff --git a/client/makefile b/client/makefile deleted file mode 100644 index be625e2..0000000 --- a/client/makefile +++ /dev/null @@ -1,60 +0,0 @@ -#include directories -INCLUDES+=. client_utilities entities gameplay_scenes menu_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 -LIBS+=client.a ../libcommon.a -lSDL_net -ifeq ($(OS),Windows_NT) - LIBS+=-lwsock32 -liphlpapi -lmingw32 -endif -LIBS+=-lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf - -#flags -CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -ifeq ($(shell uname), Linux) - #read data about the current install - CXXFLAGS+=$(shell sdl-config --cflags --static-libs) -endif - -#source -CXXSRC=$(wildcard *.cpp) - -#objects -OBJDIR=obj -OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) - -#output -OUTDIR=../out -OUT=$(addprefix $(OUTDIR)/,client) - -#targets -all: $(OBJ) $(OUT) - $(MAKE) -C client_utilities - $(MAKE) -C entities -# $(MAKE) -C gameplay_scenes -# $(MAKE) -C menu_scenes -# $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) - -$(OBJ): | $(OBJDIR) - -$(OUT): | $(OUTDIR) - -$(OBJDIR): - mkdir $(OBJDIR) - -$(OUTDIR): - mkdir $(OUTDIR) - -$(OBJDIR)/%.o: %.cpp - $(CXX) $(CXXFLAGS) -c -o $@ $< - -clean: -ifeq ($(OS),Windows_NT) - $(RM) *.o *.a *.exe -else ifeq ($(shell uname), Linux) - find . -type f -name *.o -exec rm -f -r -v {} \; - find . -type f -name *.a -exec rm -f -r -v {} \; - rm -f -v out/client out/server -endif - -rebuild: clean all diff --git a/client/menu_scenes/disconnected_screen.cpp b/client/menu_scenes/disconnected_screen.cpp deleted file mode 100644 index 0a5e655..0000000 --- a/client/menu_scenes/disconnected_screen.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "disconnected_screen.hpp" - -#include "channels.hpp" -#include "config_utility.hpp" -#include "udp_network_utility.hpp" - -#include - -//------------------------- -//Public access members -//------------------------- - -DisconnectedScreen::DisconnectedScreen() { - ConfigUtility& config = ConfigUtility::GetSingleton(); - - //setup the utility objects - //TODO: (1) resource tool, to prevent reloading like this - image.Load(GetRenderer(), config["dir.interface"] + "button.png"); - font = TTF_OpenFont(config["client.font"].c_str(), 12); - - //setup the button - backButton.SetBackgroundTexture(GetRenderer(), image.GetTexture()); - backButton.SetText(GetRenderer(), font, "Back", {255, 255, 255, 255}); - - //set the button positions - backButton.SetX(50); - backButton.SetY(50); - - //set the disconnection message text - textLine.SetText(GetRenderer(), font, config["client.disconnectMessage"], {255, 255, 255, 255}); - - //full reset - UDPNetworkUtility::GetSingleton().Unbind(Channels::SERVER); - - //auto return - startTick = std::chrono::steady_clock::now(); -} - -DisconnectedScreen::~DisconnectedScreen() { - TTF_CloseFont(font); -} - -//------------------------- -//Frame loop -//------------------------- - -void DisconnectedScreen::FrameStart() { - // -} - -void DisconnectedScreen::Update() { - if (std::chrono::steady_clock::now() - startTick > std::chrono::duration(10)) { - SetSceneSignal(SceneSignal::MAINMENU); - } - - //Eat incoming packets - while(UDPNetworkUtility::GetSingleton().Receive()); -} - -void DisconnectedScreen::FrameEnd() { - // -} - -void DisconnectedScreen::RenderFrame(SDL_Renderer* renderer) { - backButton.DrawTo(renderer); - textLine.DrawTo(renderer, 50, 50); -} - -//------------------------- -//Event handlers -//------------------------- - -void DisconnectedScreen::MouseMotion(SDL_MouseMotionEvent const& event) { - backButton.MouseMotion(event); -} - -void DisconnectedScreen::MouseButtonDown(SDL_MouseButtonEvent const& event) { - backButton.MouseButtonDown(event); -} - -void DisconnectedScreen::MouseButtonUp(SDL_MouseButtonEvent const& event) { - if (backButton.MouseButtonUp(event) == Button::State::RELEASED) { - SetSceneSignal(SceneSignal::MAINMENU); - } -} - -void DisconnectedScreen::KeyDown(SDL_KeyboardEvent const& event) { - switch(event.keysym.sym) { - case SDLK_ESCAPE: - SetSceneSignal(SceneSignal::MAINMENU); - break; - } -} - -void DisconnectedScreen::KeyUp(SDL_KeyboardEvent const& event) { - // -} diff --git a/client/menu_scenes/disconnected_screen.hpp b/client/menu_scenes/disconnected_screen.hpp deleted file mode 100644 index 5edf340..0000000 --- a/client/menu_scenes/disconnected_screen.hpp +++ /dev/null @@ -1,63 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "base_scene.hpp" -#include "button.hpp" -#include "image.hpp" -#include "text_line.hpp" - -#include "SDL2/SDL_ttf.h" - -#include - -class DisconnectedScreen : public BaseScene { -public: - //Public access members - DisconnectedScreen(); - ~DisconnectedScreen(); - - void RenderFrame(SDL_Renderer* renderer) override; - -protected: - //frame phases - void FrameStart() override; - void Update() override; - void FrameEnd() override; - - //input events - void MouseMotion(SDL_MouseMotionEvent const& event) override; - void MouseButtonDown(SDL_MouseButtonEvent const& event) override; - void MouseButtonUp(SDL_MouseButtonEvent const& event) override; - void MouseWheel(SDL_MouseWheelEvent const& event) override; - void KeyDown(SDL_KeyboardEvent const& event) override; - void KeyUp(SDL_KeyboardEvent const& event) override; - - //graphics - Image image; - TTF_Font* font = nullptr; - Button backButton; - TextLine textLine; - - //auto return - std::chrono::steady_clock::time_point startTick; -}; diff --git a/client/menu_scenes/lobby_menu.cpp b/client/menu_scenes/lobby_menu.cpp deleted file mode 100644 index be12984..0000000 --- a/client/menu_scenes/lobby_menu.cpp +++ /dev/null @@ -1,306 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "lobby_menu.hpp" - -#include "channels.hpp" - -#include -#include - -//------------------------- -//Public access members -//------------------------- - -LobbyMenu::LobbyMenu(int* const argClientIndex, int* const argAccountIndex): - clientIndex(*argClientIndex), - accountIndex(*argAccountIndex) -{ - //preemptive reset - clientIndex = -1; - accountIndex = -1; - - //setup the utility objects - buttonImage.Load(GetRenderer(), config["dir.interface"] + "button.png"); - font = TTF_OpenFont(config["client.font"].c_str(), 12); - - //setup the buttons - searchButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture()); - searchButton.SetText(GetRenderer(), font, "Search", {255, 255, 255, 255}); - joinButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture()); - joinButton.SetText(GetRenderer(), font, "Join", {255, 255, 255, 255}); - backButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture()); - backButton.SetText(GetRenderer(), font, "Back", {255, 255, 255, 255}); - - //set the button positions (assumed) - searchButton.SetX(50); - searchButton.SetY(50); - joinButton.SetX(50); - joinButton.SetY(70); - backButton.SetX(50); - backButton.SetY(90); - - //pseudo-list selection - boundingBox = {300, 50, 200, 12}; - - //DEBUG: hacked together a highlight box - highlightImage.Create(GetRenderer(), 300, 12, {49, 150, 5, 255}); - - //Eat incoming packets - while(network.Receive()); - - //Initial broadcast - SendBroadcastRequest(); -} - -LobbyMenu::~LobbyMenu() { - TTF_CloseFont(font); -} - -//------------------------- -//Frame loop -//------------------------- - -void LobbyMenu::FrameStart() { - // -} - -void LobbyMenu::Update() { - //suck in and process all waiting packets - SerialPacket* packetBuffer = reinterpret_cast(new char[MAX_PACKET_SIZE]); - while(network.Receive(packetBuffer)) { - HandlePacket(packetBuffer); - } - delete reinterpret_cast(packetBuffer); -} - -void LobbyMenu::FrameEnd() { - // -} - -void LobbyMenu::RenderFrame(SDL_Renderer* renderer) { - //TODO: (2) I need a proper UI system for the entire client and the editor - - //UI - searchButton.DrawTo(renderer); - joinButton.DrawTo(renderer); - backButton.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++) { - //draw the selected server's highlight - if (selection == &serverVector[i]) { - highlightImage.DrawTo(renderer, boundingBox.x, boundingBox.y + boundingBox.h * i); - } - - //draw the server's info - serverVector[i].nameImage.DrawTo(renderer, boundingBox.x, boundingBox.y + boundingBox.h * i); - serverVector[i].playerCountImage.DrawTo(renderer, boundingBox.x, boundingBox.y + boundingBox.h * i); - } -} - -//------------------------- -//Event handlers -//------------------------- - -void LobbyMenu::MouseMotion(SDL_MouseMotionEvent const& event) { - searchButton.MouseMotion(event); - joinButton.MouseMotion(event); - backButton.MouseMotion(event); -} - -void LobbyMenu::MouseButtonDown(SDL_MouseButtonEvent const& event) { - searchButton.MouseButtonDown(event); - joinButton.MouseButtonDown(event); - backButton.MouseButtonDown(event); -} - -void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& event) { - if (searchButton.MouseButtonUp(event) == Button::State::RELEASED) { - SendBroadcastRequest(); - } - if (joinButton.MouseButtonUp(event) == Button::State::RELEASED && selection && selection->compatible) { - SendJoinRequest(); - } - if (backButton.MouseButtonUp(event) == Button::State::RELEASED) { - SetSceneSignal(SceneSignal::MAINMENU); - } - - //has the user selected a server on the list? - BoundingBox tmpBox = boundingBox; - tmpBox.h *= serverVector.size(); //within the list bounds - if (tmpBox.CheckOverlap({event.x, event.y})) { - //NOTE: this memory trick requires a vector - selection = &serverVector[(event.y - boundingBox.y)/boundingBox.h]; - } - else { - selection = nullptr; - } -} - -void LobbyMenu::MouseWheel(SDL_MouseWheelEvent const& event) { - // -} - -void LobbyMenu::KeyDown(SDL_KeyboardEvent const& event) { - switch(event.keysym.sym) { - case SDLK_ESCAPE: - SetSceneSignal(SceneSignal::MAINMENU); - break; - } -} - -void LobbyMenu::KeyUp(SDL_KeyboardEvent const& event) { - // -} - -//------------------------- -//Network handlers -//------------------------- - -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: { - std::ostringstream msg; - msg << "Unknown SerialPacketType encountered in LobbyMenu: " << static_cast(argPacket->type); - throw(std::runtime_error( msg.str() )); - } - break; - } -} - -void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) { - //extract the data - ServerInfo newServer; - - newServer.address = argPacket->srcAddress; - newServer.name = argPacket->name; - newServer.playerCount = argPacket->playerCount; - newServer.version = argPacket->version; - newServer.compatible = newServer.version == NETWORK_VERSION; - - //push - serverVector.push_back(newServer); - - //BUGFIX: since TextLine lacks the memory management of Image, I'll wait until after the line is in the vector to handle these - - //fancy colors - SDL_Color color; - if (newServer.compatible) { - color = {255, 255, 255, 255}; - } - else { - color = {255, 0, 0, 255}; - } - - //fancy itoa - auto itoa_base10 = [](int i) -> std::string { - char str[20]; - printf(str, "%d", i); - return std::string(str); - }; - - //text graphics - serverVector.back().nameImage.SetText(GetRenderer(), font, newServer.name, color); - serverVector.back().playerCountImage.SetText(GetRenderer(), font, itoa_base10(newServer.playerCount), color); -} - -void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) { - //save the server's data - clientIndex = argPacket->clientIndex; - 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; - SetSceneSignal(SceneSignal::WORLD); -} - -void LobbyMenu::HandleJoinRejection(TextPacket* const argPacket) { - //TODO: (9) LobbyMenu::HandleJoinRejection() -} - -void LobbyMenu::HandleLoginRejection(TextPacket* const argPacket) { - //TODO: (9) LobbyMenu::HandleLoginRejection -} - -//------------------------- -//server control -//------------------------- - -void LobbyMenu::SendBroadcastRequest() { - //broadcast to the network, or a specific server - ClientPacket packet; - packet.type = SerialPacketType::BROADCAST_REQUEST; - network.SendTo(config["server.host"].c_str(), config.Int("server.port"), &packet); - - //reset the server list - serverVector.clear(); - selection = nullptr; -} - -void LobbyMenu::SendJoinRequest() { - //pack the packet - ClientPacket packet; - packet.type = SerialPacketType::JOIN_REQUEST; - - //join the selected server - network.SendTo(selection->address, &packet); - selection = nullptr; -} - -void LobbyMenu::SendLoginRequest() { - //NOTE: high cohesion - //TODO: have a separate login screen - 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/menu_scenes/lobby_menu.hpp b/client/menu_scenes/lobby_menu.hpp deleted file mode 100644 index e591346..0000000 --- a/client/menu_scenes/lobby_menu.hpp +++ /dev/null @@ -1,110 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 - -//graphics & ui -#include "image.hpp" -#include "button.hpp" -#include "bounding_box.hpp" -#include "text_line.hpp" - -#include "SDL2/SDL_ttf.h" - -//utilities -#include "config_utility.hpp" -#include "udp_network_utility.hpp" -#include "serial_packet.hpp" - -//client -#include "base_scene.hpp" - -//STL -#include - -class LobbyMenu : public BaseScene { -public: - //Public access members - LobbyMenu(int* const argClientIndex, int* const argAccountIndex); - ~LobbyMenu(); - - void RenderFrame(SDL_Renderer* renderer) override; - -protected: - //frame phases - void FrameStart() override; - void Update() override; - void FrameEnd() override; - - //input events - void MouseMotion(SDL_MouseMotionEvent const& event) override; - void MouseButtonDown(SDL_MouseButtonEvent const& event) override; - void MouseButtonUp(SDL_MouseButtonEvent const& event) override; - void MouseWheel(SDL_MouseWheelEvent const& event) override; - void KeyDown(SDL_KeyboardEvent const& event) override; - void KeyUp(SDL_KeyboardEvent const& event) override; - - //Network handlers - 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(); - UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton(); - int& clientIndex; - int& accountIndex; - - //define the list object - struct ServerInfo { - //graphics - TextLine nameImage; - TextLine playerCountImage; - - //networking - IPaddress address; - std::string name; - int playerCount; - int version; - bool compatible; - }; - - //members - Image buttonImage; - Image highlightImage; - TTF_Font* font = nullptr; - Button searchButton; - Button joinButton; - Button backButton; - - std::vector serverVector; - ServerInfo* selection = nullptr; - - BoundingBox boundingBox; -}; diff --git a/client/menu_scenes/main_menu.cpp b/client/menu_scenes/main_menu.cpp deleted file mode 100644 index aac2d18..0000000 --- a/client/menu_scenes/main_menu.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "main_menu.hpp" - -#include "config_utility.hpp" - -//------------------------- -//Public access members -//------------------------- - -MainMenu::MainMenu() { - ConfigUtility& config = ConfigUtility::GetSingleton(); - - //setup the utility objects - buttonImage.Load(GetRenderer(), config["dir.interface"] + "button.png"); - font = TTF_OpenFont(config["client.font"].c_str(), 12); - - //setup the buttons - startButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture()); - startButton.SetText(GetRenderer(), font, "Start", {255, 255, 255, 255}); - optionsButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture()); - optionsButton.SetText(GetRenderer(), font, "Options", {255, 255, 255, 255}); - quitButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture()); - quitButton.SetText(GetRenderer(), font, "Quit", {255, 255, 255, 255}); - - //set the button positions - startButton.SetX(50); - startButton.SetY(50 + 20 * 0); - optionsButton.SetX(50); - optionsButton.SetY(50 + 20 * 1); - quitButton.SetX(50); - quitButton.SetY(50 + 20 * 2); - - //text box - textBox.PushLine(GetRenderer(), font, "Thanks for playing!", {255, 255, 255, 255}); - textBox.PushLine(GetRenderer(), font, "You can get the latest version at: ", {255, 255, 255, 255}); - textBox.PushLine(GetRenderer(), font, "krgamestudios.com", {255, 255, 255, 255}); - - //debug - // -} - -MainMenu::~MainMenu() { - TTF_CloseFont(font); -} - -//------------------------- -//Frame loop -//------------------------- - -void MainMenu::FrameStart() { - // -} - -void MainMenu::Update() { - // -} - -void MainMenu::FrameEnd() { - // -} - -void MainMenu::RenderFrame(SDL_Renderer* renderer) { - startButton.DrawTo(renderer); - optionsButton.DrawTo(renderer); - quitButton.DrawTo(renderer); - - textBox.DrawTo(renderer, 50, 50, 12); -} - -//------------------------- -//Event handlers -//------------------------- - -void MainMenu::MouseMotion(SDL_MouseMotionEvent const& event) { - startButton.MouseMotion(event); - optionsButton.MouseMotion(event); - quitButton.MouseMotion(event); -} - -void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& event) { - startButton.MouseButtonDown(event); - optionsButton.MouseButtonDown(event); - quitButton.MouseButtonDown(event); -} - -void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& event) { - //TODO: (2) Buttons should only register as "selected" when the left button is used - if (startButton.MouseButtonUp(event) == Button::State::RELEASED) { - SetSceneSignal(SceneSignal::LOBBYMENU); - } - if (optionsButton.MouseButtonUp(event) == Button::State::RELEASED) { - SetSceneSignal(SceneSignal::OPTIONSMENU); - } - if (quitButton.MouseButtonUp(event) == Button::State::RELEASED) { - QuitEvent(); - } -} - -void MainMenu::KeyDown(SDL_KeyboardEvent const& event) { - // -} - -void MainMenu::KeyUp(SDL_KeyboardEvent const& event) { - switch(event.keysym.sym) { - case SDLK_ESCAPE: - QuitEvent(); - break; - } -} diff --git a/client/menu_scenes/main_menu.hpp b/client/menu_scenes/main_menu.hpp deleted file mode 100644 index 272408c..0000000 --- a/client/menu_scenes/main_menu.hpp +++ /dev/null @@ -1,60 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "base_scene.hpp" -#include "button.hpp" -#include "image.hpp" -#include "text_box.hpp" - -#include "SDL2/SDL_ttf.h" - -class MainMenu : public BaseScene { -public: - //Public access members - MainMenu(); - ~MainMenu(); - - void RenderFrame(SDL_Renderer* renderer) override; - -protected: - //frame phases - void FrameStart() override; - void Update() override; - void FrameEnd() override; - - //input events - void MouseMotion(SDL_MouseMotionEvent const& event) override; - void MouseButtonDown(SDL_MouseButtonEvent const& event) override; - void MouseButtonUp(SDL_MouseButtonEvent const& event) override; - void MouseWheel(SDL_MouseWheelEvent const& event) override; - void KeyDown(SDL_KeyboardEvent const& event) override; - void KeyUp(SDL_KeyboardEvent const& event) override; - - //members - Image buttonImage; - TTF_Font* font = nullptr; - Button startButton; - Button optionsButton; - Button quitButton; - TextBox textBox; -}; diff --git a/client/menu_scenes/makefile b/client/menu_scenes/makefile deleted file mode 100644 index f03de53..0000000 --- a/client/menu_scenes/makefile +++ /dev/null @@ -1,32 +0,0 @@ -#config -INCLUDES+=. .. ../client_utilities ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities -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 $@ $< diff --git a/client/menu_scenes/options_menu.cpp b/client/menu_scenes/options_menu.cpp deleted file mode 100644 index 96863b3..0000000 --- a/client/menu_scenes/options_menu.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "options_menu.hpp" - -#include "config_utility.hpp" - -//------------------------- -//Public access members -//------------------------- - -OptionsMenu::OptionsMenu() { - ConfigUtility& config = ConfigUtility::GetSingleton(); - - //setup the utility objects - buttonImage.Load(GetRenderer(), config["dir.interface"] + "button.png"); - font = TTF_OpenFont(config["client.font"].c_str(), 12); - - //setup the button - backButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture()); - backButton.SetText(GetRenderer(), font, "Back", {255, 255, 255, 255}); - - //set the button positions - backButton.SetX(50); - backButton.SetY(50); - - //text line - textLine.SetText(GetRenderer(), font, "This code is fucking hard to refactor.", {255, 255, 255, 255}); -} - -OptionsMenu::~OptionsMenu() { - TTF_CloseFont(font); -} - -//------------------------- -//Frame loop -//------------------------- - -void OptionsMenu::FrameStart() { - // -} - -void OptionsMenu::Update() { - // -} - -void OptionsMenu::FrameEnd() { - // -} - -void OptionsMenu::RenderFrame(SDL_Renderer* renderer) { - backButton.DrawTo(renderer); - textLine.DrawTo(renderer, 50, 30); -} - -//------------------------- -//Event handlers -//------------------------- - -void OptionsMenu::MouseMotion(SDL_MouseMotionEvent const& event) { - backButton.MouseMotion(event); -} - -void OptionsMenu::MouseButtonDown(SDL_MouseButtonEvent const& event) { - backButton.MouseButtonDown(event); -} - -void OptionsMenu::MouseButtonUp(SDL_MouseButtonEvent const& event) { - if (backButton.MouseButtonUp(event) == Button::State::RELEASED) { - SetSceneSignal(SceneSignal::MAINMENU); - } -} - -void OptionsMenu::KeyDown(SDL_KeyboardEvent const& event) { - switch(event.keysym.sym) { - case SDLK_ESCAPE: - SetSceneSignal(SceneSignal::MAINMENU); - break; - } -} - -void OptionsMenu::KeyUp(SDL_KeyboardEvent const& event) { - // -} diff --git a/client/menu_scenes/options_menu.hpp b/client/menu_scenes/options_menu.hpp deleted file mode 100644 index 31507f6..0000000 --- a/client/menu_scenes/options_menu.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "button.hpp" -#include "image.hpp" -#include "text_line.hpp" - -#include "base_scene.hpp" - -//NOTE: The options screen needs to be USED -class OptionsMenu : public BaseScene { -public: - //Public access members - OptionsMenu(); - ~OptionsMenu(); - - void RenderFrame(SDL_Renderer* renderer) override; - -private: - //frame phases - void FrameStart() override; - void Update() override; - void FrameEnd() override; - - //input events - void MouseMotion(SDL_MouseMotionEvent const& event) override; - void MouseButtonDown(SDL_MouseButtonEvent const& event) override; - void MouseButtonUp(SDL_MouseButtonEvent const& event) override; - void MouseWheel(SDL_MouseWheelEvent const& event) override; - void KeyDown(SDL_KeyboardEvent const& event) override; - void KeyUp(SDL_KeyboardEvent const& event) override; - - //members - Image buttonImage; - TTF_Font* font = nullptr; - Button backButton; - TextLine textLine; -}; diff --git a/client/menu_scenes/splash_screen.cpp b/client/menu_scenes/splash_screen.cpp deleted file mode 100644 index 9fefd4a..0000000 --- a/client/menu_scenes/splash_screen.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "splash_screen.hpp" - -#include "config_utility.hpp" - -//------------------------- -//Public access members -//------------------------- - -SplashScreen::SplashScreen() { - logo.Load(GetRenderer(), ConfigUtility::GetSingleton()["dir.logos"] + "krstudios.png"); - startTick = std::chrono::steady_clock::now(); -} - -SplashScreen::~SplashScreen() { - // -} - -//------------------------- -//Frame loop -//------------------------- - -void SplashScreen::FrameStart() { - if (std::chrono::steady_clock::now() - startTick > std::chrono::duration(1)) { - SetSceneSignal(SceneSignal::MAINMENU); - } -} - -void SplashScreen::RenderFrame(SDL_Renderer* renderer) { - int w = 0, h = 0; - SDL_RenderGetLogicalSize(renderer, &w, &h); - logo.DrawTo(renderer, (w - logo.GetClipW()) / 2, (h - logo.GetClipH()) / 2); -} diff --git a/client/menu_scenes/splash_screen.hpp b/client/menu_scenes/splash_screen.hpp deleted file mode 100644 index 469c647..0000000 --- a/client/menu_scenes/splash_screen.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "base_scene.hpp" -#include "image.hpp" - -#include - -class SplashScreen : public BaseScene { -public: - //Public access members - SplashScreen(); - ~SplashScreen(); - - void RenderFrame(SDL_Renderer* renderer) override; - -private: - //Frame loop - void FrameStart() override; - - //members - std::chrono::steady_clock::time_point startTick; - Image logo; -}; diff --git a/client/scene_signal.hpp b/client/scene_signal.hpp deleted file mode 100644 index 2604ce4..0000000 --- a/client/scene_signal.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 - -enum SceneSignal { - //reserved members for internal use - QUIT = -1, - CONTINUE = 0, - FIRST = 1, - - //custom scenes - SPLASHSCREEN, - MAINMENU, - OPTIONSMENU, - LOBBYMENU, - WORLD, - DISCONNECTEDSCREEN, -}; \ No newline at end of file diff --git a/common/graphics/makefile b/common/graphics/makefile deleted file mode 100644 index 0d2afc1..0000000 --- a/common/graphics/makefile +++ /dev/null @@ -1,32 +0,0 @@ -#config -INCLUDES+=. ../map -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)/,libcommon.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 $@ $< diff --git a/common/makefile b/common/makefile deleted file mode 100644 index dcfef9b..0000000 --- a/common/makefile +++ /dev/null @@ -1,7 +0,0 @@ -all: - $(MAKE) -C debugging - $(MAKE) -C gameplay - $(MAKE) -C graphics - $(MAKE) -C map - $(MAKE) -C network - $(MAKE) -C utilities diff --git a/copyright.txt b/copyright.txt deleted file mode 100644 index 964147d..0000000 --- a/copyright.txt +++ /dev/null @@ -1,15 +0,0 @@ -Future versions (to be determined) may be released under a modified version of the Uplink Developer's License. - -The current version of Tortuga is released under the zlib license. - -Copyright (c) 2013-2015 Kayne Ruse - -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. \ No newline at end of file diff --git a/client/client_utilities/makefile b/debugging/makefile similarity index 87% rename from client/client_utilities/makefile rename to debugging/makefile index 803bbcf..e6bcb85 100644 --- a/client/client_utilities/makefile +++ b/debugging/makefile @@ -10,10 +10,6 @@ CXXSRC=$(wildcard *.cpp) OBJDIR=obj OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) -#output -OUTDIR=.. -OUT=$(addprefix $(OUTDIR)/,client.a) - #targets all: $(OBJ) $(OUT) ar -crs $(OUT) $(OBJ) diff --git a/common/debugging/timer.cpp b/debugging/timer.cpp similarity index 100% rename from common/debugging/timer.cpp rename to debugging/timer.cpp diff --git a/common/debugging/timer.hpp b/debugging/timer.hpp similarity index 100% rename from common/debugging/timer.hpp rename to debugging/timer.hpp diff --git a/common/gameplay/character_defines.hpp b/gameplay/character_defines.hpp similarity index 100% rename from common/gameplay/character_defines.hpp rename to gameplay/character_defines.hpp diff --git a/common/utilities/makefile b/gameplay/makefile similarity index 86% rename from common/utilities/makefile rename to gameplay/makefile index 104b518..e6bcb85 100644 --- a/common/utilities/makefile +++ b/gameplay/makefile @@ -10,10 +10,6 @@ CXXSRC=$(wildcard *.cpp) OBJDIR=obj OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) -#output -OUTDIR=../.. -OUT=$(addprefix $(OUTDIR)/,libcommon.a) - #targets all: $(OBJ) $(OUT) ar -crs $(OUT) $(OBJ) diff --git a/common/graphics/button.cpp b/graphics/button.cpp similarity index 100% rename from common/graphics/button.cpp rename to graphics/button.cpp diff --git a/common/graphics/button.hpp b/graphics/button.hpp similarity index 100% rename from common/graphics/button.hpp rename to graphics/button.hpp diff --git a/common/graphics/image.cpp b/graphics/image.cpp similarity index 100% rename from common/graphics/image.cpp rename to graphics/image.cpp diff --git a/common/graphics/image.hpp b/graphics/image.hpp similarity index 100% rename from common/graphics/image.hpp rename to graphics/image.hpp diff --git a/common/debugging/makefile b/graphics/makefile similarity index 86% rename from common/debugging/makefile rename to graphics/makefile index 104b518..e6bcb85 100644 --- a/common/debugging/makefile +++ b/graphics/makefile @@ -10,10 +10,6 @@ CXXSRC=$(wildcard *.cpp) OBJDIR=obj OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) -#output -OUTDIR=../.. -OUT=$(addprefix $(OUTDIR)/,libcommon.a) - #targets all: $(OBJ) $(OUT) ar -crs $(OUT) $(OBJ) diff --git a/common/graphics/sprite_sheet.cpp b/graphics/sprite_sheet.cpp similarity index 100% rename from common/graphics/sprite_sheet.cpp rename to graphics/sprite_sheet.cpp diff --git a/common/graphics/sprite_sheet.hpp b/graphics/sprite_sheet.hpp similarity index 100% rename from common/graphics/sprite_sheet.hpp rename to graphics/sprite_sheet.hpp diff --git a/common/graphics/text_box.cpp b/graphics/text_box.cpp similarity index 100% rename from common/graphics/text_box.cpp rename to graphics/text_box.cpp diff --git a/common/graphics/text_box.hpp b/graphics/text_box.hpp similarity index 100% rename from common/graphics/text_box.hpp rename to graphics/text_box.hpp diff --git a/common/graphics/text_line.cpp b/graphics/text_line.cpp similarity index 100% rename from common/graphics/text_line.cpp rename to graphics/text_line.cpp diff --git a/common/graphics/text_line.hpp b/graphics/text_line.hpp similarity index 100% rename from common/graphics/text_line.hpp rename to graphics/text_line.hpp diff --git a/instructions.txt b/instructions.txt deleted file mode 100644 index 85fcaf9..0000000 --- a/instructions.txt +++ /dev/null @@ -1,35 +0,0 @@ -This is the README for Tortuga's demo build. The source code is available at: - - https://github.com/Ratstail91/Tortuga - -The current build may have bugs, missing features, bugs masquerading as -features, etc. You can report a bug/feature here: - - https://github.com/Ratstail91/Tortuga/issues - -Please note that this game requires a functioning server to operate correctly. -Both a game server and game client are included in this package. - -------------------------- -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: - -* client.username -* client.handle - -5. There are currently two options for 'client.avatar': - -* client.avatar = elliot2.bmp #male -* client.avatar = coa2.bmp #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. diff --git a/makefile b/makefile index efa122e..c5ac867 100644 --- a/makefile +++ b/makefile @@ -1,31 +1,19 @@ -#Windows 7: -#RM=del /y - -#Windows 8.1: -#RM=del /S - -OUTDIR=out +#output +export OUTDIR=.. +export OUT=$(addprefix $(OUTDIR)/,libcommon.a) all: $(OUTDIR) - $(MAKE) -C common -# $(MAKE) -C server - $(MAKE) -C client + $(MAKE) -C debugging + $(MAKE) -C gameplay + $(MAKE) -C graphics + $(MAKE) -C map + $(MAKE) -C network + $(MAKE) -C ui + $(MAKE) -C utilities debug: export CXXFLAGS+=-g debug: clean all -release: export CXXFLAGS+=-static-libgcc -static-libstdc++ -release: clean all package - -#For use on my machine ONLY -package: -ifeq ($(OS),Windows_NT) - rar a -r -ep Tortuga-win.rar $(OUTDIR)/*.exe $(OUTDIR)/*.dll - rar a -r Tortuga-win.rar rsc/* copyright.txt instructions.txt -else ifeq ($(shell uname), Linux) - tar -C $(OUTDIR) -zcvf Tortuga-linux.tar client server ../rsc ../copyright.txt ../instructions.txt -endif - $(OUTDIR): mkdir $(OUTDIR) @@ -33,9 +21,9 @@ clean: ifeq ($(OS),Windows_NT) $(RM) *.o *.a *.exe else ifeq ($(shell uname), Linux) - find . -type f -name '*.o' -exec rm -f -r -v {} \; - find . -type f -name '*.a' -exec rm -f -r -v {} \; - rm -f -v $(OUT) + find . -type f -name *.o -exec rm -f -r -v {} \; + find . -type f -name *.a -exec rm -f -r -v {} \; + rm -f -v out/client out/server endif rebuild: clean all diff --git a/common/map/makefile b/map/makefile similarity index 86% rename from common/map/makefile rename to map/makefile index 03a0db8..7e6b897 100644 --- a/common/map/makefile +++ b/map/makefile @@ -10,10 +10,6 @@ CXXSRC=$(wildcard *.cpp) OBJDIR=obj OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) -#output -OUTDIR=../.. -OUT=$(addprefix $(OUTDIR)/,libcommon.a) - #targets all: $(OBJ) $(OUT) ar -crs $(OUT) $(OBJ) diff --git a/common/map/region.cpp b/map/region.cpp similarity index 100% rename from common/map/region.cpp rename to map/region.cpp diff --git a/common/map/region.hpp b/map/region.hpp similarity index 100% rename from common/map/region.hpp rename to map/region.hpp diff --git a/common/map/region_api.cpp b/map/region_api.cpp similarity index 100% rename from common/map/region_api.cpp rename to map/region_api.cpp diff --git a/common/map/region_api.hpp b/map/region_api.hpp similarity index 100% rename from common/map/region_api.hpp rename to map/region_api.hpp diff --git a/common/map/region_pager_api.cpp b/map/region_pager_api.cpp similarity index 100% rename from common/map/region_pager_api.cpp rename to map/region_pager_api.cpp diff --git a/common/map/region_pager_api.hpp b/map/region_pager_api.hpp similarity index 100% rename from common/map/region_pager_api.hpp rename to map/region_pager_api.hpp diff --git a/common/map/region_pager_base.cpp b/map/region_pager_base.cpp similarity index 100% rename from common/map/region_pager_base.cpp rename to map/region_pager_base.cpp diff --git a/common/map/region_pager_base.hpp b/map/region_pager_base.hpp similarity index 100% rename from common/map/region_pager_base.hpp rename to map/region_pager_base.hpp diff --git a/common/map/region_pager_lua.cpp b/map/region_pager_lua.cpp similarity index 100% rename from common/map/region_pager_lua.cpp rename to map/region_pager_lua.cpp diff --git a/common/map/region_pager_lua.hpp b/map/region_pager_lua.hpp similarity index 100% rename from common/map/region_pager_lua.hpp rename to map/region_pager_lua.hpp diff --git a/common/map/tile_sheet.cpp b/map/tile_sheet.cpp similarity index 100% rename from common/map/tile_sheet.cpp rename to map/tile_sheet.cpp diff --git a/common/map/tile_sheet.hpp b/map/tile_sheet.hpp similarity index 100% rename from common/map/tile_sheet.hpp rename to map/tile_sheet.hpp diff --git a/common/network/makefile b/network/makefile similarity index 87% rename from common/network/makefile rename to network/makefile index f1d2063..3bcac3d 100644 --- a/common/network/makefile +++ b/network/makefile @@ -10,10 +10,6 @@ CXXSRC=$(wildcard *.cpp) OBJDIR=obj OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) -#output -OUTDIR=../.. -OUT=$(addprefix $(OUTDIR)/,libcommon.a) - #targets all: $(OBJ) $(OUT) ar -crs $(OUT) $(OBJ) diff --git a/common/network/packet_types/character_packet.cpp b/network/packet_types/character_packet.cpp similarity index 100% rename from common/network/packet_types/character_packet.cpp rename to network/packet_types/character_packet.cpp diff --git a/common/network/packet_types/character_packet.hpp b/network/packet_types/character_packet.hpp similarity index 100% rename from common/network/packet_types/character_packet.hpp rename to network/packet_types/character_packet.hpp diff --git a/common/network/packet_types/client_packet.cpp b/network/packet_types/client_packet.cpp similarity index 100% rename from common/network/packet_types/client_packet.cpp rename to network/packet_types/client_packet.cpp diff --git a/common/network/packet_types/client_packet.hpp b/network/packet_types/client_packet.hpp similarity index 100% rename from common/network/packet_types/client_packet.hpp rename to network/packet_types/client_packet.hpp diff --git a/common/network/packet_types/makefile b/network/packet_types/makefile similarity index 88% rename from common/network/packet_types/makefile rename to network/packet_types/makefile index 241fc55..3526e73 100644 --- a/common/network/packet_types/makefile +++ b/network/packet_types/makefile @@ -11,8 +11,8 @@ OBJDIR=obj OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) #output -OUTDIR=../../.. -OUT=$(addprefix $(OUTDIR)/,libcommon.a) +OUTDIR=../$(OUTDIR) +OUT=../$(OUT) #targets all: $(OBJ) $(OUT) diff --git a/common/network/packet_types/monster_packet.cpp b/network/packet_types/monster_packet.cpp similarity index 100% rename from common/network/packet_types/monster_packet.cpp rename to network/packet_types/monster_packet.cpp diff --git a/common/network/packet_types/monster_packet.hpp b/network/packet_types/monster_packet.hpp similarity index 100% rename from common/network/packet_types/monster_packet.hpp rename to network/packet_types/monster_packet.hpp diff --git a/common/network/packet_types/region_packet.cpp b/network/packet_types/region_packet.cpp similarity index 100% rename from common/network/packet_types/region_packet.cpp rename to network/packet_types/region_packet.cpp diff --git a/common/network/packet_types/region_packet.hpp b/network/packet_types/region_packet.hpp similarity index 100% rename from common/network/packet_types/region_packet.hpp rename to network/packet_types/region_packet.hpp diff --git a/common/network/packet_types/serial_packet_base.cpp b/network/packet_types/serial_packet_base.cpp similarity index 100% rename from common/network/packet_types/serial_packet_base.cpp rename to network/packet_types/serial_packet_base.cpp diff --git a/common/network/packet_types/serial_packet_base.hpp b/network/packet_types/serial_packet_base.hpp similarity index 100% rename from common/network/packet_types/serial_packet_base.hpp rename to network/packet_types/serial_packet_base.hpp diff --git a/common/network/packet_types/server_packet.cpp b/network/packet_types/server_packet.cpp similarity index 100% rename from common/network/packet_types/server_packet.cpp rename to network/packet_types/server_packet.cpp diff --git a/common/network/packet_types/server_packet.hpp b/network/packet_types/server_packet.hpp similarity index 100% rename from common/network/packet_types/server_packet.hpp rename to network/packet_types/server_packet.hpp diff --git a/common/network/packet_types/text_packet.cpp b/network/packet_types/text_packet.cpp similarity index 100% rename from common/network/packet_types/text_packet.cpp rename to network/packet_types/text_packet.cpp diff --git a/common/network/packet_types/text_packet.hpp b/network/packet_types/text_packet.hpp similarity index 100% rename from common/network/packet_types/text_packet.hpp rename to network/packet_types/text_packet.hpp diff --git a/common/network/serial_packet.hpp b/network/serial_packet.hpp similarity index 100% rename from common/network/serial_packet.hpp rename to network/serial_packet.hpp diff --git a/common/network/serial_packet_type.hpp b/network/serial_packet_type.hpp similarity index 100% rename from common/network/serial_packet_type.hpp rename to network/serial_packet_type.hpp diff --git a/common/network/serial_utility.cpp b/network/serial_utility.cpp similarity index 100% rename from common/network/serial_utility.cpp rename to network/serial_utility.cpp diff --git a/common/network/serial_utility.hpp b/network/serial_utility.hpp similarity index 100% rename from common/network/serial_utility.hpp rename to network/serial_utility.hpp diff --git a/common/network/udp_network_utility.cpp b/network/udp_network_utility.cpp similarity index 100% rename from common/network/udp_network_utility.cpp rename to network/udp_network_utility.cpp diff --git a/common/network/udp_network_utility.hpp b/network/udp_network_utility.hpp similarity index 100% rename from common/network/udp_network_utility.hpp rename to network/udp_network_utility.hpp diff --git a/rsc/config.cfg b/rsc/config.cfg deleted file mode 100644 index cf72bdc..0000000 --- a/rsc/config.cfg +++ /dev/null @@ -1,33 +0,0 @@ -#configuration of the programs - -#server specific settings -server.host = 255.255.255.255 -server.port = 21795 -server.name = local - -server.dbname = database.db - -#client specific settings -#client.screen.w = 800 -#client.screen.h = 600 -client.screen.f = false - -#TODO: change this based on platform? -client.font = /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf - -client.username = username -client.handle = handle -client.avatar = elliot2.bmp - -#directories -dir.logos = rsc/graphics/logos/ -dir.sprites = rsc/graphics/sprites/ -dir.tilesets = rsc/graphics/tilesets/ -dir.interface = rsc/graphics/interface/ -dir.scripts = rsc/scripts/ -dir.maps = rsc/maps/ - -#map system -map.savename = servermap - -#debugging diff --git a/rsc/graphics/interface/button.png b/rsc/graphics/interface/button.png deleted file mode 100644 index 867cd63..0000000 Binary files a/rsc/graphics/interface/button.png and /dev/null differ diff --git a/rsc/graphics/logos/krstudios.png b/rsc/graphics/logos/krstudios.png deleted file mode 100644 index 9a411c1..0000000 Binary files a/rsc/graphics/logos/krstudios.png and /dev/null differ diff --git a/rsc/graphics/sprites/aniflower.bmp b/rsc/graphics/sprites/aniflower.bmp deleted file mode 100644 index fbc60f5..0000000 Binary files a/rsc/graphics/sprites/aniflower.bmp and /dev/null differ diff --git a/rsc/graphics/sprites/coa2.bmp b/rsc/graphics/sprites/coa2.bmp deleted file mode 100644 index bd7b3c0..0000000 Binary files a/rsc/graphics/sprites/coa2.bmp and /dev/null differ diff --git a/rsc/graphics/sprites/elliot2.bmp b/rsc/graphics/sprites/elliot2.bmp deleted file mode 100644 index 89f66d8..0000000 Binary files a/rsc/graphics/sprites/elliot2.bmp and /dev/null differ diff --git a/rsc/graphics/sprites/skume1.bmp b/rsc/graphics/sprites/skume1.bmp deleted file mode 100644 index ae31c9a..0000000 Binary files a/rsc/graphics/sprites/skume1.bmp and /dev/null differ diff --git a/rsc/graphics/sprites/skume2.bmp b/rsc/graphics/sprites/skume2.bmp deleted file mode 100644 index b2c5623..0000000 Binary files a/rsc/graphics/sprites/skume2.bmp and /dev/null differ diff --git a/rsc/graphics/tilesets/MishMash.bmp b/rsc/graphics/tilesets/MishMash.bmp deleted file mode 100644 index 36093a8..0000000 Binary files a/rsc/graphics/tilesets/MishMash.bmp and /dev/null differ diff --git a/rsc/graphics/tilesets/blank.bmp b/rsc/graphics/tilesets/blank.bmp deleted file mode 100644 index 44b11c7..0000000 Binary files a/rsc/graphics/tilesets/blank.bmp and /dev/null differ diff --git a/rsc/graphics/tilesets/dirt.bmp b/rsc/graphics/tilesets/dirt.bmp deleted file mode 100644 index 089ba2a..0000000 Binary files a/rsc/graphics/tilesets/dirt.bmp and /dev/null differ diff --git a/rsc/graphics/tilesets/grass.bmp b/rsc/graphics/tilesets/grass.bmp deleted file mode 100644 index ac8c6e4..0000000 Binary files a/rsc/graphics/tilesets/grass.bmp and /dev/null differ diff --git a/rsc/graphics/tilesets/longgrass.bmp b/rsc/graphics/tilesets/longgrass.bmp deleted file mode 100644 index 8561d29..0000000 Binary files a/rsc/graphics/tilesets/longgrass.bmp and /dev/null differ diff --git a/rsc/graphics/tilesets/overworld.bmp b/rsc/graphics/tilesets/overworld.bmp deleted file mode 100644 index d9cc0c6..0000000 Binary files a/rsc/graphics/tilesets/overworld.bmp and /dev/null differ diff --git a/rsc/graphics/tilesets/sand.bmp b/rsc/graphics/tilesets/sand.bmp deleted file mode 100644 index c5f156a..0000000 Binary files a/rsc/graphics/tilesets/sand.bmp and /dev/null differ diff --git a/rsc/graphics/tilesets/terrain.bmp b/rsc/graphics/tilesets/terrain.bmp deleted file mode 100644 index 0a39c74..0000000 Binary files a/rsc/graphics/tilesets/terrain.bmp and /dev/null differ diff --git a/rsc/graphics/tilesets/water.bmp b/rsc/graphics/tilesets/water.bmp deleted file mode 100644 index 2c3f33e..0000000 Binary files a/rsc/graphics/tilesets/water.bmp and /dev/null differ diff --git a/rsc/scripts/door_utility.lua b/rsc/scripts/door_utility.lua deleted file mode 100644 index 49f272d..0000000 --- a/rsc/scripts/door_utility.lua +++ /dev/null @@ -1,89 +0,0 @@ ---[[ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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. -*/ ---]] - ---DOCS: a placeholder door utility - -local doorUtility = {} - -roomAPI = require("room") -regionPagerAPI = require("region_pager") - -triggerAPI = require("trigger") -triggerManagerAPI = require("trigger_manager") - -entityAPI = require("entity") -characterAPI = require("character") - -networkAPI = require("network") - -function doorUtility.createTrigger(handle, room, x, y, script) - local pager = roomAPI.GetPager(room) - - --place the indicator tile - regionPagerAPI.SetTile(pager, x / 32, y / 32, 0, mapMaker.dirt) - regionPagerAPI.SetTile(pager, x / 32, y / 32, 1, mapMaker.blank) - regionPagerAPI.SetTile(pager, x / 32, y / 32, 2, mapMaker.blank) - - --create the trigger object - triggerManagerAPI.Create( - roomAPI.GetTriggerMgr(room), handle, x, y, - 0, 0, 32, 32, --size of the tiles - script - ) -end - -function doorUtility.createDoorPair(handle, roomOne, Xone, Yone, roomTwo, Xtwo, Ytwo) - --create the scripts - local function scriptOne(entity) - if entityAPI.GetType(entity) ~= "character" then return end - - --move the character - characterAPI.SetRoom(entity, roomTwo) - characterAPI.SetOrigin(entity, Xtwo, Ytwo-16) - networkAPI.PumpCharacterUpdate(entity) - - --disable the other trigger - local triggerTwo = triggerManagerAPI.GetTrigger(roomAPI.GetTriggerMgr(roomTwo), handle) - triggerAPI.PushExclusionEntity(triggerTwo, entity) - end - - local function scriptTwo(entity) - if entityAPI.GetType(entity) ~= "character" then return end - - --move the character - characterAPI.SetRoom(entity, roomOne) - characterAPI.SetOrigin(entity, Xone, Yone-16) --NOTE: the 16 pixel margin for presentation - networkAPI.PumpCharacterUpdate(entity) - - --disable the other trigger - local triggerOne = triggerManagerAPI.GetTrigger(roomAPI.GetTriggerMgr(roomOne), handle) - triggerAPI.PushExclusionEntity(triggerOne, entity) - end - - --create the triggers proper - doorUtility.createTrigger(handle, roomOne, Xone, Yone, scriptOne) - doorUtility.createTrigger(handle, roomTwo, Xtwo, Ytwo, scriptTwo) -end - -return doorUtility \ No newline at end of file diff --git a/rsc/scripts/map_maker.lua b/rsc/scripts/map_maker.lua deleted file mode 100644 index 596570f..0000000 --- a/rsc/scripts/map_maker.lua +++ /dev/null @@ -1,141 +0,0 @@ ---[[ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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. -*/ ---]] - ---DOCS: a placeholder map generator - -local regionAPI = require("region") - -local mapMaker = {} - ---utility functions -function mapMaker.Sqr(x) return x*x end -function mapMaker.Dist(x, y, i, j) return math.sqrt(mapMaker.Sqr(x - i) + mapMaker.Sqr(y - j)) end - ---tile macros, mapped to the tilesheet "overworld.bmp" -mapMaker.blank = 0 -mapMaker.water = 18 + 3 * 0 -mapMaker.sand = 18 + 3 * 1 -mapMaker.plains = 18 + 3 * 2 -mapMaker.grass = 18 + 3 * 3 -mapMaker.dirt = 18 + 3 * 4 - ---"edge" macros -mapMaker.edges = {} -mapMaker.edges.north = -16 -mapMaker.edges.south = 16 -mapMaker.edges.east = 1 -mapMaker.edges.west = -1 - ---TODO: (1) path system ---use these macros (mapped to "overworld.bmp" for now) to smooth the region's edges -function mapMaker.SmoothEdgesSimple(r) - --make and pad an array to use - local shiftArray = {} - for i = 1, regionAPI.GetWidth(r) do - shiftArray[i] = {} - for j = 1, regionAPI.GetHeight(r) do - shiftArray[i][j] = 0 - end - end - - --build the array - for i = 1, regionAPI.GetWidth(r) do - for j = 1, regionAPI.GetHeight(r) do - --if (not regionAPI edge) and (west tile < this tile), etc. - if i > 1 and regionAPI.GetTile(r, i - 1, j, 1) < regionAPI.GetTile(r, i, j, 1) then - shiftArray[i][j] = shiftArray[i][j] + mapMaker.edges.west - end - if j > 1 and regionAPI.GetTile(r, i, j - 1, 1) < regionAPI.GetTile(r, i, j, 1) then - shiftArray[i][j] = shiftArray[i][j] + mapMaker.edges.north - end - if i < regionAPI.GetWidth(r) and regionAPI.GetTile(r, i + 1, j, 1) < regionAPI.GetTile(r, i, j, 1) then - shiftArray[i][j] = shiftArray[i][j] + mapMaker.edges.east - end - if j < regionAPI.GetHeight(r) and regionAPI.GetTile(r, i, j + 1, 1) < regionAPI.GetTile(r, i, j, 1) then - shiftArray[i][j] = shiftArray[i][j] + mapMaker.edges.south - end - end - end - - --finally apply this - for i = 1, regionAPI.GetWidth(r) do - for j = 1, regionAPI.GetHeight(r) do - if shiftArray[i][j] ~= 0 then - regionAPI.SetTile(r, i, j, 2, regionAPI.GetTile(r, i, j, 1) + shiftArray[i][j]) - regionAPI.SetTile(r, i, j, 1, regionAPI.GetTile(r, i, j, 1) - 3) - end - end - end -end - ---custom generation systems here -function mapMaker.DebugIsland(r) - --debug - io.write("map_maker:DebugIsland(", regionAPI.GetX(r), ", ", regionAPI.GetY(r), ")\n") - - --basic distance check for each tile, placing an island around the world origin - for i = 1, regionAPI.GetWidth(r) do - for j = 1, regionAPI.GetHeight(r) do - local dist = mapMaker.Dist(0, 0, i + regionAPI.GetX(r) -1, j + regionAPI.GetY(r) -1) - if dist < 10 then - regionAPI.SetTile(r, i, j, 1, mapMaker.plains) - elseif dist < 12 then - regionAPI.SetTile(r, i, j, 1, mapMaker.sand) - else - regionAPI.SetTile(r, i, j, 1, mapMaker.water) - regionAPI.SetSolid(r, i, j, true) - end - end - end - - --examples of the smoothing function NOT working correctly - --[[ - for j = 1, regionAPI.GetHeight(r) do - regionAPI.SetTile(r, 3, j, 1, mapMaker.dirt) - regionAPI.SetTile(r, 4, j, 1, mapMaker.dirt) - - regionAPI.SetTile(r, 10, j, 1, mapMaker.dirt) - end - --]] - - --A generic edge system - mapMaker.SmoothEdgesSimple(r) -end - -function mapMaker.DebugGrassland(r) - --debug - io.write("map_maker:DebugGrassland(", regionAPI.GetX(r), ", ", regionAPI.GetY(r), ")\n") - - --all dirt - for i = 1, regionAPI.GetWidth(r) do - for j = 1, regionAPI.GetHeight(r) do - regionAPI.SetTile(r, i, j, 1, mapMaker.grass) - end - end - - --A generic edge system --- mapMaker.SmoothEdgesSimple(r) -end - -return mapMaker \ No newline at end of file diff --git a/rsc/scripts/map_saver.lua b/rsc/scripts/map_saver.lua deleted file mode 100644 index f2f4ea0..0000000 --- a/rsc/scripts/map_saver.lua +++ /dev/null @@ -1,39 +0,0 @@ ---[[ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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. -*/ ---]] - -local region = require("region") - -local mapSaver = {} - -function mapSaver.Load(r) - --empty --- io.write("map_saver:Load(", region.GetX(r), ", ", region.GetY(r), ")\n") -end -function mapSaver.Save(r) - --empty --- io.write("map_saver:Save(", region.GetX(r), ", ", region.GetY(r), ")\n") -end - ---TODO: (3) create a flexible saving & loading system -return mapSaver \ No newline at end of file diff --git a/rsc/scripts/setup_server.lua b/rsc/scripts/setup_server.lua deleted file mode 100644 index 4cb4972..0000000 --- a/rsc/scripts/setup_server.lua +++ /dev/null @@ -1,61 +0,0 @@ ---[[ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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. -*/ ---]] - ---DOCS: This script is run by the server on startup - -print("Lua script check") - ---requirements -roomManagerAPI = require("room_manager") -roomAPI = require("room") - -mapMaker = require("map_maker") -mapSaver = require("map_saver") - -doorUtility = require("door_utility") - ---test the room hooks -roomManagerAPI.SetOnCreate(function(room, index) - print("", "Creating room: ", roomAPI.GetName(room), index) - - roomAPI.SetOnTick(room, function(room) - roomAPI.ForEachCharacter(room, function(character) - -- - end) - end) -end) - -roomManagerAPI.SetOnUnload(function(room, index) - print("", "Unloading room: ", roomAPI.GetName(room), index) -end) - ---NOTE: room 0 is the first that the client asks for, therefore it must exist -local overworld, uidOne = roomManagerAPI.CreateRoom("overworld", "overworld.bmp") -roomAPI.Initialize(overworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugIsland, mapSaver.Save) - -local underworld, uidTwo = roomManagerAPI.CreateRoom("underworld", "overworld.bmp") -roomAPI.Initialize(underworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugGrassland, mapSaver.Save) - ---call the monstrosity -doorUtility.createDoorPair("pair 1", overworld, -64, -64, underworld, 64, 64) diff --git a/rsc/scripts/setup_server.sql b/rsc/scripts/setup_server.sql deleted file mode 100644 index 1ef5983..0000000 --- a/rsc/scripts/setup_server.sql +++ /dev/null @@ -1,158 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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. -*/ - -CREATE TABLE IF NOT EXISTS UserAccounts ( - uid INTEGER PRIMARY KEY AUTOINCREMENT, - username varchar(100) UNIQUE, --TODO: (3) Swap username for email address - - --server-client security --- passhash varchar(100), --- passsalt varchar(100), - - --server controls - blacklisted BIT DEFAULT 0, - whitelisted BIT DEFAULT 1, - mod BIT DEFAULT 0, - admin BIT DEFAULT 0 -); - -CREATE TABLE IF NOT EXISTS LiveCharacters ( - uid INTEGER PRIMARY KEY AUTOINCREMENT, - - --metadata - owner INTEGER REFERENCES Accounts(uid), - handle varchar(100) UNIQUE, - avatar varchar(100), - birth timestamp NOT NULL DEFAULT (datetime()), - - --physically exists in the world - roomIndex INTEGER DEFAULT 0, - originX INTEGER DEFAULT 0, - originY INTEGER DEFAULT 0, - boundsX INTEGER DEFAULT 0, - boundsY INTEGER DEFAULT 0, - boundsW INTEGER DEFAULT 0, - boundsH INTEGER DEFAULT 0 -); - -CREATE TABLE IF NOT EXISTS DeadCharacters ( - uid INTEGER PRIMARY KEY, - - --metadata - owner INTEGER REFERENCES Accounts(uid), - handle varchar(100), - avatar varchar(100), - birth timestamp NOT NULL -); - -CREATE TABLE IF NOT EXISTS LiveMonsters ( - uid INTEGER PRIMARY KEY AUTOINCREMENT, - - --metadata - handle varchar(100) UNIQUE, - avatar varchar(100), - - --actions --- script - - --physically exists in the world - roomIndex INTEGER DEFAULT 0, - originX INTEGER DEFAULT 0, - originY INTEGER DEFAULT 0, - boundsX INTEGER DEFAULT 0, - boundsY INTEGER DEFAULT 0, - boundsW INTEGER DEFAULT 0, - boundsH INTEGER DEFAULT 0 -); - -CREATE TABLE IF NOT EXISTS DeadMonsters ( - uid INTEGER PRIMARY KEY, - - --metadata - handle varchar(100) UNIQUE, - avatar varchar(100) -); - -------------------------- ---Utility tables -------------------------- - -CREATE TABLE IF NOT EXISTS StatisticSets ( - --metadata - uid INTEGER PRIMARY KEY AUTOINCREMENT, - - --general use statistics - level INTEGER DEFAULT 0, - exp INTEGER DEFAULT 0, - maxHP INTEGER DEFAULT 0, - health INTEGER DEFAULT 0, - maxMP INTEGER DEFAULT 0, - mana INTEGER DEFAULT 0, - attack INTEGER DEFAULT 0, - defence INTEGER DEFAULT 0, - intelligence INTEGER DEFAULT 0, - resistance INTEGER DEFAULT 0, - speed INTEGER DEFAULT 0, - accuracy REAL DEFAULT 0.0, - evasion REAL DEFAULT 0.0, - luck REAL DEFAULT 0.0 -); - -CREATE TABLE IF NOT EXISTS InWorldItems ( - --metadata - uid INTEGER PRIMARY KEY AUTOINCREMENT, - itemType INTEGER, - - --position in the world - roomIndex INTEGER DEFAULT 0, - originX INTEGER DEFAULT 0, - originY INTEGER DEFAULT 0, - - --unique information - stackSize INTEGER DEFAULT 0, - durability INTEGER DEFAULT 0, - stats INTEGER REFERENCES StatisticSets(uid) -); - -CREATE TABLE IF NOT EXISTS InventoryItems ( - --metadata - uid INTEGER PRIMARY KEY AUTOINCREMENT, - owner INTEGER REFERENCES Characters(uid), - itemType INTEGER, - - --unique information - stackSize INTEGER DEFAULT 0, - durability INTEGER DEFAULT 0, - stats INTEGER REFERENCES StatisticSets(uid) -); - -CREATE TABLE IF NOT EXISTS WornEquipment ( - --metadata - uid INTEGER PRIMARY KEY AUTOINCREMENT, - owner INTEGER REFERENCES Characters(uid), - itemType INTEGER, - - --unique information - durability INTEGER DEFAULT 0, - stats INTEGER REFERENCES StatisticSets(uid) - --attached script? -); diff --git a/server/accounts/account_data.cpp b/server/accounts/account_data.cpp deleted file mode 100644 index 0ee36b0..0000000 --- a/server/accounts/account_data.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "account_data.hpp" - -int AccountData::SetClientIndex(int i) { - return clientIndex = i; -} - -int AccountData::GetClientIndex() { - return clientIndex; -} - -std::string AccountData::SetUsername(std::string s) { - return username = s; -} - -std::string AccountData::GetUsername() { - return username; -} - -bool AccountData::GetBlackListed() { - return blackListed; -} - -bool AccountData::GetWhiteListed() { - return whiteListed; -} - -bool AccountData::GetModerator() { - return mod; -} - -bool AccountData::GetAdministrator() { - return admin; -} \ No newline at end of file diff --git a/server/accounts/account_data.hpp b/server/accounts/account_data.hpp deleted file mode 100644 index 2feecd8..0000000 --- a/server/accounts/account_data.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 - -class AccountData { -public: - AccountData() = default; - ~AccountData() = default; - - //accessors and mutators - int SetClientIndex(int i); - int GetClientIndex(); - - std::string SetUsername(std::string s); - std::string GetUsername(); - - //database stuff - bool GetBlackListed(); - bool GetWhiteListed(); - bool GetModerator(); - bool GetAdministrator(); - -private: - friend class AccountManager; - - int clientIndex; - std::string username; - //password/auth token - - //bit fields? - bool blackListed = false; - bool whiteListed = true; - bool mod = false; - bool admin = false; -}; diff --git a/server/accounts/account_manager.cpp b/server/accounts/account_manager.cpp deleted file mode 100644 index bf67d41..0000000 --- a/server/accounts/account_manager.cpp +++ /dev/null @@ -1,279 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "account_manager.hpp" - -#include - -//------------------------- -//Define the queries -//------------------------- - -static const char* CREATE_USER_ACCOUNT = "INSERT INTO UserAccounts (username) VALUES (?);"; - -static const char* LOAD_USER_ACCOUNT = "SELECT " - "uid, " - "blacklisted, " - "whitelisted, " - "mod, " - "admin " - " FROM UserAccounts WHERE username = ?;"; - -static const char* SAVE_USER_ACCOUNT = "UPDATE OR FAIL UserAccounts SET " - "blacklisted = ?2, " - "whitelisted = ?3, " - "mod = ?4, " - "admin = ?5 " - "WHERE uid = ?1;"; - -static const char* DELETE_USER_ACCOUNT = "DELETE FROM UserAccounts WHERE uid = ?;"; - -static const char* COUNT_USER_ACCOUNT_RECORDS = "SELECT COUNT(*) FROM UserAccounts;"; - -//------------------------- -//Define the public methods -//------------------------- - -//TODO: (1) block blacklisted accounts -int AccountManager::Create(std::string username, int clientIndex) { - //create this user account, failing if it exists, leave this account in memory - sqlite3_stmt* statement = nullptr; - - //prep - if (sqlite3_prepare_v2(database, CREATE_USER_ACCOUNT, -1, &statement, nullptr) != SQLITE_OK) { - throw( std::runtime_error(std::string() + "Failed to prepare an SQL statement: " + sqlite3_errmsg(database)) ); - } - - //parameter - if (sqlite3_bind_text(statement, 1, username.c_str(), username.size() + 1, SQLITE_STATIC) != SQLITE_OK) { - throw( std::runtime_error(std::string() + "Failed to replace a prepared statement's parameter: " + sqlite3_errmsg(database)) ); - } - - //execute - if (sqlite3_step(statement) != SQLITE_DONE) { - //if this fails, than this account exists - sqlite3_finalize(statement); - return -1; - } - - sqlite3_finalize(statement); - - //load this account into memory - return Load(username, clientIndex); -} - -int AccountManager::Load(std::string username, int clientIndex) { - //load this user account, failing if it is in memory, creating it if it doesn't exist - sqlite3_stmt* statement = nullptr; - - //prep - if (sqlite3_prepare_v2(database, LOAD_USER_ACCOUNT, -1, &statement, nullptr) != SQLITE_OK) { - throw( std::runtime_error(std::string() + "Failed to prepare an SQL statement: " + sqlite3_errmsg(database)) ); - } - - //parameter - if (sqlite3_bind_text(statement, 1, username.c_str(), username.size() + 1, SQLITE_STATIC) != SQLITE_OK) { - throw( std::runtime_error(std::string() + "Failed to replace a prepared statement's parameter: " + sqlite3_errmsg(database)) ); - } - - //execute - int ret = sqlite3_step(statement); - - //process the result - if (ret == SQLITE_ROW) { - //get the index - int uid = sqlite3_column_int(statement, 0); - - //check to see if this account is already loaded - if (elementMap.find(uid) != elementMap.end()) { - sqlite3_finalize(statement); - return -1; - } - - //extract the data into memory - AccountData& newAccount = elementMap[uid]; - newAccount.username = username; - newAccount.blackListed = sqlite3_column_int(statement, 1); - newAccount.whiteListed = sqlite3_column_int(statement, 2); - newAccount.mod = sqlite3_column_int(statement, 3); - newAccount.admin = sqlite3_column_int(statement, 4); - newAccount.clientIndex = clientIndex; - - //finish the routine - sqlite3_finalize(statement); - return uid; - } - - sqlite3_finalize(statement); - - if (ret == SQLITE_DONE) { - //create the non-existant account instead - return Create(username, clientIndex); - } - - throw(std::runtime_error(std::string() + "Unknown SQL error in LoadAccount: " + sqlite3_errmsg(database) )); -} - -int AccountManager::Save(int uid) { - //save this user account from memory, replacing it if it exists in the database - //DOCS: To use this method, change the in-memory copy, and then call this function using that object's UID. - - //this method fails if this account is not loaded - if (elementMap.find(uid) == elementMap.end()) { - return -1; - } - - AccountData& account = elementMap[uid]; - sqlite3_stmt* statement = nullptr; - - //prep - if (sqlite3_prepare_v2(database, SAVE_USER_ACCOUNT, -1, &statement, nullptr) != SQLITE_OK) { - throw( std::runtime_error(std::string() + "Failed to prepare an SQL statement: " + sqlite3_errmsg(database)) ); - } - - //parameters - bool ret = false; - ret |= sqlite3_bind_int(statement, 1, uid) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 2, account.blackListed) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 3, account.whiteListed) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 4, account.mod) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 5, account.admin) != SQLITE_OK; - - //check for binding errors - if (ret) { - throw( std::runtime_error(std::string() + "Failed to replace a prepared statement's parameter: " + sqlite3_errmsg(database)) ); - } - - //execute - if (sqlite3_step(statement) != SQLITE_DONE) { - //if this fails, than something went horribly wrong - sqlite3_finalize(statement); - throw( std::runtime_error(std::string() + "Unknown SQL error when saving an account: " + sqlite3_errmsg(database)) ); - } - - sqlite3_finalize(statement); - - //successful execution - return 0; -} - -void AccountManager::Unload(int uid) { - //save this user account, and then unload it - //NOTE: the associated characters are unloaded externally - Save(uid); - elementMap.erase(uid); -} - -void AccountManager::Delete(int uid) { - //delete a user account from the database, and remove it from memory - //NOTE: the associated characters should be deleted externally - sqlite3_stmt* statement = nullptr; - - //prep - if (sqlite3_prepare_v2(database, DELETE_USER_ACCOUNT, -1, &statement, nullptr) != SQLITE_OK) { - throw( std::runtime_error(std::string() + "Failed to prepare an SQL statement: " + sqlite3_errmsg(database)) ); - } - - //parameter - if (sqlite3_bind_int(statement, 1, uid) != SQLITE_OK) { - throw( std::runtime_error(std::string() + "Failed to replace a prepared statement's parameter: " + sqlite3_errmsg(database)) ); - } - - //execute - if (sqlite3_step(statement) != SQLITE_DONE) { - //if this fails, than something went horribly wrong - sqlite3_finalize(statement); - throw( std::runtime_error(std::string() + "Unknown SQL error when deleting an account: " + sqlite3_errmsg(database)) ); - } - - //finish the routine - sqlite3_finalize(statement); - elementMap.erase(uid); -} - -void AccountManager::UnloadAll() { - for (auto& it : elementMap) { - Save(it.first); - } - elementMap.clear(); -} - -void AccountManager::UnloadIf(std::function)> fn) { - //replicate std::remove_if, using custom code - std::map::iterator it = elementMap.begin(); - while (it != elementMap.end()) { - if (fn(*it)) { - Save(it->first); - it = elementMap.erase(it); - } - else { - ++it; - } - } -} - -//------------------------- -//Define the accessors and mutators -//------------------------- - -AccountData* AccountManager::Get(int uid) { - std::map::iterator it = elementMap.find(uid); - - if (it == elementMap.end()) { - return nullptr; - } - - return &it->second; -} - -int AccountManager::GetLoadedCount() { - return elementMap.size(); -} - -int AccountManager::GetTotalCount() { - //a lot just to count something. - sqlite3_stmt* statement = nullptr; - - //prep - if (sqlite3_prepare_v2(database, COUNT_USER_ACCOUNT_RECORDS, -1, &statement, nullptr) != SQLITE_OK) { - throw( std::runtime_error(std::string() + "Failed to prepare an SQL statement: " + sqlite3_errmsg(database)) ); - } - - //execute & retrieve the result - sqlite3_step(statement); - int ret = sqlite3_column_int(statement, 0); - - //finish the routine - sqlite3_finalize(statement); - return ret; -} - -std::map* AccountManager::GetContainer() { - return &elementMap; -} - -sqlite3* AccountManager::SetDatabase(sqlite3* db) { - return database = db; -} - -sqlite3* AccountManager::GetDatabase() { - return database; -} diff --git a/server/accounts/account_manager.hpp b/server/accounts/account_manager.hpp deleted file mode 100644 index 9a3ca45..0000000 --- a/server/accounts/account_manager.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "account_data.hpp" -#include "singleton.hpp" - -#include "sqlite3.h" - -#include -#include - -class AccountManager: public Singleton { -public: - //common public methods - int Create(std::string username, int clientIndex); - int Load(std::string username, int clientIndex); - int Save(int uid); - void Unload(int uid); - void Delete(int uid); - - void UnloadAll(); - void UnloadIf(std::function)> fn); - - //accessors and mutators - AccountData* Get(int uid); - int GetLoadedCount(); - int GetTotalCount(); - std::map* GetContainer(); - - sqlite3* SetDatabase(sqlite3* db); - sqlite3* GetDatabase(); - -private: - friend Singleton; - - AccountManager() = default; - ~AccountManager() = default; - - //members - std::map elementMap; - sqlite3* database = nullptr; -}; diff --git a/server/accounts/makefile b/server/accounts/makefile deleted file mode 100644 index 635dbd4..0000000 --- a/server/accounts/makefile +++ /dev/null @@ -1,32 +0,0 @@ -#config -INCLUDES+=. ../server_utilities ../../common/utilities -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)/,server.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 $@ $< diff --git a/server/characters/character_api.cpp b/server/characters/character_api.cpp deleted file mode 100644 index 99b2cfe..0000000 --- a/server/characters/character_api.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "character_api.hpp" - -#include "character_data.hpp" -#include "character_manager.hpp" -#include "entity_api.hpp" -#include "room_manager.hpp" -#include "server_utilities.hpp" - -#include - -static int setRoom(lua_State* L) { - //reverse engineer the character index - int characterIndex = -1; - CharacterData* character = static_cast(lua_touserdata(L, 1)); - CharacterManager& characterMgr = CharacterManager::GetSingleton(); - - for (auto& it : *characterMgr.GetContainer()) { - if (character == &it.second) { - characterIndex = it.first; - break; - } - } - - //error checking - if (characterIndex == -1) { - throw(std::runtime_error("Lua Error: Failed to find character index by reference")); - } - - //get the room index, depending on the parameter type - int roomIndex = -1; - RoomManager& roomMgr = RoomManager::GetSingleton(); - switch(lua_type(L, 2)) { - case LUA_TNUMBER: - roomIndex = lua_tointeger(L, 2); - break; - case LUA_TLIGHTUSERDATA: - //reverse engineer the room index - for (auto& it : *roomMgr.GetContainer()) { - if (lua_touserdata(L, 2) == &it.second) { - roomIndex = it.first; - break; - } - } - break; - } - - //error checking - if (roomIndex == -1) { - throw(std::runtime_error("Lua Error: Failed to find room index by reference")); - } - - //send the delete & create messages - pumpAndChangeRooms(character, roomIndex, characterIndex); - return 0; -} - -static int getOwner(lua_State* L) { - CharacterData* character = static_cast(lua_touserdata(L, 1)); - lua_pushinteger(L, character->GetOwner()); - return 1; -} - -static int getHandle(lua_State* L) { - CharacterData* character = static_cast(lua_touserdata(L, 1)); - lua_pushstring(L, character->GetHandle().c_str()); - return 1; -} - -static int getAvatar(lua_State* L) { - CharacterData* character = static_cast(lua_touserdata(L, 1)); - lua_pushstring(L, character->GetAvatar().c_str()); - return 1; -} - -static const luaL_Reg characterLib[] = { - {"SetRoom", setRoom}, -// {"GetOwner", getOwner}, //unusable without account API - {"GetHandle", getHandle}, - {"GetAvatar", getAvatar}, - {nullptr, nullptr} -}; - -LUAMOD_API int openCharacterAPI(lua_State* L) { - //get the parent table - luaL_requiref(L, TORTUGA_ENTITY_API, openEntityAPI, false); - - //the local table - luaL_newlib(L, characterLib); - - //merge the local table into the parent table - lua_pushnil(L); //first key - while(lua_next(L, -2)) { - //copy the key-value pair - lua_pushvalue(L, -2); - lua_pushvalue(L, -2); - - //push the copy to the parent table - lua_settable(L, -6); - - //pop the original value before continuing - lua_pop(L, 1); - } - - //remove the local table, leaving the expanded parent table - lua_pop(L, 1); - - return 1; -} \ No newline at end of file diff --git a/server/characters/character_api.hpp b/server/characters/character_api.hpp deleted file mode 100644 index c8534e7..0000000 --- a/server/characters/character_api.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "lua.hpp" - -#define TORTUGA_CHARACTER_API "character" -LUAMOD_API int openCharacterAPI(lua_State* L); diff --git a/server/characters/character_data.cpp b/server/characters/character_data.cpp deleted file mode 100644 index 3d9d728..0000000 --- a/server/characters/character_data.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "character_data.hpp" - -CharacterData::CharacterData(): Entity("character") { - //EMPTY -} - -int CharacterData::GetOwner() { - return owner; -} - -std::string CharacterData::GetHandle() { - return handle; -} - -std::string CharacterData::GetAvatar() { - return avatar; -} \ No newline at end of file diff --git a/server/characters/character_data.hpp b/server/characters/character_data.hpp deleted file mode 100644 index ba10705..0000000 --- a/server/characters/character_data.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 - -//components -#include "character_defines.hpp" -#include "entity.hpp" - -//std namespace -#include -#include - -class CharacterData: public Entity { -public: - CharacterData(); - ~CharacterData() = default; - - //database stuff - int GetOwner(); - std::string GetHandle(); - std::string GetAvatar(); - -private: - friend class CharacterManager; - - int owner = -1; - std::string handle; - std::string avatar; -}; diff --git a/server/characters/character_manager.cpp b/server/characters/character_manager.cpp deleted file mode 100644 index 0108b43..0000000 --- a/server/characters/character_manager.cpp +++ /dev/null @@ -1,348 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "character_manager.hpp" - -#include "sqlite3.h" - -#include "character_defines.hpp" - -#include -#include -#include - -//------------------------- -//Define the queries -//------------------------- - -//NOTE: Programmer set variables are NOT zero-indexed -//NOTE: SQLite3 returned variables (i.e. loading) ARE zero-indexed - -static const char* CREATE_CHARACTER = "INSERT INTO LiveCharacters (" - "owner, " - "handle, " - "avatar, " - "boundsX, " - "boundsY, " - "boundsW, " - "boundsH" - ") VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7);"; - -static const char* LOAD_CHARACTER = "SELECT " - "uid, " - "owner, " - "handle, " - "avatar, " - "roomIndex, " - "originX, " - "originY, " - "boundsX, " - "boundsY, " - "boundsW, " - "boundsH " - "FROM LiveCharacters WHERE handle = ?;"; - -static const char* SAVE_CHARACTER = "UPDATE OR FAIL LiveCharacters SET " - "roomIndex = ?2, " - "originX = ?3, " - "originY = ?4, " - "boundsX = ?5, " - "boundsY = ?6, " - "boundsW = ?7, " - "boundsH = ?8 " - "WHERE uid = ?1;"; - -static const char* DELETE_CHARACTER = "DELETE FROM LiveCharacters WHERE uid = ?;"; - -static const char* COUNT_CHARACTER_RECORDS = "SELECT COUNT(*) FROM LiveCharacters;"; - -//------------------------- -//Define the methods -//------------------------- - -//NOTE: default baseStats as a parameter would be good for different beggining states or multiple classes -int CharacterManager::Create(int owner, std::string handle, std::string avatar) { - //Create the character, failing if it exists - sqlite3_stmt* statement = nullptr; - - //prep - if (sqlite3_prepare_v2(database, CREATE_CHARACTER, -1, &statement, nullptr) != SQLITE_OK) { - throw( std::runtime_error(std::string() + "Failed to prepare an SQL statement: " + sqlite3_errmsg(database)) ); - } - - //parameters - bool ret = false; - ret |= sqlite3_bind_int(statement, 1, owner); - ret |= sqlite3_bind_text(statement, 2, handle.c_str(), handle.size() + 1, SQLITE_STATIC); - ret |= sqlite3_bind_text(statement, 3, avatar.c_str(), avatar.size() + 1, SQLITE_STATIC); - ret |= sqlite3_bind_int(statement, 4, CHARACTER_BOUNDS_X); - ret |= sqlite3_bind_int(statement, 5, CHARACTER_BOUNDS_Y); - ret |= sqlite3_bind_int(statement, 6, CHARACTER_BOUNDS_WIDTH); - ret |= sqlite3_bind_int(statement, 7, CHARACTER_BOUNDS_HEIGHT); - - //check for binding errors - if (ret) { - throw( std::runtime_error(std::string() + "Failed to replace a prepared statement's parameter: " + sqlite3_errmsg(database)) ); - } - - //execute - if (sqlite3_step(statement) != SQLITE_DONE) { - //if this fails, than this character exists - sqlite3_finalize(statement); - return -1; - } - - sqlite3_finalize(statement); - - //load this character into memory - return Load(owner, handle, avatar); -} - -int CharacterManager::Load(int owner, std::string handle, std::string avatar) { - //load the specified character, creating it if it doesn't exist - //fail if it is already loaded, or does not belong to this account - sqlite3_stmt* statement = nullptr; - - //prep - if (sqlite3_prepare_v2(database, LOAD_CHARACTER, -1, &statement, nullptr) != SQLITE_OK) { - throw( std::runtime_error(std::string() + "Failed to prepare an SQL statement: " + sqlite3_errmsg(database)) ); - } - - //parameter - if (sqlite3_bind_text(statement, 1, handle.c_str(), handle.size() + 1, SQLITE_STATIC) != SQLITE_OK) { - throw( std::runtime_error(std::string() + "Failed to replace a prepared statement's parameter: " + sqlite3_errmsg(database)) ); - } - - //execute - int ret = sqlite3_step(statement); - - //process the result - if (ret == SQLITE_ROW) { - //get the index - int uid = sqlite3_column_int(statement, 0); - - //check to see if this character is already loaded - if (elementMap.find(uid) != elementMap.end()) { - sqlite3_finalize(statement); - return -1; - } - - //check the owner - if (owner != sqlite3_column_int(statement, 1)) { - sqlite3_finalize(statement); - //unload the already loaded character - Unload(uid); - return -2; - } - - //extract the data into memory - CharacterData& newChar = elementMap[uid]; - - //metadata - newChar.owner = owner; - newChar.handle = reinterpret_cast(sqlite3_column_text(statement, 2)); - newChar.avatar = reinterpret_cast(sqlite3_column_text(statement, 3)); - //Don't cache the birth - - //world origin - newChar.roomIndex = sqlite3_column_int(statement, 4); - newChar.origin.x = (double)sqlite3_column_int(statement, 5); - newChar.origin.y = (double)sqlite3_column_int(statement, 6); - //bounds - newChar.bounds.x = (int)sqlite3_column_int(statement, 7); - newChar.bounds.y = (int)sqlite3_column_int(statement, 8); - newChar.bounds.w = (int)sqlite3_column_int(statement, 9); - newChar.bounds.h = (int)sqlite3_column_int(statement, 10); - - //gameplay components: equipment, items, buffs, debuffs... - - //finish the routine - sqlite3_finalize(statement); - return uid; - } - - sqlite3_finalize(statement); - - if (ret == SQLITE_DONE) { - //create the non-existant character instead - return Create(owner, handle, avatar); - } - - throw(std::runtime_error(std::string() + "Unknown SQL error in LoadCharacter: " + sqlite3_errmsg(database) )); -} - -int CharacterManager::Save(int uid) { - //save this character from memory, replacing it if it exists in the database - //DOCS: To use this method, change the in-memory copy, and then call this function using that object's UID. - - //this method fails if this character is not loaded - if (elementMap.find(uid) == elementMap.end()) { - return -1; - } - - CharacterData& character = elementMap[uid]; - sqlite3_stmt* statement = nullptr; - - //prep - if (sqlite3_prepare_v2(database, SAVE_CHARACTER, -1, &statement, nullptr) != SQLITE_OK) { - throw( std::runtime_error(std::string() + "Failed to prepare an SQL statement: " + sqlite3_errmsg(database)) ); - } - - //parameters - bool ret = false; - ret |= sqlite3_bind_int(statement, 1, uid) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 2, character.roomIndex) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 3, (int)character.origin.x) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 4, (int)character.origin.y) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 5, character.bounds.x) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 6, character.bounds.y) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 7, character.bounds.w) != SQLITE_OK; - ret |= sqlite3_bind_int(statement, 8, character.bounds.h) != SQLITE_OK; - - //gameplay components: equipment, items, buffs, debuffs... - - //check for binding errors - if (ret) { - throw( std::runtime_error(std::string() + "Failed to replace a prepared statement's parameter: " + sqlite3_errmsg(database)) ); - } - - //execute - if (sqlite3_step(statement) != SQLITE_DONE) { - //if this fails, than something went horribly wrong - sqlite3_finalize(statement); - throw( std::runtime_error(std::string() + "Unknown SQL error when saving a character: " + sqlite3_errmsg(database)) ); - } - - sqlite3_finalize(statement); - - //successful execution - return 0; -} - -void CharacterManager::Unload(int uid) { - //save this character, then unload it - Save(uid); - elementMap.erase(uid); -} - -void CharacterManager::Delete(int uid) { - //TODO: when deleting a character, move it to an archive table - //delete this character from the database, then remove it from memory - sqlite3_stmt* statement = nullptr; - - //prep - if (sqlite3_prepare_v2(database, DELETE_CHARACTER, -1, &statement, nullptr) != SQLITE_OK) { - throw( std::runtime_error(std::string() + "Failed to prepare an SQL statement: " + sqlite3_errmsg(database)) ); - } - - //parameter - if (sqlite3_bind_int(statement, 1, uid) != SQLITE_OK) { - throw( std::runtime_error(std::string() + "Failed to replace a prepared statement's parameter: " + sqlite3_errmsg(database)) ); - } - - //execute - if (sqlite3_step(statement) != SQLITE_DONE) { - //if this fails, than something went horribly wrong - sqlite3_finalize(statement); - throw( std::runtime_error(std::string() + "Unknown SQL error when deleting a character: " + sqlite3_errmsg(database)) ); - } - - //finish the routine - sqlite3_finalize(statement); - elementMap.erase(uid); -} - -void CharacterManager::UnloadAll() { - for (auto& it : elementMap) { - Save(it.first); - } - elementMap.clear(); -} - -void CharacterManager::UnloadIf(std::function)> fn) { - std::map::iterator it = elementMap.begin(); - while (it != elementMap.end()) { - if (fn(*it)) { - Save(it->first); - it = elementMap.erase(it); - } - else { - ++it; - } - } -} - -//------------------------- -//Define the accessors and mutators -//------------------------- - -CharacterData* CharacterManager::Get(int uid) { - std::map::iterator it = elementMap.find(uid); - - if (it == elementMap.end()) { - return nullptr; - } - - return &it->second; -} - -CharacterData* CharacterManager::Get(std::string handle) { - for (std::map::iterator it = elementMap.begin(); it != elementMap.end(); ++it) { - if (it->second.GetHandle() == handle) { - return &it->second; - } - } - return nullptr; -} - -int CharacterManager::GetLoadedCount() { - return elementMap.size(); -} - -int CharacterManager::GetTotalCount() { - //a lot just to count something. - sqlite3_stmt* statement = nullptr; - - //prep - if (sqlite3_prepare_v2(database, COUNT_CHARACTER_RECORDS, -1, &statement, nullptr) != SQLITE_OK) { - throw( std::runtime_error(std::string() + "Failed to prepare an SQL statement: " + sqlite3_errmsg(database)) ); - } - - //execute & retrieve the result - sqlite3_step(statement); - int ret = sqlite3_column_int(statement, 0); - - //finish the routine - sqlite3_finalize(statement); - return ret; -} - -std::map* CharacterManager::GetContainer() { - return &elementMap; -} - -sqlite3* CharacterManager::SetDatabase(sqlite3* db) { - return database = db; -} - -sqlite3* CharacterManager::GetDatabase() { - return database; -} diff --git a/server/characters/character_manager.hpp b/server/characters/character_manager.hpp deleted file mode 100644 index 2d1f3e4..0000000 --- a/server/characters/character_manager.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "character_data.hpp" -#include "singleton.hpp" - -#include "sqlite3.h" - -#include -#include - -class CharacterManager: public Singleton { -public: - //common public methods - int Create(int owner, std::string handle, std::string avatar); - int Load(int owner, std::string handle, std::string avatar); - int Save(int uid); - void Unload(int uid); - void Delete(int uid); - - void UnloadAll(); - void UnloadIf(std::function)> fn); - - //accessors and mutators - CharacterData* Get(int uid); - CharacterData* Get(std::string handle); - int GetLoadedCount(); - int GetTotalCount(); - std::map* GetContainer(); - - //API interface - sqlite3* SetDatabase(sqlite3* db); - sqlite3* GetDatabase(); - - //hooks - //TODO: character hooks - -private: - friend Singleton; - - CharacterManager() = default; - ~CharacterManager() = default; - - //members - std::map elementMap; - sqlite3* database = nullptr; -}; diff --git a/server/characters/character_manager_api.cpp b/server/characters/character_manager_api.cpp deleted file mode 100644 index a853f39..0000000 --- a/server/characters/character_manager_api.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "character_manager_api.hpp" - -#include "character_manager.hpp" - -#include -#include - -//TODO: (1) character hooks? - -static int setOnCreate(lua_State* L) { - //TODO: (9) setOnCreate() -} - -static int setOnLoad(lua_State* L) { - //TODO: (9) setOnLoad() -} - -static int setOnSave(lua_State* L) { - //TODO: (9) setOnSave() -} - -static int setOnUnload(lua_State* L) { - //TODO: (9) setOnUnload() -} - -static int setOnDelete(lua_State* L) { - //TODO: (9) setOnDelete() -} - -static int getCharacter(lua_State* L) { - //integer vs name - CharacterManager& characterMgr = CharacterManager::GetSingleton(); - CharacterData* characterData = nullptr; - - switch(lua_type(L, 1)) { - case LUA_TNUMBER: - characterData = characterMgr.Get(lua_tointeger(L, 1)); - break; - case LUA_TSTRING: - //access characters via their handles - characterData = characterMgr.Get(lua_tostring(L, 1)); - break; - } - - if (characterData) { - lua_pushlightuserdata(L, static_cast(characterData)); - } - else { - lua_pushnil(L); - } - - return 1; -} - -static int getLoadedCount(lua_State* L) { - CharacterManager& characterMgr = CharacterManager::GetSingleton(); - lua_pushinteger(L, characterMgr.GetLoadedCount()); - return 1; -} - -static int forEach(lua_State* L) { - CharacterManager& characterMgr = CharacterManager::GetSingleton(); - //pass each character to the given function - for (auto& it : *characterMgr.GetContainer()) { - lua_pushvalue(L, -1); - lua_pushlightuserdata(L, static_cast(&it.second)); - //call each iteration, throwing an exception if something happened - if (lua_pcall(L, 1, 0, 0) != LUA_OK) { - std::ostringstream os; - os << "Lua error: "; - os << lua_tostring(L, -1); - throw(std::runtime_error(os.str())); - } - } - return 0; -} - -static const luaL_Reg characterManagerLib[] = { -// {"SetOnCreate", setOnCreate}, -// {"SetOnLoad", setOnLoad}, -// {"SetOnSave", setOnSave}, -// {"SetOnUnload", setOnUnload}, -// {"SetOnDelete", setOnDelete}, - {"GetCharacter", getCharacter}, - {"GetLoadedCount", getLoadedCount}, - {"ForEach", forEach}, - {nullptr, nullptr} -}; - -LUAMOD_API int openCharacterManagerAPI(lua_State* L) { - luaL_newlib(L, characterManagerLib); - return 1; -} \ No newline at end of file diff --git a/server/characters/character_manager_api.hpp b/server/characters/character_manager_api.hpp deleted file mode 100644 index 166251e..0000000 --- a/server/characters/character_manager_api.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "lua.hpp" - -#define TORTUGA_CHARACTER_MANAGER_API "character_manager" -LUAMOD_API int openCharacterManagerAPI(lua_State* L); diff --git a/server/characters/makefile b/server/characters/makefile deleted file mode 100644 index ecf6192..0000000 --- a/server/characters/makefile +++ /dev/null @@ -1,32 +0,0 @@ -#config -INCLUDES+=. ../entities ../monsters ../rooms ../server_utilities ../triggers ../../common/gameplay ../../common/map ../../common/network ../../common/network/packet_types ../../common/utilities -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)/,server.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 $@ $< diff --git a/server/clients/client_data.cpp b/server/clients/client_data.cpp deleted file mode 100644 index 1a549a4..0000000 --- a/server/clients/client_data.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "client_data.hpp" - -ClientData::ClientData(IPaddress add) { - address = add; -} - -IPaddress ClientData::SetAddress(IPaddress add) { - return address = add; -} - -IPaddress ClientData::GetAddress() { - return address; -} - -ClientData::Clock::time_point ClientData::GetLastBeat() { - return lastBeat; -} - -int ClientData::GetAttempts() { - return attemptedBeats; -} - -int ClientData::IncrementAttempts() { - lastBeat = Clock::now(); - return attemptedBeats++; -} - -int ClientData::ResetAttempts() { - lastBeat = Clock::now(); - return attemptedBeats = 0; -} \ No newline at end of file diff --git a/server/clients/client_data.hpp b/server/clients/client_data.hpp deleted file mode 100644 index bcf7cc8..0000000 --- a/server/clients/client_data.hpp +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "SDL_net.h" - -#include - -class ClientData { -public: - typedef std::chrono::steady_clock Clock; - - ClientData() = default; - ClientData(IPaddress add); - ~ClientData() = default; - - IPaddress SetAddress(IPaddress add); - IPaddress GetAddress(); - - Clock::time_point GetLastBeat(); - - int GetAttempts(); - int IncrementAttempts(); - int ResetAttempts(); - -private: - IPaddress address = {0,0}; - - Clock::time_point lastBeat = Clock::now(); - int attemptedBeats = 0; -}; diff --git a/server/clients/client_manager.cpp b/server/clients/client_manager.cpp deleted file mode 100644 index 80d6942..0000000 --- a/server/clients/client_manager.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "client_manager.hpp" - -#include "ip_operators.hpp" -#include "udp_network_utility.hpp" - -#include - -std::list ClientManager::CheckConnections() { - //list of clients to disconnect - std::list returnList; - - for (auto& it : elementMap) { - //3 seconds between beats - if (ClientData::Clock::now() - it.second.GetLastBeat() > std::chrono::seconds(3)) { - ServerPacket newPacket; - newPacket.type = SerialPacketType::PING; - UDPNetworkUtility::GetSingleton().SendTo(it.second.GetAddress(), &newPacket); - it.second.IncrementAttempts(); - } - } - - for (auto& it : elementMap) { - if (it.second.GetAttempts() > 2) { - returnList.push_back(it.first); - } - } - - return returnList; -} - -void ClientManager::HandlePong(ServerPacket* const argPacket) { - //find and update the specified client - for (auto& it : elementMap) { - if (it.second.GetAddress() == argPacket->srcAddress) { - it.second.ResetAttempts(); - return; - } - } -} - -int ClientManager::Create(IPaddress add) { - ClientData& client = elementMap[counter]; - client.SetAddress(add); - return counter++; -} - -void ClientManager::Unload(int uid) { - elementMap.erase(uid); -} - -void ClientManager::UnloadAll() { - elementMap.clear(); -} - -void ClientManager::UnloadIf(std::function)> fn) { - std::map::iterator it = elementMap.begin(); - while (it != elementMap.end()) { - if (fn(*it)) { - it = elementMap.erase(it); - } - else { - ++it; - } - } -} - -ClientData* ClientManager::Get(int uid) { - std::map::iterator it = elementMap.find(uid); - - if (it == elementMap.end()) { - return nullptr; - } - - return &it->second; -} - -int ClientManager::GetLoadedCount() { - return elementMap.size(); -} - -int ClientManager::GetTotalCount() { - return elementMap.size(); -} - -std::map* ClientManager::GetContainer() { - return &elementMap; -} \ No newline at end of file diff --git a/server/clients/client_manager.hpp b/server/clients/client_manager.hpp deleted file mode 100644 index 7a7b930..0000000 --- a/server/clients/client_manager.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "client_data.hpp" -#include "server_packet.hpp" -#include "singleton.hpp" - -#include "SDL_net.h" - -#include -#include -#include - -class ClientManager: public Singleton { -public: - //methods - std::list CheckConnections(); - void HandlePong(ServerPacket* const argPacket); - - //common public methods - int Create(IPaddress); - void Unload(int uid); - - void UnloadAll(); - void UnloadIf(std::function)> fn); - - //accessors & mutators - ClientData* Get(int uid); - int GetLoadedCount(); - int GetTotalCount(); - std::map* GetContainer(); - -private: - friend Singleton; - - ClientManager() = default; - ~ClientManager() = default; - - //members - std::map elementMap; - int counter = 0; -}; diff --git a/server/clients/makefile b/server/clients/makefile deleted file mode 100644 index 1384da7..0000000 --- a/server/clients/makefile +++ /dev/null @@ -1,32 +0,0 @@ -#config -INCLUDES+=. ../server_utilities ../../common/network ../../common/network/packet_types ../../common/utilities -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)/,server.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 $@ $< diff --git a/server/entities/entity.cpp b/server/entities/entity.cpp deleted file mode 100644 index dd3249d..0000000 --- a/server/entities/entity.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "entity.hpp" - -Entity::Entity(const char* _type): type(_type) { - //EMPTY -} - -void Entity::Update() { - origin += motion; -} - -int Entity::SetRoomIndex(int i) { - return roomIndex = i; -} - -Vector2 Entity::SetOrigin(Vector2 v) { - return origin = v; -} - -Vector2 Entity::SetMotion(Vector2 v) { - return motion = v; -} - -BoundingBox Entity::SetBounds(BoundingBox b) { - return bounds = b; -} - -int Entity::GetRoomIndex() const { - return roomIndex; -} - -Vector2 Entity::GetOrigin() const { - return origin; -} - -Vector2 Entity::GetMotion() const { - return motion; -} - -BoundingBox Entity::GetBounds() const { - return bounds; -} - -const char* Entity::GetType() const { - return type; -} \ No newline at end of file diff --git a/server/entities/entity.hpp b/server/entities/entity.hpp deleted file mode 100644 index 8ed7889..0000000 --- a/server/entities/entity.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "bounding_box.hpp" -#include "vector2.hpp" - -#include - -//The base class for all objects in the world -class Entity { -public: - virtual void Update(); - - //accessors & mutators - int SetRoomIndex(int i); - Vector2 SetOrigin(Vector2 v); - Vector2 SetMotion(Vector2 v); - BoundingBox SetBounds(BoundingBox b); - - int GetRoomIndex() const; - Vector2 GetOrigin() const; - Vector2 GetMotion() const; - BoundingBox GetBounds() const; - - const char* GetType() const; - -protected: - Entity(const char* type); - virtual ~Entity() = default; - - int roomIndex = -1; - Vector2 origin = {0, 0}; - Vector2 motion = {0, 0}; - BoundingBox bounds = {0, 0, 0, 0}; - const char* type; -}; diff --git a/server/entities/entity_api.cpp b/server/entities/entity_api.cpp deleted file mode 100644 index 13bda83..0000000 --- a/server/entities/entity_api.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "entity_api.hpp" - -#include "entity.hpp" - -static int setRoomIndex(lua_State* L) { - Entity* entity = static_cast(lua_touserdata(L, 1)); - entity->SetRoomIndex(lua_tointeger(L, 2)); - return 0; -} - -static int setOrigin(lua_State* L) { - Entity* entity = static_cast(lua_touserdata(L, 1)); - entity->SetOrigin({lua_tonumber(L, 2), lua_tonumber(L, 3)}); - return 0; -} - -static int setMotion(lua_State* L) { - Entity* entity = static_cast(lua_touserdata(L, 1)); - entity->SetMotion({lua_tonumber(L, 2), lua_tonumber(L, 3)}); - return 0; -} - -static int setBounds(lua_State* L) { - Entity* entity = static_cast(lua_touserdata(L, 1)); - entity->SetBounds({ - lua_tointeger(L, 2), - lua_tointeger(L, 3), - lua_tointeger(L, 4), - lua_tointeger(L, 5) - }); - return 0; -} - -static int getRoomIndex(lua_State* L) { - Entity* entity = static_cast(lua_touserdata(L, 1)); - lua_pushinteger(L, entity->GetRoomIndex()); - return 1; -} - -static int getOrigin(lua_State* L) { - Entity* entity = static_cast(lua_touserdata(L, 1)); - lua_pushnumber(L, entity->GetOrigin().x); - lua_pushnumber(L, entity->GetOrigin().y); - return 2; -} - -static int getMotion(lua_State* L) { - Entity* entity = static_cast(lua_touserdata(L, 1)); - lua_pushnumber(L, entity->GetMotion().x); - lua_pushnumber(L, entity->GetMotion().y); - return 2; -} - -static int getBounds(lua_State* L) { - Entity* entity = static_cast(lua_touserdata(L, 1)); - lua_pushinteger(L, entity->GetBounds().x); - lua_pushinteger(L, entity->GetBounds().y); - lua_pushinteger(L, entity->GetBounds().w); - lua_pushinteger(L, entity->GetBounds().h); - return 4; -} - -static int getType(lua_State* L) { - Entity* entity = static_cast(lua_touserdata(L, 1)); - lua_pushstring(L, entity->GetType()); - return 1; -} - -static const luaL_Reg entityLib[] = { - {"SetRoomIndex", setRoomIndex}, - {"SetOrigin", setOrigin}, - {"SetMotion", setMotion}, - {"SetBounds", setBounds}, - {"GetRoomIndex", getRoomIndex}, - {"GetOrigin", getOrigin}, - {"GetMotion", getMotion}, - {"GetBounds", getBounds}, - {"GetType", getType}, - {nullptr, nullptr} -}; - -LUAMOD_API int openEntityAPI(lua_State* L) { - luaL_newlib(L, entityLib); - return 1; -} \ No newline at end of file diff --git a/server/entities/entity_api.hpp b/server/entities/entity_api.hpp deleted file mode 100644 index cfd5dec..0000000 --- a/server/entities/entity_api.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "lua.hpp" - -#define TORTUGA_ENTITY_API "entity" -LUAMOD_API int openEntityAPI(lua_State* L); diff --git a/server/entities/makefile b/server/entities/makefile deleted file mode 100644 index 1b92ad0..0000000 --- a/server/entities/makefile +++ /dev/null @@ -1,32 +0,0 @@ -#config -INCLUDES+=. ../../common/utilities -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)/,server.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 $@ $< diff --git a/server/linit.cpp b/server/linit.cpp deleted file mode 100644 index f1c05bb..0000000 --- a/server/linit.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* $Id: linit.c,v 1.32, modified - * Initialization of libraries for lua.c and other clients - * See Copyright Notice in lua.h - * - * If you embed Lua in your program and need to open the standard - * libraries, call luaL_openlibs in your program. If you need a - * different set of libraries, copy this file to your project and edit - * it to suit your needs. - * - * Modified for use in Tortuga, renamed to linit.cpp - * Modifications are released under the zlib license: - * - * Copyright: (c) Kayne Ruse 2013-2015 - * - * 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. -*/ -#define linit_c -#define LUA_LIB - -#include "lua.hpp" - -#include "entity_api.hpp" -#include "character_api.hpp" -#include "character_manager_api.hpp" -#include "region_api.hpp" -#include "region_pager_api.hpp" -//#include "monster_api.hpp" -//#include "monster_manager_api.hpp" -#include "network_api.hpp" -#include "room_api.hpp" -#include "room_manager_api.hpp" -#include "trigger_api.hpp" -#include "trigger_manager_api.hpp" - -//these libs are loaded by lua.c and are readily available to any Lua program -static const luaL_Reg loadedlibs[] = { - //Standard libs - {"_G", luaopen_base}, - {LUA_LOADLIBNAME, luaopen_package}, - {LUA_COLIBNAME, luaopen_coroutine}, - {LUA_TABLIBNAME, luaopen_table}, - {LUA_IOLIBNAME, luaopen_io}, - {LUA_OSLIBNAME, luaopen_os}, - {LUA_STRLIBNAME, luaopen_string}, - {LUA_BITLIBNAME, luaopen_bit32}, - {LUA_MATHLIBNAME, luaopen_math}, - {LUA_DBLIBNAME, luaopen_debug}, - {NULL, NULL} -}; - -//these libs are preloaded and must be required before used -static const luaL_Reg preloadedlibs[] = { - {TORTUGA_ENTITY_API, openEntityAPI}, //required by derived classes - {TORTUGA_CHARACTER_API, openCharacterAPI}, - {TORTUGA_CHARACTER_MANAGER_API, openCharacterManagerAPI}, -// {TORTUGA_MONSTER_API, openMonsterAPI}, -// {TORTUGA_MONSTER_MANAGER_API, openMonsterManagerAPI}, - {TORTUGA_NETWORK_API, openNetworkAPI}, - {TORTUGA_REGION_API, openRegionAPI}, - {TORTUGA_REGION_PAGER_API, openRegionPagerAPI}, - {TORTUGA_ROOM_API, openRoomAPI}, - {TORTUGA_ROOM_MANAGER_API, openRoomManagerAPI}, - {TORTUGA_TRIGGER_API, openTriggerAPI}, - {TORTUGA_TRIGGER_MANAGER_API, openTriggerManagerAPI}, - {NULL, NULL} -}; - -LUALIB_API void luaL_openlibs (lua_State *L) { - const luaL_Reg *lib; - //call open functions from 'loadedlibs' and set results to global table - for (lib = loadedlibs; lib->func; lib++) { - luaL_requiref(L, lib->name, lib->func, 1); - lua_pop(L, 1); //remove lib - } - //add open functions from 'preloadedlibs' into 'package.preload' table - luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); - for (lib = preloadedlibs; lib->func; lib++) { - lua_pushcfunction(L, lib->func); - lua_setfield(L, -2, lib->name); - } - lua_pop(L, 1); //remove _PRELOAD table -} diff --git a/server/main.cpp b/server/main.cpp deleted file mode 100644 index a69dfb0..0000000 --- a/server/main.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "server_application.hpp" - -//singletons -#include "account_manager.hpp" -#include "character_manager.hpp" -#include "client_manager.hpp" -#include "config_utility.hpp" -#include "room_manager.hpp" -#include "udp_network_utility.hpp" - -#include -#include - -using namespace std; - -int main(int argc, char* argv[]) { - try { - //create the singletons - AccountManager::CreateSingleton(); - CharacterManager::CreateSingleton(); - ClientManager::CreateSingleton(); - ConfigUtility::CreateSingleton(); - RoomManager::CreateSingleton(); - UDPNetworkUtility::CreateSingleton(); - - //call the server's routines - ServerApplication::CreateSingleton(); - ServerApplication& app = ServerApplication::GetSingleton(); - - app.Init(argc, argv); - app.Proc(); - app.Quit(); - - ServerApplication::DeleteSingleton(); - - //delete the singletons - AccountManager::DeleteSingleton(); - CharacterManager::DeleteSingleton(); - ClientManager::DeleteSingleton(); - ConfigUtility::DeleteSingleton(); - RoomManager::DeleteSingleton(); - UDPNetworkUtility::DeleteSingleton(); - } - catch(exception& e) { - cerr << "Fatal exception thrown: " << e.what() << endl; - return 1; - } - return 0; -} \ No newline at end of file diff --git a/server/makefile b/server/makefile deleted file mode 100644 index fd5b942..0000000 --- a/server/makefile +++ /dev/null @@ -1,64 +0,0 @@ -#include directories -INCLUDES+=SDL . accounts characters clients entities rooms server_utilities triggers ../common/debugging ../common/gameplay ../common/map ../common/network ../common/network/packet_types ../common/utilities - -#libraries -#the order of the $(LIBS) is important, at least for MinGW -LIBS+=server.a ../libcommon.a -lSDL_net -ifeq ($(OS),Windows_NT) - LIBS+=-lwsock32 -liphlpapi -lmingw32 -endif -LIBS+=-lSDLmain -lSDL -llua -lsqlite3 -ifeq ($(shell uname), Linux) - #I don't know what this does, but Ubuntu needs it (dynamic linking for lua) - LIBS+=-ldl -endif - -#flags -CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) - -#source -CXXSRC=$(wildcard *.cpp) - -#objects -OBJDIR=obj -OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) - -#output -OUTDIR=../out -OUT=$(addprefix $(OUTDIR)/,server) - -#targets -all: $(OBJ) $(OUT) - $(MAKE) -C accounts - $(MAKE) -C characters - $(MAKE) -C clients - $(MAKE) -C entities -# $(MAKE) -C monsters - $(MAKE) -C rooms - $(MAKE) -C server_utilities - $(MAKE) -C triggers - $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) - -$(OBJ): | $(OBJDIR) - -$(OUT): | $(OUTDIR) - -$(OBJDIR): - mkdir $(OBJDIR) - -$(OUTDIR): - mkdir $(OUTDIR) - -$(OBJDIR)/%.o: %.cpp - $(CXX) $(CXXFLAGS) -c -o $@ $< - -clean: -ifeq ($(OS),Windows_NT) - $(RM) *.o *.a *.exe -else ifeq ($(shell uname), Linux) - find . -type f -name *.o -exec rm -f -r -v {} \; - find . -type f -name *.a -exec rm -f -r -v {} \; - rm -f -v out/client out/server -endif - -rebuild: clean all diff --git a/server/monsters/makefile b/server/monsters/makefile deleted file mode 100644 index efc3852..0000000 --- a/server/monsters/makefile +++ /dev/null @@ -1,32 +0,0 @@ -#config -INCLUDES+=. ../entities ../server_utilities ../../common/gameplay ../../common/utilities -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)/,server.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 $@ $< diff --git a/server/monsters/monster_api.cpp b/server/monsters/monster_api.cpp deleted file mode 100644 index c5c4d93..0000000 --- a/server/monsters/monster_api.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "monster_api.hpp" - -#include "monster_data.hpp" - -#include "entity_api.hpp" - -static int setAvatar(lua_State* L) { - MonsterData* monster = static_cast(lua_touserdata(L, 1)); - monster->SetAvatar(lua_tostring(L, 2)); - //TODO: (1) send an update to the clients? - return 0; -} - -static int getAvatar(lua_State* L) { - MonsterData* monster = static_cast(lua_touserdata(L, 1)); - lua_pushstring(L, monster->GetAvatar().c_str()); - return 1; -} - -static int setScript(lua_State* L) { - MonsterData* monster = static_cast(lua_touserdata(L, 1)); - luaL_unref(L, LUA_REGISTRYINDEX, monster->GetScriptReference()); - monster->SetScriptReference(luaL_ref(L, LUA_REGISTRYINDEX)); - return 0; -} - -static int getScript(lua_State* L) { - MonsterData* monster = static_cast(lua_touserdata(L, 1)); - lua_pushinteger(L, monster->GetScriptReference()); - lua_gettable(L, LUA_REGISTRYINDEX); - return 1; -} - -static const luaL_Reg monsterLib[] = { - {"SetAvatar", setAvatar}, - {"GetAvatar", getAvatar}, - {"SetScript", setScript}, - {"GetScript", getScript}, - {nullptr, nullptr} -}; - -LUAMOD_API int openMonsterAPI(lua_State* L) { - //get the parent table - luaL_requiref(L, TORTUGA_ENTITY_API, openEntityAPI, false); - - //the local table - luaL_newlib(L, monsterLib); - - //merge the local table into the parent table - lua_pushnil(L); //first key - while(lua_next(L, -2)) { - //copy the key-value pair - lua_pushvalue(L, -2); - lua_pushvalue(L, -2); - - //push the copy to the parent table - lua_settable(L, -6); - - //pop the original value before continuing - lua_pop(L, 1); - } - - //remove the local table, leaving the expanded parent table - lua_pop(L, 1); - - return 1; -} \ No newline at end of file diff --git a/server/monsters/monster_api.hpp b/server/monsters/monster_api.hpp deleted file mode 100644 index 73d535d..0000000 --- a/server/monsters/monster_api.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "lua.hpp" - -#define TORTUGA_MONSTER_API "monster" -LUAMOD_API int openMonsterAPI(lua_State* L); diff --git a/server/monsters/monster_data.cpp b/server/monsters/monster_data.cpp deleted file mode 100644 index d2d6abf..0000000 --- a/server/monsters/monster_data.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "monster_data.hpp" - -MonsterData::MonsterData(std::string _avatar, int _scriptRef): - Entity("monster"), - avatar(_avatar), - scriptRef(_scriptRef) -{ - //EMPTY -} - -void MonsterData::Update() { - Entity::Update(); - //TODO: (0) call the script reference -} - -//------------------------- -//accessors & mutators -//------------------------- - -std::string MonsterData::SetAvatar(std::string s) { - return avatar = s; -} - -std::string MonsterData::GetAvatar() { - return avatar; -} - -int MonsterData::SetScriptReference(int i) { - return scriptRef = i; -} - -int MonsterData::GetScriptReference() { - return scriptRef; -} \ No newline at end of file diff --git a/server/monsters/monster_data.hpp b/server/monsters/monster_data.hpp deleted file mode 100644 index aac2d03..0000000 --- a/server/monsters/monster_data.hpp +++ /dev/null @@ -1,57 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "entity.hpp" - -#include "lua.hpp" - -#include - -/* DOCS: Monster attributes, read more - * species (avatar, script) - * level - * health/mana - * permadeath/respawn -*/ - -class MonsterData: public Entity { -public: - MonsterData(std::string avatar, int scriptRef); - ~MonsterData() = default; - - virtual void Update(); - - //accessors & mutators - - std::string SetAvatar(std::string); - std::string GetAvatar(); - - int SetScriptReference(int); - int GetScriptReference(); - -private: - friend class MonsterManager; - - std::string avatar; - int scriptRef = LUA_NOREF; -}; diff --git a/server/monsters/monster_manager.cpp b/server/monsters/monster_manager.cpp deleted file mode 100644 index 7f9a11a..0000000 --- a/server/monsters/monster_manager.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "monster_manager.hpp" - -MonsterManager::MonsterManager() { - //EMPTY -} - -MonsterManager::~MonsterManager() { - UnloadAll(); -} - -int MonsterManager::Create(std::string avatar, int scriptRef) { - //implicitly create the new - elementMap.emplace(counter, MonsterData(avatar, scriptRef)); - - //TODO: do various things like saving to the database - return counter++; -} - -//TODO: (1) monster load, save - -void MonsterManager::Unload(int uid) { - elementMap.erase(uid); -} - -void MonsterManager::UnloadAll() { - elementMap.clear(); -} - -void MonsterManager::UnloadIf(std::function)> fn) { - std::map::iterator it = elementMap.begin(); - while (it != elementMap.end()) { - if (fn(*it)) { - it = elementMap.erase(it); - } - else { - ++it; - } - } -} - -MonsterData* MonsterManager::Get(int uid) { - std::map::iterator it = elementMap.find(uid); - - if (it == elementMap.end()) { - return nullptr; - } - - return &it->second; -} - -int MonsterManager::GetLoadedCount() { - return elementMap.size(); -} - -std::map* MonsterManager::GetContainer() { - return &elementMap; -} - -lua_State* MonsterManager::SetLuaState(lua_State* L) { - return lua = L; -} - -lua_State* MonsterManager::GetLuaState() { - return lua; -} - -sqlite3* MonsterManager::SetDatabase(sqlite3* db) { - return database = db; -} - -sqlite3* MonsterManager::GetDatabase() { - return database; -} diff --git a/server/monsters/monster_manager.hpp b/server/monsters/monster_manager.hpp deleted file mode 100644 index 76b8ffa..0000000 --- a/server/monsters/monster_manager.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "monster_data.hpp" - -#include "lua.hpp" -#include "sqlite3.h" - -#include -#include -#include - -class MonsterManager { -public: - MonsterManager(); - ~MonsterManager(); - - //common public methods - int Create(std::string avatar, int scriptRef); - void Unload(int uid); - - void UnloadAll(); - void UnloadIf(std::function)> fn); - - //accessors & mutators - MonsterData* Get(int uid); - int GetLoadedCount(); - std::map* GetContainer(); - - //hooks - lua_State* SetLuaState(lua_State* L); - lua_State* GetLuaState(); - sqlite3* SetDatabase(sqlite3* db); - sqlite3* GetDatabase(); - -private: - //members - std::map elementMap; - int counter = 0; - lua_State* lua = nullptr; - sqlite3* database = nullptr; -}; diff --git a/server/monsters/monster_manager_api.cpp b/server/monsters/monster_manager_api.cpp deleted file mode 100644 index 08be549..0000000 --- a/server/monsters/monster_manager_api.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "monster_manager_api.hpp" - -#include "monster_manager.hpp" - -static int create(lua_State* L) { - MonsterManager* mgr = static_cast(lua_touserdata(L, 1)); - int index = mgr->Create(lua_tostring(L, 2), lua_tointeger(L, 3)); - MonsterData* monster = mgr->Get(index); - lua_pushlightuserdata(L, static_cast(monster)); - lua_pushinteger(L, index); - return 2; -} - -//TOOD: this needs to take the userdata as a parameter too -static int unload(lua_State* L) { - MonsterManager* mgr = static_cast(lua_touserdata(L, 1)); - mgr->Unload(lua_tointeger(L, 2)); - return 0; -} - -static int unloadAll(lua_State* L) { - MonsterManager* mgr = static_cast(lua_touserdata(L, 1)); - mgr->UnloadAll(); - return 0; -} - -static int unloadIf(lua_State* L) { - MonsterManager* mgr = static_cast(lua_touserdata(L, 1)); - //TODO: unloadIf - return 0; -} - -static int get(lua_State* L) { - MonsterManager* mgr = static_cast(lua_touserdata(L, 1)); - MonsterData* monster = mgr->Get(lua_tointeger(L, 2)); - lua_pushlightuserdata(L, static_cast(monster)); - return 1; -} - -static int getLoadedCount(lua_State* L) { - MonsterManager* mgr = static_cast(lua_touserdata(L, 1)); - lua_pushinteger(L, mgr->GetLoadedCount()); - return 1; -} - -static const luaL_Reg monsterManagerLib[] = { - {"Create", create}, - {"Unload", unload}, - {"UnloadAll", unloadAll}, -// {"UnloadIf", unloadIf}, - {"Get", get}, - {"GetLoadedCount", getLoadedCount}, - {nullptr, nullptr} -}; - -LUAMOD_API int openMonsterManagerAPI(lua_State* L) { - luaL_newlib(L, monsterManagerLib); - return 1; -} \ No newline at end of file diff --git a/server/monsters/monster_manager_api.hpp b/server/monsters/monster_manager_api.hpp deleted file mode 100644 index 218246c..0000000 --- a/server/monsters/monster_manager_api.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "lua.hpp" - -#define TORTUGA_MONSTER_MANAGER_API "monster_manager" -LUAMOD_API int openMonsterManagerAPI(lua_State* L); diff --git a/server/rooms/makefile b/server/rooms/makefile deleted file mode 100644 index 048c575..0000000 --- a/server/rooms/makefile +++ /dev/null @@ -1,32 +0,0 @@ -#config -INCLUDES+=. ../characters ../entities ../monsters ../server_utilities ../triggers ../../common/gameplay ../../common/map ../../common/utilities -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)/,server.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 $@ $< diff --git a/server/rooms/room_api.cpp b/server/rooms/room_api.cpp deleted file mode 100644 index 9aad030..0000000 --- a/server/rooms/room_api.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "room_api.hpp" - -#include "room_data.hpp" - -#include -#include - -static int setRoomName(lua_State* L) { - RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); - room->SetName(lua_tostring(L, 2)); - return 0; -} - -static int getRoomName(lua_State* L) { - RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); - lua_pushstring(L, room->GetName().c_str()); - return 1; -} - -static int setTilesetName(lua_State* L) { - RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); - room->SetTileset(lua_tostring(L, 2)); - return 0; -} - -static int getTilesetName(lua_State* L) { - RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); - lua_pushstring(L, room->GetTileset().c_str()); - return 1; -} - -static int getPager(lua_State* L) { - RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); - lua_pushlightuserdata(L, reinterpret_cast(room->GetPager()) ); - return 1; -} - -/* -static int getMonsterMgr(lua_State* L) { - RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); - lua_pushlightuserdata(L, reinterpret_cast(room->GetMonsterMgr()) ); - return 1; -} -*/ - -static int getTriggerMgr(lua_State* L) { - RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); - lua_pushlightuserdata(L, reinterpret_cast(room->GetTriggerMgr()) ); - return 1; -} - -static int forEachCharacter(lua_State* L) { - RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); - //pass each character to the given function - for (auto& it : *room->GetCharacterList()) { - lua_pushvalue(L, -1); - lua_pushlightuserdata(L, static_cast(it)); - //call each iteration, throwing an exception if something happened - if (lua_pcall(L, 1, 0, 0) != LUA_OK) { - std::ostringstream os; - os << "Lua error: "; - os << lua_tostring(L, -1); - throw(std::runtime_error(os.str())); - } - } - return 0; -} - -/* -static int forEachMonster(lua_State* L) { - RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); - MonsterManager* monsterMgr = room->GetMonsterMgr(); - //pass each monster to the given function - for (auto& it : *monsterMgr->GetContainer()) { - lua_pushvalue(L, -1); - lua_pushlightuserdata(L, static_cast(&it.second)); - //call each iteration, throwing an exception if something happened - if (lua_pcall(L, 1, 0, 0) != LUA_OK) { - std::ostringstream os; - os << "Lua error: "; - os << lua_tostring(L, -1); - throw(std::runtime_error(os.str())); - } - } - return 0; -} -*/ - -static int setOnTick(lua_State* L) { - RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); - luaL_unref(L, LUA_REGISTRYINDEX, room->GetTickReference()); - room->SetTickReference(luaL_ref(L, LUA_REGISTRYINDEX)); - return 0; -} - -static int getOnTick(lua_State* L) { - RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); - lua_rawgeti(L, LUA_REGISTRYINDEX, room->GetTickReference()); - return 1; -} - -static int initialize(lua_State* L) { - RoomData* room = static_cast(lua_touserdata(L, 1)); - - //set the refs of these parameters (backwards, since it pops from the top of the stack) - room->GetPager()->SetUnloadReference(luaL_ref(L, LUA_REGISTRYINDEX)); - room->GetPager()->SetCreateReference(luaL_ref(L, LUA_REGISTRYINDEX)); - room->GetPager()->SetSaveReference(luaL_ref(L, LUA_REGISTRYINDEX)); - room->GetPager()->SetLoadReference(luaL_ref(L, LUA_REGISTRYINDEX)); - - //more parameters can be added here later - return 0; -} - -static const luaL_Reg roomLib[] = { - {"SetName", setRoomName}, - {"GetName", getRoomName}, - {"SetTileset", setTilesetName}, - {"GetTileset", getTilesetName}, - - {"GetPager",getPager}, -// {"GetMonsterMgr",getMonsterMgr}, - {"GetTriggerMgr",getTriggerMgr}, - - {"ForEachCharacter", forEachCharacter}, -// {"ForEachMonster", forEachMonster}, - - {"SetOnTick", setOnTick}, - {"GetOnTick", getOnTick}, - - {"Initialize", initialize}, - {nullptr, nullptr} -}; - -LUAMOD_API int openRoomAPI(lua_State* L) { - luaL_newlib(L, roomLib); - return 1; -} \ No newline at end of file diff --git a/server/rooms/room_api.hpp b/server/rooms/room_api.hpp deleted file mode 100644 index b3af811..0000000 --- a/server/rooms/room_api.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "lua.hpp" - -#define TORTUGA_ROOM_API "room" -LUAMOD_API int openRoomAPI(lua_State* L); diff --git a/server/rooms/room_data.cpp b/server/rooms/room_data.cpp deleted file mode 100644 index cb6e8e0..0000000 --- a/server/rooms/room_data.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "room_data.hpp" - -#include -#include -#include -#include - -//TODO: (9) character collisions should be preformed client-side -void RoomData::RunFrame() { - //get the hook - lua_rawgeti(lua, LUA_REGISTRYINDEX, tickRef); - - if (!lua_isnil(lua, -1)) { - //call the tick function, with this as a parameter - lua_pushlightuserdata(lua, this); - if (lua_pcall(lua, 1, 0, 0) != LUA_OK) { - throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) )); - } - } - else { - lua_pop(lua, 1); - } - - //update the entities in the room - for (auto& it : characterList) { - it->Update(); - } - //TODO: (3) iterate through the monster map - //TODO: (3) trigger script for monsters - - //build a list of game entities - std::stack entityStack; - for (auto& it : characterList) { - entityStack.push(it); - } - //TODO: (3) push the monster entities - - //compare the triggers to the entities, using their real hitboxes - //NOTE: this stack solution should prevent problems when modifying the various lists - while(entityStack.size()) { - //get the entity & hitbox - Entity* entity = entityStack.top(); - BoundingBox entityBox = entity->GetBounds() + entity->GetOrigin(); - - //get the trigger pair & hitbox - for (auto& triggerPair : *triggerMgr.GetContainer()) { - BoundingBox triggerBox = triggerPair.second.GetBoundingBox() + triggerPair.second.GetOrigin(); - - //find all collisions - if (entityBox.CheckOverlap(triggerBox)) { - //skip members of the exclusion list - if (std::any_of(triggerPair.second.GetExclusionList()->begin(), triggerPair.second.GetExclusionList()->end(), [entity](Entity* ptr) -> bool { - return entity == ptr; - })) { - continue; - } - - //run the trigger script - lua_rawgeti(lua, LUA_REGISTRYINDEX, triggerPair.second.GetScriptReference()); - lua_pushlightuserdata(lua, entity); - - if (lua_pcall(lua, 1, 0, 0) != LUA_OK) { - //error - throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) )); - } - - //push to the exclusion list - triggerPair.second.GetExclusionList()->push_back(entity); - } - else { - //remove members of the exclusion list - //NOTE: characters in different rooms won't be removed, but that shouldn't be a problem - triggerPair.second.GetExclusionList()->remove_if([entity](Entity* ptr) -> bool { - return entity == ptr; - }); - } - } - - //next - entityStack.pop(); - } -} - -std::string RoomData::SetName(std::string s) { - return roomName = s; -} - -std::string RoomData::GetName() { - return roomName; -} - -std::string RoomData::SetTileset(std::string s) { - return tilesetName = s; -} - -std::string RoomData::GetTileset() { - return tilesetName; -} - -RegionPagerLua* RoomData::GetPager() { - return &pager; -} - -TriggerManager* RoomData::GetTriggerMgr() { - return &triggerMgr; -} - -std::list* RoomData::GetCharacterList() { - return &characterList; -} - -lua_State* RoomData::SetLuaState(lua_State* L) { - lua = L; - pager.SetLuaState(lua); - triggerMgr.SetLuaState(lua); - return lua; -} - -lua_State* RoomData::GetLuaState() { - return lua; -} - -sqlite3* RoomData::SetDatabase(sqlite3* db) { - database = db; - return database; -} - -sqlite3* RoomData::GetDatabase() { - return database; -} - -int RoomData::SetTickReference(int i) { - return tickRef = i; -} - -int RoomData::GetTickReference() { - return tickRef; -} \ No newline at end of file diff --git a/server/rooms/room_data.hpp b/server/rooms/room_data.hpp deleted file mode 100644 index 7cd11b2..0000000 --- a/server/rooms/room_data.hpp +++ /dev/null @@ -1,79 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "character_data.hpp" -#include "region_pager_lua.hpp" -#include "trigger_manager.hpp" - -#include "lua.hpp" -#include "sqlite3.h" - -#include -#include - -class RoomData { -public: - RoomData() = default; - ~RoomData() = default; - - void RunFrame(); - - //accessors and mutators - std::string SetName(std::string); - std::string GetName(); - - std::string SetTileset(std::string); - std::string GetTileset(); - - RegionPagerLua* GetPager(); - TriggerManager* GetTriggerMgr(); - std::list* GetCharacterList(); - - //API interfaces - lua_State* SetLuaState(lua_State* L); - lua_State* GetLuaState(); - sqlite3* SetDatabase(sqlite3* db); - sqlite3* GetDatabase(); - - //hooks - int SetTickReference(int i); - int GetTickReference(); - //TODO: other triggers like player entry & exit, etc. - -private: - //metadata - std::string roomName; - std::string tilesetName; - - //members - RegionPagerLua pager; - TriggerManager triggerMgr; - std::list characterList; - - //API - lua_State* lua = nullptr; - sqlite3* database = nullptr; - - //hooks - int tickRef = LUA_NOREF; -}; diff --git a/server/rooms/room_manager.cpp b/server/rooms/room_manager.cpp deleted file mode 100644 index c974413..0000000 --- a/server/rooms/room_manager.cpp +++ /dev/null @@ -1,209 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "room_manager.hpp" - -#include "room_api.hpp" - -#include - -//------------------------- -//public access methods -//------------------------- - -int RoomManager::Create(std::string roomName, std::string tileset) { - //create the room - RoomData* newRoom = &elementMap[counter]; //implicitly constructs the element - newRoom->SetName(roomName); - newRoom->SetTileset(tileset); - - newRoom->SetLuaState(lua); - newRoom->SetDatabase(database); - - //get the hook - lua_rawgeti(lua, LUA_REGISTRYINDEX, createRef); - - if(!lua_isnil(lua, -1)) { - lua_pushlightuserdata(lua, newRoom); - lua_pushinteger(lua, counter); - //call the function, 2 arg, 0 return - if (lua_pcall(lua, 2, 0, 0) != LUA_OK) { - throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) )); - } - } - - //finish the routine - return counter++; -} - -void RoomManager::UnloadAll() { - //get the hook - lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef); - - if(!lua_isnil(lua, -1)) { - //pass each room to the hook - for (auto& it : elementMap) { - lua_pushvalue(lua, -1); //copy the hook - lua_pushlightuserdata(lua, &it.second); - lua_pushinteger(lua, it.first); - //call the function, 2 arg, 0 return - if (lua_pcall(lua, 2, 0, 0) != LUA_OK) { - throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) )); - } - } - } - - //pop the hook or nil - lua_pop(lua, 1); - - elementMap.clear(); -} - -void RoomManager::UnloadIf(std::function)> fn) { - //get the hook - lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef); - - //get the element - std::map::iterator it = elementMap.begin(); - - //jenky pattern - while (it != elementMap.end()) { - if (fn(*it)) { - - if(!lua_isnil(lua, -1)) { - lua_pushvalue(lua, -1); //copy the hook - lua_pushlightuserdata(lua, &it->second); - lua_pushinteger(lua, it->first); - - //call the function, 2 arg, 0 return - if (lua_pcall(lua, 2, 0, 0) != LUA_OK) { - throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) )); - } - } - - it = elementMap.erase(it); - } - else { - ++it; - } - } - - //pop the hook or nil - lua_pop(lua, 1); -} - -void RoomManager::PushCharacter(CharacterData* character) { - if (!character) { - throw(std::runtime_error("Failed to push a null character to a room")); - } - - RoomData* room = Get(character->GetRoomIndex()); - - if (!room) { - throw(std::runtime_error("Failed to push an character to a non-existant room")); - } - - room->GetCharacterList()->push_back(character); -} - -void RoomManager::PopCharacter(CharacterData const* character) { - //NOTE: to pop an character from a room, the character must first exist - if (!character) { - throw(std::runtime_error("Failed to pop a null character to a room")); - } - - RoomData* room = Get(character->GetRoomIndex()); - - if (!room) { - throw(std::runtime_error("Failed to pop an character to a non-existant room")); - } - - room->GetCharacterList()->remove_if([character](CharacterData* ptr) { - return character == ptr; - }); -} - -RoomData* RoomManager::Get(int uid) { - std::map::iterator it = elementMap.find(uid); - - if (it == elementMap.end()) { - return nullptr; - } - - return &it->second; -} - -RoomData* RoomManager::Get(std::string name) { - for (std::map::iterator it = elementMap.begin(); it != elementMap.end(); ++it) { - if (it->second.GetName() == name) { - return &it->second; - } - } - return nullptr; -} - -int RoomManager::GetLoadedCount() { - return elementMap.size(); -} - -std::map* RoomManager::GetContainer() { - return &elementMap; -} - -lua_State* RoomManager::SetLuaState(lua_State* L) { - lua = L; - for (auto& it : elementMap) { - it.second.SetLuaState(lua); - } - return lua; -} - -lua_State* RoomManager::GetLuaState() { - return lua; -} - -sqlite3* RoomManager::SetDatabase(sqlite3* db) { - database = db; - for (auto& it : elementMap) { - it.second.SetDatabase(database); - } - return database; -} - -sqlite3* RoomManager::GetDatabase() { - return database; -} - -int RoomManager::SetCreateReference(int i) { - return createRef = i; -} - -int RoomManager::SetUnloadReference(int i) { - return unloadRef = i; -} - -int RoomManager::GetCreateReference() { - return createRef; -} - -int RoomManager::GetUnloadReference() { - return unloadRef; -} diff --git a/server/rooms/room_manager.hpp b/server/rooms/room_manager.hpp deleted file mode 100644 index af95d56..0000000 --- a/server/rooms/room_manager.hpp +++ /dev/null @@ -1,81 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "character_data.hpp" -#include "room_data.hpp" -#include "singleton.hpp" - -#include "lua.hpp" -#include "sqlite3.h" - -#include -#include - -class RoomManager: public Singleton { -public: - //common public methods - int Create(std::string name, std::string tileset); - - void UnloadAll(); - void UnloadIf(std::function)> fn); - - void PushCharacter(CharacterData* character); - void PopCharacter(CharacterData const* character); - - //accessors and mutators - RoomData* Get(int uid); - RoomData* Get(std::string name); - int GetLoadedCount(); - std::map* GetContainer(); - - //API interfaces - lua_State* SetLuaState(lua_State* L); - lua_State* GetLuaState(); - sqlite3* SetDatabase(sqlite3* db); - sqlite3* GetDatabase(); - - //hooks - int SetCreateReference(int i); - int SetUnloadReference(int i); - - int GetCreateReference(); - int GetUnloadReference(); - -private: - friend Singleton; - - RoomManager() = default; - ~RoomManager() = default; - - //members - std::map elementMap; - int counter = 0; - - //API - lua_State* lua = nullptr; - sqlite3* database = nullptr; - - //hooks - int createRef = LUA_NOREF; - int unloadRef = LUA_NOREF; -}; diff --git a/server/rooms/room_manager_api.cpp b/server/rooms/room_manager_api.cpp deleted file mode 100644 index c0e88a6..0000000 --- a/server/rooms/room_manager_api.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "room_manager_api.hpp" - -#include "room_manager.hpp" - -int createRoom(lua_State* L) { - //create & get the room - RoomManager& roomMgr = RoomManager::GetSingleton(); - int uid = roomMgr.Create(lua_tostring(L, 1), lua_tostring(L, 2)); - RoomData* room = roomMgr.Get(uid); - - //TODO: initialization parameters here? - - //return room, uid - lua_pushlightuserdata(L, static_cast(room)); - lua_pushinteger(L, uid); //for debugging, mostly - - return 2; -} - -int unloadRoom(lua_State* L) { - RoomManager& roomMgr = RoomManager::GetSingleton(); - - switch(lua_type(L, 1)) { - case LUA_TNUMBER: { - //number - int uid = lua_tointeger(L, 1); - roomMgr.UnloadIf([uid](std::pair it){ - return it.first == uid; - }); - } - break; - case LUA_TSTRING: { - //name - std::string name = lua_tostring(L, 1); - roomMgr.UnloadIf([name](std::pair it){ - return it.second.GetName() == name; - }); - } - break; - case LUA_TLIGHTUSERDATA: { - //the room itself - std::string name = static_cast(lua_touserdata(L, 1))->GetName(); - roomMgr.UnloadIf([name](std::pair it){ - return it.second.GetName() == name; - }); - } - break; - } - return 0; -} - -int getRoom(lua_State* L) { - //integer vs name for getRoom() - RoomManager& roomMgr = RoomManager::GetSingleton(); - RoomData* room = nullptr; - - switch(lua_type(L, 1)) { - case LUA_TNUMBER: - //number - room = roomMgr.Get(lua_tointeger(L, 1)); - break; - case LUA_TSTRING: - //name - room = roomMgr.Get(lua_tostring(L, 1)); - break; - } - - if (room) { - lua_pushlightuserdata(L, static_cast(room)); - } - else { - lua_pushnil(L); - } - - return 1; -} - -static int setOnCreate(lua_State* L) { - RoomManager& roomMgr = RoomManager::GetSingleton(); - luaL_unref(L, LUA_REGISTRYINDEX, roomMgr.GetCreateReference()); - roomMgr.SetCreateReference(luaL_ref(L, LUA_REGISTRYINDEX)); - return 0; -} - -static int setOnUnload(lua_State* L) { - RoomManager& roomMgr = RoomManager::GetSingleton(); - luaL_unref(L, LUA_REGISTRYINDEX, roomMgr.GetUnloadReference()); - roomMgr.SetUnloadReference(luaL_ref(L, LUA_REGISTRYINDEX)); - return 0; -} - -static const luaL_Reg roomManagerLib[] = { - {"CreateRoom", createRoom}, - {"UnloadRoom", unloadRoom}, - {"GetRoom", getRoom}, - {"SetOnCreate", setOnCreate}, - {"SetOnUnload", setOnUnload}, - {nullptr, nullptr} -}; - -LUAMOD_API int openRoomManagerAPI(lua_State* L) { - luaL_newlib(L, roomManagerLib); - return 1; -} diff --git a/server/rooms/room_manager_api.hpp b/server/rooms/room_manager_api.hpp deleted file mode 100644 index 0606d83..0000000 --- a/server/rooms/room_manager_api.hpp +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "lua.hpp" - -#define TORTUGA_ROOM_MANAGER_API "room_manager" -LUAMOD_API int openRoomManagerAPI(lua_State* L); diff --git a/server/server_application.hpp b/server/server_application.hpp deleted file mode 100644 index 29ed8ff..0000000 --- a/server/server_application.hpp +++ /dev/null @@ -1,129 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 - -//managers -#include "account_manager.hpp" -#include "character_manager.hpp" -#include "client_manager.hpp" -#include "room_manager.hpp" - -//utilities -#include "config_utility.hpp" -#include "udp_network_utility.hpp" - -//common utilities -#include "ip_operators.hpp" -#include "serial_packet.hpp" -#include "singleton.hpp" - -//server utilities -#include "server_utilities.hpp" - -//APIs -#include "lua.hpp" -#include "sqlite3.h" - -#include "SDL/SDL.h" - -//STL -#include -#include - -//The main application class -class ServerApplication: public Singleton { -public: - //public methods - void Init(int argc, char* argv[]); - void Proc(); - void Quit(); - -private: - friend Singleton; - - ServerApplication() = default; - ~ServerApplication() = default; - - //handle incoming traffic - void HandlePacket(SerialPacket* const); - - //heartbeat system - void hPing(ServerPacket* const); - void hPong(ServerPacket* const); - - //basic connections - void hBroadcastRequest(ServerPacket* const); - void hJoinRequest(ClientPacket* const); - void hLoginRequest(ClientPacket* const); - - //client disconnections - void hLogoutRequest(ClientPacket* const); - void hDisconnectRequest(ClientPacket* const); - - //server commands - void hAdminDisconnectForced(ClientPacket* const); - void hAdminShutdownRequest(ClientPacket* const); - - //data management - void hRegionRequest(RegionPacket* const); - void hQueryCharacterExists(CharacterPacket* const); - void hQueryCharacterStats(CharacterPacket* const); - void hQueryCharacterLocation(CharacterPacket* const); - void hQueryMonsterExists(MonsterPacket* const); - void hQueryMonsterStats(MonsterPacket* const); - void hQueryMonsterLocation(MonsterPacket* const); - - //character management - void hCharacterCreate(CharacterPacket* const); - void hCharacterDelete(CharacterPacket* const); - void hCharacterLoad(CharacterPacket* const); - void hCharacterUnload(CharacterPacket* const); - - //character movement - void hCharacterMovement(CharacterPacket* const); - void hCharacterAttack(CharacterPacket* const); - void hCharacterDamage(CharacterPacket* const); - - //chat - void hTextBroadcast(TextPacket* const); - void hTextSpeech(TextPacket* const); - void hTextWhisper(TextPacket* const); - - //utility methods - void SaveServerState(); - - //APIs and utilities - sqlite3* database = nullptr; - lua_State* luaState = nullptr; - - //ugly references; I hate this - ClientManager& clientMgr = ClientManager::GetSingleton(); - AccountManager& accountMgr = AccountManager::GetSingleton(); - CharacterManager& characterMgr = CharacterManager::GetSingleton(); - RoomManager& roomMgr = RoomManager::GetSingleton(); - - ConfigUtility& config = ConfigUtility::GetSingleton(); - UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton(); - - //misc - bool running = true; -}; diff --git a/server/server_character_methods.cpp b/server/server_character_methods.cpp deleted file mode 100644 index 4e85ee6..0000000 --- a/server/server_character_methods.cpp +++ /dev/null @@ -1,243 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "server_application.hpp" - -#include -#include -#include - -//------------------------- -//Character Management -//------------------------- - -void ServerApplication::hCharacterCreate(CharacterPacket* const argPacket) { - int characterIndex = characterMgr.Create(argPacket->accountIndex, argPacket->handle, argPacket->avatar); - - if (characterIndex < 0) { - //build the error message - std::ostringstream msg; - msg << "Character already exists: " << argPacket->handle; - - //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; - } - - //push to the rooms - CharacterData* characterData = characterMgr.Get(characterIndex); - roomMgr.PushCharacter(characterData); - - //pump this character to all clients - CharacterPacket newPacket; - copyCharacterToPacket(&newPacket, characterIndex); - newPacket.type = SerialPacketType::CHARACTER_CREATE; - pumpPacketProximity(&newPacket, characterData->GetRoomIndex()); -} - -void ServerApplication::hCharacterDelete(CharacterPacket* const argPacket) { - //get the user's data - AccountData* accountData = accountMgr.Get(argPacket->accountIndex); - if (!accountData) { - return; - } - ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); - if (!clientData) { - return; - } - - //check for fraud - if (clientData->GetAddress() != argPacket->srcAddress) { - std::cerr << "Falsified character deletion detected targeting: " << argPacket->handle << std::endl; - return; - } - - //load the character into memory - int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar); - - if (characterIndex < 0) { - //build the error message - std::ostringstream msg; - msg << "Cannot delete this character"; - - //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; - } - - //pop from the rooms - CharacterData* characterData = characterMgr.Get(characterIndex); - roomMgr.PopCharacter(characterData); - - //pump character delete - CharacterPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_DELETE; - newPacket.characterIndex = characterIndex; - pumpPacketProximity(static_cast(&newPacket), characterData->GetRoomIndex()); - - //delete the character - characterMgr.Delete(characterIndex); -} - -void ServerApplication::hCharacterLoad(CharacterPacket* const argPacket) { - int characterIndex = characterMgr.Load(argPacket->accountIndex, argPacket->handle, argPacket->avatar); - - if (characterIndex < 0) { - //build the error message - std::ostringstream msg; - if (characterIndex == -1) { - msg << "Character already loaded: "; - } - if (characterIndex == -2) { - msg << "Character name is taken: "; - } - msg << argPacket->handle; - - //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; - } - - //push to the rooms - CharacterData* characterData = characterMgr.Get(characterIndex); - roomMgr.PushCharacter(characterData); - - //pump this character to all clients - CharacterPacket newPacket; - copyCharacterToPacket(&newPacket, characterIndex); - newPacket.type = SerialPacketType::CHARACTER_CREATE; - pumpPacketProximity(&newPacket, characterData->GetRoomIndex()); -} - -void ServerApplication::hCharacterUnload(CharacterPacket* const argPacket) { - //get the entries - CharacterData* characterData = characterMgr.Get(argPacket->characterIndex); - if (!characterData) { - return; - } - - AccountData* accountData = accountMgr.Get(characterData->GetOwner()); - if (!accountData) { - return; - } - - ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); - if (!clientData) { - return; - } - - //check for fraud - if (clientData->GetAddress() != argPacket->srcAddress) { - std::cerr << "Falsified character unload detected targeting: uid(" << argPacket->characterIndex << ")" << std::endl; - return; - } - - //pop from the rooms - roomMgr.PopCharacter(characterData); - - //pump character delete - CharacterPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_DELETE; - newPacket.characterIndex = argPacket->characterIndex; - pumpPacketProximity(static_cast(&newPacket), characterData->GetRoomIndex()); - - //unload the character - characterMgr.Unload(argPacket->characterIndex); -} - -//------------------------- -//character movement -//------------------------- - -//TODO: (2) Could replace this verbosity with a "verify" method, taking a client, account and character ptr as arguments - -void ServerApplication::hCharacterMovement(CharacterPacket* const argPacket) { - //get the specified objects - AccountData* accountData = accountMgr.Get(argPacket->accountIndex); - - if (!accountData) { - throw(std::runtime_error("Failed to move a character, missing account")); - } - - CharacterData* characterData = characterMgr.Get(argPacket->characterIndex); - - if (!characterData) { - throw(std::runtime_error("Failed to move a character, missing character")); - } - - //get this account's client - ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); - - //check for fraud - if (clientData->GetAddress() != argPacket->srcAddress) { - std::cerr << "Falsified set character motion targeting uid(" << argPacket->characterIndex << ")" << std::endl; - return; - } - - //check if allowed - if (characterData->GetOwner() != argPacket->accountIndex && !accountData->GetModerator() && !accountData->GetAdministrator()) { - //TODO: (3) send to the client? - std::cerr << "Failed to set character motion due to lack of permissions targeting uid(" << argPacket->characterIndex << ")" << std::endl; - return; - } - - //check if moving rooms - if (characterData->GetRoomIndex() != argPacket->roomIndex) { - //set the character's origin and motion - characterData->SetOrigin(argPacket->origin); - characterData->SetMotion(argPacket->motion); - - //send the delete & create messages - pumpAndChangeRooms(characterData, argPacket->roomIndex, argPacket->characterIndex); - } - //if not moving between rooms - else { - //set the character's origin and motion - characterData->SetOrigin(argPacket->origin); - characterData->SetMotion(argPacket->motion); - - //update the clients - CharacterPacket newPacket; - copyCharacterToPacket(&newPacket, argPacket->characterIndex); - newPacket.type = SerialPacketType::CHARACTER_MOVEMENT; - pumpPacketProximity(&newPacket, characterData->GetRoomIndex()); - } -} - -void ServerApplication::hCharacterAttack(CharacterPacket* const argPacket) { - //TODO: (9) ServerApplication::hCharacterAttack() -} - -void ServerApplication::hCharacterDamage(CharacterPacket* const argPacket) { - //TODO: (9) ServerApplication::hCharacterDamage() -} \ No newline at end of file diff --git a/server/server_chat.cpp b/server/server_chat.cpp deleted file mode 100644 index f5395f0..0000000 --- a/server/server_chat.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "server_application.hpp" - -void ServerApplication::hTextBroadcast(TextPacket* const argPacket) { - //TODO: (9) ServerApplication::hTextBroadcast() -} - -void ServerApplication::hTextSpeech(TextPacket* const argPacket) { - //TODO: (9) ServerApplication::hTextSpeech() -} - -void ServerApplication::hTextWhisper(TextPacket* const argPacket) { - //TODO: (9) ServerApplication::hTextWhisper() -} diff --git a/server/server_connections.cpp b/server/server_connections.cpp deleted file mode 100644 index e88c1dd..0000000 --- a/server/server_connections.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "server_application.hpp" - -#include -#include -#include - -//------------------------- -//heartbeat system -//------------------------- - -void ServerApplication::hPing(ServerPacket* const argPacket) { - ServerPacket newPacket; - newPacket.type = SerialPacketType::PONG; - network.SendTo(argPacket->srcAddress, &newPacket); -} - -void ServerApplication::hPong(ServerPacket* const argPacket) { - clientMgr.HandlePong(argPacket); -} - -//------------------------- -//basic connections -//------------------------- - -void ServerApplication::hBroadcastRequest(ServerPacket* const argPacket) { - //send the server's data - ServerPacket newPacket; - - newPacket.type = SerialPacketType::BROADCAST_RESPONSE; - strncpy(newPacket.name, config["server.name"].c_str(), PACKET_STRING_SIZE); - newPacket.playerCount = characterMgr.GetLoadedCount(); - newPacket.version = NETWORK_VERSION; - - network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); -} - -void ServerApplication::hJoinRequest(ClientPacket* const argPacket) { - //register the client - int clientIndex = clientMgr.Create(argPacket->srcAddress); - - //send the client their info - ClientPacket newPacket; - newPacket.type = SerialPacketType::JOIN_RESPONSE; - newPacket.clientIndex = clientIndex; - - network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); - - //finished this routine - std::cout << "New join, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; -} - -void ServerApplication::hLoginRequest(ClientPacket* const argPacket) { - //get the client data - ClientData* clientData = clientMgr.Get(argPacket->clientIndex); - - if (clientData == nullptr || clientData->GetAddress() != argPacket->srcAddress) { - std::cerr << "Falsified client index detected: " << argPacket->clientIndex << std::endl; - return; - } - - //load the user account - int accountIndex = accountMgr.Load(argPacket->username, argPacket->clientIndex); - - //Cannot load - if (accountIndex < 0) { - //build the message - std::ostringstream msg; - msg << "Account already loaded: " << argPacket->username; - - //build the packet - TextPacket newPacket; - newPacket.type = SerialPacketType::LOGIN_REJECTION; - strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); - network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); - - //log the error - std::cerr << "Error message sent: " << newPacket.text << std::endl; - return; - } - - //send the client their info - ClientPacket newPacket; - newPacket.type = SerialPacketType::LOGIN_RESPONSE; - newPacket.clientIndex = argPacket->clientIndex; - newPacket.accountIndex = accountIndex; - - network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); - - //finished this routine - std::cout << "New login, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; -} - -void ServerApplication::hLogoutRequest(ClientPacket* const argPacket) { - //get the account and client data - AccountData* accountData = accountMgr.Get(argPacket->accountIndex); - if (!accountData) { - return; - } - - ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); - if (!clientData) { - std::ostringstream msg; - msg << "No client found for an account: " << accountData->GetUsername(); - throw(std::logic_error(msg.str())); - } - - //check for fraud - if (clientData->GetAddress() != argPacket->srcAddress) { - std::cerr << "Falsified logout detected targeting: " << accountData->GetUsername() << std::endl; - return; - } - - //send the logout response - ClientPacket newPacket; - newPacket.type = SerialPacketType::LOGOUT_RESPONSE; - newPacket.accountIndex = argPacket->accountIndex; - - network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); - - //save and unload this account and it's characters - fullAccountUnload(argPacket->accountIndex); - - //finished this routine - std::cout << "New logout, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; -} - -void ServerApplication::hDisconnectRequest(ClientPacket* const argPacket) { - //get the client data - ClientData* clientData = clientMgr.Get(argPacket->clientIndex); - if (!clientData) { - return; - } - - //check for fraud - if (clientData->GetAddress() != argPacket->srcAddress) { - std::cerr << "Falsified disconnection detected targeting: " << argPacket->clientIndex << std::endl; - return; - } - - //send the disconnect response - ClientPacket newPacket; - newPacket.type = SerialPacketType::DISCONNECT_RESPONSE; - newPacket.clientIndex = argPacket->clientIndex; - - network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); - - //unload the client, it's accounts, and their characters - fullClientUnload(argPacket->clientIndex); - - //finished this routine - std::cout << "New disconnection, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; -} diff --git a/server/server_data_queries.cpp b/server/server_data_queries.cpp deleted file mode 100644 index 721925a..0000000 --- a/server/server_data_queries.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "server_application.hpp" - -#include -#include -#include - -//------------------------- -//Queries -//------------------------- - -void ServerApplication::hRegionRequest(RegionPacket* const argPacket) { - //get the region object, send a rejection on error - RoomData* room = roomMgr.Get(argPacket->roomIndex); - if (!room) { - //build the error message - std::ostringstream msg; - msg << "Failed to find Region (" << argPacket->roomIndex << "," << argPacket->x << "," << argPacket->y << "); "; - msg << "Room " << argPacket->roomIndex << " does not exist"; - - //build the packet - TextPacket newPacket; - newPacket.type = SerialPacketType::REGION_REJECTION; - strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); - network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); - - //log the error - std::cerr << "Error message sent: " << newPacket.text << std::endl; - return; - } - Region* region = room->GetPager()->GetRegion(argPacket->x, argPacket->y); - - //send the content - RegionPacket newPacket; - - newPacket.type = SerialPacketType::REGION_CONTENT; - newPacket.roomIndex = argPacket->roomIndex; - newPacket.x = argPacket->x; - newPacket.y = argPacket->y; - newPacket.region = region; - - network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); -} - -void ServerApplication::hQueryCharacterExists(CharacterPacket* const argPacket) { - //respond with all character data - CharacterPacket newPacket; - - for (auto& it : *characterMgr.GetContainer()) { - if (argPacket->roomIndex != -1 && it.second.GetRoomIndex() != argPacket->roomIndex) { - continue; - } - copyCharacterToPacket(&newPacket, it.first); - newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS; - network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); - } -} - -void ServerApplication::hQueryCharacterStats(CharacterPacket* const argPacket) { - //TODO: (9) ServerApplication::hQueryCharacterStats() -} - -void ServerApplication::hQueryCharacterLocation(CharacterPacket* const argPacket) { - //TODO: (9) ServerApplication::hQueryCharacterLocation() -} - -void ServerApplication::hQueryMonsterExists(MonsterPacket* const argPacket) { - //TODO: (9) ServerApplication::hQueryMonsterExists() -} - -void ServerApplication::hQueryMonsterStats(MonsterPacket* const argPacket) { - //TODO: (9) ServerApplication::hQueryMonsterStats() -} - -void ServerApplication::hQueryMonsterLocation(MonsterPacket* const argPacket) { - //TODO: (9) ServerApplication::hQueryMonsterLocation() -} diff --git a/server/server_logic.cpp b/server/server_logic.cpp deleted file mode 100644 index ed31f6f..0000000 --- a/server/server_logic.cpp +++ /dev/null @@ -1,350 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "server_application.hpp" - -//utility functions -#include "sql_tools.hpp" - -//std & STL -#include -#include - #include -#include -#include -#include -#include - -//------------------------- -//public methods -//------------------------- - -//BUG: #35 The server fails without at least one room - -void ServerApplication::Init(int argc, char* argv[]) { - //NOTE: I might need to rearrange the init process so that lua & SQL can interact with the map system as needed. - std::cout << "Beginning " << argv[0] << std::endl; - - //load the config settings - config.Load("rsc/config.cfg", false, argc, argv); - - //------------------------- - //Initialize the APIs - //------------------------- - - //Init SDL - if (SDL_Init(0)) { - std::ostringstream os; - os << "Failed to initialize SDL: " << SDL_GetError(); - throw(std::runtime_error(os.str())); - } - std::cout << "Initialized SDL" << std::endl; - - //Init SDL_net - if (SDLNet_Init()) { - throw(std::runtime_error("Failed to initialize SDL_net")); - } - network.Open(config.Int("server.port")); - std::cout << "Initialized SDL_net" << std::endl; - - //Init SQL - int ret = sqlite3_open_v2(config["server.dbname"].c_str(), &database, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, nullptr); - if (ret != SQLITE_OK || !database) { - throw(std::runtime_error(std::string() + "Failed to initialize SQL: " + sqlite3_errmsg(database) )); - } - std::cout << "Initialized SQL" << std::endl; - - //Init lua - luaState = luaL_newstate(); - if (!luaState) { - throw(std::runtime_error("Failed to initialize lua")); - } - luaL_openlibs(luaState); - - std::cout << "Initialized lua" << std::endl; - - //append config["dir.scripts"] to the module path - if (config["dir.scripts"].size() > 0) { - //get the original path - lua_getglobal(luaState, "package"); - lua_getfield(luaState, -1, "path"); - - //build & push the message - std::ostringstream path; - path << lua_tostring(luaState, -1) << ";" << config["dir.scripts"] << "?.lua"; - lua_pushstring(luaState, path.str().c_str()); - - //set the new path and clean up the stack - lua_setfield(luaState, -3, "path"); - lua_pop(luaState, 2); - - std::cout << "\tLua script directory appended" << std::endl; - } - - //------------------------- - //Setup the objects - //------------------------- - - //set the hooks - accountMgr.SetDatabase(database); - characterMgr.SetDatabase(database); - - roomMgr.SetLuaState(luaState); - roomMgr.SetDatabase(database); - - std::cout << "Internal managers initialized" << std::endl; - - //------------------------- - //Run the startup scripts - //------------------------- - - //setup the database - if (runSQLScript(database, config["dir.scripts"] + "setup_server.sql")) { - throw(std::runtime_error("Failed to initialize SQL's setup script")); - } - std::cout << "Completed SQL's setup script" << std::endl; - - //run lua's startup script - if (luaL_dofile(luaState, (config["dir.scripts"] + "setup_server.lua").c_str())) { - throw(std::runtime_error(std::string() + "Failed to initialize lua's setup script: " + lua_tostring(luaState, -1) )); - } - std::cout << "Completed lua's setup script" << std::endl; - - //------------------------- - //debug output - //------------------------- - -#define DEBUG_OUTPUT_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl; - - std::cout << "Internal sizes:" << std::endl; - - DEBUG_OUTPUT_VAR(NETWORK_VERSION); - DEBUG_OUTPUT_VAR(sizeof(Region::type_t)); - DEBUG_OUTPUT_VAR(sizeof(Region)); - DEBUG_OUTPUT_VAR(REGION_WIDTH); - DEBUG_OUTPUT_VAR(REGION_HEIGHT); - DEBUG_OUTPUT_VAR(REGION_DEPTH); - DEBUG_OUTPUT_VAR(REGION_TILE_FOOTPRINT); - DEBUG_OUTPUT_VAR(REGION_SOLID_FOOTPRINT); - DEBUG_OUTPUT_VAR(PACKET_STRING_SIZE); - DEBUG_OUTPUT_VAR(PACKET_BUFFER_SIZE); - DEBUG_OUTPUT_VAR(MAX_PACKET_SIZE); - DEBUG_OUTPUT_VAR(static_cast(SerialPacketType::LAST)); - -#undef DEBUG_OUTPUT_VAR - - //------------------------- - //finalize the startup - //------------------------- - - std::cout << "Startup completed successfully" << std::endl; - - //------------------------- - //debugging - //------------------------- - - //... -} - -void ServerApplication::Proc() { - //network buffer - SerialPacket* packetBuffer = reinterpret_cast(new char[MAX_PACKET_SIZE]); - memset(packetBuffer, 0, MAX_PACKET_SIZE); //zero the buffer - - //time system - typedef std::chrono::steady_clock Clock; - - Clock::time_point simTime = Clock::now(); - Clock::time_point realTime; - - while(running) { - //suck in the waiting packets & process them - while(network.Receive(packetBuffer)) { - try { - HandlePacket(packetBuffer); - } - catch(std::exception& e) { - std::cerr << "HandlePacket Error: " << e.what() << std::endl; - } - //reset the buffer - memset(packetBuffer, 0, MAX_PACKET_SIZE); - } - - //Check client connections - std::list disconnections = clientMgr.CheckConnections(); - for(auto const& it : disconnections) { - fullClientUnload(it); - std::cerr << "Client dropped: " << it << std::endl; - } - - //"tick" the internals - realTime = Clock::now(); - - if (simTime < realTime) { - while(simTime < realTime) { - for (auto& it : *roomMgr.GetContainer()) { - it.second.RunFrame(); - } - //~60 FPS - simTime += std::chrono::duration(16); - } - } - else { - //give the machine a break - SDL_Delay(10); - } - } - delete reinterpret_cast(packetBuffer); -} - -void ServerApplication::Quit() { - std::cout << "Shutting down" << std::endl; - - //save the server state - SaveServerState(); - - //close the managers - accountMgr.UnloadAll(); - characterMgr.UnloadAll(); - clientMgr.UnloadAll(); - roomMgr.UnloadAll(); - - //APIs - lua_close(luaState); - sqlite3_close_v2(database); - network.Close(); - SDLNet_Quit(); - SDL_Quit(); - - std::cout << "Clean exit" << std::endl; -} - -//------------------------- -//handle incoming traffic -//------------------------- - -void ServerApplication::HandlePacket(SerialPacket* const argPacket) { - switch(argPacket->type) { - //heartbeat system - case SerialPacketType::PING: - hPing(static_cast(argPacket)); - break; - case SerialPacketType::PONG: - hPong(static_cast(argPacket)); - break; - - //client connections - case SerialPacketType::BROADCAST_REQUEST: - hBroadcastRequest(static_cast(argPacket)); - break; - case SerialPacketType::JOIN_REQUEST: - hJoinRequest(static_cast(argPacket)); - break; - case SerialPacketType::LOGIN_REQUEST: - hLoginRequest(static_cast(argPacket)); - break; - - //client disconnections - case SerialPacketType::LOGOUT_REQUEST: - hLogoutRequest(static_cast(argPacket)); - break; - case SerialPacketType::DISCONNECT_REQUEST: - hDisconnectRequest(static_cast(argPacket)); - break; - - //server commands - case SerialPacketType::ADMIN_DISCONNECT_FORCED: - hAdminDisconnectForced(static_cast(argPacket)); - break; - case SerialPacketType::ADMIN_SHUTDOWN_REQUEST: - hAdminShutdownRequest(static_cast(argPacket)); - break; - - //data management & queries - case SerialPacketType::REGION_REQUEST: - hRegionRequest(static_cast(argPacket)); - break; - case SerialPacketType::QUERY_CHARACTER_EXISTS: - hQueryCharacterExists(static_cast(argPacket)); - break; - case SerialPacketType::QUERY_CHARACTER_STATS: - hQueryCharacterStats(static_cast(argPacket)); - break; - case SerialPacketType::QUERY_CHARACTER_LOCATION: - hQueryCharacterLocation(static_cast(argPacket)); - break; - - case SerialPacketType::QUERY_MONSTER_EXISTS: - hQueryMonsterExists(static_cast(argPacket)); - break; - case SerialPacketType::QUERY_MONSTER_STATS: - hQueryMonsterStats(static_cast(argPacket)); - break; - case SerialPacketType::QUERY_MONSTER_LOCATION: - hQueryMonsterLocation(static_cast(argPacket)); - break; - - //character management - case SerialPacketType::CHARACTER_CREATE: - hCharacterCreate(static_cast(argPacket)); - break; - case SerialPacketType::CHARACTER_DELETE: - hCharacterDelete(static_cast(argPacket)); - break; - case SerialPacketType::CHARACTER_LOAD: - hCharacterLoad(static_cast(argPacket)); - break; - case SerialPacketType::CHARACTER_UNLOAD: - hCharacterUnload(static_cast(argPacket)); - break; - - //character movement - case SerialPacketType::CHARACTER_MOVEMENT: - hCharacterMovement(static_cast(argPacket)); - break; - case SerialPacketType::CHARACTER_ATTACK: - hCharacterAttack(static_cast(argPacket)); - break; - case SerialPacketType::CHARACTER_DAMAGE: - hCharacterDamage(static_cast(argPacket)); - break; - - //chat - case SerialPacketType::TEXT_BROADCAST: - hTextBroadcast(static_cast(argPacket)); - break; - case SerialPacketType::TEXT_SPEECH: - hTextSpeech(static_cast(argPacket)); - break; - case SerialPacketType::TEXT_WHISPER: - hTextWhisper(static_cast(argPacket)); - break; - - //handle errors - default: { - std::ostringstream msg; - msg << "Unknown SerialPacketType encountered in the server: "; - msg << static_cast(argPacket->type); - throw(std::runtime_error(msg.str())); - } - break; - } -} diff --git a/server/server_methods.cpp b/server/server_methods.cpp deleted file mode 100644 index d23c13b..0000000 --- a/server/server_methods.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "server_application.hpp" - -#include - #include -#include -#include - -//------------------------- -//server commands -//------------------------- - -void ServerApplication::hAdminDisconnectForced(ClientPacket* const argPacket) { - //TODO: (9) ServerApplication::hAdminDisconnectForced() -} - -void ServerApplication::hAdminShutdownRequest(ClientPacket* const argPacket) { - //get the account and client data - AccountData* accountData = accountMgr.Get(argPacket->accountIndex); - if (!accountData) { - return; - } - ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); - if (!clientData) { - std::ostringstream msg; - msg << "No client found for an account: " << accountData->GetUsername(); - throw(std::logic_error(msg.str())); - } - - //check for fraud - if (clientData->GetAddress() != argPacket->srcAddress) { - std::cerr << "Falsified server shutdown detected from: " << accountData->GetUsername() << std::endl; - return; - } - - //reject non-admin requests - if (accountData->GetAdministrator() != true) { - std::cerr << "Rejected server shutdown command from: " << accountData->GetUsername() << std::endl; - - //build the message - std::ostringstream msg; - msg << "Invalid admin status"; - - //build the packet - TextPacket newPacket; - newPacket.type = SerialPacketType::SHUTDOWN_REJECTION; - strncpy(newPacket.text, msg.str().c_str(), PACKET_STRING_SIZE); - - //send the rejection message - network.SendTo(argPacket->srcAddress, static_cast(&newPacket)); - - return; - } - - //end the server - running = false; - - //disconnect all clients - TextPacket newPacket; - newPacket.type = SerialPacketType::ADMIN_DISCONNECT_FORCED; - strncpy(newPacket.text, "Server shutdown", PACKET_STRING_SIZE); - pumpPacket(&newPacket); - - //finished this routine - std::cout << "Shutdown signal accepted" << std::endl; -} - -void ServerApplication::SaveServerState() { - //TODO: (3) Periodic mass server saves -} diff --git a/server/server_utilities/makefile b/server/server_utilities/makefile deleted file mode 100644 index 7a87443..0000000 --- a/server/server_utilities/makefile +++ /dev/null @@ -1,32 +0,0 @@ -#config -INCLUDES+=. ../accounts ../characters ../clients ../entities ../monsters ../rooms ../triggers ../../common/gameplay ../../common/map ../../common/network ../../common/network/packet_types ../../common/utilities -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)/,server.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 $@ $< diff --git a/server/server_utilities/network_api.cpp b/server/server_utilities/network_api.cpp deleted file mode 100644 index c1fe6ac..0000000 --- a/server/server_utilities/network_api.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "network_api.hpp" - -#include "character_data.hpp" -#include "character_manager.hpp" -#include "server_utilities.hpp" - -#include - -static int pumpCharacterUpdate(lua_State* L) { - CharacterData* characterData = static_cast(lua_touserdata(L, 1)); - - //determine the character's index - int index = -1; - for (auto const& it : *CharacterManager::GetSingleton().GetContainer()) { - if(characterData == &it.second) { - index = it.first; - break; - } - } - - //signal an error - if (index == -1) { - lua_pushboolean(L, false); - return 1; - } - - //fill the packet with all of this character's data - CharacterPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_UPDATE; - newPacket.characterIndex = index; - strncpy(newPacket.handle, characterData->GetHandle().c_str(), PACKET_STRING_SIZE); - strncpy(newPacket.avatar, characterData->GetAvatar().c_str(), PACKET_STRING_SIZE); - newPacket.accountIndex = characterData->GetOwner(); - newPacket.roomIndex = characterData->GetRoomIndex(); - newPacket.origin = characterData->GetOrigin(); - newPacket.motion = characterData->GetMotion(); - - //pump to the room - pumpPacketProximity(&newPacket, characterData->GetRoomIndex()); - - //signal success - lua_pushboolean(L, true); - return 1; -} - -static int pumpMonsterUpdate(lua_State* L) { - //TODO: (0) send the info about a specific monster instance -} - -static const luaL_Reg networkLib[] = { - {"PumpCharacterUpdate", pumpCharacterUpdate}, - {"PumpMonsterUpdate", pumpMonsterUpdate}, - {nullptr, nullptr} -}; - -LUAMOD_API int openNetworkAPI(lua_State* L) { - luaL_newlib(L, networkLib); - return 1; -} \ No newline at end of file diff --git a/server/server_utilities/network_api.hpp b/server/server_utilities/network_api.hpp deleted file mode 100644 index 62d8381..0000000 --- a/server/server_utilities/network_api.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "lua.hpp" - -#define TORTUGA_NETWORK_API "network" -LUAMOD_API int openNetworkAPI(lua_State* L); diff --git a/server/server_utilities/server_utilities.cpp b/server/server_utilities/server_utilities.cpp deleted file mode 100644 index 698ed29..0000000 --- a/server/server_utilities/server_utilities.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "server_utilities.hpp" - -#include "account_manager.hpp" -#include "character_manager.hpp" -#include "client_manager.hpp" -#include "room_manager.hpp" -#include "udp_network_utility.hpp" - -#include - -//------------------------- -//manager unload functions -//------------------------- - -void fullClientUnload(int index) { - ClientManager::GetSingleton().UnloadIf([index](std::pair clientPair) -> bool { - //skip the wrong clients - if (clientPair.first != index) { - return false; - } - - AccountManager& accountMgr = AccountManager::GetSingleton(); - - //unload associated accounts - for (std::map::iterator it = accountMgr.GetContainer()->begin(); it != accountMgr.GetContainer()->end(); /* EMPTY */) { - if (it->second.GetClientIndex() == index) { - fullAccountUnload(it->first); - it = accountMgr.GetContainer()->begin(); - } - else { - ++it; - } - } - - //unload this client - return true; - }); -} - -void fullAccountUnload(int index) { - AccountManager::GetSingleton().UnloadIf([index](std::pair accountPair) -> bool { - //skip the wrong accounts - if (accountPair.first != index) { - return false; - } - - CharacterManager& characterMgr = CharacterManager::GetSingleton(); - - //unload associated characters - for (std::map::iterator it = characterMgr.GetContainer()->begin(); it != characterMgr.GetContainer()->end(); /* EMPTY */) { - if (it->second.GetOwner() == index) { - fullCharacterUnload(it->first); - it = characterMgr.GetContainer()->begin(); - } - else { - ++it; - } - } - - //unload this account - return true; - }); -} - -void fullCharacterUnload(int index) { - CharacterManager::GetSingleton().UnloadIf([index](std::pair characterPair) -> bool { - //skip the wrong characters - if (characterPair.first != index) { - return false; - } - - //pop from the rooms - RoomManager::GetSingleton().PopCharacter(&characterPair.second); - - //pump character unload - CharacterPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_DELETE; - newPacket.characterIndex = characterPair.first; - //NOTE: more character info as needed - - //TODO: proximity? - pumpPacketProximity(&newPacket, characterPair.second.GetRoomIndex()); - - //unload this character - return true; - }); -} - -//------------------------- -//utility functions -//------------------------- - -void pumpPacket(SerialPacket* const argPacket) { - for (auto& it : *ClientManager::GetSingleton().GetContainer()) { - UDPNetworkUtility::GetSingleton().SendTo(it.second.GetAddress(), argPacket); - } -} - -void pumpPacketProximity(SerialPacket* const argPacket, int roomIndex, Vector2 position, int distance) { - RoomData* roomData = RoomManager::GetSingleton().Get(roomIndex); - - if (!roomData) { - throw(std::runtime_error("Failed to pump to a non-existant room")); - } - - AccountData* accountData = nullptr; - ClientData* clientData = nullptr; - - for (auto& characterIt : *roomData->GetCharacterList()) { - if (distance == -1 || (characterIt->GetOrigin() - position).Length() <= distance) { - accountData = AccountManager::GetSingleton().Get(characterIt->GetOwner()); - clientData = ClientManager::GetSingleton().Get(accountData->GetClientIndex()); - UDPNetworkUtility::GetSingleton().SendTo(clientData->GetAddress(), argPacket); - } - } -} - -void copyCharacterToPacket(CharacterPacket* const packet, int characterIndex) { - CharacterData* characterData = CharacterManager::GetSingleton().Get(characterIndex); - if (!characterData) { - throw(std::runtime_error("Failed to copy a character to a packet")); - } - - copyCharacterToPacket(packet, characterData, characterIndex); -} - -void copyCharacterToPacket(CharacterPacket* const packet, CharacterData* const characterData, int characterIndex) { - //NOTE: keep this up to date when the character changes - packet->characterIndex = characterIndex; - strncpy(packet->handle, characterData->GetHandle().c_str(), PACKET_STRING_SIZE); - strncpy(packet->avatar, characterData->GetAvatar().c_str(), PACKET_STRING_SIZE); - packet->accountIndex = characterData->GetOwner(); - packet->roomIndex = characterData->GetRoomIndex(); - packet->origin = characterData->GetOrigin(); - packet->motion = characterData->GetMotion(); - packet->bounds = characterData->GetBounds(); -} - -void pumpAndChangeRooms(int characterIndex, int newRoomIndex) { - //get the character object - CharacterData* character = CharacterManager::GetSingleton().Get(characterIndex); - - //pass ownwards - pumpAndChangeRooms(character, newRoomIndex, characterIndex); -} - -void pumpAndChangeRooms(CharacterData* const characterData, int newRoomIndex, int characterIndex) { - //delete from the old room - CharacterPacket newPacket; - copyCharacterToPacket(&newPacket, characterData, characterIndex); - newPacket.type = SerialPacketType::CHARACTER_DELETE; - pumpPacketProximity(&newPacket, characterData->GetRoomIndex()); - - //move the character between rooms - RoomManager::GetSingleton().PopCharacter(characterData); - characterData->SetRoomIndex(newRoomIndex); - RoomManager::GetSingleton().PushCharacter(characterData); - - //create in the new room - copyCharacterToPacket(&newPacket, characterData, characterIndex); - newPacket.type = SerialPacketType::CHARACTER_CREATE; - pumpPacketProximity(&newPacket, characterData->GetRoomIndex()); -} \ No newline at end of file diff --git a/server/server_utilities/server_utilities.hpp b/server/server_utilities/server_utilities.hpp deleted file mode 100644 index 64035b7..0000000 --- a/server/server_utilities/server_utilities.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "character_data.hpp" -#include "serial_packet.hpp" -#include "vector2.hpp" - -void fullClientUnload(int index); -void fullAccountUnload(int index); -void fullCharacterUnload(int index); - -void pumpPacket(SerialPacket* const argPacket); -void pumpPacketProximity(SerialPacket* const argPacket, int roomIndex, Vector2 position = {0, 0}, int distance = -1); - -void copyCharacterToPacket(CharacterPacket* const packet, int characterIndex); -void copyCharacterToPacket(CharacterPacket* const packet, CharacterData* const characterData, int characterIndex); -void pumpAndChangeRooms(int characterIndex, int newRoomIndex); -void pumpAndChangeRooms(CharacterData* const characterData, int newRoomIndex, int characterIndex); diff --git a/server/server_utilities/sql_tools.cpp b/server/server_utilities/sql_tools.cpp deleted file mode 100644 index 78e1065..0000000 --- a/server/server_utilities/sql_tools.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "sql_tools.hpp" - -#include -#include -#include -#include - -int runSQLScript(sqlite3* db, std::string fname, int (*callback)(void*,int,char**,char**), void* argPtr) { - //load the file into a string - std::ifstream is(fname); - if (!is.is_open()) { - return -1; - } - std::string script; - getline(is, script, '\0'); - is.close(); - - //run the SQL loaded from the file - char* errmsg = nullptr; - int ret = sqlite3_exec(db, script.c_str(), callback, argPtr, &errmsg); - if (ret != SQLITE_OK) { - //handle any errors received from the SQL - std::ostringstream msg; - msg << "SQL Script Error " << ret << ": " << errmsg; - free(errmsg); - throw(std::runtime_error( msg.str() )); - } - return ret; -} \ No newline at end of file diff --git a/server/server_utilities/sql_tools.hpp b/server/server_utilities/sql_tools.hpp deleted file mode 100644 index 838bbba..0000000 --- a/server/server_utilities/sql_tools.hpp +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "sqlite3.h" - -#include - -int runSQLScript(sqlite3* db, std::string fname, int (*callback)(void*,int,char**,char**) = nullptr, void* argPtr = nullptr); diff --git a/server/triggers/makefile b/server/triggers/makefile deleted file mode 100644 index 16035a5..0000000 --- a/server/triggers/makefile +++ /dev/null @@ -1,32 +0,0 @@ -#config -INCLUDES+=. ../entities ../server_utilities ../../common/utilities -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)/,server.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 $@ $< diff --git a/server/triggers/trigger_api.cpp b/server/triggers/trigger_api.cpp deleted file mode 100644 index 8f9089a..0000000 --- a/server/triggers/trigger_api.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "trigger_api.hpp" - -#include "trigger_data.hpp" - -//hamdle -static int setHandle(lua_State* L) { - TriggerData* trigger = static_cast(lua_touserdata(L, 1)); - trigger->SetHandle(lua_tostring(L, 2)); - return 0; -} - -static int getHandle(lua_State* L) { - TriggerData* trigger = static_cast(lua_touserdata(L, 1)); - lua_pushstring(L, trigger->GetHandle().c_str()); - return 1; -} - -//origin -static int setOrigin(lua_State* L) { - TriggerData* trigger = static_cast(lua_touserdata(L, 1)); - trigger->SetOrigin(Vector2(lua_tonumber(L, 2), lua_tonumber(L, 3))); - return 0; -} - -static int getOrigin(lua_State* L) { - TriggerData* trigger = static_cast(lua_touserdata(L, 1)); - lua_pushnumber(L, trigger->GetOrigin().x); - lua_pushnumber(L, trigger->GetOrigin().y); - return 2; -} - -//bounds -static int setBoundingBox(lua_State* L) { - TriggerData* trigger = static_cast(lua_touserdata(L, 1)); - trigger->SetBoundingBox(BoundingBox( - lua_tonumber(L, 2), - lua_tonumber(L, 3), - lua_tonumber(L, 4), - lua_tonumber(L, 5) - )); - return 0; -} - -static int getBoundingBox(lua_State* L) { - TriggerData* trigger = static_cast(lua_touserdata(L, 1)); - lua_pushinteger(L, trigger->GetBoundingBox().x); - lua_pushinteger(L, trigger->GetBoundingBox().y); - lua_pushinteger(L, trigger->GetBoundingBox().w); - lua_pushinteger(L, trigger->GetBoundingBox().h); - return 4; -} - -//triggers -static int setReference(lua_State* L) { - TriggerData* trigger = static_cast(lua_touserdata(L, 1)); - luaL_unref(L, LUA_REGISTRYINDEX, trigger->GetScriptReference()); - trigger->SetScriptReference(luaL_ref(L, LUA_REGISTRYINDEX)); - return 0; -} - -static int getReference(lua_State* L) { - TriggerData* trigger = static_cast(lua_touserdata(L, 1)); - lua_pushinteger(L, trigger->GetScriptReference()); - lua_gettable(L, LUA_REGISTRYINDEX); - return 1; -} - -static int pushExclusionEntity(lua_State* L) { - TriggerData* trigger = static_cast(lua_touserdata(L, 1)); - trigger->GetExclusionList()->push_back(static_cast(lua_touserdata(L, 2))); - return 0; -} - -static int removeExclusionEntity(lua_State* L) { - TriggerData* trigger = static_cast(lua_touserdata(L, 1)); - Entity* entity = static_cast(lua_touserdata(L, 2)); - trigger->GetExclusionList()->remove_if([entity](Entity* ptr){ - return entity == ptr; - }); - return 0; -} - -static const luaL_Reg triggerLib[] = { - {"SetHandle", setHandle}, - {"GetHandle", getHandle}, - - {"SetOrigin",setOrigin}, - {"GetOrigin",getOrigin}, - - {"SetBounds",setBoundingBox}, - {"GetBounds",getBoundingBox}, - - {"SetScript",setReference}, - {"GetScript",getReference}, - - {"PushExclusionEntity", pushExclusionEntity}, - {"RemoveExclusionEntity", removeExclusionEntity}, - - {nullptr, nullptr} -}; - -LUAMOD_API int openTriggerAPI(lua_State* L) { - luaL_newlib(L, triggerLib); - return 1; -} \ No newline at end of file diff --git a/server/triggers/trigger_api.hpp b/server/triggers/trigger_api.hpp deleted file mode 100644 index 12f3e85..0000000 --- a/server/triggers/trigger_api.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "lua.hpp" - -#define TORTUGA_TRIGGER_API "trigger" -LUAMOD_API int openTriggerAPI(lua_State* L); diff --git a/server/triggers/trigger_data.cpp b/server/triggers/trigger_data.cpp deleted file mode 100644 index 32ce359..0000000 --- a/server/triggers/trigger_data.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "trigger_data.hpp" - -std::string TriggerData::SetHandle(std::string s) { - return handle = s; -} - -std::string TriggerData::GetHandle() const { - return handle; -} - -Vector2 TriggerData::SetOrigin(Vector2 v) { - return origin = v; -} - -Vector2 TriggerData::GetOrigin() { - return origin; -} - -BoundingBox TriggerData::SetBoundingBox(BoundingBox b) { - return bounds = b; -} - -BoundingBox TriggerData::GetBoundingBox() { - return bounds; -} - -int TriggerData::SetScriptReference(int i) { - return scriptRef = i; -} - -int TriggerData::GetScriptReference() { - return scriptRef; -} - -std::list* TriggerData::GetExclusionList() { - return &exclusionList; -} \ No newline at end of file diff --git a/server/triggers/trigger_data.hpp b/server/triggers/trigger_data.hpp deleted file mode 100644 index 36e9181..0000000 --- a/server/triggers/trigger_data.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "bounding_box.hpp" -#include "entity.hpp" -#include "vector2.hpp" - -#include "lua.hpp" - -#include -#include - -class TriggerData { -public: - TriggerData() = default; - ~TriggerData() = default; - - std::string SetHandle(std::string); - std::string GetHandle() const; - - Vector2 SetOrigin(Vector2 v); - Vector2 GetOrigin(); - - BoundingBox SetBoundingBox(BoundingBox b); - BoundingBox GetBoundingBox(); - - int SetScriptReference(int i); - int GetScriptReference(); - - std::list* GetExclusionList(); - -private: - std::string handle; - Vector2 origin; - BoundingBox bounds; - int scriptRef = LUA_NOREF; - std::list exclusionList; -}; diff --git a/server/triggers/trigger_manager.cpp b/server/triggers/trigger_manager.cpp deleted file mode 100644 index c6de249..0000000 --- a/server/triggers/trigger_manager.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "trigger_manager.hpp" - -TriggerManager::TriggerManager() { - //EMPTY -} - -TriggerManager::~TriggerManager() { - UnloadAll(); -} - -int TriggerManager::Create(std::string handle) { - //implicitly creates the element - TriggerData& triggerData = elementMap[counter]; - - triggerData.SetHandle(handle); - - return counter++; -} - -void TriggerManager::Unload(int uid) { - elementMap.erase(uid); -} - -void TriggerManager::UnloadAll() { - //TODO: save? - elementMap.clear(); -} - -void TriggerManager::UnloadIf(std::function)> fn) { - std::map::iterator it = elementMap.begin(); - while (it != elementMap.end()) { - if (fn(*it)) { - it = elementMap.erase(it); - } - else { - ++it; - } - } -} - -TriggerData* TriggerManager::Get(int uid) { - std::map::iterator it = elementMap.find(uid); - - if (it == elementMap.end()) { - return nullptr; - } - - return &it->second; -} - -TriggerData* TriggerManager::Get(std::string handle) { - for (std::map::iterator it = elementMap.begin(); it != elementMap.end(); ++it) { - if (it->second.GetHandle() == handle) { - return &it->second; - } - } - return nullptr; -} - -int TriggerManager::GetLoadedCount() { - return elementMap.size(); -} - -std::map* TriggerManager::GetContainer() { - return &elementMap; -} - -//hooks -lua_State* TriggerManager::SetLuaState(lua_State* L) { - return lua = L; -} - -lua_State* TriggerManager::GetLuaState() { - return lua; -} \ No newline at end of file diff --git a/server/triggers/trigger_manager.hpp b/server/triggers/trigger_manager.hpp deleted file mode 100644 index 067f9ec..0000000 --- a/server/triggers/trigger_manager.hpp +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "bounding_box.hpp" -#include "vector2.hpp" -#include "trigger_data.hpp" - -#include "lua.hpp" - -#include -#include -#include - -class TriggerManager { -public: - TriggerManager(); - ~TriggerManager(); - - //common public methods - int Create(std::string handle); - void Unload(int uid); - - void UnloadAll(); - void UnloadIf(std::function)> fn); - - //accessors & mutators - TriggerData* Get(int uid); - TriggerData* Get(std::string handle); - int GetLoadedCount(); - std::map* GetContainer(); - - //hooks - lua_State* SetLuaState(lua_State* L); - lua_State* GetLuaState(); - -private: - //members - std::map elementMap; - lua_State* lua = nullptr; - int counter = 0; -}; diff --git a/server/triggers/trigger_manager_api.cpp b/server/triggers/trigger_manager_api.cpp deleted file mode 100644 index 580ea5e..0000000 --- a/server/triggers/trigger_manager_api.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "trigger_manager_api.hpp" - -#include "trigger_manager.hpp" - -static int create(lua_State* L) { - //DOCS: params: create(triggerMgr, name[, originX, originY[, boundsX, boundsY, boundsW, boundsH]][, script]) - - //get the trigger manager - TriggerManager* mgr = static_cast(lua_touserdata(L, 1)); - - //create the trigger - int index = mgr->Create(lua_tostring(L, 2)); - TriggerData* triggerData = mgr->Get(index); - - //origin - if (lua_gettop(L) >= 4) { - triggerData->SetOrigin({lua_tonumber(L, 3), lua_tonumber(L, 4)}); //vectorX, vectorY - } - - //bounds - if (lua_gettop(L) >= 8) { - triggerData->SetBoundingBox({ - lua_tointeger(L, 5), //boundsX - lua_tointeger(L, 6), //boundsY - lua_tointeger(L, 7), //boundsW - lua_tointeger(L, 8) //boundsH - }); - } - - //if the parameter list isn't capped with a script, append a nil instead - if (lua_type(L, -1) != LUA_TFUNCTION) { - lua_pushnil(L); - } - - //set the script reference (may be nil) - triggerData->SetScriptReference(luaL_ref(L, LUA_REGISTRYINDEX)); - - //push to the scipts - lua_pushlightuserdata(L, static_cast(triggerData)); - lua_pushinteger(L, index); - - return 2; -} - -static int unload(lua_State* L) { - TriggerManager* mgr = static_cast(lua_touserdata(L, 1)); - int count = 0; //the number removed - - //based on the type - switch(lua_type(L, 2)) { - //unload this index - case LUA_TNUMBER: - mgr->UnloadIf([L, &count](std::pair it) -> bool { - if (it.first == lua_tointeger(L, 2)) { - count++; - return true; - } - else { - return false; - } - }); - break; - - //unload this name - case LUA_TSTRING: - mgr->UnloadIf([L, &count](std::pair it) -> bool { - if (it.second.GetHandle() == lua_tostring(L, 2)) { - count++; - return true; - } - else { - return false; - } - }); - break; - } - - //return the number removed - lua_pushinteger(L, count); - return 1; -} - -static int getTrigger(lua_State* L) { - TriggerManager* mgr = static_cast(lua_touserdata(L, 1)); - TriggerData* triggerData = nullptr; - - switch(lua_type(L, 2)) { - case LUA_TNUMBER: - triggerData = mgr->Get(lua_tointeger(L, 2)); - break; - case LUA_TSTRING: - triggerData = mgr->Get(lua_tostring(L, 2)); - break; - } - - if (triggerData) { - lua_pushlightuserdata(L, static_cast(triggerData)); - } - else { - lua_pushnil(L); - } - - return 1; -} - -static int forEach(lua_State* L) { - //TODO: (9) forEach() -} - -static int getLoadedCount(lua_State* L) { - TriggerManager* mgr = static_cast(lua_touserdata(L, 1)); - lua_pushinteger(L, mgr->GetLoadedCount()); - return 1; -} - -static const luaL_Reg triggerManagerLib[] = { - {"Create",create}, - {"Unload",unload}, - {"GetTrigger",getTrigger}, - {"GetCount",getLoadedCount}, - {nullptr, nullptr} -}; - -LUAMOD_API int openTriggerManagerAPI(lua_State* L) { - luaL_newlib(L, triggerManagerLib); - return 1; -} \ No newline at end of file diff --git a/server/triggers/trigger_manager_api.hpp b/server/triggers/trigger_manager_api.hpp deleted file mode 100644 index 2350b60..0000000 --- a/server/triggers/trigger_manager_api.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * 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 "lua.hpp" - -#define TORTUGA_TRIGGER_MANAGER_API "trigger_manager" -LUAMOD_API int openTriggerManagerAPI(lua_State* L); diff --git a/todo.txt b/todo.txt deleted file mode 100644 index 3bbb4dd..0000000 --- a/todo.txt +++ /dev/null @@ -1,26 +0,0 @@ -TODO: upgrade to lua 5.3 -TODO: upgrade to SDL 2.0 -TODO: Split config.cfg in two, one for the server and the client -TODO: Consistency for bounds names - -TODO: Account passwords (list) - * backbone account server OR - * social network login OR - * ... - * salts & hashes - * login screen prompting for username & password - -TODO: Features - * Make sure login errors are sent to the client - * Add the "home" parameter to the server's config file - * Waypoints, with positions and trigger zones (collision areas) for doors, monster spawns, etc. (trigger system) - * Fix shoddy movement - * Remove the big "Shut Down" button (currently broken...) - * Make a way for the server owner to control the server directly - * The TileSheet class should implement the surface itself - * Time delay for requesting region packets - * A proper logging system - * Fix the const-ness of accessors - * Add a screenshot of the game to README.md - * joystick/gamepad support - * add the tilesheet to the map system \ No newline at end of file diff --git a/common/utilities/bounding_box.hpp b/utilities/bounding_box.hpp similarity index 100% rename from common/utilities/bounding_box.hpp rename to utilities/bounding_box.hpp diff --git a/common/utilities/config_utility.cpp b/utilities/config_utility.cpp similarity index 100% rename from common/utilities/config_utility.cpp rename to utilities/config_utility.cpp diff --git a/common/utilities/config_utility.hpp b/utilities/config_utility.hpp similarity index 100% rename from common/utilities/config_utility.hpp rename to utilities/config_utility.hpp diff --git a/common/utilities/frame_rate.hpp b/utilities/frame_rate.hpp similarity index 100% rename from common/utilities/frame_rate.hpp rename to utilities/frame_rate.hpp diff --git a/common/utilities/ip_operators.cpp b/utilities/ip_operators.cpp similarity index 100% rename from common/utilities/ip_operators.cpp rename to utilities/ip_operators.cpp diff --git a/common/utilities/ip_operators.hpp b/utilities/ip_operators.hpp similarity index 100% rename from common/utilities/ip_operators.hpp rename to utilities/ip_operators.hpp diff --git a/common/gameplay/makefile b/utilities/makefile similarity index 86% rename from common/gameplay/makefile rename to utilities/makefile index 104b518..e6bcb85 100644 --- a/common/gameplay/makefile +++ b/utilities/makefile @@ -10,10 +10,6 @@ CXXSRC=$(wildcard *.cpp) OBJDIR=obj OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) -#output -OUTDIR=../.. -OUT=$(addprefix $(OUTDIR)/,libcommon.a) - #targets all: $(OBJ) $(OUT) ar -crs $(OUT) $(OBJ) diff --git a/common/utilities/singleton.hpp b/utilities/singleton.hpp similarity index 100% rename from common/utilities/singleton.hpp rename to utilities/singleton.hpp diff --git a/common/utilities/vector2.hpp b/utilities/vector2.hpp similarity index 100% rename from common/utilities/vector2.hpp rename to utilities/vector2.hpp