Dragonfly 4.20
A text-based game engine
Public Member Functions | Protected Attributes | Private Member Functions | List of all members
df::NetworkNode Class Reference
Inheritance diagram for df::NetworkNode:
Inheritance graph

Public Member Functions

virtual int eventHandler (const Event *p_e) override
 
virtual int handleConnect (const EventNetwork *p_e)
 
virtual int handleClose (const EventNetwork *p_e)
 
virtual int handleAccept (const EventNetwork *p_e)
 
virtual int handleData (const EventNetwork *p_e)
 
int sendMessage (MessageType msg_type, int sock_index=-1)
 
int sendMessage (MessageType msg_type, Object *p_obj, unsigned int attr=0, int sock_index=-1)
 
int sendMessage (MessageType msg_type, EventKeyboardAction action, Keyboard::Key key, int sock_index=-1)
 
int sendMessage (MessageType msg_type, EventMouseAction action, Mouse::Button button, Vector mouse_position, int sock_index=-1)
 
int sendMessage (MessageType msg_type, int num_bytes, const void *bytes, int sock_index=-1)
 
virtual ObjectcreateObject (std::string object_type)
 
- Public Member Functions inherited from df::Object
 Object ()
 
virtual ~Object ()
 
void setId (int new_id)
 
int getId () const
 
virtual void setType (std::string new_type)
 
std::string getType () const
 
virtual int setPosition (Vector new_position)
 
Vector getPosition () const
 
virtual int eventHandler (const Event *p_event)
 
bool isSolid () const
 
virtual int setSolidness (Solidness new_solid)
 
Solidness getSolidness () const
 
void setNoSoft (bool new_no_soft=true)
 
bool getNoSoft () const
 
virtual void setAvoidCollisions (bool new_avoid_collisions=true)
 
bool getAvoidCollisions () const
 
virtual int setAltitude (int new_altitude)
 
int getAltitude () const
 
void setSpeed (float speed)
 
float getSpeed () const
 
virtual void setDirection (Vector new_direction)
 
Vector getDirection () const
 
virtual void setVelocity (Vector velocity)
 
Vector getVelocity () const
 
virtual void setAcceleration (Vector new_acceleration)
 
Vector getAcceleration () const
 
void accelerate ()
 
Vector predictPosition ()
 
void pathTo (Vector position)
 
void pathTo (Object *p_o_target)
 
void moveTo (Vector new_position)
 
void doPathFollowing ()
 
int setVisible (bool new_visible=true)
 
virtual bool isVisible () const
 
virtual int setActive (bool new_active=true)
 
bool isActive () const
 
virtual void setBox (Box new_box)
 
Box getBox () const
 
int registerInterest (std::string event_type)
 
int unregisterInterest (std::string event_type)
 
int getEventCount () const
 
virtual int setSprite (std::string sprite_label)
 
virtual void setAnimation (Animation new_animation, bool set_box=true)
 
Animation getAnimation () const
 
virtual int draw ()
 
virtual int serialize (std::stringstream *p_ss, unsigned int attr=0)
 
virtual int deserialize (std::stringstream *p_ss, unsigned int *p_a=NULL)
 
bool isModified (enum ObjectAttribute attribute) const
 
bool isModified () const
 
virtual void setModified (unsigned int new_modified)
 
virtual unsigned int getModified () const
 
virtual void setShape (Shape new_shape)
 
Shape getShape () const
 
virtual void setFollowPath (bool new_follow_path=true)
 
bool getFollowPath () const
 
void setPath (Path new_path)
 
Path getPath () const
 
PathFindgetPathFind ()
 
std::string toString () const
 
bool operator== (const Object &o)
 
bool operator!= (const Object &o)
 

Protected Attributes

char * m_p_buff
 
int m_buff_size
 

Private Member Functions

int sizeBuffer (int msg_size)
 
int prepMessageHeader (MessageType msg_type, int msg_size)
 

Additional Inherited Members

- Static Public Attributes inherited from df::Object
static int max_id
 

Member Function Documentation

◆ createObject()

virtual Object * df::NetworkNode::createObject ( std::string  object_type)
virtual

Create Object of given type.

Return pointer to Object.

◆ eventHandler()

virtual int df::NetworkNode::eventHandler ( const Event p_e)
overridevirtual

Handle network event.

Return 1 if handled, else 0 if ignored.

Reimplemented from df::Object.

◆ handleAccept()

virtual int df::NetworkNode::handleAccept ( const EventNetwork p_e)
virtual

Handle accept network event (base class does nothing).

Return 1 if handled, else 0 if ignored.

◆ handleClose()

virtual int df::NetworkNode::handleClose ( const EventNetwork p_e)
virtual

Handle closed socket (base class does nothing).

Return 1 if handled, else 0 if ignored.

◆ handleConnect()

virtual int df::NetworkNode::handleConnect ( const EventNetwork p_e)
virtual

Handle connect network event (base class does nothing).

Return 1 if handled, else 0 if ignored.

◆ handleData()

virtual int df::NetworkNode::handleData ( const EventNetwork p_e)
virtual

Handle data network event using data in m_p_buff.


Return 1 if handled, else 0 if ignored.

◆ prepMessageHeader()

int df::NetworkNode::prepMessageHeader ( MessageType  msg_type,
int  msg_size 
)
private

Prepare message buffer and header.

Return 0 if ok, else -1 if error.

◆ sendMessage() [1/5]

int df::NetworkNode::sendMessage ( MessageType  msg_type,
EventKeyboardAction  action,
Keyboard::Key  key,
int  sock_index = -1 
)

Send message from Client to Server.

KEYBOARD_INPUT Return 1 if something sent, 0 if nothing sent, -1 if error.

◆ sendMessage() [2/5]

int df::NetworkNode::sendMessage ( MessageType  msg_type,
EventMouseAction  action,
Mouse::Button  button,
Vector  mouse_position,
int  sock_index = -1 
)

Send message from Client to Server.

MOUSE_INPUT Return 1 if something sent, 0 if nothing sent, -1 if error.

◆ sendMessage() [3/5]

int df::NetworkNode::sendMessage ( MessageType  msg_type,
int  num_bytes,
const void *  bytes,
int  sock_index = -1 
)

Send message from Client to Server.

CUSTOM_MESSAGE Return 1 if something sent, 0 if nothing sent, -1 if error.

◆ sendMessage() [4/5]

int df::NetworkNode::sendMessage ( MessageType  msg_type,
int  sock_index = -1 
)

Send message (supporting various message types).

Send message from Server to Client. SET_GAME_OVER Return 1 if something sent, 0 if nothing sent, -1 if error.

◆ sendMessage() [5/5]

int df::NetworkNode::sendMessage ( MessageType  msg_type,
Object p_obj,
unsigned int  attr = 0,
int  sock_index = -1 
)

Send message from Server to Client.

SYNC_OBJECT or DELETE_OBJECT Synchronize attr, passed to serialize() (default is sync all). Return 1 if something sent, 0 if nothing sent, -1 if error.

◆ sizeBuffer()

int df::NetworkNode::sizeBuffer ( int  msg_size)
private

Increase size of network message buffer (if needed).

Return 0 if ok, else -1 if error.