Planeshift

cmdbase.h

Go to the documentation of this file.
00001 /*
00002  * cmdbase.h - Author: Keith Fulton
00003  *
00004  * Copyright (C) 2001 Atomic Blue ([email protected], http://www.atomicblue.org) 
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 
00025 #ifndef __CMDBASE_H__
00026 #define __CMDBASE_H__
00027 
00028 #include "net/subscriber.h"
00029 #include "net/messages.h"
00030 #include <iutil/objreg.h>
00031 
00032 #include <ivaria/reporter.h>
00033 
00034 class  CmdHandler;  // needed for circular includes
00035 class  ClientMsgHandler;
00036 class  Client;  // dummy blind definition.  Only used on server.
00037 
00042 class psCmdBase : public iNetSubscriber, public iCmdSubscriber
00043 {
00044 protected:
00045     ClientMsgHandler   *msgqueue;
00046     CmdHandler         *cmdsource;
00047     iObjectRegistry    *objreg;
00048 
00049 public:
00050     psCmdBase(ClientMsgHandler *mh, CmdHandler *ch, iObjectRegistry* obj);
00051     
00052     virtual ~psCmdBase() {}
00053     virtual bool Setup(ClientMsgHandler* mh, CmdHandler* ch);
00054 
00055     // iCmdSubscriber interface
00056     virtual const char *HandleCommand(const char *cmd) = 0;
00057 
00058     // iNetSubscriber interface
00059     virtual void HandleMessage(MsgEntry *msg,Client*) { HandleMessage(msg); }
00060     virtual void HandleMessage(MsgEntry *msg) = 0;
00061     virtual bool Verify(MsgEntry *,unsigned int,Client *& ) { return true; }
00062 
00063     // Wrapper for csReport
00064     void Report(int severity, const char* msgtype, const char* description, ... );
00065 };
00066 
00067 class psClientNetSubscriber : public iNetSubscriber
00068 {
00069 public:
00070     virtual ~psClientNetSubscriber() {}
00071 
00072     // iNetSubscriber interface
00073     virtual void HandleMessage(MsgEntry *msg,Client*) { HandleMessage(msg); }
00074     virtual void HandleMessage(MsgEntry *msg) = 0;
00075     virtual bool Verify(MsgEntry *,unsigned int,Client *& ) { return true; }
00076 
00077 };
00078 
00081 #endif
00082