Planeshift
|
00001 /* 00002 * npcmessages.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 __NPCMESSAGES_H__ 00020 #define __NPCMESSAGES_H__ 00021 00022 #include "net/message.h" 00023 #include "net/messages.h" 00024 #include <csutil/csstring.h> 00025 #include <csutil/databuf.h> 00026 #include <csgeom/vector3.h> 00027 #include "util/psstring.h" 00028 00029 00030 // Forward declarations 00031 class Location; 00032 class LocationType; 00033 class Waypoint; 00034 class WaypointAlias; 00035 class psPath; 00036 class psPathPoint; 00037 struct iSector; 00038 00046 class psNPCAuthenticationMessage : public psAuthenticationMessage 00047 { 00048 public: 00049 00055 psNPCAuthenticationMessage(uint32_t clientnum, 00056 const char *userid, 00057 const char *password); 00058 00064 psNPCAuthenticationMessage(MsgEntry *message); 00065 00066 PSF_DECLARE_MSG_FACTORY(); 00067 00068 bool NetVersionOk(); 00069 }; 00070 00076 class psNPCListMessage : public psMessageCracker 00077 { 00078 public: 00079 00080 psString xml; 00081 00083 psNPCListMessage(uint32_t clientToken,int size); 00084 00086 psNPCListMessage(MsgEntry *message); 00087 00088 PSF_DECLARE_MSG_FACTORY(); 00089 00096 virtual csString ToString(NetBase::AccessPointers * accessPointers); 00097 }; 00098 00103 class psNPCReadyMessage : public psMessageCracker 00104 { 00105 public: 00107 psNPCReadyMessage(); 00108 00110 psNPCReadyMessage(MsgEntry *message); 00111 00112 PSF_DECLARE_MSG_FACTORY(); 00113 00120 virtual csString ToString(NetBase::AccessPointers * accessPointers); 00121 }; 00122 00128 class psMapListMessage : public psMessageCracker 00129 { 00130 public: 00131 00132 csArray<csString> map; 00133 00135 psMapListMessage(uint32_t clientToken,csString& str); 00136 00138 psMapListMessage(MsgEntry *message); 00139 00140 PSF_DECLARE_MSG_FACTORY(); 00141 00148 virtual csString ToString(NetBase::AccessPointers * accessPointers); 00149 }; 00150 00155 class psNPCRaceListMessage : public psMessageCracker 00156 { 00157 public: 00158 00159 typedef struct 00160 { 00161 csString name; 00162 float walkSpeed; 00163 float runSpeed; 00164 csVector3 size; 00165 float scale; 00166 } NPCRaceInfo_t; 00167 00168 00169 csArray<NPCRaceInfo_t> raceInfo; 00170 00172 psNPCRaceListMessage(uint32_t clientToken,int count); 00173 00175 psNPCRaceListMessage(MsgEntry *message); 00176 00177 PSF_DECLARE_MSG_FACTORY(); 00178 00182 void AddRace(csString& name, float walkSpeed, float runSpeed, const csVector3& size, float scale, bool last); 00183 00190 virtual csString ToString(NetBase::AccessPointers * accessPointers); 00191 }; 00192 00198 class psNPCCommandsMessage : public psMessageCracker 00199 { 00200 public: 00201 00202 enum Flags 00203 { 00204 NONE = 0, 00205 INVISIBLE = 1 << 0, 00206 INVINCIBLE = 1 << 1, 00207 IS_ALIVE = 1 << 2 00208 }; 00209 00210 enum PerceptionType 00211 { 00212 // Commands go from superclient to server 00213 CMD_TERMINATOR, 00214 CMD_ASSESS, 00215 CMD_ATTACK, 00216 CMD_BUSY, 00217 CMD_CAST, 00218 CMD_DELETE_NPC, 00219 CMD_DEQUIP, 00220 CMD_DRDATA, 00221 CMD_DROP, 00222 CMD_EMOTE, 00223 CMD_ANIMATION, 00224 CMD_EQUIP, 00225 CMD_TEMPORARILY_IMPERVIOUS, 00226 CMD_INFO_REPLY, 00227 CMD_PICKUP, 00228 CMD_RESURRECT, 00229 CMD_SEQUENCE, 00230 CMD_SCRIPT, // used for superclient to request a progress script to be run at server 00231 CMD_SIT, 00232 CMD_SPAWN, 00233 CMD_SPAWN_BUILDING, // used for superclient to request a new building 00234 CMD_TALK, 00235 CMD_TRANSFER, 00236 CMD_UNBUILD, // used for superclient to request a building to be tearn down 00237 CMD_VISIBILITY, 00238 CMD_WORK, 00239 CMD_CONTROL, 00240 CMD_LOOT, 00241 // Perceptions go from server to superclient 00242 PCPT_ANYRANGEPLAYER, 00243 PCPT_ASSESS, 00244 PCPT_ATTACK, 00245 PCPT_CHANGE_BRAIN, 00246 PCPT_DEATH, 00247 PCPT_DEBUG_NPC, 00248 PCPT_DEBUG_TRIBE, 00249 PCPT_DMG, 00250 PCPT_FAILED_TO_ATTACK, 00251 PCPT_FLAG, 00252 PCPT_GROUPATTACK, 00253 PCPT_INFO_REQUEST, // Command to superclient, not a perception 00254 PCPT_INVENTORY, 00255 PCPT_LONGRANGEPLAYER, 00256 PCPT_NPCCMD, 00257 PCPT_OWNER_ACTION, 00258 PCPT_OWNER_CMD, 00259 PCPT_PERCEPT, 00260 PCPT_SHORTRANGEPLAYER, 00261 PCPT_SPAWNED, 00262 PCPT_SPELL, 00263 PCPT_STAT_DR, 00264 PCPT_SPOKEN_TO, 00265 PCPT_TALK, 00266 PCPT_TELEPORT, 00267 PCPT_TRANSFER, 00268 PCPT_VERYSHORTRANGEPLAYER, 00269 PCPT_CHANGE_OWNER, // Command to superclient, not a perception 00270 }; 00271 00272 enum PerceptionTalkType 00273 { 00274 TALK_SAY, 00275 TALK_ME, 00276 TALK_MY, 00277 TALK_NARRATE 00278 }; 00279 00281 psNPCCommandsMessage(uint32_t clientToken, int size); 00282 00284 psNPCCommandsMessage(MsgEntry *message); 00285 00286 PSF_DECLARE_MSG_FACTORY(); 00287 00293 virtual csString ToString(NetBase::AccessPointers * accessPointers); 00294 }; 00295 00296 00297 //helpers for message splitting 00298 #define ALLENTITYPOS_SIZE_PER_ENTITY (4 * sizeof(float) + sizeof(bool) + sizeof(uint32_t) + 100*sizeof(char)) 00299 #define ALLENTITYPOS_MAX_AMOUNT (MAX_MESSAGE_SIZE-2)/ALLENTITYPOS_SIZE_PER_ENTITY 00300 00306 class psAllEntityPosMessage: public psMessageCracker 00307 { 00308 public: 00310 int count; 00311 00313 psAllEntityPosMessage() { count = 0; msg=NULL; } 00314 00316 psAllEntityPosMessage(MsgEntry *message); 00317 00318 PSF_DECLARE_MSG_FACTORY(); 00319 00326 virtual csString ToString(NetBase::AccessPointers * accessPointers); 00327 00329 void SetLength(int size,int client); 00330 00332 void Add(EID id, csVector3 & pos, iSector* & sector, InstanceID instance, csStringSet* msgstrings, bool forced = false); 00333 00335 EID Get(csVector3 & pos, iSector* & sector, InstanceID & instance, bool &forced, csStringSet* msgstrings, 00336 csStringHashReversible* msgstringshash, iEngine* engine); 00337 }; 00338 00343 class psNPCWorkDoneMessage : public psMessageCracker 00344 { 00345 public: 00346 EID npcEID; 00347 const char* resource; 00348 const char* nick; 00349 00350 psNPCWorkDoneMessage(uint32_t clientToken, EID npcEID, const char* resource, const char* nick); 00351 00352 psNPCWorkDoneMessage(MsgEntry *message); 00353 00354 PSF_DECLARE_MSG_FACTORY(); 00355 00356 virtual csString ToString(NetBase::AccessPointers* accessPointers); 00357 }; 00358 00363 class psNewNPCCreatedMessage : public psMessageCracker 00364 { 00365 public: 00366 PID new_npc_id, master_id, owner_id; 00367 00369 psNewNPCCreatedMessage(uint32_t clientToken, PID new_npc_id, PID master_id, PID owner_id); 00370 00372 psNewNPCCreatedMessage(MsgEntry *message); 00373 00374 PSF_DECLARE_MSG_FACTORY(); 00375 00382 virtual csString ToString(NetBase::AccessPointers * accessPointers); 00383 }; 00384 00389 class psNPCDeletedMessage : public psMessageCracker 00390 { 00391 public: 00392 PID npc_id; 00393 00395 psNPCDeletedMessage(uint32_t clientToken, PID npc_id); 00396 00398 psNPCDeletedMessage(MsgEntry *message); 00399 00400 PSF_DECLARE_MSG_FACTORY(); 00401 00408 virtual csString ToString(NetBase::AccessPointers * accessPointers); 00409 }; 00410 00415 class psPETCommandMessage : public psMessageCracker 00416 { 00417 public: 00418 00419 typedef enum 00420 { 00421 CMD_FOLLOW, 00422 CMD_STAY, 00423 CMD_DISMISS, 00424 CMD_SUMMON, 00425 CMD_ATTACK, 00426 CMD_GUARD, 00427 CMD_ASSIST, 00428 CMD_STOPATTACK, 00429 CMD_NAME, 00430 CMD_TARGET, 00431 CMD_RUN, 00432 CMD_WALK, 00433 CMD_LAST // LAST command, insert new commands before this 00434 } PetCommand_t; 00435 00436 static const char *petCommandString[]; 00437 00438 int command; 00439 psString target; 00440 psString options; 00441 00443 psPETCommandMessage(uint32_t clientToken, int cmd, const char * target, const char * options); 00444 00446 psPETCommandMessage(MsgEntry *message); 00447 00448 PSF_DECLARE_MSG_FACTORY(); 00449 00456 virtual csString ToString(NetBase::AccessPointers * accessPointers); 00457 }; 00458 00463 class psServerCommandMessage : public psMessageCracker 00464 { 00465 public: 00466 00467 psString command; 00468 00470 psServerCommandMessage(uint32_t clientToken, const char * target); 00471 00473 psServerCommandMessage(MsgEntry *message); 00474 00475 PSF_DECLARE_MSG_FACTORY(); 00476 00483 virtual csString ToString(NetBase::AccessPointers* accessPointers); 00484 }; 00485 00488 class psPathNetworkMessage : public psMessageCracker 00489 { 00490 public: 00491 00492 typedef enum 00493 { 00494 PATH_ADD_POINT, 00495 PATH_CREATE, 00496 PATH_RENAME, 00497 PATH_REMOVE_POINT, 00498 PATH_SET_FLAG, 00499 POINT_ADJUSTED, 00500 WAYPOINT_ADJUSTED, 00501 WAYPOINT_ALIAS_ADD, 00502 WAYPOINT_ALIAS_REMOVE, 00503 WAYPOINT_ALIAS_ROTATION_ANGLE, 00504 WAYPOINT_CREATE, 00505 WAYPOINT_RADIUS, 00506 WAYPOINT_RENAME, 00507 WAYPOINT_SET_FLAG 00508 } Command; 00509 00510 Command command; 00511 uint32_t id; 00512 csVector3 position; 00513 iSector* sector; 00514 csString string; 00515 bool enable; 00516 float radius; 00517 csString flags; 00518 uint32_t startId; 00519 uint32_t stopId; 00520 uint32_t secondId; 00521 float rotationAngle; 00522 uint32_t aliasID; 00523 00524 // Create psMessageBytes struct for outbound use 00525 00528 psPathNetworkMessage(Command command, const psPath* path); 00529 00532 psPathNetworkMessage(Command command, const psPath* path, const psPathPoint* point); 00533 00536 psPathNetworkMessage(Command command, const psPath* path, int secondId); 00537 00538 00541 psPathNetworkMessage(Command command, const psPath* path, const csString& string, bool enable); 00542 00545 psPathNetworkMessage(Command command, const psPathPoint* point); 00546 00549 psPathNetworkMessage(Command command, const Waypoint* waypoint); 00550 00553 psPathNetworkMessage(Command command, const Waypoint* waypoint, const WaypointAlias* alias); 00554 00557 psPathNetworkMessage(Command command, const Waypoint* waypoint, const csString& string); 00558 00561 psPathNetworkMessage(Command command, const Waypoint* waypoint, const csString& string, bool enable); 00562 00563 00565 psPathNetworkMessage(MsgEntry *message); 00566 00567 PSF_DECLARE_MSG_FACTORY(); 00568 00575 virtual csString ToString(NetBase::AccessPointers* accessPointers); 00576 }; 00577 00580 class psLocationMessage : public psMessageCracker 00581 { 00582 public: 00583 00584 typedef enum 00585 { 00586 LOCATION_ADJUSTED, 00587 LOCATION_CREATED, 00588 LOCATION_DELETED, 00589 LOCATION_INSERTED, 00590 LOCATION_RADIUS, 00591 LOCATION_RENAME, 00592 LOCATION_SET_FLAG, 00593 LOCATION_TYPE_ADD, 00594 LOCATION_TYPE_REMOVE 00595 } Command; 00596 00597 Command command; 00598 uint32_t id; 00599 csVector3 position; 00600 iSector* sector; 00601 bool enable; 00602 float radius; 00603 float rotationAngle; 00604 csString flags; 00605 csString typeName; 00606 csString name; 00607 uint32_t prevID; 00608 00609 // Create psMessageBytes struct for outbound use 00610 00613 psLocationMessage(Command command, const Location* location); 00614 00617 psLocationMessage(Command command, const LocationType* locationType); 00618 00621 psLocationMessage(Command command, const csString& name); 00622 00624 psLocationMessage(MsgEntry *message); 00625 00626 PSF_DECLARE_MSG_FACTORY(); 00627 00634 virtual csString ToString(NetBase::AccessPointers* accessPointers); 00635 }; 00636 00639 #endif 00640