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; }
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; }
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; }
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; }