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

#151 2012-04-25 16:18:57

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

Re: DragonThunder (formerly Virtual Ground)

bump


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

Offline

 

#152 2012-04-26 02:49:30

trinary
Scratcher
Registered: 2012-01-29
Posts: 1000+

Re: DragonThunder (formerly Virtual Ground)

Is anything else needed?


http://trinary.tk/images/signature_.php

Offline

 

#153 2012-04-29 13:01:40

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

Re: DragonThunder (formerly Virtual Ground)

Opening Day!


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

Offline

 

#154 2012-04-29 13:11:43

TorbyFork234
Scratcher
Registered: 2012-03-01
Posts: 1000+

Re: DragonThunder (formerly Virtual Ground)

bobbybee wrote:

Opening Day!

???

Opening Day? For what? You're already done?

Offline

 

#155 2012-04-29 13:15:10

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

Re: DragonThunder (formerly Virtual Ground)

Well, partially. See here


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

Offline

 

#156 2012-04-29 13:18:08

TorbyFork234
Scratcher
Registered: 2012-03-01
Posts: 1000+

Re: DragonThunder (formerly Virtual Ground)

Oh...

I think you should make a single player mode also because I have no idea how to connect to the server and I don't want to put extra files on my computer, I doubt anyone else wants to either...

Offline

 

#157 2012-04-29 13:19:57

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

Re: DragonThunder (formerly Virtual Ground)

TorbyFork234 wrote:

Oh...

I think you should make a single player mode also because I have no idea how to connect to the server and I don't want to put extra files on my computer, I doubt anyone else wants to either...

Hmm..


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

Offline

 

#158 2012-04-29 13:28:42

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

Re: DragonThunder (formerly Virtual Ground)

TorbyFork234 wrote:

Oh...

I think you should make a single player mode also because I have no idea how to connect to the server and I don't want to put extra files on my computer, I doubt anyone else wants to either...

I honestly don't mind  tongue


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

Offline

 

#159 2012-04-30 03:47:02

trinary
Scratcher
Registered: 2012-01-29
Posts: 1000+

Re: DragonThunder (formerly Virtual Ground)

bobbybee wrote:

Opening Day!

It's released!  big_smile


http://trinary.tk/images/signature_.php

Offline

 

#160 2012-05-05 12:51:42

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

Re: DragonThunder (formerly Virtual Ground)

Bump!  big_smile


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

Offline

 

#161 2012-05-05 12:53:48

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

Re: DragonThunder (formerly Virtual Ground)

Use this mirror instead of the one in the Show and Tell topic. Lemme set up the gueat account in the DB.

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 = '96.127.188.39'
SPORT = 8089

# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### #
# 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.
        print(data);
            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

Last edited by bobbybee (2012-05-05 12:54:25)


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

Offline

 

#162 2012-05-05 12:57:06

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

Re: DragonThunder (formerly Virtual Ground)

Okay, I'll have to translate it to Python 3 though  tongue


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

Offline

 

#163 2012-05-05 12:58:18

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

Re: DragonThunder (formerly Virtual Ground)

slinger wrote:

Okay, I'll have to translate it to Python 3 though  tongue

...


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

Offline

 

#164 2012-05-05 13:05:44

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

Re: DragonThunder (formerly Virtual Ground)

Nvm, I installed Python 2.7  tongue
The mirror crashes :\


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

Offline

 

#165 2012-05-05 13:15:14

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

Re: DragonThunder (formerly Virtual Ground)

slinger wrote:

Nvm, I installed Python 2.7  tongue
The mirror crashes :\

Hmm...Is Scratch open, and Remote Sensor Connections enabled and everything?


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

Offline

 

#166 2012-05-05 13:20:58

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

Re: DragonThunder (formerly Virtual Ground)

Yeah...
I'm guessing you write part of that mirror because I found a semicolon where most likely there shouldn't have been: after a print statement  tongue
(only saying that 'cause you're a C programmer...)


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

Offline

 

#167 2012-05-05 13:24:14

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

Re: DragonThunder (formerly Virtual Ground)

I did...


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

Offline

 

#168 2012-05-05 13:25:50

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

Re: DragonThunder (formerly Virtual Ground)

Does it crash for you when you try it?


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

Offline

 

#169 2012-05-05 13:42:10

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

Re: DragonThunder (formerly Virtual Ground)

Ah. It was an indentation issue. If you use the original mirror (FireChat source code, if you got that source, not executable) and change the IP, it should work. I can upload the source if you need it, though.


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

Offline

 

#170 2012-05-05 13:47:34

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

Re: DragonThunder (formerly Virtual Ground)

Okay, I can do that!
edit: meanwhile I got it down to one error! Hooray  big_smile

Last edited by slinger (2012-05-05 13:48:01)


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

Offline

 

#171 2012-05-05 13:50:10

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

Re: DragonThunder (formerly Virtual Ground)

Woo-hoo!


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

Offline

 

#172 2012-05-05 13:52:14

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

Re: DragonThunder (formerly Virtual Ground)

Blarg Python can be frustrating. I'm still getting error(yes, I'm using 2.7  tongue )


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

Offline

 

#173 2012-05-05 13:54:21

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

Re: DragonThunder (formerly Virtual Ground)

slinger wrote:

Blarg Python can be frustrating. I'm still getting error(yes, I'm using 2.7  tongue )

Don't speak too soon--an expert in Python has a much easier time than an expert in C. The hours spent debugging...


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

Offline

 

#174 2012-05-05 13:56:44

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

Re: DragonThunder (formerly Virtual Ground)

Haha, I know what you mean...
(I program in Pascal but seeing as C and Pascal are brother languages...)

edit: Debugged! Later I'll make it compatible with Python 3.

here is the code:

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 = 8089

# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### #
# 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.
        print(data);
        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."

Last edited by slinger (2012-05-05 13:58:34)


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

Offline

 

#175 2012-05-05 13:58:04

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

Re: DragonThunder (formerly Virtual Ground)

slinger wrote:

Haha, I know what you mean...
(I program in Pascal but seeing as C and Pascal are brother languages...)

My worst nightmare (moon)  tongue


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

Offline

 

Board footer