Beispiel #1
0
 // 쓰레드 함수 구현
 void RunThread()
 {
     while (true)
     {
         // 처리
         byte[] recvBuf = client.recMessage(4);
         int    num     = BitConverter.ToInt32(recvBuf, 0);
         Task   task    = new Task();
         task.type = num;
         switch (num)
         {
         case 0:
             RecvPoint recvPoint = new RecvPoint();
             byte[]    recvBuf1  = client.recMessage(Marshal.SizeOf(typeof(RecvPoint)));
             task.type = BitConverter.ToInt32(recvBuf, 0);
             Serializer.Deserialize <RecvPoint>(recvBuf1, ref recvPoint);
             task.data = recvPoint;
             break;
         }
         TaskQueue.Enqueue(task);
     }
 }
    public int LoginCo()
    {
  
        OnMessage();
        OpenMessage();

        Message.text = "로그인 중입니다";
        Okay.SetActive(false);
        Cancel.SetActive(false);
        if (IDInputField.text == "" || PassInputField.text == "")
        {
            
            Message.text = "아이디와 비밀번호가 올바른지 확인해주십시오";
            return -1;
        }

        try
        {
            SendMemberInfo smInfo = new SendMemberInfo(2, Convert.ToInt32(IDInputField.text), Convert.ToInt32(PassInputField.text));
            byte[] sendBuf = Serializer.Serialize<SendMemberInfo>(smInfo);
            int sendLen = client.getSock().Send(sendBuf);
           
        }
        catch (FormatException e)
        {
            e.ToString();
            Message.text = "ID 와 Password형식은 int 형식이어야 합니다.";
            return -1;
        }

         byte[] recvBuf = client.recMessage(4);
        int num = BitConverter.ToInt32(recvBuf, 0);
        if (num != 2)
        {
            print("요청에 대한 잘못된 리턴값 반환");
            return -1;
        }
        RecvMemberInfo recvMem = new RecvMemberInfo();
        byte[] recvbuf1 = client.recMessage(Marshal.SizeOf(typeof(RecvMemberInfo)));
        Serializer.Deserialize<RecvMemberInfo>(recvbuf1, ref recvMem);
        if(recvMem.id ==Int32.MaxValue || recvMem.password == Int32.MaxValue)
        {
            Message.text = "ID와 비밀번호가 일치하는지 확인해 주십시오.";
            return -1;
        }
        if (recvMem.id == Int32.MinValue || recvMem.password == Int32.MinValue)
        {
            Message.text = "누군가가 접속하고 있습니다 .";
            return -1;
        }

        return 0;
      
    }