示例#1
0
        /// <summary>
        /// 33 - "@a"
        /// </summary>
        public void MESSENGER_SENDMSG()
        {
            int receiverAmount = Request.getNextWiredParameter();

            Request.Content = Request.Content.Substring(wireEncoding.Encode(receiverAmount).Length);

            List <int> buddyIDs    = ObjectTree.Game.Messenger.getBuddyIDs(Session.User.ID);
            List <int> receiverIDs = new List <int>();

            for (int i = 0; i < receiverAmount; i++)
            {
                int receiverID = Request.getNextWiredParameter();
                if (buddyIDs.Contains(receiverID) && !receiverIDs.Contains(receiverID))
                {
                    receiverIDs.Add(receiverID);
                }

                Request.Content = Request.Content.Substring(wireEncoding.Encode(receiverID).Length);
            }
            buddyIDs = null;

            messengerMessage pMessage = new messengerMessage();

            pMessage.senderID = Session.User.ID;
            pMessage.Sent     = DateTime.Now;
            pMessage.Body     = Request.getParameter(0);
            stringFunctions.filterVulnerableStuff(ref pMessage.Body, false);

            ObjectTree.Game.Messenger.Postmaster.sendMessengerMessage(receiverIDs.ToArray(), pMessage);
        }
示例#2
0
        /// <summary>
        /// Retrieves all non-read messages of a given user and returns it as a messengerMessage array.
        /// </summary>
        /// <param name="userID">The database ID of the user to get the messages for.</param>
        public messengerMessage[] getMessages(int userID)
        {
            List <messengerMessage> Messages = new List <messengerMessage>();
            Database Database = new Database(false, true);

            Database.addParameterWithValue("userid", userID);
            Database.Open();

            if (Database.Ready)
            {
                DataTable dTable = Database.getTable("SELECT messageid,senderid,sent,body FROM messenger_messages WHERE receiverid = @userid ORDER BY messageid ASC");
                foreach (DataRow dRow in dTable.Rows)
                {
                    messengerMessage Message = new messengerMessage();
                    Message.ID       = (int)dRow["messageid"];
                    Message.senderID = (int)dRow["senderid"];
                    Message.Sent     = (DateTime)dRow["sent"];
                    Message.Body     = (string)dRow["body"];

                    Messages.Add(Message);
                }
            }

            return(Messages.ToArray());
        }
        /// <summary>
        /// Delivers a messengerMessage object to a given list of receivers. This is done either synchronous or asynchronous depending on the amount of receivers and the configured value for max synchronous messages.
        /// </summary>
        /// <param name="receiverIDs">An integer array with the database IDs of the users that receive the message on their messenger.</param>
        /// <param name="pMessage">The Woodpecker.Game.Messenger.messengerMessage object that will be distributed.</param>
        public void sendMessengerMessage(int[] receiverIDs, messengerMessage pMessage)
        {
            if (pMessage.senderID == 0) // Invalid message object
            {
                return;
            }

            if (receiverIDs.Length > mMaxSyncMessages) // Launch the message bird on a separate thread
            {
                messageBird.BeginInvoke(receiverIDs, pMessage, null, null);
            }
            else
            {
                messageBird.Invoke(receiverIDs, pMessage);
            }
        }
        private void _launchBird(int[] receiverIDs, messengerMessage pMessage)
        {
            Database Database = new Database(false, false);

            Database.addParameterWithValue("senderid", pMessage.senderID);
            Database.addParameterWithValue("sent", pMessage.Sent);
            Database.addParameterWithValue("body", pMessage.Body);
            Database.Open();
            if (Database.Ready)
            {
                //DateTime now = DateTime.Now;
                //Woodpecker.Core.Logging.Log("Start: " + now.ToString("hh:mm:ss:fff"));
                foreach (int receiverID in receiverIDs)
                {
                    if (Engine.Game.Users.userIsLoggedIn(receiverID)) // Receiver is logged in, retrieve the next message ID, write the message in the database & send it to the receiver
                    {
                        int messageID = Database.getInteger("SELECT MAX(messageid) + 1 FROM messenger_messages WHERE receiverid = '" + receiverID + "' LIMIT 1");
                        Database.runQuery("INSERT INTO messenger_messages(receiverid,messageid,senderid,sent,body) VALUES ('" + receiverID + "','" + messageID + "',@senderid,@sent,@body)");

                        serverMessage Message = new serverMessage(134); // "BF"
                        Message.appendWired(1);
                        pMessage.ID = messageID;
                        Message.Append(pMessage.ToString());
                        Engine.Game.Users.trySendGameMessage(receiverID, Message);
                    }
                    else // Receiver is not online, no need for getting our hands on the next message ID etc
                    {
                        Database.runQuery(
                            "INSERT INTO messenger_messages(receiverid,messageid,senderid,sent,body) " +
                            "SELECT " +
                            "'" + receiverID + "'," +
                            "(MAX(messageid) + 1)," +
                            "@senderid," +
                            "@sent," +
                            "@body " +
                            "FROM messenger_messages WHERE receiverid = '" + receiverID + "' LIMIT 1");
                    }
                }
                //now = DateTime.Now;
                //Woodpecker.Core.Logging.Log("Stop: " + now.ToString("hh:mm:ss:fff"));

                Database.Close();
            }
        }
