Beispiel #1
0
        void ChatMsg( FriendChatMsg_t chatMsg )
        {
            byte[] msgData = new byte[ 1024 * 4 ];
            EChatEntryType type = EChatEntryType.k_EChatEntryTypeChatMsg;

            CSteamID reciever = new CSteamID( chatMsg.m_ulReceiver );

            int msgLength = steamFriends.GetChatMessage( chatMsg.m_ulReceiver, ( int )chatMsg.m_iChatID, msgData, msgData.Length, ref type );

            if ( type == EChatEntryType.k_EChatEntryTypeTyping )
                return;

            msgLength = Clamp( msgLength, 1, msgData.Length );

            LogMessage log = new LogMessage();

            log.Sender = new CSteamID( chatMsg.m_ulSender );
            log.SenderName = steamFriends.GetFriendPersonaName( log.Sender );

            log.Reciever = reciever;
            log.RecieverName = steamFriends.GetFriendPersonaName( log.Reciever );

            log.Message = Encoding.UTF8.GetString( msgData, 0, msgLength );
            log.Message = log.Message.Substring( 0, log.Message.Length - 1 );
            log.MessageTime = DateTime.Now;
            log.MessageType = type;

            AddLog( log );
        }
Beispiel #2
0
        void FriendChatMsg_OnRun(FriendChatMsg_t param)
        {
            if (context.SteamUser.GetSteamID() == param.m_ulSender)
            {
                return;
            }

            EChatEntryType type = EChatEntryType.k_EChatEntryTypeChatMsg;

            context.SteamFriends.GetChatMessage(param.m_ulSender, ( int )param.m_iChatID, new byte[0], 0, ref type);

            foreach (MessageForm msgForm in this.OwnedForms)
            {
                if (msgForm.FriendID.SteamID == param.m_ulSender)
                {
                    msgForm.RecievedMessage(param);

                    if (chkNoEscape.Checked)
                    {
                        if (type == ( EChatEntryType )6)
                        {
                            msgForm.AwayMsg(param, awayMessageBox.Text);
                            return;
                        }
                    }

                    if (isAway && type != EChatEntryType.k_EChatEntryTypeTyping && type != ( EChatEntryType )6)
                    {
                        msgForm.AwayMsg(param, awayMessageBox.Text);
                        return;
                    }

                    return;
                }
            }

            if (type == EChatEntryType.k_EChatEntryTypeTyping || type == ( EChatEntryType )6)
            {
                return;
            }

            Friend friend = new Friend();

            friend.SteamID     = param.m_ulSender;
            friend.PersonaName = context.SteamFriends.GetFriendPersonaName(friend.SteamID);

            MessageForm mf = new MessageForm(context, friend, sets);

            this.Invoke((MethodInvoker) delegate
            {
                mf.Show(this);
                mf.RecievedMessage(param);

                if (isAway)
                {
                    mf.AwayMsg(param, awayMessageBox.Text);
                }
            });
        }
        private void FriendMessage(FriendChatMsg_t message)
        {
            if (message.m_ulSender == clientUser.GetSteamID())
            {
                return;
            }
            IClient cl = GetSteamClient(message.m_ulSender);

            if (cl == null)
            {
                if (clientList.Clients.ContainsKey(message.m_ulSender))
                {
                    cl = clientList.Clients[message.m_ulSender];
                }
                else
                {
                    cl = new SteamClient(message.m_ulSender);
                }

                clients.Add(cl);
                GetChannel("&Friends").AddClient(cl);
            }

            byte[]         msg     = new byte[4096];
            EChatEntryType type    = EChatEntryType.k_EChatEntryTypeInvalid;
            ulong          chatter = 0;

            int len = clientFriends.GetChatMessage(message.m_ulSender, (int)message.m_iChatID, msg, 4096, ref type, ref chatter);

            len--;

            if (type != EChatEntryType.k_EChatEntryTypeChatMsg && type != EChatEntryType.k_EChatEntryTypeEmote)
            {
                return;
            }

            byte[] a = new byte[len];
            Array.Copy(msg, a, len);

            string[] Messs = Encoding.UTF8.GetString(a).Split(new char[] { '\n' });

            foreach (string Mess in Messs)
            {
                foreach (IClient cli in clients)
                {
                    if (cli.GetType().Equals(typeof(IRCClient)))
                    {
                        cl.AddMessage(IRCMessage.GetStatic().CreateMessage(cl, cl.UserString, "PRIVMSG", new string[] { cli.NickName, (type == EChatEntryType.k_EChatEntryTypeEmote ? "ACTION " : "") + Mess + (type == EChatEntryType.k_EChatEntryTypeEmote ? "" : "") }));
                    }
                }
            }
            //cl.SendMessage(Message.CreateMessage(GetClient(message.m_ulSender), GetClient(message.m_ulSender).UserString, "PRIVMSG", new string[] { client.NickName, "" + (type == EChatEntryType.k_EChatEntryTypeEmote ? "ACTION " : "") + Mess + (type == EChatEntryType.k_EChatEntryTypeEmote ? "" : "" ) }));
        }
