Planeshift
cmdhandler.h
Go to the documentation of this file.
1 /*
2  * cmdhandler.h - Author: Keith Fulton
3  *
4  * Copyright (C) 2001 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 #ifndef __CmdHandler_H__
20 #define __CmdHandler_H__
21 
22 #include <csutil/ref.h>
23 #include <csutil/refcount.h>
24 #include <csutil/list.h>
25 #include <csutil/csstring.h>
26 #include <csutil/parray.h>
27 #include <csutil/redblacktree.h>
28 #include <iutil/objreg.h>
29 #include <csutil/redblacktree.h>
30 
31 #include "net/subscriber.h"
32 #include "net/cmdbase.h"
33 #include "util/psstring.h"
34 
35 class psChatWindow;
36 
41 // This little struct tracks who is interested in what.
43 {
45  csString cmd;
46 
48  bool visible;
49 
52 };
53 
54 class CmdHandler : public csRefCount
55 {
56 protected:
57  iObjectRegistry* objreg;
58  csPDelArray<CmdSubscription> subscribers;
59 
60 public:
61  CmdHandler(iObjectRegistry *obj);
62  virtual ~CmdHandler();
63 
64  enum
65  {
66  INVISIBLE_TO_USER = 0,
67  VISIBLE_TO_USER = 1
68  };
73  bool Subscribe(const char *cmd, iCmdSubscriber *subscriber);
74 
76  bool Unsubscribe(const char *cmd, iCmdSubscriber *subscriber);
77 
79  bool UnsubscribeAll(iCmdSubscriber *subscriber);
80 
82  const char *Publish(const csString & cmd);
83 
90  void Execute(const char *script, bool breakSemiColon=true);
91 
93  void GetSubscribedCommands(csRedBlackTree<psString>& tree);
94 };
95 
98 #endif
99 
This interface must be implemented by objects that want to receive command line strings messages...
Definition: subscriber.h:52
iObjectRegistry * objreg
Definition: cmdhandler.h:57
csPDelArray< CmdSubscription > subscribers
Definition: cmdhandler.h:58
bool visible
is this command visible to user in /help command?
Definition: cmdhandler.h:48
csString cmd
name of command this listener listens to, like "/say"
Definition: cmdhandler.h:45
iCmdSubscriber * subscriber
pointer to the subscriber
Definition: cmdhandler.h:51