2011-02-20 23:45:14 +01:00
|
|
|
/*
|
|
|
|
Minetest-c55
|
|
|
|
Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SERVEROBJECT_HEADER
|
|
|
|
#define SERVEROBJECT_HEADER
|
|
|
|
|
|
|
|
#include "common_irrlicht.h"
|
|
|
|
#include "activeobject.h"
|
|
|
|
#include "utility.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Some planning
|
|
|
|
-------------
|
|
|
|
|
|
|
|
* Server environment adds an active object, which gets the id 1
|
|
|
|
* The active object list is scanned for each client once in a while,
|
|
|
|
and it finds out what objects have been added that are not known
|
|
|
|
by the client yet. This scan is initiated by the server and the
|
|
|
|
result ends up directly to the server.
|
|
|
|
* A network packet is created with the info and sent to the client.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2011-02-21 15:10:36 +01:00
|
|
|
class ServerEnvironment;
|
|
|
|
|
2011-02-20 23:45:14 +01:00
|
|
|
class ServerActiveObject : public ActiveObject
|
|
|
|
{
|
|
|
|
public:
|
2011-02-21 15:10:36 +01:00
|
|
|
ServerActiveObject(ServerEnvironment *env, u16 id, v3f pos=v3f(0,0,0));
|
2011-02-20 23:45:14 +01:00
|
|
|
virtual ~ServerActiveObject();
|
|
|
|
|
|
|
|
v3f getBasePosition()
|
|
|
|
{
|
|
|
|
return m_base_position;
|
|
|
|
}
|
|
|
|
|
2011-02-21 15:10:36 +01:00
|
|
|
void setBasePosition(v3f pos)
|
|
|
|
{
|
|
|
|
m_base_position = pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
ServerEnvironment* getEnv()
|
|
|
|
{
|
|
|
|
return m_env;
|
|
|
|
}
|
|
|
|
|
2011-02-20 23:45:14 +01:00
|
|
|
/*
|
|
|
|
Step object in time.
|
|
|
|
Messages added to messages are sent to client over network.
|
|
|
|
*/
|
|
|
|
virtual void step(float dtime, Queue<ActiveObjectMessage> &messages){}
|
|
|
|
|
2011-02-21 15:10:36 +01:00
|
|
|
/*
|
|
|
|
The return value of this is passed to the client-side object
|
|
|
|
when it is created
|
|
|
|
*/
|
|
|
|
virtual std::string getClientInitializationData(){return "";}
|
|
|
|
|
|
|
|
/*
|
|
|
|
The return value of this is passed to the server-side object
|
|
|
|
when it is loaded from disk or from a static object
|
|
|
|
*/
|
|
|
|
virtual std::string getServerInitializationData(){return "";}
|
|
|
|
|
|
|
|
/*
|
|
|
|
This takes the return value of getServerInitializationData
|
|
|
|
*/
|
|
|
|
virtual void initialize(const std::string &data){}
|
|
|
|
|
|
|
|
// Number of players which know about this object
|
2011-02-20 23:45:14 +01:00
|
|
|
u16 m_known_by_count;
|
|
|
|
/*
|
2011-04-07 23:47:14 +02:00
|
|
|
- Whether this object is to be removed when nobody knows about
|
|
|
|
it anymore.
|
|
|
|
- Removal is delayed to preserve the id for the time during which
|
|
|
|
it could be confused to some other object by some client.
|
|
|
|
- This is set to true by the step() method when the object wants
|
|
|
|
to be deleted.
|
2011-02-20 23:45:14 +01:00
|
|
|
*/
|
|
|
|
bool m_removed;
|
|
|
|
|
|
|
|
protected:
|
2011-02-21 15:10:36 +01:00
|
|
|
ServerEnvironment *m_env;
|
2011-02-20 23:45:14 +01:00
|
|
|
v3f m_base_position;
|
|
|
|
};
|
|
|
|
|
|
|
|
class TestSAO : public ServerActiveObject
|
|
|
|
{
|
|
|
|
public:
|
2011-02-21 15:10:36 +01:00
|
|
|
TestSAO(ServerEnvironment *env, u16 id, v3f pos);
|
2011-02-20 23:45:14 +01:00
|
|
|
u8 getType() const
|
|
|
|
{
|
|
|
|
return ACTIVEOBJECT_TYPE_TEST;
|
|
|
|
}
|
|
|
|
void step(float dtime, Queue<ActiveObjectMessage> &messages);
|
|
|
|
private:
|
|
|
|
float m_timer1;
|
|
|
|
float m_age;
|
|
|
|
};
|
|
|
|
|
2011-04-07 23:47:14 +02:00
|
|
|
class ItemSAO : public ServerActiveObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ItemSAO(ServerEnvironment *env, u16 id, v3f pos,
|
|
|
|
const std::string inventorystring);
|
|
|
|
u8 getType() const
|
|
|
|
{
|
|
|
|
return ACTIVEOBJECT_TYPE_ITEM;
|
|
|
|
}
|
|
|
|
void step(float dtime, Queue<ActiveObjectMessage> &messages);
|
|
|
|
std::string getClientInitializationData();
|
|
|
|
private:
|
|
|
|
std::string m_inventorystring;
|
|
|
|
};
|
|
|
|
|
2011-02-20 23:45:14 +01:00
|
|
|
#endif
|
|
|
|
|