public async Task<long> AwaitUser(ChatUserInfo user)
 {
     Log.Info("Awaiting for " + user.Name);
     var ticket = _ticketCounter++;
     _awaitingUsers.Add(ticket, user);
     Fiber.Shedule(() => ExpireTicketAsync(ticket), TimeSpan.FromSeconds(10), LockType.Write);
     return ticket;
 }
Пример #2
0
 public static void Serialize(ChatUserInfo x, BinaryWriter w)
 {
     if (x == null)
     {
         w.Write(false);
         return;
     }
     w.Write(true);
     w.Write(x.Id);
     StringSerializer.Serialize(x.Name, w);
 }
Пример #3
0
        public async Task <Int64> AwaitUser(ChatUserInfo user)
        {
            var request = MessageFactory.New <IChatRoomAwaitUserRequest>();

            request.user = user;
            Message reply = await ExecuteOperation(request);

            var ret = ((IChatRoomAwaitUserReply)reply).RetVal;

            MessageFactory.Free(reply);
            return(ret);
        }
Пример #4
0
        public static ChatUserInfo Deserialize(BinaryReader r)
        {
            {
                bool isNotNull = r.ReadBoolean();
                if (!isNotNull)
                {
                    return(null);
                }
            }
            var ret = new ChatUserInfo();

            ret.Id   = r.ReadUInt32();
            ret.Name = StringSerializer.Deserialize(r);
            return(ret);
        }
        public async Task<ChatUserInfo> TryRegisterUser(string name)
        {
            if (_usersByName.ContainsKey(name))
                return null;

            uint id = _userCounter++;

            var user = new ChatUserInfo
            {
                Id = id,
                Name = name
            };

            _usersByName.Add(name, user);
            _usersById.Add(id, user);

            return user;
        }
        public async Task<LoginResult> Login(string name)
        {
            Log.Info(name + " is logging in");

            ActorProxy<IUserManager> chatManager = await Node.GetActor<IUserManager>();
            ChatUserInfo userInfo = await chatManager.Channel.TryRegisterUser(name);
            if (userInfo == null)
            {
                Log.Warn("name in use");
                return LoginResult.NameInUse;
            }

            _user = userInfo;

            SetHandler<IChatService>(this);
            RemoveHandler<IChatLogin>();

            Log = LogManager.GetLogger(string.Format("ChatClient<NetId:{0}, UserId:{1}, Name:{2}>", Channel.Id, userInfo.Id, userInfo.Name));
            Log.Info("login successfull");

            return LoginResult.Ok;
        }
		public static ChatUserInfo Deserialize(BinaryReader r)
		{
			{
				bool isNotNull = r.ReadBoolean();
				if(!isNotNull)
					return null;
			}
			var ret = new ChatUserInfo();
			ret.Id = r.ReadUInt32();
			ret.Name = StringSerializer.Deserialize(r);
			return ret;
		}
		public static void Serialize(ChatUserInfo x, BinaryWriter w)
		{
			if(x == null)
			{
				w.Write(false);
				return;
			}
			w.Write(true);
			w.Write(x.Id);
			StringSerializer.Serialize(x.Name, w);
		}
        public override void Deserialize(BinaryReader r)
        {
            base.Deserialize(r);
			user = ChatUserInfoSerializer.Deserialize(r);
        }
		public async Task< Int64 > AwaitUser ( ChatUserInfo user )
		{
			var request = MessageFactory.New< IChatRoomAwaitUserRequest >();
			request.user=user;
			Message reply = await ExecuteOperation(request);
			var ret = ((IChatRoomAwaitUserReply)reply).RetVal;
			MessageFactory.Free(reply);
			return ret;
		}
 public ChatRoomClient(INetPeer peer, ChatUserInfo info)
 {
     Peer = peer;
     Info = info;
 }
Пример #12
0
 public override void Deserialize(BinaryReader r)
 {
     base.Deserialize(r);
     user = ChatUserInfoSerializer.Deserialize(r);
 }