Modcraft - The community dedicated to quality WoW modding!

Wrath of the Lich King Modding => Serverside Modding => Topic started by: Everon Mightbane on August 24, 2011, 09:09:53 pm

Title: [C++] Trinity Announce System
Post by: Everon Mightbane on August 24, 2011, 09:09:53 pm
Hey does anyone have or know about a trinity announce system that roughly outputs:

Servername Rank PlayerName: Message

So for example


CoolWoW Admin Bob: Hello world.

Thanks in advance.
Title: Re: [C++] Trinity Announce System
Post by: Laniax on August 25, 2011, 12:10:51 am
you can mod the announce command to include the servername. check out the cs_* and level* files.
Title: Re: [C++] Trinity Announce System
Post by: Everon Mightbane on August 25, 2011, 11:32:06 am
Yeah, I've been able to include the server name but I haven't managed to do the rank part.
Title: Re: [C++] Trinity Announce System
Post by: Laniax on August 25, 2011, 11:21:08 pm
You could call the player's GMlevel and then based on that level add a rank to the command

for example:

Code: [Select]
uint32 gmlevel = player->GetSession()->GetSecurity();
std::string rank;
switch (gmlevel)
{
   case 1: // gmlevel is 1
     rank = "Moderator"; break;
  case 2: // gmlevel is 2
     rank = "Game Master"; break;
   case 3: // gmlevel is 3
     rank = "Server Admin"; break;
default: rank = ""; break;
}

that way the 'rank' string has the current playerrank, you can simple add this inside the announce. Adding more ranks should be easy.
Title: Re: [C++] Trinity Announce System
Post by: schlumpf on August 25, 2011, 11:28:08 pm
Quote from: "Laniax"
You could call the player's GMlevel and then based on that level add a rank to the command

for example:

Code: [Select]
uint32 gmlevel = player->GetSession()->GetSecurity();
std::string rank;
switch (gmlevel)
{
   case 1: // gmlevel is 1
     rank = "Moderator"; break;
  case 2: // gmlevel is 2
     rank = "Game Master"; break;
   case 3: // gmlevel is 3
     rank = "Server Admin"; break;
default: rank = ""; break;
}

that way the 'rank' string has the current playerrank, you can simple add this inside the announce. Adding more ranks should be easy.

I hope their rank variable is enumerated. You may want to use that enumeration instead.
Title: Re: [C++] Trinity Announce System
Post by: Laniax on August 25, 2011, 11:37:14 pm
Quote from: "schlumpf"
I hope their rank variable is enumerated. You may want to use that enumeration instead.

It is, and GetSecurity() returns the value of that. yet you have to put a string with that int yourself.
Title: Re: [C++] Trinity Announce System
Post by: schlumpf on August 25, 2011, 11:38:16 pm
Quote from: "Laniax"
Quote from: "schlumpf"
I hope their rank variable is enumerated. You may want to use that enumeration instead.

It is, and GetSecurity() returns the value of that. yet you have to put a string with that int yourself.
Yes, but you shouldn't compare to 1, 2 and 3 then but against the names of the enumeration, to be safe and verbose.
Title: Re: [C++] Trinity Announce System
Post by: Laniax on August 25, 2011, 11:42:54 pm
Quote from: "schlumpf"
Quote from: "Laniax"
Quote from: "schlumpf"
I hope their rank variable is enumerated. You may want to use that enumeration instead.

It is, and GetSecurity() returns the value of that. yet you have to put a string with that int yourself.
Yes, but you shouldn't compare to 1, 2 and 3 then but against the names of the enumeration, to be safe and verbose.

Yeah alright :P i wasn't applying code styles eitherway since i wrote this in 10secs.
Yet with your way it would look like this;

Code: [Select]
  case SEC_MODERATOR:
     rank = "Moderator"; break;
  case SEC_GAMEMASTER:
     rank = "Game Master"; break;
   case SEC_ADMINISTRATOR:
     rank = "Server Admin"; break;
Title: Re: [C++] Trinity Announce System
Post by: Everon Mightbane on August 26, 2011, 12:11:52 am
Alright, Just compiling now. Lets see how this goes :D Thanks for your help everyone.
Title: Re: [C++] Trinity Announce System
Post by: Everon Mightbane on August 27, 2011, 01:54:09 pm
It didn't work so far but I'm going to tinker with it, one thing though. As trinity only has the account permissions 0-4, 4 being the console, is there anyway to increase the number? Or change it to like az a p - As in alphabetical account permissions?
Title: Re: [C++] Trinity Announce System
Post by: Laniax on August 27, 2011, 03:02:16 pm
Quote from: "Everon Mightbane"
It didn't work so far but I'm going to tinker with it, one thing though. As trinity only has the account permissions 0-4, 4 being the console, is there anyway to increase the number? Or change it to like az a p - As in alphabetical account permissions?

You can add more account permission levels in Common.h atleast if you keep your SEC_CONSOLE as the last one. The security level required to do commands is held in the Command table in your database. so you will probably have to update all those records. (can be done with a few lines of SQL)
Title: Re: [C++] Trinity Announce System
Post by: Everon Mightbane on August 27, 2011, 03:36:32 pm
Thanks :D I'll work on that now. EDIT: Also, can I change them to alphabetic characters so for example:

SEC_ADMINISTRATOR = "az",

