summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/permissionmanager.cpp3
-rw-r--r--src/common/resourcemanager.cpp29
-rw-r--r--src/common/resourcemanager.hpp3
-rw-r--r--src/game-server/itemmanager.cpp3
-rw-r--r--src/game-server/mapmanager.cpp3
-rw-r--r--src/game-server/mapreader.cpp6
-rw-r--r--src/game-server/monstermanager.cpp3
-rw-r--r--src/game-server/skillmanager.cpp3
-rw-r--r--src/game-server/statusmanager.cpp3
-rw-r--r--src/scripting/lua.cpp2
-rw-r--r--src/scripting/script.cpp15
11 files changed, 24 insertions, 49 deletions
diff --git a/src/common/permissionmanager.cpp b/src/common/permissionmanager.cpp
index 549e3628..8483e42e 100644
--- a/src/common/permissionmanager.cpp
+++ b/src/common/permissionmanager.cpp
@@ -53,8 +53,7 @@ void PermissionManager::initialize(const std::string & file)
void PermissionManager::reload()
{
int size;
- // Note: The file is checked for UTF-8 BOM.
- char *data = ResourceManager::loadFile(permissionFile, size, true);
+ char *data = ResourceManager::loadFile(permissionFile, size);
if (!data) {
LOG_ERROR("Permission Manager: Could not find "
diff --git a/src/common/resourcemanager.cpp b/src/common/resourcemanager.cpp
index 5a56479b..8db45465 100644
--- a/src/common/resourcemanager.cpp
+++ b/src/common/resourcemanager.cpp
@@ -64,11 +64,10 @@ std::string ResourceManager::resolve(const std::string &path)
return std::string();
}
-char *ResourceManager::loadFile(const std::string &fileName, int &fileSize,
- bool removeBOM)
+char *ResourceManager::loadFile(const std::string &fileName, int &fileSize)
{
// Attempt to open the specified file using PhysicsFS
- PHYSFS_file* file = PHYSFS_openRead(fileName.c_str());
+ PHYSFS_file *file = PHYSFS_openRead(fileName.c_str());
// If the handler is an invalid pointer indicate failure
if (file == NULL)
@@ -81,30 +80,6 @@ char *ResourceManager::loadFile(const std::string &fileName, int &fileSize,
// Get the size of the file
fileSize = PHYSFS_fileLength(file);
- if (removeBOM)
- {
- // Inspired by BOMstrip from Peter Pentchev, 2008, public domain.
- const char utf8Bom[] = "\xef\xbb\xbf";
- const int bomLength = sizeof(utf8Bom);
- char bomBuffer[bomLength];
- PHYSFS_read(file, bomBuffer, 1, bomLength);
-
- std::istringstream iss(std::string(bomBuffer, bomLength));
- std::string line;
-
- // if we find a BOM, then we remove it from the buffer
- if (std::getline(iss, line) && !line.substr(0, 3).compare(utf8Bom))
- {
- LOG_INFO("Found a Byte Order Mask (BOM) in '" << fileName);
- fileSize = fileSize - bomLength;
- }
- else
- {
- // No BOM, we get back to the file start.
- PHYSFS_seek(file, 0);
- }
- }
-
// Allocate memory and load the file
char *buffer = (char *) malloc(fileSize + 1);
if (PHYSFS_read(file, buffer, 1, fileSize) != fileSize)
diff --git a/src/common/resourcemanager.hpp b/src/common/resourcemanager.hpp
index f5b1b1ef..55bfe7df 100644
--- a/src/common/resourcemanager.hpp
+++ b/src/common/resourcemanager.hpp
@@ -52,8 +52,7 @@ namespace ResourceManager
* or <code>NULL</code> on failure.
* @note The array contains an extra \0 character at position fileSize.
*/
- char *loadFile(const std::string &fileName, int &fileSize,
- bool removeBOM = false);
+ char *loadFile(const std::string &fileName, int &fileSize);
}
#endif
diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp
index 275f24b0..e7069636 100644
--- a/src/game-server/itemmanager.cpp
+++ b/src/game-server/itemmanager.cpp
@@ -46,8 +46,7 @@ void ItemManager::initialize(const std::string &file)
void ItemManager::reload()
{
int size;
- // Note: The file is checked for UTF-8 BOM.
- char *data = ResourceManager::loadFile(itemReferenceFile, size, true);
+ char *data = ResourceManager::loadFile(itemReferenceFile, size);
std::string absPathFile = ResourceManager::resolve(itemReferenceFile);
diff --git a/src/game-server/mapmanager.cpp b/src/game-server/mapmanager.cpp
index 562abb0d..f2f6b396 100644
--- a/src/game-server/mapmanager.cpp
+++ b/src/game-server/mapmanager.cpp
@@ -45,8 +45,7 @@ unsigned int MapManager::initialize(const std::string &mapReferenceFile)
unsigned int loadedMaps = 0;
int size;
- // Note: The file is checked for UTF-8 BOM.
- char *data = ResourceManager::loadFile(mapReferenceFile, size, true);
+ char *data = ResourceManager::loadFile(mapReferenceFile, size);
std::string absPathFile = ResourceManager::resolve(mapReferenceFile);
diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp
index 80885821..3e1065d2 100644
--- a/src/game-server/mapreader.cpp
+++ b/src/game-server/mapreader.cpp
@@ -39,12 +39,10 @@
static std::vector< int > tilesetFirstGids;
-bool MapReader::readMap(const std::string &filename, MapComposite
-*composite)
+bool MapReader::readMap(const std::string &filename, MapComposite *composite)
{
int fileSize;
- // Note: The file is checked for UTF-8 BOM.
- char *buffer = ResourceManager::loadFile(filename, fileSize, true);
+ char *buffer = ResourceManager::loadFile(filename, fileSize);
if (buffer == NULL)
{
diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp
index 7396744d..f73a1bec 100644
--- a/src/game-server/monstermanager.cpp
+++ b/src/game-server/monstermanager.cpp
@@ -63,8 +63,7 @@ void MonsterManager::initialize(const std::string &file)
void MonsterManager::reload()
{
int size;
- // Note: The file is checked for UTF-8 BOM.
- char *data = ResourceManager::loadFile(monsterReferenceFile, size, true);
+ char *data = ResourceManager::loadFile(monsterReferenceFile, size);
std::string absPathFile = ResourceManager::resolve(monsterReferenceFile);
diff --git a/src/game-server/skillmanager.cpp b/src/game-server/skillmanager.cpp
index 48319198..ccf15923 100644
--- a/src/game-server/skillmanager.cpp
+++ b/src/game-server/skillmanager.cpp
@@ -45,8 +45,7 @@ void SkillManager::reload()
*/
int size;
- // Note: The file is checked for UTF-8 BOM.
- char *data = ResourceManager::loadFile(skillReferenceFile, size, true);
+ char *data = ResourceManager::loadFile(skillReferenceFile, size);
std::string absPathFile = ResourceManager::resolve(skillReferenceFile);
diff --git a/src/game-server/statusmanager.cpp b/src/game-server/statusmanager.cpp
index 89621806..2ca5a8a3 100644
--- a/src/game-server/statusmanager.cpp
+++ b/src/game-server/statusmanager.cpp
@@ -43,8 +43,7 @@ void StatusManager::initialize(const std::string &file)
void StatusManager::reload()
{
int size;
- // Note: The file is checked for UTF-8 BOM.
- char *data = ResourceManager::loadFile(statusReferenceFile, size, true);
+ char *data = ResourceManager::loadFile(statusReferenceFile, size);
std::string absPathFile = ResourceManager::resolve(statusReferenceFile);
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index da47d931..507b348f 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -1628,7 +1628,7 @@ LuaScript::LuaScript():
lua_pop(mState, 2);
// Put some callback functions in the scripting environment.
- static luaL_reg const callbacks[] = {
+ static luaL_Reg const callbacks[] = {
{ "npc_create", &npc_create },
{ "npc_message", &npc_message },
{ "npc_choice", &npc_choice },
diff --git a/src/scripting/script.cpp b/src/scripting/script.cpp
index 01d237f3..fe3c5d8d 100644
--- a/src/scripting/script.cpp
+++ b/src/scripting/script.cpp
@@ -27,6 +27,8 @@
#include <cstdlib>
#include <map>
+#include <string.h>
+
typedef std::map< std::string, Script::Factory > Engines;
static Engines *engines = NULL;
@@ -70,15 +72,22 @@ void Script::update()
execute();
}
+static char *skipPotentialBom(char *text)
+{
+ // Based on the C version of bomstrip
+ const char * const utf8Bom = "\xef\xbb\xbf";
+ const int bomLength = strlen(utf8Bom);
+ return (strncmp(text, utf8Bom, bomLength) == 0) ? text + bomLength : text;
+}
+
bool Script::loadFile(const std::string &name)
{
int size;
- // Note: The file is checked for UTF-8 BOM.
- char *buffer = ResourceManager::loadFile(name, size, true);
+ char *buffer = ResourceManager::loadFile(name, size);
if (buffer)
{
mScriptFile = name;
- load(buffer);
+ load(skipPotentialBom(buffer));
free(buffer);
return true;
} else {