Beispiel #4
0
        public void AwayMsg(FriendChatMsg_t param, string msg)
        {
            byte[] text = Encoding.ASCII.GetBytes(msg);

            context.SteamFriends.SendMsgToFriend(param.m_ulSender, EChatEntryType.k_EChatEntryTypeChatMsg, text, text.Length + 1);

            chatBox.Invoke((MethodInvoker) delegate
            {
                chatBox.AppendText(context.SteamFriends.GetPersonaName() + ": " + msg + Environment.NewLine);
                chatBox.ScrollToCaret();
                FlashWindow.Flash(this);
            });
        }
Beispiel #5
0
        private void HandleFriendChatMessage(FriendChatMsg_t param)
        {
            var message = new Message(this, param);
            var type    = message.Type;
            var sent    = message.Sender == LocalUser;

            var msgFunc = sent ? MessageSent : MessageReceived;

            var args = new MessageEventArgs(message);

            OnMessage(args);
            if (msgFunc != null)
            {
                msgFunc(this, args);
            }
            Friends.HandleMessageEvent(sent ? message.Receiver : message.Sender, args);
            if (sent)
            {
                Friends.HandleMessageSentEvent(args);
            }
            else
            {
                Friends.HandleMessageReceivedEvent(args);
            }

            switch (type)
            {
            case EChatEntryType.k_EChatEntryTypeChatMsg:
                OnChatMessage(args);
                var chatFunc = sent ? ChatMessageSent : ChatMessageReceived;
                if (chatFunc != null)
                {
                    chatFunc(this, args);
                }
                Friends.HandleChatMessageEvent(sent ? message.Receiver : message.Sender, args);
                if (sent)
                {
                    Friends.HandleChatMessageSentEvent(args);
                }
                else
                {
                    Friends.HandleChatMessageReceivedEvent(args);
                }
                break;

            case EChatEntryType.k_EChatEntryTypeTyping:
                OnTypingMessage(args);
                var typingFunc = sent ? TypingMessageSent : TypingMessageReceived;
                if (typingFunc != null)
                {
                    typingFunc(this, args);
                }
                Friends.HandleTypingMessageEvent(sent ? message.Receiver : message.Sender, args);
                if (sent)
                {
                    Friends.HandleTypingMessageSentEvent(args);
                }
                else
                {
                    Friends.HandleTypingMessageReceivedEvent(args);
                }
                break;
            }
        }