Would that work?
Title: Re: [C++] Trinity Announce System
Post by: Laniax on August 27, 2011, 09:20:14 pm
Quote from: "Everon Mightbane"
Thanks :D I'll work on that now. EDIT: Also, can I change them to alphabetic characters so for example:

SEC_ADMINISTRATOR = "az",

Would that work?

No that won't work, you cannot enumerate anything else then integers
Title: Re: [C++] Trinity Announce System
Post by: Everon Mightbane on August 27, 2011, 09:49:02 pm
Yeah, I worked that out after I attempted to compile it, Is there any way I can change that?
Title: Re: [C++] Trinity Announce System
Post by: Laniax on August 27, 2011, 09:59:32 pm
Quote from: "Everon Mightbane"
Yeah, I worked that out after I attempted to compile it, Is there any way I can change that?
I'm afraid there isn't an easy way, no. :P
Title: Re: [C++] Trinity Announce System
Post by: Everon Mightbane on August 27, 2011, 10:00:47 pm
Meh. Well that sucks. Thanks anyway.
Title: Re: [C++] Trinity Announce System
Post by: Everon Mightbane on August 28, 2011, 08:10:35 pm
Sorry for double posting, but could someone take a look at this and tell me why its not working, it compiles just fine, however when I use .announce my worldserver.exe crashes.: [spoiler:2mi2ysll]
Code: [Select]
#include "Chat.h"
#include "ScriptPCH.h"
class ann_commandscript : public CommandScript
{
public:
    ann_commandscript() : CommandScript("ann_commandscript") { }
    ChatCommand* GetCommands() const
    {
        static ChatCommand commandTable[] =
        {
            { "announce",                              SEC_PLAYER,  true, &HandleAnnounceCommand,                                  "", NULL },
{ NULL,                                             0, false, NULL,                                                    "", NULL }
        };
        return commandTable;
    };
static bool HandleAnnounceCommand(ChatHandler* handler, const char* args)
{
    std::string rank("");
    uint32 gmlevel;
    WorldPacket data;
    std::string name("Console");
    if (WorldSession* session = handler->GetSession())
    {
Player* player = session->GetPlayer();
gmlevel = player->GetSession()->GetSecurity();
    switch (gmlevel)
{
    case 0:
      rank = "|cff0051FFPlayer|r"; break;
    case 1:
      rank = "|cff88DC51Voter|r"; break;
    case 2:
      rank = "|cffF28A00Donator|r"; break;
    case 3:
      rank = "|cffAD01B0Moderator|r"; break;
  case 4:
      rank = "|cffAD01B0Administrator|r"; break;
}  
    }
   
    if (!*args)
        return false;
    if (WorldSession* session = handler->GetSession())
        name = session->GetPlayer()->GetName();
    sWorld->SendWorldText(LANG_CUSTOM_ANNOUNCE, rank, name, args);
    return true;
    }
};
void AddSC_ann_commandscript()
{
    new ann_commandscript();
};
[/spoiler:2mi2ysll]

LANG_CUSTOM_ANNOUNCE is linked up in language.h and has the correct reference in my trinity_string table and the script compiles without issue.
Title: Re: [C++] Trinity Announce System
Post by: Steff on September 01, 2011, 12:08:11 am
Please use pastbin!
Title: Re: [C++] Trinity Announce System
Post by: schlumpf on September 01, 2011, 12:09:33 am
Player* player = session->GetPlayer();
> Not checked for player == NULL.
   gmlevel = player->GetSession()->GetSecurity();
> Not checked for GetSessin() == NULL, also this should be the same as session already retrieved earlier.
    if (!*args)
> You should check that right away on the top, before doing anything else.
    if (WorldSession* session = handler->GetSession())
        name = session->GetPlayer()->GetName();
> You're getting the session another time. Also, not checking for player being NULL.
    sWorld->SendWorldText(LANG_CUSTOM_ANNOUNCE, rank, name, args);
> sWorld is NULL? Idk.
Title: Re: [C++] Trinity Announce System
Post by: Everon Mightbane on September 01, 2011, 12:44:00 am
Still not working heres my updated code: http://pastebin.com/FV1rtUP7 (http://pastebin.com/FV1rtUP7" onclick="window.open(this.href);return false;)
Title: Re: [C++] Trinity Announce System
Post by: schlumpf on September 01, 2011, 01:31:54 am
Quote from: "Everon Mightbane"
Still not working heres my updated code: http://pastebin.com/FV1rtUP7 (http://pastebin.com/FV1rtUP7" onclick="window.open(this.href);return false;)
When Trinity is crashing, it produces a crash dump containing information for MSVC++. this even contains the line where it crashed and maybe indicators, why.
Have a look at that.
Title: Re: [C++] Trinity Announce System
Post by: Everon Mightbane on September 01, 2011, 01:49:04 pm
Mine says this:
Code: [Select]
C:UsersSamDesktopGlorious-WoW CoresrcserverworldserverMaster.cpp:105 in FreezeDetectorRunnable::run ASSERTION FAILED:
  false
[0x2dc430]
?invoke@ACE_OS_Thread_Adapter@@UAEKXZ()+0x74 [0x0]
_endthreadex()+0x3a [0x0]
_endthreadex()+0xe4 [0x0]
BaseThreadInitThunk()+0x12 [0x0]
RtlInitializeExceptionChain()+0x63 [0x0]
RtlInitializeExceptionChain()+0x36 [0x0]