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");
}