Implemented a basic API for the server's rooms
This commit is contained in:
@@ -66,7 +66,8 @@ static int getDepth(lua_State* L) {
|
|||||||
|
|
||||||
static int load(lua_State* L) {
|
static int load(lua_State* L) {
|
||||||
//TODO: fill this
|
//TODO: fill this
|
||||||
return 0;
|
lua_pushboolean(L, false);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int save(lua_State* L) {
|
static int save(lua_State* L) {
|
||||||
|
|||||||
@@ -4,33 +4,17 @@ print("Lua script check (./rsc)")
|
|||||||
--Map API overrides
|
--Map API overrides
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
function map.create(region)
|
function region.create(r)
|
||||||
for i = 1, map.getregionwidth() do
|
for i = 1, region.getwidth() do
|
||||||
for j = 1, map.getregionheight() do
|
for j = 1, region.getheight() do
|
||||||
if math.abs(map.getx(region) + i -1) == math.abs(map.gety(region) + j -1) then
|
if math.abs(region.getx(r) + i -1) == math.abs(region.gety(r) + j -1) then
|
||||||
map.settile(region, i, j, 1, 50)
|
region.settile(r, i, j, 1, 50)
|
||||||
else
|
else
|
||||||
map.settile(region, i, j, 1, 14)
|
region.settile(r, i, j, 1, 14)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function map.unload(region)
|
--signal
|
||||||
--
|
region.settile(r, 4, 5, 2, 86)
|
||||||
end
|
end
|
||||||
|
|
||||||
function map.load(region, dir)
|
|
||||||
--return true if file loaded, otherwise return false
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
function map.save(region, dir)
|
|
||||||
--
|
|
||||||
end
|
|
||||||
|
|
||||||
-------------------------
|
|
||||||
--Enemy API
|
|
||||||
-------------------------
|
|
||||||
|
|
||||||
--TODO
|
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#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
|
LIBS+=../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
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>
|
#include <map>
|
||||||
|
|
||||||
|
#define ROOM_MANAGER_PSEUDOINDEX "RoomManager"
|
||||||
|
|
||||||
class RoomManager {
|
class RoomManager {
|
||||||
public:
|
public:
|
||||||
RoomManager() = default;
|
RoomManager() = default;
|
||||||
~RoomManager() = default;
|
~RoomManager() = default;
|
||||||
|
|
||||||
//public access methods
|
//public access methods
|
||||||
//TODO
|
//TODO: Fill this out
|
||||||
|
|
||||||
//accessors and mutators
|
//accessors and mutators
|
||||||
RoomData* GetRoom(int uid);
|
RoomData* GetRoom(int uid);
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ void ServerApplication::Init(int argc, char** argv) {
|
|||||||
//Setup the objects
|
//Setup the objects
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
|
//set the hooks
|
||||||
accountMgr.SetDatabase(database);
|
accountMgr.SetDatabase(database);
|
||||||
characterMgr.SetDatabase(database);
|
characterMgr.SetDatabase(database);
|
||||||
|
|
||||||
@@ -83,7 +84,14 @@ void ServerApplication::Init(int argc, char** argv) {
|
|||||||
roomMgr.SetLuaState(luaState);
|
roomMgr.SetLuaState(luaState);
|
||||||
enemyMgr.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
|
//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 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 << "\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 << "\tPACKET_BUFFER_SIZE (max size): " << PACKET_BUFFER_SIZE << std::endl;
|
||||||
|
std::cout << "\tMAX_PACKET_SIZE: " << MAX_PACKET_SIZE << std::endl;
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//finalize the startup
|
//finalize the startup
|
||||||
@@ -121,16 +130,7 @@ void ServerApplication::Init(int argc, char** argv) {
|
|||||||
//debugging
|
//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() {
|
void ServerApplication::Proc() {
|
||||||
|
|||||||
Reference in New Issue
Block a user