From 83a85531ae789e2f30da2379990899f815f53ff1 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 10 Feb 2019 18:16:04 -0500 Subject: Added new element, added server-specific code for networking Added a new element for client gui: iguicombobox Added a part of the engine specifically for the server so server is no longer just a stripped down client --- src/server/lua_api/load_game.cpp | 27 +++++++++++++++++ src/server/lua_api/load_game.hpp | 13 +++++++++ src/server/lua_api/load_io.cpp | 63 ++++++++++++++++++++++++++++++++++++++++ src/server/lua_api/load_io.hpp | 13 +++++++++ 4 files changed, 116 insertions(+) create mode 100644 src/server/lua_api/load_game.cpp create mode 100644 src/server/lua_api/load_game.hpp create mode 100644 src/server/lua_api/load_io.cpp create mode 100644 src/server/lua_api/load_io.hpp (limited to 'src/server') diff --git a/src/server/lua_api/load_game.cpp b/src/server/lua_api/load_game.cpp new file mode 100644 index 0000000..4464dd7 --- /dev/null +++ b/src/server/lua_api/load_game.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +#include +extern "C" { + #include + #include + #include +} + +extern bool game_active; + +//exit() +int exit_game(lua_State *L){ + game_active = false; + return 0; +} + +void load_gamefuncs(lua_State* L){ + lua_newtable(L); + lua_setglobal(L,"GAME"); + + lua_getglobal(L,"GAME"); + lua_pushcfunction(L,exit_game); + lua_setfield(L,-2,"exit"); + lua_pop(L,1); +} diff --git a/src/server/lua_api/load_game.hpp b/src/server/lua_api/load_game.hpp new file mode 100644 index 0000000..7937b15 --- /dev/null +++ b/src/server/lua_api/load_game.hpp @@ -0,0 +1,13 @@ +#ifndef __H_loadgame +#define __H_loadgame +#include +#include +#include +extern "C" { + #include + #include + #include +} + +void load_gamefuncs(lua_State* L); +#endif diff --git a/src/server/lua_api/load_io.cpp b/src/server/lua_api/load_io.cpp new file mode 100644 index 0000000..af471b1 --- /dev/null +++ b/src/server/lua_api/load_io.cpp @@ -0,0 +1,63 @@ + +extern "C" { + #include + #include + #include +} +#include +//STL +#include +#include +#include + +#define epath "../data" +#define epathlen sizeof(epath) + +/*Add an io.dir(path) function, which lists all the files in (path)*/ +int dirpath(lua_State *L){ + if(!lua_isstring(L,-1)){ + lua_pushstring(L,"io.dir() requires a string as argument #1"); + lua_error(L); + } + size_t pathstrlen; + const char *pathstr = lua_tolstring(L,-1,&pathstrlen); + //printf("got pathstr: %s\n",pathstr); + //char tpathstr[pathstrlen + epathlen + 1 + 1]; //+1 for null, +1 for / + //memcpy(tpathstr,epath,epathlen); + //tpathstr[epathlen] = '/'; + //memcpy(tpathstr+epathlen,pathstr,pathstrlen); + //tpathstr[pathstrlen + epathlen + 1] = '\0'; + //printf("tpathstr is: \"%s\"\n",tpathstr); + //lua_pop(L,1); + DIR *dir; + struct dirent *ent; + const char *tpathstr = pathstr; + dir = opendir(tpathstr); + if(dir == NULL){ + perror("Cannot open"); + lua_pushstring(L,"Failed to open directory: "); + lua_pushstring(L,tpathstr); + lua_concat(L,2); + lua_error(L); + } + int i = 1; + ent = readdir(dir); + lua_newtable(L); + while( (ent = readdir(dir)) != NULL){ + lua_pushinteger(L,i); + lua_pushstring(L,ent->d_name); + lua_settable(L,-3); + i++; + } + closedir(dir); + return 1; +} + + +void load_iofuncs(lua_State* L){ + lua_getglobal(L,"io"); + + lua_pushcfunction(L,dirpath); + lua_setfield(L,-2,"dir"); + lua_pop(L,1); +} diff --git a/src/server/lua_api/load_io.hpp b/src/server/lua_api/load_io.hpp new file mode 100644 index 0000000..19f7a77 --- /dev/null +++ b/src/server/lua_api/load_io.hpp @@ -0,0 +1,13 @@ +#ifndef __H_loadio +#define __H_loadio +#include +#include +#include +extern "C" { + #include + #include + #include +} + +void load_iofuncs(lua_State* L); +#endif -- cgit v1.2.3-70-g09d2