This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-02-24 09:16:44

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

FireChat (Chat.Py's biggest competition...just kidding)

FireChat is a program that showcases my own server, FireMMO (FireMMO has it's own thread here) With little coding, FireMMO can do almost anything. As a matter of fact, FireChat is only a few lines long. (FireMMO is a few hundred lines long. Oh...the pain)


Woo-Hoo! PMing is now supported. Get the new client!

The server is currently On.

Outdated, ignore: Notice: Currently, the server is turned off. I am working on some functionality that is crucial. It has to do with the mirror, and the mirror's will be obsolete. FireChat will not be online for a while until I can get this to work properly (or revert to my old method. Reply if you have any questions.


Here's instructions to get connected.

1) Download and open up FireChat
   1a) Link here
   1b) Does a dialog enabling Remote Sensors Connections come up?
         1ba) If yes, click okay. Proceed to step 2
         1bb) If no, go to sensing, and right-click the slider sensor value block at the bottom. Click enable remote sensors connections.

2) Run the python mirror:
    2a) Source is this:
     

Code:

# Scratch Mirror
# Version 1.5.0
# Originally by: Magnie. Modified by bobbybee for use in FireMMO

import socket # Network base
import time # For delaying purposes mostly.
import threading # So it can send and receive at the same time anytime.
import array

# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### #
# CHOST is the IP Scratch is running on, if you are running it    #
# on this computer, then the IP is 127.0.0.1                      #
# Theoretically you could run this Mirror on another computer.    #
# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### #
# CPOST is the port Scratch is listening on, the default is       #
# 42001. Usually this is only change by a Scratcher who knows a   #
# about Squeak and networking with sockets.                       #
# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### #
CHOST = '127.0.0.1'
CPORT = 42001

# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### #
# SHOST is the IP the server is running on.                       #
# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### #
# SPORT is the port that the server is using. 42002 is the        #
# unofficial port for Scratch Servers. The host will need to make #
# sure to port-forward the port so people can connect from the    #
# internet.                                                       #
# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### #
SHOST = 'firechat.servequake.com'
SPORT = 42002

# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### #
# Some extra settings that are more for advanced users are below. #
# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### #

# Time between checking the threads for broken ones.
THREADCHECK = 5



class Client(threading.Thread): # This class listens for messages sent from Scratch and sends it to the Server.
    def parse_message(self, message):
        if message:
            sensors = {}
            broadcasts = []

            commands = []
            i = 0
            while True:
                length = ord(message[i]) + ord(message[i+1]) + ord(message[i+2]) + ord(message[i+3])
            
                command = message[i + 4:i + length + 4]
                commands.append(command)
                if (i + length + 4) < len(message):
                    i = (i+4) + length
                else:
                    del command
                    break
            
            for command in commands:
        print command
                if command[0] == 'b':
                    command = command.split('"')
                    command.pop(0)
                    broadcasts.append(command[0])
                
                elif command[0] == 's':
                    command = command.split('"')
                    command.pop(0)
            print(command);
                    try:
                command.remove(' ')
            except ValueError:
                     pass
                    sensors[command[0]] = command[1]
        
            return dict([('sensor-update', sensors), ('broadcast', broadcasts)])
        else: 
            return None
    def sendScratchCommand(self, cmd):
        n = len(cmd)
        a = array('c')
        a.append(chr((n >> 24) & 0xFF))
        a.append(chr((n >> 16) & 0xFF))
        a.append(chr((n >>  8) & 0xFF))
        a.append(chr(n & 0xFF))
        server.sock.send(a.tostring() + cmd)
    
    def __init__(self, CHOST, CPORT):
        threading.Thread.__init__(self) # Initialize it, basically just separate it from the main thread.
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Defines the type of connection ( UPD, TCP on IPv4 or IPv6 )
        print("Connecting to Scratch...")
        self.sock.connect((CHOST, CPORT)) # Connect to Scratch
        print("Connected to Scratch!")
        
    def run(self):
        global running
        print "Listening for Scratch messages."
        while running:
            data = self.sock.recv(1024) # Wait for something to be sent to the mirror
            
            data = self.parse_message(data)
            for sensor in data['sensor-update']:
                if sensor == "packet":
                    self.send(data['sensor-update'][sensor])

    
    def send(self, message):
        server.sock.send(message) # Send the data to the server.

