Planeshift
networkmgr.h
Go to the documentation of this file.
1 /*
2  * networkmgr.h
3  *
4  * Copyright (C) 2003 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 __NETWORKMGR_H__
20 #define __NETWORKMGR_H__
21 //=============================================================================
22 // Crystal Space Includes
23 //=============================================================================
24 #include <csutil/csstring.h>
25 
26 //=============================================================================
27 // Library Includes
28 //=============================================================================
29 #include "net/cmdbase.h" // Subscriber class
30 #include "net/npcmessages.h"
31 #include "util/serverconsole.h" // iCommandCatcher
32 
33 class MsgHandler;
34 class EventManager;
35 class psLinearMovement;
36 
37 //=============================================================================
38 // Local Includes
39 //=============================================================================
40 
46 class psNetConnection;
47 class psGameEvent;
48 class NPC;
49 class gemNPCActor;
50 class gemNPCObject;
51 class gemNPCItem;
52 
57 {
58 protected:
61  bool ready;
62  bool connected;
63 
64  // Command Message Queue
66  csHash<NPC*,PID> cmd_dr_outbound;
67  int cmd_count;
68 
69  void RequestAllObjects();
70 
76  bool HandleMapList(MsgEntry* msg);
77 
83  bool HandleNPCList(MsgEntry* msg);
84 
91 
97  void HandlePersistMessage(MsgEntry* msg);
98 
104  void HandlePerceptions(MsgEntry* msg);
105 
111  void HandleDisconnect(MsgEntry* msg);
112 
118  void HandleHiredNPCScript(MsgEntry* me);
119 
125  void HandleTimeUpdate(MsgEntry* msg);
126 
132  void HandleNPCWorkDone(MsgEntry* msg);
133 
139  void HandleNewNpc(MsgEntry* msg);
140 
146  void HandleNpcDeleted(MsgEntry* msg);
147 
153  void HandleConsoleCommand(MsgEntry* me);
154 
160  void HandleRaceList(MsgEntry* me);
161 
167  void HandleAllEntities(MsgEntry* message);
168 
174  void HandleActor(MsgEntry* msg);
175 
181  void HandleItem(MsgEntry* me);
182 
188  void HandleObjectRemoval(MsgEntry* me);
189 
195  void HandlePathNetwork(MsgEntry* me);
196 
202  void HandleLocation(MsgEntry* me);
203 
204  csString host,password,user;
205  int port;
206 
207 public:
208 
212  NetworkManager(MsgHandler* mh,psNetConnection* conn, iEngine* engine);
213 
217  virtual ~NetworkManager();
218 
224  virtual void HandleMessage(MsgEntry* pMsg);
225 
226  void Authenticate(csString &host,int port,csString &user,csString &pass);
227  bool IsReady()
228  {
229  return ready;
230  }
231  void Disconnect();
232 
239  void CheckCommandsOverrun(size_t neededSize);
240 
241 private:
242 
252  void QueueDRDataCommand(NPC* npc);
253 
254 public:
258  void PrepareCommandMessage();
259 
265  void SendAllCommands(bool final = false);
266 
275  void QueueDRData(NPC* npc);
276 
285  void QueueDRData2(NPC* npc);
286 
290  void DequeueDRData(NPC* npc);
291 
299  void QueueAttackCommand(gemNPCActor* attacker, gemNPCActor* target, const char* stance, const char* attack_type);
300 
308  void QueueScriptCommand(gemNPCActor* npc, gemNPCObject* target, const csString &scriptName);
309 
317  void QueueSitCommand(gemNPCActor* npc, gemNPCObject* target, bool sit);
318 
326  void QueueSpawnCommand(gemNPCActor* mother, gemNPCActor* father, const csString &tribeMemberType);
327 
338  void QueueSpawnBuildingCommand(gemNPCActor* spawner, csVector3 where, iSector* sector, const char* buildingName, int tribeID, bool pickupable);
339 
346  void QueueUnbuildCommand(gemNPCActor* unbuilder, gemNPCItem* building);
347 
359  void QueueTalkCommand(gemNPCActor* speaker, gemNPCActor* target, psNPCCommandsMessage::PerceptionTalkType talkType, bool publicTalk, const char* text);
360 
367  void QueueVisibilityCommand(gemNPCActor* entity, bool status);
368 
376  void QueuePickupCommand(gemNPCActor* entity, gemNPCObject* item, int count);
377 
385  void QueueEmoteCommand(gemNPCActor* npc, gemNPCObject* target, const csString &cmd);
386 
393  void QueueAnimationCommand(gemNPCActor* npc, const csString &cmd);
394 
398  void QueueEquipCommand(gemNPCActor* entity, csString item, csString slot, int count);
399 
403  void QueueDequipCommand(gemNPCActor* entity, csString slot);
404 
408  void QueueWorkCommand(gemNPCActor* entity, const csString &type, const csString &resource);
409 
413  void QueueTransferCommand(gemNPCActor* entity, csString item, int count, csString target);
414 
418  void QueueDeleteNPCCommand(NPC* npcx);
419 
423  void QueueDropCommand(gemNPCActor* entity, csString slot);
424 
428  void QueueResurrectCommand(csVector3 where, float rot, iSector* sector, PID character_id);
429 
433  void QueueSequenceCommand(csString name, int cmd, int count);
434 
441  void QueueTemporarilyImperviousCommand(gemNPCActor* entity, bool impervious);
442 
449  void QueueSystemInfoCommand(uint32_t clientNum, const char* reply, ...);
450 
455  void QueueAssessCommand(gemNPCActor* entity, gemNPCObject* target, const csString &physicalAssessmentPerception,
456  const csString &magicalAssessmentPerception, const csString &overallAssessmentPerception);
457 
461  void QueueCastCommand(gemNPCActor* entity, gemNPCObject* target, const csString &spell, float kFactor);
462 
466  void QueueBusyCommand(gemNPCActor* entity, bool busy);
467 
471  void QueueControlCommand(gemNPCActor* controllingEntity, gemNPCActor* controlledEntity);
472 
476  void QueueLootCommand(gemNPCActor* entity, EID targetEID, const csString &type);
477 
483  void SendConsoleCommand(const char* cmd);
484 
488  csStringHashReversible* GetMsgStrings();
489 
493  const char* GetCommonString(uint32_t cstr_id);
494 
498  uint32_t GetCommonStringID(const char* string);
499 
503  void ReAuthenticate();
504 
508  void ReConnect();
509 
510  bool reconnect;
511 
512 private:
513  iEngine* engine;
514 };
515 
517 {
518 protected:
520  bool authent;
521 
522 public:
523  psNPCReconnect(int offsetticks, NetworkManager* mgr, bool authent);
524  virtual void Trigger(); // Abstract event processing function
525 };
526 
529 #endif
530 
void QueueVisibilityCommand(gemNPCActor *entity, bool status)
Queue a change in visibility.
void HandleHiredNPCScript(MsgEntry *me)
Handle Hired npc script from server.
void QueueAssessCommand(gemNPCActor *entity, gemNPCObject *target, const csString &physicalAssessmentPerception, const csString &magicalAssessmentPerception, const csString &overallAssessmentPerception)
Send a command to do an assessment.
void HandlePositionUpdates(MsgEntry *msg)
Handle update update of positions from server.
void CheckCommandsOverrun(size_t neededSize)
Checks if the npc command message could overrun if the neededSize is tried to be added.
void SendAllCommands(bool final=false)
Send the queued commands.
csString user
Definition: networkmgr.h:204
MsgHandler * msghandler
Definition: networkmgr.h:59
NetworkManager * networkMgr
Definition: networkmgr.h:519
void QueueLootCommand(gemNPCActor *entity, EID targetEID, const csString &type)
Send a command to loot selected target.
void QueueDRData(NPC *npc)
Queue the NPC for an DR Update to the server.
void QueueSystemInfoCommand(uint32_t clientNum, const char *reply,...)
Send an system info command to the client.
void ReAuthenticate()
Reauthenicate with the server.
The structure of 1 queue entry (pointer to a message)
Definition: message.h:143
void HandleNpcDeleted(MsgEntry *msg)
Handle information from server about deleted NPC.
Client-side UDP handler.
Definition: connection.h:42
Movement related class.
Definition: linmove.h:68
Handle all network messages inn and out of the NPC Client.
Definition: networkmgr.h:56
int cmd_count
Entities queued for sending of DR.
Definition: networkmgr.h:67
void RequestAllObjects()
Number of command messages queued.
void QueueSitCommand(gemNPCActor *npc, gemNPCObject *target, bool sit)
Send a sit command to server.
void QueueBusyCommand(gemNPCActor *entity, bool busy)
Send a command to change the busy state.
void QueueSpawnCommand(gemNPCActor *mother, gemNPCActor *father, const csString &tribeMemberType)
Send a spawn command to server.
void QueueScriptCommand(gemNPCActor *npc, gemNPCObject *target, const csString &scriptName)
Send a script command to server.
void Authenticate(csString &host, int port, csString &user, csString &pass)
void QueueWorkCommand(gemNPCActor *entity, const csString &type, const csString &resource)
Send a command to start working.
psNetConnection * connection
Definition: networkmgr.h:60
void HandleLocation(MsgEntry *me)
Handle location changes from server.
bool HandleNPCList(MsgEntry *msg)
Handle a list of npcs received from server.
void HandleTimeUpdate(MsgEntry *msg)
Handle time updates from server.
NetworkManager(MsgHandler *mh, psNetConnection *conn, iEngine *engine)
Construct the network manager.
void HandleNPCWorkDone(MsgEntry *msg)
Handle information from server that work is done.
void QueueCastCommand(gemNPCActor *entity, gemNPCObject *target, const csString &spell, float kFactor)
Send a command to start cast a spell.
void QueueEmoteCommand(gemNPCActor *npc, gemNPCObject *target, const csString &cmd)
Send an emote command to server.
bool HandleMapList(MsgEntry *msg)
Handle the map list received from server.
void HandleItem(MsgEntry *me)
Handle a new item from server.
void HandleNewNpc(MsgEntry *msg)
Handle information from server about NPCs to use.
void QueueAttackCommand(gemNPCActor *attacker, gemNPCActor *target, const char *stance, const char *attack_type)
Queue an Attack Command for an NPC to the server.
psNPCCommandsMessage * outbound
Definition: networkmgr.h:65
void ReConnect()
Reconnect to the server server.
This object represents each NPC managed by this superclient.
Definition: npc.h:126
void HandleActor(MsgEntry *msg)
Handle an actor from server.
void HandleDisconnect(MsgEntry *msg)
Handle command to disconnect from server.
void QueueTalkCommand(gemNPCActor *speaker, gemNPCActor *target, psNPCCommandsMessage::PerceptionTalkType talkType, bool publicTalk, const char *text)
Queue a talk command to the server.
void QueueUnbuildCommand(gemNPCActor *unbuilder, gemNPCItem *building)
Send a unbuild command to server.
csString password
Definition: networkmgr.h:204
uint32_t GetCommonStringID(const char *string)
Convert a string into a common string id.
This class is the client&#39;s and server&#39;s main interface for either sending network messages out or get...
Definition: msghandler.h:106
void QueueResurrectCommand(csVector3 where, float rot, iSector *sector, PID character_id)
Send a command to resurrect.
void QueueAnimationCommand(gemNPCActor *npc, const csString &cmd)
Send an animation command to server.
void DequeueDRData(NPC *npc)
Call to remove queued dr updates when entities are removed/deleted.
void QueueDeleteNPCCommand(NPC *npcx)
Send a command to delete a npc.
void HandlePathNetwork(MsgEntry *me)
Handle changes to path network from server.
void HandleConsoleCommand(MsgEntry *me)
void SendConsoleCommand(const char *cmd)
Send a console command.
void QueuePickupCommand(gemNPCActor *entity, gemNPCObject *item, int count)
Queue a command to pickup a item.
const char * GetCommonString(uint32_t cstr_id)
Convert a common string id into the corresponding string.
csHash< NPC *, PID > cmd_dr_outbound
Definition: networkmgr.h:66
void QueueEquipCommand(gemNPCActor *entity, csString item, csString slot, int count)
Send a command to equip an equipment.
csStringHashReversible * GetMsgStrings()
Get the message string table.
void HandleRaceList(MsgEntry *me)
Handle list of races from server.
void QueueTransferCommand(gemNPCActor *entity, csString item, int count, csString target)
Send a command to transfere an item between two entities.
void QueueDequipCommand(gemNPCActor *entity, csString slot)
Send a command to dequip an equipment.
void HandlePersistMessage(MsgEntry *msg)
Handle new entities from server.
csString host
Definition: networkmgr.h:204
bool IsReady()
Definition: networkmgr.h:227
void QueueControlCommand(gemNPCActor *controllingEntity, gemNPCActor *controlledEntity)
Send a command start controll an entity.
virtual ~NetworkManager()
Destructor.
void HandleAllEntities(MsgEntry *message)
Handle list of all entities from server.
void HandlePerceptions(MsgEntry *msg)
Handle perceptions from the server.
void QueueSpawnBuildingCommand(gemNPCActor *spawner, csVector3 where, iSector *sector, const char *buildingName, int tribeID, bool pickupable)
Send a spawn building command to server.
void HandleObjectRemoval(MsgEntry *me)
Handle removal of an object from server.
void QueueDropCommand(gemNPCActor *entity, csString slot)
Send a command to drop the content of a slot.
All scheduled events must inherit from this class.
Definition: gameevent.h:36
void QueueSequenceCommand(csString name, int cmd, int count)
Send a command to start a sequence.
virtual void HandleMessage(MsgEntry *pMsg)
Handle all messages from server and send them to specefic Handle functions for each message type...
void QueueDRData2(NPC *npc)
Queue the NPC for an DR Update to the server.
This class handles all queueing and invoking of timed events, such as combat, spells, NPC dialog responses, range weapons, or NPC respawning.
Definition: eventmanager.h:40
void PrepareCommandMessage()
Prepare a new command message allow for queuing of new commands.
bool reconnect
Set to true if reconnect should be done.
Definition: networkmgr.h:510
void QueueTemporarilyImperviousCommand(gemNPCActor *entity, bool impervious)
Send a command to change the temporarily impervious status.
The message sent from server to superclient after successful login.
Definition: npcmessages.h:198