Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
cs_account.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: account_commandscript
8%Complete: 100
9Comment: All account related commands
10Category: commandscripts
11EndScriptData */
12
13#include "AccountMgr.h"
14#include "Chat.h"
15#include "Language.h"
16#include "NetworkAddress.h"
17#include "Player.h"
18#include "ScriptMgr.h"
19
21{
22public:
23 account_commandscript() : CommandScript("account_commandscript") { }
24
25 std::vector<ChatCommand> GetCommands() const OVERRIDE
26 {
27 static std::vector<ChatCommand> accountSetSecTable =
28 {
31 };
32 static std::vector<ChatCommand> accountSetCommandTable =
33 {
35 { "sec", rbac::RBAC_PERM_COMMAND_ACCOUNT_SET_SEC, true, NULL, "", accountSetSecTable },
38 };
39 static std::vector<ChatCommand> accountLockCommandTable =
40 {
43 };
44 static std::vector<ChatCommand> accountBoostCommandTable =
45 {
48 };
49 static std::vector<ChatCommand> accountCommandTable =
50 {
52 { "boost", rbac::RBAC_PERM_COMMAND_ACCOUNT_BOOST, false, NULL, "", accountBoostCommandTable },
57 { "lock", rbac::RBAC_PERM_COMMAND_ACCOUNT_LOCK, false, NULL, "", accountLockCommandTable },
58 { "set", rbac::RBAC_PERM_COMMAND_ACCOUNT_SET, true, NULL, "", accountSetCommandTable },
60 };
61 static std::vector<ChatCommand> commandTable =
62 {
63 { "account", rbac::RBAC_PERM_COMMAND_ACCOUNT, true, NULL, "", accountCommandTable },
64 };
65 return commandTable;
66 }
67
68 static bool HandleAccountAddonCommand(ChatHandler* handler, char const* args)
69 {
70 if (!*args)
71 {
73 handler->SetSentErrorMessage(true);
74 return false;
75 }
76
77 char* exp = strtok((char*)args, " ");
78
79 uint32 accountId = handler->GetSession()->GetAccountId();
80
81 int expansion = atoi(exp); //get int anyway (0 if error)
82 if (expansion < 0 || uint8(expansion) > sWorld->getIntConfig(WorldIntConfigs::CONFIG_EXPANSION))
83 {
85 handler->SetSentErrorMessage(true);
86 return false;
87 }
88
89 PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_EXPANSION);
90
91 stmt->setUInt8(0, uint8(expansion));
92 stmt->setUInt32(1, accountId);
93
94 LoginDatabase.Execute(stmt);
95
96 handler->PSendSysMessage(LANG_ACCOUNT_ADDON, expansion);
97 return true;
98 }
99
101 static bool HandleAccountCreateCommand(ChatHandler* handler, char const* args)
102 {
103 if (!*args)
104 return false;
105
106 std::string email;
107
109 char* accountName = strtok((char*)args, " ");
110 char* password = strtok(NULL, " ");
111 char* possibleEmail = strtok(NULL, " ' ");
112 if (possibleEmail)
113 email = possibleEmail;
114
115 if (!accountName || !password)
116 return false;
117
118 AccountOpResult result = sAccountMgr->CreateAccount(std::string(accountName), std::string(password), email);
119 switch (result)
120 {
122 handler->PSendSysMessage(LANG_ACCOUNT_CREATED, accountName);
123 if (handler->GetSession())
124 {
125 SF_LOG_INFO("entities.player.character", "Account: %d (IP: %s) Character:[%s] (GUID: %u) created Account %s (Email: '%s')",
126 handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(),
127 handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUIDLow(),
128 accountName, email.c_str());
129 }
130 break;
133 handler->SetSentErrorMessage(true);
134 return false;
137 handler->SetSentErrorMessage(true);
138 return false;
141 handler->SetSentErrorMessage(true);
142 return false;
143 default:
144 handler->PSendSysMessage(LANG_ACCOUNT_NOT_CREATED, accountName);
145 handler->SetSentErrorMessage(true);
146 return false;
147 }
148
149 return true;
150 }
151
154 static bool HandleAccountDeleteCommand(ChatHandler* handler, char const* args)
155 {
156 if (!*args)
157 return false;
158
160 char* account = strtok((char*)args, " ");
161 if (!account)
162 return false;
163
164 std::string accountName = account;
165 if (!AccountMgr::normalizeString(accountName))
166 {
167 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
168 handler->SetSentErrorMessage(true);
169 return false;
170 }
171
172 uint32 accountId = AccountMgr::GetId(accountName);
173 if (!accountId)
174 {
175 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
176 handler->SetSentErrorMessage(true);
177 return false;
178 }
179
183 if (handler->HasLowerSecurityAccount(NULL, accountId, true))
184 return false;
185
186 AccountOpResult result = AccountMgr::DeleteAccount(accountId);
187 switch (result)
188 {
190 handler->PSendSysMessage(LANG_ACCOUNT_DELETED, accountName.c_str());
191 break;
193 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
194 handler->SetSentErrorMessage(true);
195 return false;
197 handler->PSendSysMessage(LANG_ACCOUNT_NOT_DELETED_SQL_ERROR, accountName.c_str());
198 handler->SetSentErrorMessage(true);
199 return false;
200 default:
201 handler->PSendSysMessage(LANG_ACCOUNT_NOT_DELETED, accountName.c_str());
202 handler->SetSentErrorMessage(true);
203 return false;
204 }
205
206 return true;
207 }
208
210 static bool HandleAccountOnlineListCommand(ChatHandler* handler, char const* /*args*/)
211 {
214
215 PreparedQueryResult result = CharacterDatabase.Query(stmt);
216
217 if (!result)
218 {
220 return true;
221 }
222
227
229 do
230 {
231 Field* fieldsDB = result->Fetch();
232 std::string name = fieldsDB[0].GetString();
233 uint32 account = fieldsDB[1].GetUInt32();
234
236 // No SQL injection. account is uint32.
237 stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_INFO);
238 stmt->setUInt32(0, account);
239 PreparedQueryResult resultLogin = LoginDatabase.Query(stmt);
240
241 if (resultLogin)
242 {
243 Field* fieldsLogin = resultLogin->Fetch();
245 fieldsLogin[0].GetCString(), name.c_str(), fieldsLogin[1].GetCString(),
246 fieldsDB[2].GetUInt16(), fieldsDB[3].GetUInt16(), fieldsLogin[3].GetUInt8(),
247 fieldsLogin[2].GetUInt8());
248 }
249 else
250 handler->PSendSysMessage(LANG_ACCOUNT_LIST_ERROR, name.c_str());
251 } while (result->NextRow());
252
254 return true;
255 }
256
257 static bool HandleAccountLockCountryCommand(ChatHandler* handler, char const* args)
258 {
259 if (!*args)
260 {
262 handler->SetSentErrorMessage(true);
263 return false;
264 }
265 std::string param = (char*)args;
266
267 if (!param.empty())
268 {
269 if (param == "on")
270 {
271 PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_LOGON_COUNTRY);
274 stmt->setUInt32(0, ip);
275 PreparedQueryResult result = LoginDatabase.Query(stmt);
276 if (result)
277 {
278 Field* fields = result->Fetch();
279 std::string country = fields[0].GetString();
280 stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_CONTRY);
281 stmt->setString(0, country);
282 stmt->setUInt32(1, handler->GetSession()->GetAccountId());
283 LoginDatabase.Execute(stmt);
285 }
286 else
287 {
288 handler->PSendSysMessage("[IP2NATION] Table empty");
289 SF_LOG_DEBUG("server.authserver", "[IP2NATION] Table empty");
290 }
291 }
292 else if (param == "off")
293 {
295 stmt->setString(0, "00");
296 stmt->setUInt32(1, handler->GetSession()->GetAccountId());
297 LoginDatabase.Execute(stmt);
299 }
300 return true;
301 }
303 handler->SetSentErrorMessage(true);
304 return false;
305 }
306
307 static bool HandleAccountLockIpCommand(ChatHandler* handler, char const* args)
308 {
309 if (!*args)
310 {
312 handler->SetSentErrorMessage(true);
313 return false;
314 }
315
316 std::string param = (char*)args;
317
318 if (!param.empty())
319 {
320 PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK);
321
322 if (param == "on")
323 {
324 stmt->setBool(0, true); // locked
326 }
327 else if (param == "off")
328 {
329 stmt->setBool(0, false); // unlocked
331 }
332
333 stmt->setUInt32(1, handler->GetSession()->GetAccountId());
334
335 LoginDatabase.Execute(stmt);
336 return true;
337 }
338
340 handler->SetSentErrorMessage(true);
341 return false;
342 }
343
344 static bool HandleAccountEmailCommand(ChatHandler* handler, char const* args)
345 {
346 if (!*args)
347 {
349 handler->SetSentErrorMessage(true);
350 return false;
351 }
352
353 char* oldEmail = strtok((char*)args, " ");
354 char* password = strtok(NULL, " ");
355 char* email = strtok(NULL, " ");
356 char* emailConfirmation = strtok(NULL, " ");
357
358 if (!oldEmail || !password || !email || !emailConfirmation)
359 {
361 handler->SetSentErrorMessage(true);
362 return false;
363 }
364
365 if (!AccountMgr::CheckEmail(handler->GetSession()->GetAccountId(), std::string(oldEmail)))
366 {
368 handler->SetSentErrorMessage(true);
369 SF_LOG_INFO("entities.player.character", "Account: %u (IP: %s) Character:[%s] (GUID: %u) Tried to change email, but the provided email [%s] is not equal to registration email [%s].",
370 handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(),
371 handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUIDLow(),
372 email, oldEmail);
373 return false;
374 }
375
376 if (!AccountMgr::CheckPassword(handler->GetSession()->GetAccountId(), std::string(password)))
377 {
379 handler->SetSentErrorMessage(true);
380 SF_LOG_INFO("entities.player.character", "Account: %u (IP: %s) Character:[%s] (GUID: %u) Tried to change email, but the provided password is wrong.",
381 handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(),
382 handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUIDLow());
383 return false;
384 }
385
386 if (strcmp(email, oldEmail) == 0)
387 {
389 handler->SetSentErrorMessage(true);
390 return false;
391 }
392
393 if (strcmp(email, emailConfirmation) != 0)
394 {
396 handler->SetSentErrorMessage(true);
397 SF_LOG_INFO("entities.player.character", "Account: %u (IP: %s) Character:[%s] (GUID: %u) Tried to change email, but the provided password is wrong.",
398 handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(),
399 handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUIDLow());
400 return false;
401 }
402
403
404 AccountOpResult result = AccountMgr::ChangeEmail(handler->GetSession()->GetAccountId(), std::string(email));
405 switch (result)
406 {
409 SF_LOG_INFO("entities.player.character", "Account: %u (IP: %s) Character:[%s] (GUID: %u) Changed Email from [%s] to [%s].",
410 handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(),
411 handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUIDLow(),
412 oldEmail, email);
413 break;
416 handler->SetSentErrorMessage(true);
417 return false;
418 default:
420 handler->SetSentErrorMessage(true);
421 return false;
422 }
423
424 return true;
425 }
426
427 static bool HandleAccountPasswordCommand(ChatHandler* handler, char const* args)
428 {
429 // If no args are given at all, we can return false right away.
430 if (!*args)
431 {
433 handler->SetSentErrorMessage(true);
434 return false;
435 }
436
437 // First, we check config. What security type (sec type) is it ? Depending on it, the command branches out
438 uint32 pwConfig = sWorld->getIntConfig(WorldIntConfigs::CONFIG_ACC_PASSCHANGESEC); // 0 - PW_NONE, 1 - PW_EMAIL, 2 - PW_RBAC
439
440 // Command is supposed to be: .account password [$oldpassword] [$newpassword] [$newpasswordconfirmation] [$emailconfirmation]
441 char* oldPassword = strtok((char*)args, " "); // This extracts [$oldpassword]
442 char* newPassword = strtok(NULL, " "); // This extracts [$newpassword]
443 char* passwordConfirmation = strtok(NULL, " "); // This extracts [$newpasswordconfirmation]
444 char const* emailConfirmation = strtok(NULL, " "); // This defines the emailConfirmation variable, which is optional depending on sec type.
445 if (!emailConfirmation) // This extracts [$emailconfirmation]. If it doesn't exist, however...
446 emailConfirmation = ""; // ... it's simply "" for emailConfirmation.
447
448 //Is any of those variables missing for any reason ? We return false.
449 if (!oldPassword || !newPassword || !passwordConfirmation)
450 {
452 handler->SetSentErrorMessage(true);
453 return false;
454 }
455
456 // We compare the old, saved password to the entered old password - no chance for the unauthorized.
457 if (!AccountMgr::CheckPassword(handler->GetSession()->GetAccountId(), std::string(oldPassword)))
458 {
460 handler->SetSentErrorMessage(true);
461 SF_LOG_INFO("entities.player.character", "Account: %u (IP: %s) Character:[%s] (GUID: %u) Tried to change password, but the provided old password is wrong.",
462 handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(),
463 handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUIDLow());
464 return false;
465 }
466
467 // This compares the old, current email to the entered email - however, only...
468 if ((pwConfig == PW_EMAIL || (pwConfig == PW_RBAC && handler->HasPermission(rbac::RBAC_PERM_EMAIL_CONFIRM_FOR_PASS_CHANGE))) // ...if either PW_EMAIL or PW_RBAC with the Permission is active...
469 && !AccountMgr::CheckEmail(handler->GetSession()->GetAccountId(), std::string(emailConfirmation))) // ... and returns false if the comparison fails.
470 {
472 handler->SetSentErrorMessage(true);
473 SF_LOG_INFO("entities.player.character", "Account: %u (IP: %s) Character:[%s] (GUID: %u) Tried to change password, but the entered email [%s] is wrong.",
474 handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(),
475 handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUIDLow(),
476 emailConfirmation);
477 return false;
478 }
479
480 // Making sure that newly entered password is correctly entered.
481 if (strcmp(newPassword, passwordConfirmation) != 0)
482 {
484 handler->SetSentErrorMessage(true);
485 return false;
486 }
487
488 // Changes password and prints result.
489 AccountOpResult result = AccountMgr::ChangePassword(handler->GetSession()->GetAccountId(), std::string(newPassword));
490 switch (result)
491 {
494 SF_LOG_INFO("entities.player.character", "Account: %u (IP: %s) Character:[%s] (GUID: %u) Changed Password.",
495 handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(),
496 handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUIDLow());
497 break;
500 handler->SetSentErrorMessage(true);
501 return false;
502 default:
504 handler->SetSentErrorMessage(true);
505 return false;
506 }
507
508 return true;
509 }
510
511 static bool HandleAccountCommand(ChatHandler* handler, char const* /*args*/)
512 {
513 // GM Level
514 AccountTypes gmLevel = handler->GetSession()->GetSecurity();
515 handler->PSendSysMessage(LANG_ACCOUNT_LEVEL, uint32(gmLevel));
516
517 // Security level required
518 bool hasRBAC = (handler->HasPermission(rbac::RBAC_PERM_EMAIL_CONFIRM_FOR_PASS_CHANGE) ? true : false);
519 uint32 pwConfig = sWorld->getIntConfig(WorldIntConfigs::CONFIG_ACC_PASSCHANGESEC); // 0 - PW_NONE, 1 - PW_EMAIL, 2 - PW_RBAC
520
521 handler->PSendSysMessage(LANG_ACCOUNT_SEC_TYPE, (pwConfig == PW_NONE ? "Lowest level: No Email input required." :
522 pwConfig == PW_EMAIL ? "Highest level: Email input required." :
523 pwConfig == PW_RBAC ? "Special level: Your account may require email input depending on settings. That is the case if another lien is printed." :
524 "Unknown security level: Notify technician for details."));
525
526 // RBAC required display - is not displayed for console
527 if (pwConfig == PW_RBAC && handler->GetSession() && hasRBAC)
529
530 // Email display if sufficient rights
532 {
533 std::string emailoutput;
534 uint32 accountId = handler->GetSession()->GetAccountId();
535
536 PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_EMAIL_BY_ID);
537 stmt->setUInt32(0, accountId);
538 PreparedQueryResult result = LoginDatabase.Query(stmt);
539
540 if (result)
541 {
542 emailoutput = (*result)[0].GetString();
543 handler->PSendSysMessage(LANG_COMMAND_EMAIL_OUTPUT, emailoutput.c_str());
544 }
545 }
546
547 return true;
548 }
549
551 static bool HandleAccountSetAddonCommand(ChatHandler* handler, char const* args)
552 {
554 char* account = strtok((char*)args, " ");
555 char* exp = strtok(NULL, " ");
556
557 if (!account)
558 return false;
559
560 std::string accountName;
561 uint32 accountId;
562
563 if (!exp)
564 {
565 Player* player = handler->getSelectedPlayer();
566 if (!player)
567 return false;
568
569 accountId = player->GetSession()->GetAccountId();
570 AccountMgr::GetName(accountId, accountName);
571 exp = account;
572 }
573 else
574 {
576 accountName = account;
577 if (!AccountMgr::normalizeString(accountName))
578 {
579 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
580 handler->SetSentErrorMessage(true);
581 return false;
582 }
583
584 accountId = AccountMgr::GetId(accountName);
585 if (!accountId)
586 {
587 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
588 handler->SetSentErrorMessage(true);
589 return false;
590 }
591 }
592
593 // Let set addon state only for lesser (strong) security level
594 // or to self account
595 if (handler->GetSession() && handler->GetSession()->GetAccountId() != accountId &&
596 handler->HasLowerSecurityAccount(NULL, accountId, true))
597 return false;
598
599 int expansion = atoi(exp); //get int anyway (0 if error)
600 if (expansion < 0 || uint8(expansion) > sWorld->getIntConfig(WorldIntConfigs::CONFIG_EXPANSION))
601 return false;
602
603 PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_EXPANSION);
604
605 stmt->setUInt8(0, expansion);
606 stmt->setUInt32(1, accountId);
607
608 LoginDatabase.Execute(stmt);
609
610 handler->PSendSysMessage(LANG_ACCOUNT_SETADDON, accountName.c_str(), accountId, expansion);
611 return true;
612 }
613
614 static bool HandleAccountSetGmLevelCommand(ChatHandler* handler, char const* args)
615 {
616 if (!*args)
617 {
619 handler->SetSentErrorMessage(true);
620 return false;
621 }
622
623 std::string targetAccountName;
624 uint32 targetAccountId = 0;
625 AccountTypes targetSecurity = AccountTypes::SEC_PLAYER;
627 char* arg1 = strtok((char*)args, " ");
628 char* arg2 = strtok(NULL, " ");
629 char* arg3 = strtok(NULL, " ");
630 bool isAccountNameGiven = true;
631
632 if (!arg3)
633 {
634 if (!handler->getSelectedPlayer())
635 return false;
636 isAccountNameGiven = false;
637 }
638
639 // Check for second parameter
640 if (!isAccountNameGiven && !arg2)
641 return false;
642
643 // Check for account
644 if (isAccountNameGiven)
645 {
646 targetAccountName = arg1;
647 if (!AccountMgr::normalizeString(targetAccountName))
648 {
649 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, targetAccountName.c_str());
650 handler->SetSentErrorMessage(true);
651 return false;
652 }
653 }
654
655 // Check for invalid specified GM level.
656 gm = AccountTypes((isAccountNameGiven) ? atoi(arg2) : atoi(arg1));
658 {
660 handler->SetSentErrorMessage(true);
661 return false;
662 }
663
664 // handler->getSession() == NULL only for console
665 targetAccountId = (isAccountNameGiven) ? AccountMgr::GetId(targetAccountName) : handler->getSelectedPlayer()->GetSession()->GetAccountId();
666 int32 gmRealmID = (isAccountNameGiven) ? atoi(arg3) : atoi(arg2);
667 AccountTypes playerSecurity;
668 if (handler->GetSession())
669 playerSecurity = AccountMgr::GetSecurity(handler->GetSession()->GetAccountId(), gmRealmID);
670 else
671 playerSecurity = AccountTypes::SEC_CONSOLE;
672
673 // can set security level only for target with less security and to less security that we have
674 // This also restricts setting handler's own security.
675 targetSecurity = AccountMgr::GetSecurity(targetAccountId, gmRealmID);
676 if (targetSecurity >= playerSecurity || gm >= playerSecurity)
677 {
679 handler->SetSentErrorMessage(true);
680 return false;
681 }
682
683 // Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1
684 if (gmRealmID == -1 && !AccountMgr::IsConsoleAccount(playerSecurity))
685 {
687
688 stmt->setUInt32(0, targetAccountId);
689 stmt->setUInt8(1, uint8(gm));
690
691 PreparedQueryResult result = LoginDatabase.Query(stmt);
692
693 if (result)
694 {
696 handler->SetSentErrorMessage(true);
697 return false;
698 }
699 }
700
701 // Check if provided realmID has a negative value other than -1
702 if (gmRealmID < -1)
703 {
705 handler->SetSentErrorMessage(true);
706 return false;
707 }
708
709 rbac::RBACData* rbac = isAccountNameGiven ? NULL : handler->getSelectedPlayer()->GetSession()->GetRBACData();
710 sAccountMgr->UpdateAccountAccess(rbac, targetAccountId, uint8(gm), gmRealmID);
711
712 handler->PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
713 return true;
714 }
715
717 static bool HandleAccountSetPasswordCommand(ChatHandler* handler, char const* args)
718 {
719 if (!*args)
720 {
722 handler->SetSentErrorMessage(true);
723 return false;
724 }
725
727 char* account = strtok((char*)args, " ");
728 char* password = strtok(NULL, " ");
729 char* passwordConfirmation = strtok(NULL, " ");
730
731 if (!account || !password || !passwordConfirmation)
732 return false;
733
734 std::string accountName = account;
735 if (!AccountMgr::normalizeString(accountName))
736 {
737 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
738 handler->SetSentErrorMessage(true);
739 return false;
740 }
741
742 uint32 targetAccountId = AccountMgr::GetId(accountName);
743 if (!targetAccountId)
744 {
745 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
746 handler->SetSentErrorMessage(true);
747 return false;
748 }
749
752 if (handler->HasLowerSecurityAccount(NULL, targetAccountId, true))
753 return false;
754
755 if (strcmp(password, passwordConfirmation))
756 {
758 handler->SetSentErrorMessage(true);
759 return false;
760 }
761
762 AccountOpResult result = AccountMgr::ChangePassword(targetAccountId, password);
763
764 switch (result)
765 {
768 break;
770 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
771 handler->SetSentErrorMessage(true);
772 return false;
775 handler->SetSentErrorMessage(true);
776 return false;
777 default:
779 handler->SetSentErrorMessage(true);
780 return false;
781 }
782 return true;
783 }
784
786 static bool HandleAccountSetEmailCommand(ChatHandler* handler, char const* args)
787 {
788 if (!*args)
789 return false;
790
792 char* account = strtok((char*)args, " ");
793 char* email = strtok(NULL, " ");
794 char* emailConfirmation = strtok(NULL, " ");
795
796 if (!account || !email || !emailConfirmation)
797 {
799 handler->SetSentErrorMessage(true);
800 return false;
801 }
802
803 std::string accountName = account;
804 if (!AccountMgr::normalizeString(accountName))
805 {
806 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
807 handler->SetSentErrorMessage(true);
808 return false;
809 }
810
811 uint32 targetAccountId = AccountMgr::GetId(accountName);
812 if (!targetAccountId)
813 {
814 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
815 handler->SetSentErrorMessage(true);
816 return false;
817 }
818
821 if (handler->HasLowerSecurityAccount(NULL, targetAccountId, true))
822 return false;
823
824 if (strcmp(email, emailConfirmation) != 0)
825 {
827 handler->SetSentErrorMessage(true);
828 return false;
829 }
830
831 AccountOpResult result = AccountMgr::ChangeEmail(targetAccountId, email);
832 switch (result)
833 {
836 SF_LOG_INFO("entities.player.character", "ChangeEmail: Account %s [Id: %u] had it's email changed to %s.",
837 accountName.c_str(), targetAccountId, email);
838 break;
840 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
841 handler->SetSentErrorMessage(true);
842 return false;
845 handler->SetSentErrorMessage(true);
846 return false;
847 default:
849 handler->SetSentErrorMessage(true);
850 return false;
851 }
852
853 return true;
854 }
855
857 static bool HandleAccountSetRegEmailCommand(ChatHandler* handler, char const* args)
858 {
859 if (!*args)
860 return false;
861
862 //- We do not want anything short of console to use this by default.
863 //- So we force that.
864 if (handler->GetSession())
865 return false;
866
868 char* account = strtok((char*)args, " ");
869 char* email = strtok(NULL, " ");
870 char* emailConfirmation = strtok(NULL, " ");
871
872 if (!account || !email || !emailConfirmation)
873 {
875 handler->SetSentErrorMessage(true);
876 return false;
877 }
878
879 std::string accountName = account;
880 if (!AccountMgr::normalizeString(accountName))
881 {
882 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
883 handler->SetSentErrorMessage(true);
884 return false;
885 }
886
887 uint32 targetAccountId = AccountMgr::GetId(accountName);
888 if (!targetAccountId)
889 {
890 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
891 handler->SetSentErrorMessage(true);
892 return false;
893 }
894
897 if (handler->HasLowerSecurityAccount(NULL, targetAccountId, true))
898 return false;
899
900 if (strcmp(email, emailConfirmation) != 0)
901 {
903 handler->SetSentErrorMessage(true);
904 return false;
905 }
906
907 AccountOpResult result = AccountMgr::ChangeRegEmail(targetAccountId, email);
908 switch (result)
909 {
912 SF_LOG_INFO("entities.player.character", "ChangeRegEmail: Account %s [Id: %u] had it's Registration Email changed to %s.",
913 accountName.c_str(), targetAccountId, email);
914 break;
916 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
917 handler->SetSentErrorMessage(true);
918 return false;
921 handler->SetSentErrorMessage(true);
922 return false;
923 default:
925 handler->SetSentErrorMessage(true);
926 return false;
927 }
928
929 return true;
930 }
931
932 static bool HandleAccountBoostAddCommand(ChatHandler* handler, char const* args)
933 {
934 if (!*args)
935 return false;
936
938 char* account = strtok((char*)args, " ");
939 if (!account)
940 return false;
941
942 std::string accountName = account;
943 if (!AccountMgr::normalizeString(accountName))
944 {
945 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
946 handler->SetSentErrorMessage(true);
947 return false;
948 }
949
950 uint32 accountId = AccountMgr::GetId(accountName);
951 if (!accountId)
952 {
953 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
954 handler->SetSentErrorMessage(true);
955 return false;
956 }
957
958 // Check if accounts exists
959 PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BY_ID);
960 stmt->setUInt32(0, accountId);
961 PreparedQueryResult result = LoginDatabase.Query(stmt);
962
963 if (!result)
964 {
965 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
966 handler->SetSentErrorMessage(true);
967 return false;
968 }
969
970 SQLTransaction trans = LoginDatabase.BeginTransaction();
971
972 stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_BOOST);
973 stmt->setBool(0, true);
974 stmt->setUInt32(1, accountId);
975
976 LoginDatabase.Execute(stmt);
977
978 handler->PSendSysMessage(LANG_COMMAND_BOOST_ADD, accountName.c_str());
979
980 return true;
981 }
982
983 static bool HandleAccountBoostDelCommand(ChatHandler* handler, char const* args)
984 {
985 if (!*args)
986 return false;
987
989 char* account = strtok((char*)args, " ");
990 if (!account)
991 return false;
992
993 std::string accountName = account;
994 if (!AccountMgr::normalizeString(accountName))
995 {
996 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
997 handler->SetSentErrorMessage(true);
998 return false;
999 }
1000
1001 uint32 accountId = AccountMgr::GetId(accountName);
1002 if (!accountId)
1003 {
1004 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
1005 handler->SetSentErrorMessage(true);
1006 return false;
1007 }
1008
1009 // Check if accounts exists
1010 PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BY_ID);
1011 stmt->setUInt32(0, accountId);
1012 PreparedQueryResult result = LoginDatabase.Query(stmt);
1013
1014 if (!result)
1015 {
1016 handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
1017 handler->SetSentErrorMessage(true);
1018 return false;
1019 }
1020
1021 SQLTransaction trans = LoginDatabase.BeginTransaction();
1022
1023 stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_BOOST);
1024 stmt->setBool(0, false);
1025 stmt->setUInt32(1, accountId);
1026
1027 LoginDatabase.Execute(stmt);
1028
1029 handler->PSendSysMessage(LANG_COMMAND_BOOST_DEL, accountName.c_str());
1030
1031 return true;
1032 }
1033};
1034
AccountOpResult
Definition AccountMgr.h:14
@ PW_EMAIL
Definition AccountMgr.h:27
@ PW_RBAC
Definition AccountMgr.h:28
@ PW_NONE
Definition AccountMgr.h:26
#define sAccountMgr
Definition AccountMgr.h:85
void EndianConvertReverse(T &val)
@ CHAR_SEL_CHARACTER_ONLINE
AccountTypes
Definition Common.h:129
std::int32_t int32
Definition Define.h:73
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
#define OVERRIDE
Definition Define.h:60
@ LANG_ACCOUNT_ALREADY_EXIST
Definition Language.h:864
@ LANG_ACCOUNT_LIST_ERROR
Definition Language.h:869
@ LANG_COMMAND_EMAIL
Definition Language.h:842
@ LANG_COMMAND_NOTCHANGEPASSWORD
Definition Language.h:38
@ LANG_COMMAND_ACCLOCKLOCKED
Definition Language.h:41
@ LANG_COMMAND_EMAIL_OUTPUT
Definition Language.h:846
@ LANG_IMPROPER_VALUE
Definition Language.h:75
@ LANG_ACCOUNT_ADDON
Definition Language.h:74
@ LANG_PASSWORD_TOO_LONG
Definition Language.h:68
@ LANG_ACCOUNT_LIST_EMPTY
Definition Language.h:872
@ LANG_YOU_CHANGE_SECURITY
Definition Language.h:375
@ LANG_ACCOUNT_LIST_LINE
Definition Language.h:871
@ LANG_COMMAND_WRONGOLDPASSWORD
Definition Language.h:40
@ LANG_USE_BOL
Definition Language.h:265
@ LANG_ACCOUNT_NOT_DELETED_SQL_ERROR
Definition Language.h:860
@ LANG_ACCOUNT_LIST_HEADER
Definition Language.h:868
@ LANG_ACCOUNT_SETADDON
Definition Language.h:890
@ LANG_COMMAND_WRONGEMAIL
Definition Language.h:840
@ LANG_ACCOUNT_LIST_BAR
Definition Language.h:870
@ LANG_COMMAND_ACCLOCKUNLOCKED
Definition Language.h:42
@ LANG_ACCOUNT_SEC_TYPE
Definition Language.h:848
@ LANG_CMD_SYNTAX
Definition Language.h:23
@ LANG_COMMAND_BOOST_DEL
Definition Language.h:297
@ LANG_NEW_EMAILS_NOT_MATCH
Definition Language.h:841
@ LANG_ACCOUNT_NOT_CREATED_SQL_ERROR
Definition Language.h:865
@ LANG_COMMAND_BOOST_ADD
Definition Language.h:296
@ LANG_ACCOUNT_NOT_CREATED
Definition Language.h:866
@ LANG_ACCOUNT_TOO_LONG
Definition Language.h:863
@ LANG_COMMAND_NOTCHANGEEMAIL
Definition Language.h:844
@ LANG_YOURS_SECURITY_IS_LOW
Definition Language.h:377
@ LANG_INVALID_REALMID
Definition Language.h:1237
@ LANG_ACCOUNT_CREATED
Definition Language.h:862
@ LANG_BAD_VALUE
Definition Language.h:117
@ LANG_NEW_PASSWORDS_NOT_MATCH
Definition Language.h:67
@ LANG_OLD_EMAIL_IS_NEW_EMAIL
Definition Language.h:845
@ LANG_ACCOUNT_NOT_EXIST
Definition Language.h:390
@ LANG_ACCOUNT_LIST_BAR_HEADER
Definition Language.h:873
@ LANG_ACCOUNT_NOT_DELETED
Definition Language.h:861
@ LANG_ACCOUNT_LEVEL
Definition Language.h:24
@ LANG_RBAC_EMAIL_REQUIRED
Definition Language.h:849
@ LANG_ACCOUNT_DELETED
Definition Language.h:859
@ LANG_COMMAND_PASSWORD
Definition Language.h:39
@ LANG_EMAIL_TOO_LONG
Definition Language.h:843
#define SF_LOG_DEBUG(filterType__,...)
Definition Log.h:134
#define SF_LOG_INFO(filterType__,...)
Definition Log.h:137
@ LOGIN_GET_EMAIL_BY_ID
@ LOGIN_SEL_ACCOUNT_BY_ID
@ LOGIN_UPD_ACCOUNT_BOOST
@ LOGIN_UPD_EXPANSION
@ LOGIN_SEL_LOGON_COUNTRY
@ LOGIN_UPD_ACCOUNT_LOCK
@ LOGIN_SEL_ACCOUNT_INFO
@ LOGIN_SEL_ACCOUNT_ACCESS_GMLEVEL_TEST
@ LOGIN_UPD_ACCOUNT_LOCK_CONTRY
Skyfire::AutoPtr< PreparedResultSet, Skyfire::Mutex > PreparedQueryResult
Definition QueryResult.h:94
Skyfire::AutoPtr< Transaction, Skyfire::Mutex > SQLTransaction
Definition Transaction.h:42
static AccountOpResult ChangeRegEmail(uint32 accountId, std::string newEmail)
static AccountOpResult DeleteAccount(uint32 accountId)
static bool CheckPassword(uint32 accountId, std::string password)
static AccountOpResult ChangeEmail(uint32 accountId, std::string newEmail)
static AccountTypes GetSecurity(uint32 accountId)
static AccountOpResult ChangePassword(uint32 accountId, std::string newPassword)
static bool normalizeString(std::string &utf8String)
static uint32 GetId(std::string const &username)
static bool IsConsoleAccount(AccountTypes gmlevel)
static bool CheckEmail(uint32 accountId, std::string newEmail)
static bool GetName(uint32 accountId, std::string &name)
Player * getSelectedPlayer()
Definition Chat.cpp:829
WorldSession * GetSession()
Definition Chat.h:43
virtual bool HasPermission(uint32 permission) const
Definition Chat.h:78
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
bool HasLowerSecurityAccount(WorldSession *target, uint32 account, bool strong=false)
Definition Chat.cpp:98
CommandScript(const char *name)
Definition Field.h:16
uint8 GetUInt8() const
Definition Field.h:26
std::string GetString() const
Definition Field.h:228
uint16 GetUInt16() const
Definition Field.h:69
char const * GetCString() const
Definition Field.h:213
uint32 GetUInt32() const
Definition Field.h:105
uint32 GetGUIDLow() const
Definition Object.h:120
WorldSession * GetSession() const
Definition Player.h:2417
void setBool(const uint8 index, const bool value)
void setString(const uint8 index, const std::string &value)
void setUInt32(const uint8 index, const uint32 value)
void setUInt8(const uint8 index, const uint8 value)
std::string const & GetName() const
Definition Object.h:664
AccountTypes GetSecurity() const
Player * GetPlayer() const
uint32 GetAccountId() const
std::string const & GetRemoteAddress()
rbac::RBACData * GetRBACData()
static bool HandleAccountLockIpCommand(ChatHandler *handler, char const *args)
static bool HandleAccountSetGmLevelCommand(ChatHandler *handler, char const *args)
static bool HandleAccountBoostDelCommand(ChatHandler *handler, char const *args)
static bool HandleAccountSetRegEmailCommand(ChatHandler *handler, char const *args)
Change registration email for account.
static bool HandleAccountLockCountryCommand(ChatHandler *handler, char const *args)
static bool HandleAccountOnlineListCommand(ChatHandler *handler, char const *)
Display info on users currently in the realm.
static bool HandleAccountEmailCommand(ChatHandler *handler, char const *args)
static bool HandleAccountDeleteCommand(ChatHandler *handler, char const *args)
static bool HandleAccountSetEmailCommand(ChatHandler *handler, char const *args)
Set normal email for account.
static bool HandleAccountPasswordCommand(ChatHandler *handler, char const *args)
static bool HandleAccountSetPasswordCommand(ChatHandler *handler, char const *args)
Set password for account.
static bool HandleAccountBoostAddCommand(ChatHandler *handler, char const *args)
static bool HandleAccountAddonCommand(ChatHandler *handler, char const *args)
static bool HandleAccountSetAddonCommand(ChatHandler *handler, char const *args)
Set/Unset the expansion level for an account.
static bool HandleAccountCommand(ChatHandler *handler, char const *)
static bool HandleAccountCreateCommand(ChatHandler *handler, char const *args)
Create an account.
std::vector< ChatCommand > GetCommands() const OVERRIDE
void AddSC_account_commandscript()
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition Main.cpp:41
#define sWorld
Definition World.h:910
@ CONFIG_ACC_PASSCHANGESEC
Definition World.h:353
uint32 ToIPv4NetworkOrder(std::string const &host)
@ RBAC_PERM_MAY_CHECK_OWN_EMAIL
Definition RBAC.h:90
@ RBAC_PERM_COMMAND_ACCOUNT_DELETE
Definition RBAC.h:114
@ RBAC_PERM_COMMAND_ACCOUNT_SET_ADDON
Definition RBAC.h:121
@ RBAC_PERM_COMMAND_ACCOUNT_SET
Definition RBAC.h:120
@ RBAC_PERM_COMMAND_ACCOUNT_BOOST
Definition RBAC.h:692
@ RBAC_PERM_COMMAND_ACCOUNT_BOOST_ADD
Definition RBAC.h:693
@ RBAC_PERM_COMMAND_ACCOUNT_ADDON
Definition RBAC.h:112
@ RBAC_PERM_COMMAND_ACCOUNT_ONLINE_LIST
Definition RBAC.h:118
@ RBAC_PERM_COMMAND_ACCOUNT
Definition RBAC.h:111
@ RBAC_PERM_COMMAND_ACCOUNT_BOOST_DEL
Definition RBAC.h:694
@ RBAC_PERM_COMMAND_ACCOUNT_CREATE
Definition RBAC.h:113
@ RBAC_PERM_COMMAND_ACCOUNT_SET_SEC_EMAIL
Definition RBAC.h:153
@ RBAC_PERM_COMMAND_ACCOUNT_EMAIL
Definition RBAC.h:151
@ RBAC_PERM_COMMAND_ACCOUNT_SET_GMLEVEL
Definition RBAC.h:122
@ RBAC_PERM_COMMAND_ACCOUNT_PASSWORD
Definition RBAC.h:119
@ RBAC_PERM_COMMAND_ACCOUNT_SET_SEC
Definition RBAC.h:152
@ RBAC_PERM_COMMAND_ACCOUNT_LOCK_COUNTRY
Definition RBAC.h:116
@ RBAC_PERM_COMMAND_ACCOUNT_LOCK_IP
Definition RBAC.h:117
@ RBAC_PERM_COMMAND_ACCOUNT_SET_PASSWORD
Definition RBAC.h:123
@ RBAC_PERM_EMAIL_CONFIRM_FOR_PASS_CHANGE
Definition RBAC.h:89
@ RBAC_PERM_COMMAND_ACCOUNT_SET_SEC_REGMAIL
Definition RBAC.h:154
@ RBAC_PERM_COMMAND_ACCOUNT_LOCK
Definition RBAC.h:115
LoginDatabaseWorkerPool LoginDatabase
Definition Main.cpp:54