示例#1
0
    private void readSocket()
    {
        //Console.WriteLine(" - Try to read!");
        if (!socket_ready)
        {
            return;
        }

        if (net_stream.DataAvailable && net_stream.CanRead)
        {
            //Debug.Log("Read Socket");
            try {
                // decrypt ?
                BSONObject obj = null;
                obj = SimpleBSON.Load(ByteStreamParser.parseStream(net_stream));



                IClientCmd clientCmd = cmdMgr.decodeBSON(obj);
                if (clientCmd != null)
                {
                    this.observer.addClientCmd(clientCmd);
                }
                else
                {
                    Debug.LogError("ClientCmd not parsed !");
                }
            } catch (Exception e) {
                Debug.LogError("Exception:" + e);
            }
        }
    }
示例#2
0
 public IClientCmd decodeBSON(BSONObject obj)
 {
     //Debug.Log("Try to decode !");
     if (obj.ContainsKey("meta"))
     {
         string meta = obj ["meta"];
         //Debug.Log ("Meta:" + meta);
         Type t = Type.GetType("UnityBSONClient." + meta);
         if (t == null)
         {
             //Debug.Log ("Meta:" + meta + " not found");
             return(null);
         }
         IClientCmd cmd = (IClientCmd)Activator.CreateInstance(t);
         cmd.decode(obj);
         return(cmd);
     }
     return(null);
 }
示例#3
0
 public void addClientCmd(IClientCmd cmd)
 {
     //Debug.Log("New Client Cmd added!");
     clientCmdlist.Enqueue(cmd);
     //cmd.execute ();
 }