コード例 #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
        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;
        }