public string SendObject(object obj)
        {
            // objects.Add(objCounter, obj);
            var evnt = new NetworkObjectEvent();

            // objCounter++;
            return(NetworkEventParser.CallNetworkEvent(evnt, "AddNewObject", new[] { NetworkObjectParser.Deconstruct(obj) }));
        }
Exemplo n.º 2
0
 public void AddNewObject(object obj)
 {
     if (obj.GetType() == typeof(string))
     {
         var nwo = NetworkObjectParser.Construct((string)obj);
         NetworkManager.instance.AddObject(nwo);
         GD.Print("Added New Object " + obj.ToString());
     }
 }
Exemplo n.º 3
0
        public override void _Ready()
        {
            var obj = new NetworkObject();

            obj.networkId = 1054;
            // GD.Print(obj.ToString());
            GD.Print(NetworkObjectParser.Deconstruct(obj));
            var obj2 = (NetworkObject)NetworkObjectParser.Construct(NetworkObjectParser.Deconstruct(obj));

            GD.Print(obj2.networkId);
            GetNode("./Host").Connect("pressed", this, "Host");
            GetNode("./Join").Connect("pressed", this, "Join");
            GetNode("./IP").Connect("text_changed", this, "SetIP");
        }
 public override void _Process(float delta)
 {
     if (backend.tcpstream != null && backend.tcpstream.GetStatus() == StreamPeerTCP.Status.Connected && backend.tcpstream.GetAvailableBytes() > 0)
     {
         instance = this;
         var objstr = backend.tcpstream.GetVar();
         if (objstr.GetType() == typeof(string))
         {
             var obj = NetworkObjectParser.Construct((string)objstr);
             // GD.Print(obj.GetType().AssemblyQualifiedName);
             if (obj != null && obj.GetType() == typeof(NetworkVector3))
             {
                 // GD.Print(obj);
                 var nwv3 = (NetworkVector3)obj;
                 GD.Print(nwv3.pos.ToString());
             }
             else if (obj == null)
             {
                 var obj2 = NetworkEventParser.Construct((string)objstr);
                 if (obj2 != null)
                 {
                     GD.Print("Not null Event");
                     if (obj2.GetType() == typeof(NetworkObjectEvent))
                     {
                         GD.Print(objstr);
                     }
                 }
             }
         }
     }
     if (backend.tcpserver != null)
     {
         instance = this;
         foreach (var conn in backend.connections)
         {
             if (!conn.Value.IsConnectedToHost())
             {
                 continue;
             }
             if (conn.Value.GetAvailableBytes() > 0)
             {
                 var v   = conn.Value.GetVar();
                 var obj = NetworkObjectParser.Construct(v.ToString());
                 if (obj == null)
                 {
                     continue;              // TODO: add code for instancing objects and more client side objects
                 }
                 if (objects.ContainsKey((long)obj.GetType().GetField("networkId").GetValue(obj)))
                 {
                 }
                 else
                 {
                     continue;
                 }
                 // ((long)obj.GetType().GetField("networkId").GetValue(obj))
                 // var isplayer = obj.GetType().GetField("isPlayer").GetValue(obj);
                 foreach (var sendconn in backend.connections)
                 {
                     if (conn.Key == sendconn.Key)
                     {
                         continue;
                     }
                     sendconn.Value.PutVar(v);
                 }
             }
             // foreach (var objpair in objects)
             // {
             //     var obj = NetworkObjectParser.Deconstruct(objpair.Value);
             //     conn.Value.PutVar(obj);
             // }
         }
     }
 }