/// <summary> /// 验证登入 /// </summary> /// <param name="data"></param> /// <param name="e"></param> static void LogOnPack(byte[] data, SocketAsyncEventArgs e) { ReadBytesV2 read = new ReadBytesV2(data,Deflate.Decompress); int lengt; int cmd; if (read.ReadInt32(out lengt) &&lengt==read.Length && read.ReadInt32(out cmd)) { PackType cmdtype = (PackType)cmd; switch (cmdtype) { case PackType.LogOn: { LogOn logOn; if (read.ReadObject<LogOn>(out logOn)) { if (logOn.UserName.Equals(UserName, StringComparison.Ordinal) && logOn.PassWord.Equals(PassWord, StringComparison.Ordinal)) { LogOnRes res = new LogOnRes() { IsOk = true, Msg = "登入成功" }; UserManager userinfo = new UserManager() { Asyn = e, Stream = e.UserToken as ZYNetBufferReadStreamV2 }; e.UserToken = userinfo; server.SendData(e.AcceptSocket, BufferFormatV2.FormatFCA(res, Deflate.Compress)); } else { LogOnRes res = new LogOnRes() { IsOk = false, Msg = "用户名或密码错误" }; server.SendData(e.AcceptSocket, BufferFormatV2.FormatFCA(res, Deflate.Compress)); } } } break; } } }
/// <summary> /// 验证登入 /// </summary> /// <param name="data"></param> /// <param name="e"></param> void LogOnPack(byte[] data, SocketAsyncEventArgs e) { ReadBytesV2 read = new ReadBytesV2(data, Deflate.Decompress); int lengt; int cmd; if (read.ReadInt32(out lengt) && lengt == read.Length && read.ReadInt32(out cmd)) { PackType cmdtype = (PackType)cmd; switch (cmdtype) { case PackType.LogOn: { LogOn logOn; if (read.ReadObject<LogOn>(out logOn)) { User user; if ((user=UserList.Find(p=>p.UserName==logOn.UserName&&p.Password==p.Password))!=null) { LogOnRes res = new LogOnRes() { Path = user.Path, IsOk = true, Msg = "登入成功" }; UserManager userinfo = new UserManager() { Userinfo=user, UserName=user.UserName, Asyn = e, Stream = e.UserToken as ZYNetRingBufferPoolV2 }; e.UserToken = userinfo; server.SendData(e.AcceptSocket, BufferFormatV2.FormatFCA(res, Deflate.Compress)); AddLog(logOn.UserName + " 登入成功"); } else { LogOnRes res = new LogOnRes() { IsOk = false, Msg = "用户名或密码错误" }; server.SendData(e.AcceptSocket, BufferFormatV2.FormatFCA(res, Deflate.Compress)); } } } break; } } }