Advertisement
skillz79

World Chat

Aug 23rd, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. #include "ScriptPCH.h"
  2. #include "Chat.h"
  3. #include "Common.h"
  4. #include "World.h"
  5.  
  6. // Defined ranks
  7. #define ADMINISTRATOR "Admin"
  8. #define HEADGM "Head GM"
  9. #define GAMEMASTER "GM"
  10. #define DEVELOPER "Developer"
  11. #define MODERATOR "Moderator"
  12. #define OWNER "Owner"
  13. #define VIP "Vip"
  14. #define PLAYER "Player"
  15. #define EVENTM "Event Master"
  16. #define CONSOLE "Console"
  17. // Defined colors
  18. #define MSG_COLOR_ORANGE "|cffFFA500"
  19. #define MSG_COLOR_DARKORANGE "|cffFF8C00"
  20. #define MSG_COLOR_RED "|cffFF0000"
  21. #define MSG_COLOR_LIGHTRED "|cffD63931"
  22. #define MSG_COLOR_ROYALBLUE "|cff4169E1"
  23. #define MSG_COLOR_LIGHTBLUE "|cffADD8E6"
  24. #define MSG_COLOR_YELLOW "|cffFFFF00"
  25. #define MSG_COLOR_GREEN "|cff008000"
  26. #define MSG_COLOR_PURPLE "|cffDA70D6"
  27. #define MSG_COLOR_WHITE "|cffffffff"
  28. #define MSG_COLOR_SUBWHITE "|cffbbbbbb"
  29.  
  30. void _SendWorldChat(Player* player, std::string message)
  31. {
  32. std::string rank, color;
  33. std::ostringstream chat_string;
  34.  
  35. switch(player->GetSession()->GetSecurity())
  36. {
  37. case SEC_PLAYER: rank = PLAYER;
  38. color = MSG_COLOR_LIGHTBLUE;
  39. break;
  40. case SEC_VIP: rank = VIP;
  41. color = MSG_COLOR_PURPLE;
  42. break;
  43. case SEC_MODERATOR: rank = MODERATOR;
  44. color = MSG_COLOR_ROYALBLUE;
  45. break;
  46. case SEC_GAMEMASTER: rank = GAMEMASTER;
  47. color = MSG_COLOR_YELLOW;
  48. break;
  49. case SEC_EVENTM: rank = EVENTM;
  50. color = MSG_COLOR_ORANGE;
  51. break;
  52. case SEC_HEADGM: rank = HEADGM;
  53. color = MSG_COLOR_GREEN;
  54. break;
  55. case SEC_DEVELOPER: rank = DEVELOPER;
  56. color = MSG_COLOR_ROYALBLUE;
  57. break;
  58. case SEC_ADMINISTRATOR: rank = ADMINISTRATOR;
  59. color = MSG_COLOR_RED;
  60. break;
  61. case SEC_OWNER: rank = OWNER;
  62. color = MSG_COLOR_RED;
  63. break;
  64. case SEC_CONSOLE: rank = CONSOLE;
  65. color = MSG_COLOR_RED;
  66. break;
  67. }
  68.  
  69. chat_string << "[World]" << " [" << rank << "] " << "[" << color << player->GetName() << "|r]: " << message;
  70.  
  71. char msg[1024];
  72.  
  73. snprintf(msg, 1024, chat_string.str().c_str());
  74.  
  75. if(message.length() >= 3)
  76. sWorld->SendGlobalText(msg, NULL);
  77. else
  78. player->GetSession()->SendNotification("Your message has to be at least 3 characters longer");
  79.  
  80. }
  81.  
  82.  
  83. class World_Chat : public CommandScript
  84. {
  85. public:
  86. World_Chat() : CommandScript("World_Chat") { }
  87.  
  88. static bool HandleWorldChatCommand(ChatHandler * pChat, const char * msg)
  89. {
  90. if(!*msg)
  91. return false;
  92.  
  93. Player* pPlayer = pChat->GetSession()->GetPlayer();
  94.  
  95. if (!pPlayer->CanSpeak())
  96. pPlayer->GetSession()->SendNotification("You can't do that while your voice is disabled");
  97. else
  98. _SendWorldChat(pChat->GetSession()->GetPlayer(), msg);
  99.  
  100. return true;
  101. }
  102.  
  103. ChatCommand * GetCommands() const
  104. {
  105. static ChatCommand HandleWorldChatCommandTable[] =
  106. {
  107. { "world", SEC_PLAYER, true, &HandleWorldChatCommand, "", NULL },
  108. { NULL, 0, false, NULL, "", NULL }
  109. };
  110. return HandleWorldChatCommandTable;
  111. }
  112. };
  113.  
  114. void AddSC_World_Chat()
  115. {
  116. new World_Chat;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement