What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Calculator to friends

Pages: (3): « First « 1 2 [ 3 ] Last »
Calculator to friends
Author: Message:
Pinecone
New Member
*

Avatar
Coffee Powered

Posts: 9
34 / Male / Flag
Joined: Dec 2008
RE: Calculator to friends
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;
}


This post was edited on 12-21-2008 at 11:15 AM by Pinecone.
12-21-2008 11:14 AM
Profile E-Mail PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
35 / Male / Flag
Joined: Aug 2006
RE: Calculator to friends
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)

.plsc File Attachment: Calculate This.plsc (996 bytes)
This file has been downloaded 191 time(s).
<Eljay> "Problems encountered: shit blew up" :zippy:
12-21-2008 11:56 PM
Profile PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: Calculator to friends
@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

This post was edited on 12-22-2008 at 10:59 AM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
12-22-2008 10:58 AM
Profile E-Mail PM Web Find Quote Report
mrfireman
Junior Member
**


Posts: 25
Joined: Oct 2008
O.P. RE: Calculator to friends
THX GUYS!  :)
12-22-2008 12:35 PM
Profile E-Mail PM Find Quote Report
mrfireman
Junior Member
**


Posts: 25
Joined: Oct 2008
O.P. RE: Calculator to friends
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?
12-23-2008 05:18 PM
Profile E-Mail PM Find Quote Report
Pinecone
New Member
*

Avatar
Coffee Powered

Posts: 9
34 / Male / Flag
Joined: Dec 2008
RE: Calculator to friends
Maybe we can help explain where you've gone wrong if you post your changed code.

This post was edited on 12-23-2008 at 06:51 PM by Pinecone.
12-23-2008 05:26 PM
Profile E-Mail PM Find Quote Report
Pages: (3): « First « 1 2 [ 3 ] 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