class Server(threading.Thread): # This class listens for messages from the Server and sends it to Scratch.
    def sendScratchCommand(self, cmd):
        n = len(cmd)
        a = []
        a.append(chr((n >> 24) & 0xFF))
        a.append(chr((n >> 16) & 0xFF))
        a.append(chr((n >>  8) & 0xFF))
        a.append(chr(n & 0xFF))
        scratch.sock.send(''.join(a) + cmd)
    def __init__(self, SHOST, SPORT):
        threading.Thread.__init__(self) # Initialize it, basically just separate it from the main thread.
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Defines the type of connection ( UPD, TCP on IPv4 or IPv6 )
        print("Connecting to Scratch Server...")
        self.sock.connect((SHOST, SPORT)) # Connect to the Server.
        print("Connected to Server!")
        
    def run(self):   
        global running
        print "Listening for Server messages."
        while running:    
            data = self.sock.recv(1024) # Listens for messages sent from the Server.
            self.sendScratchCommand("sensor-update packet \""+data+"\"");
            self.sendScratchCommand("broadcast dataready")
    
    def send(self, message):
        scratch.sock.send(message) # Sends messages to Scratch.

running = 1
scratch = Client(CHOST, CPORT) # Start up the class for Scratch
scratch.start() # This starts the 'run' function.

server = Server(SHOST, SPORT) # Start up the class for Server
server.start() # This starts the 'run' function on the class as well.

while running:
    time.sleep(THREADCHECK) # The longer the wait time, the less CPU is used I think.
    try: # Check if the either thread died ( or exists anymore ).
        if scratch: pass
        if server: pass
    except: # If either are dead, end the program.
        running = 0
        print "Finished running."

2b) Install python, if it's not installed already.
      2c) Run the program.
3) Talk. Press the green-flag and chat!

If there are errors, post on this thread.






Known Bugs/Glitches:
-Forward slash (/) and double-quotes (") don't work.

Rules:
-No spamming
-No swearing/inappropriate content such as adult content
-No spoofing
-No hacking, or talking about illegal activities such as warez, or malware.
-Treat respectfully
-One account per person


Special Thanks to Magnie, the Scratcher who helped FireMMO succeed (and inspired me to make FireChat)

Last edited by bobbybee (2012-03-16 18:42:13)


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#2 2012-02-24 09:59:39

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

Now you are going to be asked to make join and leave messages. Then you are going to end up being spammed, so then you will want to add admins/mods, and then others will want to be able to keep their name secure and ask you to create a register, etc.

Out of curiosity, are there any other commands? You may also want to mention /s (forward slashes) and "s (double-quotes) don't work.

Love the title.  wink

Last edited by Magnie (2012-02-24 10:00:10)

Offline

 

#3 2012-02-24 10:07:23

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

I mentioned the glitches, I added rules. Join, leave, kick, and ban are easy. (ban is hard for me, though). I'll report a user if they spam (or break any rules, for that matter). It's okay if you say no, but do you want to be an admin/mod? I'll probably implement a profanity filter anyways.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#4 2012-02-24 10:19:09

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

I'll deny the offer. I've realized after many years, that being a moderator or admin is probably one of the hardest things ever.  tongue

Also, another tip/idea, I suggest putting the "Server: On" at the top of the topic-post.  smile

Offline

 

#5 2012-02-24 10:20:56

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

I agree. I'm only doing it because it's my chat room. I'll put the server indicator at the top. Can you test the new joining/leaving functionality in a few minutes. I wrote some code for join message. (not yet leaving, leavings insane (not really, just lazy  tongue ) ...)


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#6 2012-02-24 10:44:14

zippynk
Scratcher
Registered: 2011-07-23
Posts: 500+

Re: FireChat (Chat.Py's biggest competition...just kidding)

I see one problem. I have a sibling, username puppymk, who would also probably want to use this chat. However, because of the last rule (One account per person), If we both set up accounts, It would look like we were the same person because we are on the same Wi-Fi network. Any ideas on how this could work? (Or is this not something I need to worry about?)


https://dl.dropbox.com/u/60598636/trifocal_interlude_soundcloud_button.png

Offline

 

#7 2012-02-24 10:49:02

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

That's a flaw, I guess. I just feel that if I say 1 account per Scratch account, people are going to spam, because if they get 1 account banned, they'll sign up using a test account. Maybe I'll say something like, "If you have a particular reason for needing several accounts, ask me and I may be able to bend the rules for you," or something similar.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#8 2012-02-24 12:16:01

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Offline

 

#9 2012-02-24 12:20:33

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

Not sure. I think it is 2.something. You'd have to ask Magnie, though. Do you want to chat on this?


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#10 2012-02-24 13:00:49

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

It's Python 2.7  smile

I'll work on an .exe for this later.

Edit:

Here is an EXE for the mirror. Extract it, there will be a folder called "FireChatMirror" open that up then start up mirror.exe.  smile

Last edited by Magnie (2012-02-24 13:28:21)

Offline

 

#11 2012-02-24 13:35:38

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

If I understand this right I need to be connected on an ip via mesh. Right? Because it's not working for me D:
edit: Thanks magnie for the exe  smile

Last edited by slinger (2012-02-24 13:36:05)


http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

#12 2012-02-24 13:41:08

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

slinger wrote:

If I understand this right I need to be connected on an ip via mesh. Right? Because it's not working for me D:
edit: Thanks magnie for the exe  smile

Did you enable remote sensors, etc?

Cause I'm not receiving messages either.  hmm

Offline

 

#13 2012-02-24 13:45:57

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

Well I'm not sure what you mean by enable remote sensors.
edit: Aww can't be on now D:

Last edited by slinger (2012-02-24 13:48:04)


http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

#14 2012-02-24 14:04:05

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

slinger wrote:

Well I'm not sure what you mean by enable remote sensors.
edit: Aww can't be on now D:

http://wiki.scratch.mit.edu/wiki/Remote … onnections

Offline

 

#15 2012-02-24 14:10:31

muppetds
Scratcher
Registered: 2011-02-11
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

Magnie wrote:

It's Python 2.7  smile

I'll work on an .exe for this later.

Edit:

Here is an EXE for the mirror. Extract it, there will be a folder called "FireChatMirror" open that up then start up mirror.exe.  smile

can you make it a mac app?


SCRATCH'S PARTLY INSANE RESIDENT 
http://internetometer.com/imagesmall/31691.pnghttp://bluetetrarpg.x10.mx/usercard/?name=muppetds

Offline

 

#16 2012-02-24 14:25:38

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

muppetds wrote:

Magnie wrote:

It's Python 2.7  smile

I'll work on an .exe for this later.

Edit:

Here is an EXE for the mirror. Extract it, there will be a folder called "FireChatMirror" open that up then start up mirror.exe.  smile

can you make it a mac app?

Well, I attempted to make one, but I got an error in the "compiler" so I'm afraid not. Sorry. I attempted to use this on a Windows computer (which may be the problem, since I don't have a Mac). So if anyone else wants to try.

Offline

 

#17 2012-02-24 15:31:41

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

I'll try it (I'm on a mac)

