public void ServerStart(IPAddress ip, int port) { Console.WriteLine("Server is running ... "); TcpListener listener = new TcpListener(ip, port); listener.Start();//开始侦听 Console.WriteLine("Start Listening ..."); clientManager = new ClientThreadManager(); //开启定时检测客户端状态函数,每分钟检测一次 ClientThreadManager.checkClientActive(1,ClientThreadManager.ClientOverTime); while (true) { // 获取一个连接,同步方法,在此处中断 TcpClient client = listener.AcceptTcpClient(); ClientInfo newClientInfo = new ClientInfo( client.Client.RemoteEndPoint.ToString(), DateTime.Now, client); ServerBase dealClient = new ServerBase(newClientInfo); //在此需要将客户端连接信息添加到clientList,动态监控整个服务器的连接状况 clientManager.AddClientConnect(newClientInfo); //clientManager.AddClientConnect( // new ClientInfo(client.Client.RemoteEndPoint.ToString(), // DateTime.Now,dealClient.permission,client,dealClient.clientThread)); Console.WriteLine("已连接客户端数目:" + ClientThreadManager.GetClientNumber());//测试 } }
/// <summary> /// 添加权限 /// </summary> /// <param name="dataStream"></param> /// <param name="in_message"></param> /// <param name="newClientInfo"></param> /// <returns></returns> public static Boolean AddPermission(NetworkStream dataStream, Message in_message, ClientInfo newClientInfo) { Message out_message = new Message(); //登陆确认命令 out_message.Command = Message.CommandHeader.AddPermission; //从输入信息中获取用户名、密码 string name = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[0]; string projectid = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[1]; int permissionlevel = Convert.ToInt32(Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[2]); //用户名密码校验 Boolean isUserExisted = UserBussinessManager.UserExisted(name); if (!isUserExisted)//消息体需要根据数据库检索结果//同时初始化permission {//用户不存在 Console.WriteLine("添加权限:User doesn't existed!"); out_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_NOTEXISTED); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return false; } else { Boolean isPermissionExisted = PermissionExisted(name, projectid, permissionlevel); if (isPermissionExisted) {//权限已经存在 out_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_EXISTED); Console.WriteLine("添加权限:权限已经存在!"); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return false; } else { Console.WriteLine("添加权限:准备添加权限"); if (Database.insertPermission(name, projectid, permissionlevel)) { out_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_SUCCEED); Console.WriteLine("添加权限:" + name + " " + projectid + " " + permissionlevel.ToString() + "权限添加成功!"); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return true; } return false; } } }
/// <summary> /// 删除工程 /// </summary> /// <param name="dataStream"></param> /// <param name="in_message"></param> /// <param name="newClientInfo"></param> /// <returns></returns> public static Boolean deleteProject(NetworkStream dataStream, Message in_message, ClientInfo newClientInfo) { Message out_message = new Message(); //登陆删除命令 out_message.Command = Message.CommandHeader.DeleteProject; Console.WriteLine("执行删除工程aaaa"); //从输入信息中获取工程名和项目名 string UserName = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[0]; string ProjectID = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[1]; string ProgramID = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[2]; Console.WriteLine("dadfadfada" + UserName + ProjectID + ProgramID); //权限检测 if (true) { } else { } //工程是否存在 Boolean isProjectExisted = ProjectExisted(ProjectID, ProgramID); Console.WriteLine(isProjectExisted); if (isProjectExisted == false)//消息体需要根据数据库检索结果 {//用户不存在 out_message.MessageBody = Encoding.Unicode.GetBytes("false"); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return false; } else { //工程存在 if ((Database.deleteProject(UserName, ProjectID, ProgramID))) { out_message.MessageBody = Encoding.Unicode.GetBytes("succeed"); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return true; } } return false; }
/// <summary> /// 管理客户端添加工程 /// </summary> /// <param name="dataStream"></param> /// <param name="in_message"></param> /// <param name="newClientInfo"></param> /// <returns></returns> public static Boolean AddProject(NetworkStream dataStream, Message in_message, ClientInfo newClientInfo) { Message out_message = new Message(); //登陆确认命令 out_message.Command = Message.CommandHeader.AddProject; //从输入信息中获取用ProjectID,ProgramID,ProjectDescription,ProjectType string ProjectID = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[0]; string ProgramID = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[1]; string ProjectDescription = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[2]; //int ProjectType = Int32.Parse(Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[3]); string ProjectType = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[3]; //工程校验 Boolean isProjectExisted = ProjectExisted(ProjectID, ProgramID); if (!isProjectExisted)//消息体需要根据数据库检索结果 {//验证通过 Database.insertSolutionProject(ProgramID, ProjectID, ProjectDescription, ProjectType); out_message.MessageBody = Encoding.Unicode.GetBytes("succeed"); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return true; } else { //验证未通过 Console.WriteLine("project has existed!"); out_message.MessageBody = Encoding.Unicode.GetBytes("existed"); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return false; } }
/// <summary> /// 管理客户端添加用户 /// </summary> /// <param name="dataStream"></param> /// <param name="in_message"></param> /// <param name="newClientInfo"></param> /// <returns></returns> public static Boolean AddUser(NetworkStream dataStream, Message in_message, ClientInfo newClientInfo) { Message out_message = new Message(); //登陆确认命令 out_message.Command = Message.CommandHeader.AddUser; //从输入信息中获取用户名、密码 string name = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[0]; string passwd = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[1]; //int groupid = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[2]; int groupid = Int32.Parse(Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[2]); //用户名密码校验 Boolean isUserExisted = UserExisted(name); if (!isUserExisted)//消息体需要根据数据库检索结果//同时初始化permission {//验证通过 Database.insertUser(name, passwd, groupid); out_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_SUCCEED); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return true; } else { //验证未通过 Console.WriteLine("User has existed!"); out_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_EXISTED); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return false; } }
public static Boolean PushXML(NetworkStream dataStream, Message in_message, ClientInfo newClientInfo) { Console.Write("Start pushing XML from "); string fileName = string.Empty; Message out_message = new Message(); //推送命令 out_message.Command = Message.CommandHeader.PushXML; //从输入信息中获取源、目的工程id以及项目id string sourceprjid = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[0]; string destinationprjid = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[1]; string solutionname = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[2]; Console.WriteLine(sourceprjid + " to " + destinationprjid); List<ProjectInfo> solutions = Database.querySolution(solutionname); //检测项目是否存在 if (solutions == null) { out_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_NOTEXISTED); Console.WriteLine("Solution not existed!"); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return false; } else //项目存在 { string solutionProjectDirectory = solutionname + "\\" + sourceprjid; //获取源工具数据 //找一个xml描述文件,暂定为GetFiles函数的第一个文件,有待于数据库协作判断,待加 //foreach (var file in Directory.GetFiles(solutionProjectDirectory)) //{ //} // fileName = Directory.GetFiles(solutionProjectDirectory).First(); fileName = Directory.GetFiles(solutionProjectDirectory).Last(); if (fileName == null) { return false; } Console.WriteLine("File found:" + fileName); //打开本地文件,读取内容,分行写到message中,连续发送 //第一个数据包消息体:文件名 //最后一个数据包消息体:# try { ClientInfo destinationclient = ClientThreadManager.GetClient(destinationprjid); if (destinationclient == null) //检测目标客户端是否在线 { out_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_OFFLINE); Console.WriteLine("Destination client is offline!"); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return false; } else { Console.WriteLine("Destination client is online! Ready to push......"); NetworkStream pushdataStream = destinationclient.client.GetStream(); Message push_message; using (StreamReader sr = new StreamReader(fileName, Encoding.Default)) { //传送文件开始的第一个数据包 push_message = new Message(); push_message.MessageBody = Encoding.Unicode.GetBytes(solutionname + ":" + destinationprjid);//项目名+工程名 push_message.Command = Message.CommandHeader.PushXML; push_message.MessageFlag = Message.MessageFlagHeader.FileBegin; pushdataStream.Write(push_message.ToBytes(), 0, push_message.MessageLength); //下面传送文件内容 string line = string.Empty; int packetNum = 1; while ((line = sr.ReadLine()) != null) { push_message = new Message(); push_message.MessageBody = Encoding.Unicode.GetBytes(line); push_message.Command = Message.CommandHeader.PushXML; push_message.FilePacketNumber = packetNum++;//数据包添加序号 push_message.MessageFlag = Message.MessageFlagHeader.FileMiddle; pushdataStream.Write(push_message.ToBytes(), 0, push_message.MessageLength); } //文件读取结束 push_message = new Message(); push_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_SHARP);//该消息体最终被舍弃 push_message.Command = Message.CommandHeader.PushXML; push_message.MessageFlag = Message.MessageFlagHeader.FileEnd; pushdataStream.Write(push_message.ToBytes(), 0, push_message.MessageLength); Console.WriteLine("Sending......Waiting for callback......"); } out_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_WAITING); //发送成功,但是尚未接到客户端回馈,将消息送回调度者 //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); //读取客户端反馈,以判断客户端是否正确接收文件 // Message push_back_message = Message.Parse(pushdataStream); //if (push_back_message.Command == Message.CommandHeader.PushXMLAck) // if (Encoding.Unicode.GetString(push_back_message.MessageBody).CompareTo("yes") == 0) // { // Console.WriteLine("Pushing successfully!"); // out_message.MessageBody = Encoding.Unicode.GetBytes("succeed"); //发送成功,将消息送回调度者 // //打包输出信息,将输出信息写入输出流 // dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); // return true; // } // else // { // out_message.MessageBody = Encoding.Unicode.GetBytes("fail"); // //打包输出信息,将输出信息写入输出流 // dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); // Console.WriteLine("Pushing failed!"); // return false; // } } } catch (Exception ex) { Console.WriteLine("PushXML: " + ex.Message); } return false; } }
//更新推送 public static void ReminderPush(ClientInfo clientInfo, String message) { try { NetworkStream dataStream = clientInfo.client.GetStream(); Message push_message = new Message(); //生成推送消息 push_message.Command = Message.CommandHeader.ReminderAutoPush; push_message.MessageBody = Encoding.Unicode.GetBytes(message); //推送 dataStream.Write(push_message.ToBytes(), 0, push_message.MessageLength); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void PushXMLAck(NetworkStream dataStream, Message in_message, ClientInfo newClientInfo) { ClientInfo adminclient = ClientThreadManager.GetClient("ADMIN"); if (adminclient == null) { if (in_message.Command == Message.CommandHeader.PushXMLAck) if (Encoding.Unicode.GetString(in_message.MessageBody).CompareTo(Constants.M_YES) == 0) { Console.WriteLine("Pushing successfully!"); } else { Console.WriteLine("Pushing failed!"); } } else { NetworkStream pushackStream = adminclient.client.GetStream(); Message out_message = new Message(); out_message.Command = Message.CommandHeader.PushXMLAck; if (in_message.Command == Message.CommandHeader.PushXMLAck) if (Encoding.Unicode.GetString(in_message.MessageBody).CompareTo(Constants.M_YES) == 0) { Console.WriteLine("Pushing successfully!"); out_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_SUCCEED); //发送成功,将消息送回调度者 //打包输出信息,将输出信息写入输出流 pushackStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); } else { out_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_FAIL); //打包输出信息,将输出信息写入输出流 pushackStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); Console.WriteLine("Pushing failed!"); } } }
/// <summary> /// 搜索工程信息 /// </summary> /// <param name="dataStream"></param> /// <param name="in_message">工程与项目名称</param> /// <param name="newClientInfo"></param> /// <returns></returns> public static Boolean SearchProject(NetworkStream dataStream, Message in_message, ClientInfo newClientInfo) { Message out_message = new Message(); //登陆确认命令 out_message.Command = Message.CommandHeader.SearchProject; //从输入信息中获取工程名和项目名 string ProjectID = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[0]; string ProgramID = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[1]; //工程是否存在 Boolean isProjectExisted = ProjectExisted(ProjectID, ProgramID); if (isProjectExisted == false)//消息体需要根据数据库检索结果//同时初始化permission {//用户不存在 out_message.MessageBody = Encoding.Unicode.GetBytes("notexisted"); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return false; } else { //工程存在 Projectinfo tempproject = Database.queryProjectInfo(ProjectID, ProgramID); if (tempproject == null) { out_message.MessageBody = Encoding.Unicode.GetBytes("null" + ":" + "null" + ":" + "null" + ":" + "-100"); return false; } out_message.MessageBody = Encoding.Unicode.GetBytes(tempproject.projectID + ":" + tempproject.programID + ":" + tempproject.projectDescription + ":" + tempproject.projectType.ToString()); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return true; } }
public static Boolean SearchPermission(NetworkStream dataStream, Message in_message, ClientInfo newClientInfo) { Message out_message = new Message(); //登陆确认命令 out_message.Command = Message.CommandHeader.SearchPermission; //从输入信息中获取用户名 string name = Encoding.Unicode.GetString(in_message.MessageBody); //用户名是否存在 Boolean isUserExisted = UserBussinessManager.UserExisted(name); if (!isUserExisted)//消息体需要根据数据库检索结果//同时初始化permission {//用户不存在 out_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_NOTEXISTED); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return false; } else { //用户存在 List<Permission> permissions = Database.queryPermission(name); if (permissions == null) { out_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_NOTEXISTED); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return false; } else { int permissionnum = permissions.Count; string code = permissionnum.ToString(); foreach (Permission p in permissions) { code += ":" + p.projectName + ":" + p.permissionlevel.ToString(); } out_message.MessageBody = Encoding.Unicode.GetBytes(code); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return true; } } }
/// <summary> /// 用户名密码认证,权限分配读取 /// </summary> /// <param name="dataStream"></param> /// <param name="in_message"></param> /// <param name="newClientInfo"></param> /// <returns></returns> public static Boolean Authenticate(NetworkStream dataStream,Message in_message,ClientInfo newClientInfo) { Message out_message = new Message(); //登陆确认命令 out_message.Command = Message.CommandHeader.LoginAck; //从输入信息中获取用户名、密码、工具类型、工程id string name = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[0]; string passwd = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[1]; string tooltype = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[2]; string prjid = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[3]; //先进行用户名密码校验 Boolean isAuthSucceed = UserBussinessManager.CheckUser(name, passwd); if (isAuthSucceed)//消息体需要根据数据库检索结果//同时初始化permission {//验证通过 //初始化ClientInfo中name、passwd相应属性 newClientInfo.name = name; newClientInfo.passwd = passwd; newClientInfo.projectid = prjid; //工程id为空,说明工具刚启动,则校验是否用户是否有访问该工具的权限 if (prjid.Equals(string.Empty)) { newClientInfo.permissionList = Database.queryPermissionbyPrjtype(name, tooltype); } else { //初始化ClientInfo中permission相应属性 //newClientInfo.permissionList = Database.queryPermission(name); newClientInfo.permissionList = Database.queryPermissionbyPrjID(name, prjid); } if (newClientInfo.permissionList != null) { Console.WriteLine("权限存在"); string allowSolutionsAndProjects = "allow"; out_message.MessageBody = Encoding.Unicode.GetBytes(allowSolutionsAndProjects); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); //确认之后发一个含有服务器所有项目工程名称的xml描述文件 //xml描述文件由服务器动态生成 /*String mess_xml = GenerateXml(); if (mess_xml.CompareTo("") != 0) { out_message.MessageBody = Encoding.Unicode.GetBytes(mess_xml); dataStream.Write(out_message.ToBytes(),0,out_message.MessageLength); return true; //非空 } else { out_message.MessageBody = Encoding.Unicode.GetBytes("无工程信息"); dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return false; //空文件 }*/ /* * 注释(bhs) */ //阻塞读取数据,等待客户端反馈信息 while (!dataStream.CanRead) { Thread.Sleep(5);//5ms } while (!dataStream.DataAvailable) { Thread.Sleep(5);//5ms } in_message = Message.Parse(dataStream); string s = Encoding.Unicode.GetString(in_message.MessageBody); byte[] b = new byte[45]; //客户端发送ready信息,则向客户端传送服务器的项目列表xml文件 if (s.CompareTo("ready") == 0) { //ClientBusinessManager.SendSolutionProjectListXml(dataStream); return true; } else return false; } else { Console.WriteLine("权限为空"); string allowSolutionsAndProjects = "deny"; out_message.MessageBody = Encoding.Unicode.GetBytes(allowSolutionsAndProjects); Console.WriteLine(Encoding.Unicode.GetString(out_message.MessageBody)); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return false; } } else { //验证未通过 Console.WriteLine("验证未通过"); out_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_DENY_PW); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return false; } }
/// <summary> /// 搜索项目下全部信息 /// </summary> /// <param name="dataStream"></param> /// <param name="in_message"></param> /// <param name="newClientInfo"></param> /// <returns></returns> public static Boolean SearchSolution(NetworkStream dataStream, Message in_message, ClientInfo newClientInfo) { Message out_message = new Message(); //登陆确认命令 out_message.Command = Message.CommandHeader.SearchSolution; //从输入信息中获取项目名称 string name = Encoding.Unicode.GetString(in_message.MessageBody); //用户名是否存在 Boolean isSolutionExisted = true;// UserExisted(name); if (!isSolutionExisted)//消息体需要根据数据库检索结果//同时初始化permission {//用户不存在 out_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_NOTEXISTED); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return false; } else { //用户存在 List<ProjectInfo> solutions = Database.querySolution(name); if (solutions == null) { out_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_NOTEXISTED); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return false; } else { int projectnum = solutions.Count; string code = projectnum.ToString(); List<string> activeclients = ClientThreadManager.GetActiveClients(); foreach (ProjectInfo p in solutions) { if(activeclients.Contains(p.ProjectID)) code += ":" + p.ProjectType + ":" + p.ProjectID.ToString()+":在线"; else code += ":" + p.ProjectType + ":" + p.ProjectID.ToString() + ":脱机"; } out_message.MessageBody = Encoding.Unicode.GetBytes(code); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return true; } } }
public void AddClientConnect(ClientInfo clientInfo) { lock (clientList) { clientList.Add(clientInfo.clientIPWithPort, clientInfo); } }
//负责向指定客户端推送信息 public static Boolean PushMessage(ClientInfo clientInfo , string message) { try { NetworkStream dataStream = clientInfo.client.GetStream(); Message push_message = new Message(); //生成推送消息 push_message.Command = Message.CommandHeader.Push; push_message.MessageBody = Encoding.Unicode.GetBytes(message); //推送 dataStream.Write(push_message.ToBytes(), 0, push_message.MessageLength); return true; } catch (Exception ex) { Console.WriteLine(ex.Message); return false; } }
/// <summary> /// 搜索用户信息 /// </summary> /// <param name="dataStream"></param> /// <param name="in_message"></param> /// <param name="newClientInfo"></param> /// <returns></returns> public static Boolean SearchUser(NetworkStream dataStream, Message in_message, ClientInfo newClientInfo) { Message out_message = new Message(); //登陆确认命令 out_message.Command = Message.CommandHeader.SearchUser; //从输入信息中获取用户名 string name = Encoding.Unicode.GetString(in_message.MessageBody); //用户名是否存在 Boolean isUserExisted = UserExisted(name); if (!isUserExisted)//消息体需要根据数据库检索结果//同时初始化permission {//用户不存在 out_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_NOTEXISTED); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return false; } else { //用户存在 User tempuser = Database.queryUser(name); out_message.MessageBody = Encoding.Unicode.GetBytes(tempuser.name + ":" + tempuser.passwd + ":" + tempuser.groupId.ToString()); //打包输出信息,将输出信息写入输出流 dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength); return true; } }
private NetworkStream dataStream; //数据流 #endregion Fields #region Constructors public ServerBase(ClientInfo newClientInfo) { this.clientInfo = newClientInfo; DealClientTransaction(newClientInfo.client); }