Planeshift
cmdbase.h
Go to the documentation of this file.
1 /*
2  * cmdbase.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 
25 #ifndef __CMDBASE_H__
26 #define __CMDBASE_H__
27 
28 #include "net/subscriber.h"
29 #include "net/messages.h"
30 #include <iutil/objreg.h>
31 
32 #include <ivaria/reporter.h>
33 
34 class CmdHandler; // needed for circular includes
35 class ClientMsgHandler;
36 class Client; // dummy blind definition. Only used on server.
37 
42 class psCmdBase : public iNetSubscriber, public iCmdSubscriber
43 {
44 protected:
47  iObjectRegistry *objreg;
48 
49 public:
50  psCmdBase(ClientMsgHandler *mh, CmdHandler *ch, iObjectRegistry* obj);
51 
52  virtual ~psCmdBase() {}
53  virtual bool Setup(ClientMsgHandler* mh, CmdHandler* ch);
54 
55  // iCmdSubscriber interface
56  virtual const char *HandleCommand(const char *cmd) = 0;
57 
58  // iNetSubscriber interface
59  virtual void HandleMessage(MsgEntry *msg,Client*) { HandleMessage(msg); }
60  virtual void HandleMessage(MsgEntry *msg) = 0;
61  virtual bool Verify(MsgEntry *,unsigned int,Client *& ) { return true; }
62 
63  // Wrapper for csReport
64  void Report(int severity, const char* msgtype, const char* description, ... );
65 };
66 
68 {
69 public:
71 
72  // iNetSubscriber interface
73  virtual void HandleMessage(MsgEntry *msg,Client*) { HandleMessage(msg); }
74  virtual void HandleMessage(MsgEntry *msg) = 0;
75  virtual bool Verify(MsgEntry *,unsigned int,Client *& ) { return true; }
76 
77 };
78 
81 #endif
82 
This interface must be implemented by objects that want to receive command line strings messages...
Definition: subscriber.h:52
virtual void HandleMessage(MsgEntry *msg, Client *)
Interprets a received message and executes the command.
Definition: cmdbase.h:59
virtual ~psCmdBase()
Definition: cmdbase.h:52
virtual bool Verify(MsgEntry *, unsigned int, Client *&)
Definition: cmdbase.h:61
The structure of 1 queue entry (pointer to a message)
Definition: message.h:143
Handles messages to be sent out, connects to server and send those.
void Report(int severity, const char *msgtype, const char *description,...)
This interface must be implemented by objects that want to receive network messages.
Definition: subscriber.h:37
psCmdBase(ClientMsgHandler *mh, CmdHandler *ch, iObjectRegistry *obj)
virtual bool Verify(MsgEntry *, unsigned int, Client *&)
Definition: cmdbase.h:75
ClientMsgHandler * msgqueue
Definition: cmdbase.h:45
This class collects data of a netclient.
Definition: client.h:95
iObjectRegistry * objreg
Definition: cmdbase.h:47
uint8_t msgtype
Definition: message.h:56
virtual ~psClientNetSubscriber()
Definition: cmdbase.h:70
virtual const char * HandleCommand(const char *cmd)=0
Interprets a received message and executes the command.
CmdHandler * cmdsource
Definition: cmdbase.h:46
virtual void HandleMessage(MsgEntry *msg, Client *)
Interprets a received message and executes the command.
Definition: cmdbase.h:73
virtual bool Setup(ClientMsgHandler *mh, CmdHandler *ch)