Пример #1
0
 public ClientV2()
 {
     _quit     = false;
     _listener = new EventBasedNetListener();
     _client   = new NetManager(_listener);
     _client.DisconnectTimeout = 60000;
     step = ConnectionStep.Disconnected;
 }
Пример #2
0
        //使用BackgroundWorker
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            ConnectionStep step = (ConnectionStep)e.Argument;

            switch (step)
            {
            case ConnectionStep.ConnectDatabase:
                FirstStep();
                break;

            default:
                break;
            }
        }
Пример #3
0
        private void btnDBConnNext_Click(object sender, EventArgs e)
        {
            steps = ConnectionStep.ConnectDatabase;

            backgroundWorker1.RunWorkerAsync(steps);
            this.btnDBConnNext.Enabled = false;
            this.progressBar1.Value    = 0;
            int i = 0;

            while (backgroundWorker1.IsBusy)
            {
                progressBar1.Increment(1);
                //if (progressBar1.Value > 98)
                //    progressBar1.Value = 0;
                Application.DoEvents();
            }
        }
Пример #4
0
        public void ProcessClientHello(IPEndPoint ip)
        {
            if (ClientConnectionStep == ConnectionStep.None)
            {
                ClientConnectionStep = ConnectionStep.Hello;
            }

            IP = ip;

            //using (var cc = new ConsoleCopy(Settings.LogFile))
            //{
            Console.WriteLine("Client Hello! IP: {0}", ip);
            //}

            //TODO
            Server.instance.SendServerHello(IP, ID, 3567);

            ClientConnectionStep = ConnectionStep.Playing;
        }
Пример #5
0
        public void connect(string host, int port)
        {
            if (step != ConnectionStep.Disconnected)
            {
                return;                                //One connection at a time
            }
            Console.WriteLine("Client connecting...");
            step++;
            _client.Start();
            _client.Connect(host, port, "FrozenPizza" /* text key or NetDataWriter */);
            //Disconnect handler
            _listener.PeerDisconnectedEvent += (peer, disconnectInfo) =>
            {
                step = ConnectionStep.Disconnected;

                Menu.OpenModal("Disconnected from server:" + disconnectInfo.Reason.ToString(), "Error");
                Engine.setState(GameState.Menu);
                GameMain.Reset();
            };
            _listener.NetworkReceiveEvent += (fromPeer, dataReader, deliveryMethod) => { ClientHandlerV2.Parse(fromPeer, dataReader, deliveryMethod); };
            run();
        }