Beispiel #6
0
        private void HandleCallback()
        {
            // cache for callback
            CallbackMsg_t callbackMsg = new CallbackMsg_t();

            while (true)
            {
                // get callback if available
                bool callbackAvailable = Steamworks.GetCallback(m_Pipe, ref callbackMsg);

                if (callbackAvailable)
                {
                    // process callback
                    switch (callbackMsg.m_iCallback)
                    {
                    case 805:
                        // convert to chat message callback
                        FriendChatMsg_t chatMsg = (FriendChatMsg_t)Marshal.PtrToStructure(callbackMsg.m_pubParam, typeof(FriendChatMsg_t));

                        // setup buffers
                        byte[]         bMsg           = new byte[1024];
                        EChatEntryType eChatEntryType = (EChatEntryType)0;

                        // get chat message
                        int len = m_SteamFriends002.GetChatMessage((CSteamID)chatMsg.m_ulSender, (int)chatMsg.m_iChatID, bMsg, ref eChatEntryType);

                        // get sender
                        CSteamID sender = (CSteamID)chatMsg.m_ulSender;

                        if (len > 0 && eChatEntryType == EChatEntryType.k_EChatEntryTypeChatMsg)
                        {
                            // decode message (excluding null terminator)
                            string msg = Encoding.UTF8.GetString(bMsg, 0, len - 1);

                            if (msg == "PGPSTEAM_REQUEST_KEY")
                            {
                                // send public key
                                SendKey(sender);
                                break;
                            }
                            else if (msg.StartsWith("-----BEGIN PGP PUBLIC KEY BLOCK-----"))
                            {
                                // cache public key
                                File.WriteAllText("key_cache/" + sender.AccountID.ToString() + ".key", msg);
                                break;
                            }

                            if (m_ChatWindows.ContainsKey(sender))
                            {
                                // decode
                                msg = m_PGP.Decrypt(msg);

                                // inject chat message
                                m_ChatWindows[sender].Message(msg);
                            }
                            else
                            {
                                // check has key
                                if (!HasPublicKey(sender))
                                {
                                    break;
                                }

                                // open chat window
                                Chat(sender);

                                // inject chat message
                                if (m_ChatWindows.ContainsKey(sender))
                                {
                                    // decode
                                    msg = m_PGP.Decrypt(msg);

                                    // inject chat message
                                    m_ChatWindows[sender].Message(msg);
                                }
                            }
                        }
                        break;
                    }

                    // free callback
                    Steamworks.FreeLastCallback(m_Pipe);
                }
            }
        }
Beispiel #7
0
 public Message(Steam steam, FriendChatMsg_t msg)
     : this(steam, new CSteamID(msg.m_ulSenderID), new CSteamID(msg.m_ulFriendID),
            (EChatEntryType)msg.m_eChatEntryType, msg.m_iChatID)
 {
 }
Beispiel #8
0
        public void RecievedMessage(FriendChatMsg_t param)
        {
            byte[]         msgData = new byte[1024 * 4];
            EChatEntryType type    = EChatEntryType.k_EChatEntryTypeChatMsg;

            int len = context.SteamFriends.GetChatMessage(param.m_ulSender, ( int )param.m_iChatID, msgData, msgData.Length, ref type);

            if (type == EChatEntryType.k_EChatEntryTypeTyping)
            {
                chatBox.Invoke((MethodInvoker) delegate
                {
                    Text = context.SteamFriends.GetFriendPersonaName(param.m_ulSender) + " is typing a message...";
                });

                if (typingTimer == null)
                {
                    typingTimer = new System.Threading.Timer(typingTimer_Tick, null, 10000, Timeout.Infinite);
                }

                return;
            }

            string text = "";

            if (type == EChatEntryType.k_EChatEntryTypeChatMsg)
            {
                text = context.SteamFriends.GetFriendPersonaName(param.m_ulSender) + ": " + Encoding.ASCII.GetString(msgData, 0, len - 1) + Environment.NewLine;
            }
            else if (type == ( EChatEntryType )6)
            {
                text = "* " + context.SteamFriends.GetFriendPersonaName(param.m_ulSender) + " has closed the window." + Environment.NewLine;
            }
            else
            {
                text = "* " + context.SteamFriends.GetFriendPersonaName(param.m_ulSender) + " " + Encoding.ASCII.GetString(msgData, 0, len - 1) + Environment.NewLine;
            }

            chatBox.Invoke((MethodInvoker) delegate
            {
                Text = context.SteamFriends.GetFriendPersonaName(param.m_ulSender);
            });

            chatBox.Invoke((MethodInvoker) delegate
            {
                chatBox.AppendText(text);
                chatBox.ScrollToCaret();
                FlashWindow.Flash(this);
            });

            if (checkBeeKeeper.Checked && type != EChatEntryType.k_EChatEntryTypeTyping && type != ( EChatEntryType )6)
            {
                txtResponses.Invoke((MethodInvoker) delegate
                {
                    string[] responses = txtResponses.Text.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                    if (responses.Length == 0)
                    {
                        return;
                    }

                    int index = rnd.Next(0, responses.Length);

                    string resp = responses[index];

                    if (beeKeepTimer == null)
                    {
                        beeKeepTimer = new System.Threading.Timer(BeeKeeper, resp, 2000, Timeout.Infinite);
                    }
                });
            }
        }