public bool TryGetHost(out NetworkInstance serverInstance)
        {
            const string cl = "#FF2100";

            serverInstance = null;
            if (!GameLaunch.IsServer)
            {
                return(false);
            }

            if (!IsCurrentlyHosting && GameLaunch.IsServer)
            {
                // We must log this
                Debug.LogError
                (
                    $"<b>[GMS][Strange Error] <color='{cl}'>We are a server but we aren't currently hosting.</color></b>"
                );
                return(false);
            }

            if (Main.ServerInstance != Main.LocalInstance)
            {
                // We must log this
                Debug.LogError
                (
                    $"<b>[GMS][Strange Error] <color='{cl}'>We are a server but the server instance and the local instance are not equal</color></b>"
                );
                return(false);
            }

            serverInstance = Main.ServerInstance;
            return(true);
        }
示例#2
0
 public static GameServer From(NetworkInstance local, NetworkInstance server)
 {
     return(new GameServer()
     {
         LocalInstance = local,
         ServerInstance = server,
         LocalNetManager = (local.ConnectionInfo.Creator as IConnectionHost)?.Manager
     });
 }
示例#3
0
        private void SendNewInputToClients(NetworkInstance caller, InputPacket packet)
        {
            var msgMgr  = caller.GetMessageManager();
            var msgData = msgMgr.Create(InputMsgToClientsId);

            packet.WriteTo(msgData);

            m_NetworkMessageSystem.InstantSendToAllDefault(caller, msgData, DeliveryMethod.Unreliable);
        }
    void InstantiateClient(Client client)
    {
        Debug.Log("[InstantiateClient] Criando Client " + client.id + " em: " + client.position.ToString());
        GameObject clientObject = Instantiate(PlayerPrefab, client.position, Quaternion.identity);

        clientObject.transform.eulerAngles = client.rotation;
        NetworkInstance clientNet = clientObject.GetComponent <NetworkInstance>();

        clientNet.id = client.id;

        clients.Add(client.id, clientObject);
    }
        private void SendNewInputToClients(NetworkInstance caller, InputPacket packet)
        {
            if (!IsConnectedOrHosting)
            {
                return;
            }

            var msgMgr  = caller.GetMessageManager();
            var msgData = msgMgr.Create(InputMsgToClientsId);

            packet.WriteTo(msgData);

            m_NetworkMessageSystem.InstantSendToAllDefault(caller, msgData, DeliveryMethod.ReliableUnordered);
        }
