예제 #1
0
    static public List <STuple <BoltGlobalBehaviourAttribute, Type> > GetGlobalBehaviourTypes()
    {
#if UNITY_WSA
        Assembly asm = typeof(BoltLauncher).GetTypeInfo().Assembly;
#else
        Assembly asm = Assembly.GetExecutingAssembly();
#endif

        List <STuple <BoltGlobalBehaviourAttribute, Type> > result = new List <STuple <BoltGlobalBehaviourAttribute, Type> >();

        try
        {
            foreach (Type type in asm.GetTypes())
            {
                if (typeof(MonoBehaviour).IsAssignableFrom(type))
                {
#if UNITY_WSA
                    var attrs = (BoltGlobalBehaviourAttribute[])type.GetTypeInfo().GetCustomAttributes(typeof(BoltGlobalBehaviourAttribute), false);
#else
                    var attrs = (BoltGlobalBehaviourAttribute[])type.GetCustomAttributes(typeof(BoltGlobalBehaviourAttribute), false);
#endif
                    if (attrs.Length == 1)
                    {
                        result.Add(new STuple <BoltGlobalBehaviourAttribute, Type>(attrs[0], type));
                    }
                }
            }
        }
        catch (Exception e)
        {
            BoltLog.Exception(e);
        }

        return(result);
    }
 public override void PacketReceived(UdpPacket udpPacket)
 {
     try
     {
         using (Packet packet = PacketPool.Acquire())
         {
             packet.UdpPacket = udpPacket;
             packet.Frame     = packet.UdpPacket.ReadIntVB();
             if (packet.Frame > this._remoteFrameActual)
             {
                 this._remoteFrameAdjust = true;
                 this._remoteFrameActual = packet.Frame;
             }
             this._bitsSecondInAcc += packet.UdpPacket.Size;
             this._packetsReceived++;
             for (int i = 0; i < this._channels.Length; i++)
             {
                 this._channels[i].Read(packet);
             }
             this._packetStatsIn.Enqueue(packet.Stats);
         }
     }
     catch (Exception exception)
     {
         BoltLog.Exception(exception);
         ModAPI.Log.Write(exception.ToString());
     }
 }
예제 #3
0
        private bool BuildBindingInfo(out BindingInfo bindingInfo)
        {
            var connectionInfo = PlayFabMultiplayerAgentAPI.GetGameServerConnectionInfo();

            IPAddress address;

            if (IPAddress.TryParse(connectionInfo.PublicIpV4Adress, out address))
            {
                try
                {
                    var portInfo   = connectionInfo.GamePortsConfiguration.First(port => port.Name.Equals(BindingConfigKey));
                    var externalIP = new IPEndPoint(address, portInfo.ClientConnectionPort);

                    bindingInfo = new BindingInfo
                    {
                        externalInfo       = externalIP,
                        internalServerPort = portInfo.ServerListeningPort
                    };

                    return(true);
                }
                catch (InvalidOperationException ex)
                {
                    BoltLog.Exception(ex);
                }
            }

            bindingInfo = null;
            return(false);
        }
 static void NatUtility_ClosePort(NatDeviceState device, int port)
 {
     lock (syncLock) {
         Mapping mapping = new Mapping(Protocol.Udp, port, port);
         device.Nat.BeginDeletePortMap(mapping, ar => {
             lock (syncLock) {
                 try {
                     device.Nat.EndDeletePortMap(ar);
                     ClosePortMapping(device, port);
                 }
                 catch (MappingException exn) {
                     if (exn.ErrorCode == 714)
                     {
                         ClosePortMapping(device, port);
                     }
                     else
                     {
                         BoltLog.Exception(exn);
                     }
                 }
                 catch (Exception exn) {
                     BoltLog.Exception(exn);
                 }
             }
         }, null);
     }
 }
        static void NatUtility_OpenPort(NatDeviceState device, int port)
        {
            lock (syncLock) {
                Mapping mapping = new Mapping(Protocol.Udp, port, port);
                device.Nat.BeginCreatePortMap(mapping, ar => {
                    lock (syncLock) {
                        try {
                            device.Nat.EndCreatePortMap(ar);

                            // finish this
                            NatUtility_OpenPort_Finish(device, port);
                        }
                        catch (MappingException exn) {
                            if (exn.ErrorCode == 718)
                            {
                                NatUtility_OpenPort_Finish(device, port);
                            }
                            else
                            {
                                BoltLog.Exception(exn);
                            }
                        }
                        catch (Exception exn) {
                            BoltLog.Exception(exn);
                        }
                    }
                }, null);
            }
        }
        static void NatUtility_OpenPort_Finish(NatDeviceState device, int port)
        {
            try {
                var natMapping = device.PortMappings.Values.FirstOrDefault(p => p.Internal == port && p.External == port);
                if (natMapping != null)
                {
                    // set this port as open
                    natMapping.Status = Bolt.NatPortMappingStatus.Open;

                    // tell user about this
                    portChanges.Enqueue(new NatPortMappingChanged {
                        Device = device, Mapping = natMapping.Clone()
                    });

                    // meep
                    BoltLog.Info("Changed {0} on {1}", natMapping, device);
                }
                else
                {
                    BoltLog.Warn("Received incorrect port mapping result from {0}", device);
                }
            }
            catch (Exception exn) {
                BoltLog.Exception(exn);
            }
        }
