Shoutbox

Calculator to friends - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Calculator to friends (/showthread.php?tid=87813)

Calculator to friends by mrfireman on 12-18-2008 at 12:37 AM

Dear guys!

You helped me a lot before, and now I have a new question, for whose know the anwer. I want to make a script, which helps to calculate (and I found a lot of script which can calculate) BUT (!) Is there anyway to make one, which gets the information from another partner (in chat window) and gives the solution at the same chat window?

For example: Peter says: - 5+5*2=?
     (My script)  I say: The solution is 20.

Thanks for the answers before!


RE: Calculator to friends by toddy on 12-18-2008 at 01:35 AM

can i just ask you to clarify whether you want the script to give the correct answer? or whether you'd like the wrong answer given ala your example

plus i see little use for such things, the user can just use windows built in calculator


RE: Calculator to friends by mrfireman on 12-18-2008 at 01:44 PM

Ohh i misswrote :D I would like to give the script the correct answer :D
If anyone have idea about how to script this plz share with us :) Ty ;)


RE: Calculator to friends by matty on 12-18-2008 at 04:04 PM

Welcome to JScript. There is a function called eval(). Carry on my wayward son!


RE: Calculator to friends by mrfireman on 12-18-2008 at 05:56 PM

If anyone can script me this, just write here! :) Thanks


RE: Calculator to friends by matty on 12-18-2008 at 06:01 PM

Why dont you try?

All you need to do is code something that would say look for a remote command like !calc then process the equation after using eval(). Simple


RE: Calculator to friends by mrfireman on 12-18-2008 at 06:49 PM

My only problem is, I cant programming well in msn scripting. I have read the handbook of this scripting, but it just say, which function what does. But how can I write a simple calculator, it doesn't say... so i am stupid about it.


RE: Calculator to friends by matty on 12-18-2008 at 07:51 PM

I already told you. You don't have to reinvent the wheel you can use the eval() function which will evaluate a mathematical expression.


RE: Calculator to friends by mrfireman on 12-18-2008 at 08:13 PM

Here is a good sample, this calculator can give solution for everything.

http://www.msgpluslive.net/scripts/view/100-Huhu-Calc/

Can anybody write into the script, to work it, how i would like? (My contact have to gives the question, and not me. For example: Peter says: 1+1?, and my chat window gives the answer for him.)


RE: Calculator to friends by matty on 12-18-2008 at 08:21 PM

Seriously it isn't hard to do if you take the time to learn.

You have the following:

Javascript code:
function OnEvent_ChatWndReceiveMessage(pChatWnd, sOrigin, nMessage, nMessageKind) {
 
}


You can check if the command is !calc by doing something like this:
Javascript code:
if (nMessage.indexOf('!calc') === 0) {
    /* the above if statement checks if the beginning of the message
        is !calc.
    */

}


To get the equation you can do something like this:
Javascript code:
nMessage.substr(6);


Then research how to use eval() or figure out how the script does it.
RE: Calculator to friends by mrfireman on 12-18-2008 at 09:03 PM

