Replace instances of std::map<std::string, std::string> with StringMap

Also, clean up surrounding code style
Replace by-value parameter passing with const refs when possible
Fix post-increment of iterators
This commit is contained in:
kwolekr 2015-05-19 02:24:14 -04:00
parent 603297cc35
commit da34a2b33e
25 changed files with 180 additions and 193 deletions

@ -74,18 +74,14 @@ void BanManager::load()
void BanManager::save()
{
JMutexAutoLock lock(m_mutex);
infostream<<"BanManager: saving to "<<m_banfilepath<<std::endl;
infostream << "BanManager: saving to " << m_banfilepath << std::endl;
std::ostringstream ss(std::ios_base::binary);
for(std::map<std::string, std::string>::iterator
i = m_ips.begin();
i != m_ips.end(); i++)
{
ss << i->first << "|" << i->second << "\n";
}
for (StringMap::iterator it = m_ips.begin(); it != m_ips.end(); ++it)
ss << it->first << "|" << it->second << "\n";
if(!fs::safeWriteToFile(m_banfilepath, ss.str())) {
infostream<<"BanManager: failed saving to "<<m_banfilepath<<std::endl;
if (!fs::safeWriteToFile(m_banfilepath, ss.str())) {
infostream << "BanManager: failed saving to " << m_banfilepath << std::endl;
throw SerializationError("BanManager::save(): Couldn't write file");
}
@ -102,25 +98,23 @@ std::string BanManager::getBanDescription(const std::string &ip_or_name)
{
JMutexAutoLock lock(m_mutex);
std::string s = "";
for(std::map<std::string, std::string>::iterator
i = m_ips.begin();
i != m_ips.end(); i++)
{
if(i->first == ip_or_name || i->second == ip_or_name
|| ip_or_name == "")
s += i->first + "|" + i->second + ", ";
for (StringMap::iterator it = m_ips.begin(); it != m_ips.end(); ++it) {
if (it->first == ip_or_name || it->second == ip_or_name
|| ip_or_name == "") {
s += it->first + "|" + it->second + ", ";
}
s = s.substr(0, s.size()-2);
}
s = s.substr(0, s.size() - 2);
return s;
}
std::string BanManager::getBanName(const std::string &ip)
{
JMutexAutoLock lock(m_mutex);
std::map<std::string, std::string>::iterator i = m_ips.find(ip);
if(i == m_ips.end())
StringMap::iterator it = m_ips.find(ip);
if (it == m_ips.end())
return "";
return i->second;
return it->second;
}
void BanManager::add(const std::string &ip, const std::string &name)
@ -133,14 +127,11 @@ void BanManager::add(const std::string &ip, const std::string &name)
void BanManager::remove(const std::string &ip_or_name)
{
JMutexAutoLock lock(m_mutex);
for(std::map<std::string, std::string>::iterator
i = m_ips.begin();
i != m_ips.end();)
{
if((i->first == ip_or_name) || (i->second == ip_or_name)) {
m_ips.erase(i++);
for (StringMap::iterator it = m_ips.begin(); it != m_ips.end();) {
if ((it->first == ip_or_name) || (it->second == ip_or_name)) {
m_ips.erase(it++);
} else {
++i;
++it;
}
}
m_modified = true;

@ -20,8 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef BAN_HEADER
#define BAN_HEADER
#include <map>
#include <string>
#include "util/string.h"
#include "jthread/jthread.h"
#include "jthread/jmutex.h"
#include "exceptions.h"
@ -43,7 +42,7 @@ public:
private:
JMutex m_mutex;
std::string m_banfilepath;
std::map<std::string, std::string> m_ips;
StringMap m_ips;
bool m_modified;
};

@ -1102,7 +1102,7 @@ void Client::sendRemovedSounds(std::vector<s32> &soundList)
}
void Client::sendNodemetaFields(v3s16 p, const std::string &formname,
const std::map<std::string, std::string> &fields)
const StringMap &fields)
{
size_t fields_size = fields.size();
@ -1112,10 +1112,10 @@ void Client::sendNodemetaFields(v3s16 p, const std::string &formname,
pkt << p << formname << (u16) (fields_size & 0xFFFF);
for(std::map<std::string, std::string>::const_iterator
i = fields.begin(); i != fields.end(); i++) {
const std::string &name = i->first;
const std::string &value = i->second;
StringMap::const_iterator it;
for (it = fields.begin(); it != fields.end(); ++it) {
const std::string &name = it->first;
const std::string &value = it->second;
pkt << name;
pkt.putLongString(value);
}
@ -1124,7 +1124,7 @@ void Client::sendNodemetaFields(v3s16 p, const std::string &formname,
}
void Client::sendInventoryFields(const std::string &formname,
const std::map<std::string, std::string> &fields)
const StringMap &fields)
{
size_t fields_size = fields.size();
FATAL_ERROR_IF(fields_size > 0xFFFF, "Unsupported number of inventory fields");
@ -1132,10 +1132,10 @@ void Client::sendInventoryFields(const std::string &formname,
NetworkPacket pkt(TOSERVER_INVENTORY_FIELDS, 0);
pkt << formname << (u16) (fields_size & 0xFFFF);
for(std::map<std::string, std::string>::const_iterator
i = fields.begin(); i != fields.end(); i++) {
const std::string &name = i->first;
const std::string &value = i->second;
StringMap::const_iterator it;
for (it = fields.begin(); it != fields.end(); ++it) {
const std::string &name = it->first;
const std::string &value = it->second;
pkt << name;
pkt.putLongString(value);
}
@ -1918,14 +1918,13 @@ ParticleManager* Client::getParticleManager()
scene::IAnimatedMesh* Client::getMesh(const std::string &filename)
{
std::map<std::string, std::string>::const_iterator i =
m_mesh_data.find(filename);
if(i == m_mesh_data.end()){
errorstream<<"Client::getMesh(): Mesh not found: \""<<filename<<"\""
<<std::endl;
StringMap::const_iterator it = m_mesh_data.find(filename);
if (it == m_mesh_data.end()) {
errorstream << "Client::getMesh(): Mesh not found: \"" << filename
<< "\"" << std::endl;
return NULL;
}
const std::string &data = i->second;
const std::string &data = it->second;
scene::ISceneManager *smgr = m_device->getSceneManager();
// Create the mesh, remove it from cache and return it

@ -405,9 +405,9 @@ public:
void interact(u8 action, const PointedThing& pointed);
void sendNodemetaFields(v3s16 p, const std::string &formname,
const std::map<std::string, std::string> &fields);
const StringMap &fields);
void sendInventoryFields(const std::string &formname,
const std::map<std::string, std::string> &fields);
const StringMap &fields);
void sendInventoryAction(InventoryAction *a);
void sendChatMessage(const std::wstring &message);
void sendChangePassword(const std::string &oldpassword,
@ -648,7 +648,7 @@ private:
std::map<std::string, Inventory*> m_detached_inventories;
// Storage for mesh data for creating multiple instances of the same mesh
std::map<std::string, std::string> m_mesh_data;
StringMap m_mesh_data;
// own state
LocalClientState m_state;

@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapnode.h"
#include "nodedef.h"
#include "nameidmapping.h"
#include <map>
#include "util/string.h"
/*
Legacy node content type IDs
@ -218,14 +218,13 @@ public:
}
std::string get(const std::string &old)
{
std::map<std::string, std::string>::const_iterator i;
i = old_to_new.find(old);
if(i == old_to_new.end())
StringMap::const_iterator it = old_to_new.find(old);
if (it == old_to_new.end())
return "";
return i->second;
return it->second;
}
private:
std::map<std::string, std::string> old_to_new;
StringMap old_to_new;
};
NewNameGetter newnamegetter;

@ -87,11 +87,11 @@ struct TextDestNodeMetadata : public TextDest {
std::string ntext = wide_to_narrow(text);
infostream << "Submitting 'text' field of node at (" << m_p.X << ","
<< m_p.Y << "," << m_p.Z << "): " << ntext << std::endl;
std::map<std::string, std::string> fields;
StringMap fields;
fields["text"] = ntext;
m_client->sendNodemetaFields(m_p, "", fields);
}
void gotText(std::map<std::string, std::string> fields)
void gotText(const StringMap &fields)
{
m_client->sendNodemetaFields(m_p, "", fields);
}
@ -111,7 +111,7 @@ struct TextDestPlayerInventory : public TextDest {
m_client = client;
m_formname = formname;
}
void gotText(std::map<std::string, std::string> fields)
void gotText(const StringMap &fields)
{
m_client->sendInventoryFields(m_formname, fields);
}
@ -138,7 +138,7 @@ struct LocalFormspecHandler : public TextDest {
errorstream << "LocalFormspecHandler::gotText old style message received" << std::endl;
}
void gotText(std::map<std::string, std::string> fields)
void gotText(const StringMap &fields)
{
if (m_formname == "MT_PAUSE_MENU") {
if (fields.find("btn_sound") != fields.end()) {
@ -180,9 +180,9 @@ struct LocalFormspecHandler : public TextDest {
if ((fields.find("btn_send") != fields.end()) ||
(fields.find("quit") != fields.end())) {
if (fields.find("f_text") != fields.end()) {
m_client->typeChatMessage(narrow_to_wide(fields["f_text"]));
}
StringMap::const_iterator it = fields.find("f_text");
if (it != fields.end())
m_client->typeChatMessage(narrow_to_wide(it->second));
return;
}
@ -210,12 +210,14 @@ struct LocalFormspecHandler : public TextDest {
return;
}
errorstream << "LocalFormspecHandler::gotText unhandled >" << m_formname << "< event" << std::endl;
int i = 0;
errorstream << "LocalFormspecHandler::gotText unhandled >"
<< m_formname << "< event" << std::endl;
for (std::map<std::string, std::string>::iterator iter = fields.begin();
iter != fields.end(); iter++) {
errorstream << "\t" << i << ": " << iter->first << "=" << iter->second << std::endl;
int i = 0;
StringMap::const_iterator it;
for (it = fields.begin(); it != fields.end(); ++it) {
errorstream << "\t" << i << ": " << it->first
<< "=" << it->second << std::endl;
i++;
}
}

@ -53,7 +53,7 @@ TextDestGuiEngine::TextDestGuiEngine(GUIEngine* engine)
}
/******************************************************************************/
void TextDestGuiEngine::gotText(std::map<std::string, std::string> fields)
void TextDestGuiEngine::gotText(const StringMap &fields)
{
m_engine->getScriptIface()->handleMainMenuButtons(fields);
}

@ -73,7 +73,7 @@ public:
* receive fields transmitted by guiFormSpecMenu
* @param fields map containing formspec field elements currently active
*/
void gotText(std::map<std::string, std::string> fields);
void gotText(const StringMap &fields);
/**
* receive text/events transmitted by guiFormSpecMenu

@ -84,7 +84,7 @@ void GUIFileSelectMenu::drawMenu()
void GUIFileSelectMenu::acceptInput() {
if ((m_text_dst != 0) && (this->m_formname != "")){
std::map<std::string, std::string> fields;
StringMap fields;
if (m_accepted)
fields[m_formname + "_accepted"] = wide_to_narrow(m_fileOpenDialog->getFileName());

@ -2579,7 +2579,7 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
{
if(m_text_dst)
{
std::map<std::string, std::string> fields;
StringMap fields;
if (quitmode == quit_mode_accept) {
fields["quit"] = "true";

@ -56,7 +56,7 @@ struct TextDest
virtual ~TextDest() {};
// This is deprecated I guess? -celeron55
virtual void gotText(std::wstring text){}
virtual void gotText(std::map<std::string, std::string> fields) = 0;
virtual void gotText(const StringMap &fields) = 0;
virtual void setFormName(std::string formname)
{ m_formname = formname;};

@ -266,8 +266,7 @@ HTTPFetchOngoing::HTTPFetchOngoing(HTTPFetchRequest request_, CurlHandlePool *po
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
} else if (request.multipart) {
curl_httppost *last = NULL;
for (std::map<std::string, std::string>::iterator it =
request.post_fields.begin();
for (StringMap::iterator it = request.post_fields.begin();
it != request.post_fields.end(); ++it) {
curl_formadd(&post, &last,
CURLFORM_NAMELENGTH, it->first.size(),
@ -282,10 +281,8 @@ HTTPFetchOngoing::HTTPFetchOngoing(HTTPFetchRequest request_, CurlHandlePool *po
} else if (request.post_data.empty()) {
curl_easy_setopt(curl, CURLOPT_POST, 1);
std::string str;
for (std::map<std::string, std::string>::iterator it =
request.post_fields.begin();
it != request.post_fields.end();
++it) {
for (StringMap::iterator it = request.post_fields.begin();
it != request.post_fields.end(); ++it) {
if (str != "")
str += "&";
str += urlencode(it->first);

@ -20,9 +20,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef HTTPFETCH_HEADER
#define HTTPFETCH_HEADER
#include <string>
#include <vector>
#include <map>
#include "util/string.h"
#include "config.h"
// Can be used in place of "caller" in asynchronous transfers to discard result
@ -54,7 +53,7 @@ struct HTTPFetchRequest
// POST fields. Fields are escaped properly.
// If this is empty a GET request is done instead.
std::map<std::string, std::string> post_fields;
StringMap post_fields;
// Raw POST data, overrides post_fields.
std::string post_data;

@ -280,26 +280,23 @@ public:
}
virtual std::string getAlias(const std::string &name) const
{
std::map<std::string, std::string>::const_iterator i;
i = m_aliases.find(name);
if(i != m_aliases.end())
return i->second;
StringMap::const_iterator it = m_aliases.find(name);
if (it != m_aliases.end())
return it->second;
return name;
}
virtual std::set<std::string> getAll() const
{
std::set<std::string> result;
for(std::map<std::string, ItemDefinition*>::const_iterator
i = m_item_definitions.begin();
i != m_item_definitions.end(); i++)
{
result.insert(i->first);
for(std::map<std::string, ItemDefinition *>::const_iterator
it = m_item_definitions.begin();
it != m_item_definitions.end(); ++it) {
result.insert(it->first);
}
for(std::map<std::string, std::string>::const_iterator
i = m_aliases.begin();
i != m_aliases.end(); i++)
{
result.insert(i->first);
for (StringMap::const_iterator
it = m_aliases.begin();
it != m_aliases.end(); ++it) {
result.insert(it->first);
}
return result;
}
@ -571,22 +568,24 @@ public:
writeU8(os, 0); // version
u16 count = m_item_definitions.size();
writeU16(os, count);
for(std::map<std::string, ItemDefinition*>::const_iterator
i = m_item_definitions.begin();
i != m_item_definitions.end(); i++)
{
ItemDefinition *def = i->second;
for (std::map<std::string, ItemDefinition *>::const_iterator
it = m_item_definitions.begin();
it != m_item_definitions.end(); ++it) {
ItemDefinition *def = it->second;
// Serialize ItemDefinition and write wrapped in a string
std::ostringstream tmp_os(std::ios::binary);
def->serialize(tmp_os, protocol_version);
os<<serializeString(tmp_os.str());
os << serializeString(tmp_os.str());
}
writeU16(os, m_aliases.size());
for(std::map<std::string, std::string>::const_iterator
i = m_aliases.begin(); i != m_aliases.end(); i++)
{
os<<serializeString(i->first);
os<<serializeString(i->second);
for (StringMap::const_iterator
it = m_aliases.begin();
it != m_aliases.end(); ++it) {
os << serializeString(it->first);
os << serializeString(it->second);
}
}
void deSerialize(std::istream &is)
@ -633,7 +632,7 @@ private:
// Key is name
std::map<std::string, ItemDefinition*> m_item_definitions;
// Aliases
std::map<std::string, std::string> m_aliases;
StringMap m_aliases;
#ifndef SERVER
// The id of the thread that is allowed to use irrlicht directly
threadid_t m_main_thread;

@ -192,7 +192,7 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
{
std::string reason;
if(m_script->on_prejoinplayer(playername, addr_s, reason)) {
if (m_script->on_prejoinplayer(playername, addr_s, &reason)) {
actionstream << "Server: Player with the name \"" << playerName << "\" "
<< "tried to connect from " << addr_s << " "
<< "but it was disallowed for the following reason: "
@ -480,7 +480,7 @@ void Server::handleCommand_Init_Legacy(NetworkPacket* pkt)
{
std::string reason;
if (m_script->on_prejoinplayer(playername, addr_s, reason)) {
if (m_script->on_prejoinplayer(playername, addr_s, &reason)) {
actionstream << "Server: Player with the name \"" << playername << "\" "
<< "tried to connect from " << addr_s << " "
<< "but it was disallowed for the following reason: "
@ -1742,7 +1742,7 @@ void Server::handleCommand_NodeMetaFields(NetworkPacket* pkt)
*pkt >> p >> formname >> num;
std::map<std::string, std::string> fields;
StringMap fields;
for (u16 k = 0; k < num; k++) {
std::string fieldname;
*pkt >> fieldname;
@ -1792,7 +1792,7 @@ void Server::handleCommand_InventoryFields(NetworkPacket* pkt)
*pkt >> formname >> num;
std::map<std::string, std::string> fields;
StringMap fields;
for (u16 k = 0; k < num; k++) {
std::string fieldname;
*pkt >> fieldname;

@ -45,10 +45,11 @@ void NodeMetadata::serialize(std::ostream &os) const
{
int num_vars = m_stringvars.size();
writeU32(os, num_vars);
for(std::map<std::string, std::string>::const_iterator
i = m_stringvars.begin(); i != m_stringvars.end(); i++){
os<<serializeString(i->first);
os<<serializeLongString(i->second);
for (StringMap::const_iterator
it = m_stringvars.begin();
it != m_stringvars.end(); ++it) {
os << serializeString(it->first);
os << serializeLongString(it->second);
}
m_inventory->serialize(os);
@ -203,11 +204,10 @@ void NodeMetadataList::clear()
std::string NodeMetadata::getString(const std::string &name,
unsigned short recursion) const
{
std::map<std::string, std::string>::const_iterator it;
it = m_stringvars.find(name);
if (it == m_stringvars.end()) {
StringMap::const_iterator it = m_stringvars.find(name);
if (it == m_stringvars.end())
return "";
}
return resolveString(it->second, recursion);
}

@ -21,10 +21,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define NODEMETADATA_HEADER
#include "irr_v3d.h"
#include <string>
#include <iostream>
#include <vector>
#include <map>
#include "util/string.h"
/*
NodeMetadata stores arbitary amounts of data for special blocks.
@ -54,19 +53,19 @@ public:
void setString(const std::string &name, const std::string &var);
// Support variable names in values
std::string resolveString(const std::string &str, unsigned short recursion = 0) const;
std::map<std::string, std::string> getStrings() const
StringMap getStrings() const
{
return m_stringvars;
}
// The inventory
Inventory* getInventory()
Inventory *getInventory()
{
return m_inventory;
}
private:
std::map<std::string, std::string> m_stringvars;
StringMap m_stringvars;
Inventory *m_inventory;
};

@ -53,7 +53,7 @@ void ScriptApiMainMenu::handleMainMenuEvent(std::string text)
scriptError();
}
void ScriptApiMainMenu::handleMainMenuButtons(std::map<std::string, std::string> fields)
void ScriptApiMainMenu::handleMainMenuButtons(const StringMap &fields)
{
SCRIPTAPI_PRECHECKHEADER
@ -69,8 +69,8 @@ void ScriptApiMainMenu::handleMainMenuButtons(std::map<std::string, std::string>
// Convert fields to a Lua table
lua_newtable(L);
std::map<std::string, std::string>::const_iterator it;
for (it = fields.begin(); it != fields.end(); it++){
StringMap::const_iterator it;
for (it = fields.begin(); it != fields.end(); ++it) {
const std::string &name = it->first;
const std::string &value = it->second;
lua_pushstring(L, name.c_str());

@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define S_MAINMENU_H_
#include "cpp_api/s_base.h"
#include <map>
#include "util/string.h"
class ScriptApiMainMenu
: virtual public ScriptApiBase
@ -43,7 +43,7 @@ public:
* process field data recieved from formspec
* @param fields data in field format
*/
void handleMainMenuButtons(std::map<std::string, std::string> fields);
void handleMainMenuButtons(const StringMap &fields);
};
#endif /* S_MAINMENU_H_ */

@ -200,7 +200,7 @@ bool ScriptApiNode::node_on_timer(v3s16 p, MapNode node, f32 dtime)
void ScriptApiNode::node_on_receive_fields(v3s16 p,
const std::string &formname,
const std::map<std::string, std::string> &fields,
const StringMap &fields,
ServerActiveObject *sender)
{
SCRIPTAPI_PRECHECKHEADER
@ -220,8 +220,8 @@ void ScriptApiNode::node_on_receive_fields(v3s16 p,
push_v3s16(L, p); // pos
lua_pushstring(L, formname.c_str()); // formname
lua_newtable(L); // fields
std::map<std::string, std::string>::const_iterator it;
for (it = fields.begin(); it != fields.end(); it++){
StringMap::const_iterator it;
for (it = fields.begin(); it != fields.end(); it++) {
const std::string &name = it->first;
const std::string &value = it->second;
lua_pushstring(L, name.c_str());

@ -20,11 +20,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef S_NODE_H_
#define S_NODE_H_
#include <map>
#include "irr_v3d.h"
#include "cpp_api/s_base.h"
#include "cpp_api/s_nodemeta.h"
#include "util/string.h"
struct MapNode;
class ServerActiveObject;
@ -47,7 +46,7 @@ public:
bool node_on_timer(v3s16 p, MapNode node, f32 dtime);
void node_on_receive_fields(v3s16 p,
const std::string &formname,
const std::map<std::string, std::string> &fields,
const StringMap &fields,
ServerActiveObject *sender);
void node_falling_update(v3s16 p);
void node_falling_update_single(v3s16 p);

@ -83,7 +83,10 @@ bool ScriptApiPlayer::on_respawnplayer(ServerActiveObject *player)
return positioning_handled_by_some;
}
bool ScriptApiPlayer::on_prejoinplayer(std::string name, std::string ip, std::string &reason)
bool ScriptApiPlayer::on_prejoinplayer(
const std::string &name,
const std::string &ip,
std::string *reason)
{
SCRIPTAPI_PRECHECKHEADER
@ -94,7 +97,7 @@ bool ScriptApiPlayer::on_prejoinplayer(std::string name, std::string ip, std::st
lua_pushstring(L, ip.c_str());
script_run_callbacks(L, 2, RUN_CALLBACKS_MODE_OR);
if (lua_isstring(L, -1)) {
reason.assign(lua_tostring(L, -1));
reason->assign(lua_tostring(L, -1));
return true;
}
return false;
@ -142,7 +145,7 @@ void ScriptApiPlayer::on_cheat(ServerActiveObject *player,
void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player,
const std::string &formname,
const std::map<std::string, std::string> &fields)
const StringMap &fields)
{
SCRIPTAPI_PRECHECKHEADER
@ -156,17 +159,19 @@ void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player,
lua_pushstring(L, formname.c_str());
// param 3
lua_newtable(L);
for(std::map<std::string, std::string>::const_iterator
i = fields.begin(); i != fields.end(); i++){
const std::string &name = i->first;
const std::string &value = i->second;
StringMap::const_iterator it;
for (it = fields.begin(); it != fields.end(); ++it) {
const std::string &name = it->first;
const std::string &value = it->second;
lua_pushstring(L, name.c_str());
lua_pushlstring(L, value.c_str(), value.size());
lua_settable(L, -3);
}
script_run_callbacks(L, 3, RUN_CALLBACKS_MODE_OR_SC);
}
ScriptApiPlayer::~ScriptApiPlayer() {
ScriptApiPlayer::~ScriptApiPlayer()
{
}

@ -20,10 +20,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef S_PLAYER_H_
#define S_PLAYER_H_
#include <map>
#include "cpp_api/s_base.h"
#include "irr_v3d.h"
#include "util/string.h"
struct ToolCapabilities;
@ -36,17 +35,16 @@ public:
void on_newplayer(ServerActiveObject *player);
void on_dieplayer(ServerActiveObject *player);
bool on_respawnplayer(ServerActiveObject *player);
bool on_prejoinplayer(std::string name, std::string ip, std::string &reason);
bool on_prejoinplayer(const std::string &name, const std::string &ip,
std::string *reason);
void on_joinplayer(ServerActiveObject *player);
void on_leaveplayer(ServerActiveObject *player);
void on_cheat(ServerActiveObject *player, const std::string &cheat_type);
bool on_punchplayer(ServerActiveObject *player,
ServerActiveObject *hitter, float time_from_last_punch,
const ToolCapabilities *toolcap, v3f dir, s16 damage);
void on_playerReceiveFields(ServerActiveObject *player,
const std::string &formname,
const std::map<std::string, std::string> &fields);
const std::string &formname, const StringMap &fields);
};

@ -190,32 +190,34 @@ int NodeMetaRef::l_to_table(lua_State *L)
NodeMetaRef *ref = checkobject(L, 1);
NodeMetadata *meta = getmeta(ref, true);
if(meta == NULL){
if (meta == NULL) {
lua_pushnil(L);
return 1;
}
lua_newtable(L);
// fields
lua_newtable(L);
{
std::map<std::string, std::string> fields = meta->getStrings();
for(std::map<std::string, std::string>::const_iterator
i = fields.begin(); i != fields.end(); i++){
const std::string &name = i->first;
const std::string &value = i->second;
StringMap fields = meta->getStrings();
for (StringMap::const_iterator
it = fields.begin(); it != fields.end(); ++it) {
const std::string &name = it->first;
const std::string &value = it->second;
lua_pushlstring(L, name.c_str(), name.size());
lua_pushlstring(L, value.c_str(), value.size());
lua_settable(L, -3);
}
}
lua_setfield(L, -2, "fields");
// inventory
lua_newtable(L);
Inventory *inv = meta->getInventory();
if(inv){
std::vector<const InventoryList*> lists = inv->getLists();
for(std::vector<const InventoryList*>::const_iterator
i = lists.begin(); i != lists.end(); i++){
if (inv) {
std::vector<const InventoryList *> lists = inv->getLists();
for(std::vector<const InventoryList *>::const_iterator
i = lists.begin(); i != lists.end(); i++) {
push_inventory_list(L, inv, (*i)->getName().c_str());
lua_setfield(L, -2, (*i)->getName().c_str());
}

@ -103,10 +103,8 @@ std::string getShaderPath(const std::string &name_of_shader,
class SourceShaderCache
{
public:
void insert(const std::string &name_of_shader,
const std::string &filename,
const std::string &program,
bool prefer_local)
void insert(const std::string &name_of_shader, const std::string &filename,
const std::string &program, bool prefer_local)
{
std::string combined = name_of_shader + DIR_DELIM + filename;
// Try to use local shader instead if asked to
@ -122,42 +120,43 @@ public:
}
m_programs[combined] = program;
}
std::string get(const std::string &name_of_shader,
const std::string &filename)
{
std::string combined = name_of_shader + DIR_DELIM + filename;
std::map<std::string, std::string>::iterator n;
n = m_programs.find(combined);
if(n != m_programs.end())
StringMap::iterator n = m_programs.find(combined);
if (n != m_programs.end())
return n->second;
return "";
}
// Primarily fetches from cache, secondarily tries to read from filesystem
std::string getOrLoad(const std::string &name_of_shader,
const std::string &filename)
{
std::string combined = name_of_shader + DIR_DELIM + filename;
std::map<std::string, std::string>::iterator n;
n = m_programs.find(combined);
if(n != m_programs.end())
StringMap::iterator n = m_programs.find(combined);
if (n != m_programs.end())
return n->second;
std::string path = getShaderPath(name_of_shader, filename);
if(path == ""){
infostream<<"SourceShaderCache::getOrLoad(): No path found for \""
<<combined<<"\""<<std::endl;
if (path == "") {
infostream << "SourceShaderCache::getOrLoad(): No path found for \""
<< combined << "\"" << std::endl;
return "";
}
infostream<<"SourceShaderCache::getOrLoad(): Loading path \""<<path
<<"\""<<std::endl;
infostream << "SourceShaderCache::getOrLoad(): Loading path \""
<< path << "\"" << std::endl;
std::string p = readFile(path);
if(p != ""){
if (p != "") {
m_programs[combined] = p;
return p;
}
return "";
}
private:
std::map<std::string, std::string> m_programs;
StringMap m_programs;
std::string readFile(const std::string &path)
{
std::ifstream is(path.c_str(), std::ios::binary);