/// <summary> /// 登录成功 /// </summary> /// <param name="loginRecData"></param> /// <returns></returns> bool LoginSuccess(ByteArray loginRecData) { uint _local4 = Parse(loginRecData); if (_local4 != REC_SUCCESS) return false; ASObject ao = (ASObject)loginRecData.ReadObject(); ASObject login_ack = (ASObject)ao["login_ack"]; //result: // 13 需要验证码 int s = (int)login_ack["result"]; if (s == 13)//需要验证码 netParams.verifyUrl = login_ack["verify_url"].ToString(); if (s == LOGIN_SUCCESS) { uid = uint.Parse(login_ack["uid"].ToString());//uid return true; } return false; }
/////////////////////////////////////////////////以下无效////////////// /// <summary> /// 变换频道 /// </summary> /// <param name="topsid"></param> /// <param name="subsid"></param> bool ChangeChannel(uint topsid, uint subsid) { if (!isLogined)//未登录 return false; channelVerifyUrl = null; string changelVerify = null; if (IsChanneled) return true; changeChannelOk = false; //伺服对象 if (Common.ServoUser.myname == myname) { while (true) { //是否需要验证码 if (!string.IsNullOrEmpty(channelVerifyUrl)) { Common.verForm.VerUrl = channelVerifyUrl; changelVerify = Common.verForm.VerCode; channelVerifyUrl = null; //清空验证码地址 } //进入频道 ChangeChannel(topsid, subsid, changelVerify); changelVerify = null;//清空验证码 //等待消息循环线程完成 while (changeChannelAndMsgLoopFlag) Thread.Sleep(30); //将互斥标志清空 lock (changeChannelAndMsgLoop) { changeChannelAndMsgLoopFlag = true; } if (changeChannelOk) return true; } } else { while (true) { //需要数据 noNeedData = false; //是否需要验证码 if (!string.IsNullOrEmpty(channelVerifyUrl)) { Common.verForm.VerUrl = channelVerifyUrl; changelVerify = Common.verForm.VerCode; channelVerifyUrl = null; //清空验证码地址 } //进入频道 ChangeChannel(topsid, subsid, changelVerify); changelVerify = null;//清空验证码 //处理是否有返回验证码地址 byte[] cmdBuff = new byte[1024]; int i = 0; while (i < 10) { i++; int N = socket.Receive(cmdBuff); if (N <= 0) return true; MemoryStream ms = new MemoryStream(cmdBuff, 0, N); ByteArray m_recvBuff = new ByteArray(ms); uint _local4 = Parse(m_recvBuff); if (_local4 != REC_SUCCESS)//网络数据未判断是否完整接收,进频道错误,就有可能是这里的问题。 continue; ASObject ao = (ASObject)m_recvBuff.ReadObject(); uint uriv = uint.Parse(ao["uri"].ToString()); if (uriv == 356)//需要验证码 { ao = (ASObject)ao["change_topsid_ack"]; channelVerifyUrl = ao["verify_url"].ToString(); changeChannelOk = false; break; } else if (uriv == 18)//进入成功 { ASObject join_session_ack = (ASObject)ao["join_session_ack"]; //未验证result channelVerifyUrl = null; changeChannelOk = true; break; } } //不需要验证码 if (string.IsNullOrEmpty(channelVerifyUrl)) { //不需要数据 noNeedData = true; return true; } } } }
/// <summary> /// exchangeKey请求数据包 /// </summary> byte[] ExchangeKeyReqData(ByteArray publicKeyRecData) { uint _local4 = Parse(publicKeyRecData); if(_local4!=REC_SUCCESS) return null;//接收数据异常 ASObject ao = (ASObject)publicKeyRecData.ReadObject(); ASObject aopka = (ASObject)ao["get_public_key_ack"]; ByteArray barsa_e = (ByteArray)aopka["rsa_e"]; byte[] rsa_ebuf = new byte[barsa_e.Length]; barsa_e.ReadBytes(rsa_ebuf, 0, barsa_e.Length); //string rsa_e = bytesValueToHexString(rsa_ebuf); ByteArray barsa_n = (ByteArray)aopka["rsa_n"]; byte[] rsa_nbuf = new byte[barsa_n.Length]; barsa_n.ReadBytes(rsa_nbuf, 0, barsa_n.Length); //string rs = System.Text.Encoding.Default.GetString(rsa_nbuf); //RSA //rsaParams RSAParameters rsaParams = new RSAParameters(); rsaParams.Exponent = rsa_ebuf;//E rsaParams.Modulus = rsa_nbuf;//N RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(); RSA.ImportParameters(rsaParams); //data byte[] rsabuf = RSA.Encrypt(mKey, false); byte[] data1={00,00,00,119,10,11,01,33,101,120,99,104,97,110,103,101,95,107,101,121,95,114,101,113,10,01,35,101,110,99,114,121,112,116,101,100,95,114,99,52,95,107,101,121,12,129,01}; byte[] data3={01,07,117,114,105,04,01,01}; byte[] data=new byte[119]; data1.CopyTo(data,0); rsabuf.CopyTo(data,data1.Length); data3.CopyTo(data,data1.Length+rsabuf.Length); return data; }
/// <summary> /// 接受网络数据(同频道一个user调用就可以) /// </summary> public void NetMsgLoop() { if (!isLogined)//未登录 return; //非伺对象不可循环 if (Common.ServoUser==null || Common.ServoUser.myname != myname) return; byte[] dataBuff = new byte[409600]; dataBuff.Initialize(); int indexBuff = 0; byte[] recvBuff = new byte[204800]; recvBuff.Initialize(); while (true) { while (!ReadTotal()) { //掉线 if (!isLogined) return; Thread.Sleep(50); } int n = socket.Receive(recvBuff); recvBuff.CopyTo(dataBuff, indexBuff); recvBuff.Initialize();//清空临时buff indexBuff += n; //数据异常时 if (indexBuff >= recvBuff.Length) { indexBuff = 0; dataBuff.Initialize(); continue; } MemoryStream ms = new MemoryStream(dataBuff, 0, indexBuff); ByteArray m_recvBuff = new ByteArray(ms); while (true) { uint _local4 = Parse(m_recvBuff); if (_local4 == REC_SUCCESS) { ASObject ao = (ASObject)m_recvBuff.ReadObject(); prossObject(ao); if (m_recvBuff.Position == m_recvBuff.Length)//数据刚好取完 { dataBuff.Initialize(); indexBuff = 0; Thread.Sleep(30); break; } } else { long noDataLength = m_recvBuff.Length - m_recvBuff.Position;//剩余数据长度 Array.Copy(dataBuff, m_recvBuff.Position, recvBuff, 0, noDataLength); dataBuff.Initialize(); recvBuff.CopyTo(dataBuff, 0); indexBuff = (int)noDataLength; break; } } } }