What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Fix] Problem with OnEvent_ChatWndRecieveMessage's Origin

Pages: (2): « First [ 1 ] 2 » Last »
[Fix] Problem with OnEvent_ChatWndRecieveMessage's Origin
Author: Message:
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
O.P. [Fix] Problem with OnEvent_ChatWndRecieveMessage's Origin

Please  refer to CookieRevised's reply to [Fix] Problem with OnEvent_ChatWndRecieveMessage's Origin as this give proper code.



The rest of this post has been kept for understanding the flow of the thread, the code in it has some flaws and is recommended not to be used, sorry.


A note to script developers:

Because of the StuffPlug Chat Only names feature you will have to use a different method when checking the origin of a received message.

Instead of using:
code:
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind){//When a message is recieved in a chat window
     if(Origin !== Messenger.MyName){//If the sender's name is not my name
          //Do stuff here
     }
     //Do more here if you like
}

You should use the following code:
code:
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind){//When a message is recieved in a chat window
     var WSH = new ActiveXObject("WScript.Shell");
     try{
          var enabled = WSH.RegRead("HKLM\\SOFTWARE\\iAvatars.com\\StuffPlug\\"+Messenger.MyUserId+"\\ChatName");//check id a StuffPlug Registry for Chat Only names exists
          if(enabled === 1){//Check if Chat Only names are enabled
               try{
                    var nick = WSH.RegRead("HKLM\\SOFTWARE\\iAvatars.com\\StuffPlug\\"+Messenger.MyUserId+"\\szChatName");//Test for what the Chat Only name currently is
               }catch(e){//if there is no registry for the Chat Only name
                    var nick = Messenger.MyName;
               }
          }else{//if Chat Only names are _NOT_ enabled
               var nick = Messenger.MyName;
          }
     }catch(e){//if there is no registry for if Chat Only names (ie. StuffPlug is not installed)
          var nick = Messenger.MyName;
     }
     if(Origin !== nick){//If the sender's name is not my name
          //Do stuff here
     }
     //Do more here if you like
}

I do realise this is a little more complex to do, but it will fix this problem that may be effecting your scripts.

Thanks Cookie and deAd for informing me about my mistakes

This post was edited on 01-22-2007 at 06:09 AM by markee.
[Image: markee.png]
01-22-2007 03:05 AM
Profile PM Find Quote Report
deAd
Scripting Contest Winner
*****

Avatar

Posts: 1060
Reputation: 28
– / Male / Flag
Joined: Jan 2006
RE: [Fix] Problem with OnEvent_ChatWndRecieveMessage's Origin
First of all, Messenger.MyUserId is not going to equal the origin unless someone has set their name to it :S (typo/mixup?).

Also, there's an easier method. If you're trying to just find which message is yours, you can do this:

code:
var bSent = false; // a global variable

function OnEvent_ChatWndSendMessage(ChatWnd, Message){
bSent = true; // we've sent a message so set bSent to true
}

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
if(bSent){ // if bSent is true, meaning we just sent a message
bSent = false; // we caught our message so reset it
} else {
// a contact sent the message, so do whatever
}
}
This code ignores the first message that's been received after you send one, which is almost always yours because messenger places your sent message into the textbox immediately after you press Send or Enter.

This post was edited on 01-22-2007 at 03:27 AM by deAd.
01-22-2007 03:26 AM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: [Fix] Problem with OnEvent_ChatWndRecieveMessage's Origin
- 'Origin' is not equal to a user id, it is the nickname
- You need to check on reg setting 'DisabledForxxxxxxxxxx' first
- Reg setting 'ChatName' is a DWORD not a string, thus it will be returned as a number, using ==='1' will always fail.
- You must take in account that 'szChatName' doesn't exist even if ChatName is enabed, in that case the name is 'StuffPlug User'
- Some comments are not prefixed with //
- Code can be optimized a lot


EDIT: I see dead posted first.... anyhow, dead's code can be optimized too...

This post was edited on 01-22-2007 at 06:21 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
01-22-2007 03:36 AM
Profile PM Find Quote Report
deAd
Scripting Contest Winner
*****

Avatar

Posts: 1060
Reputation: 28
– / Male / Flag
Joined: Jan 2006
RE: RE: [Fix] Problem with OnEvent_ChatWndRecieveMessage's Origin
quote:
Originally posted by CookieRevised
EDIT: I see dead posted first.... anyhow, dead's code can be optimized too...
I never said it was perfect :P However, even without optimization I'd consider it to be better than what markee posted. It doesn't rely on the registry, which could change in future SP3 versions (unlikely but possible!). It also doesn't read from the registry every time you receive a message :P .. It's also shorter, less confusing, etc. But yes I agree it could be optimized at least a little.
01-22-2007 03:42 AM
Profile PM Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
O.P. RE: [Fix] Problem with OnEvent_ChatWndRecieveMessage's Origin
@ deAd: Your code has a chance of not working properly.  There is a chance that a contact sends a message between these events being called and that will cause problems.

@ Cookie: Where is the registry 'DisabledForxxxxxxxxxx' I have found nothing with a search of the registry with a search for 'DisabledFor'.  Also I wouldn't mind seeing the code optimised either, that was just the easiest way I could think about doing it.
[Image: markee.png]
01-22-2007 03:45 AM
Profile PM Find Quote Report
deAd
Scripting Contest Winner
*****

Avatar

Posts: 1060
Reputation: 28
– / Male / Flag
Joined: Jan 2006
RE: RE: [Fix] Problem with OnEvent_ChatWndRecieveMessage's Origin
quote:
Originally posted by markee
@ deAd: Your code has a chance of not working properly.  There is a chance that a contact sends a message between these events being called and that will cause problems.
This is highly, highly, highly unlikely. Right from the Plus! documentation:

