Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
GlobalMethods.h
Go to the documentation of this file.
1/*
2* Copyright (C) 2010 - 2013 Eluna Lua Engine <http://emudevs.com/>
3* This program is free software licensed under GPL version 3
4* Please see the included DOCS/LICENSE.TXT for more information
5*/
6
7#ifndef GLOBALMETHODS_H
8#define GLOBALMETHODS_H
9
10extern void StartEluna(bool restart);
11
13{
14 // RegisterServerEvent(event, function)
15 int RegisterServerEvent(lua_State* L)
16 {
17 lua_settop(L, 2);
18 uint32 ev = luaL_checkunsigned(L, 1);
19 if (ev == 0)
20 {
21 luaL_error(L, "0 is not a valid event");
22 return 0;
23 }
24 luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION);
25
26 int functionRef = lua_ref(L, true);
27 if (functionRef > 0)
28 sEluna->Register(REGTYPE_SERVER, 0, ev, functionRef);
29 return 0;
30 }
31
32 // RegisterPlayerEvent(event, function)
33 int RegisterPlayerEvent(lua_State* L)
34 {
35 lua_settop(L, 2);
36 uint32 ev = luaL_checkunsigned(L, 1);
37 if (ev == 0)
38 {
39 luaL_error(L, "0 is not a valid event");
40 return 0;
41 }
42 luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION);
43
44 int functionRef = lua_ref(L, true);
45 if (functionRef > 0)
46 sEluna->Register(REGTYPE_PLAYER, 0, ev, functionRef);
47 return 0;
48 }
49
50 // RegisterVehicleEvent(event, function)
51 int RegisterVehicleEvent(lua_State* L)
52 {
53 lua_settop(L, 2);
54 uint32 ev = luaL_checkunsigned(L, 1);
55 if (ev == 0)
56 {
57 luaL_error(L, "0 is not a valid event");
58 return 0;
59 }
60 luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION);
61
62 int functionRef = lua_ref(L, true);
63 if (functionRef > 0)
64 sEluna->Register(REGTYPE_VEHICLE, 0, ev, functionRef);
65 return 0;
66 }
67
68 // RegisterGuildEvent(event, function)
69 int RegisterGuildEvent(lua_State* L)
70 {
71 lua_settop(L, 2);
72 uint32 ev = luaL_checkunsigned(L, 1);
73 if (ev == 0)
74 {
75 luaL_error(L, "0 is not a valid event");
76 return 0;
77 }
78 luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION);
79
80 int functionRef = lua_ref(L, true);
81 if (functionRef > 0)
82 sEluna->Register(REGTYPE_GUILD, 0, ev, functionRef);
83 return 0;
84 }
85
86 // RegisterGroupEvent(event, function)
87 int RegisterGroupEvent(lua_State* L)
88 {
89 lua_settop(L, 2);
90 uint32 ev = luaL_checkunsigned(L, 1);
91 if (ev == 0)
92 {
93 luaL_error(L, "0 is not a valid event");
94 return 0;
95 }
96 luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION);
97
98 int functionRef = lua_ref(L, true);
99 if (functionRef > 0)
100 sEluna->Register(REGTYPE_GROUP, 0, ev, functionRef);
101 return 0;
102 }
103
104 // RegisterCreatureGossipEvent(entry, event, function)
106 {
107 lua_settop(L, 3);
108 uint32 entry = luaL_checkunsigned(L, 1);
109 uint32 ev = luaL_checkunsigned(L, 2);
110 if (ev == 0)
111 {
112 luaL_error(L, "0 is not a valid event");
113 return 0;
114 }
115 luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION);
116
117 int functionRef = lua_ref(L, true);
118 if (functionRef > 0)
119 sEluna->Register(REGTYPE_CREATURE_GOSSIP, entry, ev, functionRef);
120 return 0;
121 }
122
123 // RegisterGameObjectGossipEvent(entry, event, function)
125 {
126 lua_settop(L, 3);
127 uint32 entry = luaL_checkunsigned(L, 1);
128 uint32 ev = luaL_checkunsigned(L, 2);
129 if (ev == 0)
130 {
131 luaL_error(L, "0 is not a valid event");
132 return 0;
133 }
134 luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION);
135
136 int functionRef = lua_ref(L, true);
137 if (functionRef > 0)
138 sEluna->Register(REGTYPE_GAMEOBJECT_GOSSIP, entry, ev, functionRef);
139 return 0;
140 }
141
142 // RegisterItemEvent(entry, event, function)
143 int RegisterItemEvent(lua_State* L)
144 {
145 lua_settop(L, 3);
146 uint32 entry = luaL_checkunsigned(L, 1);
147 uint32 ev = luaL_checkunsigned(L, 2);
148 if (ev == 0)
149 {
150 luaL_error(L, "0 is not a valid event");
151 return 0;
152 }
153 luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION);
154
155 int functionRef = lua_ref(L, true);
156 if (functionRef > 0)
157 sEluna->Register(REGTYPE_ITEM, entry, ev, functionRef);
158 return 0;
159 }
160
161 // RegisterItemGossipEvent(entry, event, function)
162 int RegisterItemGossipEvent(lua_State* L)
163 {
164 lua_settop(L, 3);
165 uint32 entry = luaL_checkunsigned(L, 1);
166 uint32 ev = luaL_checkunsigned(L, 2);
167 if (ev == 0)
168 {
169 luaL_error(L, "0 is not a valid event");
170 return 0;
171 }
172 luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION);
173
174 int functionRef = lua_ref(L, true);
175 if (functionRef > 0)
176 sEluna->Register(REGTYPE_ITEM_GOSSIP, entry, ev, functionRef);
177 return 0;
178 }
179
180 // RegisterPlayerGossipEvent(menu_id, event, function)
182 {
183 lua_settop(L, 3);
184 uint32 menu_id = luaL_checkunsigned(L, 1);
185 uint32 ev = luaL_checkunsigned(L, 2);
186 if (ev == 0)
187 {
188 luaL_error(L, "0 is not a valid event");
189 return 0;
190 }
191 luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION);
192
193 int functionRef = lua_ref(L, true);
194 if (functionRef > 0)
195 sEluna->Register(REGTYPE_PLAYER_GOSSIP, menu_id, ev, functionRef);
196 return 0;
197 }
198
199 // RegisterCreatureEvent(entry, event, function)
200 int RegisterCreatureEvent(lua_State* L)
201 {
202 lua_settop(L, 3);
203 uint32 entry = luaL_checkunsigned(L, 1);
204 uint32 ev = luaL_checkunsigned(L, 2);
205 if (ev == 0)
206 {
207 luaL_error(L, "0 is not a valid event");
208 return 0;
209 }
210 luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION);
211
212 int functionRef = lua_ref(L, true);
213 if (functionRef > 0)
214 sEluna->Register(REGTYPE_CREATURE, entry, ev, functionRef);
215 return 0;
216 }
217
218 // RegisterGameObjectEvent(entry, event, function)
219 int RegisterGameObjectEvent(lua_State* L)
220 {
221 lua_settop(L, 3);
222 uint32 entry = luaL_checkunsigned(L, 1);
223 uint32 ev = luaL_checkunsigned(L, 2);
224 if (ev == 0)
225 {
226 luaL_error(L, "0 is not a valid event");
227 return 0;
228 }
229 luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION);
230
231 int functionRef = lua_ref(L, true);
232 if (functionRef > 0)
233 sEluna->Register(REGTYPE_GAMEOBJECT, entry, ev, functionRef);
234 return 0;
235 }
236
237 // GetLuaEngine() - Gets lua engine name
238 int GetLuaEngine(lua_State* L)
239 {
240 sEluna->Push(L, "ElunaEngine");
241 return 1;
242 }
243
244 // GetCoreVersion() - Gets core version as a string
245 int GetCoreVersion(lua_State* L)
246 {
247 sEluna->Push(L, "00");
248 return 1;
249 }
250
251 // GetQuest(questId)
252 int GetQuest(lua_State* L)
253 {
254 uint32 questId = luaL_checkunsigned(L, 1);
255 if (!questId)
256 return 0;
257
258 sEluna->Push(L, sObjectMgr->GetQuestTemplate(questId));
259 return 1;
260 }
261
262 // ReloadEluna() - Reloads eluna
263 int ReloadEluna(lua_State* L)
264 {
265 StartEluna(true);
266 return 0;
267 }
268
269 // GetPlayerByGUID(guid) - Gets Player object by its guid
270 int GetPlayerByGUID(lua_State* L)
271 {
272 uint64 guid = sEluna->CHECK_ULONG(L, 1);
274 return 1;
275 }
276
277 // GetPlayerByName("name") - Gets player object by name
278 int GetPlayerByName(lua_State* L)
279 {
280 const char* message = luaL_checkstring(L, 1);
281 sEluna->Push(L, ObjectAccessor::FindPlayerByName(message));
282 return 1;
283 }
284
285 // GetGameTime() - Gets ingame time as seconds (server time?)
286 int GetGameTime(lua_State* L)
287 {
288 sEluna->Push(L, sWorld->GetGameTime());
289 return 1;
290 }
291
292 // SendWorldMessage("msg") - Sends a broadcast message to everyone
293 int SendWorldMessage(lua_State* L)
294 {
295 const char* message = luaL_checkstring(L, 1);
296 sWorld->SendServerMessage(SERVER_MSG_STRING, message);
297 return 0;
298 }
299
300 // GetPlayersInWorld([team, onlyGM]) - Gets a table with players in world. Team can be 0 for ally, 1 for horde and 2 for both.
301 int GetPlayersInWorld(lua_State* L)
302 {
303 uint32 team = luaL_optunsigned(L, 1, TEAM_NEUTRAL);
304 bool onlyGM = luaL_optbool(L, 2, false);
305
306 lua_newtable(L);
307 int tbl = lua_gettop(L);
308 uint32 i = 0;
309
310 SessionMap const& sessions = sWorld->GetAllSessions();
311 for (SessionMap::const_iterator it = sessions.begin(); it != sessions.end(); ++it)
312 {
313 if (Player* player = it->second->GetPlayer())
314 {
315 if (player->GetSession() && ((team >= TEAM_NEUTRAL || player->GetTeamId() == team) && (!onlyGM || player->IsGuildMaster())))
316 {
317 ++i;
318 sEluna->Push(L, i);
319 sEluna->Push(L, player);
320 lua_settable(L, tbl);
321 }
322 }
323 }
324
325 lua_settop(L, tbl); // push table to top of stack
326 return 1;
327 }
328
329 // GetPlayersInMap(mapid[, instanceid, team]) - Gets a table with players in the map. Instanceid optional (0 for normal map). Team can be 0 for ally, 1 for horde and 2 for both
330 int GetPlayersInMap(lua_State* L)
331 {
332 uint32 mapID = luaL_checkunsigned(L, 1);
333 uint32 instanceID = luaL_optunsigned(L, 2, 0);
334 uint32 team = luaL_optunsigned(L, 3, TEAM_NEUTRAL);
335
336 Map* map = sMapMgr->FindMap(mapID, instanceID);
337 if (!map)
338 return 0;
339
340 lua_newtable(L);
341 int tbl = lua_gettop(L);
342 uint32 i = 0;
343
344 Map::PlayerList const& players = map->GetPlayers();
345 for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
346 {
347 Player* player = itr->GetSource();
348 if (!player)
349 continue;
350 if (player->GetSession() && (team >= TEAM_NEUTRAL || player->GetTeamId() == team))
351 {
352 ++i;
353 sEluna->Push(L, i);
354 sEluna->Push(L, player);
355 lua_settable(L, tbl);
356 }
357 }
358
359 lua_settop(L, tbl);
360 return 1;
361 }
362
363 // WorldDBQuery("sql") - Executes SQL to world database and returns the query Result or nil (instant)
364 int WorldDBQuery(lua_State* L)
365 {
366 const char* query = luaL_checkstring(L, 1);
367 if (!query)
368 return 0;
369
370 QueryResult Result = WorldDatabase.Query(query);
371 if (!Result)
372 return 0;
373
374 sEluna->Push(L, new QueryResult(Result));
375 return 1;
376 }
377
378 // WorldDBExecute("sql") - Executes SQL to world database (not instant)
379 int WorldDBExecute(lua_State* L)
380 {
381 const char* query = luaL_checkstring(L, 1);
382 if (!query)
383 return 0;
384
385 WorldDatabase.Execute(query);
386 return 0;
387 }
388
389 // CharDBQuery("sql") - Executes SQL to characters database and returns the query Result or nil (instant)
390 int CharDBQuery(lua_State* L)
391 {
392 const char* query = luaL_checkstring(L, 1);
393 if (!query)
394 return 0;
395
396 QueryResult Result = CharacterDatabase.Query(query);
397 if (!Result)
398 return 0;
399
400 sEluna->Push(L, new QueryResult(Result));
401 return 1;
402 }
403
404 // CharDBExecute("sql") - Executes SQL to characters database (not instant)
405 int CharDBExecute(lua_State* L)
406 {
407 const char* query = luaL_checkstring(L, 1);
408 if (!query)
409 return 0;
410
411 CharacterDatabase.Execute(query);
412 return 0;
413 }
414
415 // AuthDBQuery("sql") - Executes SQL to auth database and returns the query Result or nil (instant)
416 int AuthDBQuery(lua_State* L)
417 {
418 const char* query = luaL_checkstring(L, 1);
419 if (!query)
420 return 0;
421
422 QueryResult Result = LoginDatabase.Query(query);
423 if (!Result)
424 return 0;
425
426 sEluna->Push(L, new QueryResult(Result));
427 return 1;
428 }
429
430 // AuthDBExecute("sql") - Executes SQL to auth database (not instant)
431 int AuthDBExecute(lua_State* L)
432 {
433 const char* query = luaL_checkstring(L, 1);
434 if (!query)
435 return 0;
436
437 LoginDatabase.Execute(query);
438 return 0;
439 }
440
441 // GetGuildByName("name") - Gets guild object
442 int GetGuildByName(lua_State* L)
443 {
444 const char* name = luaL_checkstring(L, 1);
445 sEluna->Push(L, sGuildMgr->GetGuildByName(name));
446 return 1;
447 }
448
449 // GetMapById()
450 int GetMapById(lua_State* L)
451 {
452 uint32 mapid = luaL_checkunsigned(L, 1);
453 if (!sMapStore.LookupEntry(mapid))
454 return 0;
455
456 sEluna->Push(L, sMapMgr->CreateBaseMap(mapid));
457 return 1;
458 }
459
460 // GetGuildByLeaderGUID(leaderGUID) - Gets guild object
461 int GetGuildByLeaderGUID(lua_State* L)
462 {
463 Object* obj = sEluna->CHECK_OBJECT(L, 1);
464
465 sEluna->Push(L, sGuildMgr->GetGuildByLeader(obj->GetGUID()));
466 return 1;
467 }
468
469 // GetPlayerCount() - Gets server player count
470 int GetPlayerCount(lua_State* L)
471 {
472 sEluna->Push(L, sWorld->GetActiveSessionCount());
473 return 1;
474 }
475
476 /*// FindUnit(guid)
477 int FindUnit(lua_State* L)
478 {
479 uint64 guid = sEluna->CHECK_ULONG(L, 1);
480 // sEluna->Push(L, sObjectAccessor->FindUnit(guid));
481 return 1;
482 }*/
483
484 // GetPlayerGUID(lowguid)
485 static int GetPlayerGUID(lua_State* L)
486 {
487 uint32 lowguid = luaL_checkunsigned(L, 1);
488 sEluna->Push(L, MAKE_NEW_GUID(lowguid, 0, HIGHGUID_PLAYER));
489 return 1;
490 }
491
492 // GetItemGUID(lowguid)
493 static int GetItemGUID(lua_State* L)
494 {
495 uint32 lowguid = luaL_checkunsigned(L, 1);
496 sEluna->Push(L, MAKE_NEW_GUID(lowguid, 0, HIGHGUID_ITEM));
497 return 1;
498 }
499
500 // GetObjectGUID(lowguid, entry)
501 static int GetObjectGUID(lua_State* L)
502 {
503 uint32 lowguid = luaL_checkunsigned(L, 1);
504 uint32 entry = luaL_checkunsigned(L, 2);
505 sEluna->Push(L, MAKE_NEW_GUID(lowguid, entry, HIGHGUID_GAMEOBJECT));
506 return 1;
507 }
508
509 // GetUnitGUID(lowguid, entry)
510 static int GetUnitGUID(lua_State* L)
511 {
512 uint32 lowguid = luaL_checkunsigned(L, 1);
513 uint32 entry = luaL_checkunsigned(L, 2);
514 sEluna->Push(L, MAKE_NEW_GUID(lowguid, entry, HIGHGUID_UNIT));
515 return 1;
516 }
517
518 int CreateLuaEvent(lua_State* L)
519 {
520 luaL_checktype(L, 1, LUA_TFUNCTION);
521 uint32 delay = luaL_checkunsigned(L, 2);
522 uint32 repeats = luaL_checkunsigned(L, 3);
523
524 lua_settop(L, 1);
525 int functionRef = lua_ref(L, true);
526 sEluna->Push(L, sEluna->m_EventMgr.AddEvent(&sEluna->m_EventMgr.GlobalEvents, functionRef, delay, repeats));
527 return 1;
528 }
529
530 int RemoveEventById(lua_State* L)
531 {
532 int eventId = luaL_checkinteger(L, 1);
533 bool all_Events = luaL_optbool(L, 1, false);
534
535 if (all_Events)
536 sEluna->m_EventMgr.RemoveEvent(eventId);
537 else
538 sEluna->m_EventMgr.RemoveEvent(&sEluna->m_EventMgr.GlobalEvents, eventId);
539 return 0;
540 }
541
542 int RemoveEvents(lua_State* L)
543 {
544 bool all_Events = luaL_optbool(L, 1, false);
545
546 if (all_Events)
547 sEluna->m_EventMgr.RemoveEvents();
548 else
549 sEluna->m_EventMgr.RemoveEvents(&sEluna->m_EventMgr.GlobalEvents);
550 return 0;
551 }
552
553 // PerformIngameSpawn(spawntype, entry, mapid, instanceid, x, y, z, o[, save, DurOrResptime, phase])
554 // spawntype: 1 Creature, 2 Object. DurOrResptime is respawntime for gameobjects and despawntime for creatures if creature is not saved
555 int PerformIngameSpawn(lua_State* L)
556 {
557 int spawntype = luaL_checkinteger(L, 1);
558 uint32 entry = luaL_checkunsigned(L, 2);
559 uint32 mapID = luaL_checkunsigned(L, 3);
560 uint32 instanceID = luaL_checkunsigned(L, 4);
561 float x = luaL_checknumber(L, 5);
562 float y = luaL_checknumber(L, 6);
563 float z = luaL_checknumber(L, 7);
564 float o = luaL_checknumber(L, 8);
565 bool save = luaL_optbool(L, 9, false);
566 uint32 durorresptime = luaL_optunsigned(L, 10, 0);
567 uint32 phase = luaL_optunsigned(L, 11, PHASEMASK_NORMAL);
568 if (!phase)
569 return 0;
570
571 Map* map = sMapMgr->FindMap(mapID, instanceID);
572 if (!map)
573 return 0;
574
575 Position pos = {x,y,z,o};
576
577 if (spawntype == 1) // spawn creature
578 {
579 if (save)
580 {
581 Creature* creature = new Creature();
582 if (!creature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, entry, 0, 0, x, y, z, o))
583 {
584 delete creature;
585 return 0;
586 }
587
588 creature->SetPhaseMask(phase, false);
589 creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()));
590
591 uint32 db_lowguid = creature->GetDBTableGUIDLow();
592 if (!creature->LoadCreatureFromDB(db_lowguid, map))
593 {
594 delete creature;
595 return 0;
596 }
597
598 sObjectMgr->AddCreatureToGrid(db_lowguid, sObjectMgr->GetCreatureData(db_lowguid));
599 sEluna->Push(L, creature);
600 }
601 else
602 {
603 TempSummon* creature = map->SummonCreature(entry, pos, NULL, durorresptime);
604 if (!creature)
605 return 0;
606
607 if (durorresptime)
609 else
611
612 sEluna->Push(L, creature);
613 }
614
615 return 1;
616 }
617
618 if (spawntype == 2) // Spawn object
619 {
620 const GameObjectTemplate* objectInfo = sObjectMgr->GetGameObjectTemplate(entry);
621 if (!objectInfo)
622 return 0;
623
624 if (objectInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId))
625 return 0;
626
627 GameObject* object = new GameObject;
628 uint32 lowguid = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT);
629 if (!object->Create(lowguid, objectInfo->entry, map, x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 100, GOState::GO_STATE_READY))
630 {
631 delete object;
632 return 0;
633 }
634
635 object->SetPhaseMask(phase, false);
636
637 if (durorresptime)
638 object->SetRespawnTime(durorresptime);
639
640 if (save)
641 {
642 // fill the gameobject data and save to the db
643 object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()));
644
645 // this will generate a new lowguid if the object is in an instance
646 if (!object->LoadGameObjectFromDB(lowguid, map))
647 {
648 delete object;
649 return false;
650 }
651
652 sObjectMgr->AddGameobjectToGrid(lowguid, sObjectMgr->GetGOData(lowguid));
653 }
654 else
655 map->AddToMap(object);
656 sEluna->Push(L, object);
657 return 1;
658 }
659
660 return 0;
661 }
662
663 // CreatePacket(opcode, size)
664 int CreatePacket(lua_State* L)
665 {
666 uint16 opcode = luaL_checkunsigned(L, 1);
667 size_t size = luaL_checkunsigned(L, 2);
668
669 if (opcode >= NUM_OPCODE_HANDLERS)
670 luaL_error(L, "Invalid opcode type (%d)", opcode);
671 else
672 {
673 WorldPacket* _packet = new WorldPacket(static_cast<Opcodes>(opcode), size);
674 sEluna->Push(L, _packet);
675 return 1;
676 }
677 return 0;
678 }
679
680 // AddVendorItem(entry, itemId, maxcount, incrtime, extendedcost[, persist(bool)])
681 int AddVendorItem(lua_State* L)
682 {
683 // @TODO
684 //uint32 entry = luaL_checkunsigned(L, 1);
685 //uint32 item = luaL_checkunsigned(L, 2);
686 //int maxcount = luaL_checkinteger(L, 3);
687 //uint32 incrtime = luaL_checkunsigned(L, 4);
688 //uint32 extendedcost = luaL_checkunsigned(L, 5);
689 //bool persist = luaL_optbool(L, 6, true);
690 //if (!sObjectMgr->GetCreatureTemplate(entry))
691 //{
692 // luaL_error(L, "Couldn't find a creature with (ID: %d)!", entry);
693 // return 0;
694 //}
695
696 //if (!sObjectMgr->IsVendorItemValid(entry, item, maxcount, incrtime, extendedcost))
697 // return 0;
698 //sObjectMgr->AddVendorItem(entry, item, maxcount, incrtime, extendedcost, persist);
699 return 0;
700 }
701
702 // VendorRemoveItem(entry, item[, persist(bool)])
703 int VendorRemoveItem(lua_State* L)
704 {
705 // @TODO
706 //uint32 entry = luaL_checkunsigned(L, 1);
707 //uint32 item = luaL_checkunsigned(L, 2);
708 //if (!sObjectMgr->GetCreatureTemplate(entry))
709 //{
710 // luaL_error(L, "Couldn't find a creature with (ID: %d)!", entry);
711 // return 0;
712 //}
713
714 //sObjectMgr->RemoveVendorItem(entry, item);
715 return 0;
716 }
717
718 // VendorRemoveAllItems(entry, persist(bool))
719 int VendorRemoveAllItems(lua_State* L)
720 {
721 //@TODO
722 //uint32 entry = luaL_checkunsigned(L, 1);
723
724 //VendorItemData const* items = sObjectMgr->GetNpcVendorItemList(entry);
725 //if (!items || items->Empty())
726 // return 0;
727
728 //VendorItemList const itemlist = items->m_items;
729 //for (VendorItemList::const_iterator itr = itemlist.begin(); itr != itemlist.end(); ++itr)
730 // sObjectMgr->RemoveVendorItem(entry, (*itr)->item);
731 return 0;
732 }
733
734 // Kick(player)
735 int Kick(lua_State* L)
736 {
737 Player* player = sEluna->CHECK_PLAYER(L, 1);
738 if (!player)
739 return 0;
740 player->GetSession()->KickPlayer();
741 return 0;
742 }
743
744 // Ban(banMode(integer), nameOrIP(string), duration(string), reason(string), player(whoBanned))
745 int Ban(lua_State* L)
746 {
747 //@TODO
748 //int banMode = luaL_checkint(L, 1);
749 //std::string nameOrIP = luaL_checkstring(L, 2);
750 //uint32 duration = luaL_checkunsigned(L, 3);
751 //const char* reason = luaL_checkstring(L, 4);
752 //Player* whoBanned = sEluna->CHECK_PLAYER(L, 5);
753 //if (!whoBanned)
754 // return 0;
755
756 //switch (banMode)
757 //{
758 // case BAN_ACCOUNT:
759 // if (!AccountMgr::normalizeString(nameOrIP))
760 // return 0;
761 // break;
762 // case BAN_CHARACTER:
763 // if (!normalizePlayerName(nameOrIP))
764 // return 0;
765 // break;
766 // case BAN_IP:
767 // if (!IsIPAddress(nameOrIP.c_str()))
768 // return 0;
769 // break;
770 // default:
771 // return 0;
772 //}
773
774 //switch (sWorld->BanAccount((BanMode)banMode, nameOrIP, duration, reason, whoBanned->GetSession() ? whoBanned->GetName() : ""))
775 //{
776 // case BAN_SUCCESS:
777 // if (duration > 0)
778 // ChatHandler(whoBanned->GetSession()).PSendSysMessage(LANG_BAN_YOUBANNED, nameOrIP.c_str(), secsToTimeString(duration, true).c_str(), reason);
779 // else
780 // ChatHandler(whoBanned->GetSession()).PSendSysMessage(LANG_BAN_YOUPERMBANNED, nameOrIP.c_str(), reason);
781 // break;
782 // case BAN_SYNTAX_ERROR:
783 // return 0;
784 // case BAN_NOTFOUND:
785 // return 0;
786 //}
787 return 0;
788 }
789
790 // SaveAllPlayers()
791 int SaveAllPlayers(lua_State* L)
792 {
794 return 0;
795 }
796
797 // GetGUIDLow(guid)
798 int GetGUIDLow(lua_State* L)
799 {
800 uint64 guid = sEluna->CHECK_ULONG(L, 1);
801
802 sEluna->Push(L, GUID_LOPART(guid));
803 return 1;
804 }
805
806 // SendMail(subject, text, receiverLowGUID[, sender, stationary, delay, itemEntry, itemAmount, itemEntry2, itemAmount2...])
807 int SendMail(lua_State* L)
808 {
809 int i = 0;
810 std::string subject = luaL_checkstring(L, ++i);
811 std::string text = luaL_checkstring(L, ++i);
812 uint32 receiverGUIDLow = luaL_checkunsigned(L, ++i);
813 Player* senderPlayer = sEluna->CHECK_PLAYER(L, ++i);
814 uint32 stationary = luaL_optunsigned(L, ++i, MAIL_STATIONERY_DEFAULT);
815 uint32 delay = luaL_optunsigned(L, ++i, 0);
816 int32 argAmount = lua_gettop(L);
817
818 MailSender sender(MAIL_NORMAL, senderPlayer ? GUID_LOPART(senderPlayer->GetGUID()) : 0, (MailStationery)stationary);
819 MailDraft draft(subject, text);
820
821 SQLTransaction trans = CharacterDatabase.BeginTransaction();
822 uint8 addedItems = 0;
823 while (addedItems <= MAX_MAIL_ITEMS && i+2 <= argAmount)
824 {
825 uint32 entry = luaL_checkunsigned(L, ++i);
826 uint32 amount = luaL_checkunsigned(L, ++i);
827
828 ItemTemplate const* item_proto = sObjectMgr->GetItemTemplate(entry);
829 if (!item_proto)
830 {
831 luaL_error(L, "Item entry %d does not exist", entry);
832 continue;
833 }
834 if (amount < 1 || (item_proto->MaxCount > 0 && amount > uint32(item_proto->MaxCount)))
835 {
836 luaL_error(L, "Item entry %d has invalid amount %d", entry, amount);
837 continue;
838 }
839 if (Item* item = Item::CreateItem(entry, amount, senderPlayer ? senderPlayer : 0))
840 {
841 item->SaveToDB(trans);
842 draft.AddItem(item);
843 ++addedItems;
844 }
845 }
846
847 draft.SendMailTo(trans, MailReceiver(receiverGUIDLow), sender, MAIL_CHECK_MASK_NONE, delay);
848 CharacterDatabase.CommitTransaction(trans);
849 return 0;
850 }
851
852 // bit_and(a, b)
853 int bit_and(lua_State* L)
854 {
855 uint32 a = luaL_checkunsigned(L, 1);
856 uint32 b = luaL_checkunsigned(L, 2);
857 sEluna->Push(L, a & b);
858 return 1;
859 }
860
861 // bit_or(a, b)
862 int bit_or(lua_State* L)
863 {
864 uint32 a = luaL_checkunsigned(L, 1);
865 uint32 b = luaL_checkunsigned(L, 2);
866 sEluna->Push(L, a | b);
867 return 1;
868 }
869
870 // bit_lshift(a, b)
871 int bit_lshift(lua_State* L)
872 {
873 uint32 a = luaL_checkunsigned(L, 1);
874 uint32 b = luaL_checkunsigned(L, 2);
875 sEluna->Push(L, a << b);
876 return 1;
877 }
878
879 // bit_rshift(a, b)
880 int bit_rshift(lua_State* L)
881 {
882 uint32 a = luaL_checkunsigned(L, 1);
883 uint32 b = luaL_checkunsigned(L, 2);
884 sEluna->Push(L, a >> b);
885 return 1;
886 }
887
888 // bit_xor(a, b)
889 int bit_xor(lua_State* L)
890 {
891 uint32 a = luaL_checkunsigned(L, 1);
892 uint32 b = luaL_checkunsigned(L, 2);
893 sEluna->Push(L, a ^ b);
894 return 1;
895 }
896
897 // bit_not(a)
898 int bit_not(lua_State* L)
899 {
900 uint32 a = luaL_checkunsigned(L, 1);
901 sEluna->Push(L, ~ a);
902 return 1;
903 }
904
905 int GetGUIDType(lua_State* L)
906 {
907 uint64 guid = sEluna->CHECK_ULONG(L, 1);
908 sEluna->Push(L, uint32(GUID_HIPART(guid)));
909 return 1;
910 }
911
912 int GetGUIDEntry(lua_State* L)
913 {
914 uint64 guid = sEluna->CHECK_ULONG(L, 1);
915 sEluna->Push(L, GUID_ENPART(guid));
916 return 1;
917 }
918
919 // AddTaxiPath(pathTable, mountA, mountH[, price, pathId])
920 int AddTaxiPath(lua_State* L)
921 {
922 luaL_checktype(L, 1, LUA_TTABLE);
923 uint32 mountA = luaL_checkunsigned(L, 2);
924 uint32 mountH = luaL_checkunsigned(L, 3);
925 uint32 price = luaL_optunsigned(L, 4, 0);
926 uint32 pathId = luaL_optunsigned(L, 5, 0);
927 lua_settop(L, 1);
928
929 std::list<TaxiPathNodeEntry> nodes;
930
931 int start = lua_gettop(L);
932 int end = start;
933
934 lua_pushnil(L);
935 while (lua_next(L, -2) != 0)
936 {
937 luaL_checktype(L, -1, LUA_TTABLE);
938 lua_pushnil(L);
939 while (lua_next(L, -2) != 0)
940 {
941 lua_insert(L, end++);
942 }
943 if (start == end)
944 continue;
945 if (end - start < 4) // no mandatory args, dont add
946 {
947 while (end != start)
948 lua_remove(L, --end);
949 continue;
950 }
951
952 while (end - start < 8) // fill optional args with 0
953 {
954 lua_pushunsigned(L, 0);
955 lua_insert(L, end++);
956 }
958 // mandatory
959 entry->mapid = luaL_checkunsigned(L, start);
960 entry->x = luaL_checknumber(L, start + 1);
961 entry->y = luaL_checknumber(L, start + 2);
962 entry->z = luaL_checknumber(L, start + 3);
963 // optional
964 entry->actionFlag = luaL_checkunsigned(L, start + 4);
965 entry->delay = luaL_checkunsigned(L, start + 5);
966 entry->arrivalEventID = luaL_checkunsigned(L, start + 6);
967 entry->departureEventID = luaL_checkunsigned(L, start + 7);
968
969 nodes.push_back(*entry);
970
971 while (end != start) // remove args
972 lua_remove(L, --end);
973
974 lua_pop(L, 1);
975 }
976
977 sEluna->Push(L, LuaTaxiMgr::AddPath(nodes, mountA, mountH, price, pathId));
978 return 1;
979 }
980
981 int GetItemLink(lua_State* L)
982 {
983 /*
984 LOCALE_enUS = 0,
985 LOCALE_koKR = 1,
986 LOCALE_frFR = 2,
987 LOCALE_deDE = 3,
988 LOCALE_zhCN = 4,
989 LOCALE_zhTW = 5,
990 LOCALE_esES = 6,
991 LOCALE_esMX = 7,
992 LOCALE_ruRU = 8
993 */
994 uint32 entry = luaL_checkunsigned(L, 1);
995 int loc_idx = luaL_optint(L, 2, DEFAULT_LOCALE);
996 if (loc_idx < 0 || loc_idx >= MAX_LOCALES)
997 {
998 luaL_error(L, "Invalid locale index (%d)", loc_idx);
999 return 0;
1000 }
1001
1002 const ItemTemplate* temp = sObjectMgr->GetItemTemplate(entry);
1003 if (!temp)
1004 {
1005 luaL_error(L, "Invalid item entry (%d)", entry);
1006 return 0;
1007 }
1008
1009 std::string name = temp->Name1;
1010 if (ItemLocale const* il = sObjectMgr->GetItemLocale(entry))
1011 ObjectMgr::GetLocaleString(il->Name, loc_idx, name);
1012
1013 std::ostringstream oss;
1014 oss << "|c" << std::hex << ItemQualityColors[temp->Quality] << std::dec <<
1015 "|Hitem:" << entry << ":0:0:0:0:0:0:0:0:0|h[" << name << "]|h|r";
1016
1017 sEluna->Push(L, oss.str());
1018 return 1;
1019 }
1020
1021}
1022#endif
#define DEFAULT_LOCALE
Definition Common.h:154
#define MAX_LOCALES
Definition Common.h:156
DBCStorage< GameObjectDisplayInfoEntry > sGameObjectDisplayInfoStore(GameObjectDisplayInfofmt)
DBCStorage< MapEntry > sMapStore(MapEntryfmt)
std::int32_t int32
Definition Define.h:73
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
std::uint64_t uint64
Definition Define.h:76
std::uint16_t uint16
Definition Define.h:78
static constexpr TempSummonType TEMPSUMMON_MANUAL_DESPAWN
static constexpr TempSummonType TEMPSUMMON_TIMED_OR_DEAD_DESPAWN
@ GO_STATE_READY
Definition GameObject.h:577
void StartEluna(bool restart)
Definition LuaEngine.cpp:41
#define sGuildMgr
Definition GuildMgr.h:53
@ REGTYPE_GUILD
Definition HookMgr.h:34
@ REGTYPE_PLAYER_GOSSIP
Definition HookMgr.h:43
@ REGTYPE_PLAYER
Definition HookMgr.h:33
@ REGTYPE_SERVER
Definition HookMgr.h:32
@ REGTYPE_VEHICLE
Definition HookMgr.h:37
@ REGTYPE_GROUP
Definition HookMgr.h:35
@ REGTYPE_GAMEOBJECT
Definition HookMgr.h:39
@ REGTYPE_ITEM_GOSSIP
Definition HookMgr.h:42
@ REGTYPE_CREATURE
Definition HookMgr.h:36
@ REGTYPE_GAMEOBJECT_GOSSIP
Definition HookMgr.h:40
@ REGTYPE_ITEM
Definition HookMgr.h:41
@ REGTYPE_CREATURE_GOSSIP
Definition HookMgr.h:38
#define sEluna
Definition LuaEngine.h:710
@ MAIL_CHECK_MASK_NONE
Definition Mail.h:34
#define MAX_MAIL_ITEMS
Definition Mail.h:20
MailStationery
Definition Mail.h:44
@ MAIL_STATIONERY_DEFAULT
Definition Mail.h:46
@ MAIL_NORMAL
Definition Mail.h:24
#define sMapMgr
Definition MapManager.h:145
@ PHASEMASK_NORMAL
Definition Object.h:80
uint32 GUID_LOPART(uint64 x)
uint32 GUID_ENPART(uint64 x)
@ HIGHGUID_GAMEOBJECT
@ HIGHGUID_PLAYER
@ HIGHGUID_UNIT
@ HIGHGUID_ITEM
uint64 MAKE_NEW_GUID(uint32 l, uint32 e, uint32 h)
uint32 GUID_HIPART(uint64 guid)
#define sObjectMgr
Definition ObjectMgr.h:1617
Skyfire::AutoPtr< ResultSet, Skyfire::Mutex > QueryResult
Definition QueryResult.h:48
const uint32 ItemQualityColors[MAX_ITEM_QUALITY]
@ TEAM_NEUTRAL
Skyfire::AutoPtr< Transaction, Skyfire::Mutex > SQLTransaction
Definition Transaction.h:42
uint32 GetDBTableGUIDLow() const
Definition Creature.h:445
bool Create(uint32 guidlow, Map *map, uint32 Entry, uint32 vehId, uint32 team, float x, float y, float z, float ang, const CreatureData *data=NULL)
Definition Creature.cpp:740
void SaveToDB()
Definition Creature.cpp:934
bool LoadCreatureFromDB(uint32 guid, Map *map, bool addToMap=true)
bool Create(uint32 guidlow, uint32 name_id, Map *map, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 animprogress, GOState go_state, uint32 artKit=0)
bool LoadGameObjectFromDB(uint32 guid, Map *map, bool addToMap=true)
Definition Item.h:202
static Item * CreateItem(uint32 itemEntry, uint32 count, Player const *player=NULL)
Definition Item.cpp:1012
static uint32 AddPath(std::list< TaxiPathNodeEntry > nodes, uint32 mountA, uint32 mountH, uint32 price=0, uint32 pathId=0)
void SendMailTo(SQLTransaction &trans, MailReceiver const &receiver, MailSender const &sender, MailCheckMask checked=MAIL_CHECK_MASK_NONE, uint32 deliver_delay=0)
Definition Mail.cpp:162
MailDraft & AddItem(Item *item)
Definition Mail.cpp:70
Definition Map.h:238
bool AddToMap(T *)
Definition Map.cpp:504
MapRefManager PlayerList
Definition Map.h:406
uint8 GetSpawnMode() const
Definition Map.h:358
TempSummon * SummonCreature(uint32 entry, Position const &pos, SummonPropertiesEntry const *properties=NULL, uint32 duration=0, Unit *summoner=NULL, uint32 spellId=0, uint32 vehId=0)
Definition Object.cpp:2564
uint32 GetId(void) const
Definition Map.h:300
PlayerList const & GetPlayers() const
Definition Map.h:407
iterator end()
iterator begin()
LinkedListHead::Iterator< MapReference const > const_iterator
static void SaveAllPlayers()
static Player * FindPlayerByName(std::string const &name)
static Player * FindPlayer(uint64)
uint64 GetGUID() const
Definition Object.h:119
static void GetLocaleString(const StringVector &data, int loc_idx, std::string &value)
Definition ObjectMgr.h:1353
WorldSession * GetSession() const
Definition Player.h:2417
TeamId GetTeamId() const
Definition Player.h:2531
void SetTempSummonType(TempSummonType type)
void SetPhaseMask(uint32 newPhaseMask, bool update) override
Definition Unit.cpp:7454
static Player * GetPlayer(WorldObject &object, uint64 guid)
Definition Unit.cpp:4900
void KickPlayer()
Kick a player out of the World.
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition Main.cpp:41
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition Main.cpp:40
Opcodes
List of Opcodes.
Definition Opcodes.h:21
#define NUM_OPCODE_HANDLERS
Definition Opcodes.h:16
#define sWorld
Definition World.h:910
UNORDERED_MAP< uint32, WorldSession * > SessionMap
Definition World.h:543
@ SERVER_MSG_STRING
Definition World.h:38
int GetLuaEngine(lua_State *L)
int RemoveEventById(lua_State *L)
int bit_rshift(lua_State *L)
int bit_or(lua_State *L)
int WorldDBExecute(lua_State *L)
int GetGUIDType(lua_State *L)
static int GetUnitGUID(lua_State *L)
int RegisterGroupEvent(lua_State *L)
int RegisterVehicleEvent(lua_State *L)
int GetPlayerCount(lua_State *L)
int CreatePacket(lua_State *L)
int GetGUIDLow(lua_State *L)
int GetGUIDEntry(lua_State *L)
int SaveAllPlayers(lua_State *L)
int CreateLuaEvent(lua_State *L)
int GetMapById(lua_State *L)
int GetPlayerByName(lua_State *L)
int GetGuildByName(lua_State *L)
int AuthDBExecute(lua_State *L)
int GetGameTime(lua_State *L)
int GetItemLink(lua_State *L)
int RegisterGameObjectEvent(lua_State *L)
int SendMail(lua_State *L)
int bit_lshift(lua_State *L)
int RegisterGuildEvent(lua_State *L)
int VendorRemoveAllItems(lua_State *L)
static int GetPlayerGUID(lua_State *L)
int RegisterCreatureGossipEvent(lua_State *L)
int GetPlayerByGUID(lua_State *L)
int Kick(lua_State *L)
int AddVendorItem(lua_State *L)
static int GetObjectGUID(lua_State *L)
int bit_not(lua_State *L)
int RegisterItemGossipEvent(lua_State *L)
int GetPlayersInMap(lua_State *L)
int VendorRemoveItem(lua_State *L)
int GetCoreVersion(lua_State *L)
int RegisterGameObjectGossipEvent(lua_State *L)
int RegisterPlayerGossipEvent(lua_State *L)
int CharDBQuery(lua_State *L)
int AddTaxiPath(lua_State *L)
int RegisterPlayerEvent(lua_State *L)
int GetPlayersInWorld(lua_State *L)
int RemoveEvents(lua_State *L)
int GetQuest(lua_State *L)
int RegisterItemEvent(lua_State *L)
int CharDBExecute(lua_State *L)
int bit_xor(lua_State *L)
int SendWorldMessage(lua_State *L)
int WorldDBQuery(lua_State *L)
int GetGuildByLeaderGUID(lua_State *L)
int PerformIngameSpawn(lua_State *L)
int RegisterCreatureEvent(lua_State *L)
int AuthDBQuery(lua_State *L)
int RegisterServerEvent(lua_State *L)
int Ban(lua_State *L)
int bit_and(lua_State *L)
int ReloadEluna(lua_State *L)
static int GetItemGUID(lua_State *L)
LoginDatabaseWorkerPool LoginDatabase
Definition Main.cpp:54
std::string Name1
float y
uint32 arrivalEventID
uint32 actionFlag
uint32 departureEventID
float x
uint32 mapid
uint32 delay
float z