Merge branch 'develop'

Conflicts:
	todo.txt
This commit is contained in:
Kayne Ruse
2014-12-27 23:44:54 +11:00
143 changed files with 3155 additions and 1119 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+4 -4
View File
@@ -1,11 +1,11 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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 ClientApplications, and to alter it and redistribute it
* 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
@@ -49,7 +49,7 @@ void ClientApplication::Init(int argc, char* argv[]) {
//load the prerequisites
ConfigUtility& config = ConfigUtility::GetSingleton();
config.Load("rsc/config.cfg", argc, argv);
config.Load("rsc/config.cfg", false, argc, argv);
//-------------------------
//Initialize the APIs
@@ -178,7 +178,7 @@ void ClientApplication::LoadScene(SceneList sceneIndex) {
activeScene = new OptionsMenu();
break;
case SceneList::LOBBYMENU:
activeScene = new LobbyMenu(&clientIndex, &accountIndex); //TODO: can I use the ConfigUtility for these parameters?
activeScene = new LobbyMenu(&clientIndex, &accountIndex);
break;
case SceneList::INWORLD:
activeScene = new InWorld(&clientIndex, &accountIndex);
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -19,12 +19,5 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef SERIALSTATISTICS_HPP_
#define SERIALSTATISTICS_HPP_
#include "terminal_error.hpp"
#include "statistics.hpp"
void serializeStatistics(void** buffer, Statistics* stats);
void deserializeStatistics(void** buffer, Statistics* stats);
#endif
@@ -0,0 +1,34 @@
/* 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.
*/
#ifndef TERMINALERROR_HPP_
#define TERMINALERROR_HPP_
#include <stdexcept>
#include <string>
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) {}
};
#endif
+83
View File
@@ -0,0 +1,83 @@
/* 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.SetYIndex(0);
}
else if (motion.y < 0) {
sprite.SetYIndex(1);
}
else if (motion.x > 0) {
sprite.SetYIndex(3);
}
else if (motion.x < 0) {
sprite.SetYIndex(2);
}
//animation
if (motion != 0) {
sprite.SetDelay(0.1);
}
else {
sprite.SetDelay(0);
sprite.SetXIndex(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(std::string s) {
avatar = s;
sprite.LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + avatar, CHARACTER_CELLS_X, CHARACTER_CELLS_Y);
return avatar;
}
std::string BaseCharacter::GetAvatar() const {
return avatar;
}
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -24,12 +24,12 @@
//components
#include "character_defines.hpp"
#include "renderable.hpp"
#include "entity.hpp"
//std namespace
#include <string>
class BaseCharacter : public Renderable {
class BaseCharacter: public Entity {
public:
BaseCharacter() = default;
virtual ~BaseCharacter() = default;
@@ -38,14 +38,14 @@ public:
void CorrectSprite();
//metadata
int SetOwner(int i) { return owner = i; }
int GetOwner() { return owner; }
std::string SetHandle(std::string s) { return handle = s; }
std::string GetHandle() const { return handle; }
std::string SetAvatar(std::string s) { return avatar = s; }
std::string GetAvatar() const { return avatar; }
int SetOwner(int i);
int GetOwner();
std::string SetHandle(std::string s);
std::string GetHandle() const;
std::string SetAvatar(std::string s);
std::string GetAvatar() const;
private:
protected:
//metadata
int owner;
std::string handle;
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -22,14 +22,14 @@
#ifndef BASEMONSTER_HPP_
#define BASEMONSTER_HPP_
#include "renderable.hpp"
#include "entity.hpp"
class BaseMonster {
class BaseMonster: public Entity {
public:
BaseMonster() = default;
virtual ~BaseMonster() = default;
private:
protected:
//
};
+63
View File
@@ -0,0 +1,63 @@
/* 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_Surface* const dest, int camX, int camY) {
sprite.DrawTo(dest, 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;
}
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -19,37 +19,37 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef RENDERABLE_HPP_
#define RENDERABLE_HPP_
#ifndef ENTITY_HPP_
#define ENTITY_HPP_
#include "bounding_box.hpp"
#include "sprite_sheet.hpp"
#include "vector2.hpp"
class Renderable {
//The base class for all objects in the world
class Entity {
public:
Renderable() = default;
virtual ~Renderable() = default;
virtual void Update();
virtual void DrawTo(SDL_Surface* const, int camX, int camY);
SpriteSheet* GetSprite() { return &sprite; }
SpriteSheet* GetSprite();
//position
Vector2 SetOrigin(Vector2 v) { return origin = v; }
Vector2 GetOrigin() const { return origin; }
Vector2 SetMotion(Vector2 v) { return motion = v; }
Vector2 GetMotion() const { return motion; }
//accessors & mutators
Vector2 SetOrigin(Vector2 v);
Vector2 SetMotion(Vector2 v);
BoundingBox SetBounds(BoundingBox b);
//collision
BoundingBox SetBounds(BoundingBox b) { return bounds = b; }
BoundingBox GetBounds() { return bounds; }
Vector2 GetOrigin();
Vector2 GetMotion();
BoundingBox GetBounds();
protected:
Entity() = default;
virtual ~Entity() = default;
protected: //TODO: should be private
SpriteSheet sprite;
Vector2 origin = {0, 0};
Vector2 motion = {0, 0};
Vector2 origin;
Vector2 motion;
BoundingBox bounds;
};
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -21,3 +21,15 @@
*/
#include "local_character.hpp"
#include <iostream>
bool LocalCharacter::ProcessCollisionGrid(std::list<BoundingBox> boxList) {
for(auto& box : boxList) {
if (box.CheckOverlap(origin + bounds)) {
origin -= motion;
motion = {0, 0};
return true;
}
}
return false;
}
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -23,22 +23,20 @@
#define LOCALCHARACTER_HPP_
#include "base_character.hpp"
#include "statistics.hpp"
#include "bounding_box.hpp"
#include "vector2.hpp"
class LocalCharacter : public BaseCharacter {
#include <list>
class LocalCharacter: public BaseCharacter {
public:
LocalCharacter() = default;
~LocalCharacter() = default;
virtual ~LocalCharacter() = default;
int SetRoomIndex(int i) { return roomIndex = i; }
int GetRoomIndex() { return roomIndex; }
Statistics* GetBaseStats() { return &baseStats; }
bool ProcessCollisionGrid(std::list<BoundingBox>);
private:
int roomIndex = -1;
Statistics baseStats;
//TODO: weapons, armour, buffs, debuffs, etc.
//NOTE: NO MEMBERS
};
#endif
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
@@ -36,7 +36,7 @@ int main(int argc, char* argv[]) {
ConfigUtility::CreateSingleton();
UDPNetworkUtility::CreateSingleton();
//call the server's routines
//call the client's routines
ClientApplication::CreateSingleton();
ClientApplication& app = ClientApplication::GetSingleton();
+2 -2
View File
@@ -1,5 +1,5 @@
#include directories
INCLUDES+=. client_utilities renderable scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet_types ../common/ui ../common/utilities
INCLUDES+=. client_utilities entities scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet_types ../common/ui ../common/utilities
#libraries
#the order of the $(LIBS) is important, at least for MinGW
@@ -26,8 +26,8 @@ OUT=$(addprefix $(OUTDIR)/,client)
#targets
all: $(OBJ) $(OUT)
$(MAKE) -C client_utilities
$(MAKE) -C entities
$(MAKE) -C scenes
$(MAKE) -C renderable
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
$(OBJ): | $(OBJDIR)
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
+491 -275
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
@@ -23,12 +23,25 @@
#include "channels.hpp"
#include "utility.hpp"
#include "config_utility.hpp"
#include "terminal_error.hpp"
#include <stdexcept>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
//-------------------------
//these should've come standard
//-------------------------
bool operator==(IPaddress lhs, IPaddress rhs) {
return lhs.host == rhs.host && lhs.port == rhs.port;
}
bool operator!=(IPaddress lhs, IPaddress rhs) {
return !(lhs == rhs);
}
//-------------------------
//Public access members
@@ -38,8 +51,6 @@ InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex):
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex)
{
ConfigUtility& config = ConfigUtility::GetSingleton();
//setup the utility objects
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
buttonImage.SetClipH(buttonImage.GetClipH()/3);
@@ -62,27 +73,36 @@ InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex):
shutDownButton.SetText("Shut Down");
//load the tilesheet
//TODO: add the tilesheet to the map system?
//TODO: add the tilesheet to the map system
//TODO: Tile size and tile sheet should be loaded elsewhere
tileSheet.Load(config["dir.tilesets"] + "overworld.bmp", 32, 32);
//send this player's character info
//Send the character data
//TODO: login scene, prompt, etc.
CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_NEW;
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);
//request a sync
RequestSynchronize();
//query the world state
memset(&newPacket, 0, MAX_PACKET_SIZE);
newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
network.SendTo(Channels::SERVER, &newPacket);
//set the camera's values
camera.width = GetScreen()->w;
camera.height = GetScreen()->h;
//debug
//
}
InWorld::~InWorld() {
//
//unload the local data
characterMap.clear();
monsterMap.clear();
}
//-------------------------
@@ -94,69 +114,57 @@ void InWorld::FrameStart() {
}
void InWorld::Update() {
//suck in and process all waiting packets
//create and zero the buffer
SerialPacket* packetBuffer = reinterpret_cast<SerialPacket*>(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<char*>(packetBuffer);
//update the characters
//heartbeat system
CheckHeartBeat();
//update all entities
for (auto& it : characterMap) {
it.second.Update();
}
for (auto& it : monsterMap) {
it.second.Update();
}
//check the map
//update the map
UpdateMap();
//skip the rest
//skip the rest without a local character
if (!localCharacter) {
return;
}
//check for collisions with the map
BoundingBox wallBounds = {0, 0, tileSheet.GetTileW(), tileSheet.GetTileH()};
const int xCount = localCharacter->GetBounds().w / wallBounds.w + 1;
const int yCount = localCharacter->GetBounds().h / wallBounds.h + 1;
//get the collidable boxes
std::list<BoundingBox> boxList = GenerateCollisionGrid(localCharacter, tileSheet.GetTileW(), tileSheet.GetTileH());
for (int i = -1; i <= xCount; ++i) {
for (int j = -1; j <= yCount; ++j) {
//set the wall's position
wallBounds.x = wallBounds.w * i + snapToBase((double)wallBounds.w, localCharacter->GetOrigin().x);
wallBounds.y = wallBounds.h * j + snapToBase((double)wallBounds.h, localCharacter->GetOrigin().y);
if (!regionPager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) {
continue;
}
if ((localCharacter->GetOrigin() + localCharacter->GetBounds()).CheckOverlap(wallBounds)) {
localCharacter->SetOrigin(localCharacter->GetOrigin() - (localCharacter->GetMotion()));
localCharacter->SetMotion({0,0});
//process the collisions
if (localCharacter->ProcessCollisionGrid(boxList)) {
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
}
SendLocalCharacterMotion();
}
//update the camera (following the player)
//update the camera
camera.x = localCharacter->GetOrigin().x - camera.marginX;
camera.y = localCharacter->GetOrigin().y - camera.marginY;
//check the connection
if (Clock::now() - lastBeat > std::chrono::seconds(3)) {
if (attemptedBeats > 2) {
RequestDisconnect();
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server";
}
ServerPacket newPacket;
newPacket.type = SerialPacketType::PING;
network.SendTo(Channels::SERVER, &newPacket);
attemptedBeats++;
lastBeat = Clock::now();
}
}
void InWorld::FrameEnd() {
@@ -164,7 +172,7 @@ void InWorld::FrameEnd() {
}
void InWorld::RenderFrame() {
// SDL_FillRect(GetScreen(), 0, 0);
SDL_FillRect(GetScreen(), 0, 0);
Render(GetScreen());
SDL_Flip(GetScreen());
fps.Calculate();
@@ -176,10 +184,13 @@ void InWorld::Render(SDL_Surface* const screen) {
tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y);
}
//draw characters
//draw the entities
for (auto& it : characterMap) {
//BUG: #29 drawing order according to Y origin
//TODO: use a list of renderable objects
//TODO: depth ordering
it.second.DrawTo(screen, camera.x, camera.y);
}
for (auto& it : monsterMap) {
//TODO: depth ordering
it.second.DrawTo(screen, camera.x, camera.y);
}
@@ -194,8 +205,8 @@ void InWorld::Render(SDL_Surface* const screen) {
//-------------------------
void InWorld::QuitEvent() {
//exit the game AND the server
RequestDisconnect();
//two-step logout
SendDisconnectRequest();
SetNextScene(SceneList::QUIT);
}
@@ -211,110 +222,167 @@ void InWorld::MouseButtonDown(SDL_MouseButtonEvent const& button) {
void InWorld::MouseButtonUp(SDL_MouseButtonEvent const& button) {
if (disconnectButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) {
RequestDisconnect();
SendLogoutRequest();
}
if (shutDownButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) {
RequestShutDown();
SendShutdownRequest();
}
}
void InWorld::KeyDown(SDL_KeyboardEvent const& key) {
if (!localCharacter) {
return;
}
//hotkeys
switch(key.keysym.sym) {
case SDLK_ESCAPE:
RequestDisconnect();
break;
}
//player movement
Vector2 motion = localCharacter->GetMotion();
switch(key.keysym.sym) {
case SDLK_LEFT:
motion.x -= CHARACTER_WALKING_SPEED;
break;
case SDLK_RIGHT:
motion.x += CHARACTER_WALKING_SPEED;
break;
case SDLK_UP:
motion.y -= CHARACTER_WALKING_SPEED;
break;
case SDLK_DOWN:
motion.y += CHARACTER_WALKING_SPEED;
break;
default:
//TODO: the escape key should actually control menus and stuff
SendLogoutRequest();
return;
}
localCharacter->SetMotion(motion);
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
//character movement
if (!localCharacter) {
return;
}
//player movement
Vector2 motion = localCharacter->GetMotion();
switch(key.keysym.sym) {
//NOTE: The use of min/max here are to prevent awkward movements
case SDLK_LEFT:
motion.x = std::min(motion.x + CHARACTER_WALKING_SPEED, 0.0);
case SDLK_w:
motion.y -= CHARACTER_WALKING_SPEED;
break;
case SDLK_RIGHT:
motion.x = std::max(motion.x - CHARACTER_WALKING_SPEED, 0.0);
case SDLK_a:
motion.x -= CHARACTER_WALKING_SPEED;
break;
case SDLK_UP:
motion.y = std::min(motion.y + CHARACTER_WALKING_SPEED, 0.0);
case SDLK_s:
motion.y += CHARACTER_WALKING_SPEED;
break;
case SDLK_DOWN:
motion.y = std::max(motion.y - CHARACTER_WALKING_SPEED, 0.0);
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();
SendPlayerUpdate();
SendLocalCharacterMotion();
}
void InWorld::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();
SendLocalCharacterMotion();
}
//-------------------------
//Network handlers
//Basic connections
//-------------------------
void InWorld::HandlePacket(SerialPacket* const argPacket) {
switch(argPacket->type) {
//heartbeat system
case SerialPacketType::PING:
HandlePing(static_cast<ServerPacket*>(argPacket));
break;
case SerialPacketType::PONG:
HandlePong(static_cast<ServerPacket*>(argPacket));
break;
case SerialPacketType::DISCONNECT:
HandleDisconnect(static_cast<ClientPacket*>(argPacket));
//game server connections
case SerialPacketType::LOGOUT_RESPONSE:
HandleLogoutResponse(static_cast<ClientPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_NEW:
HandleCharacterNew(static_cast<CharacterPacket*>(argPacket));
case SerialPacketType::DISCONNECT_RESPONSE:
HandleDisconnectResponse(static_cast<ClientPacket*>(argPacket));
break;
case SerialPacketType::DISCONNECT_FORCED:
HandleDisconnectForced(static_cast<ClientPacket*>(argPacket));
break;
//map management
case SerialPacketType::REGION_CONTENT:
HandleRegionContent(static_cast<RegionPacket*>(argPacket));
break;
//character management
case SerialPacketType::CHARACTER_CREATE:
HandleCharacterCreate(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_DELETE:
HandleCharacterDelete(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_UPDATE:
HandleCharacterUpdate(static_cast<CharacterPacket*>(argPacket));
case SerialPacketType::QUERY_CHARACTER_EXISTS:
HandleCharacterQueryExists(static_cast<CharacterPacket*>(argPacket));
break;
//character movement
case SerialPacketType::CHARACTER_SET_ROOM:
HandleCharacterSetRoom(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_SET_ORIGIN:
HandleCharacterSetOrigin(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_SET_MOTION:
HandleCharacterSetMotion(static_cast<CharacterPacket*>(argPacket));
break;
//rejection messages
case SerialPacketType::REGION_REJECTION:
case SerialPacketType::CHARACTER_REJECTION:
HandleCharacterRejection(static_cast<TextPacket*>(argPacket));
throw(terminal_error(static_cast<TextPacket*>(argPacket)->text));
break;
case SerialPacketType::REGION_CONTENT:
HandleRegionContent(static_cast<RegionPacket*>(argPacket));
case SerialPacketType::SHUTDOWN_REJECTION:
throw(std::runtime_error(static_cast<TextPacket*>(argPacket)->text));
break;
//handle errors
default:
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in InWorld: " + to_string_custom(static_cast<int>(argPacket->type)) ));
//errors
default: {
std::ostringstream msg;
msg << "Unknown SerialPacketType encountered in InWorld: " << static_cast<int>(argPacket->type);
throw(std::runtime_error(msg.str()));
}
break;
}
}
@@ -326,97 +394,109 @@ void InWorld::HandlePing(ServerPacket* const argPacket) {
}
void InWorld::HandlePong(ServerPacket* const argPacket) {
if (network.GetIPAddress(Channels::SERVER)->host != argPacket->srcAddress.host) {
if (*network.GetIPAddress(Channels::SERVER) != argPacket->srcAddress) {
throw(std::runtime_error("Heartbeat message received from an unknown source"));
}
attemptedBeats = 0;
lastBeat = Clock::now();
}
void InWorld::HandleDisconnect(ClientPacket* const argPacket) {
//TODO: More needed in the disconnection
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been disconnected";
//-------------------------
//Connection control
//-------------------------
void InWorld::SendLogoutRequest() {
ClientPacket newPacket;
//send a logout request
newPacket.type = SerialPacketType::LOGOUT_REQUEST;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
if (characterMap.find(argPacket->characterIndex) != characterMap.end()) {
throw(std::runtime_error("Cannot create duplicate characters"));
}
void InWorld::SendDisconnectRequest() {
ClientPacket newPacket;
//create the character object
BaseCharacter& newCharacter = characterMap[argPacket->characterIndex];
//send a disconnect request
newPacket.type = SerialPacketType::DISCONNECT_REQUEST;
newPacket.clientIndex = clientIndex;
//fill out the character's members
newCharacter.SetHandle(argPacket->handle);
newCharacter.SetAvatar(argPacket->avatar);
newCharacter.GetSprite()->LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + newCharacter.GetAvatar(), 4, 4);
newCharacter.SetOrigin(argPacket->origin);
newCharacter.SetMotion(argPacket->motion);
newCharacter.SetBounds({
CHARACTER_BOUNDS_X,
CHARACTER_BOUNDS_Y,
CHARACTER_BOUNDS_WIDTH,
CHARACTER_BOUNDS_HEIGHT
});
// (*newCharacter.GetBaseStats()) = argPacket->stats;
//bookkeeping code
newCharacter.CorrectSprite();
//catch this client's player object
if (argPacket->accountIndex == accountIndex && !localCharacter) {
characterIndex = argPacket->characterIndex;
localCharacter = &newCharacter;
//setup the camera
camera.width = GetScreen()->w;
camera.height = GetScreen()->h;
//center on the player's character
camera.marginX = (GetScreen()->w / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2);
camera.marginY = (GetScreen()->h / 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2);
}
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
//TODO: authenticate when own character is being deleted (linked to a TODO in the server)
void InWorld::SendShutdownRequest() {
ClientPacket newPacket;
//catch this client's player object
if (argPacket->characterIndex == characterIndex) {
characterIndex = -1;
//send a shutdown request
newPacket.type = SerialPacketType::SHUTDOWN_REQUEST;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::HandleLogoutResponse(ClientPacket* const argPacket) {
if (localCharacter) {
characterMap.erase(characterIndex);
localCharacter = nullptr;
}
characterMap.erase(argPacket->characterIndex);
accountIndex = -1;
characterIndex = -1;
//reset the camera
camera.marginX = camera.marginY = 0;
//because, why not? I guess...
SendDisconnectRequest();
}
void InWorld::HandleCharacterUpdate(CharacterPacket* const argPacket) {
if (characterMap.find(argPacket->characterIndex) == characterMap.end()) {
HandleCharacterNew(argPacket);
return;
}
BaseCharacter& character = characterMap[argPacket->characterIndex];
//other characters moving
if (argPacket->characterIndex != characterIndex) {
character.SetOrigin(argPacket->origin);
character.SetMotion(argPacket->motion);
character.CorrectSprite();
}
}
void InWorld::HandleCharacterRejection(TextPacket* const argPacket) {
RequestDisconnect();
void InWorld::HandleDisconnectResponse(ClientPacket* const argPacket) {
HandleLogoutResponse(argPacket);//shortcut
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility& config = ConfigUtility::GetSingleton();
config["client.disconnectMessage"] = "Error: ";
config["client.disconnectMessage"] += argPacket->text;
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have successfully logged out";
}
void InWorld::HandleDisconnectForced(ClientPacket* const argPacket) {
HandleDisconnectResponse(argPacket);//shortcut
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server";
}
void InWorld::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();
}
}
}
//-------------------------
//map management
//-------------------------
void InWorld::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 InWorld::HandleRegionContent(RegionPacket* const argPacket) {
@@ -429,82 +509,11 @@ void InWorld::HandleRegionContent(RegionPacket* const argPacket) {
argPacket->region = nullptr;
}
//-------------------------
//Server control
//-------------------------
void InWorld::RequestSynchronize() {
ClientPacket newPacket;
//request a sync
newPacket.type = SerialPacketType::SYNCHRONIZE;
newPacket.clientIndex = clientIndex;
newPacket.accountIndex = accountIndex;
//TODO: location, range for sync request
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::SendPlayerUpdate() {
CharacterPacket newPacket;
//pack the packet
newPacket.type = SerialPacketType::CHARACTER_UPDATE;
newPacket.characterIndex = characterIndex;
//NOTE: omitting the handle and avatar here
newPacket.accountIndex = accountIndex;
newPacket.roomIndex = 0; //TODO: room index
newPacket.origin = localCharacter->GetOrigin();
newPacket.motion = localCharacter->GetMotion();
// newPacket.stats = *localCharacter->GetBaseStats();
//TODO: gameplay components: equipment, items, buffs, debuffs
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::RequestDisconnect() {
ClientPacket newPacket;
//send a disconnect request
newPacket.type = SerialPacketType::DISCONNECT;
newPacket.clientIndex = clientIndex;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::RequestShutDown() {
ClientPacket newPacket;
//send a shutdown request
newPacket.type = SerialPacketType::SHUTDOWN;
newPacket.clientIndex = clientIndex;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::RequestRegion(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);
}
//-------------------------
//Utilities
//-------------------------
//TODO: convert this into a more generic function?; using parameters for the bounds
void InWorld::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;
@@ -513,27 +522,234 @@ void InWorld::UpdateMap() {
int yEnd = snapToBase(REGION_HEIGHT, (camera.y+camera.height)/tileSheet.GetTileH()) + REGION_HEIGHT;
//prune distant regions
for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); /* EMPTY */) {
//check if the region is outside of this area
if (it->GetX() < xStart || it->GetX() > xEnd || it->GetY() < yStart || it->GetY() > yEnd) {
//clunky, but the alternative was time consuming
int tmpX = it->GetX();
int tmpY = it->GetY();
++it;
regionPager.UnloadRegion(tmpX, tmpY);
continue;
}
++it;
}
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) {
if (!regionPager.FindRegion(i, j)) {
RequestRegion(0, i, j);
SendRegionRequest(roomIndex, i, j);
}
}
}
}
//-------------------------
//entity management
//-------------------------
//NOTE: preexisting characters will result in query responses
//NOTE: new characters will result in create messages
//NOTE: this client's character will exist in both (skipped)
void InWorld::HandleCharacterCreate(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->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();
//check for this player's character
if (character->GetOwner() == accountIndex) {
localCharacter = static_cast<LocalCharacter*>(character);
//focus the camera on this character
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;
}
//debug
std::cout << "Create, total: " << characterMap.size() << std::endl;
}
void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
//ignore if this character doesn't exist
std::map<int, BaseCharacter>::iterator characterIt = characterMap.find(argPacket->characterIndex);
if (characterIt == characterMap.end()) {
//debug
std::cout << "Ignoring character deletion" << std::endl;
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;
}
//remove this character
characterMap.erase(characterIt);
//debug
std::cout << "Delete, total: " << characterMap.size() << std::endl;
}
void InWorld::HandleCharacterQueryExists(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 << "Query, total: " << characterMap.size() << std::endl;
}
void InWorld::HandleCharacterSetRoom(CharacterPacket* const argPacket) {
//someone else's character
if (argPacket->characterIndex != characterIndex) {
characterMap.erase(argPacket->characterIndex);
return;
}
//this character is moving between rooms
roomIndex = argPacket->roomIndex;
//set the character's info
localCharacter->SetOrigin(argPacket->origin);
localCharacter->SetMotion(argPacket->motion);
localCharacter->CorrectSprite();
//clear the old room's data
regionPager.UnloadAll();
monsterMap.clear();
//use the jenky pattern for std::map to skip this player's character
for (std::map<int, BaseCharacter>::iterator it = characterMap.begin(); it != characterMap.end(); /* EMPTY */ ) {
if (it->first != characterIndex) {
it = characterMap.erase(it);
}
else {
++it;
}
}
//request the info on characters in this room
CharacterPacket newPacket;
newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
newPacket.roomIndex = roomIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::HandleCharacterSetOrigin(CharacterPacket* const argPacket) {
//TODO: Authentication
if (argPacket->characterIndex == characterIndex) {
return;
}
//check that this character exists
std::map<int, BaseCharacter>::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 InWorld::HandleCharacterSetMotion(CharacterPacket* const argPacket) {
//TODO: Authentication
if (argPacket->characterIndex == characterIndex) {
return;
}
//check that this character exists
std::map<int, BaseCharacter>::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();
}
}
//-------------------------
//player movement
//-------------------------
//TODO: add a "movement" packet type
void InWorld::SendLocalCharacterMotion() {
CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_SET_MOTION;
newPacket.accountIndex = accountIndex;
newPacket.characterIndex = characterIndex;
newPacket.roomIndex = roomIndex;
newPacket.origin = localCharacter->GetOrigin();
newPacket.motion = localCharacter->GetMotion();
network.SendTo(Channels::SERVER, &newPacket);
}
std::list<BoundingBox> InWorld::GenerateCollisionGrid(Entity* ptr, int tileWidth, int tileHeight) {
//prepare for collisions
BoundingBox wallBounds = {0, 0, tileWidth, tileHeight};
std::list<BoundingBox> 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);
}
+39 -26
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
@@ -25,9 +25,10 @@
//maps
#include "region_pager_base.hpp"
//networking
//utilities
#include "udp_network_utility.hpp"
#include "serial_packet.hpp"
#include "config_utility.hpp"
//graphics
#include "image.hpp"
@@ -38,12 +39,10 @@
//common
#include "frame_rate.hpp"
#include "base_character.hpp"
#include "base_monster.hpp"
#include "local_character.hpp"
//client
#include "base_scene.hpp"
#include "base_monster.hpp"
#include "local_character.hpp"
//STL
#include <map>
@@ -72,34 +71,44 @@ protected:
void KeyDown(SDL_KeyboardEvent const&);
void KeyUp(SDL_KeyboardEvent const&);
//Network handlers
//Basic connections
void HandlePacket(SerialPacket* const);
void HandlePing(ServerPacket* const);
void HandlePong(ServerPacket* const);
void HandleDisconnect(ClientPacket* const);
void HandleCharacterNew(CharacterPacket* const);
void HandleCharacterDelete(CharacterPacket* const);
void HandleCharacterUpdate(CharacterPacket* const);
void HandleCharacterRejection(TextPacket* const);
//Connection control
void SendLogoutRequest();
void SendDisconnectRequest();
void SendShutdownRequest();
void HandleLogoutResponse(ClientPacket* const);
void HandleDisconnectResponse(ClientPacket* const);
void HandleDisconnectForced(ClientPacket* const);
void CheckHeartBeat();
//map management
void SendRegionRequest(int roomIndex, int x, int y);
void HandleRegionContent(RegionPacket* const);
//Server control
void RequestSynchronize();
void SendPlayerUpdate();
void RequestDisconnect();
void RequestShutDown();
void RequestRegion(int roomIndex, int x, int y);
//utilities
void UpdateMap();
//singleton shortcut
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
//character management
void HandleCharacterCreate(CharacterPacket* const);
void HandleCharacterDelete(CharacterPacket* const);
void HandleCharacterQueryExists(CharacterPacket* const);
void HandleCharacterSetRoom(CharacterPacket* const);
void HandleCharacterSetOrigin(CharacterPacket* const);
void HandleCharacterSetMotion(CharacterPacket* const);
//player movement
void SendLocalCharacterMotion();
std::list<BoundingBox> GenerateCollisionGrid(Entity*, int tileWidth, int tileHeight);
//indexes
int& clientIndex;
int& accountIndex;
int characterIndex = -1;
int roomIndex = -1;
//graphics
Image buttonImage;
@@ -121,16 +130,20 @@ protected:
int marginX = 0, marginY = 0;
} camera;
//game components
BaseCharacter* localCharacter = nullptr;
//entities
std::map<int, BaseCharacter> characterMap;
std::map<int, BaseMonster> monsterMap;
LocalCharacter* localCharacter = nullptr;
//heartbeat
//TODO: This needs it's own utility, for both InWorld and InCombat
//TODO: 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();
};
#endif
+36 -3
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
@@ -190,15 +190,25 @@ void LobbyMenu::KeyUp(SDL_KeyboardEvent const& key) {
void LobbyMenu::HandlePacket(SerialPacket* const argPacket) {
switch(argPacket->type) {
//responses
case SerialPacketType::BROADCAST_RESPONSE:
HandleBroadcastResponse(static_cast<ServerPacket*>(argPacket));
break;
case SerialPacketType::JOIN_RESPONSE:
HandleJoinResponse(static_cast<ClientPacket*>(argPacket));
break;
case SerialPacketType::LOGIN_RESPONSE:
HandleLoginResponse(static_cast<ClientPacket*>(argPacket));
break;
//rejections
case SerialPacketType::JOIN_REJECTION:
HandleJoinRejection(static_cast<TextPacket*>(argPacket));
break;
case SerialPacketType::LOGIN_REJECTION:
HandleLoginRejection(static_cast<TextPacket*>(argPacket));
break;
//handle errors
default:
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in LobbyMenu: " + to_string_custom(static_cast<int>(argPacket->type)) ));
@@ -222,9 +232,19 @@ void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) {
}
void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) {
//save the server's data
clientIndex = argPacket->clientIndex;
accountIndex = argPacket->accountIndex;
network.Bind(argPacket->srcAddress, Channels::SERVER);
//request login data
SendLoginRequest();
}
void LobbyMenu::HandleLoginResponse(ClientPacket* const argPacket) {
if (argPacket->clientIndex != clientIndex) {
throw(std::runtime_error("Client index invalid during login"));
}
accountIndex = argPacket->accountIndex;
SetNextScene(SceneList::INWORLD);
}
@@ -232,6 +252,10 @@ void LobbyMenu::HandleJoinRejection(TextPacket* const argPacket) {
//TODO: Better output for join rejection
}
void LobbyMenu::HandleLoginRejection(TextPacket* const argPacket) {
//TODO: Better output for login rejection
}
//-------------------------
//server control
//-------------------------
@@ -251,9 +275,18 @@ void LobbyMenu::SendJoinRequest() {
//pack the packet
ClientPacket packet;
packet.type = SerialPacketType::JOIN_REQUEST;
strncpy(packet.username, config["client.username"].c_str(), PACKET_STRING_SIZE);
//join the selected server
network.SendTo(selection->address, &packet);
selection = nullptr;
}
void LobbyMenu::SendLoginRequest() {
//NOTE: high cohesion
ClientPacket packet;
packet.type = SerialPacketType::LOGIN_REQUEST;
packet.clientIndex = clientIndex;
strncpy(packet.username, config["client.username"].c_str(), PACKET_STRING_SIZE);
network.SendTo(Channels::SERVER, &packet);
}
+4 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
@@ -63,11 +63,14 @@ protected:
void HandlePacket(SerialPacket* const);
void HandleBroadcastResponse(ServerPacket* const);
void HandleJoinResponse(ClientPacket* const);
void HandleLoginResponse(ClientPacket* const);
void HandleJoinRejection(TextPacket* const);
void HandleLoginRejection(TextPacket* const);
//server control
void SendBroadcastRequest();
void SendJoinRequest();
void SendLoginRequest();
//shared parameters
ConfigUtility& config = ConfigUtility::GetSingleton();
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,5 +1,5 @@
#config
INCLUDES+=. .. ../renderable ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities
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))
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -39,7 +39,7 @@ void Timer::Stop() {
std::ostream& operator<<(std::ostream& os, Timer& t) {
os << t.GetName() << ": ";
os << std::chrono::duration_cast<std::chrono::milliseconds>(t.GetTime()).count();
os << "ms";
os << std::chrono::duration_cast<std::chrono::microseconds>(t.GetTime()).count();
os << "us";
return os;
}
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -34,8 +34,8 @@ public:
Timer(std::string s);
~Timer() = default;
inline void Start();
inline void Stop();
void Start();
void Stop();
//accessors and mutators
Clock::duration GetTime() { return timeSpan; }
+5 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -35,4 +35,8 @@ constexpr int CHARACTER_BOUNDS_Y = 16;
constexpr int CHARACTER_BOUNDS_WIDTH = 32;
constexpr int CHARACTER_BOUNDS_HEIGHT = 32;
//the character's sprite format
constexpr int CHARACTER_CELLS_X = 4;
constexpr int CHARACTER_CELLS_Y = 4;
#endif
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+77
View File
@@ -0,0 +1,77 @@
/* 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 "map_system_api.hpp"
//all map API headers
#include "region_api.hpp"
#include "region_pager_api.hpp"
#include "tile_sheet_api.hpp"
//macros
#include "region.hpp"
//useful "globals"
static int getRegionWidth(lua_State* L) {
lua_pushinteger(L, REGION_WIDTH);
return 1;
}
static int getRegionHeight(lua_State* L) {
lua_pushinteger(L, REGION_HEIGHT);
return 1;
}
static int getRegionDepth(lua_State* L) {
lua_pushinteger(L, REGION_DEPTH);
return 1;
}
//This mimics linit.c to create a nested collection of all map modules.
static const luaL_Reg funcs[] = {
//synonyms
{"GetRegionWidth", getRegionWidth},
{"GetRegionHeight", getRegionHeight},
{"GetRegionDepth", getRegionDepth},
{nullptr, nullptr}
};
static const luaL_Reg libs[] = {
{"Region", openRegionAPI},
{"RegionPager", openRegionPagerAPI},
// {"TileSheet", openTileSheetAPI},
{nullptr, nullptr}
};
int openMapSystemAPI(lua_State* L) {
//create the table
luaL_newlibtable(L, libs);
//push the "global" functions
luaL_setfuncs(L, funcs, 0);
//push the substable
for (const luaL_Reg* lib = libs; lib->func; lib++) {
lib->func(L);
lua_setfield(L, -2, lib->name);
}
return 1;
}
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -19,13 +19,16 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "renderable.hpp"
#ifndef MAPSYSTEMAPI_HPP_
#define MAPSYSTEMAPI_APP_
void Renderable::Update() {
origin += motion;
sprite.Update(0.016);
}
#if defined(__MINGW32__)
#include "lua/lua.hpp"
#else
#include "lua.hpp"
#endif
void Renderable::DrawTo(SDL_Surface* const dest, int camX, int camY) {
sprite.DrawTo(dest, origin.x - camX, origin.y - camY);
}
#define TORTUGA_MAP_SYSTEM_API "map_system"
LUAMOD_API int openMapSystemAPI(lua_State* L);
#endif
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -28,7 +28,7 @@
#include "lua.hpp"
#endif
#define TORTUGA_REGION_NAME "Region"
#define TORTUGA_REGION_NAME "region"
LUAMOD_API int openRegionAPI(lua_State* L);
#endif
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -28,7 +28,7 @@
#include "lua.hpp"
#endif
#define TORTUGA_REGION_PAGER_NAME "RegionPager"
#define TORTUGA_REGION_PAGER_NAME "region_pager"
LUAMOD_API int openRegionPagerAPI(lua_State* L);
#endif
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
+15 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -23,6 +23,17 @@
#include <stdexcept>
RegionPagerLua::~RegionPagerLua() {
//unload all regions
UnloadAll();
//clear any stored functions
luaL_unref(lua, LUA_REGISTRYINDEX, loadRef);
luaL_unref(lua, LUA_REGISTRYINDEX, saveRef);
luaL_unref(lua, LUA_REGISTRYINDEX, createRef);
luaL_unref(lua, LUA_REGISTRYINDEX, unloadRef);
}
//return the loaded region, or nullptr on failure
Region* RegionPagerLua::LoadRegion(int x, int y) {
//get the pager's function from the registry
lua_rawgeti(lua, LUA_REGISTRYINDEX, loadRef);
@@ -54,6 +65,7 @@ Region* RegionPagerLua::LoadRegion(int x, int y) {
}
}
//return the saved region, or nullptr on failure
Region* RegionPagerLua::SaveRegion(int x, int y) {
//get the pager's function from the registry
lua_rawgeti(lua, LUA_REGISTRYINDEX, saveRef);
@@ -88,6 +100,7 @@ Region* RegionPagerLua::SaveRegion(int x, int y) {
}
}
//return the created region, or nullptr on failure
Region* RegionPagerLua::CreateRegion(int x, int y) {
if (FindRegion(x, y)) {
throw(std::logic_error("Cannot overwrite an existing region"));
@@ -116,6 +129,7 @@ Region* RegionPagerLua::CreateRegion(int x, int y) {
return &regionList.front();
}
//no return
void RegionPagerLua::UnloadRegion(int x, int y) {
//get the pager's function from the registry
lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef);
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -35,7 +35,7 @@
class RegionPagerLua : public RegionPagerBase {
public:
RegionPagerLua() = default;
~RegionPagerLua() = default;
~RegionPagerLua();
//region manipulation
Region* LoadRegion(int x, int y) override;
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
+2 -3
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -28,8 +28,7 @@
#include "lua.hpp"
#endif
#define TORTUGA_TILE_SHEET_NAME "TileSheet"
#define TORTUGA_TILE_SHEET_NAME "tile_sheet"
LUAMOD_API int openTileSheetAPI(lua_State* L);
#endif
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -23,8 +23,6 @@
#include "serial_utility.hpp"
#include "serial_statistics.hpp"
void serializeCharacter(void* buffer, CharacterPacket* packet) {
serialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
@@ -43,9 +41,6 @@ void serializeCharacter(void* buffer, CharacterPacket* packet) {
serialCopy(&buffer, &packet->motion.x, sizeof(double));
serialCopy(&buffer, &packet->motion.y, sizeof(double));
//stats structure
serializeStatistics(&buffer, &packet->stats);
//gameplay components: equipment, items, buffs, debuffs...
}
@@ -67,8 +62,5 @@ void deserializeCharacter(void* buffer, CharacterPacket* packet) {
deserialCopy(&buffer, &packet->motion.x, sizeof(double));
deserialCopy(&buffer, &packet->motion.y, sizeof(double));
//stats structure
deserializeStatistics(&buffer, &packet->stats);
//gameplay components: equipment, items, buffs, debuffs...
}
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
@@ -25,7 +25,6 @@
#include "serial_packet_base.hpp"
#include "vector2.hpp"
#include "statistics.hpp"
struct CharacterPacket : SerialPacketBase {
//identify the character
@@ -35,15 +34,13 @@ struct CharacterPacket : SerialPacketBase {
//the owner
int accountIndex;
//TODO: Authentication token?
//location
int roomIndex;
Vector2 origin;
Vector2 motion;
//gameplay
Statistics stats;
//gameplay components: equipment, items, buffs, debuffs...
};
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
@@ -1,64 +0,0 @@
/* Copyright: (c) Kayne Ruse 2014
*
* 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 "serial_statistics.hpp"
#include "serial_utility.hpp"
void serializeStatistics(void** buffer, Statistics* stats) {
//integers
serialCopy(buffer, &stats->level, sizeof(int));
serialCopy(buffer, &stats->exp, sizeof(int));
serialCopy(buffer, &stats->maxHP, sizeof(int));
serialCopy(buffer, &stats->health, sizeof(int));
serialCopy(buffer, &stats->maxMP, sizeof(int));
serialCopy(buffer, &stats->mana, sizeof(int));
serialCopy(buffer, &stats->attack, sizeof(int));
serialCopy(buffer, &stats->defence, sizeof(int));
serialCopy(buffer, &stats->intelligence, sizeof(int));
serialCopy(buffer, &stats->resistance, sizeof(int));
serialCopy(buffer, &stats->speed, sizeof(int));
//floats
serialCopy(buffer, &stats->accuracy, sizeof(float));
serialCopy(buffer, &stats->evasion, sizeof(float));
serialCopy(buffer, &stats->luck, sizeof(float));
}
void deserializeStatistics(void** buffer, Statistics* stats) {
//integers
deserialCopy(buffer, &stats->level, sizeof(int));
deserialCopy(buffer, &stats->exp, sizeof(int));
deserialCopy(buffer, &stats->maxHP, sizeof(int));
deserialCopy(buffer, &stats->health, sizeof(int));
deserialCopy(buffer, &stats->maxMP, sizeof(int));
deserialCopy(buffer, &stats->mana, sizeof(int));
deserialCopy(buffer, &stats->attack, sizeof(int));
deserialCopy(buffer, &stats->defence, sizeof(int));
deserialCopy(buffer, &stats->intelligence, sizeof(int));
deserialCopy(buffer, &stats->resistance, sizeof(int));
deserialCopy(buffer, &stats->speed, sizeof(int));
//floats
deserialCopy(buffer, &stats->accuracy, sizeof(float));
deserialCopy(buffer, &stats->evasion, sizeof(float));
deserialCopy(buffer, &stats->luck, sizeof(float));
}
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
@@ -33,7 +33,7 @@
typedef SerialPacketBase SerialPacket;
//DOCS: NETWORK_VERSION is used to discern compatible servers and clients
constexpr int NETWORK_VERSION = 20140909;
constexpr int NETWORK_VERSION = 20141227;
union MaxPacket {
CharacterPacket a;
+50 -29
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
@@ -27,6 +27,7 @@
* valid data, but it will still be carried in that packet's format.
*/
//TODO: This needs to be smoothed out
enum class SerialPacketType {
//default: there is something wrong
NONE = 0,
@@ -37,30 +38,37 @@ enum class SerialPacketType {
//-------------------------
//heartbeat
PING,
PONG,
PING = 1,
PONG = 2,
//Used for finding available servers
BROADCAST_REQUEST,
BROADCAST_RESPONSE,
BROADCAST_REQUEST = 3,
BROADCAST_RESPONSE = 4,
//-------------------------
//ClientPacket
// client index, account index, character index
// client index, account index, username
//-------------------------
//Connecting to a server as a client
JOIN_REQUEST,
JOIN_RESPONSE,
//client requests all information from the server
SYNCHRONIZE,
JOIN_REQUEST = 5,
JOIN_RESPONSE = 6,
//disconnect from the server
DISCONNECT,
DISCONNECT_REQUEST = 7,
DISCONNECT_RESPONSE = 8,
DISCONNECT_FORCED = 9,
//load the account
LOGIN_REQUEST = 10,
LOGIN_RESPONSE = 11,
//unload the account
LOGOUT_REQUEST = 12,
LOGOUT_RESPONSE = 13,
//shut down the server
SHUTDOWN,
SHUTDOWN_REQUEST = 14,
//-------------------------
//RegionPacket
@@ -68,24 +76,35 @@ enum class SerialPacketType {
//-------------------------
//map data
REGION_REQUEST,
REGION_CONTENT,
REGION_REQUEST = 15, //NOTE: technically a query
REGION_CONTENT = 16,
//-------------------------
//CharacterPacket
// handle, avatar, character index, account index,
// room index, origin, motion
// character index,
// handle, avatar,
// account index (owner),
// room index, origin, motion,
// statistics
//-------------------------
//controlling characters
CHARACTER_NEW,
CHARACTER_DELETE,
CHARACTER_UPDATE,
//character management
CHARACTER_CREATE = 17,
CHARACTER_DELETE = 18,
CHARACTER_LOAD = 19,
CHARACTER_UNLOAD = 20,
//authentication, character index => character stats
CHARACTER_STATS_REQUEST,
CHARACTER_STATS_RESPONSE,
//find out info from the server
QUERY_CHARACTER_EXISTS = 21,
QUERY_CHARACTER_STATS = 22,
QUERY_CHARACTER_LOCATION = 23,
//set the info in the server
CHARACTER_SET_ROOM = 24,
CHARACTER_SET_ORIGIN = 25,
CHARACTER_SET_MOTION = 26,
//TODO: enemy management
//-------------------------
//TextPacket
@@ -93,18 +112,20 @@ enum class SerialPacketType {
//-------------------------
//general speech
TEXT_BROADCAST,
TEXT_BROADCAST = 27,
//rejection/error messages
SHUTDOWN_REJECTION,
JOIN_REJECTION,
CHARACTER_REJECTION,
JOIN_REJECTION = 28,
LOGIN_REJECTION = 29,
REGION_REJECTION = 30,
CHARACTER_REJECTION = 31,
SHUTDOWN_REJECTION = 32,
//-------------------------
//not used
//-------------------------
LAST
LAST = 33
};
#endif
+41 -17
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -54,26 +54,38 @@ void serializePacket(void* buffer, SerialPacketBase* packet) {
break;
case SerialPacketType::JOIN_REQUEST:
case SerialPacketType::JOIN_RESPONSE:
case SerialPacketType::SYNCHRONIZE:
case SerialPacketType::DISCONNECT:
case SerialPacketType::SHUTDOWN:
case SerialPacketType::DISCONNECT_REQUEST:
case SerialPacketType::DISCONNECT_RESPONSE:
case SerialPacketType::DISCONNECT_FORCED:
case SerialPacketType::LOGIN_REQUEST:
case SerialPacketType::LOGIN_RESPONSE:
case SerialPacketType::LOGOUT_REQUEST:
case SerialPacketType::LOGOUT_RESPONSE:
case SerialPacketType::SHUTDOWN_REQUEST:
serializeClient(buffer, static_cast<ClientPacket*>(packet));
break;
case SerialPacketType::REGION_REQUEST:
case SerialPacketType::REGION_CONTENT:
serializeRegion(buffer, static_cast<RegionPacket*>(packet));
break;
case SerialPacketType::CHARACTER_NEW:
case SerialPacketType::CHARACTER_CREATE:
case SerialPacketType::CHARACTER_DELETE:
case SerialPacketType::CHARACTER_UPDATE:
case SerialPacketType::CHARACTER_STATS_REQUEST:
case SerialPacketType::CHARACTER_STATS_RESPONSE:
case SerialPacketType::CHARACTER_LOAD:
case SerialPacketType::CHARACTER_UNLOAD:
case SerialPacketType::QUERY_CHARACTER_EXISTS:
case SerialPacketType::QUERY_CHARACTER_STATS:
case SerialPacketType::QUERY_CHARACTER_LOCATION:
case SerialPacketType::CHARACTER_SET_ROOM:
case SerialPacketType::CHARACTER_SET_ORIGIN:
case SerialPacketType::CHARACTER_SET_MOTION:
serializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
break;
case SerialPacketType::TEXT_BROADCAST:
case SerialPacketType::JOIN_REJECTION:
case SerialPacketType::SHUTDOWN_REJECTION:
case SerialPacketType::LOGIN_REJECTION:
case SerialPacketType::REGION_REJECTION:
case SerialPacketType::CHARACTER_REJECTION:
case SerialPacketType::SHUTDOWN_REJECTION:
serializeText(buffer, static_cast<TextPacket*>(packet));
break;
}
@@ -93,26 +105,38 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
break;
case SerialPacketType::JOIN_REQUEST:
case SerialPacketType::JOIN_RESPONSE:
case SerialPacketType::SYNCHRONIZE:
case SerialPacketType::DISCONNECT:
case SerialPacketType::SHUTDOWN:
case SerialPacketType::DISCONNECT_REQUEST:
case SerialPacketType::DISCONNECT_RESPONSE:
case SerialPacketType::DISCONNECT_FORCED:
case SerialPacketType::LOGIN_REQUEST:
case SerialPacketType::LOGIN_RESPONSE:
case SerialPacketType::LOGOUT_REQUEST:
case SerialPacketType::LOGOUT_RESPONSE:
case SerialPacketType::SHUTDOWN_REQUEST:
deserializeClient(buffer, static_cast<ClientPacket*>(packet));
break;
case SerialPacketType::REGION_REQUEST:
case SerialPacketType::REGION_CONTENT:
deserializeRegion(buffer, static_cast<RegionPacket*>(packet));
break;
case SerialPacketType::CHARACTER_NEW:
case SerialPacketType::CHARACTER_CREATE:
case SerialPacketType::CHARACTER_DELETE:
case SerialPacketType::CHARACTER_UPDATE:
case SerialPacketType::CHARACTER_STATS_REQUEST:
case SerialPacketType::CHARACTER_STATS_RESPONSE:
case SerialPacketType::CHARACTER_LOAD:
case SerialPacketType::CHARACTER_UNLOAD:
case SerialPacketType::QUERY_CHARACTER_EXISTS:
case SerialPacketType::QUERY_CHARACTER_STATS:
case SerialPacketType::QUERY_CHARACTER_LOCATION:
case SerialPacketType::CHARACTER_SET_ROOM:
case SerialPacketType::CHARACTER_SET_ORIGIN:
case SerialPacketType::CHARACTER_SET_MOTION:
deserializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
break;
case SerialPacketType::TEXT_BROADCAST:
case SerialPacketType::JOIN_REJECTION:
case SerialPacketType::SHUTDOWN_REJECTION:
case SerialPacketType::LOGIN_REJECTION:
case SerialPacketType::REGION_REJECTION:
case SerialPacketType::CHARACTER_REJECTION:
case SerialPacketType::SHUTDOWN_REJECTION:
deserializeText(buffer, static_cast<TextPacket*>(packet));
break;
}
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+12 -7
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
@@ -27,13 +27,13 @@
#include <sstream>
#include <stdexcept>
void ConfigUtility::Load(std::string fname, int argc, char* argv[]) {
void ConfigUtility::Load(std::string fname, bool skipMissingFile, int argc, char* argv[]) {
//clear the stored configuration
configMap.clear();
//use the default file
if (argc < 2) {
configMap = Read(fname);
configMap = Read(fname, skipMissingFile);
return;
}
@@ -47,7 +47,9 @@ void ConfigUtility::Load(std::string fname, int argc, char* argv[]) {
for (int i = 1; i < argc; ++i) {
//read from a specified config file
if (!strncmp(argv[i], "-config=", 8)) {
redirectedFile = Read(argv[i] + 8);
//older specified files take precedence
table_t tmp = Read(argv[i] + 8, skipMissingFile);
redirectedFile.insert(tmp.begin(), tmp.end());
redirectUsed = true;
continue;
}
@@ -73,18 +75,21 @@ void ConfigUtility::Load(std::string fname, int argc, char* argv[]) {
//finally, construct the final config table
if (!redirectUsed) {
redirectedFile = Read(fname);
redirectedFile = Read(fname, skipMissingFile);
}
configMap.insert(cmdLineParams.begin(), cmdLineParams.end());
configMap.insert(redirectedFile.begin(), redirectedFile.end());
}
ConfigUtility::table_t ConfigUtility::Read(std::string fname) {
ConfigUtility::table_t ConfigUtility::Read(std::string fname, bool skipMissingFile) {
//read in and return this file's data
table_t retTable;
std::ifstream is(fname);
if (!is.is_open()) {
if (skipMissingFile) {
return {}; //empty table
}
std::ostringstream os;
os << "Failed to open a config file: " << fname;
throw(std::runtime_error( os.str() ));
@@ -143,7 +148,7 @@ ConfigUtility::table_t ConfigUtility::Read(std::string fname) {
//load in any subordinate config files
if (retTable.find("config.next") != retTable.end()) {
table_t subTable = Read(retTable["config.next"]);
table_t subTable = Read(retTable["config.next"], skipMissingFile);
retTable.insert(subTable.begin(), subTable.end());
}
+4 -7
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
@@ -27,9 +27,9 @@
#include <map>
#include <string>
class ConfigUtility : public Singleton<ConfigUtility> {
class ConfigUtility: public Singleton<ConfigUtility> {
public:
void Load(std::string fname, int argc = 0, char* argv[] = nullptr);
void Load(std::string fname, bool skipMissingFile = false, int argc = 0, char* argv[] = nullptr);
//convert to a type
std::string& String(std::string);
@@ -47,10 +47,7 @@ private:
friend Singleton<ConfigUtility>;
ConfigUtility() = default;
~ConfigUtility() = default;
table_t Read(std::string fname);
table_t Read(std::string fname, bool skipMissingFile);
table_t configMap;
};
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
+5 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
/* 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
@@ -92,6 +92,10 @@ public:
return ret;
}
//unary operators
Vector2 operator-() { return {-x, -y}; }
//comparison operators
bool operator==(Vector2 v) { return (x == v.x && y == v.y); }
bool operator!=(Vector2 v) { return (x != v.x || y != v.y); }
+9 -7
View File
@@ -1,3 +1,5 @@
local mapSystem = require "map_system"
local mapMaker = {}
--utility functions
@@ -19,16 +21,16 @@ mapMaker.dirt = 18 + 3 * 4
--custom generation systems here
function mapMaker.debugIsland(region)
for i = 1, Region.GetWidth(region) do
for j = 1, Region.GetHeight(region) do
local dist = mapMaker.dist(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1)
for i = 1, mapSystem.Region.GetWidth(region) do
for j = 1, mapSystem.Region.GetHeight(region) do
local dist = mapMaker.dist(0, 0, i + mapSystem.Region.GetX(region) -1, j + mapSystem.Region.GetY(region) -1)
if dist < 10 then
Region.SetTile(region, i, j, 1, mapMaker.plains)
mapSystem.Region.SetTile(region, i, j, 1, mapMaker.plains)
elseif dist < 12 then
Region.SetTile(region, i, j, 1, mapMaker.sand)
mapSystem.Region.SetTile(region, i, j, 1, mapMaker.sand)
else
Region.SetTile(region, i, j, 1, mapMaker.water)
Region.SetSolid(region, i, j, true)
mapSystem.Region.SetTile(region, i, j, 1, mapMaker.water)
mapSystem.Region.SetSolid(region, i, j, true)
end
end
end
+9
View File
@@ -0,0 +1,9 @@
local mapSaver = {}
function mapSaver.Load(region)
--empty
end
function mapSaver.Save(region)
--empty
end
--TODO: create a flexible saving & loading system
return mapSaver
View File
+25 -5
View File
@@ -2,11 +2,31 @@ print("Lua script check")
mapMaker = require "map_maker"
mapSaver = require "map_saver"
roomSystem = require "room_system"
--BUG: #35 The server fails without at least one room
--TODO: Create rooms with names?
newRoom = RoomManager.CreateRoom("overworld", "overworld.bmp")
pager = Room.GetPager(newRoom)
RegionPager.SetOnCreate(pager, mapMaker.debugIsland)
local function dumpTable(t)
print(t)
for k, v in pairs(t) do
print("",k, v)
end
end
--create the overworld, set it's generator, loader & saver
--[[
local t = {
"overworld.bmp", --tileset name
mapSaver.load, --load function
mapSaver.save, --save function
mapMaker.debugIsland, --create function
mapSaver.save --unload function
}]]
dumpTable(roomSystem)
dumpTable(roomSystem.RoomManager)
dumpTable(roomSystem.Room)
--NOTE: room 0 is the first that the client asks for, therefore it must exist
local overworld, uid = roomSystem.RoomManager.CreateRoom("overworld")
roomSystem.Room.Initialize(overworld, "overworld.bmp", mapSaver.Load, mapSaver.Save, mapMaker.debugIsland, mapSaver.Save)
print("Finished the lua script")
+2
View File
@@ -1,3 +1,5 @@
--TODO: An archive table of all dead characters
CREATE TABLE IF NOT EXISTS Accounts (
uid INTEGER PRIMARY KEY AUTOINCREMENT,
username varchar(100) UNIQUE,
+54
View File
@@ -0,0 +1,54 @@
/* 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;
}
+10 -9
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -30,17 +30,17 @@ public:
~AccountData() = default;
//accessors and mutators
int SetClientIndex(int i) { return clientIndex = i; }
int GetClientIndex() { return clientIndex; }
int SetClientIndex(int i);
int GetClientIndex();
std::string SetUsername(std::string s) { return username = s; }
std::string GetUsername() { return username; }
std::string SetUsername(std::string s);
std::string GetUsername();
//database stuff
bool GetBlackListed() { return blackListed; }
bool GetWhiteListed() { return whiteListed; }
bool GetModerator() { return mod; }
bool GetAdministrator() { return admin; }
bool GetBlackListed();
bool GetWhiteListed();
bool GetModerator();
bool GetAdministrator();
private:
friend class AccountManager;
@@ -49,6 +49,7 @@ private:
std::string username;
//TODO: password
//bit fields?
bool blackListed = false;
bool whiteListed = true;
bool mod = false;
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -19,14 +19,16 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "client_data.hpp"
#include "character_data.hpp"
int ClientData::IncrementAttempts() {
lastBeat = Clock::now();
return attemptedBeats++;
int CharacterData::GetOwner() {
return owner;
}
int ClientData::ResetAttempts() {
lastBeat = Clock::now();
return attemptedBeats = 0;
std::string CharacterData::GetHandle() {
return handle;
}
std::string CharacterData::GetAvatar() {
return avatar;
}
+7 -24
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -24,45 +24,28 @@
//components
#include "character_defines.hpp"
#include "vector2.hpp"
#include "statistics.hpp"
#include "entity.hpp"
//std namespace
#include <string>
#include <cmath>
class CharacterData {
class CharacterData: public Entity {
public:
CharacterData() = default;
~CharacterData() = default;
//location and movement
int SetRoomIndex(int i) { return roomIndex = i; }
Vector2 SetOrigin(Vector2 v) { return origin = v; }
Vector2 SetMotion(Vector2 v) { return motion = v; }
int GetRoomIndex() { return roomIndex; }
Vector2 GetOrigin() { return origin; }
Vector2 GetMotion() { return motion; }
//accessors and mutators
Statistics* GetBaseStats() { return &baseStats; }
//...
//database stuff
int GetOwner() { return owner; }
std::string GetHandle() { return handle; }
std::string GetAvatar() { return avatar; }
int GetOwner();
std::string GetHandle();
std::string GetAvatar();
private:
friend class CharacterManager;
//world position
int roomIndex = 0;
Vector2 origin = {0.0,0.0};
Vector2 motion = {0.0,0.0};
Statistics baseStats;
int owner;
std::string handle;
std::string avatar;
+3 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014
/* 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
@@ -110,6 +110,8 @@ int CharacterManager::Load(int owner, std::string handle, std::string avatar) {
//check the owner
if (owner != sqlite3_column_int(statement, 1)) {
sqlite3_finalize(statement);
//unload the already loaded character
Unload(uid);
return -2;
}

Some files were not shown because too many files have changed in this diff Show More