Example #1
0
        void Connect_Click(Button sender)
        {
            if (string.IsNullOrEmpty(userName))
            {
                SetInfo("Invalid user name.", true);
                return;
            }

            SetInfo("Connecting to the server...", false);

            GameNetworkClient client = new GameNetworkClient(true);

            client.ConnectionStatusChanged += Client_ConnectionStatusChanged;

            int    port     = 56565;
            string password = "";

            string error;

            if (!client.BeginConnect(connectToAddress, port, EngineVersionInformation.Version,
                                     userName, password, out error))
            {
                Log.Error(error);
                DisposeClient();
                return;
            }

            editBoxUserName.Enable    = false;
            editBoxConnectTo.Enable   = false;
            buttonCreateServer.Enable = false;
            buttonConnect.Enable      = false;
        }
        public void TryConnectToServer(string host, int port, string userName, string password)
        {
            GameNetworkClient client = new GameNetworkClient(true);

            client.ConnectionStatusChanged += Client_ConnectionStatusChanged;
            client.ChatService.ReceiveText += Client_ChatService_ReceiveText;
            client.CustomMessagesService.ReceiveMessage += Client_CustomMessagesService_ReceiveMessage;

            //add handlers for entity system service events
            client.EntitySystemService.WorldCreateBegin += Client_EntitySystemService_WorldCreateBegin;
            client.EntitySystemService.WorldCreateEnd   += Client_EntitySystemService_WorldCreateEnd;
            client.EntitySystemService.WorldDestroy     += Client_EntitySystemService_WorldDestroy;

            if (!client_SubscribedToMapLoadingEvents)
            {
                Map.Client_MapLoadingBegin         += Map_Client_MapLoadingBegin;
                Map.Client_MapLoadingEnd           += Map_Client_MapLoadingEnd;
                client_SubscribedToMapLoadingEvents = true;
            }

            string error;

            if (!client.BeginConnect(host, port, EngineVersionInformation.Version, userName, password,
                                     out error))
            {
                Log.Error(error);
                Client_DisconnectFromServer();
                return;
            }
        }
        void Connect()
        {
            if (GameNetworkClient.Instance != null)
            {
                Log("Error: Client already connected");
                return;
            }

            string loginName = textBoxUserName.Text.Trim();

            if (string.IsNullOrEmpty(loginName))
            {
                Log("Error: Empty login name");
                return;
            }

            GameNetworkClient client = new GameNetworkClient(false);

            client.ConnectionStatusChanged               += Client_ConnectionStatusChanged;
            client.UserManagementService.AddUserEvent    += UserManagementService_AddUserEvent;
            client.UserManagementService.RemoveUserEvent += UserManagementService_RemoveUserEvent;
            client.ChatService.ReceiveText               += ChatService_ReceiveText;

            string password = "";

            int port = 56565;

            string error;

            if (!client.BeginConnect(textBoxAddress.Text, port, EngineVersionInformation.Version,
                                     loginName, password, out error))
            {
                Log("Error: " + error);
                Disconnect();
                return;
            }

            buttonConnect.Enabled     = false;
            buttonDisconnect.Enabled  = true;
            textBoxUserName.ReadOnly  = true;
            textBoxAddress.ReadOnly   = true;
            textBoxEnterText.ReadOnly = true;
            buttonSend.Enabled        = true;

            Log("Trying to connect...");
        }
Example #4
0
        private void RunMap(object SelectedItem)
        {
            AKservers selectedserver = SelectedItem as AKservers;

            if (SelectedItem != null)
            {
                GameNetworkClient client = new GameNetworkClient(true);
                client.ConnectionStatusChanged += Client_ConnectionStatusChanged;
                string error;
                if (!client.BeginConnect(selectedserver.IP, selectedserver.Port, EngineVersionInformation.Version,
                                         Program.username, serverpassword, out error))
                {
                    Log.Error("Running Map Error: " + error);
                    DisposeClient();
                    return;
                }
            }
        }
Example #5
0
        protected override void OnAttach()
        {
            window = ControlDeclarationManager.Instance.CreateControl("Gui\\MPAKlobbyWindow.gui");
            Controls.Add(window);

            //positionY = maxout;

            listBox = (ListBox)window.Controls["Servers"];

            ((Button)window.Controls["Quit"]).Click += delegate(Button sender)
            {
                SetShouldDetach();// Back(true);
            };

            //positionY = maxout;

            ((Button)window.Controls["TechLab"]).Click += delegate(Button sender)
            {
                this.OnDetach();
                Controls.Add(new TechLabUnitBuyWindow());
            };

            ((Button)window.Controls["Refresh"]).Click += delegate(Button sender)
            {
                refreshlistbox();
            };

            ((Button)window.Controls["Customize"]).Click += delegate(Button sender)
            {
                this.OnDetach();
                Controls.Add(new TechLabUnitCustomizeWindow());
            };

            //Run button event handler
            ((Button)window.Controls["Run"]).Click += delegate(Button sender)
            {
                if (listBox.SelectedIndex != -1)
                {
                    RunMap(AKSERVERS[listBox.SelectedIndex]);
                }
            };

            createServerPort = window.Controls["Serverport"] as EditBox;
            if (createServerPort != null)
            {
                createServerPort.TextChange += delegate(Control sender)
                {
                    createServerPort.TextChange += createServerPort_TextChange;
                };
                createserverport = int.Parse(createServerPort.Text.Trim());
            }

            PassBox = window.Controls["passwordBox"] as PasswordBox;
            if (PassBox != null)
            {
                PassBox.TextChange += delegate(Control sender)
                {
                    PassBox.TextChange += PassBox_TextChange;
                    if (PassBox.Text.Length > 0)
                    {
                        clientpassword = PassBox.Text.Trim();
                        serverpassword = clientpassword;
                    }
                    else
                    {
                        clientpassword = serverpassword = "";
                    }
                };
            }

            CheckPrivate = window.Controls["chkserverPrivate"] as CheckBox;
            if (CheckPrivate != null)
            {
                CheckPrivate.CheckedChange += delegate(CheckBox sender)
                {
                    if (CheckPrivate.Checked == true)
                    {
                        privateserver = true;
                        SetInfo("Server set to private", false);
                    }
                    else
                    {
                        privateserver = false;
                    }
                };
            }

            EditBox IPtext = window.Controls["DirectConnectionTextBox"] as EditBox;

            ((Button)window.Controls["DirectIPCon"]).Click += delegate(Button sender)
            {
                GameNetworkClient client = new GameNetworkClient(true);
                client.ConnectionStatusChanged += Client_ConnectionStatusChanged;
                string error;
                if (!client.BeginConnect(IPtext.Text.ToString(), int.Parse(createserverport.ToString()), EngineVersionInformation.Version,
                                         Program.username, clientpassword, out error))
                {
                    Log.Error(error);
                    DisposeClient();
                    return;
                }
            };

            ((Button)window.Controls["singlePlayer"]).Click += delegate(Button sender)
            {
                GameEngineApp.Instance.SetNeedMapLoad("Maps\\MainDemo\\Map.map");
            };

            //TextBox ComWelN = window.Controls["ComWelNote"] as TextBox;
            //if (ComWelN != null)
            //{
            //    ComWelN.Text = "Welcome Commander " + MySqlGetUserName();
            //}

            buttonCreateServer        = (Button)window.Controls["CreateServer"];
            buttonCreateServer.Click += CreateServer_Click;

            //refreshlistbox();

            base.OnAttach();
        }