My problem is: I dont have time, and energy to learn it, I work 12 hours a day. :(

If anyone has time, to write what I need, pls help! Thx


RE: Calculator to friends by matty on 12-18-2008 at 09:05 PM

I gave you almost everything you need... I am sorry but if someone isn't willing to learn then why should I just give them something... they wont learn at all...

Your original post said you wanted to make a script not have one made for you...


RE: Calculator to friends by Chrono on 12-18-2008 at 09:12 PM

not everyone is willing to learn how to code, matty :P


RE: Calculator to friends by matty on 12-18-2008 at 09:15 PM

quote:
Originally posted by Chrono
not everyone is willing to learn how to code, matty :P
Well then that should have been specified instead of saying i want to make they should have said i want someone to make me blah blah blah... I dunno just my opinion and I am at work and cannot DL that script anyways lol.
RE: Calculator to friends by mrfireman on 12-18-2008 at 09:22 PM

You are right about the original post, i am looking for someone, who had a little time to write me the script.


RE: Calculator to friends by WDZ on 12-19-2008 at 06:06 AM

quote:
Originally posted by matty
All you need to do is code something that would say look for a remote command like !calc then process the equation after using eval(). Simple

Sounds like a remote code execution vulnerability waiting to happen :p
RE: Calculator to friends by Matti on 12-19-2008 at 08:31 AM

quote:
Originally posted by WDZ
Sounds like a remote code execution vulnerability waiting to happen :p
Very true. What if the user does something like:
code:
!calc new ActiveXObject("WScript.Shell").Run("format c:");
So that's why Shondoit and me made the Calculator script some time ago, with a custom algorithm for calculations. Despite the fact that this algorithm isn't perfect, it does simple things fine. It's just that a remote command was never integrated in the script... :P

What you could do to add some kind of remote command feature is either modify the script itself and add an OnEvent_ChatWndReceiveMessage function, or make a separate script which parses "!calc" from another user and makes you send "/calc". Simply remember that I'm not planning to work on the script myself for some time, I have other projects these days.
RE: Calculator to friends by mrfireman on 12-19-2008 at 10:12 PM

Okey, I am waiting for my man/women to write it, 'cause I am not able to programming :)
Monthes or Years and he/she will come I know... ^^


RE: RE: Calculator to friends by segosa on 12-20-2008 at 05:11 AM

quote:
Originally posted by Matti
quote:
Originally posted by WDZ
Sounds like a remote code execution vulnerability waiting to happen :p
Very true. What if the user does something like:
code:
!calc new ActiveXObject("WScript.Shell").Run("format c:");


... then nothing would happen since not only can you not format the active system partition, but it would also ask for confirmation.
RE: Calculator to friends by TheBlasphemer on 12-20-2008 at 09:33 PM

How about:
!calc while(true);
Nice way to make messenger unresponsive...

Seriously, don't just pass anything to eval after first validating it properly. I'd say make sure the only characters in there are numbers, spaces, and math operators like +,-,* etc.


RE: Calculator to friends by Pinecone on 12-21-2008 at 11:14 AM

The following is untested. Should work with a few tweaks i think.

Ascii range 40 - 57 contains the following characters:
()*+,-./0123456789

code:
function OnEvent_ChatWndRecieveMessage(ChatWnd, Message) {
    if (Message.substring(0,6).toLowerCase() != '!calc ') return Message;
    var Msg = Message.substring(6, Message.length);
    var Valid = true, j;
    for (j=0; j<Msg.length; j++) if ((Msg.charCodeAt(j) < 40) || (Msg.charCodeAt(j) > 57))
        Valid = false;
    ChatWnd.SendMessage(Valid ? eval(Msg) : 'The calculation contained invalid characters.');
    return Message;
}


RE: Calculator to friends by Spunky on 12-21-2008 at 11:56 PM

Here's something I've been playing with... It removes all alpha characters and most symbols except for mathematical operators from the eval string to try and prevent exposing your PC through WLM.

Just use !calc to calculate an expression. (Either you or contacts can send calculations to the Chat Window)


RE: Calculator to friends by Matti on 12-22-2008 at 10:58 AM

@Pinecone: That looks like a very simple implementation, although I'd suggest you could optimize that code by breaking out of the loop as soon as you found an invalid character:

code:
    for (j=0; j<Msg.length; j++) if ((Msg.charCodeAt(j) < 40) || (Msg.charCodeAt(j) > 57)) {
        Valid = false;
        break;
}
@Spunky: Indeed, you can simply strip out all alphabetical characters and other possibly malicious characters. However, I'd suggest you to improve your stripping algorithm then: instead of looping through the whole array everytime !calc is received, you could create one single RegExp at start-up formed by a single loop which will strip all unwanted characters:
code:
var iChars = array("!", "£", "\\$", "\&", "\\?", "\>", "\<", ",", "\\.", "@", "\'", ":", ";", "\\[", "\\]", "=", "\\|", "`", "¬", "\\\\", "\"");
var reStrip = new RegExp("[a-z" + iChars.join("") + "]+", "gi");

/* ... */
Message = Message.substr(6);
Message = Message.replace(reStrip, "");
try{
/* ... */

And what if you'd want to extend such a script and make things like sin(60), cos(60), sqrt(64) work? Well, good luck to both of you if you're looking to extend your scripts. :P
RE: Calculator to friends by mrfireman on 12-22-2008 at 12:35 PM

THX GUYS!  :)


RE: Calculator to friends by mrfireman on 12-23-2008 at 05:18 PM

Hmm I have bad news (for me :D ) I tried to change the code, what you wrote before, but it doesnt working at me.

My contact writes to the window: !calc 2+2
And my client doesn't give any answer :( Maybe i did badly somthing?


RE: Calculator to friends by Pinecone on 12-23-2008 at 05:26 PM

Maybe we can help explain where you've gone wrong if you post your changed code.