예제 #1
0
        public override void Connect(IPAddress address, int port)
        {
            socket = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            try {
                socket.Connect(address, port);
            } catch (SocketException ex) {
                ErrorHandler.LogError("connecting to server", ex);
                game.Disconnect("Failed to connect to " + address + ":" + port,
                                "You failed to connect to the server. It's probably down!");
                Dispose();
                return;
            }

            reader = new NetReader(socket);
            writer = new NetWriter(socket);

            classic = new ClassicProtocol(game);
            classic.Init();
            cpe = new CPEProtocol(game);
            cpe.Init();
            cpeBlockDefs = new CPEProtocolBlockDefs(game);
            cpeBlockDefs.Init();
            wom = new WoMProtocol(game);
            wom.Init();

            Disconnected                  = false;
            receivedFirstPosition         = false;
            lastPacket                    = DateTime.UtcNow;
            game.WorldEvents.OnNewMap    += OnNewMap;
            game.UserEvents.BlockChanged += BlockChanged;

            classic.WriteLogin(game.Username, game.Mppass);
            SendPacket();
            lastPacket = DateTime.UtcNow;
        }
예제 #2
0
 internal void ReadDefinePartPacket( NetReader reader )
 {
     ushort partId = reader.ReadUInt16();
     byte type = reader.ReadUInt8();
     Vector3 min = ReadS16Vec3( reader );
     Vector3 max = ReadS16Vec3( reader );
 }
예제 #3
0
        public override void Connect( IPAddress address, int port )
        {
            socket = new Socket( address.AddressFamily, SocketType.Stream, ProtocolType.Tcp );
            try {
                socket.Connect( address, port );
            } catch( SocketException ex ) {
                ErrorHandler.LogError( "connecting to server", ex );
                game.Disconnect( "&eUnable to reach " + address + ":" + port,
                                "Unable to establish an underlying connection" );
                Dispose();
                return;
            }

            NetworkStream stream = new NetworkStream( socket, true );
            reader = new NetReader( stream );
            writer = new NetWriter( stream );
            gzippedMap = new FixedBufferStream( reader.buffer );

            Disconnected = false;
            receivedFirstPosition = false;
            lastPacket = DateTime.UtcNow;
            game.WorldEvents.OnNewMap += OnNewMap;

            MakeLoginPacket( game.Username, game.Mppass );
            SendPacket();
            lastPacket = DateTime.UtcNow;
        }
예제 #4
0
        public override void Connect(IPAddress address, int port)
        {
            socket = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            try {
                socket.Connect(address, port);
            } catch (SocketException ex) {
                ErrorHandler.LogError("connecting to server", ex);
                game.Disconnect("&eUnable to reach " + address + ":" + port,
                                "Unable to establish an underlying connection");
                Dispose();
                return;
            }

            NetworkStream stream = new NetworkStream(socket, true);

            reader     = new NetReader(stream);
            writer     = new NetWriter(stream);
            gzippedMap = new FixedBufferStream(reader.buffer);

            Disconnected                  = false;
            receivedFirstPosition         = false;
            lastPacket                    = DateTime.UtcNow;
            game.WorldEvents.OnNewMap    += OnNewMap;
            game.UserEvents.BlockChanged += BlockChanged;

            MakeLoginPacket(game.Username, game.Mppass);
            SendPacket();
            lastPacket = DateTime.UtcNow;
        }
예제 #5
0
 internal void ReadMetadataPacket( NetReader reader )
 {
     collisonSize = ReadS16Vec3( reader );
     pickingBounds.Min = ReadS16Vec3( reader );
     pickingBounds.Max = ReadS16Vec3( reader );
     nameYOffset = reader.ReadInt16() / 256f;
     eyeY = reader.ReadInt16() / 256f;
     bobbing = reader.ReadUInt8() != 0;
 }
예제 #6
0
        void FinishConnect()
        {
            connecting = false;
            game.WorldEvents.RaiseLoading(0);
            reader = new NetReader(socket);
            writer = new NetWriter(socket);

            classic      = new ClassicProtocol(game);
            cpe          = new CPEProtocol(game);
            cpeBlockDefs = new CPEProtocolBlockDefs(game);
            wom          = new WoMProtocol(game);
            ResetState();

            classic.WriteLogin(game.Username, game.Mppass);
            SendPacket();
            lastPacket = DateTime.UtcNow;
        }
예제 #7
0
 internal void ReadRotationPacket( NetReader reader )
 {
     ushort partId = reader.ReadUInt16();
     byte order = reader.ReadUInt8();
     RotateData rotX = ReadRotateData( reader );
     RotateData rotY = ReadRotateData( reader );
     RotateData rotZ = ReadRotateData( reader );
 }
예제 #8
0
 Vector3 ReadS16Vec3( NetReader reader )
 {
     return new Vector3( reader.ReadInt16() / 256f, reader.ReadInt16() / 256f,
                        reader.ReadInt16() / 256f );
 }
예제 #9
0
 RotateData ReadRotateData( NetReader reader )
 {
     RotateData data = default(RotateData);
     data.Origin = reader.ReadInt16() / 256f;
     data.Type = reader.ReadUInt8();
     data.VarA = reader.ReadInt16() / 512f;
     data.VarB = reader.ReadInt16() / 512f;
     return data;
 }
예제 #10
0
 internal void ReadSetupPacket( NetReader reader )
 {
 }