Planeshift

cmdhandler.h

Go to the documentation of this file.
00001 /*
00002  * cmdhandler.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 #ifndef __CmdHandler_H__
00020 #define __CmdHandler_H__
00021 
00022 #include <csutil/ref.h>
00023 #include <csutil/refcount.h>
00024 #include <csutil/list.h>
00025 #include <csutil/csstring.h>
00026 #include <csutil/parray.h>
00027 #include <csutil/redblacktree.h>
00028 #include <iutil/objreg.h>
00029 #include <csutil/redblacktree.h>
00030 
00031 #include "net/subscriber.h"
00032 #include "net/cmdbase.h"
00033 #include "util/psstring.h"
00034 
00035 class psChatWindow;
00036 
00041 // This little struct tracks who is interested in what.
00042 struct CmdSubscription
00043 {
00045     csString cmd;
00046 
00048     bool visible;
00049 
00051     iCmdSubscriber *subscriber;
00052 };
00053 
00054 class CmdHandler : public csRefCount
00055 {
00056 protected:
00057     iObjectRegistry*    objreg;
00058     csPDelArray<CmdSubscription>  subscribers;
00059 
00060 public:
00061     CmdHandler(iObjectRegistry *obj);
00062     virtual ~CmdHandler();
00063 
00064     enum
00065     {
00066     INVISIBLE_TO_USER = 0,
00067     VISIBLE_TO_USER = 1
00068     };
00073     bool Subscribe(const char *cmd, iCmdSubscriber *subscriber);
00074 
00076     bool Unsubscribe(const char *cmd, iCmdSubscriber *subscriber);
00077 
00079     bool UnsubscribeAll(iCmdSubscriber *subscriber);
00080     
00082     const char *Publish(const csString & cmd);
00083 
00090     void Execute(const char *script, bool breakSemiColon=true);
00091 
00093     void GetSubscribedCommands(csRedBlackTree<psString>& tree);
00094 };
00095 
00098 #endif
00099