(wow, my discussion on my thread while I'm not even on...)


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#18 2012-02-24 15:34:14

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

Also Magnie, I received all of your messages (through the server anyways) Do you know if the mirror was receiving the messages?


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#19 2012-02-24 16:18:43

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

bobbybee wrote:

Also Magnie, I received all of your messages (through the server anyways) Do you know if the mirror was receiving the messages?

No, I didn't receive any of my messages.  hmm

Offline

 

#20 2012-02-24 16:26:58

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

Magnie wrote:

bobbybee wrote:

Also Magnie, I received all of your messages (through the server anyways) Do you know if the mirror was receiving the messages?

No, I didn't receive any of my messages.  hmm

Maybe it doesn't send back the message you added?

Offline

 

#21 2012-02-24 18:37:26

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

I have a feeling it has to do something with the mirror...it never worked consistently for me. The thread terminates half the time...


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#22 2012-02-24 18:58:41

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

I restarted the server, and it's running a clean binary now. I have a feeling I was running a weird version of FireMMO...

Try connecting now.

EDIT: Found the source of my grief. The connections should work now.

Last edited by bobbybee (2012-02-24 19:25:27)


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#23 2012-02-24 20:24:21

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

I think I got leaving working right. Also, here is what I plan on doing and when:

-Profanity Filter
-Kicks
-Bans
-Timestamps
-IRC stuff...


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#24 2012-02-25 10:56:27

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

How do I run the mirror?

Offline

 

#25 2012-02-25 11:17:54

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: FireChat (Chat.Py's biggest competition...just kidding)

ImagineIt wrote:

How do I run the mirror?

If you have Python 2.7, you would just double-click the file (I'm pretty sure). If you don't have Python, then you can use this EXE version: http://scratch.mit.edu/forums/viewtopic … 8#p1151288

Offline

 

Board footer