/*
* actionhandler.h
*
* Copyright (C) 2005 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
*
* Credits : 
*           Michael Cummings <cummings.michael@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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Creation Date: 1/20/2005
* Description : client handler for clickable map object actions
*
*/
#ifndef ACTIONHANDLER_H
#define ACTIONHANDLER_H

#include <csutil/parray.h>
#include <csutil/ref.h>
#include <csutil/weakref.h>
#include "net/cmdbase.h"
#include "util/growarray.h"
#include "util/prb.h"
#include "net/messages.h"

class  MsgHandler;

/**
 *  This class handles mode messages from the server, specifying
 *  actions for a clicked location.  Right now, all
 *  it does is display a description, but in the future
 *  this class could also trigger whatever else we think of.
 */
class ActionHandler : public psClientNetSubscriber
{
protected:

    iObjectRegistry*        object_reg;
    csRef<MsgHandler>        msghandler;

public:

    ActionHandler( MsgHandler* mh, iObjectRegistry* object_reg );
    virtual ~ActionHandler();
    void HandleMessage( MsgEntry* me );

    /** Creates and XML Query to send to the server. 
     *   Create XML query
     *   <PRE>
     *   <location>
     *     <sector></sector>
     *     <mesh></mesh>
     *     <polygon></polygon>
     *     <position><x/><y/><z/></position>
     *     <triggertype</triggertype>
     *   <location>
     *   </PRE>
     */
    void Query( const char* trigger, const char* sector, const char* mesh, int32_t poly, csVector3 pos );

    /** Command server to save an action location to the database. 
      * Create XML query
      * <PRE>
      * <location>
      *     <id></id>
      *     <masterid></masterid>
      *     <name></name>
      *     <sector></sector>
      *     <mesh></mesh>
      *     <polygon></polygon>
      *     <position><x/><y/><z/></position>
      *     <radius></radius>
      *     <triggertype></triggertype>
      *     <responsetype></responsetype>
      *     <response></respoonse>
      * <location>          
      * </PRE>
      */
    void Save( const char* id, const char* masterid, const char* name, const char* sector, const char* mesh, const char* poly, const char* posx, const char* posy, const char* posz, const char* radius, const char* triggertype, const char* responsetype, const char* response );

    /** Command server to remove an action location. 
      * Create XML query
      * <PRE>
      * <location>
      *     <id></id>
      * <location> 
      * </PRE>
      */
    void DeleteAction( const char* id );

    /** Resend the client actions back to the client. */
    void ReloadCache( );
};

#endif

