Removed some annoying debugging messages
This commit is contained in:
@@ -27,11 +27,6 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
//debugging
|
|
||||||
#include <iostream>
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -350,15 +345,6 @@ void InWorld::HandleRegionContent(NetworkPacket packet) {
|
|||||||
}
|
}
|
||||||
regionPager.PushRegion(packet.regionInfo.region);
|
regionPager.PushRegion(packet.regionInfo.region);
|
||||||
packet.regionInfo.region = nullptr;
|
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
|
//prune distant regions
|
||||||
for (auto it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); /* EMPTY */) {
|
for (auto it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); /* EMPTY */) {
|
||||||
if (CheckBufferDistance(*it) > 2) {
|
if (CheckBufferDistance(*it) > 2) {
|
||||||
//debugging
|
|
||||||
cout << "unloading: " << (*it)->GetX() << ", " << (*it)->GetY() << endl;
|
|
||||||
|
|
||||||
regionPager.UnloadRegion((*it)->GetX(), (*it)->GetY());
|
regionPager.UnloadRegion((*it)->GetX(), (*it)->GetY());
|
||||||
|
|
||||||
//reset
|
//reset
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
print("Lua script check OK (./rsc)")
|
print("Lua script check OK (./rsc)")
|
||||||
|
|
||||||
function Region.Create(r)
|
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 i = 1, Region.GetWidth(r) do
|
||||||
for j = 1, Region.GetHeight(r) do
|
for j = 1, Region.GetHeight(r) do
|
||||||
if math.abs(i) == math.abs(j) then
|
if math.abs(i) == math.abs(j) then
|
||||||
@@ -11,19 +11,19 @@ function Region.Create(r)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
print("done")
|
-- print("done")
|
||||||
end
|
end
|
||||||
|
|
||||||
function Region.Unload(r)
|
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
|
end
|
||||||
|
|
||||||
--return true if file loaded, otherwise return false
|
--return true if file loaded, otherwise return false
|
||||||
function Region.Load(r, saveDir)
|
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
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function Region.Save(r, saveDir)
|
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
|
end
|
||||||
|
|||||||
@@ -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
|
* 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
|
||||||
@@ -26,31 +26,13 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
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
|
//Define the public members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void ServerApplication::Init(int argc, char** argv) {
|
void ServerApplication::Init(int argc, char** argv) {
|
||||||
cout << "Beginning startup" << endl;
|
std::cout << "Beginning startup" << std::endl;
|
||||||
|
|
||||||
//initial setup
|
//initial setup
|
||||||
ClientEntry::uidCounter = 0;
|
ClientEntry::uidCounter = 0;
|
||||||
@@ -59,43 +41,43 @@ void ServerApplication::Init(int argc, char** argv) {
|
|||||||
|
|
||||||
//Init SDL
|
//Init SDL
|
||||||
if (SDL_Init(0)) {
|
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
|
//Init SDL_net
|
||||||
if (SDLNet_Init()) {
|
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);
|
network.Open(config.Int("server.port"), PACKET_BUFFER_SIZE);
|
||||||
cout << "Initialized SDL_net" << endl;
|
std::cout << "Initialized SDL_net" << std::endl;
|
||||||
|
|
||||||
//Init SQL
|
//Init SQL
|
||||||
int ret = sqlite3_open_v2(config["server.dbname"].c_str(), &database, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, nullptr);
|
int ret = sqlite3_open_v2(config["server.dbname"].c_str(), &database, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, nullptr);
|
||||||
if (ret != SQLITE_OK || !database) {
|
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
|
//setup the database
|
||||||
if (runSQLScript(database, config["dir.scripts"] + "setup_server.sql")) {
|
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
|
//lua
|
||||||
luaState = luaL_newstate();
|
luaState = luaL_newstate();
|
||||||
if (!luaState) {
|
if (!luaState) {
|
||||||
throw(runtime_error("Failed to initialize lua"));
|
throw(std::runtime_error("Failed to initialize lua"));
|
||||||
}
|
}
|
||||||
luaL_openlibs(luaState);
|
luaL_openlibs(luaState);
|
||||||
cout << "Initialized lua" << endl;
|
std::cout << "Initialized lua" << std::endl;
|
||||||
|
|
||||||
//run the startup script
|
//run the startup script
|
||||||
if (luaL_dofile(luaState, (config["dir.scripts"] + "setup_server.lua").c_str())) {
|
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
|
//setup the map object
|
||||||
regionPager.GetAllocator()->SetLuaState(luaState);
|
regionPager.GetAllocator()->SetLuaState(luaState);
|
||||||
@@ -105,12 +87,12 @@ void ServerApplication::Init(int argc, char** argv) {
|
|||||||
//TODO: pass args to the generator & format as needed
|
//TODO: pass args to the generator & format as needed
|
||||||
//NOTE: I might need to rearrange the init process so that lua & SQL can interact
|
//NOTE: I might need to rearrange the init process so that lua & SQL can interact
|
||||||
// with the map system as needed.
|
// with the map system as needed.
|
||||||
cout << "Initialized the map system" << endl;
|
std::cout << "Initialized the map system" << std::endl;
|
||||||
cout << "\tsizeof(NetworkPacket): " << sizeof(NetworkPacket) << endl;
|
std::cout << "\tsizeof(NetworkPacket): " << sizeof(NetworkPacket) << std::endl;
|
||||||
cout << "\tPACKET_BUFFER_SIZE: " << PACKET_BUFFER_SIZE << endl;
|
std::cout << "\tPACKET_BUFFER_SIZE: " << PACKET_BUFFER_SIZE << std::endl;
|
||||||
|
|
||||||
//finalize the startup
|
//finalize the startup
|
||||||
cout << "Startup completed successfully" << endl;
|
std::cout << "Startup completed successfully" << std::endl;
|
||||||
|
|
||||||
//debugging
|
//debugging
|
||||||
//
|
//
|
||||||
@@ -135,7 +117,7 @@ void ServerApplication::Loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ServerApplication::Quit() {
|
void ServerApplication::Quit() {
|
||||||
cout << "Shutting down" << endl;
|
std::cout << "Shutting down" << std::endl;
|
||||||
//empty the members
|
//empty the members
|
||||||
regionPager.UnloadAll();
|
regionPager.UnloadAll();
|
||||||
|
|
||||||
@@ -145,7 +127,7 @@ void ServerApplication::Quit() {
|
|||||||
network.Close();
|
network.Close();
|
||||||
SDLNet_Quit();
|
SDLNet_Quit();
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
cout << "Shutdown finished" << endl;
|
std::cout << "Shutdown finished" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -183,7 +165,7 @@ void ServerApplication::HandlePacket(NetworkPacket packet) {
|
|||||||
break;
|
break;
|
||||||
//handle errors
|
//handle errors
|
||||||
default:
|
default:
|
||||||
throw(runtime_error("Unknown NetworkPacket::Type encountered"));
|
throw(std::runtime_error("Unknown NetworkPacket::Type encountered"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,7 +203,7 @@ void ServerApplication::HandleJoinRequest(NetworkPacket packet) {
|
|||||||
|
|
||||||
//finished this routine
|
//finished this routine
|
||||||
ClientEntry::uidCounter++;
|
ClientEntry::uidCounter++;
|
||||||
cout << "Connect, total: " << clientMap.size() << endl;
|
std::cout << "Connect, total: " << clientMap.size() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerApplication::HandleDisconnect(NetworkPacket packet) {
|
void ServerApplication::HandleDisconnect(NetworkPacket packet) {
|
||||||
@@ -255,7 +237,7 @@ void ServerApplication::HandleDisconnect(NetworkPacket packet) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//finished this routine
|
//finished this routine
|
||||||
cout << "Disconnect, total: " << clientMap.size() << endl;
|
std::cout << "Disconnect, total: " << clientMap.size() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerApplication::HandleSynchronize(NetworkPacket packet) {
|
void ServerApplication::HandleSynchronize(NetworkPacket packet) {
|
||||||
@@ -290,7 +272,7 @@ void ServerApplication::HandleShutdown(NetworkPacket packet) {
|
|||||||
PumpPacket(packet);
|
PumpPacket(packet);
|
||||||
|
|
||||||
//finished this routine
|
//finished this routine
|
||||||
cout << "Shutdown signal accepted" << endl;
|
std::cout << "Shutdown signal accepted" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerApplication::HandlePlayerNew(NetworkPacket packet) {
|
void ServerApplication::HandlePlayerNew(NetworkPacket packet) {
|
||||||
|
|||||||
@@ -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
|
* 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,7 @@
|
|||||||
#define SERVERAPPLICATION_HPP_
|
#define SERVERAPPLICATION_HPP_
|
||||||
|
|
||||||
//server specific stuff
|
//server specific stuff
|
||||||
|
#include "server_utility.hpp"
|
||||||
#include "client_entry.hpp"
|
#include "client_entry.hpp"
|
||||||
#include "player_entry.hpp"
|
#include "player_entry.hpp"
|
||||||
|
|
||||||
@@ -47,7 +48,6 @@
|
|||||||
|
|
||||||
//STL
|
//STL
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
//The main application class
|
//The main application class
|
||||||
class ServerApplication {
|
class ServerApplication {
|
||||||
|
|||||||
@@ -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 <fstream>
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -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 <string>
|
||||||
|
|
||||||
|
int runSQLScript(sqlite3* db, std::string fname);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user