public override void DoCommand() { byte[] content = Decode.DecodeFirstContendBtyes(bytes); LoginInfo myInfo = DataDo.Json2Object <LoginInfo>(content); string strContent = "SELECT * FROM counter where id=" + myInfo.id + " ;"; PersonalInfo user = SqlConn.Select(strContent); if (user != null) { if (user.password == myInfo.passWord) { Console.WriteLine("用户登陆成功"); Server.AddUser(myInfo.id, conn); conn.ID = myInfo.id; //客户端的id作为属性存起来了便于访问 user.status = (int)PersonStatus.OnLine; //在线 PersonalInfo.ChangeStatusInfo(int.Parse(conn.ID), "", (int)PersonStatus.OnLine); conn.SendBts(Incode.IncodeFirstCommand(type, DataDo.Object2Json(user))); } else { Console.WriteLine("密码错误"); //回客户端消息 } } else { Console.WriteLine("账号不存在"); //回客户端消息 } }
public override void DoCommand() { LoginInfo myInfo = DataDo.Json2Object <LoginInfo>(Decode.DecodeFirstContendBtyes(bytes)); string id = SqlConn.Insert(myInfo.userName, myInfo.passWord); // 添加到数据库 通过访问数据库获取自动分配的id Server.AddUser(id, conn); //添加到服务器连接字典里去 conn.ID = id; //客户端的id作为属性存起来了便于访问 //Console.WriteLine("获取id:" + id); string strContent = "SELECT * FROM counter where id=" + id + " ;"; PersonalInfo user = SqlConn.Select(strContent); if (user != null) { //Console.WriteLine("用户登陆成功"); user.status = (int)PersonStatus.OnLine;//在线(发送数据修改) PersonalInfo.ChangeStatusInfo(int.Parse(conn.ID), "", (int)PersonStatus.OnLine); conn.SendBts(Incode.IncodeFirstCommand(type, DataDo.Object2Json(user))); } }