ACR_ServerCommunicator.ACR_ServerCommunicator.SendIrcMessage C# (CSharp) Method

SendIrcMessage() private method

Send an IRC message via an IRC gateway.
private SendIrcMessage ( int GatewayId, string Recipient, uint SenderObjectId, string Message ) : void
GatewayId int Supplies the destination IRC gateway /// id.
Recipient string Supplies the destination IRC recipient. ///
SenderObjectId uint Supplies the object id of the sender. /// May be OBJECT_INVALID to send a message using the notification /// service infrastructure. ///
Message string Supplies the message to send.
return void
        private void SendIrcMessage(int GatewayId, string Recipient, uint SenderObjectId, string Message)
        {
            IALFADatabase Database = GetDatabase();
            PlayerState State = TryGetPlayerState(SenderObjectId);
            int CharacterId;
            string FormattedMessage;

            if (State == null)
            {
                //
                // If the sender object is OBJECT_INVALID, then send the
                // message using the infrastructure notification service
                // account.  Otherwise, the sender has already logged out or is
                // not considered online.
                //

                if (SenderObjectId == OBJECT_INVALID)
                {
                    CharacterId = GetLocalInt(GetModule(), "ACR_NOTIFY_SERVICE_CID");

                    if (CharacterId == 0)
                    {
                        return;
                    }
                }
                else
                {
                    SendFeedbackError(SenderObjectId, "Unable to locate player state.");
                    return;
                }
            }
            else
            {
                CharacterId = State.CharacterId;
            }

            if (Recipient.Length > IRC_GATEWAY_MAX_RECIPIENT_LENGTH)
            {
                SendFeedbackError(SenderObjectId, "Recipient too long.");
                return;
            }

            FormattedMessage = String.Format(
                "</c><c=#FFCC99>{0}: </c><c=#30DDCC>[{1}] {2}</c>",
                GetName(SenderObjectId),
                Recipient,
                Message);

            while (!String.IsNullOrEmpty(Message))
            {
                string MessagePart;

                if (Message.Length > IRC_GATEWAY_MAX_MESSAGE_LENGTH)
                {
                    MessagePart = Message.Substring(0, IRC_GATEWAY_MAX_MESSAGE_LENGTH);
                    Message = Message.Substring(IRC_GATEWAY_MAX_MESSAGE_LENGTH);
                }
                else
                {
                    MessagePart = Message;
                    Message = null;
                }

                EnqueueExecuteQuery(String.Format(
                    "INSERT INTO `irc_gateway_messages` (`ID`, `GatewayID`, `SourceCharacterID`, `Recipient`, `Message`) VALUES (0, {0}, {1}, '{2}', '{3}')",
                    GatewayId,
                    CharacterId,
                    Database.ACR_SQLEncodeSpecialChars(Recipient),
                    Database.ACR_SQLEncodeSpecialChars(MessagePart)));
            }

            WorldManager.SignalIPCEventWakeup();
            SendChatMessage(
                OBJECT_INVALID,
                SenderObjectId,
                CHAT_MODE_SERVER,
                FormattedMessage,
                FALSE);
            Database.ACR_IncrementStatistic("IRC_GATEWAY_MESSAGES");
        }
ACR_ServerCommunicator