示例#1
0
 public void CallBroker(uint callId, string jsonData, int cmdId)
 {
     Logger.DEBUG(string.Empty);
     try
     {
         PendingRequest pendingRequest = new PendingRequest();
         pendingRequest.createTime = Utils.NowSeconds();
         pendingRequest.seqNo      = callId;
         Dictionary <string, object> dictionary = new Dictionary <string, object>();
         UserData userData = Pandora.Instance.GetUserData();
         dictionary.set_Item("seq_id", callId);
         dictionary.set_Item("cmd_id", cmdId);
         dictionary.set_Item("type", 1);
         dictionary.set_Item("from_ip", "10.0.0.108");
         dictionary.set_Item("process_id", 1);
         dictionary.set_Item("mod_id", 10);
         dictionary.set_Item("version", Pandora.Instance.GetSDKVersion());
         dictionary.set_Item("body", jsonData);
         dictionary.set_Item("app_id", userData.sAppId);
         string text   = Json.Serialize(dictionary);
         string text2  = MinizLib.Compress(text.get_Length(), text);
         byte[] array  = Convert.FromBase64String(text2);
         int    num    = IPAddress.HostToNetworkOrder(array.Length);
         byte[] bytes  = BitConverter.GetBytes(num);
         byte[] array2 = new byte[bytes.Length + array.Length];
         Array.Copy(bytes, 0, array2, 0, bytes.Length);
         Array.Copy(array, 0, array2, bytes.Length, array.Length);
         pendingRequest.data = array2;
         this.brokerPendingRequests.Enqueue(pendingRequest);
     }
     catch (Exception ex)
     {
         Logger.ERROR(ex.get_StackTrace());
     }
 }
示例#2
0
 public static string UnCompress(int encodedCompressedDataLen, string encodedCompressedData)
 {
     MinizLib.PandoraNet_RegisterMinizHandler(new MinizLib.MinizHandler(MinizLib.MinizCallback));
     if (MinizLib.PandoraNet_UnCompress(encodedCompressedDataLen, encodedCompressedData) == 0)
     {
         return(MinizLib.lastMinizData);
     }
     return(string.Empty);
 }
示例#3
0
 public static string Compress(int rawDataLen, string rawData)
 {
     MinizLib.PandoraNet_RegisterMinizHandler(new MinizLib.MinizHandler(MinizLib.MinizCallback));
     if (MinizLib.PandoraNet_Compress(rawDataLen, rawData) == 0)
     {
         return(MinizLib.lastMinizData);
     }
     return(string.Empty);
 }
示例#4
0
 public override void OnReceived(Packet thePacket)
 {
     Logger.DEBUG(string.Empty);
     try
     {
         string text    = Convert.ToBase64String(thePacket.theContent, 4, thePacket.theContent.Length - 4);
         string text2   = MinizLib.UnCompress(text.get_Length(), text);
         byte[] array   = Convert.FromBase64String(text2);
         string @string = Encoding.get_UTF8().GetString(array);
         Logger.DEBUG(@string);
         Message message = new Message();
         message.status  = 0;
         message.content = (Json.Deserialize(@string) as Dictionary <string, object>);
         message.action  = this.packetRecvdAction;
         Pandora.Instance.GetNetLogic().EnqueueResult(message);
     }
     catch (Exception ex)
     {
         Logger.ERROR(ex.get_StackTrace());
     }
 }