quote:
Originally posted by Documentation
Because Messenger Plus! analyses messages received only when they reach the chat window, it is not possible to determine exactly from which contact the message came from. However, several methods can be used to guess if the message was actually sent by the current user. For example, to determine whether or not the personalized status messages should be sent when a message is received, Messenger Plus! compares the time of the last ChatWndSendMessage event with the current time. If it is less than 1 second, the message is considered to come from the current user and the previously recorded time is reset. Even if this method of analysis can seem too simplistic, it works in almost every scenario as it is extremely rare to receive a message sent by a contact between the time the "Send" button was pressed and the time the message of the current user was added to the window (as Messenger does not wait to receive a reply from the server before adding the message to the history control).

The code I posted works in a similar way to what Plus! describes. However, instead of using a timer, it simply checks the next message. In this way, it is susceptible to the same extremely rare problem that Plus!'s detection has, but also accounts for messenger hanging for any reason and the message being delivered after more than just a second.

The way you are doing it is more prone to error and confusion because somebody can set their name/chat-only name to yours. The chance of this is much, much higher than the chance of a message being received between the time the Send button was pressed and the sent message is added to the history box.
01-22-2007 04:11 AM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: [Fix] Problem with OnEvent_ChatWndRecieveMessage's Origin
quote:
Originally posted by deAd
The code I posted works in a similar way to what Plus! describes.
not at all... it will fail in many occasions...
quote:
Originally posted by deAd
However, even without optimization I'd consider it to be better than what markee posted.
it is worse though...


----------------------------





Code which checks upon the registry for StuffPlug's ChatOnly name:
code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind) {

    var sMyChatName = Messenger.MyName;
    var sStuffPlugPath = "HKLM\\SOFTWARE\\iAvatars.com\\StuffPlug\\";
    var oWSH = new ActiveXObject("WScript.Shell");
    try {
        var bStuffPlugEnabled = true;
        var bStuffPlugEnabled = oWSH.RegRead(sStuffPlugPath + "DisabledFor" + Messenger.MyUserId) == 0;
    } catch( e){}
    try {
        if (bStuffPlugEnabled) {
            if (oWSH.RegRead(sStuffPlugPath + Messenger.MyUserId + "\\ChatName") == 1) {
                var sMyChatName = "StuffPlug User";
                var sMyChatName = oWSH.RegRead(sStuffPlugPath + Messenger.MyUserId + "\\szChatName");
            }
        }
    } catch( e){}

    if (Origin !== sMyChatName) {
        // a contact sent the message, so do whatever
    }
}
- will fail if contact has same chat name as user.




Code without checking (maybe version dependant) registry settings:
code:
var aSent = new Array();

function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
    aSent[ChatWnd.Handle] = Message;
}

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind) {
    if (aSent[ChatWnd.Handle] === Message) {
        delete aSent[ChatWnd.Handle];
    } else {
        // a contact sent the message, so do whatever
    }
}

This post was edited on 01-22-2007 at 06:22 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
01-22-2007 04:14 AM
Profile PM Find Quote Report
deAd
Scripting Contest Winner
*****

Avatar

Posts: 1060
Reputation: 28
– / Male / Flag
Joined: Jan 2006
RE: RE: [Fix] Problem with OnEvent_ChatWndRecieveMessage's Origin
quote:
Originally posted by CookieRevised
quote:
Originally posted by deAd
The code I posted works in a similar way to what Plus! describes.
not at all... it will fail in many occasions...
It will fail in the same occasions as Plus! does -- when a message is received between the press of the Send button/enter key and when it is entered to the history box.

It does do what the documentation describes, except without a timer. This just accounts for one other potential (and unlikely) problem.
01-22-2007 04:17 AM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: [Fix] Problem with OnEvent_ChatWndRecieveMessage's Origin
quote:
Originally posted by deAd
It will fail in the same occasions as Plus! does
No... it will fail in much more occasions...
quote:
Originally posted by deAd
It does do what the documentation describes, except without a timer.
The timer is there for a reason! But even without the timer and the issue of 'pending' messages, your code will still fail in many more occasions than Plus! does.

---

For both, please see the codes I posted...

sorry to be so short, but I haven't the time atm

This post was edited on 01-22-2007 at 05:01 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
01-22-2007 04:22 AM
Profile PM Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
O.P. RE: [Fix] Problem with OnEvent_ChatWndRecieveMessage's Origin
Cookie, I changed your code because I still could not find that registry on my computer and so I would imagine other people would have the same problem as I am having if this was used.

code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind) {

    var sMyChatName = Messenger.MyName;
    var sStuffPlugPath = "HKLM\\SOFTWARE\\iAvatars.com\\StuffPlug\\";
    var oWSH = new ActiveXObject("WScript.Shell");
    try {
        try{
            var reg = oWSH.RegRead(sStuffPlugPath + "DisabledFor" + Messenger.MyUserId)
            throw "";
        }catch( e){
            if(reg !== undefined && reg !== 0){
                throw "";
            }
            if (oWSH.RegRead(sStuffPlugPath + Messenger.MyUserId + "\\ChatName") === 1) {
                var sMyChatName = "StuffPlug User";
                try {
                    var sMyChatName = oWSH.RegRead(sStuffPlugPath + Messenger.MyUserId + "\\szChatName");
                } catch( e){}
            }
        }
    } catch( e){}

    if (Origin !== sMyChatName) {
        // Do stuff here
    }
    // Do more here if you like
}

This post was edited on 01-22-2007 at 04:49 AM by markee.
[Image: markee.png]
01-22-2007 04:48 AM
Profile PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On