ServerRemotePlayer implements ServerActiveObject
authorPerttu Ahola <celeron55@gmail.com>
Sat, 12 Nov 2011 13:41:29 +0000 (15:41 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Tue, 29 Nov 2011 17:13:40 +0000 (19:13 +0200)
src/content_object.h
src/player.cpp
src/player.h
src/server.cpp
src/serverobject.h

index f092b2789139f043c957860c31af13d640d3c453..af863614893052753aa8bf072912c288d9ad4721 100644 (file)
@@ -29,5 +29,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #define ACTIVEOBJECT_TYPE_LUAENTITY 7
 
+// Special type, not stored in active object lists
+#define ACTIVEOBJECT_TYPE_PLAYER 100
+
 #endif
 
index 73291182813d3396081d98b98a8f5569e13de525..396ce2494537224a794ab32e4cb3f50603ccfdee 100644 (file)
@@ -144,16 +144,12 @@ void Player::deSerialize(std::istream &is)
                args.parseConfigLine(line);
        }
 
-       //args.getS32("version");
+       //args.getS32("version"); // Version field value not used
        std::string name = args.get("name");
        updateName(name.c_str());
-       /*std::string password = "";
-       if(args.exists("password"))
-               password = args.get("password");
-       updatePassword(password.c_str());*/
-       m_pitch = args.getFloat("pitch");
-       m_yaw = args.getFloat("yaw");
-       m_position = args.getV3F("position");
+       setPitch(args.getFloat("pitch"));
+       setYaw(args.getFloat("yaw"));
+       setPosition(args.getV3F("position"));
        try{
                craftresult_is_preview = args.getBool("craftresult_is_preview");
        }catch(SettingNotFoundException &e){
@@ -164,20 +160,6 @@ void Player::deSerialize(std::istream &is)
        }catch(SettingNotFoundException &e){
                hp = 20;
        }
-       /*try{
-               std::string sprivs = args.get("privs");
-               if(sprivs == "all")
-               {
-                       privs = PRIV_ALL;
-               }
-               else
-               {
-                       std::istringstream ss(sprivs);
-                       ss>>privs;
-               }
-       }catch(SettingNotFoundException &e){
-               privs = PRIV_DEFAULT;
-       }*/
 
        inventory.deSerialize(is);
 }
index a352c1bd94790bfe8d38cf388f119443990ca69c..c3be0789415ce8b9009d75d96d3a91a3eba8f9e8 100644 (file)
@@ -179,11 +179,23 @@ public:
        Player on the server
 */
 
-class ServerRemotePlayer : public Player
+#include "serverobject.h"
+#include "content_object.h" // Object type IDs
+
+class ServerRemotePlayer : public Player, public ServerActiveObject
 {
 public:
-       ServerRemotePlayer()
+       ServerRemotePlayer():
+               ServerActiveObject(NULL, v3f(0,0,0))
+       {
+       }
+       ServerRemotePlayer(ServerEnvironment *env, v3f pos_, u16 peer_id_,
+                       const char *name_):
+               ServerActiveObject(env, pos_)
        {
+               setPosition(pos_);
+               peer_id = peer_id_;
+               updateName(name_);
        }
        virtual ~ServerRemotePlayer()
        {
@@ -198,6 +210,17 @@ public:
        {
        }
        
+       virtual void setPosition(const v3f &position)
+       {
+               Player::setPosition(position);
+               ServerActiveObject::setBasePosition(position);
+       }
+
+       /*
+               ServerActiveObject interface
+       */
+       u8 getType() const
+               {return ACTIVEOBJECT_TYPE_PLAYER;}
 private:
 };
 
index fd9703bd56d0a509633101fcdcc6e26da4e38ecf..330ce21c2c912cdeccd8e6e8c78d74f7df6c3538 100644 (file)
@@ -4279,11 +4279,7 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id
                Create a new player
        */
        {
-               player = new ServerRemotePlayer();
-               //player->peer_id = c.peer_id;
-               //player->peer_id = PEER_ID_INEXISTENT;
-               player->peer_id = peer_id;
-               player->updateName(name);
+               // Add authentication stuff
                m_authmanager.add(name);
                m_authmanager.setPassword(name, password);
                m_authmanager.setPrivs(name,
@@ -4294,11 +4290,11 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id
                */
                
                infostream<<"Server: Finding spawn place for player \""
-                               <<player->getName()<<"\""<<std::endl;
+                               <<name<<"\""<<std::endl;
 
                v3f pos = findSpawnPos(m_env->getServerMap());
 
-               player->setPosition(pos);
+               player = new ServerRemotePlayer(m_env, pos, peer_id, name);
 
                /*
                        Add player to environment
index 6d616c75e60b66a8a5d7a22f240a8d24e1ba10cc..66118cca021460985eb146e8702f4e4b51f9200d 100644 (file)
@@ -72,13 +72,14 @@ public:
                Some more dynamic interface
        */
        virtual void setPos(v3f pos)
-       { setBasePosition(pos); }
+               { setBasePosition(pos); }
        // continuous: if true, object does not stop immediately at pos
        virtual void moveTo(v3f pos, bool continuous)
-       { setBasePosition(pos); }
+               { setBasePosition(pos); }
        // If object has moved less than this and data has not changed,
        // saving to disk may be omitted
-       virtual float getMinimumSavedMovement(){ return 2.0*BS; }
+       virtual float getMinimumSavedMovement()
+               { return 2.0*BS; }
 
        /*
                Step object in time.