Compare commits

...

50 Commits

Author SHA1 Message Date
Kayne Ruse 99af76c5b5 Merge branch 'develop'
Conflicts:
	todo.txt
2014-12-27 23:44:54 +11:00
Kayne Ruse cc6458daa7 Merge branch 'high-water-mark' into develop
Thank fuck that's over.
2014-12-27 23:34:51 +11:00
Kayne Ruse 8708cfbee0 I give up, I'm just using the stop-dead system for now. 2014-12-27 23:16:48 +11:00
Kayne Ruse b67e85e87b Moved some messy code from InWorld::Update() to utility methods 2014-12-27 21:00:00 +11:00
Kayne Ruse 33c3143de9 Added unary negative to Vector2
This is the only fragment I'm bothering to salvage from the collisions
branch.
2014-12-27 20:31:09 +11:00
Kayne Ruse ce16fc6969 Merge branch 'develop' into high-water-mark
Conflicts:
	server/server_logic.cpp

Finally merging the changes to develop. This is only the ConfigUtility
skipping missing files, and something with the Timer class, that I'll need
to test the collisions.
2014-12-27 19:28:02 +11:00
Kayne Ruse f6e90d7e39 Fixed controls & hotkeys interferring; smoother logouts 2014-12-27 19:25:49 +11:00
Kayne Ruse ee0b7884a8 Partial collision (box prep) complete; untested 2014-12-27 15:05:34 +11:00
Kayne Ruse 7e5a7f8183 Updated the copyright headers about a week ahead 2014-12-27 13:29:16 +11:00
Kayne Ruse f2d517df9d BUGFIX: Infinitely small motion on an axis after repeated key release;
read more

I've patched this issue by setting motion's elements to
CHARACTER_WALKING_SPEED or negative CHARACTER_WALKING_SPEED if they're
above or below zero, respectively.
2014-12-27 12:33:51 +11:00
Kayne Ruse 6c11aa0927 Characters are moving around in the world 2014-12-27 02:26:44 +11:00
Kayne Ruse 398f1c8bfd Added a room check to the character query 2014-12-27 01:33:10 +11:00
Kayne Ruse 3e2d1a5a56 Implemented client-side HandleCharacterSet*(); untested 2014-12-22 23:09:28 +11:00
Kayne Ruse f52eafdf55 Implemented server-side HandleSetCharacter*(); untested 2014-12-22 22:13:42 +11:00
Kayne Ruse dff04b5b69 Moved server_util.cpp methods; created server_character_methods.cpp 2014-12-21 08:07:55 +11:00
Kayne Ruse 900f623f3b Camera centering and client drop message 2014-12-19 20:33:09 +11:00
Kayne Ruse 44a1edac30 HOTFIX: Patched the stupid auto& for loop with the jenky pattern 2014-12-19 20:11:22 +11:00
Kayne Ruse 2ae2c48819 Added LocalCharacter, removed entityIndex 2014-12-19 19:44:34 +11:00
Kayne Ruse 07af05712b Implemented client-side query 2014-12-19 18:33:41 +11:00
Kayne Ruse 15ea360b8a Replaced lambda implementations with calls to the 'full unload' methods
IT should be noted that ClientManager::CheckConnections() no longer
removes a client; instead, it returns a client index that needs to be
removed via another means. This allows ServerApplication to use the 'full
unload' method.
2014-12-19 17:58:50 +11:00
Kayne Ruse 0d9dfad4a5 Implemented 'full unload' methods, not used yet 2014-12-19 15:52:05 +11:00
Kayne Ruse 7962692641 Implemented client-side character delete; untested 2014-12-19 14:21:05 +11:00
Kayne Ruse 4d1bb17382 Comment tweaks 2014-12-18 09:28:24 +11:00
Kayne Ruse 015631a73d Implemented client-side HandleCharacterCreate 2014-12-18 09:14:11 +11:00
Kayne Ruse 3399053e64 Added an option to skip missing config files 2014-12-16 21:49:50 +11:00
Kayne Ruse ae046977f0 Server state query works, client doesn't use the result yet
Both sides of this message uses QUERY_CHARACTER_EXISTS because I'm just
trying to push forward, without worrying about mistakes I might be making.
I just want to merge this back into the main branch so I can say that I've
actually done something over the last few months.
2014-12-11 08:02:38 +11:00
Kayne Ruse 72f641bf63 Server sends character create & delete messages 2014-12-11 07:12:16 +11:00
Kayne Ruse dbd1289ced Moved map and character management to server_data.cpp 2014-12-09 00:41:09 +11:00
Kayne Ruse de4e539449 Moved the connection code to server_connections.cpp 2014-12-03 00:46:38 +11:00
Kayne Ruse 61f462a882 Server-side HandleCharacterUnload() 2014-12-03 00:06:07 +11:00
Kayne Ruse 5607f76ce7 Server-side HandleCharacterDelete() 2014-12-02 23:41:08 +11:00
Kayne Ruse 0e666d3203 Server accepts and creates the character's data 2014-12-02 23:11:08 +11:00
Kayne Ruse f50406d69f Code tweak 2014-12-01 22:59:26 +11:00
Kayne Ruse cc167180f6 Added support for cleaning up after rejection messages 2014-12-01 22:33:15 +11:00
Kayne Ruse c89f94b681 Missed the map system's nested API table 2014-12-01 00:26:47 +11:00
Kayne Ruse 822ff5827e Map protocol works in theory 2014-12-01 00:13:46 +11:00
Kayne Ruse 8579d7e0d6 Implemented client-side HandleRegionContent() 2014-11-30 23:29:46 +11:00
Kayne Ruse 06eb1f2e9e Minor tweak to the Timer class; kind of pointless 2014-11-30 23:04:54 +11:00
Kayne Ruse b59cd0fe87 Server-side HandleRegionRequest() reimplemented
Note that this locally handles bug #35, and adds a new packet type:

