diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 38b39c1..62ad57c 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -27,11 +27,6 @@ #include #include -//debugging -#include -using std::cout; -using std::endl; - //------------------------- //Public access members //------------------------- @@ -350,15 +345,6 @@ void InWorld::HandleRegionContent(NetworkPacket packet) { } regionPager.PushRegion(packet.regionInfo.region); packet.regionInfo.region = nullptr; - - //debugging - cout << "Received region: " << packet.regionInfo.x << ", " << packet.regionInfo.y << endl; - if (regionPager.FindRegion(packet.regionInfo.x, packet.regionInfo.y)) { - cout << "Success" << endl; - } - else { - cout << "Failure" << endl; - } } //------------------------- @@ -472,9 +458,6 @@ void InWorld::UpdateMap() { //prune distant regions for (auto it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); /* EMPTY */) { if (CheckBufferDistance(*it) > 2) { - //debugging - cout << "unloading: " << (*it)->GetX() << ", " << (*it)->GetY() << endl; - regionPager.UnloadRegion((*it)->GetX(), (*it)->GetY()); //reset diff --git a/rsc/scripts/setup_server.lua b/rsc/scripts/setup_server.lua index c201054..1a7cc8a 100644 --- a/rsc/scripts/setup_server.lua +++ b/rsc/scripts/setup_server.lua @@ -1,7 +1,7 @@ print("Lua script check OK (./rsc)") function Region.Create(r) - print("Region:Create(r", Region.GetX(r), Region.GetY(r), ")") +-- print("Region:Create(r", Region.GetX(r), Region.GetY(r), ")") for i = 1, Region.GetWidth(r) do for j = 1, Region.GetHeight(r) do if math.abs(i) == math.abs(j) then @@ -11,19 +11,19 @@ function Region.Create(r) end end end - print("done") +-- print("done") end function Region.Unload(r) - print("Region:Unload(r", Region.GetX(r), Region.GetY(r), ")") +-- print("Region:Unload(r", Region.GetX(r), Region.GetY(r), ")") end --return true if file loaded, otherwise return false function Region.Load(r, saveDir) - print("Region:Load(r,", saveDir, Region.GetX(r), Region.GetY(r), ")") +-- print("Region:Load(r,", saveDir, Region.GetX(r), Region.GetY(r), ")") return false end function Region.Save(r, saveDir) - print("Region:Save(r,", saveDir, Region.GetX(r), Region.GetY(r), ")") +-- print("Region:Save(r,", saveDir, Region.GetX(r), Region.GetY(r), ")") end diff --git a/server/server_application.cpp b/server/server_application.cpp index 56a9b24..78e42b7 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 @@ -26,31 +26,13 @@ #include #include #include -#include - -using namespace std; - -int runSQLScript(sqlite3* db, std::string fname) { - ifstream is(fname); - if (!is.is_open()) { - return -1; - } - string script; - getline(is, script, '\0'); - is.close(); - //NOTE: flesh out this error if needed - if (sqlite3_exec(db, script.c_str(), nullptr, nullptr, nullptr) != SQLITE_OK) { - return -2; - } - return 0; -} //------------------------- //Define the public members //------------------------- void ServerApplication::Init(int argc, char** argv) { - cout << "Beginning startup" << endl; + std::cout << "Beginning startup" << std::endl; //initial setup ClientEntry::uidCounter = 0; @@ -59,43 +41,43 @@ void ServerApplication::Init(int argc, char** argv) { //Init SDL if (SDL_Init(0)) { - throw(runtime_error("Failed to initialize SDL")); + throw(std::runtime_error("Failed to initialize SDL")); } - cout << "Initialized SDL" << endl; + std::cout << "Initialized SDL" << std::endl; //Init SDL_net if (SDLNet_Init()) { - throw(runtime_error("Failed to initialize SDL_net")); + throw(std::runtime_error("Failed to initialize SDL_net")); } network.Open(config.Int("server.port"), PACKET_BUFFER_SIZE); - cout << "Initialized SDL_net" << endl; + std::cout << "Initialized SDL_net" << std::endl; //Init SQL int ret = sqlite3_open_v2(config["server.dbname"].c_str(), &database, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, nullptr); if (ret != SQLITE_OK || !database) { - throw(runtime_error(string() + "Failed to initialize SQL: " + sqlite3_errmsg(database) )); + throw(std::runtime_error(std::string() + "Failed to initialize SQL: " + sqlite3_errmsg(database) )); } - cout << "Initialized SQL" << endl; + std::cout << "Initialized SQL" << std::endl; //setup the database if (runSQLScript(database, config["dir.scripts"] + "setup_server.sql")) { - throw(runtime_error("Failed to initialize SQL's setup script")); + throw(std::runtime_error("Failed to initialize SQL's setup script")); } - cout << "Initialized SQL's setup script" << endl; + std::cout << "Initialized SQL's setup script" << std::endl; //lua luaState = luaL_newstate(); if (!luaState) { - throw(runtime_error("Failed to initialize lua")); + throw(std::runtime_error("Failed to initialize lua")); } luaL_openlibs(luaState); - cout << "Initialized lua" << endl; + std::cout << "Initialized lua" << std::endl; //run the startup script if (luaL_dofile(luaState, (config["dir.scripts"] + "setup_server.lua").c_str())) { - throw(runtime_error(string() + "Failed to initialize lua's setup script: " + lua_tostring(luaState, -1) )); + throw(std::runtime_error(std::string() + "Failed to initialize lua's setup script: " + lua_tostring(luaState, -1) )); } - cout << "Initialized lua's setup script" << endl; + std::cout << "Initialized lua's setup script" << std::endl; //setup the map object regionPager.GetAllocator()->SetLuaState(luaState); @@ -105,12 +87,12 @@ void ServerApplication::Init(int argc, char** argv) { //TODO: pass args to the generator & format as needed //NOTE: I might need to rearrange the init process so that lua & SQL can interact // with the map system as needed. - cout << "Initialized the map system" << endl; - cout << "\tsizeof(NetworkPacket): " << sizeof(NetworkPacket) << endl; - cout << "\tPACKET_BUFFER_SIZE: " << PACKET_BUFFER_SIZE << endl; + std::cout << "Initialized the map system" << std::endl; + std::cout << "\tsizeof(NetworkPacket): " << sizeof(NetworkPacket) << std::endl; + std::cout << "\tPACKET_BUFFER_SIZE: " << PACKET_BUFFER_SIZE << std::endl; //finalize the startup - cout << "Startup completed successfully" << endl; + std::cout << "Startup completed successfully" << std::endl; //debugging // @@ -135,7 +117,7 @@ void ServerApplication::Loop() { } void ServerApplication::Quit() { - cout << "Shutting down" << endl; + std::cout << "Shutting down" << std::endl; //empty the members regionPager.UnloadAll(); @@ -145,7 +127,7 @@ void ServerApplication::Quit() { network.Close(); SDLNet_Quit(); SDL_Quit(); - cout << "Shutdown finished" << endl; + std::cout << "Shutdown finished" << std::endl; } //------------------------- @@ -183,7 +165,7 @@ void ServerApplication::HandlePacket(NetworkPacket packet) { break; //handle errors default: - throw(runtime_error("Unknown NetworkPacket::Type encountered")); + throw(std::runtime_error("Unknown NetworkPacket::Type encountered")); break; } } @@ -221,7 +203,7 @@ void ServerApplication::HandleJoinRequest(NetworkPacket packet) { //finished this routine ClientEntry::uidCounter++; - cout << "Connect, total: " << clientMap.size() << endl; + std::cout << "Connect, total: " << clientMap.size() << std::endl; } void ServerApplication::HandleDisconnect(NetworkPacket packet) { @@ -255,7 +237,7 @@ void ServerApplication::HandleDisconnect(NetworkPacket packet) { }); //finished this routine - cout << "Disconnect, total: " << clientMap.size() << endl; + std::cout << "Disconnect, total: " << clientMap.size() << std::endl; } void ServerApplication::HandleSynchronize(NetworkPacket packet) { @@ -290,7 +272,7 @@ void ServerApplication::HandleShutdown(NetworkPacket packet) { PumpPacket(packet); //finished this routine - cout << "Shutdown signal accepted" << endl; + std::cout << "Shutdown signal accepted" << std::endl; } void ServerApplication::HandlePlayerNew(NetworkPacket packet) { diff --git a/server/server_application.hpp b/server/server_application.hpp index 8a10aa5..8aa7211 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 @@ -23,6 +23,7 @@ #define SERVERAPPLICATION_HPP_ //server specific stuff +#include "server_utility.hpp" #include "client_entry.hpp" #include "player_entry.hpp" @@ -47,7 +48,6 @@ //STL #include -#include //The main application class class ServerApplication { diff --git a/server/server_utility.cpp b/server/server_utility.cpp new file mode 100644 index 0000000..ebecbbd --- /dev/null +++ b/server/server_utility.cpp @@ -0,0 +1,40 @@ +/* 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 "server_utility.hpp" + +#include + + +int runSQLScript(sqlite3* db, std::string fname) { + std::ifstream is(fname); + if (!is.is_open()) { + return -1; + } + std::string script; + getline(is, script, '\0'); + is.close(); + //NOTE: flesh out this error if needed + if (sqlite3_exec(db, script.c_str(), nullptr, nullptr, nullptr) != SQLITE_OK) { + return -2; + } + return 0; +} \ No newline at end of file diff --git a/server/server_utility.hpp b/server/server_utility.hpp new file mode 100644 index 0000000..c0fe9b9 --- /dev/null +++ b/server/server_utility.hpp @@ -0,0 +1,31 @@ +/* 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 SERVERUTILITY_HPP_ +#define SERVERUTILITY_HPP_ + +#include "sqlite3/sqlite3.h" + +#include + +int runSQLScript(sqlite3* db, std::string fname); + +#endif