Implemented a basic API for the server's rooms
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
||||
#config
|
||||
INCLUDES+=. ../common/gameplay ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/script ../common/utilities
|
||||
INCLUDES+=. ../common/gameplay ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/utilities
|
||||
LIBS+=../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "room_api.hpp"
|
||||
|
||||
#include "room_manager.hpp"
|
||||
#include "room_data.hpp"
|
||||
|
||||
static int getType(lua_State* L) {
|
||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
lua_pushinteger(L, static_cast<int>(room->type));
|
||||
return 1;
|
||||
}
|
||||
|
||||
//TODO: parameters
|
||||
|
||||
static int getRegionPager(lua_State* L) {
|
||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
lua_pushlightuserdata(L, reinterpret_cast<void*>(&room->pager));
|
||||
return 1;
|
||||
}
|
||||
|
||||
//RoomManager only
|
||||
static int getRoom(lua_State* L) {
|
||||
//get the room manager
|
||||
lua_pushstring(L, ROOM_MANAGER_PSEUDOINDEX);
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
RoomManager* roomMgr = reinterpret_cast<RoomManager*>(lua_touserdata(L, -1));
|
||||
|
||||
//push the room and return it
|
||||
lua_pushlightuserdata(L, reinterpret_cast<void*>( roomMgr->GetRoom(lua_tointeger(L, -2)) ));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg roomlib[] = {
|
||||
{"gettype",getType},
|
||||
{"getregionpager",getRegionPager},
|
||||
{"getroom",getRoom},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
LUAMOD_API int luaopen_roomapi(lua_State* L) {
|
||||
luaL_newlib(L, roomlib);
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef ROOMAPI_HPP_
|
||||
#define ROOMAPI_HPP_
|
||||
|
||||
#include "lua/lua.hpp"
|
||||
|
||||
#define LUA_ROOMLIBNAME "room"
|
||||
LUAMOD_API int luaopen_roomapi(lua_State* L);
|
||||
|
||||
#endif
|
||||
@@ -28,13 +28,15 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#define ROOM_MANAGER_PSEUDOINDEX "RoomManager"
|
||||
|
||||
class RoomManager {
|
||||
public:
|
||||
RoomManager() = default;
|
||||
~RoomManager() = default;
|
||||
|
||||
//public access methods
|
||||
//TODO
|
||||
//TODO: Fill this out
|
||||
|
||||
//accessors and mutators
|
||||
RoomData* GetRoom(int uid);
|
||||
|
||||
@@ -76,6 +76,7 @@ void ServerApplication::Init(int argc, char** argv) {
|
||||
//Setup the objects
|
||||
//-------------------------
|
||||
|
||||
//set the hooks
|
||||
accountMgr.SetDatabase(database);
|
||||
characterMgr.SetDatabase(database);
|
||||
|
||||
@@ -83,7 +84,14 @@ void ServerApplication::Init(int argc, char** argv) {
|
||||
roomMgr.SetLuaState(luaState);
|
||||
enemyMgr.SetLuaState(luaState);
|
||||
|
||||
std::cout << "Internal managers ready" << std::endl;
|
||||
std::cout << "Internal managers set" << std::endl;
|
||||
|
||||
//register the "globals"
|
||||
lua_pushstring(luaState, ROOM_MANAGER_PSEUDOINDEX);
|
||||
lua_pushlightuserdata(luaState, &roomMgr);
|
||||
lua_settable(luaState, LUA_REGISTRYINDEX);
|
||||
|
||||
std::cout << "Internal managers registered with lua" << std::endl;
|
||||
|
||||
//-------------------------
|
||||
//Run the startup scripts
|
||||
@@ -110,6 +118,7 @@ void ServerApplication::Init(int argc, char** argv) {
|
||||
std::cout << "\tRegion Format: " << REGION_WIDTH << ", " << REGION_HEIGHT << ", " << REGION_DEPTH << std::endl;
|
||||
std::cout << "\tRegion Content Footprint: " << REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) << std::endl;
|
||||
std::cout << "\tPACKET_BUFFER_SIZE (max size): " << PACKET_BUFFER_SIZE << std::endl;
|
||||
std::cout << "\tMAX_PACKET_SIZE: " << MAX_PACKET_SIZE << std::endl;
|
||||
|
||||
//-------------------------
|
||||
//finalize the startup
|
||||
@@ -121,16 +130,7 @@ void ServerApplication::Init(int argc, char** argv) {
|
||||
//debugging
|
||||
//-------------------------
|
||||
|
||||
std::cout << "Debugging dump:" << std::endl;
|
||||
std::cout << "\tMAX_PACKET_SIZE:\t\t" << MAX_PACKET_SIZE << std::endl;
|
||||
std::cout << "\tsizeof(SerialPacket):\t\t" << sizeof(SerialPacket) << std::endl;
|
||||
std::cout << "\tsizeof(CharacterPacket):\t" << sizeof(CharacterPacket) << std::endl;
|
||||
std::cout << "\t\tsizeof(Statistics):\t" << sizeof(Statistics) << std::endl;
|
||||
std::cout << "\tsizeof(ClientPacket):\t\t" << sizeof(ClientPacket) << std::endl;
|
||||
std::cout << "\tsizeof(CombatPacket):\t\t" << sizeof(CombatPacket) << std::endl;
|
||||
std::cout << "\tsizeof(EnemyPacket):\t\t" << sizeof(EnemyPacket) << std::endl;
|
||||
std::cout << "\tsizeof(RegionPacket):\t\t" << sizeof(RegionPacket) << std::endl;
|
||||
std::cout << "\tsizeof(ServerPacket):\t\t" << sizeof(ServerPacket) << std::endl;
|
||||
//...
|
||||
}
|
||||
|
||||
void ServerApplication::Proc() {
|
||||
|
||||
Reference in New Issue
Block a user