REGION_REJECTION
2014-11-30 22:23:46 +11:00
Kayne Ruse bac8bc2b41 Fixed a misspelled method call 2014-11-26 10:28:57 +11:00
Kayne Ruse e5abd51f76 Two-step login system works perfectly; can't shut the server down
I've also removed a large amount of commented and uncommented code from
in_world.cpp, simply because so much code was dummied out. I can readd
this code as I reimeplement various features.
2014-11-26 10:14:26 +11:00
Kayne Ruse 584b6ea303 Fixed a bug in deserializePacket() 2014-11-26 07:51:24 +11:00
Kayne Ruse 01461deaa5 Set the values for packets, and added getRoom() 2014-11-26 07:11:27 +11:00
Kayne Ruse fa0d232727 Removed one parameter from RoomManager::Create() 2014-11-26 06:41:29 +11:00
Kayne Ruse 6485839dcf Replaced RoomData's hooks with Initialize API function 2014-11-26 06:33:02 +11:00
Kayne Ruse 81a3a92603 Simplified setup_server.lua 2014-11-26 06:12:01 +11:00
Kayne Ruse 9ba76c8987 Added RegionPagerLua destructor 2014-11-26 06:11:27 +11:00
Kayne Ruse 5deb6a9d8e Merge branch 'develop' 2014-11-23 04:12:51 +11:00
Kayne Ruse 3192524922 Merge commit '0f13956'
* also eliminated ./todo.txt
2014-11-07 00:17:31 +11:00
Kayne Ruse 2a7a2889c6 Merge branch 'unix-compat' 2014-10-19 05:50:13 +11:00
133 changed files with 1743 additions and 1090 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
* arising from the use of this software. * arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * 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: * freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; you must not * 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 //load the prerequisites
ConfigUtility& config = ConfigUtility::GetSingleton(); ConfigUtility& config = ConfigUtility::GetSingleton();
config.Load("rsc/config.cfg", argc, argv); config.Load("rsc/config.cfg", false, argc, argv);
//------------------------- //-------------------------
//Initialize the APIs //Initialize the APIs
@@ -178,7 +178,7 @@ void ClientApplication::LoadScene(SceneList sceneIndex) {
activeScene = new OptionsMenu(); activeScene = new OptionsMenu();
break; break;
case SceneList::LOBBYMENU: case SceneList::LOBBYMENU:
activeScene = new LobbyMenu(&clientIndex, &accountIndex); //TODO: can I use the ConfigUtility for these parameters? activeScene = new LobbyMenu(&clientIndex, &accountIndex);
break; break;
case SceneList::INWORLD: case SceneList::INWORLD:
activeScene = new InWorld(&clientIndex, &accountIndex); 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+37
View File
@@ -0,0 +1,37 @@
#config
INCLUDES+=.
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 $@ $<
clean:
$(RM) *.o *.a *.exe
rebuild: clean all
@@ -0,0 +1,23 @@
/* 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"
@@ -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
+37 -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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -21,6 +21,12 @@
*/ */
#include "base_character.hpp" #include "base_character.hpp"
#include "config_utility.hpp"
//-------------------------
//graphics
//-------------------------
void BaseCharacter::CorrectSprite() { void BaseCharacter::CorrectSprite() {
//NOTE: These must correspond to the sprite sheet in use //NOTE: These must correspond to the sprite sheet in use
if (motion.y > 0) { if (motion.y > 0) {
@@ -45,3 +51,33 @@ void BaseCharacter::CorrectSprite() {
sprite.SetXIndex(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;
}
+9 -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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -29,7 +29,7 @@
//std namespace //std namespace
#include <string> #include <string>
class BaseCharacter : public Entity { class BaseCharacter: public Entity {
public: public:
BaseCharacter() = default; BaseCharacter() = default;
virtual ~BaseCharacter() = default; virtual ~BaseCharacter() = default;
@@ -38,14 +38,14 @@ public:
void CorrectSprite(); void CorrectSprite();
//metadata //metadata
int SetOwner(int i) { return owner = i; } int SetOwner(int i);
int GetOwner() { return owner; } int GetOwner();
std::string SetHandle(std::string s) { return handle = s; } std::string SetHandle(std::string s);
std::string GetHandle() const { return handle; } std::string GetHandle() const;
std::string SetAvatar(std::string s) { return avatar = s; } std::string SetAvatar(std::string s);
std::string GetAvatar() const { return avatar; } std::string GetAvatar() const;
private: protected:
//metadata //metadata
int owner; int owner;
std::string handle; std::string handle;
+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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -24,12 +24,12 @@
#include "entity.hpp" #include "entity.hpp"
class BaseMonster : public Entity { class BaseMonster: public Entity {
public: public:
BaseMonster() = default; BaseMonster() = default;
virtual ~BaseMonster() = default; virtual ~BaseMonster() = default;
private: protected:
// //
}; };
+12 -11
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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -30,13 +30,13 @@ void Entity::DrawTo(SDL_Surface* const dest, int camX, int camY) {
sprite.DrawTo(dest, origin.x - camX, origin.y - camY); sprite.DrawTo(dest, origin.x - camX, origin.y - camY);
} }
int Entity::SetEntityIndex(int i) { SpriteSheet* Entity::GetSprite() {
return entityIndex = i; return &sprite;
} }
int Entity::SetRoomIndex(int i) { //-------------------------
return roomIndex = i; //accessors & mutators
} //-------------------------
Vector2 Entity::SetOrigin(Vector2 v) { Vector2 Entity::SetOrigin(Vector2 v) {
return origin = v; return origin = v;
@@ -45,12 +45,9 @@ Vector2 Entity::SetOrigin(Vector2 v) {
Vector2 Entity::SetMotion(Vector2 v) { Vector2 Entity::SetMotion(Vector2 v) {
return motion = v; return motion = v;
} }
int Entity::GetEntityIndex() {
return entityIndex;
}
int Entity::GetRoomIndex() { BoundingBox Entity::SetBounds(BoundingBox b) {
return roomIndex; return bounds = b;
} }
Vector2 Entity::GetOrigin() { Vector2 Entity::GetOrigin() {
@@ -59,4 +56,8 @@ Vector2 Entity::GetOrigin() {
Vector2 Entity::GetMotion() { Vector2 Entity::GetMotion() {
return motion; return motion;
}
BoundingBox Entity::GetBounds() {
return bounds;
} }
+5 -11
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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -32,28 +32,22 @@ public:
virtual void Update(); virtual void Update();
virtual void DrawTo(SDL_Surface* const, int camX, int camY); virtual void DrawTo(SDL_Surface* const, int camX, int camY);
SpriteSheet* GetSprite() { return &sprite; } SpriteSheet* GetSprite();
//accessors & mutators //accessors & mutators
int SetEntityIndex(int i);
int SetRoomIndex(int i);
Vector2 SetOrigin(Vector2 v); Vector2 SetOrigin(Vector2 v);
Vector2 SetMotion(Vector2 v); Vector2 SetMotion(Vector2 v);
BoundingBox SetBounds(BoundingBox b) { return bounds = b; } BoundingBox SetBounds(BoundingBox b);
int GetEntityIndex();
int GetRoomIndex();
Vector2 GetOrigin(); Vector2 GetOrigin();
Vector2 GetMotion(); Vector2 GetMotion();
BoundingBox GetBounds() { return bounds; } BoundingBox GetBounds();
protected: protected:
Entity() = default; Entity() = default;
~Entity() = default; virtual ~Entity() = default;
SpriteSheet sprite; SpriteSheet sprite;
int entityIndex = -1;
int roomIndex = -1;
Vector2 origin; Vector2 origin;
Vector2 motion; Vector2 motion;
BoundingBox bounds; BoundingBox bounds;
+35
View File
@@ -0,0 +1,35 @@
/* 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 <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;
}
+42
View File
@@ -0,0 +1,42 @@
/* 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 LOCALCHARACTER_HPP_
#define LOCALCHARACTER_HPP_
#include "base_character.hpp"
#include "bounding_box.hpp"
#include "vector2.hpp"
#include <list>
class LocalCharacter: public BaseCharacter {
public:
LocalCharacter() = default;
virtual ~LocalCharacter() = default;
bool ProcessCollisionGrid(std::list<BoundingBox>);
private:
//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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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(); ConfigUtility::CreateSingleton();
UDPNetworkUtility::CreateSingleton(); UDPNetworkUtility::CreateSingleton();
//call the server's routines //call the client's routines
ClientApplication::CreateSingleton(); ClientApplication::CreateSingleton();
ClientApplication& app = ClientApplication::GetSingleton(); ClientApplication& app = ClientApplication::GetSingleton();
+2 -1
View File
@@ -1,5 +1,5 @@
#include directories #include directories
INCLUDES+=. entities 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 #libraries
#the order of the $(LIBS) is important, at least for MinGW #the order of the $(LIBS) is important, at least for MinGW
@@ -25,6 +25,7 @@ OUT=$(addprefix $(OUTDIR)/,client)
#targets #targets
all: $(OBJ) $(OUT) all: $(OBJ) $(OUT)
$(MAKE) -C client_utilities
$(MAKE) -C entities $(MAKE) -C entities
$(MAKE) -C scenes $(MAKE) -C scenes
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
+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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+504 -307
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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -23,12 +23,25 @@
#include "channels.hpp" #include "channels.hpp"
#include "utility.hpp" #include "utility.hpp"
#include "config_utility.hpp"
#include "terminal_error.hpp"
#include <stdexcept> #include <stdexcept>
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <iostream> #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 //Public access members
@@ -38,8 +51,6 @@ InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex):
clientIndex(*argClientIndex), clientIndex(*argClientIndex),
accountIndex(*argAccountIndex) accountIndex(*argAccountIndex)
{ {
ConfigUtility& config = ConfigUtility::GetSingleton();
//setup the utility objects //setup the utility objects
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp"); buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
buttonImage.SetClipH(buttonImage.GetClipH()/3); buttonImage.SetClipH(buttonImage.GetClipH()/3);
@@ -62,27 +73,36 @@ InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex):
shutDownButton.SetText("Shut Down"); shutDownButton.SetText("Shut Down");
//load the tilesheet //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 //TODO: Tile size and tile sheet should be loaded elsewhere
tileSheet.Load(config["dir.tilesets"] + "overworld.bmp", 32, 32); tileSheet.Load(config["dir.tilesets"] + "overworld.bmp", 32, 32);
//send this player's character info //Send the character data
// CharacterPacket newPacket; //TODO: login scene, prompt, etc.
// newPacket.type = SerialPacketType::CHARACTER_NEW; CharacterPacket newPacket;
// strncpy(newPacket.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE); newPacket.type = SerialPacketType::CHARACTER_LOAD;
// strncpy(newPacket.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE); strncpy(newPacket.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE);
// newPacket.accountIndex = accountIndex; strncpy(newPacket.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE);
// network.SendTo(Channels::SERVER, &newPacket); newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
//request a sync //query the world state
// RequestSynchronize(); 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 //debug
// //
} }
InWorld::~InWorld() { InWorld::~InWorld() {
// //unload the local data
characterMap.clear();
monsterMap.clear();
} }
//------------------------- //-------------------------
@@ -94,69 +114,57 @@ void InWorld::FrameStart() {
} }
void InWorld::Update() { 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]); SerialPacket* packetBuffer = reinterpret_cast<SerialPacket*>(new char[MAX_PACKET_SIZE]);
while(network.Receive(packetBuffer)) { memset(packetBuffer, 0, MAX_PACKET_SIZE);
HandlePacket(packetBuffer);
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); delete reinterpret_cast<char*>(packetBuffer);
//update the characters //heartbeat system
CheckHeartBeat();
//update all entities
for (auto& it : characterMap) { for (auto& it : characterMap) {
it.second.Update(); it.second.Update();
} }
for (auto& it : monsterMap) {
it.second.Update();
}
//check the map //update the map
UpdateMap(); UpdateMap();
//skip the rest //skip the rest without a local character
if (!localCharacter) { if (!localCharacter) {
return; return;
} }
//check for collisions with the map //get the collidable boxes
BoundingBox wallBounds = {0, 0, tileSheet.GetTileW(), tileSheet.GetTileH()}; std::list<BoundingBox> boxList = GenerateCollisionGrid(localCharacter, tileSheet.GetTileW(), tileSheet.GetTileH());
const int xCount = localCharacter->GetBounds().w / wallBounds.w + 1;
const int yCount = localCharacter->GetBounds().h / wallBounds.h + 1;
for (int i = -1; i <= xCount; ++i) { //process the collisions
for (int j = -1; j <= yCount; ++j) { if (localCharacter->ProcessCollisionGrid(boxList)) {
//set the wall's position localCharacter->CorrectSprite();
wallBounds.x = wallBounds.w * i + snapToBase((double)wallBounds.w, localCharacter->GetOrigin().x); SendLocalCharacterMotion();
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});
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
}
} }
//update the camera (following the player) //update the camera
camera.x = localCharacter->GetOrigin().x - camera.marginX; camera.x = localCharacter->GetOrigin().x - camera.marginX;
camera.y = localCharacter->GetOrigin().y - camera.marginY; 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() { void InWorld::FrameEnd() {
@@ -164,7 +172,7 @@ void InWorld::FrameEnd() {
} }
void InWorld::RenderFrame() { void InWorld::RenderFrame() {
// SDL_FillRect(GetScreen(), 0, 0); SDL_FillRect(GetScreen(), 0, 0);
Render(GetScreen()); Render(GetScreen());
SDL_Flip(GetScreen()); SDL_Flip(GetScreen());
fps.Calculate(); fps.Calculate();
@@ -176,10 +184,13 @@ void InWorld::Render(SDL_Surface* const screen) {
tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y); tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y);
} }
//draw characters //draw the entities
for (auto& it : characterMap) { for (auto& it : characterMap) {
//BUG: #29 drawing order according to Y origin //TODO: depth ordering
//TODO: use a list of renderable objects it.second.DrawTo(screen, camera.x, camera.y);
}
for (auto& it : monsterMap) {
//TODO: depth ordering
it.second.DrawTo(screen, camera.x, camera.y); it.second.DrawTo(screen, camera.x, camera.y);
} }
@@ -194,8 +205,8 @@ void InWorld::Render(SDL_Surface* const screen) {
//------------------------- //-------------------------
void InWorld::QuitEvent() { void InWorld::QuitEvent() {
//exit the game AND the server //two-step logout
RequestDisconnect(); SendDisconnectRequest();
SetNextScene(SceneList::QUIT); SetNextScene(SceneList::QUIT);
} }
@@ -211,231 +222,281 @@ void InWorld::MouseButtonDown(SDL_MouseButtonEvent const& button) {
void InWorld::MouseButtonUp(SDL_MouseButtonEvent const& button) { void InWorld::MouseButtonUp(SDL_MouseButtonEvent const& button) {
if (disconnectButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) { 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) { if (shutDownButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) {
RequestShutDown(); SendShutdownRequest();
} }
} }
void InWorld::KeyDown(SDL_KeyboardEvent const& key) { void InWorld::KeyDown(SDL_KeyboardEvent const& key) {
if (!localCharacter) {
return;
}
//hotkeys //hotkeys
switch(key.keysym.sym) { switch(key.keysym.sym) {
case SDLK_ESCAPE: case SDLK_ESCAPE:
RequestDisconnect(); //TODO: the escape key should actually control menus and stuff
break; SendLogoutRequest();
}
//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:
return;
}
localCharacter->SetMotion(motion);
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
if (!localCharacter) {
return; return;
} }
//player movement //character movement
if (!localCharacter) {
return;
}
Vector2 motion = localCharacter->GetMotion(); Vector2 motion = localCharacter->GetMotion();
switch(key.keysym.sym) { switch(key.keysym.sym) {
//NOTE: The use of min/max here are to prevent awkward movements case SDLK_w:
case SDLK_LEFT: motion.y -= CHARACTER_WALKING_SPEED;
motion.x = std::min(motion.x + CHARACTER_WALKING_SPEED, 0.0);
break; break;
case SDLK_RIGHT: case SDLK_a:
motion.x = std::max(motion.x - CHARACTER_WALKING_SPEED, 0.0); motion.x -= CHARACTER_WALKING_SPEED;
break; break;
case SDLK_UP: case SDLK_s:
motion.y = std::min(motion.y + CHARACTER_WALKING_SPEED, 0.0); motion.y += CHARACTER_WALKING_SPEED;
break; break;
case SDLK_DOWN: case SDLK_d:
motion.y = std::max(motion.y - CHARACTER_WALKING_SPEED, 0.0); motion.x += CHARACTER_WALKING_SPEED;
break; break;
default: default:
//DOCS: prevents wrong keys screwing with character movement
return; return;
} }
//handle diagonals
if (motion.x != 0 && motion.y != 0) {
motion *= CHARACTER_WALKING_MOD;
}
//set the info
localCharacter->SetMotion(motion); localCharacter->SetMotion(motion);
localCharacter->CorrectSprite(); 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) { void InWorld::HandlePacket(SerialPacket* const argPacket) {
switch(argPacket->type) { switch(argPacket->type) {
//heartbeat system //heartbeat system
case SerialPacketType::PING: { case SerialPacketType::PING:
ServerPacket newPacket; HandlePing(static_cast<ServerPacket*>(argPacket));
newPacket.type = SerialPacketType::PONG;
network.SendTo(argPacket->srcAddress, &newPacket);
}
break; break;
case SerialPacketType::PONG: case SerialPacketType::PONG:
// HandlePong(static_cast<ServerPacket*>(argPacket)); HandlePong(static_cast<ServerPacket*>(argPacket));
break; break;
//game server connections //game server connections
case SerialPacketType::LOGOUT_RESPONSE: case SerialPacketType::LOGOUT_RESPONSE:
// HandleLogoutResponse(static_cast<ClientPacket*>(argPacket)); HandleLogoutResponse(static_cast<ClientPacket*>(argPacket));
break; break;
case SerialPacketType::DISCONNECT_REQUEST: case SerialPacketType::DISCONNECT_RESPONSE:
// HandleDisconnectRequest(static_cast<ClientPacket*>(argPacket)); HandleDisconnectResponse(static_cast<ClientPacket*>(argPacket));
break; break;
case SerialPacketType::DISCONNECT_FORCED: case SerialPacketType::DISCONNECT_FORCED:
// HandleDisconnectForced(static_cast<ClientPacket*>(argPacket)); HandleDisconnectForced(static_cast<ClientPacket*>(argPacket));
break; break;
//data management //map management
case SerialPacketType::REGION_CONTENT: case SerialPacketType::REGION_CONTENT:
// HandleRegionContent(static_cast<RegionPacket*>(argPacket)); HandleRegionContent(static_cast<RegionPacket*>(argPacket));
break; break;
// case SerialPacketType::QUERY_CHARACTER_EXISTS:
// case SerialPacketType::QUERY_CHARACTER_STATS:
// case SerialPacketType::QUERY_CHARACTER_LOCATION:
//character management //character management
// case SerialPacketType::CHARACTER_NEW: case SerialPacketType::CHARACTER_CREATE:
// HandleCharacterNew(static_cast<CharacterPacket*>(argPacket)); HandleCharacterCreate(static_cast<CharacterPacket*>(argPacket));
// break; break;
// case SerialPacketType::CHARACTER_DELETE: case SerialPacketType::CHARACTER_DELETE:
// HandleCharacterDelete(static_cast<CharacterPacket*>(argPacket)); HandleCharacterDelete(static_cast<CharacterPacket*>(argPacket));
// break; break;
// case SerialPacketType::CHARACTER_UPDATE: case SerialPacketType::QUERY_CHARACTER_EXISTS:
// HandleCharacterUpdate(static_cast<CharacterPacket*>(argPacket)); HandleCharacterQueryExists(static_cast<CharacterPacket*>(argPacket));
// break; break;
// case SerialPacketType::CHARACTER_REJECTION:
// HandleCharacterRejection(static_cast<TextPacket*>(argPacket));
// break;
//enemy management //character movement
//TODO: enemy management 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;
//TODO: text //rejection messages
case SerialPacketType::REGION_REJECTION:
case SerialPacketType::CHARACTER_REJECTION:
throw(terminal_error(static_cast<TextPacket*>(argPacket)->text));
break;
case SerialPacketType::SHUTDOWN_REJECTION:
throw(std::runtime_error(static_cast<TextPacket*>(argPacket)->text));
break;
//handle errors //errors
default: default: {
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in InWorld: " + to_string_custom(static_cast<int>(argPacket->type)) )); std::ostringstream msg;
msg << "Unknown SerialPacketType encountered in InWorld: " << static_cast<int>(argPacket->type);
throw(std::runtime_error(msg.str()));
}
break; break;
} }
} }
void InWorld::HandlePing(ServerPacket* const argPacket) {
ServerPacket newPacket;
newPacket.type = SerialPacketType::PONG;
network.SendTo(argPacket->srcAddress, &newPacket);
}
void InWorld::HandlePong(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")); throw(std::runtime_error("Heartbeat message received from an unknown source"));
} }
attemptedBeats = 0; attemptedBeats = 0;
lastBeat = Clock::now(); lastBeat = Clock::now();
} }
void InWorld::HandleDisconnect(ClientPacket* const argPacket) { //-------------------------
//TODO: More needed in the disconnection //Connection control
SetNextScene(SceneList::DISCONNECTEDSCREEN); //-------------------------
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been disconnected";
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) { void InWorld::SendDisconnectRequest() {
if (characterMap.find(argPacket->characterIndex) != characterMap.end()) { ClientPacket newPacket;
throw(std::runtime_error("Cannot create duplicate characters"));
}
//create the character object //send a disconnect request
BaseCharacter& newCharacter = characterMap[argPacket->characterIndex]; newPacket.type = SerialPacketType::DISCONNECT_REQUEST;
newPacket.clientIndex = clientIndex;
//fill out the character's members network.SendTo(Channels::SERVER, &newPacket);
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);
}
} }
void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) { void InWorld::SendShutdownRequest() {
//TODO: authenticate when own character is being deleted (linked to a TODO in the server) ClientPacket newPacket;
//catch this client's player object //send a shutdown request
if (argPacket->characterIndex == characterIndex) { newPacket.type = SerialPacketType::SHUTDOWN_REQUEST;
characterIndex = -1; newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::HandleLogoutResponse(ClientPacket* const argPacket) {
if (localCharacter) {
characterMap.erase(characterIndex);
localCharacter = nullptr; 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) { void InWorld::HandleDisconnectResponse(ClientPacket* const argPacket) {
if (characterMap.find(argPacket->characterIndex) == characterMap.end()) { HandleLogoutResponse(argPacket);//shortcut
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();
SetNextScene(SceneList::DISCONNECTEDSCREEN); SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility& config = ConfigUtility::GetSingleton(); ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have successfully logged out";
config["client.disconnectMessage"] = "Error: "; }
config["client.disconnectMessage"] += argPacket->text;
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) { void InWorld::HandleRegionContent(RegionPacket* const argPacket) {
@@ -448,82 +509,11 @@ void InWorld::HandleRegionContent(RegionPacket* const argPacket) {
argPacket->region = nullptr; 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_REQUEST;
newPacket.clientIndex = clientIndex;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::RequestShutDown() {
ClientPacket newPacket;
//send a shutdown request
newPacket.type = SerialPacketType::SHUTDOWN_REQUEST;
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() { void InWorld::UpdateMap() {
if (roomIndex == -1) {
return;
}
//these represent the zone of regions that the client needs loaded, including the mandatory buffers (+1/-1) //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 xStart = snapToBase(REGION_WIDTH, camera.x/tileSheet.GetTileW()) - REGION_WIDTH;
int xEnd = snapToBase(REGION_WIDTH, (camera.x+camera.width)/tileSheet.GetTileW()) + REGION_WIDTH; int xEnd = snapToBase(REGION_WIDTH, (camera.x+camera.width)/tileSheet.GetTileW()) + REGION_WIDTH;
@@ -532,27 +522,234 @@ void InWorld::UpdateMap() {
int yEnd = snapToBase(REGION_HEIGHT, (camera.y+camera.height)/tileSheet.GetTileH()) + REGION_HEIGHT; int yEnd = snapToBase(REGION_HEIGHT, (camera.y+camera.height)/tileSheet.GetTileH()) + REGION_HEIGHT;
//prune distant regions //prune distant regions
for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); /* EMPTY */) { regionPager.GetContainer()->remove_if([&](Region const& region) -> bool {
//check if the region is outside of this area return region.GetX() < xStart || region.GetX() > xEnd || region.GetY() < yStart || region.GetY() > yEnd;
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;
}
//request empty regions within this zone //request empty regions within this zone
for (int i = xStart; i <= xEnd; i += REGION_WIDTH) { for (int i = xStart; i <= xEnd; i += REGION_WIDTH) {
for (int j = yStart; j <= yEnd; j += REGION_HEIGHT) { for (int j = yStart; j <= yEnd; j += REGION_HEIGHT) {
if (!regionPager.FindRegion(i, j)) { 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);
}
+40 -25
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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -25,9 +25,10 @@
//maps //maps
#include "region_pager_base.hpp" #include "region_pager_base.hpp"
//networking //utilities
#include "udp_network_utility.hpp" #include "udp_network_utility.hpp"
#include "serial_packet.hpp" #include "serial_packet.hpp"
#include "config_utility.hpp"
//graphics //graphics
#include "image.hpp" #include "image.hpp"
@@ -38,11 +39,10 @@
//common //common
#include "frame_rate.hpp" #include "frame_rate.hpp"
#include "base_character.hpp"
#include "base_monster.hpp"
//client //client
#include "base_scene.hpp" #include "base_scene.hpp"
#include "base_monster.hpp"
#include "local_character.hpp"
//STL //STL
#include <map> #include <map>
@@ -71,33 +71,44 @@ protected:
void KeyDown(SDL_KeyboardEvent const&); void KeyDown(SDL_KeyboardEvent const&);
void KeyUp(SDL_KeyboardEvent const&); void KeyUp(SDL_KeyboardEvent const&);
//Network handlers //Basic connections
void HandlePacket(SerialPacket* const); void HandlePacket(SerialPacket* const);
void HandlePing(ServerPacket* const);
void HandlePong(ServerPacket* const); void HandlePong(ServerPacket* const);
void HandleDisconnect(ClientPacket* const);
void HandleCharacterNew(CharacterPacket* const); //Connection control
void HandleCharacterDelete(CharacterPacket* const); void SendLogoutRequest();
void HandleCharacterUpdate(CharacterPacket* const); void SendDisconnectRequest();
void HandleCharacterRejection(TextPacket* const); 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); 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(); void UpdateMap();
//singleton shortcut //character management
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton(); 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 //indexes
int& clientIndex; int& clientIndex;
int& accountIndex; int& accountIndex;
int characterIndex = -1; int characterIndex = -1;
int roomIndex = -1;
//graphics //graphics
Image buttonImage; Image buttonImage;
@@ -119,16 +130,20 @@ protected:
int marginX = 0, marginY = 0; int marginX = 0, marginY = 0;
} camera; } camera;
//game components //entities
BaseCharacter* localCharacter = nullptr;
std::map<int, BaseCharacter> characterMap; std::map<int, BaseCharacter> characterMap;
std::map<int, BaseMonster> monsterMap; std::map<int, BaseMonster> monsterMap;
LocalCharacter* localCharacter = nullptr;
//heartbeat //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; typedef std::chrono::steady_clock Clock;
Clock::time_point lastBeat = Clock::now(); Clock::time_point lastBeat = Clock::now();
int attemptedBeats = 0; int attemptedBeats = 0;
//ugly references; I hate this
ConfigUtility& config = ConfigUtility::GetSingleton();
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
}; };
#endif #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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
#config #config
INCLUDES+=. .. ../entities ../../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+= LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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) { std::ostream& operator<<(std::ostream& os, Timer& t) {
os << t.GetName() << ": "; os << t.GetName() << ": ";
os << std::chrono::duration_cast<std::chrono::milliseconds>(t.GetTime()).count(); os << std::chrono::duration_cast<std::chrono::microseconds>(t.GetTime()).count();
os << "ms"; os << "us";
return os; 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -34,8 +34,8 @@ public:
Timer(std::string s); Timer(std::string s);
~Timer() = default; ~Timer() = default;
inline void Start(); void Start();
inline void Stop(); void Stop();
//accessors and mutators //accessors and mutators
Clock::duration GetTime() { return timeSpan; } 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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_WIDTH = 32;
constexpr int CHARACTER_BOUNDS_HEIGHT = 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 #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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -70,7 +70,7 @@ int openMapSystemAPI(lua_State* L) {
//push the substable //push the substable
for (const luaL_Reg* lib = libs; lib->func; lib++) { for (const luaL_Reg* lib = libs; lib->func; lib++) {
lua_pushcfunction(L, lib->func); lib->func(L);
lua_setfield(L, -2, lib->name); lua_setfield(L, -2, lib->name);
} }
return 1; return 1;
+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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -23,6 +23,17 @@
#include <stdexcept> #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) { Region* RegionPagerLua::LoadRegion(int x, int y) {
//get the pager's function from the registry //get the pager's function from the registry
lua_rawgeti(lua, LUA_REGISTRYINDEX, loadRef); 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) { Region* RegionPagerLua::SaveRegion(int x, int y) {
//get the pager's function from the registry //get the pager's function from the registry
lua_rawgeti(lua, LUA_REGISTRYINDEX, saveRef); 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) { Region* RegionPagerLua::CreateRegion(int x, int y) {
if (FindRegion(x, y)) { if (FindRegion(x, y)) {
throw(std::logic_error("Cannot overwrite an existing region")); throw(std::logic_error("Cannot overwrite an existing region"));
@@ -116,6 +129,7 @@ Region* RegionPagerLua::CreateRegion(int x, int y) {
return &regionList.front(); return &regionList.front();
} }
//no return
void RegionPagerLua::UnloadRegion(int x, int y) { void RegionPagerLua::UnloadRegion(int x, int y) {
//get the pager's function from the registry //get the pager's function from the registry
lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef); 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -35,7 +35,7 @@
class RegionPagerLua : public RegionPagerBase { class RegionPagerLua : public RegionPagerBase {
public: public:
RegionPagerLua() = default; RegionPagerLua() = default;
~RegionPagerLua() = default; ~RegionPagerLua();
//region manipulation //region manipulation
Region* LoadRegion(int x, int y) override; 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -33,7 +33,7 @@
typedef SerialPacketBase SerialPacket; typedef SerialPacketBase SerialPacket;
//DOCS: NETWORK_VERSION is used to discern compatible servers and clients //DOCS: NETWORK_VERSION is used to discern compatible servers and clients
constexpr int NETWORK_VERSION = -1; constexpr int NETWORK_VERSION = 20141227;
union MaxPacket { union MaxPacket {
CharacterPacket a; CharacterPacket a;
+34 -33
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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -38,12 +38,12 @@ enum class SerialPacketType {
//------------------------- //-------------------------
//heartbeat //heartbeat
PING, PING = 1,
PONG, PONG = 2,
//Used for finding available servers //Used for finding available servers
BROADCAST_REQUEST, BROADCAST_REQUEST = 3,
BROADCAST_RESPONSE, BROADCAST_RESPONSE = 4,
//------------------------- //-------------------------
//ClientPacket //ClientPacket
@@ -51,24 +51,24 @@ enum class SerialPacketType {
//------------------------- //-------------------------
//Connecting to a server as a client //Connecting to a server as a client
JOIN_REQUEST, JOIN_REQUEST = 5,
JOIN_RESPONSE, JOIN_RESPONSE = 6,
//disconnect from the server //disconnect from the server
DISCONNECT_REQUEST, DISCONNECT_REQUEST = 7,
DISCONNECT_RESPONSE, DISCONNECT_RESPONSE = 8,
DISCONNECT_FORCED, DISCONNECT_FORCED = 9,
//load the account //load the account
LOGIN_REQUEST, LOGIN_REQUEST = 10,
LOGIN_RESPONSE, LOGIN_RESPONSE = 11,
//unload the account //unload the account
LOGOUT_REQUEST, LOGOUT_REQUEST = 12,
LOGOUT_RESPONSE, LOGOUT_RESPONSE = 13,
//shut down the server //shut down the server
SHUTDOWN_REQUEST, SHUTDOWN_REQUEST = 14,
//------------------------- //-------------------------
//RegionPacket //RegionPacket
@@ -76,8 +76,8 @@ enum class SerialPacketType {
//------------------------- //-------------------------
//map data //map data
REGION_REQUEST, //NOTE: technically a query REGION_REQUEST = 15, //NOTE: technically a query
REGION_CONTENT, REGION_CONTENT = 16,
//------------------------- //-------------------------
//CharacterPacket //CharacterPacket
@@ -89,20 +89,20 @@ enum class SerialPacketType {
//------------------------- //-------------------------
//character management //character management
CHARACTER_CREATE, CHARACTER_CREATE = 17,
CHARACTER_DELETE, CHARACTER_DELETE = 18,
CHARACTER_LOAD, CHARACTER_LOAD = 19,
CHARACTER_UNLOAD, CHARACTER_UNLOAD = 20,
//find out info from the server //find out info from the server
QUERY_CHARACTER_EXISTS, QUERY_CHARACTER_EXISTS = 21,
QUERY_CHARACTER_STATS, QUERY_CHARACTER_STATS = 22,
QUERY_CHARACTER_LOCATION, QUERY_CHARACTER_LOCATION = 23,
//set the info in the server //set the info in the server
CHARACTER_SET_ROOM, CHARACTER_SET_ROOM = 24,
CHARACTER_SET_ORIGIN, CHARACTER_SET_ORIGIN = 25,
CHARACTER_SET_MOTION, CHARACTER_SET_MOTION = 26,
//TODO: enemy management //TODO: enemy management
@@ -112,19 +112,20 @@ enum class SerialPacketType {
//------------------------- //-------------------------
//general speech //general speech
TEXT_BROADCAST, TEXT_BROADCAST = 27,
//rejection/error messages //rejection/error messages
JOIN_REJECTION, JOIN_REJECTION = 28,
LOGIN_REJECTION, LOGIN_REJECTION = 29,
CHARACTER_REJECTION, REGION_REJECTION = 30,
SHUTDOWN_REJECTION, CHARACTER_REJECTION = 31,
SHUTDOWN_REJECTION = 32,
//------------------------- //-------------------------
//not used //not used
//------------------------- //-------------------------
LAST LAST = 33
}; };
#endif #endif
+4 -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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -83,6 +83,7 @@ void serializePacket(void* buffer, SerialPacketBase* packet) {
case SerialPacketType::TEXT_BROADCAST: case SerialPacketType::TEXT_BROADCAST:
case SerialPacketType::JOIN_REJECTION: case SerialPacketType::JOIN_REJECTION:
case SerialPacketType::LOGIN_REJECTION: case SerialPacketType::LOGIN_REJECTION:
case SerialPacketType::REGION_REJECTION:
case SerialPacketType::CHARACTER_REJECTION: case SerialPacketType::CHARACTER_REJECTION:
case SerialPacketType::SHUTDOWN_REJECTION: case SerialPacketType::SHUTDOWN_REJECTION:
serializeText(buffer, static_cast<TextPacket*>(packet)); serializeText(buffer, static_cast<TextPacket*>(packet));
@@ -95,7 +96,7 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
SerialPacketType type; SerialPacketType type;
memcpy(&type, buffer, sizeof(SerialPacketType)); memcpy(&type, buffer, sizeof(SerialPacketType));
switch(packet->type) { switch(type) {
case SerialPacketType::PING: case SerialPacketType::PING:
case SerialPacketType::PONG: case SerialPacketType::PONG:
case SerialPacketType::BROADCAST_REQUEST: case SerialPacketType::BROADCAST_REQUEST:
@@ -133,6 +134,7 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
case SerialPacketType::TEXT_BROADCAST: case SerialPacketType::TEXT_BROADCAST:
case SerialPacketType::JOIN_REJECTION: case SerialPacketType::JOIN_REJECTION:
case SerialPacketType::LOGIN_REJECTION: case SerialPacketType::LOGIN_REJECTION:
case SerialPacketType::REGION_REJECTION:
case SerialPacketType::CHARACTER_REJECTION: case SerialPacketType::CHARACTER_REJECTION:
case SerialPacketType::SHUTDOWN_REJECTION: case SerialPacketType::SHUTDOWN_REJECTION:
deserializeText(buffer, static_cast<TextPacket*>(packet)); deserializeText(buffer, static_cast<TextPacket*>(packet));
+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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -27,13 +27,13 @@
#include <sstream> #include <sstream>
#include <stdexcept> #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 //clear the stored configuration
configMap.clear(); configMap.clear();
//use the default file //use the default file
if (argc < 2) { if (argc < 2) {
configMap = Read(fname); configMap = Read(fname, skipMissingFile);
return; return;
} }
@@ -47,7 +47,9 @@ void ConfigUtility::Load(std::string fname, int argc, char* argv[]) {
for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i) {
//read from a specified config file //read from a specified config file
if (!strncmp(argv[i], "-config=", 8)) { 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; redirectUsed = true;
continue; continue;
} }
@@ -73,18 +75,21 @@ void ConfigUtility::Load(std::string fname, int argc, char* argv[]) {
//finally, construct the final config table //finally, construct the final config table
if (!redirectUsed) { if (!redirectUsed) {
redirectedFile = Read(fname); redirectedFile = Read(fname, skipMissingFile);
} }
configMap.insert(cmdLineParams.begin(), cmdLineParams.end()); configMap.insert(cmdLineParams.begin(), cmdLineParams.end());
configMap.insert(redirectedFile.begin(), redirectedFile.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 //read in and return this file's data
table_t retTable; table_t retTable;
std::ifstream is(fname); std::ifstream is(fname);
if (!is.is_open()) { if (!is.is_open()) {
if (skipMissingFile) {
return {}; //empty table
}
std::ostringstream os; std::ostringstream os;
os << "Failed to open a config file: " << fname; os << "Failed to open a config file: " << fname;
throw(std::runtime_error( os.str() )); throw(std::runtime_error( os.str() ));
@@ -143,7 +148,7 @@ ConfigUtility::table_t ConfigUtility::Read(std::string fname) {
//load in any subordinate config files //load in any subordinate config files
if (retTable.find("config.next") != retTable.end()) { 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()); 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -27,9 +27,9 @@
#include <map> #include <map>
#include <string> #include <string>
class ConfigUtility : public Singleton<ConfigUtility> { class ConfigUtility: public Singleton<ConfigUtility> {
public: 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 //convert to a type
std::string& String(std::string); std::string& String(std::string);
@@ -47,10 +47,7 @@ private:
friend Singleton<ConfigUtility>; friend Singleton<ConfigUtility>;
ConfigUtility() = default; table_t Read(std::string fname, bool skipMissingFile);
~ConfigUtility() = default;
table_t Read(std::string fname);
table_t configMap; 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -92,6 +92,10 @@ public:
return ret; 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); }
bool operator!=(Vector2 v) { return (x != v.x || y != v.y); } bool operator!=(Vector2 v) { return (x != v.x || y != v.y); }
+6
View File
@@ -1,3 +1,9 @@
local mapSaver = {} local mapSaver = {}
function mapSaver.Load(region)
--empty
end
function mapSaver.Save(region)
--empty
end
--TODO: create a flexible saving & loading system --TODO: create a flexible saving & loading system
return mapSaver return mapSaver
+14 -15
View File
@@ -11,23 +11,22 @@ local function dumpTable(t)
end end
end end
dumpTable(mapMaker)
dumpTable(mapSaver)
dumpTable(roomSystem)
dumpTable(roomSystem.Room)
dumpTable(roomSystem.RoomManager)
--create the overworld, set it's generator, loader & saver --create the overworld, set it's generator, loader & saver
local overworld = roomSystem.RoomManager.CreateRoom("overworld", "overworld.bmp") --[[
roomSystem.Room.SetOnLoad(overworld, 1123) local t = {
roomSystem.Room.SetOnUnload(overworld, 458) "overworld.bmp", --tileset name
mapSaver.load, --load function
mapSaver.save, --save function
mapMaker.debugIsland, --create function
mapSaver.save --unload function
}]]
if roomSystem.Room.GetOnLoad(overworld) == 1123 then dumpTable(roomSystem)
print("onload retreival works") dumpTable(roomSystem.RoomManager)
end dumpTable(roomSystem.Room)
if roomSystem.Room.GetOnUnload(overworld) == 458 then --NOTE: room 0 is the first that the client asks for, therefore it must exist
print("onunload retreival works") local overworld, uid = roomSystem.RoomManager.CreateRoom("overworld")
end roomSystem.Room.Initialize(overworld, "overworld.bmp", mapSaver.Load, mapSaver.Save, mapMaker.debugIsland, mapSaver.Save)
print("Finished the lua script") print("Finished the lua script")
+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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 //check the owner
if (owner != sqlite3_column_int(statement, 1)) { if (owner != sqlite3_column_int(statement, 1)) {
sqlite3_finalize(statement); sqlite3_finalize(statement);
//unload the already loaded character
Unload(uid);
return -2; return -2;
} }
+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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -39,7 +39,7 @@ int ClientManager::CheckConnections() {
for (auto& it : elementMap) { for (auto& it : elementMap) {
if (it.second.GetAttempts() > 2) { if (it.second.GetAttempts() > 2) {
int ret = it.first; int ret = it.first;
elementMap.erase(it.first); // elementMap.erase(it.first);
return ret; return ret;
} }
} }

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