Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
cs_go.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6/* ScriptData
7Name: go_commandscript
8%Complete: 100
9Comment: All go related commands
10Category: commandscripts
11EndScriptData */
12
13#include "Chat.h"
14#include "Language.h"
15#include "MapManager.h"
16#include "ObjectMgr.h"
17#include "Player.h"
18#include "ScriptMgr.h"
19#include "TicketMgr.h"
20
22{
23public:
24 go_commandscript() : CommandScript("go_commandscript") { }
25
26 std::vector<ChatCommand> GetCommands() const OVERRIDE
27 {
28 static std::vector<ChatCommand> goCommandTable =
29 {
40 };
41
42 static std::vector<ChatCommand> commandTable =
43 {
44 { "go", rbac::RBAC_PERM_COMMAND_GO, false, NULL, "", goCommandTable },
45 };
46 return commandTable;
47 }
48
59 //teleport to creature
60 static bool HandleGoCreatureCommand(ChatHandler* handler, char const* args)
61 {
62 if (!*args)
63 return false;
64
65 Player* player = handler->GetSession()->GetPlayer();
66
67 // "id" or number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
68 char* param1 = handler->extractKeyFromLink((char*)args, "Hcreature");
69 if (!param1)
70 return false;
71
72 std::ostringstream whereClause;
73
74 // User wants to teleport to the NPC's template entry
75 if (strcmp(param1, "id") == 0)
76 {
77 // Get the "creature_template.entry"
78 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
79 char* tail = strtok(NULL, "");
80 if (!tail)
81 return false;
82 char* id = handler->extractKeyFromLink(tail, "Hcreature_entry");
83 if (!id)
84 return false;
85
86 int32 entry = atoi(id);
87 if (!entry)
88 return false;
89
90 whereClause << "WHERE id = '" << entry << '\'';
91 }
92 else
93 {
94 int32 guid = atoi(param1);
95
96 // Number is invalid - maybe the user specified the mob's name
97 if (!guid)
98 {
99 std::string name = param1;
100 WorldDatabase.EscapeString(name);
101 whereClause << ", creature_template WHERE creature.id = creature_template.entry AND creature_template.name " _LIKE_ " '" << name << '\'';
102 }
103 else
104 whereClause << "WHERE guid = '" << guid << '\'';
105 }
106
107 QueryResult result = WorldDatabase.PQuery("SELECT position_x, position_y, position_z, orientation, map, guid, id FROM creature %s", whereClause.str().c_str());
108 if (!result)
109 {
111 handler->SetSentErrorMessage(true);
112 return false;
113 }
114 if (result->GetRowCount() > 1)
116
117 Field* fields = result->Fetch();
118 float x = fields[0].GetFloat();
119 float y = fields[1].GetFloat();
120 float z = fields[2].GetFloat();
121 float ort = fields[3].GetFloat();
122 int mapId = fields[4].GetUInt16();
123 uint32 guid = fields[5].GetUInt32();
124 uint32 id = fields[6].GetUInt32();
125
126 // if creature is in same map with caster go at its current location
127 if (Creature* creature = sObjectAccessor->GetCreature(*player, MAKE_NEW_GUID(guid, id, HIGHGUID_UNIT)))
128 {
129 x = creature->GetPositionX();
130 y = creature->GetPositionY();
131 z = creature->GetPositionZ();
132 ort = creature->GetOrientation();
133 }
134
135 if (!MapManager::IsValidMapCoord(mapId, x, y, z, ort))
136 {
137 handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, mapId);
138 handler->SetSentErrorMessage(true);
139 return false;
140 }
141
142 // stop flight if need
143 if (player->IsInFlight())
144 {
145 player->GetMotionMaster()->MovementExpired();
146 player->CleanupAfterTaxiFlight();
147 }
148 // save only in non-flight case
149 else
150 player->SaveRecallPosition();
151
152 player->TeleportTo(mapId, x, y, z, ort);
153 return true;
154 }
155
156 static bool HandleGoGraveyardCommand(ChatHandler* handler, char const* args)
157 {
158 Player* player = handler->GetSession()->GetPlayer();
159
160 if (!*args)
161 return false;
162
163 char* gyId = strtok((char*)args, " ");
164 if (!gyId)
165 return false;
166
167 int32 graveyardId = atoi(gyId);
168
169 if (!graveyardId)
170 return false;
171
172 WorldSafeLocsEntry const* gy = sWorldSafeLocsStore.LookupEntry(graveyardId);
173 if (!gy)
174 {
175 handler->PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, graveyardId);
176 handler->SetSentErrorMessage(true);
177 return false;
178 }
179
180 if (!MapManager::IsValidMapCoord(gy->map_id, gy->x, gy->y, gy->z))
181 {
182 handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, gy->x, gy->y, gy->map_id);
183 handler->SetSentErrorMessage(true);
184 return false;
185 }
186
187 // stop flight if need
188 if (player->IsInFlight())
189 {
190 player->GetMotionMaster()->MovementExpired();
191 player->CleanupAfterTaxiFlight();
192 }
193 // save only in non-flight case
194 else
195 player->SaveRecallPosition();
196
197 player->TeleportTo(gy->map_id, gy->x, gy->y, gy->z, player->GetOrientation());
198 return true;
199 }
200
201 //teleport to grid
202 static bool HandleGoGridCommand(ChatHandler* handler, char const* args)
203 {
204 if (!*args)
205 return false;
206
207 Player* player = handler->GetSession()->GetPlayer();
208
209 char* gridX = strtok((char*)args, " ");
210 char* gridY = strtok(NULL, " ");
211 char* id = strtok(NULL, " ");
212
213 if (!gridX || !gridY)
214 return false;
215
216 uint32 mapId = id ? (uint32)atoi(id) : player->GetMapId();
217
218 // center of grid
219 float x = ((float)atof(gridX) - CENTER_GRID_ID + 0.5f) * SIZE_OF_GRIDS;
220 float y = ((float)atof(gridY) - CENTER_GRID_ID + 0.5f) * SIZE_OF_GRIDS;
221
222 if (!MapManager::IsValidMapCoord(mapId, x, y))
223 {
224 handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, mapId);
225 handler->SetSentErrorMessage(true);
226 return false;
227 }
228
229 // stop flight if need
230 if (player->IsInFlight())
231 {
232 player->GetMotionMaster()->MovementExpired();
233 player->CleanupAfterTaxiFlight();
234 }
235 // save only in non-flight case
236 else
237 player->SaveRecallPosition();
238
239 Map const* map = sMapMgr->CreateBaseMap(mapId);
240 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
241
242 player->TeleportTo(mapId, x, y, z, player->GetOrientation());
243 return true;
244 }
245
246 //teleport to gameobject
247 static bool HandleGoObjectCommand(ChatHandler* handler, char const* args)
248 {
249 if (!*args)
250 return false;
251
252 Player* player = handler->GetSession()->GetPlayer();
253
254 // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
255 char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
256 if (!id)
257 return false;
258
259 int32 guid = atoi(id);
260 if (!guid)
261 return false;
262
263 float x, y, z, ort;
264 int mapId;
265
266 // by DB guid
267 if (GameObjectData const* goData = sObjectMgr->GetGOData(guid))
268 {
269 x = goData->posX;
270 y = goData->posY;
271 z = goData->posZ;
272 ort = goData->orientation;
273 mapId = goData->mapid;
274 }
275 else
276 {
278 handler->SetSentErrorMessage(true);
279 return false;
280 }
281
282 if (!MapManager::IsValidMapCoord(mapId, x, y, z, ort))
283 {
284 handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, mapId);
285 handler->SetSentErrorMessage(true);
286 return false;
287 }
288
289 // stop flight if need
290 if (player->IsInFlight())
291 {
292 player->GetMotionMaster()->MovementExpired();
293 player->CleanupAfterTaxiFlight();
294 }
295 // save only in non-flight case
296 else
297 player->SaveRecallPosition();
298
299 player->TeleportTo(mapId, x, y, z, ort);
300 return true;
301 }
302
303 static bool HandleGoTaxinodeCommand(ChatHandler* handler, char const* args)
304 {
305 Player* player = handler->GetSession()->GetPlayer();
306
307 if (!*args)
308 return false;
309
310 char* id = handler->extractKeyFromLink((char*)args, "Htaxinode");
311 if (!id)
312 return false;
313
314 int32 nodeId = atoi(id);
315 if (!nodeId)
316 return false;
317
318 TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(nodeId);
319 if (!node)
320 {
322 handler->SetSentErrorMessage(true);
323 return false;
324 }
325
326 if ((node->x == 0.0f && node->y == 0.0f && node->z == 0.0f) ||
327 !MapManager::IsValidMapCoord(node->map_id, node->x, node->y, node->z))
328 {
329 handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, node->x, node->y, node->map_id);
330 handler->SetSentErrorMessage(true);
331 return false;
332 }
333
334 // stop flight if need
335 if (player->IsInFlight())
336 {
337 player->GetMotionMaster()->MovementExpired();
338 player->CleanupAfterTaxiFlight();
339 }
340 // save only in non-flight case
341 else
342 player->SaveRecallPosition();
343
344 player->TeleportTo(node->map_id, node->x, node->y, node->z, player->GetOrientation());
345 return true;
346 }
347
348 static bool HandleGoTriggerCommand(ChatHandler* handler, char const* args)
349 {
350 Player* player = handler->GetSession()->GetPlayer();
351
352 if (!*args)
353 return false;
354
355 char* id = strtok((char*)args, " ");
356 if (!id)
357 return false;
358
359 int32 areaTriggerId = atoi(id);
360
361 if (!areaTriggerId)
362 return false;
363
364 AreaTriggerEntry const* at = sAreaTriggerStore.LookupEntry(areaTriggerId);
365 if (!at)
366 {
367 handler->PSendSysMessage(LANG_COMMAND_GOAREATRNOTFOUND, areaTriggerId);
368 handler->SetSentErrorMessage(true);
369 return false;
370 }
371
372 if (!MapManager::IsValidMapCoord(at->mapid, at->x, at->y, at->z))
373 {
374 handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, at->x, at->y, at->mapid);
375 handler->SetSentErrorMessage(true);
376 return false;
377 }
378
379 // stop flight if need
380 if (player->IsInFlight())
381 {
382 player->GetMotionMaster()->MovementExpired();
383 player->CleanupAfterTaxiFlight();
384 }
385 // save only in non-flight case
386 else
387 player->SaveRecallPosition();
388
389 player->TeleportTo(at->mapid, at->x, at->y, at->z, player->GetOrientation());
390 return true;
391 }
392
393 //teleport at coordinates
394 static bool HandleGoZoneXYCommand(ChatHandler* handler, char const* args)
395 {
396 if (!*args)
397 return false;
398
399 Player* player = handler->GetSession()->GetPlayer();
400
401 char* zoneX = strtok((char*)args, " ");
402 char* zoneY = strtok(NULL, " ");
403 char* tail = strtok(NULL, "");
404
405 char* id = handler->extractKeyFromLink(tail, "Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
406
407 if (!zoneX || !zoneY)
408 return false;
409
410 float x = (float)atof(zoneX);
411 float y = (float)atof(zoneY);
412
413 // prevent accept wrong numeric args
414 if ((x == 0.0f && *zoneX != '0') || (y == 0.0f && *zoneY != '0'))
415 return false;
416
417 uint32 areaId = id ? (uint32)atoi(id) : player->GetZoneId();
418
419 AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaId);
420
421 if (x < 0 || x > 100 || y < 0 || y > 100 || !areaEntry)
422 {
423 handler->PSendSysMessage(LANG_INVALID_ZONE_COORD, x, y, areaId);
424 handler->SetSentErrorMessage(true);
425 return false;
426 }
427
428 // update to parent zone if exist (client map show only zones without parents)
429 AreaTableEntry const* zoneEntry = areaEntry->m_ParentAreaID ? GetAreaEntryByAreaID(areaEntry->m_ParentAreaID) : areaEntry;
430
431 Map const* map = sMapMgr->CreateBaseMap(zoneEntry->m_ContinentID);
432
433 if (map->Instanceable())
434 {
435 handler->PSendSysMessage(LANG_INVALID_ZONE_MAP, areaEntry->m_ID, areaEntry->m_AreaName, map->GetId(), map->GetMapName());
436 handler->SetSentErrorMessage(true);
437 return false;
438 }
439
440 Zone2MapCoordinates(x, y, zoneEntry->m_ID);
441
442 if (!MapManager::IsValidMapCoord(zoneEntry->m_ContinentID, x, y))
443 {
444 handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, zoneEntry->m_ContinentID);
445 handler->SetSentErrorMessage(true);
446 return false;
447 }
448
449 // stop flight if need
450 if (player->IsInFlight())
451 {
452 player->GetMotionMaster()->MovementExpired();
453 player->CleanupAfterTaxiFlight();
454 }
455 // save only in non-flight case
456 else
457 player->SaveRecallPosition();
458
459 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
460
461 player->TeleportTo(zoneEntry->m_ContinentID, x, y, z, player->GetOrientation());
462 return true;
463 }
464
465 //teleport at coordinates, including Z and orientation
466 static bool HandleGoXYZCommand(ChatHandler* handler, char const* args)
467 {
468 if (!*args)
469 return false;
470
471 Player* player = handler->GetSession()->GetPlayer();
472
473 char* goX = strtok((char*)args, " ");
474 char* goY = strtok(NULL, " ");
475 char* goZ = strtok(NULL, " ");
476 char* id = strtok(NULL, " ");
477 char* port = strtok(NULL, " ");
478
479 if (!goX || !goY)
480 return false;
481
482 float x = (float)atof(goX);
483 float y = (float)atof(goY);
484 float z;
485 float ort = port ? (float)atof(port) : player->GetOrientation();
486 uint32 mapId = id ? (uint32)atoi(id) : player->GetMapId();
487
488 if (goZ)
489 {
490 z = (float)atof(goZ);
491 if (!MapManager::IsValidMapCoord(mapId, x, y, z))
492 {
493 handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, mapId);
494 handler->SetSentErrorMessage(true);
495 return false;
496 }
497 }
498 else
499 {
500 if (!MapManager::IsValidMapCoord(mapId, x, y))
501 {
502 handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, mapId);
503 handler->SetSentErrorMessage(true);
504 return false;
505 }
506 Map const* map = sMapMgr->CreateBaseMap(mapId);
507 z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
508 }
509
510 // stop flight if need
511 if (player->IsInFlight())
512 {
513 player->GetMotionMaster()->MovementExpired();
514 player->CleanupAfterTaxiFlight();
515 }
516 // save only in non-flight case
517 else
518 player->SaveRecallPosition();
519
520 player->TeleportTo(mapId, x, y, z, ort);
521 return true;
522 }
523
524 static bool HandleGoTicketCommand(ChatHandler* handler, char const* args)
525 {
526 if (!*args)
527 return false;
528
529 char* id = strtok((char*)args, " ");
530 if (!id)
531 return false;
532
533 uint32 ticketId = atoi(id);
534 if (!ticketId)
535 return false;
536
537 GmTicket* ticket = sTicketMgr->GetTicket(ticketId);
538 if (!ticket)
539 {
541 return true;
542 }
543
544 Player* player = handler->GetSession()->GetPlayer();
545 if (player->IsInFlight())
546 {
547 player->GetMotionMaster()->MovementExpired();
548 player->CleanupAfterTaxiFlight();
549 }
550 else
551 player->SaveRecallPosition();
552
553 ticket->TeleportTo(player);
554 return true;
555 }
556};
557
559{
560 new go_commandscript();
561}
DBCStorage< WorldSafeLocsEntry > sWorldSafeLocsStore(WorldSafeLocsEntryfmt)
void Zone2MapCoordinates(float &x, float &y, uint32 zone)
DBCStorage< AreaTriggerEntry > sAreaTriggerStore(AreaTriggerEntryfmt)
DBCStorage< TaxiNodesEntry > sTaxiNodesStore(TaxiNodesEntryfmt)
AreaTableEntry const * GetAreaEntryByAreaID(uint32 area_id)
#define _LIKE_
Definition DatabaseEnv.h:19
std::int32_t int32
Definition Define.h:73
std::uint32_t uint32
Definition Define.h:77
#define OVERRIDE
Definition Define.h:60
#define SIZE_OF_GRIDS
Definition GridDefines.h:26
#define CENTER_GRID_ID
Definition GridDefines.h:27
@ LANG_COMMAND_GOCREATNOTFOUND
Definition Language.h:275
@ LANG_COMMAND_GRAVEYARDNOEXIST
Definition Language.h:429
@ LANG_COMMAND_GOAREATRNOTFOUND
Definition Language.h:269
@ LANG_COMMAND_GOTAXINODENOTFOUND
Definition Language.h:354
@ LANG_INVALID_ZONE_MAP
Definition Language.h:272
@ LANG_COMMAND_GOOBJNOTFOUND
Definition Language.h:274
@ LANG_INVALID_TARGET_COORD
Definition Language.h:270
@ LANG_COMMAND_GOCREATMULTIPLE
Definition Language.h:276
@ LANG_COMMAND_TICKETNOTEXIST
Definition Language.h:1040
@ LANG_INVALID_ZONE_COORD
Definition Language.h:271
#define MAX_HEIGHT
Definition Map.h:141
#define sMapMgr
Definition MapManager.h:145
#define sObjectAccessor
@ HIGHGUID_UNIT
uint64 MAKE_NEW_GUID(uint32 l, uint32 e, uint32 h)
#define sObjectMgr
Definition ObjectMgr.h:1617
Skyfire::AutoPtr< ResultSet, Skyfire::Mutex > QueryResult
Definition QueryResult.h:48
#define sTicketMgr
Definition TicketMgr.h:117
WorldSession * GetSession()
Definition Chat.h:43
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition Chat.cpp:873
void PSendSysMessage(const char *format,...) ATTR_PRINTF(2
Definition Chat.cpp:221
void SetSentErrorMessage(bool val)
Definition Chat.h:114
virtual void SendSysMessage(const char *str)
Definition Chat.cpp:153
CommandScript(const char *name)
Definition Field.h:16
uint16 GetUInt16() const
Definition Field.h:69
float GetFloat() const
Definition Field.h:177
uint32 GetUInt32() const
Definition Field.h:105
Definition Map.h:238
float GetWaterLevel(float x, float y) const
Definition Map.cpp:2195
float GetHeight(float x, float y, float z, bool checkVMap=true, float maxSearchDist=DEFAULT_HEIGHT_SEARCH) const
Definition Map.cpp:1959
bool Instanceable() const
Definition Map.h:367
const char * GetMapName() const
Definition Map.cpp:2285
uint32 GetId(void) const
Definition Map.h:300
static bool IsValidMapCoord(uint32 mapid, float x, float y)
Definition MapManager.h:75
void MovementExpired(bool reset=true)
void SaveRecallPosition()
Definition Player.cpp:6866
bool TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options=0)
Definition Player.cpp:2090
void CleanupAfterTaxiFlight()
Definition Player.cpp:16748
void TeleportTo(Player *player) const
MotionMaster * GetMotionMaster()
Definition Unit.h:2605
bool IsInFlight() const
Definition Unit.h:1891
uint32 GetMapId() const
Definition Object.h:546
uint32 GetZoneId() const
Definition Object.cpp:1597
Player * GetPlayer() const
static bool HandleGoTaxinodeCommand(ChatHandler *handler, char const *args)
Definition cs_go.cpp:303
static bool HandleGoCreatureCommand(ChatHandler *handler, char const *args)
Teleport the GM to the specified creature.
Definition cs_go.cpp:60
static bool HandleGoXYZCommand(ChatHandler *handler, char const *args)
Definition cs_go.cpp:466
static bool HandleGoTriggerCommand(ChatHandler *handler, char const *args)
Definition cs_go.cpp:348
static bool HandleGoObjectCommand(ChatHandler *handler, char const *args)
Definition cs_go.cpp:247
static bool HandleGoTicketCommand(ChatHandler *handler, char const *args)
Definition cs_go.cpp:524
static bool HandleGoZoneXYCommand(ChatHandler *handler, char const *args)
Definition cs_go.cpp:394
static bool HandleGoGraveyardCommand(ChatHandler *handler, char const *args)
Definition cs_go.cpp:156
static bool HandleGoGridCommand(ChatHandler *handler, char const *args)
Definition cs_go.cpp:202
std::vector< ChatCommand > GetCommands() const OVERRIDE
Definition cs_go.cpp:26
void AddSC_go_commandscript()
Definition cs_go.cpp:558
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition Main.cpp:40
@ RBAC_PERM_COMMAND_GO_TRIGGER
Definition RBAC.h:272
@ RBAC_PERM_COMMAND_GO_XYZ
Definition RBAC.h:273
@ RBAC_PERM_COMMAND_GO_CREATURE
Definition RBAC.h:266
@ RBAC_PERM_COMMAND_GO
Definition RBAC.h:265
@ RBAC_PERM_COMMAND_GO_ZONEXY
Definition RBAC.h:274
@ RBAC_PERM_COMMAND_GO_GRAVEYARD
Definition RBAC.h:267
@ RBAC_PERM_COMMAND_GO_TAXINODE
Definition RBAC.h:270
@ RBAC_PERM_COMMAND_GO_OBJECT
Definition RBAC.h:269
@ RBAC_PERM_COMMAND_GO_GRID
Definition RBAC.h:268
@ RBAC_PERM_COMMAND_GO_TICKET
Definition RBAC.h:271
uint32 m_ID
char * m_AreaName
uint32 m_ParentAreaID
uint32 m_ContinentID
uint32 mapid
float z
float y
float x
float GetOrientation() const
Definition Object.h:331
float z
uint32 map_id
float x
float y
float x
float z
float y
uint32 map_id