Ejemplo n.º 1
0
        /// <summary>
        /// overridden OnConnect to start off SHTTP protocol.
        /// </summary>
        /// <param name="sock"></param>
        public override void OnConnect(Bedrock.Net.BaseSocket sock)
        {
            if (m_state == States.Connecting)
            { // CONNECT users.instapix.com:5222 HTTP/1.0
                m_state = States.WaitingForAuth;
                string cmd = string.Format(@"CONNECT {0}:{1} HTTP/1.1
Host: {0}
", RemoteAddress.Hostname, RemoteAddress.Port);

                // if authinfo is set, send it.
                if (Username != null && Username.Length > 0 && Password != null && Password.Length > 0)
                {
                    string auth = Convert.ToBase64String(Encoding.ASCII.GetBytes(Username + ":" + Password));
                    cmd += "Proxy-Authorization: Basic " + auth + "\r\n";
                }
                cmd += "\r\n";
                Debug.WriteLine("PSEND:" + cmd);
                Write(Encoding.ASCII.GetBytes(cmd));
                RequestRead();
            }
        }
Ejemplo n.º 2
0
        public static void ResetBlocks(Level level, BoundingBox bbox, bool repopulate = false)
        {
            bbox = bbox.GetAdjustedBoundingBox();
            ChunkColumn chunk = null;
            Dictionary <ChunkCoordinates, ChunkColumn> chunks = new Dictionary <ChunkCoordinates, ChunkColumn>();

            for (int x = (int)bbox.Min.X; x < (int)bbox.Max.X + 1; x++)
            {
                for (int z = (int)bbox.Min.Z; z < (int)bbox.Max.Z + 1; z++)
                {
                    var blockCoord = new BlockCoordinates(x, 0, z);
                    ChunkCoordinates chunkCoordinates = (ChunkCoordinates)blockCoord;
                    if (chunk == null || chunk.X != chunkCoordinates.X || chunk.Z != chunkCoordinates.Z)
                    {
                        if (!chunks.TryGetValue(chunkCoordinates, out chunk))
                        {
                            chunk = level.GetChunk(chunkCoordinates, true);
                            chunks[chunkCoordinates] = chunk;
                        }
                    }

                    level.SetBiomeId(blockCoord, 1);
                    int height = 255;
                    if (chunk != null)
                    {
                        height = chunk.GetHeight(blockCoord.X & 0x0f, blockCoord.Z & 0x0f);
                    }

                    for (int y = 0; y < 256; y++)
                    {
                        if (y == 0)
                        {
                            var block = new Bedrock {
                                Coordinates = new BlockCoordinates(x, y, z)
                            };
                            level.SetBlock(block, applyPhysics: false, calculateLight: false, possibleChunk: chunk);                             // Bedrock
                        }
                        else if (repopulate && y == PlotHeight)
                        {
                            var block = PlotPattern.Next(new BlockCoordinates(x, PlotHeight, z));
                            level.SetBlock(block, applyPhysics: false, calculateLight: false, possibleChunk: chunk);                             // grass
                        }
                        else if (y >= PlotHeight)
                        {
                            if (y <= height || !level.IsAir(new BlockCoordinates(x, y, z)))
                            {
                                var block = new Air {
                                    Coordinates = new BlockCoordinates(x, y, z)
                                };
                                level.SetBlock(block, applyPhysics: false, calculateLight: false, possibleChunk: chunk);                                 // air
                            }
                        }
                        else if (y == PlotHeight - 1)
                        {
                            var block = new Grass {
                                Coordinates = new BlockCoordinates(x, y, z)
                            };
                            level.SetBlock(block, applyPhysics: false, calculateLight: false, possibleChunk: chunk);                             // grass
                        }
                        else if (y > PlotHeight - 4)
                        {
                            var block = new Dirt {
                                Coordinates = new BlockCoordinates(x, y, z)
                            };
                            level.SetBlock(block, applyPhysics: false, calculateLight: false, possibleChunk: chunk);                             // dirt
                        }
                        else
                        {
                            var block = new Stone {
                                Coordinates = new BlockCoordinates(x, y, z)
                            };
                            level.SetBlock(block, applyPhysics: false, calculateLight: false, possibleChunk: chunk);                             // stone
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
	void BuildChunk() {
		bool dataFromFile = false;
		dataFromFile = Load();

		chunkData = new Block[World.chunkSize,World.chunkSize,World.chunkSize];
		for(int z = 0; z < World.chunkSize; z++)
			for(int y = 0; y < World.chunkSize; y++)
				for(int x = 0; x < World.chunkSize; x++) {
					Vector3 pos = new Vector3(x,y,z);
					int worldX = (int)(x + chunk.transform.position.x);
					int worldY = (int)(y + chunk.transform.position.y);
					int worldZ = (int)(z + chunk.transform.position.z);

					if(dataFromFile) {
						chunkData[x,y,z] = new Block(bd.matrix[x, y, z], pos, 
							chunk.gameObject, this);
						continue;
					}


					int surfaceHeight = Utils.GenerateHeight(worldX,worldZ);


					if (worldY == 0)
						chunkData [x, y, z] = new Bedrock (pos, this); //new Block(Block.BlockType.BEDROCK, pos, 
							//chunk.gameObject, this);
					else if (Utils.fBM3D (worldX, worldY, worldZ, 0.1f, 3) < 0.42f)
						chunkData [x, y, z] = new Air (pos, this); //new Block(Block.BlockType.AIR, pos, 
							//chunk.gameObject, this);
					else if(worldY <= Utils.GenerateStoneHeight(worldX,worldZ)) {
						if (Utils.fBM3D (worldX, worldY, worldZ, 0.01f, 2) < 0.4f && worldY < 40)
							chunkData [x, y, z] = new Diamond (pos, this); //new Block (Block.BlockType.DIAMOND, pos, 
								//chunk.gameObject, this);
						else if (Utils.fBM3D (worldX, worldY, worldZ, 0.03f, 3) < 0.41f && worldY < 20)
							chunkData [x, y, z] = new RedStone (pos, this); //new Block (Block.BlockType.REDSTONE, pos, 
								//chunk.gameObject, this);
						else
							chunkData [x, y, z] = new Stone (pos, this); //new Block(Block.BlockType.STONE, pos, 
								//chunk.gameObject, this);
					}
					else if(worldY == surfaceHeight) {
						surfaceChunk = true;
						if (Utils.fBM3D (worldX, worldY, worldZ, 0.4f, 2) < 0.4f && worldY > 70)
							chunkData [x, y, z] = new WoodBase (pos, this); //new Block (Block.BlockType.WOODBASE, pos, 
								//chunk.gameObject, this);
						else {
							
							chunkData [x, y, z] = new Grass (pos, this); //new Block (Block.BlockType.GRASS, pos, 
								//chunk.gameObject, this);
						}
					}
					else if(worldY < surfaceHeight)
						chunkData[x,y,z] = new Dirt (pos, this);// new Block(Block.BlockType.DIRT, pos, 
							//chunk.gameObject, this);
					else {
						chunkData [x, y, z] = new Air (pos, this); //new Block(Block.BlockType.AIR, pos, 
							//chunk.gameObject, this);
					}

					if (worldY < 70 && worldY > 40 && chunkData [x, y, z].bType == Block.BlockType.AIR) {
						//fluid.gameObject.transform.parent = World.Instance.transform;
						chunkData [x, y, z] = new Water (pos, this); //new Block (Block.BlockType.WATER, pos, 
							//fluid.gameObject, this);
						waterChunk = true;
					}

					status = ChunkStatus.DRAW;

				}
	}
Ejemplo n.º 4
0
        ///<summary>
        /// Removes the publish-subscribe node from the manager and sends a delete
        /// node to the XMPP server.
        ///</summary>
        /// <param name="service">
        /// Component that handles PubSub requests.
        /// </param>
        /// <param name="node">
        /// The node on the component that the client wants to interact with.
        /// </param>
        /// <param name="errorHandler">
        /// Callback for any errors with the publish-subscribe node deletion.
        /// </param>
        public void RemoveNode(JID service, string node, Bedrock.ExceptionHandler errorHandler)
        {
            JIDNode jn = new JIDNode(service, node);

            PubSubNode psNode = null;
            if (m_nodes.TryGetValue(jn, out psNode))
            {
                m_nodes.Remove(jn);
            }
            else
            {
                psNode = new PubSubNode(Stream, service, node, 10);
            }

            psNode.OnError += errorHandler;

            psNode.Delete();
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Overridden OnRead to handle 4 Socks5 states...
 /// </summary>
 /// <param name="sock"></param>
 /// <param name="buf"></param>
 /// <param name="offset"></param>
 /// <param name="length"></param>
 /// <returns></returns>
 public override bool OnRead(Bedrock.Net.BaseSocket sock, byte[] buf, int offset, int length)
 {
     switch (m_state)
     {
     case States.WaitingForAuth:
         m_headerstream.Write(buf, offset, length);
         int state = 0;
         int line = 0;
         foreach (byte b in buf)
         {
             // Look for \r\n\r\n for end of response header
             switch (state)
             {
             case 0:
                 if (b == '\r')
                     state++;
                 break;
             case 1:
                 if (b == '\n')
                 {
                     byte[] hs = m_headerstream.ToArray();
                     string s = System.Text.Encoding.UTF8.GetString(hs);
                     Debug.Write("PRECV: " + s);
                     m_headers.Add(s);
                     m_headerstream.SetLength(0);
                     state++;
                     line++;
                 }
                 else
                     state = 0;
                 break;
             case 2:
                 if (b == '\r')
                     state++;
                 else
                     state = 0;
                 break;
             case 3:
                 if (b == '\n')
                 {
                     Debug.WriteLine("End of proxy headers");
                     string line0 = (string)m_headers[0];
                     if (line0.IndexOf("200") == -1)
                     {
                         Debug.WriteLine("200 response not detected.  Closing.");
                         m_state = States.Error;
                         this.Close();
                     }
                     else
                     {
                         Debug.WriteLine("Proxy connected");
                         m_listener.OnConnect(sock); // tell the real listener that we're connected.
                         m_state = States.Running;
                     }
                     // they'll call RequestRead(), so we can return false here.
                     return false;
                 }
                 else
                     state = 0;
                 break;
             }
         }
         return true;
     case States.Error:
         throw new InvalidOperationException("Cannot read after error");
     default:
         return base.OnRead(sock, buf, offset, length);
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Overridden OnWrite to ensure that the base only gets called when in running state.
 /// </summary>
 /// <param name="sock"></param>
 /// <param name="buf"></param>
 /// <param name="offset"></param>
 /// <param name="length"></param>
 public override void OnWrite(Bedrock.Net.BaseSocket sock, byte[] buf, int offset, int length)
 {
     if (m_state == States.Running)
     {
         base.OnWrite(sock, buf, offset, length);
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Remember that we're in the connecting state, let base connect to proxy, resumes in OnConnect.
 /// </summary>
 /// <param name="addr"></param>
 public override void Connect(Bedrock.Net.Address addr)
 {
     m_state = States.Connecting;
     base.Connect(addr);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Overridden OnRead to handle 4 Socks5 states...
 /// </summary>
 /// <param name="sock"></param>
 /// <param name="buf"></param>
 /// <param name="offset"></param>
 /// <param name="length"></param>
 /// <returns></returns>
 public override bool OnRead(Bedrock.Net.BaseSocket sock, byte[] buf, int offset, int length)
 {
     switch (m_state)
     {
         case States.RequestingProxy:
             bool ret = HandleRequestResponse(buf[offset], buf[offset + 1]);
             if (ret)
             {
                 m_listener.OnConnect(sock); // tell the real listener that we're connected.
                 // they'll call RequestRead(), so we can return false here.
             }
             return false;
         default:
             return base.OnRead(sock, buf, offset, length);
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// overridden OnConnect to start off Socks5 protocol.
        /// </summary>
        /// <param name="sock"></param>
        public override void OnConnect(Bedrock.Net.BaseSocket sock)
        {
            if (m_state == States.Connecting)
            {
                IPHostEntry server = Dns.GetHostEntry(RemoteAddress.Hostname);
                IPAddress ip_addr = server.AddressList[0];

                byte[] addr = ip_addr.GetAddressBytes();

                int port = RemoteAddress.Port;
                byte [] buffer = new Byte[14];
                buffer[0] = 4;  // protocol version.
                buffer[1] = 1;  // connect.
                buffer[2] = (byte)(port >> 8);
                buffer[3] = (byte)port;
                // TODO: test byte order!
                buffer[4] = addr[3];
                buffer[5] = addr[2];
                buffer[6] = addr[1];
                buffer[7] = addr[0];
                buffer[8] = (byte)'i';
                buffer[9] = (byte)'d';
                buffer[10] = (byte)'e';
                buffer[11] = (byte)'n';
                buffer[12] = (byte)'t';
                buffer[13] = 0;

                /*
                +----+----+----+----+----+----+----+----+----+----+....+----+
                | VN | CD | DSTPORT |      DSTIP        | USERID       |NULL|
                +----+----+----+----+----+----+----+----+----+----+....+----+
    # of bytes:    1    1      2              4           variable       1
                */


                Write(buffer);
                RequestRead();
                m_state = States.RequestingProxy;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Connect to the jabberd, or wait for it to connect to us.
        /// Either way, this call returns immediately.
        /// </summary>
        /// <param name="address">The address to connect to.</param>
        public void Connect(Bedrock.Net.Address address)
        {
            this.NetworkHost = address.Hostname;
            this.Port = address.Port;

            Connect();
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Saves the address passed in, and really connects to m_host:m_port.
 /// </summary>
 /// <param name="addr"></param>
 public override void Connect(Bedrock.Net.Address addr)
 {
     m_remote_addr = addr; // save this till we are ready for it...
     Debug.Assert(m_host != null);
     Debug.Assert(m_port != 0);
     // connect to the proxy.
     Address proxy_addr = new Address(m_host, m_port);
     m_sock.Connect(proxy_addr, m_hostid);
     // we'll end up in OnConnected below.
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Prepare to start accepting inbound requests.  Call RequestAccept() to start the async process.
 /// </summary>
 /// <param name="addr">Address to listen on</param>
 /// <param name="backlog">The Maximum length of the queue of pending connections</param>
 public override void Accept(Bedrock.Net.Address addr, int backlog)
 {
     m_sock.Accept(addr, backlog);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// overridden OnConnect to start off Socks5 protocol.
 /// </summary>
 /// <param name="sock"></param>
 public override void OnConnect(Bedrock.Net.BaseSocket sock)
 {
     if (m_state == States.Connecting)
     {
         byte [] buffer = new Byte[4];
         buffer[0] = 5; // protocol version.
         buffer[1] = 2; // number of methods.
         buffer[2] = 0; // no auth.
         buffer[3] = 2; // username password.
         Debug.WriteLine("sending auth methods to proxy...");
         Write(buffer);
         RequestRead();
         m_state = States.GettingMethods;
     }
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Returns a new collection that contains all of the items that
 /// are in this list *and* the other set.
 /// </summary>
 /// <param name="other">
 /// Other set to intersect with.
 /// </param>
 /// <returns>Combined set.</returns>
 public Bedrock.Collections.ISet Intersection(Bedrock.Collections.ISet other)
 {
     throw new NotImplementedException();
 }