示例#5
0
 private void ParseActData()
 {
     try
     {
         string text    = Convert.ToBase64String(this.receivedByte, 4, this.receivedByte.Length - 4);
         string text2   = MinizLib.UnCompress(text.get_Length(), text);
         byte[] array   = Convert.FromBase64String(text2);
         string @string = Encoding.get_UTF8().GetString(array);
         Debug.Log(@string);
         Dictionary <string, object> dictionary = new Dictionary <string, object>();
         dictionary = (Json.Deserialize(@string) as Dictionary <string, object>);
         if (dictionary != null && dictionary.ContainsKey("body"))
         {
             string text3 = dictionary.get_Item("body") as string;
             Debug.Log(text3);
             Dictionary <string, object> dictionary2 = new Dictionary <string, object>();
             dictionary2 = (Json.Deserialize(text3) as Dictionary <string, object>);
             if (dictionary2 != null && dictionary2.ContainsKey("ret"))
             {
                 Debug.Log(string.Empty);
                 string text4 = dictionary2.get_Item("ret").ToString();
                 if (text4.Equals("0") && dictionary2.ContainsKey("resp"))
                 {
                     string text5 = dictionary2.get_Item("resp") as string;
                     Debug.Log(text5);
                     Dictionary <string, object> dictionary3 = new Dictionary <string, object>();
                     dictionary3 = (Json.Deserialize(text5) as Dictionary <string, object>);
                     if (dictionary3 != null && dictionary3.ContainsKey("body"))
                     {
                         string text6 = dictionary3.get_Item("body") as string;
                         Debug.Log(text6);
                         Dictionary <string, object> dictionary4 = new Dictionary <string, object>();
                         dictionary4 = (Json.Deserialize(text6) as Dictionary <string, object>);
                         if (dictionary4 != null && dictionary4.ContainsKey("online_msg_info"))
                         {
                             Dictionary <string, object> dictionary5 = dictionary4.get_Item("online_msg_info") as Dictionary <string, object>;
                             if (dictionary5 != null && dictionary5.ContainsKey("act_list"))
                             {
                                 List <object> list = dictionary5.get_Item("act_list") as List <object>;
                                 using (List <object> .Enumerator enumerator = list.GetEnumerator())
                                 {
                                     while (enumerator.MoveNext())
                                     {
                                         object current = enumerator.get_Current();
                                         Dictionary <string, object> dictionary6 = current as Dictionary <string, object>;
                                         if (dictionary6 != null && dictionary6.ContainsKey("jump_url") && !string.IsNullOrEmpty(dictionary6.get_Item("jump_url").ToString()))
                                         {
                                             Debug.Log("获取到Url: " + dictionary6.get_Item("jump_url").ToString());
                                             this.urlList.Add(dictionary6.get_Item("jump_url").ToString());
                                         }
                                     }
                                 }
                                 if (list.get_Count() > 0)
                                 {
                                     this.NotifyShowZone(true);
                                 }
                                 else
                                 {
                                     this.NotifyShowZone(false);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         this.NotifyShowZone(false);
         Debug.Log(ex.get_StackTrace());
     }
 }
示例#6
0
 private void AsynCallBroker(Socket socket, string message)
 {
     if (socket == null || message == string.Empty)
     {
         return;
     }
     Debug.Log(string.Empty);
     try
     {
         int num = 9000;
         Dictionary <string, object> dictionary = new Dictionary <string, object>();
         dictionary.set_Item("seq_id", 1);
         dictionary.set_Item("cmd_id", num);
         dictionary.set_Item("type", 1);
         dictionary.set_Item("from_ip", "10.0.0.108");
         dictionary.set_Item("process_id", 1);
         dictionary.set_Item("mod_id", 10);
         dictionary.set_Item("version", this.kSDKVersion);
         dictionary.set_Item("body", message);
         dictionary.set_Item("app_id", this.userData.get_Item("sAppId"));
         string text   = Json.Serialize(dictionary);
         string text2  = MinizLib.Compress(text.get_Length(), text);
         byte[] array  = Convert.FromBase64String(text2);
         int    num2   = IPAddress.HostToNetworkOrder(array.Length);
         byte[] bytes  = BitConverter.GetBytes(num2);
         byte[] array2 = new byte[bytes.Length + array.Length];
         Array.Copy(bytes, 0, array2, 0, bytes.Length);
         Array.Copy(array, 0, array2, bytes.Length, array.Length);
         IAsyncResult asyncResult     = socket.BeginSend(array2, 0, array2.Length, 0, null, null);
         WaitHandle   asyncWaitHandle = asyncResult.get_AsyncWaitHandle();
         try
         {
             if (!asyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds((double)this.sendRcvTimeOut)))
             {
                 Debug.Log("Send Time Out:" + this.sendRcvTimeOut.ToString());
                 this.CloseSocket(socket);
             }
             else
             {
                 try
                 {
                     int num3 = socket.EndSend(asyncResult);
                     if (asyncResult.get_IsCompleted() && num3 == array2.Length)
                     {
                         Debug.Log(string.Format("客户端发送消息:{0}", text));
                         this.AsynRecive(socket);
                     }
                     else
                     {
                         this.CloseSocket(socket);
                     }
                 }
                 catch (Exception ex)
                 {
                     Debug.Log(ex.get_Message());
                     this.CloseSocket(socket);
                 }
             }
         }
         catch (Exception ex2)
         {
             Debug.Log(ex2.get_Message());
             this.CloseSocket(socket);
         }
         finally
         {
             asyncWaitHandle.Close();
         }
     }
     catch (Exception ex3)
     {
         Debug.Log(string.Format("异常信息:{0}", ex3.get_Message()));
         this.CloseSocket(socket);
     }
 }