World Chat

Post Reply
User avatar
evenmonkeys
Posts: 78
Joined: Thu Feb 13, 2014 1:53 am
Location: Midwest, US

World Chat

Post by evenmonkeys » Tue Sep 30, 2014 11:07 pm

I've been trying to read through all of the threads that already exist, but so much of the data has changed since they were posted that it's hard to follow along.

I am ultimately trying to create a world chat. I would really like it if there was a whole new command for it "/world" or whatever. However, I would settle for having "/yell" work as a global chat if the other isn't possible. Could someone please tell me how to go about doing this?

And also.. is it possible to read the chat log from php/mysql to add it to my website?

Thanks!

User avatar
atom0s
Developer
Posts: 537
Joined: Thu Oct 25, 2012 9:52 am

Re: World Chat

Post by atom0s » Tue Sep 30, 2014 11:31 pm

/ commands cannot be added on the server side, the client handles them. So unless you make a plugin / addon for Ashita/Windower and build the world chat packet when its typed it wont work that way. You need to use the games /yell command that is already in place for zone-wide chat, and just make it work server-wide on the server.

User avatar
tagban
Posts: 352
Joined: Fri Dec 28, 2012 11:31 am
Location: Pennsylvania, USA

Re: World Chat

Post by tagban » Sat Oct 25, 2014 10:59 pm

How I handle mine: (Do a search in source for case MESSAGE_YELL )

Code: Select all

				case MESSAGE_YELL:
				{
									 if (map_config.audit_chat == 1 && map_config.audit_yell == 1)
									 {
										 std::string qStr = ("INSERT into audit_chat (speaker,type,message,datetime) VALUES('");
										 qStr += PChar->GetName();
										 qStr += "','YELL','";
										 qStr += escape(data + 6);
										 qStr += "',current_timestamp());";
										 const char * cC = qStr.c_str();
										 Sql_QueryStr(SqlHandle, cC);
									 }
									 for (uint16 zone = 0; zone < MAX_ZONEID; ++zone)
									 {
										 zoneutils::GetZone(zone)->PushPacket(
											 PChar,
											 CHAR_INZONE,
											 new CChatMessagePacket(PChar, MESSAGE_YELL, data + 6));
									 }
									 //PChar->pushPacket(new CMessageStandardPacket(PChar, 0, 256));
				}
					break;

User avatar
evenmonkeys
Posts: 78
Joined: Thu Feb 13, 2014 1:53 am
Location: Midwest, US

Re: World Chat

Post by evenmonkeys » Sun Oct 26, 2014 12:24 am

Yep, I ended up finding a thread you had all of that in and I got it all updated. I just didn't update my thread! >_<; Works pretty well. Added it to audit so I can print it out on the website too. Thanks! :)

KOSMOS
Posts: 67
Joined: Thu Jan 29, 2015 10:36 pm

Re: World Chat

Post by KOSMOS » Sun Feb 28, 2016 5:19 pm

I hit an error when I used your code, not sure if it is due to linux vs Windows.

I changed my server so that say/shout/yell all do world chat, this is tested and works!

I use Ubuntu 14.04 Server.

Thanks for the suggestion tagban!

Code: Select all

/************************************************************************
*                                                                       *
*  Chat Message                                                         *
*                                                                       *
************************************************************************/

