Ejemplo n.º 1
0
    public static ExclusiveString Parse(string s)
    {
        ExclusiveString temp = new ExclusiveString();

        temp.SetData(s);
        return(temp);
    }
Ejemplo n.º 2
0
    public static ExclusiveString operator +(ExclusiveString a, ExclusiveString b)
    {
        ExclusiveString temp = new ExclusiveString();

        temp.SetData(a.GetData() + b.GetData());
        return(temp);
    }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes the Network Core variables.
 /// </summary>
 void Start()
 {
     UDPMasterMessage = new ExclusiveString();
     MasterMessage    = new ExclusiveString();
     UDPMasterMessage.SetData("");
     MasterMessage.SetData("");
     UsingUDP = false;
 }
Ejemplo n.º 4
0
    public static ExclusiveString operator +(ExclusiveString a, string b)
    {
        ExclusiveString temp = new ExclusiveString();

        lock (a.SLock)
        {
            temp.SetData(a.GetData() + b);
        }
        return(temp);
    }
Ejemplo n.º 5
0
 public void AddMsg(string msg, bool useTcp = true)
 {
     if (useTcp)
     {
         GameObjectMessages += (msg + "\n");
     }
     else
     {
         UDPGameObjectMessages += (msg + "\n");
     }
 }
Ejemplo n.º 6
0
    /// <summary>
    /// This will gather all messages that need to be sent form the NetworkIdentities
    /// Then either send it to the server or to all of the clients.
    /// This will also send the UDP messages as well.
    /// </summary>
    public override void OnSlowUpdate()
    {
        List <string> UDPMasterStringList = new List <string>();

        foreach (KeyValuePair <int, NetworkID> id in NetObjs)
        {
            //Add their message to the masterMessage (the one we send)
            MasterMessage += id.Value.GameObjectMessages.ReadAndClear() + "\n";
            UDPMasterStringList.Add(id.Value.UDPGameObjectMessages.ReadAndClear() + "\n");
        }
        //Send Master Message
        List <int> bad = new List <int>();

        string msgToSend = MasterMessage.ReadAndClear();

        //string UDPmsgToSend = UDPMasterMessage.ReadAndClear();
        foreach (KeyValuePair <int, Connector> item in Connections)
        {
            try
            {
                //This will send all of the information to the client (or to the server if on a client).
                if (msgToSend.Trim() != "")
                {
                    Send(msgToSend, item.Key);
                }
                foreach (string msg in UDPMasterStringList)
                {
                    if (msg.Trim() != "")
                    {
                        Send(msg, item.Key, false);
                    }
                }
            }
            catch (System.Exception e)
            {
                GenericNetworkCore.Logger("Exception occured in slow update: " + e.ToString());
                bad.Add(item.Key);
            }
        }
        //MasterMessage.SetData("");//delete old values.
        foreach (int i in bad)
        {
            GenericNetworkCore.Logger("We are disconecting Connection " + i.ToString() + " from " + name + ":" + this.GetType().ToString());
            this.Disconnect(i);
        }
    }
Ejemplo n.º 7
0
 /// <summary>
 /// This will destroy an object with a given ID
 /// across the network.
 /// Serer Only.
 /// </summary>
 /// <param name="netIDBad">The net ID of the object to Destroy.</param>
 public void NetDestroyObject(int netIDBad)
 {
     if (IsServer)
     {
         try
         {
             if (NetObjs.ContainsKey(netIDBad))
             {
                 Destroy(NetObjs[netIDBad].gameObject);
                 NetObjs.Remove(netIDBad);
                 string msg = "DELETE#" + netIDBad + "\n";
                 MasterMessage += msg;
             }
         }
         catch
         {
             //Already been destroyed.
         }
     }
 }
Ejemplo n.º 8
0
    /// <summary>
    /// This will spawn a game object across the network.
    /// The prefab will be identified by the index = to type.
    /// Server Only
    /// </summary>
    /// <param name="type">Index on the spawn prefab array</param>
    /// <param name="ownMe">Which player owns the object, -1 for server.</param>
    /// <param name="initPos">The initial position for the new object.</param>
    /// <param name="rotation">The initial rotation for the desired game object.</param>
    /// <returns>This function returns a pointer to the new game object.  (Server only)</returns>
    public GameObject NetCreateObject(int type, int ownMe, Vector3 initPos = new Vector3(), Quaternion rotation = new Quaternion())
    {
        if (IsServer)
        {
            GameObject temp;
            lock (ObjLock)
            {
                if (type != -1)
                {
                    temp = GameObject.Instantiate(SpawnPrefab[type], initPos, rotation);
                }
                else
                {
                    temp = GameObject.Instantiate(NetworkPlayerManager, initPos, rotation);
                }
                temp.GetComponent <NetworkID>().Owner = ownMe;
                temp.GetComponent <NetworkID>().NetId = ObjectCounter;
                temp.GetComponent <NetworkID>().Type  = type;
                NetObjs.Add(ObjectCounter, temp.GetComponent <NetworkID>());
                string MSG = "CREATE#" + type + "#" + ownMe +
                             "#" + (ObjectCounter) + "#" + initPos.ToString() + "#" +
                             rotation.eulerAngles.ToString() + "\n";
                ObjectCounter++;

                MasterMessage += MSG;
                foreach (NetworkComponent n in temp.GetComponents <NetworkComponent>())
                {
                    //Force update to all clients.
                    n.IsDirty = true;
                }
            }
            return(temp);
        }
        else
        {
            return(null);
        }
    }