示例#5
0
        /// <summary>
        /// Retrieves all non-read messages of a given user and returns it as a messengerMessage array.
        /// </summary>
        /// <param name="userID">The database ID of the user to get the messages for.</param>
        public messengerMessage[] getMessages(int userID)
        {
            List<messengerMessage> Messages = new List<messengerMessage>();
            Database Database = new Database(false, true);
            Database.addParameterWithValue("userid", userID);
            Database.Open();

            if (Database.Ready)
            {
                DataTable dTable = Database.getTable("SELECT messageid,senderid,sent,body FROM messenger_messages WHERE receiverid = @userid ORDER BY messageid ASC");
                foreach (DataRow dRow in dTable.Rows)
                {
                    messengerMessage Message = new messengerMessage();
                    Message.ID = (int)dRow["messageid"];
                    Message.senderID = (int)dRow["senderid"];
                    Message.Sent = (DateTime)dRow["sent"];
                    Message.Body = (string)dRow["body"];

                    Messages.Add(Message);
                }
            }

            return Messages.ToArray();
        }
示例#6
0
        /// <summary>
        /// 33 - "@a"
        /// </summary>
        public void MESSENGER_SENDMSG()
        {
            int receiverAmount = Request.getNextWiredParameter();
            Request.Content = Request.Content.Substring(wireEncoding.Encode(receiverAmount).Length);

            List<int> buddyIDs = ObjectTree.Game.Messenger.getBuddyIDs(Session.User.ID);
            List<int> receiverIDs = new List<int>();
            for (int i = 0; i < receiverAmount; i++)
            {
                int receiverID = Request.getNextWiredParameter();
                if (buddyIDs.Contains(receiverID) && !receiverIDs.Contains(receiverID))
                    receiverIDs.Add(receiverID);

                Request.Content = Request.Content.Substring(wireEncoding.Encode(receiverID).Length);
            }
            buddyIDs = null;

            messengerMessage pMessage = new messengerMessage();
            pMessage.senderID = Session.User.ID;
            pMessage.Sent = DateTime.Now;
            pMessage.Body = Request.getParameter(0);
            stringFunctions.filterVulnerableStuff(ref pMessage.Body, false);

            ObjectTree.Game.Messenger.Postmaster.sendMessengerMessage(receiverIDs.ToArray(), pMessage);
        }
示例#7
0
        /// <summary>
        /// Delivers a messengerMessage object to a given list of receivers. This is done either synchronous or asynchronous depending on the amount of receivers and the configured value for max synchronous messages.
        /// </summary>
        /// <param name="receiverIDs">An integer array with the database IDs of the users that receive the message on their messenger.</param>
        /// <param name="pMessage">The Woodpecker.Game.Messenger.messengerMessage object that will be distributed.</param>
        public void sendMessengerMessage(int[] receiverIDs, messengerMessage pMessage)
        {
            if (pMessage.senderID == 0) // Invalid message object
                return;

            if (receiverIDs.Length > this.maxSyncMessages) // Launch the message bird on a separate thread
                this.messageBird.BeginInvoke(receiverIDs, pMessage, null, null);
            else
                this.messageBird.Invoke(receiverIDs, pMessage);
        }
示例#8
0
        private void _launchBird(int[] receiverIDs, messengerMessage pMessage)
        {
            Database Database = new Database(false, false);
            Database.addParameterWithValue("senderid", pMessage.senderID);
            Database.addParameterWithValue("sent", pMessage.Sent);
            Database.addParameterWithValue("body", pMessage.Body);
            Database.Open();
            if (Database.Ready)
            {
                //DateTime now = DateTime.Now;
                //Woodpecker.Core.Logging.Log("Start: " + now.ToString("hh:mm:ss:fff"));
                foreach (int receiverID in receiverIDs)
                {
                    if (ObjectTree.Game.Users.userIsLoggedIn(receiverID)) // Receiver is logged in, retrieve the next message ID, write the message in the database & send it to the receiver
                    {
                        int messageID = Database.getInteger("SELECT MAX(messageid) + 1 FROM messenger_messages WHERE receiverid = '" + receiverID + "' LIMIT 1");
                        Database.runQuery("INSERT INTO messenger_messages(receiverid,messageid,senderid,sent,body) VALUES ('" + receiverID + "','" + messageID + "',@senderid,@sent,@body)");

                        serverMessage Message = new serverMessage(134); // "BF"
                        Message.appendWired(1);
                        pMessage.ID = messageID;
                        Message.Append(pMessage.ToString());
                        ObjectTree.Game.Users.trySendGameMessage(receiverID, Message);
                    }
                    else // Receiver is not online, no need for getting our hands on the next message ID etc
                    {
                        Database.runQuery(
                        "INSERT INTO messenger_messages(receiverid,messageid,senderid,sent,body) " +
                        "SELECT " +
                            "'" + receiverID + "'," +
                            "(MAX(messageid) + 1)," +
                            "@senderid," +
                            "@sent," +
                            "@body " +
                       "FROM messenger_messages WHERE receiverid = '" + receiverID + "' LIMIT 1");
                    }
                }
                //now = DateTime.Now;
                //Woodpecker.Core.Logging.Log("Stop: " + now.ToString("hh:mm:ss:fff"));

                Database.Close();
            }
        }