Planeshift
|
00001 /* 00002 * networkmgr.h 00003 * 00004 * Copyright (C) 2003 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 __NETWORKMGR_H__ 00020 #define __NETWORKMGR_H__ 00021 //============================================================================= 00022 // Crystal Space Includes 00023 //============================================================================= 00024 #include <csutil/csstring.h> 00025 00026 //============================================================================= 00027 // Library Includes 00028 //============================================================================= 00029 #include "net/cmdbase.h" // Subscriber class 00030 #include "net/npcmessages.h" 00031 #include "util/serverconsole.h" // iCommandCatcher 00032 00033 class MsgHandler; 00034 class EventManager; 00035 class psLinearMovement; 00036 00037 //============================================================================= 00038 // Local Includes 00039 //============================================================================= 00040 00045 class psNPCCommandsMessage; 00046 class psNetConnection; 00047 class psGameEvent; 00048 class NPC; 00049 class gemNPCActor; 00050 class gemNPCObject; 00051 class gemNPCItem; 00052 00056 class NetworkManager : public psClientNetSubscriber 00057 { 00058 protected: 00059 MsgHandler* msghandler; 00060 psNetConnection* connection; 00061 bool ready; 00062 bool connected; 00063 00064 // Command Message Queue 00065 psNPCCommandsMessage* outbound; 00066 csHash<NPC*,PID> cmd_dr_outbound; 00067 int cmd_count; 00068 00069 void RequestAllObjects(); 00070 00076 bool HandleMapList(MsgEntry* msg); 00077 00083 bool HandleNPCList(MsgEntry* msg); 00084 00090 void HandlePositionUpdates(MsgEntry* msg); 00091 00097 void HandlePersistMessage(MsgEntry* msg); 00098 00104 void HandlePerceptions(MsgEntry* msg); 00105 00111 void HandleDisconnect(MsgEntry* msg); 00112 00118 void HandleHiredNPCScript(MsgEntry* me); 00119 00125 void HandleTimeUpdate(MsgEntry* msg); 00126 00132 void HandleNPCWorkDone(MsgEntry* msg); 00133 00139 void HandleNewNpc(MsgEntry* msg); 00140 00146 void HandleNpcDeleted(MsgEntry* msg); 00147 00153 void HandleConsoleCommand(MsgEntry* me); 00154 00160 void HandleRaceList(MsgEntry* me); 00161 00167 void HandleAllEntities(MsgEntry* message); 00168 00174 void HandleActor(MsgEntry* msg); 00175 00181 void HandleItem(MsgEntry* me); 00182 00188 void HandleObjectRemoval(MsgEntry* me); 00189 00195 void HandlePathNetwork(MsgEntry* me); 00196 00202 void HandleLocation(MsgEntry* me); 00203 00204 csString host,password,user; 00205 int port; 00206 00207 public: 00208 00212 NetworkManager(MsgHandler* mh,psNetConnection* conn, iEngine* engine); 00213 00217 virtual ~NetworkManager(); 00218 00224 virtual void HandleMessage(MsgEntry* pMsg); 00225 00226 void Authenticate(csString &host,int port,csString &user,csString &pass); 00227 bool IsReady() 00228 { 00229 return ready; 00230 } 00231 void Disconnect(); 00232 00239 void CheckCommandsOverrun(size_t neededSize); 00240 00241 private: 00242 00252 void QueueDRDataCommand(NPC* npc); 00253 00254 public: 00258 void PrepareCommandMessage(); 00259 00265 void SendAllCommands(bool final = false); 00266 00275 void QueueDRData(NPC* npc); 00276 00285 void QueueDRData2(NPC* npc); 00286 00290 void DequeueDRData(NPC* npc); 00291 00299 void QueueAttackCommand(gemNPCActor* attacker, gemNPCActor* target, const char* stance, const char* attack_type); 00300 00308 void QueueScriptCommand(gemNPCActor* npc, gemNPCObject* target, const csString &scriptName); 00309 00317 void QueueSitCommand(gemNPCActor* npc, gemNPCObject* target, bool sit); 00318 00326 void QueueSpawnCommand(gemNPCActor* mother, gemNPCActor* father, const csString &tribeMemberType); 00327 00338 void QueueSpawnBuildingCommand(gemNPCActor* spawner, csVector3 where, iSector* sector, const char* buildingName, int tribeID, bool pickupable); 00339 00346 void QueueUnbuildCommand(gemNPCActor* unbuilder, gemNPCItem* building); 00347 00359 void QueueTalkCommand(gemNPCActor* speaker, gemNPCActor* target, psNPCCommandsMessage::PerceptionTalkType talkType, bool publicTalk, const char* text); 00360 00367 void QueueVisibilityCommand(gemNPCActor* entity, bool status); 00368 00376 void QueuePickupCommand(gemNPCActor* entity, gemNPCObject* item, int count); 00377 00385 void QueueEmoteCommand(gemNPCActor* npc, gemNPCObject* target, const csString &cmd); 00386 00393 void QueueAnimationCommand(gemNPCActor* npc, const csString &cmd); 00394 00398 void QueueEquipCommand(gemNPCActor* entity, csString item, csString slot, int count); 00399 00403 void QueueDequipCommand(gemNPCActor* entity, csString slot); 00404 00408 void QueueWorkCommand(gemNPCActor* entity, const csString &type, const csString &resource); 00409 00413 void QueueTransferCommand(gemNPCActor* entity, csString item, int count, csString target); 00414 00418 void QueueDeleteNPCCommand(NPC* npcx); 00419 00423 void QueueDropCommand(gemNPCActor* entity, csString slot); 00424 00428 void QueueResurrectCommand(csVector3 where, float rot, iSector* sector, PID character_id); 00429 00433 void QueueSequenceCommand(csString name, int cmd, int count); 00434 00441 void QueueTemporarilyImperviousCommand(gemNPCActor* entity, bool impervious); 00442 00449 void QueueSystemInfoCommand(uint32_t clientNum, const char* reply, ...); 00450 00455 void QueueAssessCommand(gemNPCActor* entity, gemNPCObject* target, const csString &physicalAssessmentPerception, 00456 const csString &magicalAssessmentPerception, const csString &overallAssessmentPerception); 00457 00461 void QueueCastCommand(gemNPCActor* entity, gemNPCObject* target, const csString &spell, float kFactor); 00462 00466 void QueueBusyCommand(gemNPCActor* entity, bool busy); 00467 00471 void QueueControlCommand(gemNPCActor* controllingEntity, gemNPCActor* controlledEntity); 00472 00476 void QueueLootCommand(gemNPCActor* entity, EID targetEID, const csString &type); 00477 00483 void SendConsoleCommand(const char* cmd); 00484 00488 csStringHashReversible* GetMsgStrings(); 00489 00493 const char* GetCommonString(uint32_t cstr_id); 00494 00498 uint32_t GetCommonStringID(const char* string); 00499 00503 void ReAuthenticate(); 00504 00508 void ReConnect(); 00509 00510 bool reconnect; 00511 00512 private: 00513 iEngine* engine; 00514 }; 00515 00516 class psNPCReconnect : public psGameEvent 00517 { 00518 protected: 00519 NetworkManager* networkMgr; 00520 bool authent; 00521 00522 public: 00523 psNPCReconnect(int offsetticks, NetworkManager* mgr, bool authent); 00524 virtual void Trigger(); // Abstract event processing function 00525 }; 00526 00529 #endif 00530