Пример #1
0
        void OnNewMessages(object state)
        {
            Message msg;

            while (m_connection.TryGetMessage(out msg))
            {
                InvokeMessageHandler((ClientMessage)msg);
            }

            m_onNewMessagesInvoked = false;

            while (m_connection.TryGetMessage(out msg))
            {
                InvokeMessageHandler((ClientMessage)msg);
            }

            if (m_connection.IsConnected == false)
            {
                trace.TraceInformation("OnDisconnect");

                m_world = null;

                m_state = ClientUserState.Disconnected;

                if (DisconnectEvent != null)
                {
                    DisconnectEvent();
                }

                DH.Dispose(ref m_connection);
            }
        }
Пример #2
0
        public Client(Socket client)
        {
            _socket = client;


            //
            // Create a new room for the new connecting client.
            //

            var roomManager = RoomManager.GetInstance();

            Room = roomManager.CreateNewRoom(this);


            //
            // Start the heartbeat timer.
            //

            _heartBeatTimer = new Timer(CheckHeartBeatTimer, null, 20000, TimerInterval);


            //
            // Set the client user state to default value.
            //

            _clientUserState = ClientUserState.InLobby;
        }
Пример #3
0
        void HandleMessage(LogOnReplyBeginMessage msg)
        {
            m_state = ClientUserState.ReceivingLoginData;

            this.PlayerID = msg.PlayerID;
            this.IsSeeAll = msg.IsSeeAll;
            // XXX move to game engine or such
            this.GameMode = msg.GameMode;
        }
Пример #4
0
        // XXX add cancellationtoken
        public async Task LogOn(string name, IProgress <string> prog)
        {
            if (m_state != ClientUserState.None)
            {
                throw new Exception();
            }

            m_state = ClientUserState.LoggingIn;

            prog.Report("Logging in");

            Send(new Messages.LogOnRequestMessage()
            {
                Name = name
            });

            prog.Report("Waiting for logon reply");

            bool ok = false;

            while (true)
            {
                var msg = await m_connection.GetMessageAsync();

                if (msg == null)
                {
                    break;
                }

                InvokeMessageHandler((ClientMessage)msg);

                if (msg is LogOnReplyEndMessage)
                {
                    ok = true;
                    break;
                }
            }

            if (m_connection.IsConnected == false)
            {
                throw new Exception("Disconnected");
            }

            if (!ok)
            {
                throw new Exception("No LogOnReplyEnd");
            }

            m_state = ClientUserState.LoggedIn;

            prog.Report("Logged in");
        }
Пример #5
0
		// XXX add cancellationtoken
		public async Task LogOn(string name, IProgress<string> prog)
		{
			if (m_state != ClientUserState.None)
				throw new Exception();

			m_state = ClientUserState.LoggingIn;

			prog.Report("Logging in");

			Send(new Messages.LogOnRequestMessage() { Name = name });

			prog.Report("Waiting for logon reply");

			bool ok = false;

			while (true)
			{
				var msg = await m_connection.GetMessageAsync();

				if (msg == null)
					break;

				InvokeMessageHandler((ClientMessage)msg);

				if (msg is LogOnReplyEndMessage)
				{
					ok = true;
					break;
				}
			}

			if (m_connection.IsConnected == false)
				throw new Exception("Disconnected");

			if (!ok)
				throw new Exception("No LogOnReplyEnd");

			m_state = ClientUserState.LoggedIn;

			prog.Report("Logged in");
		}
Пример #6
0
        public Client(Socket client)
        {
            _socket = client;

            //
            // Create a new room for the new connecting client.
            //

            var roomManager = RoomManager.GetInstance();
            Room = roomManager.CreateNewRoom(this);

            //
            // Start the heartbeat timer.
            //

            _heartBeatTimer = new Timer(CheckHeartBeatTimer, null, 20000, TimerInterval);

            //
            // Set the client user state to default value.
            //

            _clientUserState = ClientUserState.InLobby;
        }
Пример #7
0
 public void Read(System.IO.BinaryReader reader)
 {
     user.Read(reader);
     newUserState = (ClientUserState)reader.ReadByte();
 }
Пример #8
0
 public void Read(System.IO.BinaryReader reader)
 {
     user.Read(reader);
     newUserState = (ClientUserState)reader.ReadByte();
 }
Пример #9
0
		public ClientUser(IConnection connection)
		{
			m_state = ClientUserState.None;
			m_connection = connection;
		}
Пример #10
0
		void HandleMessage(LogOnReplyBeginMessage msg)
		{
			m_state = ClientUserState.ReceivingLoginData;

			this.PlayerID = msg.PlayerID;
			this.IsSeeAll = msg.IsSeeAll;
			// XXX move to game engine or such
			this.GameMode = msg.GameMode;
		}
Пример #11
0
		void OnNewMessages(object state)
		{
			Message msg;

			while (m_connection.TryGetMessage(out msg))
				InvokeMessageHandler((ClientMessage)msg);

			m_onNewMessagesInvoked = false;

			while (m_connection.TryGetMessage(out msg))
				InvokeMessageHandler((ClientMessage)msg);

			if (m_connection.IsConnected == false)
			{
				trace.TraceInformation("OnDisconnect");

				m_world = null;

				m_state = ClientUserState.Disconnected;

				if (DisconnectEvent != null)
					DisconnectEvent();

				DH.Dispose(ref m_connection);
			}
		}
Пример #12
0
 public ClientUser(IConnection connection)
 {
     m_state      = ClientUserState.None;
     m_connection = connection;
 }