Exemple #1
0
    public override void InitSev()
    {
        bTimer = new BTimer();
        bTimer.SetLog((str, level) =>
        {
            switch (level)
            {
            case BTimer.LogLevel.Info:
                Debug.Log(str);
                break;

            case BTimer.LogLevel.Log:
                Debug.Log(str);
                break;

            case BTimer.LogLevel.Warning:
                Debug.LogWarning(str);
                break;

            case BTimer.LogLevel.Error:
                Debug.LogError(str);
                break;
            }
        });

        new GameObject("TimerSevMono").AddComponent <TimerSevMono>();
    }
Exemple #2
0
    public void Init()
    {
        bTimer = new BTimer();
        bTimer.SetLog((str, level) =>
        {
            switch (level)
            {
            case BTimer.LogLevel.Info:
                Debug.Log(str);
                break;

            case BTimer.LogLevel.Log:
                Debug.Log(str);
                break;

            case BTimer.LogLevel.Warning:
                Debug.LogWarning(str);
                break;

            case BTimer.LogLevel.Error:
                Debug.LogError(str);
                break;
            }
        });
    }
Exemple #3
0
        private void HandleProvideRoomAccessCheck(IIncommingMessage message)
        {
            var data = message.Deserialize(new RoomAccessProvideCheckPacket());

            var roomController = Msf.Server.Rooms.GetRoomController(data.RoomId);

            if (roomController == null)
            {
                message.Respond("There's no room controller with room id " + data.RoomId, ResponseStatus.NotHandled);
                return;
            }

            var accessProvider = roomController._accessProvider ?? DefaultAccessProvider;
            var isProviderDone = false;

            var requester = new UsernameAndPeerIdPacket()
            {
                PeerId   = data.PeerId,
                Username = data.Username
            };

            // Invoke the access provider
            accessProvider.Invoke(requester, (access, error) =>
            {
                // In case provider timed out
                if (isProviderDone)
                {
                    return;
                }

                isProviderDone = true;

                if (access == null)
                {
                    // If access is not provided
                    message.Respond(error ?? "", ResponseStatus.Failed);
                    return;
                }

                message.Respond(access, ResponseStatus.Success);

                if (Logger.IsLogging(LogLevel.Trace))
                {
                    Logger.Trace("Room controller gave address to peer " + data.PeerId + ":" + access);
                }
            });

            // Timeout the access provider
            BTimer.AfterSeconds(Msf.Server.Rooms.AccessProviderTimeout, () =>
            {
                if (!isProviderDone)
                {
                    isProviderDone = true;
                    message.Respond("Timed out", ResponseStatus.Timeout);
                    Logger.Error("Access provider took longer than " + Msf.Server.Rooms.AccessProviderTimeout + " seconds to provide access. " +
                                 "If it's intended, increase the threshold at Msf.Server.Rooms.AccessProviderTimeout");
                }
            });
        }
Exemple #4
0
    public void Init(int interval, bool dealInMain = true)
    {
        this.interval = interval;
        bTimer        = new BTimer();
        bTimer.SetLog((str, level) =>
        {
            switch (level)
            {
            case BTimer.LogLevel.Info:
                Console.WriteLine("Info: " + str);
                break;

            case BTimer.LogLevel.Log:
                Console.WriteLine("Log: " + str);
                break;

            case BTimer.LogLevel.Warning:
                Console.WriteLine("Warning: " + str);
                break;

            case BTimer.LogLevel.Error:
                Console.WriteLine("Error: " + str);
                break;
            }
        });

        // 设置主线程处理句柄,如果调用了该方法
        // 则必须在主线程循环调用 DealTimeTask() 来在主线程处理计时任务回调
        // 如果不调用该方法,则计时任务回调是在多线程中执行
        if (dealInMain)
        {
            bTimer.SetHandle((cb, id) =>
            {
                if (cb != null)
                {
                    lock (obj)
                    {
                        taskPackQue.Enqueue(new TaskPack(id, cb));
                    }
                }
            });
        }
    }
Exemple #5
0
 public void StartTimer()
 {
     if (ResetTimer)
     {
         if (CountUp)
         {
             BTimer = new BingoTimer(0);
         }
         else
         {
             BTimer = new BingoTimer((int)TimerTime.TotalSeconds);
         }
         BTimer.InitializeNewCountDownTimer();
         BTimer.TimerStart();
         ResetTimer            = false;
         BTimer.IsTimerStarted = true;
     }
     else
     {
         BTimer.TimerStart();
         BTimer.IsTimerStarted = true;
     }
     ToggleTimerText = STOP;
 }
