Exemplo n.º 1
0
 private void LaunchAuth(object sender, DoWorkEventArgs e)
 {
     if(Client.Properties.Settings.Default.FirstTimeLaunch == true) {
         Encryption encr = new Encryption();
         string encryptionKeys = encr.CreateKeyPair();
         char[] delimiterChars = { ':' };
         string[] encryptions = encryptionKeys.Split(delimiterChars);
         Properties.Settings.Default.PublicKey = encryptions[1];
         Properties.Settings.Default.PrivateKey = encryptions[0];
         MiscMethods misc = new MiscMethods();
         Properties.Settings.Default.ClientID = misc.GetMacAddress();
         Packet sendPacket = new Packet();
         string packet = sendPacket.encodePacket(Properties.Settings.Default.ClientID.ToString(), 0, -1, publicKey, false);
     }
     else
     {
         Packet sendPacket = new Packet();
         string response = "";
         if (response == "success")
          {
         status.Image = Client.Properties.Resources.online;
         connectionStatus.Text = "- Online";
         Online = true;
          }
          else
         {
         status.Image = Client.Properties.Resources.offline;
         connectionStatus.Text = "- Offline";
         Online = false;
         }
     }
 }
Exemplo n.º 2
0
 public void Send(Packet p)
 {
     byte[] buffer = p.Compile();
     if (p.Encode)
     {
         this.m_CryptoProvider.Encrypt(buffer, 0, buffer.Length);
     }
     this.m_Socket.Send(buffer, 0, buffer.Length, SocketFlags.None);
 }
Exemplo n.º 3
0
 public static bool Send(Packet p)
 {
     if ((m_Server == null) || (p == null))
     {
         return false;
     }
     byte[] buffer = p.Compile();
     if (OnSend != null)
     {
         OnSend(buffer.Length);
     }
     if (p.Encode)
     {
         m_CryptoProvider.Encrypt(buffer, 0, buffer.Length);
     }
     try
     {
         if (buffer.Length > (m_SendBuffer.Length - m_SendLength))
         {
             if (m_SendLength > 0)
             {
                 m_Server.Send(m_SendBuffer, 0, m_SendLength, SocketFlags.None);
             }
             m_SendLength = 0;
             if (buffer.Length >= m_SendBuffer.Length)
             {
                 m_Server.Send(buffer, 0, buffer.Length, SocketFlags.None);
             }
             else
             {
                 Buffer.BlockCopy(buffer, 0, m_SendBuffer, 0, buffer.Length);
                 m_SendLength += buffer.Length;
             }
         }
         else
         {
             Buffer.BlockCopy(buffer, 0, m_SendBuffer, m_SendLength, buffer.Length);
             m_SendLength += buffer.Length;
         }
         m_LastNetworkActivity.Reset();
     }
     catch (SocketException exception)
     {
         Debug.Trace("SocketException caught in Network.Send()");
         Debug.Trace("Error Code: 0x{0:X}", exception.ErrorCode);
         Debug.Trace("Native Error Code: 0x{0:X}", exception.NativeErrorCode);
         Debug.Error(exception);
         Gumps.MessageBoxOk("Connection lost", true, new OnClick(Engine.DestroyDialogShowAcctLogin_OnClick));
         Disconnect();
         Cursor.Hourglass = false;
         m_SoftDisconnect = false;
         Engine.amMoving = false;
         p.Dispose();
         return false;
     }
     p.Dispose();
     return true;
 }
Exemplo n.º 4
0
        //매칭된시간 알려주고 3초뒤에시작한다 . 
        //지금이 19분인데 19분 30초에 매칭시작 33초에 게임시작해 패킷을 보낸다음에 
        //데이터 전송
        public static void Send(string msg, object data)
        {
            try
            {
                if (_clientSocket.Connected)
                {
                    var setData = data;
                    Packet sample = new Packet
                    {
                        MsgName = msg,
                        Data = JsonConvert.SerializeObject(setData)
                    };

                   // Debug.Log();
                    var json = JsonConvert.SerializeObject(sample);
                    var sendData = Encoding.UTF8.GetBytes(json);
                    _clientSocket.BeginSend(sendData, 0, sendData.Length, SocketFlags.None, SendCallBack, _clientSocket);
                    
                }
                else
                {
                    //소켓이 연결되어있지않음
                }
            }
            catch (Exception e)
            {
                Debug.Log(e);
                Debug.Log("전송에러");
            }
        }
Exemplo n.º 5
0
        //수신콜백함수
        private static void ReceiveCallBack(IAsyncResult ar)
        {
            try
            {
                //var tempSocket = (Socket)ar.AsyncState;
               // int readSize = tempSocket.EndReceive(ar);//버퍼 사이즈 받아옴
               
                var receiveJson = new UTF8Encoding().GetString(_buffer);
                
                var receiveData = JsonConvert.DeserializeObject<Packet>(receiveJson);
                ReceiveMsg = receiveData.MsgName;
                Debug.Log("test : " + receiveData.Data);

                switch (ReceiveMsg)
                {
                    case "OnSucceedMatching":
                        PacketData = JsonConvert.DeserializeObject<MatchingPacket>(receiveData.Data);
                        break;
                    case "InGame":
                        break;
                }

                if (_serverSocket.Connected == true)
                {
                    Receive();
                }
                    
            }
            catch (SocketException e)
            {
                Debug.Log("Socket error : " + e);
                //데이저 수신 에러
            }
            catch (Exception e)
            {
                Debug.Log("exeption 에러 : "+e);
            }

            var matchingPakcet = new MatchingPacket("id","tribe",0,1);

            var packetwrapper = new Packet()
            {
                MsgName = "MatchingPacket",
                Data = JsonConvert.SerializeObject(matchingPakcet)
            };
        }
Exemplo n.º 6
0
 protected override byte[] BuildPacket(Packet packet)
 {
     return packet.Build();
 }