예제 #7
0
        public override void SceneLoadLocalDone(string map)
        {
            BoltLog.Info("New scene: " + map);

            try
            {
                if (lobbyScene.SimpleSceneName == map)
                {
                    ChangeTo(mainMenuPanel);
                    topPanel.isInGame = false;
                }
                else if (gameScene.SimpleSceneName == map)
                {
                    ChangeTo(null);

                    backDelegate      = Stop;
                    topPanel.isInGame = true;
                    topPanel.ToggleVisibility(false);

                    // Spawn Player
                    // SpawnGamePlayer();
                }
            }
            catch (Exception e)
            {
                BoltLog.Exception(e);
            }
        }
    static BoltExecutionOrderManager()
    {
        Dictionary <string, MonoScript> monoScripts = new Dictionary <string, MonoScript>();

        foreach (MonoScript monoScript in MonoImporter.GetAllRuntimeMonoScripts())
        {
            try
            {
                switch (monoScript.name)
                {
                case "BoltPoll":
                    SetExecutionOrder(monoScript, -10000);
                    break;

                case "BoltSend":
                    SetExecutionOrder(monoScript, +10000);
                    break;

                case "BoltEntity":
                    SetExecutionOrder(monoScript, -2500);
                    break;

                default:
                    if (monoScripts.ContainsKey(monoScript.name))
                    {
                        monoScripts[monoScript.name] = monoScript;
                    }
                    else
                    {
                        monoScripts.Add(monoScript.name, monoScript);
                    }
                    break;
                }
            }
            catch { }
        }

        foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
        {
            foreach (var type in asm.GetTypes())
            {
                if (monoScripts.ContainsKey(type.Name))
                {
                    try
                    {
                        foreach (BoltExecutionOrderAttribute attribute in type.GetCustomAttributes(typeof(BoltExecutionOrderAttribute), false))
                        {
                            SetExecutionOrder(monoScripts[type.Name], attribute.executionOrder);
                        }
                    }
                    catch (Exception exn)
                    {
                        BoltLog.Exception(exn);
                    }
                }
            }
        }
    }
