Exemplo n.º 1
0
        public bool BanUsers(string clientIdStr, string addToBanlist = "1")
        {
            if (ServerContext == null)
            {
                return(false);
            }
            var idStrs = clientIdStr.Split(",");

            foreach (var idStr in idStrs)
            {
                var id = int.Parse(idStr);
                ServerContext.CloseAllSourceByClient(id);
            }
            if (addToBanlist.Trim() == "1")
            {
                lock (userLocker)
                {
                    //TODO QQQ 加入禁用列表 需要考虑线程安全
                    foreach (var idStr in idStrs)
                    {
                        ServerContext.ServerConfig.BoundConfig.UsersBanlist.Add(idStr);
                    }
                }
            }

            ServerContext.ServerConfig.SaveChanges(ServerContext.ServerConfigPath);
            //写入数据
            return(true);
        }
Exemplo n.º 2
0
        public bool CloseClient(string clientIdStr)
        {
            if (ServerContext == null)
            {
                return(false);
            }
            var idStrs = clientIdStr.Split(",");

            foreach (var idStr in idStrs)
            {
                var id = int.Parse(idStr);
                ServerContext.CloseAllSourceByClient(id);
            }

            return(true);
        }
Exemplo n.º 3
0
        public void RemoveUser(string userIndex, string userNames)
        {
            try
            {
                var arr         = userIndex.Split(',');
                var userNameArr = userNames.Split(',');
                //for (var i = arr.Length - 1; i > -1; i--)
                //{
                //    Dbop.Delete(int.Parse(arr[i]));
                //    Dbop.DeleteHash(userNameArr[i]);
                //}

                //删除用户绑定
                lock (userLocker)
                {
                    if (ServerContext.ServerConfig.BoundConfig.UserPortBounds.ContainsKey(userIndex))
                    {
                        ServerContext.ServerConfig.BoundConfig.UserPortBounds.Remove(userIndex);
                    }
                }
                //刷新绑定列表
                ServerContext.UpdatePortMap();
                ServerContext.ServerConfig.SaveChanges(ServerContext.ServerConfigPath);
                for (var i = arr.Length - 1; i > -1; i--)
                {
                    var userId  = int.Parse(arr[i]);
                    var userDto = Dbop.Get(userNameArr[i]).ToObject <UserDTO>();
                    Dbop.Delete(userId);//litedb不起作用
                    Dbop.DeleteHash(userNameArr[i]);
                    ServerContext.CloseAllSourceByClient(int.Parse(userDto.userId));
                }
            }
            catch (Exception ex)
            {
                throw new Exception("删除用户出错:" + ex.Message);
            }
        }