Exemple #1
0
        /// <summary>
        /// Begins an asynchronous join operation on the underlying <see cref="ChatProxy">ChatProxy</see>
        /// which will call the OnEndJoin() method on completion
        /// </summary>
        /// <param name="p">The <see cref="Common.Person">chatter</see> to try and join with</param>
        public bool Connect(string login_name)
        {
            bool connected = false;

            InstanceContext site = new InstanceContext(this);

            _client = new JetterCommServiceClient(site, "NetTcpBinding_IJetterCommService");
            CommPointInfo[] comm_point_info = _client.Join(login_name);

            if (comm_point_info == null || comm_point_info.Length == 0)
            {
                // Problems jointing
                Trace.WriteLine("!!!! Failed to connect/join to server.");
            }
            else
            {
                connected          = true;
                _player_login_name = login_name;

                // Print communication points
                Trace.WriteLine("\nCommunication points:");
                foreach (CommPointInfo info in comm_point_info)
                {
                    Trace.WriteLine(String.Format("   Point: {0}", info.name));
                }
            }

            ////////////////////////////////////////
            //InstanceContext site = new InstanceContext(this);
            //proxy = new ChatProxy(site);
            //IAsyncResult iar = proxy.BeginJoin(p, new AsyncCallback(OnEndJoin), null);

            return(connected);
        }
Exemple #2
0
        /// <summary>
        /// Get the player name and attempt to login to the server.
        /// </summary>
        /// <returns></returns>
        static bool PlayerLogin()
        {
            bool   login_okay        = false;
            bool   valid_player_name = false;
            string login_name        = "";

            bool done = false;

            while (!done && !valid_player_name)
            {
                Console.Write("Enter login name: ");
                login_name = Console.ReadLine();

                if (login_name.Length == 0)
                {
                    done = true;    // Take a zero length name to mean "don't attempt login".
                }
                else
                {
                    string error_message;
                    valid_player_name = ValidatePlayerLoginName(login_name, out error_message);
                    if (valid_player_name)
                    {
                        done = true;
                    }
                    else
                    {
                        Console.WriteLine("Invalid login name: {0}", error_message);
                    }
                }
            }

            if (valid_player_name)
            {
                ///////////////////////////////////////////////
                // Attempt to login ...
                JetterCommCallbackClient callback_client = new JetterCommCallbackClient();
                InstanceContext          site            = new InstanceContext(callback_client);
                _client = new JetterCommServiceClient(site, "NetTcpBinding_IJetterCommService");

                CommPointInfo[] comm_point_info = _client.Join(login_name);

                if (comm_point_info == null || comm_point_info.Length == 0)
                {
                    // Problems jointing
                    Console.WriteLine("!!!! Failed to connect/join to server.");
                }
                else
                {
                    _player_login_name = login_name;
                    login_okay         = true;

                    // Print communication points
                    Console.WriteLine("\nCommunication points:");
                    foreach (CommPointInfo info in comm_point_info)
                    {
                        Console.WriteLine("   Point: {0}", info.name);
                    }
                }
            }

            return(login_okay);
        }