예제 #9
0
 private void Hit(float amount)
 {
     if (this.Delay)
     {
         return;
     }
     if (this.mapleTree)
     {
         amount *= 2f;
     }
     this.Delay = true;
     base.Invoke("ResetDelay", 0.5f);
     this.HitStick();
     if (BoltNetwork.isRunning)
     {
         try
         {
             DamageTree damageTree = DamageTree.Raise(GlobalTargets.OnlyServer);
             damageTree.TreeEntity  = base.GetComponentInParent <TreeHealth>().LodEntity;
             damageTree.DamageIndex = int.Parse(base.transform.parent.gameObject.name);
             damageTree.Damage      = amount;
             damageTree.Send();
         }
         catch (Exception exception)
         {
             BoltLog.Exception(exception);
         }
     }
     else
     {
         this.damage += amount;
         if (this.damage >= 1f && this.damage < 2f)
         {
             this.Fake2.SetActive(true);
             this.Fake1.SetActive(false);
         }
         if (this.damage >= 2f && this.damage < 3f)
         {
             this.Fake3.SetActive(true);
             this.Fake2.SetActive(false);
             this.Fake1.SetActive(false);
         }
         if (this.damage >= 3f && this.damage < 4f)
         {
             this.Fake4.SetActive(true);
             this.Fake3.SetActive(false);
             this.Fake2.SetActive(false);
             this.Fake1.SetActive(false);
         }
         if (this.damage >= 4f)
         {
             this.MyTree.SendMessage("Hit");
             UnityEngine.Object.Destroy(base.transform.parent.gameObject);
         }
     }
 }
예제 #10
0
        void Update()
        {
            text.GetComponent <Renderer> ().enabled = !entity.hasControl;

            if (!entity.hasControl)
            {
                try {
                    transform.LookAt(PlayerCamera.instance.transform);
                    transform.rotation = Quaternion.LookRotation(-transform.forward);
                } catch (Exception exn) {
                    BoltLog.Exception(exn);
                }
            }
        }