Exemple #6
0
        public void DefaultSpawnRequestHandler(SpawnRequestPacket packet, IIncommingMessage message)
        {
            Logger.Debug("Default spawn handler started handling a request to spawn process");

            var controller = Msf.Server.Spawners.GetController(packet.SpawnerId);

            if (controller == null)
            {
                message.Respond("Failed to spawn a process. Spawner controller not found", ResponseStatus.Failed);
                return;
            }

            var port = Msf.Server.Spawners.GetAvailablePort();

            // Check if we're overriding an IP to master server
            var masterIp = string.IsNullOrEmpty(controller.DefaultSpawnerSettings.MasterIp) ?
                           controller.Connection.ConnectionIp : controller.DefaultSpawnerSettings.MasterIp;

            // Check if we're overriding a port to master server
            var masterPort = controller.DefaultSpawnerSettings.MasterPort < 0 ?
                             controller.Connection.ConnectionPort : controller.DefaultSpawnerSettings.MasterPort;

            // Machine Ip
            var machineIp = controller.DefaultSpawnerSettings.MachineIp;

            // Path to executable
            var path = controller.DefaultSpawnerSettings.ExecutablePath;

            if (string.IsNullOrEmpty(path))
            {
                path = File.Exists(Environment.GetCommandLineArgs()[0])
                    ? Environment.GetCommandLineArgs()[0]
                    : Process.GetCurrentProcess().MainModule.FileName;
            }

            // In case a path is provided with the request
            if (packet.Properties.ContainsKey(MsfDictKeys.ExecutablePath))
            {
                path = packet.Properties[MsfDictKeys.ExecutablePath];
            }

            // Get the scene name
            var sceneNameArgument = packet.Properties.ContainsKey(MsfDictKeys.SceneName)
                ? string.Format("{0} {1} ", Msf.Args.Names.LoadScene, packet.Properties[MsfDictKeys.SceneName])
                : "";

            if (!string.IsNullOrEmpty(packet.OverrideExePath))
            {
                path = packet.OverrideExePath;
            }

            // If spawn in batchmode was set and `DontSpawnInBatchmode` arg is not provided
            var spawnInBatchmode = controller.DefaultSpawnerSettings.SpawnInBatchmode &&
                                   !Msf.Args.DontSpawnInBatchmode;


            #region Custom Albot Data
            //Albot Edit! We add so that the gameserver knows if it is a realtime game and what type.
            //These values will be read in the Msf.Args and accesable after startup
            string realTimeValue   = packet.Properties[MsfDictKeys.IsRealtime];
            string gameTypeValue   = packet.Properties[MsfDictKeys.GameType];
            string spectatorsValue = packet.Properties[MsfDictKeys.Spectators];

            string realtimeInfo   = string.Format("{0} {1} ", Msf.Args.Names.Realtime, realTimeValue);
            string gameTypeInfo   = string.Format("{0} {1} ", Msf.Args.Names.GameType, gameTypeValue);
            string SpectatorsInfo = string.Format("{0} {1} ", Msf.Args.Names.Spectators, spectatorsValue);
            #endregion



            var startProcessInfo = new ProcessStartInfo(path)
            {
                CreateNoWindow  = false,
                UseShellExecute = false,
                Arguments       = " " +
                                  (spawnInBatchmode ? "-batchmode -nographics " : "") +
                                  (controller.DefaultSpawnerSettings.AddWebGlFlag ? Msf.Args.Names.WebGl + " " : "") +
                                  sceneNameArgument +
                                  string.Format("{0} {1} ", Msf.Args.Names.MasterIp, masterIp) +
                                  string.Format("{0} {1} ", Msf.Args.Names.MasterPort, masterPort) +
                                  string.Format("{0} {1} ", Msf.Args.Names.SpawnId, packet.SpawnId) +
                                  string.Format("{0} {1} ", Msf.Args.Names.AssignedPort, port) +
                                  string.Format("{0} {1} ", Msf.Args.Names.MachineIp, machineIp) +
                                  (Msf.Args.DestroyUi ? Msf.Args.Names.DestroyUi + " " : "") +
                                  string.Format("{0} \"{1}\" ", Msf.Args.Names.SpawnCode, packet.SpawnCode) +
                                  packet.CustomArgs +
                                  realtimeInfo +
                                  gameTypeInfo +
                                  SpectatorsInfo
            };

            Logger.Debug("Starting process with args: " + startProcessInfo.Arguments);

            var processStarted = false;

            try
            {
                new Thread(() =>
                {
                    try
                    {
                        Logger.Debug("New thread started");

                        using (var process = Process.Start(startProcessInfo))
                        {
                            Logger.Debug("Process started. Spawn Id: " + packet.SpawnId + ", pid: " + process.Id);
                            processStarted = true;

                            Logger.Debug(_processLock);
                            lock (_processLock)
                            {
                                // Save the process
                                _processes[packet.SpawnId] = process;
                            }

                            var processId = process.Id;
                            // Notify server that we've successfully handled the request
                            BTimer.ExecuteOnMainThread(() =>
                            {
                                Logger.Debug("Sending Success");
                                message.Respond(ResponseStatus.Success);
                                controller.NotifyProcessStarted(packet.SpawnId, processId, startProcessInfo.Arguments);
                                Logger.Debug("Post Sending Success");
                            });

                            process.WaitForExit();
                        }
                    }
                    catch {
                        if (!processStarted)
                        {
                            BTimer.ExecuteOnMainThread(() => { message.Respond(ResponseStatus.Failed); });
                        }

                        Logger.Debug("An exception was thrown while starting a process. Make sure that you have set a correct build path. " +
                                     "We've tried to start a process at: '" + path + "'. You can change it at 'SpawnerBehaviour' component");
                    }
                    finally
                    {
                        lock (_processLock)
                        {
                            // Remove the process
                            _processes.Remove(packet.SpawnId);
                        }

                        BTimer.ExecuteOnMainThread(() =>
                        {
                            // Release the port number
                            Msf.Server.Spawners.ReleasePort(port);

                            Logger.Debug("Notifying about killed process with spawn id: " + packet.SpawnerId);
                            controller.NotifyProcessKilled(packet.SpawnId);
                        });
                    }
                }).Start();
            }
            catch (Exception e)
            {
                message.Respond(e.Message, ResponseStatus.Error);
                Logs.Error(e);
            }
        }
Exemple #7
0
 public void StopTimer()
 {
     BTimer.TimerStop();
     BTimer.IsTimerStarted = false;
     ToggleTimerText       = START;
 }
Exemple #8
0
 public void RunOnMainThread(Action action)
 {
     BTimer.ExecuteOnMainThread(action);
 }