示例#6
0
        public void Build()
        {
            List <ToStringWrapper <NetworkInstance> > list = new List <ToStringWrapper <NetworkInstance> >();

            new List <ToStringWrapper <Network> >();
            try {
                this.networkOptionsControl1.TheDataGridView.Rows.Clear();
                if (this.VMwareNetworks != null)
                {
                    foreach (NetworkInstance instance in this.VMwareNetworks)
                    {
                        NetworkInstance item = instance;
                        ToStringWrapper <NetworkInstance> wrapper = new ToStringWrapper <NetworkInstance>(item, item.Name);
                        list.Add(wrapper);
                    }
                }
                foreach (ToStringWrapper <NetworkInstance> wrapper2 in list)
                {
                    DataGridViewRow         dataGridViewRow  = new DataGridViewRow();
                    DataGridViewTextBoxCell dataGridViewCell = new DataGridViewTextBoxCell {
                        Tag   = wrapper2,
                        Value = wrapper2.ToString()
                    };
                    dataGridViewRow.Cells.Add(dataGridViewCell);
                    DataGridViewComboBoxCell cell3 = (DataGridViewComboBoxCell)this.FillGridComboBox().Clone();
                    if (cell3.Items.Count > 0)
                    {
                        cell3.DisplayMember = "ToStringProperty";
                        cell3.ValueMember   = "Self";
                        cell3.Value         = cell3.Items[this.GetDefaultIndex()];
                        dataGridViewRow.Cells.Add(cell3);
                    }
                    else
                    {
                        DataGridViewTextBoxCell cell4 = new DataGridViewTextBoxCell {
                            Value = Messages.WIZARD_SELECT_NETWORK_PAGE_NO_AVAIL_NETWORKS
                        };
                        dataGridViewRow.Cells.Add(cell4);
                        cell4.ReadOnly = true;
                    }
                    this.networkOptionsControl1.TheDataGridView.Rows.Add(dataGridViewRow);
                }
            }
            catch (Exception exception) {
                LOG.Error(exception, exception);
            }
        }
        public bool TryGetHostOrError(out NetworkInstance serverInstance)
        {
            Profiler.BeginSample("TryGetHostOrError");
            const string cl = "#FF2100";

            serverInstance = null;
            Profiler.BeginSample("!GameLaunch.IsServer");
            if (!GameLaunch.IsServer)
            {
                Profiler.EndSample();
                Debug.LogError
                (
                    $"<b>[GMS][Incoherance] <color='{cl}'>We are a client but we were asked to do a server stuff.</color></b>"
                );
                return(false);
            }
            Profiler.EndSample();

            Profiler.BeginSample("!IsCurrentlyHosting && GameLaunch.IsServer");
            if (!IsCurrentlyHosting && GameLaunch.IsServer)
            {
                Profiler.EndSample();
                Debug.LogError
                (
                    $"<b>[GMS][Strange Error] <color='{cl}'>We are a server but we aren't currently hosting.</color></b>"
                );
                return(false);
            }
            Profiler.EndSample();

            Profiler.BeginSample("Main.ServerInstance != Main.LocalInstance");
            if (Main.ServerInstance != Main.LocalInstance)
            {
                Profiler.EndSample();
                Debug.LogError
                (
                    $"<b>[GMS][Strange Error] <color='{cl}'>We are a server but the server instance and the local instance are not equal</color></b>"
                );
            }
            Profiler.EndSample();

            serverInstance = Main.ServerInstance;
            Profiler.EndSample();
            return(true);
        }
示例#8
0
 public void CrossFinishLine()
 {
     if (currentState != State.Play)
     {
         return;
     }
     currentState = State.Finished;
     if (playerName != "")
     {
         UIManager.Instance.ShowText("You Win!\nPosting score, please wait ...");
         NetworkInstance.PostScore(playerName, time, () => {
             UIManager.Instance.ShowText("You Win!\nYour score is online!");
         });
     }
     else
     {
         UIManager.Instance.ShowText("You Win!\nYou need to write a name to save your score online");
     }
 }
示例#9
0
 public void CloseConnection()
 {
     try
     {
         LocalInstance.Dispose();
         if (LocalInstance != ServerInstance)
         {
             ServerInstance.Dispose();
         }
     }
     catch (Exception ex)
     {
         Debug.LogException(ex);
     }
     finally
     {
         LocalNetManager?.Stop();
         LocalNetManager = null;
         LocalInstance   = null;
         ServerInstance  = null;
     }
 }
示例#10
0
    public override NetworkInstance Launch(NetworkConfig config)
    {
        sReception = new Socket(config.afamily, config.stype, config.ptype);
        IPEndPoint targetEndPoint = new IPEndPoint(IPAddress.Parse(config.ipAddress), config.port);

        try
        {
            sReception.Bind(targetEndPoint);
        }
        catch (Exception e)
        {
            dataAdapter.Log(e.ToString());
            sReception = null;
            return(null);
        }
        sReception.Listen(config.backlog);
        NetworkInstance current = base.Launch(config);

        MainThread = new Thread(ConnectReception);
        MainThread.Start();
        socketPool = new NetworkServerSocketPool(this);
        AdapterAs <Handles_NetworkServerAdapter>().Server_Launch(this);
        return(current);
    }
示例#11
0
    public static T StartInstance <T>(Handles_NetworkDataAdapter dAdapter) where T : NetworkInstance
    {
        T instance = new NetworkInstance(dAdapter) as T;

        return(instance);
    }
示例#12
0
 public ConversionNetworkResource(NetworkInstance network)
 {
     NetworkName = network.Name;
     NetworkID   = network.Id;
 }
示例#13
0
 // Use this for initialization
 void Start()
 {
     rb          = GetComponent <Rigidbody>();
     netInstance = GetComponent <NetworkInstance>();
 }