예제 #11
0
        static public List <STuple <BoltGlobalBehaviourAttribute, Type> > GetGlobalBehaviourTypes()
        {
#if UNITY_WSA
            Assembly[] assemblies = { typeof(BoltLauncher).GetTypeInfo().Assembly };
#else
            Assembly[] assemblies =
            {
                GetAssemblyByName(ASSEMBLY_CSHARP),
                GetAssemblyByName(ASSEMBLY_CSHARP_FIRST),
                GetAssemblyByName(ASSEMBLY_PHOTON_BOLT),
                GetAssemblyByName(ASSEMBLY_PHOTON_BOLT_EDITOR)
            };
#endif

            List <STuple <BoltGlobalBehaviourAttribute, Type> > result = new List <STuple <BoltGlobalBehaviourAttribute, Type> >();

            try
            {
                foreach (Assembly asm in assemblies)
                {
                    if (asm == null)
                    {
                        continue;
                    }

                    foreach (Type type in asm.GetTypes())
                    {
                        if (typeof(MonoBehaviour).IsAssignableFrom(type))
                        {
#if UNITY_WSA
                            var attrs = (BoltGlobalBehaviourAttribute[])type.GetTypeInfo().GetCustomAttributes(typeof(BoltGlobalBehaviourAttribute), false);
#else
                            var attrs = (BoltGlobalBehaviourAttribute[])type.GetCustomAttributes(typeof(BoltGlobalBehaviourAttribute), false);
#endif
                            if (attrs.Length == 1)
                            {
                                result.Add(new STuple <BoltGlobalBehaviourAttribute, Type>(attrs[0], type));
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                BoltLog.Exception(e);
            }

            return(result);
        }
 static void NatUtility_FindPublicAddress(NatDeviceState device)
 {
     lock (syncLock) {
         device.Nat.BeginGetExternalIP(ar => {
             lock (syncLock) {
                 try {
                     device.ExternalAddress = device.Nat.EndGetExternalIP(ar);
                     BoltLog.Info("Found external address of {0}", device);
                 }
                 catch (Exception exn) {
                     BoltLog.Exception(exn);
                 }
             }
         }, null);
     }
 }
예제 #13
0
    Map <Guid, UdpSession> FetchSessionListFromPhoton()
    {
        var map = new Map <Guid, UdpSession>();

        foreach (var r in LoadBalancerClient.RoomInfoList)
        {
            if (r.Value.IsOpen)
            {
                try
                {
                    PhotonSession session = new PhotonSession();
                    session._roomName = r.Key;
                    session._id       = new Guid((r.Value.CustomProperties["UdpSessionId"] as String) ?? "");
                    session._hostData = r.Value.CustomProperties["UserToken"] as Byte[];

                    if (_config.UsePunchThrough)
                    {
                        try
                        {
                            session._socketPeerId = new Guid((r.Value.CustomProperties["SocketPeerId"] as String) ?? "");
                        }
#if DEVELOPMENT_BUILD || UNITY_EDITOR
                        catch (Exception exn)
                        {
                            BoltLog.Exception(exn);
                        }
#else
                        catch { }
#endif
                    }

                    session._playerCount = r.Value.PlayerCount;
                    session._playerLimit = r.Value.MaxPlayers;

                    map = map.Add(session.Id, session);
                }
                catch (Exception exn)
                {
                    BoltLog.Exception(exn);
                }
            }
        }

        return(map);
    }
예제 #14
0
    private void SendVoiceData(byte[] voice, int size, BoltConnection sendTo)
    {
        BoltEntity component = base.GetComponent <BoltEntity>();

        try
        {
            int    num   = 0;
            byte[] array = new byte[size + 12];
            Blit.PackU64(array, ref num, component.networkId.PackedValue);
            Blit.PackI32(array, ref num, size);
            Blit.PackBytes(array, ref num, voice, 0, size);
            sendTo.StreamBytes(CoopVoice.VoiceChannel, array);
        }
        catch (Exception exception)
        {
            BoltLog.Exception(exception);
        }
    }
        string RequestCredentials(string email)
        {
            RegistrationRequest requestData = new RegistrationRequest
            {
                Email        = email,
                ServiceTypes = RegistrationConfig.BOLT_SERVICE_ID
            };

            string body = JsonConvert.SerializeObject(requestData);

            string result = null;

            try
            {
                WebRequest webRequest = WebRequest.Create(REGISTER_URL);

                var data = Encoding.UTF8.GetBytes(body);

                webRequest.Method        = "POST";
                webRequest.ContentType   = "application/json";
                webRequest.ContentLength = data.Length;

                using (var writer = webRequest.GetRequestStream())
                {
                    writer.Write(data, 0, data.Length);
                    writer.Close();

                    using (var resp = webRequest.GetResponse())
                    {
                        using (var reader = new StreamReader(resp.GetResponseStream()))
                        {
                            result = reader.ReadToEnd();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                BoltLog.Exception(ex);
                return(null);
            }

            return(result);
        }
예제 #16
0
 private void UpdateZone(AnimalSpawnZone zone, List <Transform> positions)
 {
     try
     {
         for (int i = 0; i < positions.Count; i++)
         {
             if ((positions[i].position - zone.transform.position).sqrMagnitude < zone.ZoneRadius * zone.ZoneRadius)
             {
                 this.SpawnOneAnimalForZone(zone, positions[i]);
                 positions.RemoveAt(i);
                 i--;
             }
         }
     }
     catch (Exception exception)
     {
         BoltLog.Exception(exception);
     }
 }
        /// <summary>
        /// Start this peer as the Game Server
        /// </summary>
        private void OnServerActive()
        {
            if (BoltNetwork.IsRunning)
            {
                return;
            }

            try
            {
                // In order to start the server property when running on the PlayFab stack, it's necessary
                // to setup the local port where the server will listen and suppress the STUN request by passing
                // the binding information provided by PlayFab
                BindingInfo info;
                if (BuildBindingInfo(out info))
                {
                    // Override the STUN information sent by this peer, in other words, the public IP:PORT of this
                    // instance. This information is gattered directly from the PlayFab stack, that provides statically
                    // the binding data of each Virtual Machine
                    BoltLauncher.SetUdpPlatform(new PhotonPlatform(new PhotonPlatformConfig()
                    {
                        ForceExternalEndPoint = info.externalInfo
                    }));

                    // Set the Server port using the information from the binding configuration
                    BoltLauncher.StartServer(info.internalServerPort);
                }
                else                 // Shutdow if the binding info was not found
                {
                    BoltLog.Error(MessageInvalidBinding);
                    OnShutdown();
                }
            }
            catch (Exception ex)
            {
                BoltLog.Error(MessageExceptionServer);
                BoltLog.Exception(ex);
                OnShutdown();
            }
        }
        private static List <STuple <BoltGlobalBehaviourAttribute, Type> > GetGlobalBehaviourTypes()
        {
            List <STuple <BoltGlobalBehaviourAttribute, Type> > result = new List <STuple <BoltGlobalBehaviourAttribute, Type> >();

            try
            {
                var asmIter = BoltAssemblies.AllAssemblies;
                while (asmIter.MoveNext())
                {
                    var asm = GetAssemblyByName(asmIter.Current);
                    if (asm == null)
                    {
                        continue;
                    }

                    foreach (Type type in asm.GetTypes())
                    {
                        if (typeof(MonoBehaviour).IsAssignableFrom(type))
                        {
                            var attrs = (BoltGlobalBehaviourAttribute[])type.GetCustomAttributes(typeof(BoltGlobalBehaviourAttribute), false);

                            if (attrs.Length == 1)
                            {
                                result.Add(new STuple <BoltGlobalBehaviourAttribute, Type>(attrs[0], type));
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                BoltLog.Exception(e);
            }

            return(result);
        }
예제 #19
0
    Map <Guid, UdpSession> FetchSessionListFromPhoton()
    {
        var map = new Map <Guid, UdpSession>();

        foreach (var r in LoadBalancerClient.RoomInfoList)
        {
            if (r.Value.IsOpen && r.Value.IsVisible)
            {
                try
                {
                    if (!r.Value.CustomProperties.ContainsKey("UdpSessionId"))
                    {
                        continue;
                    }

                    PhotonSession session = new PhotonSession
                    {
                        _roomName         = r.Key,
                        _id               = new Guid((r.Value.CustomProperties["UdpSessionId"] as String) ?? ""),
                        _hostData         = r.Value.CustomProperties["UserToken"] as Byte[],
                        _playerCount      = r.Value.PlayerCount,
                        _playerLimit      = r.Value.MaxPlayers,
                        _customProperties = r.Value.CustomProperties
                    };

                    map = map.Add(session.Id, session);
                }
                catch (Exception exn)
                {
                    BoltLog.Exception(exn);
                }
            }
        }

        return(map);
    }
예제 #20
0
 private static void LobbyCreated(LobbyCreated_t param)
 {
     Debug.Log(string.Concat(new object[]
     {
         "LobbyCreated param.m_eResult=",
         param.m_eResult,
         ", lobbyId=",
         param.m_ulSteamIDLobby
     }));
     try
     {
         if (param.m_eResult == EResult.k_EResultOK)
         {
             CSteamID csteamID = new CSteamID(param.m_ulSteamIDLobby);
             if (csteamID.IsValid())
             {
                 CoopLobbyInfo coopLobbyInfo = new CoopLobbyInfo(param.m_ulSteamIDLobby);
                 coopLobbyInfo.IsOwner     = true;
                 coopLobbyInfo.Name        = CoopLobbyManager.createValues.Name;
                 coopLobbyInfo.MemberLimit = CoopLobbyManager.createValues.MemberLimit;
                 CoopLobbyManager.LobbyMatchList_Result = new List <CoopLobbyInfo>();
                 CoopLobbyManager.LobbyMatchList_Result.Add(coopLobbyInfo);
                 CoopLobby.SetActive(coopLobbyInfo);
                 if (GameSetup.IsSavedGame)
                 {
                     SaveSlotUtils.LoadHostGameGUID();
                 }
                 if (CoopLobbyManager.createCallback != null)
                 {
                     try
                     {
                         CoopLobbyManager.createCallback();
                     }
                     catch (Exception exception)
                     {
                         BoltLog.Exception(exception);
                     }
                 }
                 goto IL_112;
             }
         }
         if (CoopLobbyManager.createFailCallback != null)
         {
             try
             {
                 CoopLobbyManager.createFailCallback();
             }
             catch (Exception exception2)
             {
                 BoltLog.Exception(exception2);
             }
         }
         IL_112 :;
     }
     finally
     {
         CoopLobbyManager.createValues       = null;
         CoopLobbyManager.createCallback     = null;
         CoopLobbyManager.createFailCallback = null;
     }
 }