コード例 #1
0
        private async void testingame_click(object sender, EventArgs e)
        {
            MainButtonPress(mainButtons[1], e);             //press login
            await TaskFramework.Delay(500);

            if (!World.Instance.Client.ConnectedAndInitialized)
            {
                return;
            }
            loginUsernameTextbox.Text = "testuser";
            loginPasswordTextbox.Text = "testuser";

            MainButtonPress(loginButtons[0], e);             //login as acc testuser
            await TaskFramework.Delay(500);

            CharModButtonPress(loginCharButtons[0], e);             //login as char testuser
        }
コード例 #2
0
ファイル: Game.cs プロジェクト: Vulttwin/EndlessClient
        //--------------------------
        //***** HELPER METHODS *****
        //--------------------------
        private async Task TryConnectToServer(Action successAction)
        {
            //the mutex here should simulate the action of spamming the button.
            //no matter what, it will only do it one at a time: the mutex is only released when the bg thread ends
            if (connectMutex == null)
            {
                connectMutex = new AutoResetEvent(true);
                if (!connectMutex.WaitOne(0))
                {
                    return;
                }
            }
            else if (!connectMutex.WaitOne(0))
            {
                return;
            }

            if (World.Instance.Client.ConnectedAndInitialized && World.Instance.Client.Connected)
            {
                successAction();
                connectMutex.Set();
                return;
            }

            //execute this logic on a separate thread so the game doesn't lock up while it's trying to connect to the server
            await TaskFramework.Run(() =>
            {
                try
                {
                    if (World.Instance.Client.ConnectToServer(host, port))
                    {
                        m_packetAPI = new PacketAPI((EOClient)World.Instance.Client);

                        //set up event packet handling event bindings:
                        //	some events are triggered by the server regardless of action by the client
                        m_callbackManager = new PacketAPICallbackManager(m_packetAPI, this);
                        m_callbackManager.AssignCallbacks();

                        ((EOClient)World.Instance.Client).EventDisconnect += () => m_packetAPI.Disconnect();

                        InitData data;
                        if (m_packetAPI.Initialize(World.Instance.VersionMajor,
                                                   World.Instance.VersionMinor,
                                                   World.Instance.VersionClient,
                                                   Win32.GetHDDSerial(),
                                                   out data))
                        {
                            switch (data.ServerResponse)
                            {
                            case InitReply.INIT_OK:
                                ((EOClient)World.Instance.Client).SetInitData(data);

                                if (!m_packetAPI.ConfirmInit(data.emulti_e, data.emulti_d, data.clientID))
                                {
                                    throw new Exception();                                             //connection failed!
                                }

                                World.Instance.MainPlayer.SetPlayerID(data.clientID);
                                World.Instance.SetAPIHandle(m_packetAPI);
                                successAction();
                                break;

                            default:
                                string extra;
                                DATCONST1 msg = m_packetAPI.GetInitResponseMessage(out extra);
                                EODialog.Show(msg, extra);
                                break;
                            }
                        }
                        else
                        {
                            throw new Exception();                             //connection failed!
                        }
                    }
                    else
                    {
                        //show connection not found
                        throw new Exception();
                    }
                }
                catch
                {
                    if (!exiting)
                    {
                        EODialog.Show(DATCONST1.CONNECTION_SERVER_NOT_FOUND);
                    }
                }

                connectMutex.Set();
            });
        }