Titles.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <assert.h>
  17. #include <string.h>
  18. #include "Titles.h"
  19. #include "../common/MiscFunctions.h"
  20. Title::Title(){
  21. id = 0;
  22. memset(name, 0, sizeof(name));
  23. prefix = 0;
  24. save_needed = false;
  25. }
  26. Title::Title(Title* title){
  27. id = title->id;
  28. strncpy(name, title->GetName(), sizeof(name));
  29. prefix = title->prefix;
  30. save_needed = title->save_needed;
  31. }
  32. Title::~Title(){
  33. }
  34. MasterTitlesList::MasterTitlesList(){
  35. MMasterTitleMutex.SetName("MasterTitlesList::MMasterTitleMutex");
  36. }
  37. MasterTitlesList::~MasterTitlesList(){
  38. Clear();
  39. }
  40. void MasterTitlesList::Clear(){
  41. MMasterTitleMutex.writelock();
  42. map<sint32, Title*>::iterator itr;
  43. for(itr = titles_list.begin(); itr != titles_list.end(); itr++)
  44. safe_delete(itr->second);
  45. titles_list.clear();
  46. MMasterTitleMutex.releasewritelock();
  47. }
  48. void MasterTitlesList::AddTitle(Title* title){
  49. assert(title);
  50. MMasterTitleMutex.writelock();
  51. if(titles_list.count(title->GetID()) == 0)
  52. titles_list[title->GetID()] = title;
  53. MMasterTitleMutex.releasewritelock();
  54. }
  55. int32 MasterTitlesList::Size(){
  56. int32 size = 0;
  57. MMasterTitleMutex.readlock();
  58. size = titles_list.size();
  59. MMasterTitleMutex.releasereadlock();
  60. return size;
  61. }
  62. Title* MasterTitlesList::GetTitle(sint32 id){
  63. Title* title = 0;
  64. MMasterTitleMutex.readlock();
  65. if(titles_list.count(id) > 0)
  66. title = titles_list[id];
  67. MMasterTitleMutex.releasereadlock();
  68. return title;
  69. }
  70. Title* MasterTitlesList::GetTitleByName(const char* title_name){
  71. Title* title = 0;
  72. map<sint32, Title*>::iterator itr;
  73. MMasterTitleMutex.readlock();
  74. for(itr = titles_list.begin(); itr != titles_list.end(); itr++){
  75. Title* current_title = itr->second;
  76. if(::ToLower(string(current_title->GetName())) == ::ToLower(string(title_name))){
  77. title = current_title;
  78. break;
  79. }
  80. }
  81. MMasterTitleMutex.releasereadlock();
  82. return title;
  83. }
  84. PlayerTitlesList::PlayerTitlesList(){
  85. MPlayerTitleMutex.SetName("PlayerTitlesList::MPlayerTitleMutex");
  86. }
  87. PlayerTitlesList::~PlayerTitlesList(){
  88. MPlayerTitleMutex.writelock();
  89. vector<Title*>::iterator itr;
  90. for (itr = player_titles_list.begin(); itr != player_titles_list.end(); itr++)
  91. safe_delete(*itr);
  92. player_titles_list.clear();
  93. MPlayerTitleMutex.releasewritelock();
  94. }
  95. Title* PlayerTitlesList::GetTitle(sint32 index){
  96. MPlayerTitleMutex.readlock();
  97. Title* title = 0;
  98. Title* ret = 0;
  99. if ( index < player_titles_list.size() )
  100. ret = player_titles_list[index];
  101. MPlayerTitleMutex.releasereadlock();
  102. return ret;
  103. }
  104. Title* PlayerTitlesList::GetTitleByName(const char* title_name){
  105. Title* resTitle = 0;
  106. vector<Title*>::iterator itr;
  107. MPlayerTitleMutex.readlock();
  108. for(itr = player_titles_list.begin(); itr != player_titles_list.end(); itr++){
  109. Title* title = *itr;
  110. if(::ToLower(string(title->GetName())) == ::ToLower(string(title_name))){
  111. resTitle = title;
  112. break;
  113. }
  114. }
  115. MPlayerTitleMutex.releasereadlock();
  116. return resTitle;
  117. }
  118. vector<Title*>* PlayerTitlesList::GetAllTitles(){
  119. MPlayerTitleMutex.readlock();
  120. return &player_titles_list;
  121. }
  122. void PlayerTitlesList::Add(Title* title){
  123. MPlayerTitleMutex.writelock();
  124. player_titles_list.push_back(title);
  125. MPlayerTitleMutex.releasewritelock();
  126. }
  127. int32 PlayerTitlesList::Size(){
  128. int32 size = 0;
  129. MPlayerTitleMutex.readlock();
  130. size = player_titles_list.size();
  131. MPlayerTitleMutex.releasereadlock();
  132. return size;
  133. }