void SmallPacket0x0B5(map_session_data_t* session, CCharEntity* PChar, CBasicPacket data)
{
    if (RBUFB(data, (0x06)) == '@' && CmdHandler.call(PChar, (const int8*)data[7]) == 0)
    {
        //this makes sure a command isn't sent to chat
    }
    else if (RBUFB(data, (0x06)) == '#' && PChar->nameflags.flags & FLAG_GM)
    {
        message::send(MSG_CHAT_SERVMES, 0, 0, new CChatMessagePacket(PChar, MESSAGE_SYSTEM_1, data[7]));
    }
    else
    {
        if (jailutils::InPrison(PChar))
        {
            if (RBUFB(data, (0x04)) == MESSAGE_SAY)
            {
                PChar->loc.zone->PushPacket(PChar, CHAR_INRANGE, new CChatMessagePacket(PChar, MESSAGE_SAY, data[6]));
            }
            else
            {
                PChar->pushPacket(new CMessageBasicPacket(PChar, PChar, 0, 0, 316));
            }
        }
        else
        {
            switch (RBUFB(data, (0x04)))
            {
            case MESSAGE_SAY:
            {
                if (map_config.audit_chat == 1 && map_config.audit_say == 1)
                {
                    std::string qStr = ("INSERT into audit_chat (speaker,type,message,datetime) VALUES('");
                    qStr += PChar->GetName();
                    qStr += "','SAY','";
                    qStr += escape(data[6]);
                    qStr += "',current_timestamp());";
                    const char * cC = qStr.c_str();
                    Sql_QueryStr(SqlHandle, cC);
                }
               // PChar->loc.zone->PushPacket(PChar, CHAR_INRANGE, new CChatMessagePacket(PChar, MESSAGE_SAY, data[6]));
                for (uint16 zone = 0; zone < MAX_ZONEID; ++zone)
                            {
                               zoneutils::GetZone(zone)->PushPacket(
                                  PChar,
                                  CHAR_INZONE,
                                  new CChatMessagePacket(PChar, MESSAGE_YELL, data[6]));
                            }
            }
            break;
            case MESSAGE_EMOTION:    PChar->loc.zone->PushPacket(PChar, CHAR_INRANGE, new CChatMessagePacket(PChar, MESSAGE_EMOTION, data[6])); break;
            case MESSAGE_SHOUT:
            {
                if (map_config.audit_chat == 1 && map_config.audit_shout == 1)
                {
                    std::string qStr = ("INSERT into audit_chat (speaker,type,message,datetime) VALUES('");
                    qStr += PChar->GetName();
                    qStr += "','SHOUT','";
                    qStr += escape(data[6]);
                    qStr += "',current_timestamp());";
                    const char * cC = qStr.c_str();
                    Sql_QueryStr(SqlHandle, cC);
                }
                //PChar->loc.zone->PushPacket(PChar, CHAR_INSHOUT, new CChatMessagePacket(PChar, MESSAGE_SHOUT, data[6]));
                         for (uint16 zone = 0; zone < MAX_ZONEID; ++zone)
                            {
                               zoneutils::GetZone(zone)->PushPacket(
                                  PChar,
                                  CHAR_INZONE,
                                  new CChatMessagePacket(PChar, MESSAGE_YELL, data[6]));
                            }
            }
            break;
            case MESSAGE_LINKSHELL:
            {
                if (PChar->PLinkshell1 != nullptr)
                {
                    int8 packetData[8] {};
                    WBUFL(packetData, 0) = PChar->PLinkshell1->getID();
                    WBUFL(packetData, 4) = PChar->id;
                    message::send(MSG_CHAT_LINKSHELL, packetData, sizeof packetData, new CChatMessagePacket(PChar, MESSAGE_LINKSHELL, data[6]));

                    if (map_config.audit_chat == 1 && map_config.audit_linkshell == 1)
                    {
                        std::string qStr = ("INSERT into audit_chat (speaker,type,message,datetime) VALUES('");
                        qStr += PChar->GetName();
                        qStr += "','LINKSHELL','";
                        qStr += escape(data[6]);
                        qStr += "',current_timestamp());";
                        const char * cC = qStr.c_str();
                        Sql_QueryStr(SqlHandle, cC);
                    }
                }
            }
            break;
            case MESSAGE_LINKSHELL2:
            {
                if (PChar->PLinkshell2 != nullptr)
                {
                    int8 packetData[8] {};
                    WBUFL(packetData, 0) = PChar->PLinkshell2->getID();
                    WBUFL(packetData, 4) = PChar->id;
                    message::send(MSG_CHAT_LINKSHELL, packetData, sizeof packetData, new CChatMessagePacket(PChar, MESSAGE_LINKSHELL, data[6]));

                    if (map_config.audit_chat == 1 && map_config.audit_linkshell == 1)
                    {
                        std::string qStr = ("INSERT into audit_chat (speaker,type,message,datetime) VALUES('");
                        qStr += PChar->GetName();
                        qStr += "','LINKSHELL','";
                        qStr += escape(data[6]);
                        qStr += "',current_timestamp());";
                        const char * cC = qStr.c_str();
                        Sql_QueryStr(SqlHandle, cC);
                    }
                }
            }
            break;
            case MESSAGE_PARTY:
            {
                if (PChar->PParty != nullptr)
                {
                    int8 packetData[8] {};
                    WBUFL(packetData, 0) = PChar->PParty->GetPartyID();
                    WBUFL(packetData, 4) = PChar->id;
                    message::send(MSG_CHAT_PARTY, packetData, sizeof packetData, new CChatMessagePacket(PChar, MESSAGE_PARTY, data[6]));

                    if (map_config.audit_chat == 1 && map_config.audit_party == 1)
                    {
                        std::string qStr = ("INSERT into audit_chat (speaker,type,message,datetime) VALUES('");
                        qStr += PChar->GetName();
                        qStr += "','PARTY','";
                        qStr += escape(data[6]);
                        qStr += "',current_timestamp());";
                        const char * cC = qStr.c_str();
                        Sql_QueryStr(SqlHandle, cC);
                    }
                }
            }
            break;
              case MESSAGE_YELL:
            {
                            if (map_config.audit_chat == 1 && map_config.audit_yell == 1)
                            {
                                std::string qStr = ("INSERT into audit_chat (speaker,type,message,datetime) VALUES('");
                                qStr += PChar->GetName();
                                qStr += "','YELL','";
                                qStr += escape(data[6]);
                                qStr += "',current_timestamp());";
                                const char * cC = qStr.c_str();
                                Sql_QueryStr(SqlHandle, cC);
                            }
                            for (uint16 zone = 0; zone < MAX_ZONEID; ++zone)
                            {
                               zoneutils::GetZone(zone)->PushPacket(
                                  PChar,
                                  CHAR_INZONE,
                                  new CChatMessagePacket(PChar, MESSAGE_YELL, data[6]));
                            }
                            //PChar->pushPacket(new CMessageStandardPacket(PChar, 0, 256));
            }
               break;
          /*  case MESSAGE_YELL:
            {
                if (PChar->loc.zone->CanUseMisc(MISC_YELL))
                {
                    if (gettick() >= PChar->m_LastYell)
                    {
                        PChar->m_LastYell = gettick() + (map_config.yell_cooldown * 1000);
                        // ShowDebug(CL_CYAN" LastYell: %u \n" CL_RESET, PChar->m_LastYell);
                        int8 packetData[4] {};
                        WBUFL(packetData, 0) = PChar->id;

                        message::send(MSG_CHAT_YELL, packetData, sizeof packetData, new CChatMessagePacket(PChar, MESSAGE_YELL, data[6]));
                    }
                    else // You must wait longer to perform that action.
                    {
                        PChar->pushPacket(new CMessageStandardPacket(PChar, 0, 38));
                    }

                    if (map_config.audit_chat == 1 && map_config.audit_yell == 1)
                    {
                        std::string qStr = ("INSERT into audit_chat (speaker,type,message,datetime) VALUES('");
                        qStr += PChar->GetName();
                        qStr += "','YELL','";
                        qStr += escape(data[6]);
                        qStr += "',current_timestamp());";
                        const char * cC = qStr.c_str();
                        Sql_QueryStr(SqlHandle, cC);
                    }
                }
                else // You cannot use that command in this area.
                {
                    PChar->pushPacket(new CMessageStandardPacket(PChar, 0, 256));
                }
            }
            break; */
            }
        }
    }

    return;
}

User avatar
tagban
Posts: 352
Joined: Fri Dec 28, 2012 11:31 am
Location: Pennsylvania, USA

Re: World Chat

Post by tagban » Sun Feb 28, 2016 10:09 pm

At this point the core has changed a lot. I have a world chat that I setup to use /say I can post that here in a new thread if you'd like. If I remember tomorrow. It's complex but works beautifully. The other option is to simply set all zones to some setting (I forget which offhand) and it allows yell in all zones together. I preferred a system that users can set chatmode.

Post Reply