ofs | hex dump | ascii |
---|
0000 | 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 04 00 00 00 04 00 08 03 00 00 00 48 c3 db | .PNG........IHDR.............H.. |
0020 | b1 00 00 00 48 50 4c 54 45 00 00 00 94 9c 94 c6 c6 c6 ef ef ef f7 f7 f7 de de de bd bd bd 7b 7b | ....HPLTE.....................{{ |
0040 | 7b d6 d6 d6 ad b5 ad e7 e7 e7 63 63 63 a5 a5 a5 8c 8c 8c d6 de d6 e7 ef e7 f7 ff f7 ad ad ad ef | {.........ccc................... |
0060 | f7 ef 9c a5 9c de e7 de b5 bd b5 ff ff ff ce ce ce 28 6f 2b 7a 00 00 00 01 74 52 4e 53 00 40 e6 | .................(o+z....tRNS.@. |
0080 | d8 66 00 01 0d 29 49 44 41 54 78 5e ec d4 b1 0d 00 20 10 02 c0 9f 02 f7 df 54 13 0b 07 b0 7a bd | .f...)IDATx^.............T....z. |
00a0 | 23 a1 a4 a4 fe 06 00 00 00 00 00 a4 9e 05 24 d9 75 7f 00 67 66 ac 34 03 93 bd bf 61 73 14 54 ba | #.............$.u..gf.4....as.T. |
00c0 | 46 61 14 10 04 bc 9f 7d ee f7 39 8b ff ff 4f df b3 03 64 5d a4 88 26 9d a4 bb 67 c6 75 cd 74 84 | Fa.....}..9...O...d]..&...g.u.t. |
00e0 | 2a e5 4b 96 50 a0 05 00 10 c1 1d 64 60 1a f7 02 89 63 9d 59 03 c0 b1 26 25 22 f4 7c 81 25 01 18 | *.K.P......d`....c.Y...&%".|.%.. |
0100 | 5d fe 5c 90 0d 60 ec e2 94 72 1e f0 8e 25 5f eb d1 a2 19 6f 61 2f d2 00 85 a0 1a 9e cf d9 5a 52 | ].\..`...r...%_....oa/........ZR |
0120 | 5f 02 10 16 b6 05 94 72 8b 35 80 ce 51 29 e5 e6 00 c0 26 45 4c 00 a8 ce 06 4c de 00 76 76 57 09 | _......r.5..Q)....&EL....L..vvW. |
0140 | 65 9b 37 25 95 a2 68 cb d5 5f 83 9b 2d 00 bb 2a 22 e5 70 89 ea 2e bd 00 b9 bb db 60 7c 62 61 2e | e.7%..h.._..-..*".p........`|ba. |
0160 | a7 18 3b a7 a8 50 a1 db 15 70 c5 d2 97 96 67 c2 e6 f5 72 a6 68 6f 19 98 60 62 8d a3 36 b0 32 64 | ..;..P...p....g...r.ho..`b..6.2d |
0180 | 8a be 89 a2 5d 93 37 60 c6 51 60 d8 2e 94 f7 1a 8c 89 59 b7 db 0c 3d 5a 1e 99 e5 00 24 e6 6a 42 | ....].7`.Q`.......Y...=Z....$.jB |
01a0 | 50 1a d8 4a c8 5e 73 ec a0 95 07 b4 6a b0 f0 ca 03 81 a7 66 78 b5 89 a4 00 a5 d7 11 01 2c 77 18 | P..J.^s.....j......fx........,w. |
01c0 | c0 c4 77 11 40 00 0e 08 40 34 de 27 08 c0 21 d7 3f cc 13 a0 a2 d1 31 ea 56 da 84 dc e5 da 14 06 | ..w.@...@4.'..!.?.....1.V....... |
01e0 | f0 f0 a5 56 f2 e5 7f 45 08 ea 49 d8 99 89 23 38 12 00 fb 6f e2 71 e0 89 66 4c 00 16 15 92 00 72 | ...V...E..I...#8...o.q..fL.....r |
0200 | 77 11 cf ab bf 00 99 b3 c5 e4 14 2f 3d d3 2c 8a d0 80 e1 39 fd 49 2e f4 bd 80 58 f6 09 40 9e 79 | w........../=.,....9.I....X..@.y |
0220 | 4c 00 d1 20 8d ee 36 4d 36 6a 17 b3 37 04 b0 69 54 e8 ad cf 58 56 03 39 35 78 ad 84 86 07 08 60 | L.....6M6j..7..iT...XV.95x.....` |
0240 | ad a7 f1 41 94 81 e5 2a f7 45 b0 22 ab 68 8a a0 84 cd a5 94 a4 b4 0d 26 aa 6d 94 d4 6c 07 bd 6a | ...A...*.E.".h.........&.m..l..j |
0260 | c3 76 87 01 c2 5b 08 80 4f 83 9f 26 80 15 a9 fc a9 79 82 72 69 d6 2a 23 b1 df bb 56 ea 52 f9 4b | .v...[..O..&.....y.ri.*#...V.R.K |
0280 | 6b 93 05 4b 79 9a 5c fa e2 d4 c8 d7 aa 27 71 39 35 c0 24 a5 92 41 60 66 55 58 36 a5 e2 02 60 53 | k..Ky.\......'q95.$..A`fUX6...`S |
02a0 | 36 45 a5 a6 da ca ec bf b2 36 2c b0 44 a5 b6 25 28 62 03 bc 52 09 08 51 b9 50 2a 3f 5f 7e b6 00 | 6E.......6,.D..%(b..R..Q.P*?_~.. |
02c0 | 38 f5 02 6a ce 02 5a 75 05 1f 9b 28 86 cc 2c 54 ae 61 f1 e2 d2 8a 93 00 d8 e9 bf 4a b3 66 63 c7 | 8..j..Zu...(..,T.a.........J.fc. |
02e0 | 29 97 9e 25 fa 35 21 cf 3c 26 00 0b 3f bc db 58 0f 19 55 1f 89 f2 92 9a b9 0c 10 17 53 44 25 3d | )..%.5!.<&..?..X..U.........SD%= |
0300 | b7 00 58 07 f2 5e 63 a9 d5 60 fe 2b 99 66 2d 8a 24 0f 23 80 48 3d 44 95 1a 25 6c b8 12 aa 47 52 | ..X..^c..`.+.f-.$.#.H=D..%l...GR |
0320 | 6a b9 16 20 96 bb 71 01 09 37 60 51 3d 17 fb 9a d4 34 aa 59 0d ad 86 c8 c8 ef 21 80 00 c4 df 40 | j.....q..7`Q=....4.Y......!....@ |
0340 | 00 1e e5 4f ad 95 58 05 1a 51 a9 08 5d 02 c6 31 59 26 ae d2 a5 89 cd a5 6a 97 4b 5d 67 9f 94 f7 | ...O..X..Q..]..1Y&......j.K]g... |
0360 | 2a f9 ac 1e c7 84 d2 58 5b 6d d5 45 94 70 01 fc 55 19 fa 7a 68 3a 02 a0 f2 aa 04 34 0c 6b dd 01 | *......X[m.E.p..U..zh:.....4.k.. |
0380 | 68 9c 70 29 41 50 af 23 d6 db cd 99 d4 35 f4 c2 4e 65 00 db 37 e0 5a 8a e3 00 f6 b4 c9 56 69 b9 | h.p)AP.#.....5..Ne..7.Z......Vi. |
03a0 | 1a b0 ee 10 80 38 f3 88 00 6a 5b 8d 09 60 e6 d8 aa ea c3 50 7e 49 cd 38 66 cc f1 12 2b 10 46 f2 | .....8...j[..`.....P~I.8f...+.F. |
03c0 | 4e 43 57 da de 86 1d 64 7c e8 41 c6 4f 08 4a c5 6b 92 a4 2c 83 58 5a d7 76 04 a7 d1 ba eb da 77 | NCW....d|.A.O.J.k..,.XZ.v......w |
03e0 | e8 19 30 d7 a4 30 89 b4 d3 fe b0 f0 75 02 60 d4 4f db 00 4c b8 fc a1 bc a9 f2 af bd ad 21 c0 70 | ..0..0......u.`.O..L.........!.p |
0400 | 9c b4 00 55 b4 28 b5 58 03 a5 60 ec a2 1e 44 1d 83 b1 13 06 98 21 15 ca 43 83 75 44 00 66 44 de | ...U.(.X..`...D......!..C.uD.fD. |
0420 | 0b 30 51 b1 fc 96 3b 91 e4 f3 2a 00 b0 ff 2f 1a e5 a1 18 4d bc ca 57 00 91 ca fc b5 c0 72 a7 b1 | .0Q...;...*.../....M..W......r.. |
0440 | 27 c0 ec 10 80 ed e9 ee 11 02 70 c0 26 95 bb de be 41 17 7d 4d ea 05 2e a9 4d cc 18 2c d3 53 18 | '.........p.&....A.}M....M..,.S. |
0460 | cb 7b 0d 86 1f 26 80 54 78 83 0f fa ab 11 c0 a3 8d f1 5d 51 d9 50 c2 2b 4c 2b 46 55 8d a6 16 99 | .{...&.Tx.........]Q.P.+L+FU.... |
0480 | f1 e9 9a 94 9d 45 da 1a 0b f4 3f 41 00 1b e6 f2 e7 3e 01 2c 7c 2e 94 06 4e 40 e6 92 81 ae 6c eb | .....E....?A.....>.,|...N@....l. |
04a0 | 6b 8d 25 b7 4d cf ad 2a e8 f5 d2 cc 6b e3 6a a4 87 08 c0 c3 8e ee a9 69 34 00 88 06 be 2a 6e e5 | k.%.M..*....k.j........i4....*n. |
04c0 | 37 28 65 da 59 0e 98 d5 18 9b 95 02 3b 66 0b 57 ee d4 90 9a 41 a3 26 36 d7 6b 27 78 a5 81 a5 2b | 7(e.Y.......;f.W....A.&6.k'x...+ |
04e0 | 46 21 d3 0d d0 77 1b 3b 00 e9 0e 01 f0 cc 67 08 40 63 1e 8f 37 f5 b5 fb ce 98 8b fe 86 6b 1c a0 | F!...w.;......g.@c..7........k.. |
0500 | b6 ce 02 13 80 ad bb be 94 bb 31 01 c4 27 08 40 99 eb cc 24 16 51 33 02 68 78 20 37 13 00 1f ec | ./*
Minetest
Copyright (C) 2010-2016 celeron55, Perttu Ahola <celeron55@gmail.com>
Copyright (C) 2014-2016 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "remoteplayer.h"
#include <json/json.h>
#include "content_sao.h"
#include "filesys.h"
#include "gamedef.h"
#include "porting.h" // strlcpy
#include "server.h"
#include "settings.h"
/*
RemotePlayer
*/
// static config cache for remoteplayer
bool RemotePlayer::m_setting_cache_loaded = false;
float RemotePlayer::m_setting_chat_message_limit_per_10sec = 0.0f;
u16 RemotePlayer::m_setting_chat_message_limit_trigger_kick = 0;
RemotePlayer::RemotePlayer(const char *name, IItemDefManager *idef):
Player(name, idef),
protocol_version(0),
m_sao(NULL),
m_dirty(false),
m_last_chat_message_sent(time(NULL)),
m_chat_message_allowance(5.0f),
m_message_rate_overhead(0),
hud_hotbar_image(""),
hud_hotbar_selected_image("")
{
if (!RemotePlayer::m_setting_cache_loaded) {
RemotePlayer::m_setting_chat_message_limit_per_10sec =
g_settings->getFloat("chat_message_limit_per_10sec");
RemotePlayer::m_setting_chat_message_limit_trigger_kick =
g_settings->getU16("chat_message_limit_trigger_kick");
RemotePlayer::m_setting_cache_loaded = true;
}
movement_acceleration_default = g_settings->getFloat("movement_acceleration_default") * BS;
movement_acceleration_air = g_settings->getFloat("movement_acceleration_air") * BS;
movement_acceleration_fast = g_settings->getFloat("movement_acceleration_fast") * BS;
movement_speed_walk = g_settings->getFloat("movement_speed_walk") * BS;
movement_speed_crouch = g_settings->getFloat("movement_speed_crouch") * BS;
movement_speed_fast = g_settings->getFloat("movement_speed_fast") * BS;
movement_speed_climb = g_settings->getFloat("movement_speed_climb") * BS;
movement_speed_jump = g_settings->getFloat("movement_speed_jump") * BS;
movement_liquid_fluidity = g_settings->getFloat("movement_liquid_fluidity") * BS;
movement_liquid_fluidity_smooth = g_settings->getFloat("movement_liquid_fluidity_smooth") * BS;
movement_liquid_sink = g_settings->getFloat("movement_liquid_sink") * BS;
movement_gravity = g_settings->getFloat("movement_gravity") * BS;
}
void RemotePlayer::save(std::string savedir, IGameDef *gamedef)
{
/*
* We have to open all possible player files in the players directory
* and check their player names because some file systems are not
* case-sensitive and player names are case-sensitive.
*/
// A player to deserialize files into to check their names
RemotePlayer testplayer("", gamedef->idef());
savedir += DIR_DELIM;
std::string path = savedir + m_name;
for (u32 i = 0; i < PLAYER_FILE_ALTERNATE_TRIES; i++) {
if (!fs::PathExists(path)) {
// Open file and serialize
std::ostringstream ss(std::ios_base::binary);
serialize(ss);
if (!fs::safeWriteToFile(path, ss.str())) {
infostream << "Failed to write " << path << std::endl;
}
setModified(false);
return;
}
// Open file and deserialize
std::ifstream is(path.c_str(), std::ios_base::binary);
if (!is.good()) {
infostream << "Failed to open " << path << std::endl;
return;
}
testplayer.deSerialize(is, path, NULL);
is.close();
if (strcmp(testplayer.getName(), m_name) == 0) {
// Open file and serialize
std::ostringstream ss(std::ios_base::binary);
serialize(ss);
if (!fs::safeWriteToFile(path, ss.str())) {
infostream << "Failed to write " << path << std::endl;
}
setModified(false);
return;
}
path = savedir + m_name + itos(i);
}
infostream << "Didn't find free file for player " << m_name << std::endl;
}
void RemotePlayer::serializeExtraAttributes(std::string &output)
{
assert(m_sao);
Json::Value json_root;
const PlayerAttributes &attrs = m_sao->getExtendedAttributes();
for (PlayerAttributes::const_iterator it = attrs.begin(); it != attrs.end(); ++it) {
json_root[(*it).first] = (*it).second;
}
Json::FastWriter writer;
output = writer.write(json_root);
m_sao->setExtendedAttributeModified(false);
}
void RemotePlayer::deSerialize(std::istream &is, const std::string &playername,
PlayerSAO *sao)
{
Settings args;
if (!args.parseConfigLines(is, "PlayerArgsEnd")) {
throw SerializationError("PlayerArgsEnd of player " + playername + " not found!");
}
m_dirty = true;
//args.getS32("version"); // Version field value not used
const std::string &name = args.get("name");
strlcpy(m_name, name.c_str(), PLAYERNAME_SIZE);
if (sao) {
try {
sao->setHPRaw(args.getS32("hp"));
} catch(SettingNotFoundException &e) {
sao->setHPRaw(PLAYER_MAX_HP);
}
try {
sao->setBasePosition(args.getV3F("position"));
} catch (SettingNotFoundException &e) {}
try {
sao->setPitch(args.getFloat("pitch"));
} catch (SettingNotFoundException &e) {}
try {
sao->setYaw(args.getFloat("yaw"));
} catch (SettingNotFoundException &e) {}
try {
sao->setBreath(args.getS32("breath"), false);
} catch (SettingNotFoundException &e) {}
try {
const std::string &extended_attributes = args.get("extended_attributes");
Json::Reader reader;
Json::Value attr_root;
reader.parse(extended_attributes, attr_root);
const Json::Value::Members attr_list = attr_root.getMemberNames();
for (Json::Value::Members::const_iterator it = attr_list.begin();
it != attr_list.end(); ++it) {
Json::Value attr_value = attr_root[*it];
sao->setExtendedAttribute(*it, attr_value.asString());
}
} catch (SettingNotFoundException &e) {}
}
inventory.deSerialize(is);
if (inventory.getList("craftpreview") == NULL) {
// Convert players without craftpreview
inventory.addList("craftpreview", 1);
bool craftresult_is_preview = true;
if(args.exists("craftresult_is_preview"))
craftresult_is_preview = args.getBool("craftresult_is_preview");
if(craftresult_is_preview)
{
// Clear craftresult
inventory.getList("craftresult")->changeItem(0, ItemStack());
}
}
}
void RemotePlayer::serialize(std::ostream &os)
{
// Utilize a Settings object for storing values
Settings args;
args.setS32("version", 1);
args.set("name", m_name);
// This should not happen
assert(m_sao);
args.setS32("hp", m_sao->getHP());
args.setV3F("position", m_sao->getBasePosition());
args.setFloat("pitch", m_sao->getPitch());
args.setFloat("yaw", m_sao->getYaw());
args.setS32("breath", m_sao->getBreath());
std::string extended_attrs = "";
serializeExtraAttributes(extended_attrs);
args.set("extended_attributes", extended_attrs);
args.writeLines(os);
os<<"PlayerArgsEnd\n";
inventory.serialize(os);
}
const RemotePlayerChatResult RemotePlayer::canSendChatMessage()
{
// Rate limit messages
u32 now = time(NULL);
float time_passed = now - m_last_chat_message_sent;
m_last_chat_message_sent = now;
// If this feature is disabled
if (m_setting_chat_message_limit_per_10sec <= 0.0) {
return RPLAYER_CHATRESULT_OK;
}
m_chat_message_allowance += time_passed * (m_setting_chat_message_limit_per_10sec / 8.0f);
if (m_chat_message_allowance > m_setting_chat_message_limit_per_10sec) {
m_chat_message_allowance = m_setting_chat_message_limit_per_10sec;
}
if (m_chat_message_allowance < 1.0f) {
infostream << "Player " << m_name
<< " chat limited due to excessive message amount." << std::endl;
// Kick player if flooding is too intensive
m_message_rate_overhead++;
if (m_message_rate_overhead > RemotePlayer::m_setting_chat_message_limit_trigger_kick) {
return RPLAYER_CHATRESULT_KICK;
}
return RPLAYER_CHATRESULT_FLOODING;
}
// Reinit message overhead
if (m_message_rate_overhead > 0) {
m_message_rate_overhead = 0;
}
m_chat_message_allowance -= 1.0f;
return RPLAYER_CHATRESULT_OK;
}
|