Exemple #1
0
 private void loginCallback(IAsyncResult iar)
 {
     try
     {
         Socket sock      = (Socket)iar.AsyncState;
         int    nReadSize = sock.EndReceive(iar);
         Packet loginPkt  = new Packet(pkt);
         if (loginPkt.type == Packet.Type.SERVER_CONNECT) // 유효한 패킷인지 체크 해야함
         {
             loginPkt = new Packet(Packet.Type.PASSWORD,
                                   SHA1Util.SHA1HashStringForUTF8String(string.Concat(
                                                                            Server.password, new Packet(pkt.Take <byte>((int)pkt.Length).ToArray()).getString())));
             this.Send(loginPkt.encode());
             this.recv(new AsyncCallback(loginCallback)); // TODO 비밀번호 실패 처리 해야함
         }
         else if (pkt.Length > 0 && loginPkt.type == Packet.Type.SERVER_CONNECT_SUCCESS)
         {
             Server.status = true;
             Server.buffer_check_timer.Start();
             Server.cbSock.Blocking = false;
             this.recv(new AsyncCallback(recvCallback)); // TODO 비밀번호 실패 처리 해야함
         }
     }
     catch (SocketException se)
     {
         Console.WriteLine(se.ErrorCode.ToString());
         this.initSocket();
     }
 }
Exemple #2
0
 public static string SHA1HashStringForUTF8String(string s)
 {
     byte[] bytes = Encoding.UTF8.GetBytes(s);
     return(SHA1Util.HexStringFromBytes(SHA1.Create().ComputeHash(bytes)));
 }