Esempio n. 1
0
        public bool ExecuteCommand(int roomId, int cmdId, int sourceUserId, int targetUserId)
        {
            UserNCallback sourceUesr = null;
            UserNCallback targetUser = null;

            if (userCache.ContainsKey(sourceUserId))
            {
                sourceUesr = userCache[sourceUserId];
            }
            if (userCache.ContainsKey(targetUserId))
            {
                targetUser = userCache[targetUserId];
            }
            if (sourceUesr == null)
            {
                LogOff(sourceUserId);
            }
            else if (targetUser == null)
            {
                LogOff(targetUserId);
            }
            else
            {
                if (cache.HasCommand(roomId, cmdId, sourceUserId, sourceUesr.UserInfo.Role_Id, targetUser.UserInfo.Role_Id))
                {
                    DoCommand(roomId, cmdId, sourceUesr, targetUserId);
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 2
0
        private void DoCommand(int roomId, int cmdId, UserNCallback sourceUser, int targetUserId)
        {
            var adminId = BuiltIns._9258Administrator.Id;

            switch (cmdId)
            {
            case Applications._9258App.UserCommands.AddToBlackListCommandId:
                dataServiceClient.AddBlockList(sourceUser.User.Id, sourceUser.DataServiceToken, new BlockList {
                    Application_Id = ApplicationId, BlockType_Id = BuiltIns.BlackListType.Id, Content = targetUserId.ToString()
                });
                break;

            case Applications._9258App.UserCommands.BlockUserIdCommandId:
                dataServiceClient.AddBlockList(sourceUser.User.Id, sourceUser.DataServiceToken, new BlockList {
                    Application_Id = ApplicationId, BlockType_Id = BuiltIns.BlockUserType.Id, Content = targetUserId.ToString()
                });
                break;

            case Applications._9258App.UserCommands.BlockUserIpCommandId:
                dataServiceClient.AddBlockList(sourceUser.User.Id, sourceUser.DataServiceToken, new BlockList {
                    Application_Id = ApplicationId, BlockType_Id = BuiltIns.BlockIPType.Id, Content = targetUserId.ToString()
                });
                break;

            case Applications._9258App.UserCommands.BlockUserMacCommandId:
                dataServiceClient.AddBlockList(sourceUser.User.Id, sourceUser.DataServiceToken, new BlockList {
                    Application_Id = ApplicationId, BlockType_Id = BuiltIns.BlockMacType.Id, Content = targetUserId.ToString()
                });
                break;

            case Applications._9258App.UserCommands.SetOrCancelRoomManagerCommandId:
                var rr = dataServiceClient.GetRoomRole(sourceUser.User.Id, sourceUser.DataServiceToken, roomId, targetUserId, BuiltIns._9258RoomAdministratorRole.Id);
                if (rr == null)
                {
                    rr = new RoomRole {
                        Room_Id = roomId, User_Id = targetUserId, Role_Id = BuiltIns._9258RoomAdministratorRole.Id
                    };
                    dataServiceClient.AddRoomRole(sourceUser.User.Id, sourceUser.DataServiceToken, rr);
                    cache.AddRoomRole(rr);
                }
                else
                {
                    dataServiceClient.DeleteRoomRole(sourceUser.User.Id, sourceUser.DataServiceToken, roomId, targetUserId, BuiltIns._9258RoomAdministratorRole.Id);
                    cache.RemoveRoomRole(roomId, BuiltIns._9258RoomAdministratorRole.Id, targetUserId);
                }
                break;

            case Applications._9258App.UserCommands.UpDownUserPrivateMicCommandId:
            case Applications._9258App.UserCommands.UpDownUserPublicMicCommandId:
            case Applications._9258App.UserCommands.BlockHornHallHornCommandId:
            case Applications._9258App.UserCommands.AllowConnectPrivateMicCommandId:
            case Applications._9258App.UserCommands.AllowConnectSecretMicCommandId:
            case Applications._9258App.UserCommands.KickOutOfRoomCommandId:
                break;
            }
        }
Esempio n. 3
0
 private void Dispose(bool disposing)
 {
     if (!disposed)
     {
         if (disposing)
         {
         }
         unc = null;
         rnc = null;
     }
 }
Esempio n. 4
0
        public User Login(int userId, string password, string macAddress)
        {
            string token = string.Empty;

            logger.Debug("Enter Login : UserId - " + userId);
            if (userId == BuiltIns._9258Administrator.Id)
            {
                if (Utility.GetMD5String(password) == BuiltIns._9258Administrator.Password)
                {
                    token = serviceToken;
                    logger.Debug("9258 Admin Login");
                }
                else
                {
                    logger.Debug("9258 Admin Login Failed");
                    return(null);
                }
            }
            if (string.IsNullOrEmpty(token) && userId != BuiltIns._9258Administrator.Id)
            {
                token = dataServiceClient.Login(userId, password);
                logger.Debug("Normal Login");
            }
            if (!string.IsNullOrEmpty(token))
            {
                logger.Debug("Normal Login Succeed");
                bool relogin = false;
                if (userCache.ContainsKey(userId))
                {
                    logger.Debug("Relogin");
                    relogin = true;
                    try
                    {
                        var u = userCache[userId];
                        userCache.Remove(userId);
                        userCache[userId].ServiceInstance.Dispose();
                        u.Callback.UserRelogin();
                    }
                    catch { }
                }
                OperationContext.Current.Channel.Faulted += Channel_Faulted;
                OperationContext.Current.Channel.Closing += Channel_Closing;
                User usr  = dataServiceClient.GetUser(userId, token, userId);
                var  info = dataServiceClient.GetUserInfo(BuiltIns._9258Administrator.Id, serviceToken, userId, ApplicationId);
                if (usr != null && info != null)
                {
                    logger.Debug("Normal Login Exit");
                    unc = new UserNCallback
                    {
                        User             = usr,
                        Callback         = OperationContext.Current.GetCallbackChannel <IChatServiceCallback>(),
                        PublicIpAddress  = GetClientRemoteEndPoint().Address,
                        MacAddress       = macAddress,
                        DataServiceToken = token,
                        UserInfo         = info,
                        CommandIds       = new SafeList <int>(),
                        ServiceInstance  = this
                    };
                    userCache.Add(userId, unc);

                    if (!relogin)
                    {
                        BroadCast(u => u.Callback.UserLoggedIn(unc.User), unc.User.Id);
                    }
                    return(usr);
                }
            }
            logger.Debug("Normal Login return Null");
            return(null);
        }
Esempio n. 5
0
 private void LogOff(UserNCallback usrNC)
 {
     userCache.Remove(unc.User.Id);
     BroadCast((u) => u.Callback.UserLoggedOff(u.User.Id), usrNC.User.Id);
     usrNC.ServiceInstance.Dispose();
 }
 private void LogOff(UserNCallback usrNC)
 {
     userCache.Remove(unc.User.Id);
     BroadCast((u) => u.Callback.UserLoggedOff(u.User.Id), usrNC.User.Id);
     usrNC.ServiceInstance.Dispose();
 }
		public User Login(int userId, string password, string macAddress)
		{
            string token = string.Empty;
            logger.Debug("Enter Login : UserId - " + userId);
            if (userId == BuiltIns._9258Administrator.Id)
            {
                if (Utility.GetMD5String(password) == BuiltIns._9258Administrator.Password)
                {
                    token = serviceToken;
                    logger.Debug("9258 Admin Login");
                }
                else
                {
                    logger.Debug("9258 Admin Login Failed");
                    return null;
                }
            }
            if (string.IsNullOrEmpty(token) && userId != BuiltIns._9258Administrator.Id)
            {
                token = dataServiceClient.Login(userId, password);
                logger.Debug("Normal Login");
            }
			if (!string.IsNullOrEmpty(token))
			{
                logger.Debug("Normal Login Succeed");
                bool relogin = false;
                if (userCache.ContainsKey(userId))
                {
                    logger.Debug("Relogin");
                    relogin = true;
                    try
                    {
                        var u = userCache[userId];
                        userCache.Remove(userId);
						userCache[userId].ServiceInstance.Dispose();
                        u.Callback.UserRelogin();                        
                    }
                    catch { }
                }
				OperationContext.Current.Channel.Faulted += Channel_Faulted;
				OperationContext.Current.Channel.Closing += Channel_Closing;
				User usr = dataServiceClient.GetUser(userId, token, userId);
				var info = dataServiceClient.GetUserInfo(BuiltIns._9258Administrator.Id, serviceToken, userId, ApplicationId);
                if (usr != null && info != null)
                {
                    logger.Debug("Normal Login Exit");
                    unc = new UserNCallback
                    {
                        User = usr,
                        Callback = OperationContext.Current.GetCallbackChannel<IChatServiceCallback>(),
                        PublicIpAddress = GetClientRemoteEndPoint().Address,
                        MacAddress = macAddress,
                        DataServiceToken = token,
                        UserInfo = info,
                        CommandIds = new SafeList<int>(),
                        ServiceInstance = this
                    };
                    userCache.Add(userId, unc);

                    if (!relogin)
                    {
                        BroadCast(u => u.Callback.UserLoggedIn(unc.User), unc.User.Id);
                    }
                    return usr;
                }
			}
            logger.Debug("Normal Login return Null");
			return null;
		}
		private void Dispose(bool disposing)
		{
			if (!disposed)
			{
				if (disposing)
				{
				}
                unc = null;
                rnc = null;
			}
		}
 private void DoCommand(int roomId, int cmdId, UserNCallback sourceUser, int targetUserId)
 {
     var adminId = BuiltIns._9258Administrator.Id;
     switch (cmdId)
     {
         case Applications._9258App.UserCommands.AddToBlackListCommandId:
             dataServiceClient.AddBlockList(sourceUser.User.Id, sourceUser.DataServiceToken, new BlockList { Application_Id = ApplicationId, BlockType_Id = BuiltIns.BlackListType.Id, Content = targetUserId.ToString() });
             break;
         case Applications._9258App.UserCommands.BlockUserIdCommandId:
             dataServiceClient.AddBlockList(sourceUser.User.Id, sourceUser.DataServiceToken, new BlockList { Application_Id = ApplicationId, BlockType_Id = BuiltIns.BlockUserType.Id, Content = targetUserId.ToString() });
             break;
         case Applications._9258App.UserCommands.BlockUserIpCommandId:
             dataServiceClient.AddBlockList(sourceUser.User.Id, sourceUser.DataServiceToken, new BlockList { Application_Id = ApplicationId, BlockType_Id = BuiltIns.BlockIPType.Id, Content = targetUserId.ToString() });
             break;
         case Applications._9258App.UserCommands.BlockUserMacCommandId:
             dataServiceClient.AddBlockList(sourceUser.User.Id, sourceUser.DataServiceToken, new BlockList { Application_Id = ApplicationId, BlockType_Id = BuiltIns.BlockMacType.Id, Content = targetUserId.ToString() });
             break;
         case Applications._9258App.UserCommands.SetOrCancelRoomManagerCommandId:
             var rr = dataServiceClient.GetRoomRole(sourceUser.User.Id, sourceUser.DataServiceToken, roomId, targetUserId, BuiltIns._9258RoomAdministratorRole.Id);
             if (rr == null)
             {
                 rr = new RoomRole { Room_Id = roomId, User_Id = targetUserId, Role_Id = BuiltIns._9258RoomAdministratorRole.Id };
                 dataServiceClient.AddRoomRole(sourceUser.User.Id, sourceUser.DataServiceToken,rr );
                 cache.AddRoomRole(rr);
             }
             else
             {
                 dataServiceClient.DeleteRoomRole(sourceUser.User.Id, sourceUser.DataServiceToken, roomId, targetUserId, BuiltIns._9258RoomAdministratorRole.Id);
                 cache.RemoveRoomRole(roomId, BuiltIns._9258RoomAdministratorRole.Id, targetUserId);
             }
             break;
         case Applications._9258App.UserCommands.UpDownUserPrivateMicCommandId:
         case Applications._9258App.UserCommands.UpDownUserPublicMicCommandId:
         case Applications._9258App.UserCommands.BlockHornHallHornCommandId:
         case Applications._9258App.UserCommands.AllowConnectPrivateMicCommandId:
         case Applications._9258App.UserCommands.AllowConnectSecretMicCommandId:
         case Applications._9258App.UserCommands.KickOutOfRoomCommandId:
             break;
     }
 }