// No prototype, PlayerSAO does not need to be deserialized
-PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
+PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, u16 peer_id_,
const std::set<std::string> &privs, bool is_singleplayer):
ServerActiveObject(env_, v3f(0,0,0)),
m_player(player_),
void PlayerSAO::removingFromEnvironment()
{
ServerActiveObject::removingFromEnvironment();
- if(m_player->getPlayerSAO() == this)
- {
+ if (m_player->getPlayerSAO() == this) {
m_player->setPlayerSAO(NULL);
m_player->peer_id = 0;
- m_env->savePlayer((RemotePlayer*)m_player);
+ m_env->savePlayer(m_player);
m_env->removePlayer(m_player);
}
}
class PlayerSAO : public ServerActiveObject
{
public:
- PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
+ PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, u16 peer_id_,
const std::set<std::string> &privs, bool is_singleplayer);
~PlayerSAO();
ActiveObjectType getType() const
void disconnected();
- Player* getPlayer()
- {
- return m_player;
- }
- u16 getPeerID() const
- {
- return m_peer_id;
- }
+ RemotePlayer* getPlayer() { return m_player; }
+ u16 getPeerID() const { return m_peer_id; }
// Cheat prevention
private:
std::string getPropertyPacket();
- Player *m_player;
+ RemotePlayer *m_player;
u16 m_peer_id;
Inventory *m_inventory;
s16 m_damage;
s32 wheel = input->getMouseWheel();
u16 max_item = MYMIN(PLAYER_INVENTORY_SIZE - 1,
- player->hud_hotbar_itemcount - 1);
+ player->hud_hotbar_itemcount - 1);
s32 dir = wheel;
m_cao = toset;
}
+ u32 maxHudId() const { return hud.size(); }
+
private:
void accelerateHorizontal(const v3f &target_speed, const f32 max_increase);
void accelerateVertical(const v3f &target_speed, const f32 max_increase);
*pkt >> param >> value;
- Player *player = m_env.getLocalPlayer();
+ LocalPlayer *player = m_env.getLocalPlayer();
assert(player != NULL);
if (param == HUD_PARAM_HOTBAR_ITEMCOUNT && value.size() == 4) {
player->hud_hotbar_itemcount = hotbar_itemcount;
}
else if (param == HUD_PARAM_HOTBAR_IMAGE) {
- ((LocalPlayer *) player)->hotbar_image = value;
+ player->hotbar_image = value;
}
else if (param == HUD_PARAM_HOTBAR_SELECTED_IMAGE) {
- ((LocalPlayer *) player)->hotbar_selected_image = value;
+ player->hotbar_selected_image = value;
}
}
pitch = modulo360f(pitch);
yaw = modulo360f(yaw);
- Player *player = m_env->getPlayer(pkt->getPeerId());
+ RemotePlayer *player =
+ dynamic_cast<RemotePlayer *>(m_env->getPlayer(pkt->getPeerId()));
if (player == NULL) {
errorstream << "Server::ProcessData(): Canceling: "
"No player for peer_id=" << pkt->getPeerId()
void Server::handleCommand_InventoryAction(NetworkPacket* pkt)
{
- Player *player = m_env->getPlayer(pkt->getPeerId());
+ RemotePlayer *player =
+ dynamic_cast<RemotePlayer *>(m_env->getPlayer(pkt->getPeerId()));
+
if (player == NULL) {
errorstream << "Server::ProcessData(): Canceling: "
"No player for peer_id=" << pkt->getPeerId()
*pkt >> damage;
- Player *player = m_env->getPlayer(pkt->getPeerId());
+ RemotePlayer *player =
+ dynamic_cast<RemotePlayer *>(m_env->getPlayer(pkt->getPeerId()));
+
if (player == NULL) {
errorstream << "Server::ProcessData(): Canceling: "
"No player for peer_id=" << pkt->getPeerId()
*pkt >> breath;
- Player *player = m_env->getPlayer(pkt->getPeerId());
+ RemotePlayer *player =
+ dynamic_cast<RemotePlayer *>(m_env->getPlayer(pkt->getPeerId()));
+
if (player == NULL) {
errorstream << "Server::ProcessData(): Canceling: "
"No player for peer_id=" << pkt->getPeerId()
if (pkt->getSize() < 2)
return;
- Player *player = m_env->getPlayer(pkt->getPeerId());
+ RemotePlayer *player =
+ dynamic_cast<RemotePlayer *>(m_env->getPlayer(pkt->getPeerId()));
+
if (player == NULL) {
errorstream << "Server::ProcessData(): Canceling: "
"No player for peer_id=" << pkt->getPeerId()
verbosestream << "TOSERVER_INTERACT: action=" << (int)action << ", item="
<< item_i << ", pointed=" << pointed.dump() << std::endl;
- Player *player = m_env->getPlayer(pkt->getPeerId());
+ RemotePlayer *player =
+ dynamic_cast<RemotePlayer *>(m_env->getPlayer(pkt->getPeerId()));
+
if (player == NULL) {
errorstream << "Server::ProcessData(): Canceling: "
"No player for peer_id=" << pkt->getPeerId()
fields[fieldname] = pkt->readLongString();
}
- Player *player = m_env->getPlayer(pkt->getPeerId());
+ RemotePlayer *player =
+ dynamic_cast<RemotePlayer *>(m_env->getPlayer(pkt->getPeerId()));
+
if (player == NULL) {
errorstream << "Server::ProcessData(): Canceling: "
"No player for peer_id=" << pkt->getPeerId()
fields[fieldname] = pkt->readLongString();
}
- Player *player = m_env->getPlayer(pkt->getPeerId());
+ RemotePlayer *player =
+ dynamic_cast<RemotePlayer *>(m_env->getPlayer(pkt->getPeerId()));
+
if (player == NULL) {
errorstream << "Server::ProcessData(): Canceling: "
"No player for peer_id=" << pkt->getPeerId()
return size;
}
- void setHotbarItemcount(s32 hotbar_itemcount)
- {
- hud_hotbar_itemcount = hotbar_itemcount;
- }
-
- s32 getHotbarItemcount()
- {
- return hud_hotbar_itemcount;
- }
-
void setHotbarImage(const std::string &name)
{
hud_hotbar_image = name;
*params = m_sky_params;
}
- void overrideDayNightRatio(bool do_override, float ratio)
- {
- m_day_night_ratio_do_override = do_override;
- m_day_night_ratio = ratio;
- }
-
- void getDayNightRatio(bool *do_override, float *ratio)
- {
- *do_override = m_day_night_ratio_do_override;
- *ratio = m_day_night_ratio;
- }
-
void setLocalAnimations(v2s32 frames[4], float frame_speed)
{
for (int i = 0; i < 4; i++)
return false;
}
- virtual PlayerSAO *getPlayerSAO()
- {
- return NULL;
- }
-
virtual void setPlayerSAO(PlayerSAO *sao)
{
FATAL_ERROR("FIXME");
void setModified(const bool x)
{
m_dirty = x;
- if (x == false)
+ if (!x)
inventory.setModified(x);
}
std::string inventory_formspec;
PlayerControl control;
- PlayerControl getPlayerControl()
- {
- return control;
- }
+ const PlayerControl& getPlayerControl() { return control; }
u32 keyPressed;
u32 addHud(HudElement* hud);
HudElement* removeHud(u32 id);
void clearHud();
- u32 maxHudId() {
- return hud.size();
- }
u32 hud_flags;
s32 hud_hotbar_itemcount;
std::string m_sky_type;
video::SColor m_sky_bgcolor;
std::vector<std::string> m_sky_params;
-
- bool m_day_night_ratio_do_override;
- float m_day_night_ratio;
private:
// Protect some critical areas
// hud for example can be modified by EmergeThread
const RemotePlayerChatResult canSendChatMessage();
+ void setHotbarItemcount(s32 hotbar_itemcount)
+ {
+ hud_hotbar_itemcount = hotbar_itemcount;
+ }
+
+ s32 getHotbarItemcount() const { return hud_hotbar_itemcount; }
+
+ void overrideDayNightRatio(bool do_override, float ratio)
+ {
+ m_day_night_ratio_do_override = do_override;
+ m_day_night_ratio = ratio;
+ }
+
+ void getDayNightRatio(bool *do_override, float *ratio)
+ {
+ *do_override = m_day_night_ratio_do_override;
+ *ratio = m_day_night_ratio;
+ }
+
private:
PlayerSAO *m_sao;
u32 m_last_chat_message_sent;
float m_chat_message_allowance;
u16 m_message_rate_overhead;
+
+ bool m_day_night_ratio_do_override;
+ float m_day_night_ratio;
};
#endif
// Do it
const char *name = luaL_checkstring(L, 1);
- Player *player = env->getPlayer(name);
- if(player == NULL){
+ RemotePlayer *player = dynamic_cast<RemotePlayer *>(env->getPlayer(name));
+ if (player == NULL){
lua_pushnil(L);
return 1;
}
return (PlayerSAO*)obj;
}
-Player* ObjectRef::getplayer(ObjectRef *ref)
+RemotePlayer* ObjectRef::getplayer(ObjectRef *ref)
{
PlayerSAO *playersao = getplayersao(ref);
if (playersao == NULL)
lua_pushlstring(L, "", 0);
return 1;
}
- // Do it
- PlayerControl control = player->getPlayerControl();
+
+ const PlayerControl &control = player->getPlayerControl();
lua_newtable(L);
lua_pushboolean(L, control.up);
lua_setfield(L, -2, "up");
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
- Player *player = getplayer(ref);
+ RemotePlayer *player = getplayer(ref);
if (player == NULL)
return 0;
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
- Player *player = getplayer(ref);
+ RemotePlayer *player = getplayer(ref);
if (player == NULL)
return 0;
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
- Player *player = getplayer(ref);
+ RemotePlayer *player = getplayer(ref);
if (player == NULL)
return 0;
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
- Player *player = getplayer(ref);
+ RemotePlayer *player = getplayer(ref);
if (player == NULL)
return 0;
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
- Player *player = getplayer(ref);
+ RemotePlayer *player = getplayer(ref);
if (player == NULL)
return 0;
class LuaEntitySAO;
class PlayerSAO;
class Player;
+class RemotePlayer;
/*
ObjectRef
static PlayerSAO* getplayersao(ObjectRef *ref);
- static Player* getplayer(ObjectRef *ref);
+ static RemotePlayer* getplayer(ObjectRef *ref);
// Exported functions
break;
case InventoryLocation::PLAYER:
{
- Player *player = m_env->getPlayer(loc.name.c_str());
+ RemotePlayer *player = dynamic_cast<RemotePlayer *>(m_env->getPlayer(loc.name.c_str()));
if(!player)
return NULL;
PlayerSAO *playersao = player->getPlayerSAO();
if (!playerSend)
return;
- Player *player = m_env->getPlayer(loc.name.c_str());
- if(!player)
+ RemotePlayer *player =
+ dynamic_cast<RemotePlayer *>(m_env->getPlayer(loc.name.c_str()));
+
+ if (!player)
return;
+
PlayerSAO *playersao = player->getPlayerSAO();
if(!playersao)
return;
++i;
}
- Player *player = m_env->getPlayer(peer_id);
+ RemotePlayer *player = dynamic_cast<RemotePlayer *>(m_env->getPlayer(peer_id));
/* Run scripts and remove from environment */
- {
- if(player != NULL)
- {
- PlayerSAO *playersao = player->getPlayerSAO();
- assert(playersao);
+ if(player != NULL) {
+ PlayerSAO *playersao = player->getPlayerSAO();
+ assert(playersao);
- m_script->on_leaveplayer(playersao, reason == CDR_TIMEOUT);
+ m_script->on_leaveplayer(playersao, reason == CDR_TIMEOUT);
- playersao->disconnected();
- }
+ playersao->disconnected();
}
/*
SendChatMessage(PEER_ID_INEXISTENT,message);
}
-void Server::UpdateCrafting(Player* player)
+void Server::UpdateCrafting(RemotePlayer* player)
{
DSTACK(FUNCTION_NAME);
loc.setPlayer(player->getName());
std::vector<ItemStack> output_replacements;
getCraftingResult(&player->inventory, preview, output_replacements, false, this);
- m_env->getScriptIface()->item_CraftPredict(preview, player->getPlayerSAO(), (&player->inventory)->getList("craft"), loc);
+ m_env->getScriptIface()->item_CraftPredict(preview, player->getPlayerSAO(),
+ (&player->inventory)->getList("craft"), loc);
// Put the new preview in
InventoryList *plist = player->inventory.getList("craftpreview");
PlayerSAO* Server::getPlayerSAO(u16 peer_id)
{
- Player *player = m_env->getPlayer(peer_id);
- if(player == NULL)
+ RemotePlayer *player = dynamic_cast<RemotePlayer *>(m_env->getPlayer(peer_id));
+ if (player == NULL)
return NULL;
return player->getPlayerSAO();
}
reportPrivsModified(player->getName());
}
} else {
- Player *player = m_env->getPlayer(name.c_str());
- if(!player)
+ RemotePlayer *player =
+ dynamic_cast<RemotePlayer *>(m_env->getPlayer(name.c_str()));
+ if (!player)
return;
SendPlayerPrivileges(player->peer_id);
PlayerSAO *sao = player->getPlayerSAO();
return true;
}
-bool Server::hudSetFlags(Player *player, u32 flags, u32 mask)
+bool Server::hudSetFlags(RemotePlayer *player, u32 flags, u32 mask)
{
if (!player)
return false;
return true;
}
-bool Server::hudSetHotbarItemcount(Player *player, s32 hotbar_itemcount)
+bool Server::hudSetHotbarItemcount(RemotePlayer *player, s32 hotbar_itemcount)
{
if (!player)
return false;
+
if (hotbar_itemcount <= 0 || hotbar_itemcount > HUD_HOTBAR_ITEMCOUNT_MAX)
return false;
return true;
}
-s32 Server::hudGetHotbarItemcount(Player *player)
-{
- if (!player)
- return 0;
- return player->getHotbarItemcount();
-}
-
void Server::hudSetHotbarImage(Player *player, std::string name)
{
if (!player)
return true;
}
-bool Server::overrideDayNightRatio(Player *player, bool do_override,
+bool Server::overrideDayNightRatio(RemotePlayer *player, bool do_override,
float ratio)
{
if (!player)
#include "environment.h"
#include "chat_interface.h"
#include "clientiface.h"
+#include "player.h"
#include "network/networkpacket.h"
#include <string>
#include <list>
class BanManager;
class EventManager;
class Inventory;
-class Player;
class PlayerSAO;
class IRollbackManager;
struct RollbackAction;
u32 hudAdd(Player *player, HudElement *element);
bool hudRemove(Player *player, u32 id);
bool hudChange(Player *player, u32 id, HudElementStat stat, void *value);
- bool hudSetFlags(Player *player, u32 flags, u32 mask);
- bool hudSetHotbarItemcount(Player *player, s32 hotbar_itemcount);
- s32 hudGetHotbarItemcount(Player *player);
+ bool hudSetFlags(RemotePlayer *player, u32 flags, u32 mask);
+ bool hudSetHotbarItemcount(RemotePlayer *player, s32 hotbar_itemcount);
+ s32 hudGetHotbarItemcount(RemotePlayer *player) const
+ { return player->getHotbarItemcount(); }
void hudSetHotbarImage(Player *player, std::string name);
std::string hudGetHotbarImage(Player *player);
void hudSetHotbarSelectedImage(Player *player, std::string name);
bool setSky(Player *player, const video::SColor &bgcolor,
const std::string &type, const std::vector<std::string> ¶ms);
- bool overrideDayNightRatio(Player *player, bool do_override, float brightness);
+ bool overrideDayNightRatio(RemotePlayer *player, bool do_override, float brightness);
/* con::PeerHandler implementation. */
void peerAdded(con::Peer *peer);
void DiePlayer(u16 peer_id);
void RespawnPlayer(u16 peer_id);
void DeleteClient(u16 peer_id, ClientDeletionReason reason);
- void UpdateCrafting(Player *player);
+ void UpdateCrafting(RemotePlayer *player);
void handleChatInterfaceEvent(ChatEvent *evt);