public BroadcastManager(SecondRounding rounding = SecondRounding.Round)
 {
     Rounding    = rounding;
     _stack      = new PlayerDictionary <SortedDictionary <int, BroadcastMessage> >();
     _ticker     = new Ticker(4);
     _dirtySlots = new HashSet <int>();
 }
Ejemplo n.º 2
0
        public void AddPlayer(Player player)
        {
            var identifier = player.GetIdentifier();

            if (PlayerDictionary.ContainsKey(identifier))
            {
                throw new PlayerAlreadyExistsException(identifier.GetPlayerName());
            }
            PlayerDictionary[identifier] = player;
            EventManager.TriggerEvent <PlayerAdded>(this, player);
        }
Ejemplo n.º 3
0
 public void RemovePlayer(Identifier <Player> playerIdentifier)
 {
     if (!PlayerDictionary.ContainsKey(playerIdentifier))
     {
         throw new PlayerNotExistsException(playerIdentifier.GetPlayerName());
     }
     if (!PlayerDictionary.TryRemove(playerIdentifier, out _))
     {
         throw new OperationFailedException("remove player");                                                       //TODO i18n
     }
     EventManager.TriggerEvent <PlayerRemoved>(this, playerIdentifier);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new room UDP socket class instance
        /// </summary>
        public RoomUdpSocket(long id, string name, int maxPlayerCount, IClock clock, TPlayerFactory playerFactory, IPlayerDatabase <TPlayer, TPlayerFactory> playerDatabase, PlayerDictionary <TPlayer> players, int maxTaskCount, ILogger logger) : base(maxTaskCount, logger)
        {
            this.id = id;

            Name           = name;
            MaxPlayerCount = maxPlayerCount;

            this.clock          = clock ?? throw new ArgumentNullException();
            this.playerFactory  = playerFactory ?? throw new ArgumentNullException();
            this.playerDatabase = playerDatabase ?? throw new ArgumentNullException();
            this.players        = players ?? throw new ArgumentNullException();
        }
Ejemplo n.º 5
0
 void INotifyCreated.Created(Actor self)
 {
     frozenStates = new PlayerDictionary <FrozenState>(self.World, (player, playerIndex) =>
     {
         var frozenActor = new FrozenActor(self, this, footprint, player, startsRevealed);
         player.PlayerActor.Trait <FrozenActorLayer>().Add(frozenActor);
         return(new FrozenState(frozenActor)
         {
             IsVisible = startsRevealed
         });
     });
 }
        public GpsDotEffect(Actor actor, GpsDotInfo info)
        {
            this.actor = actor;
            this.info  = info;
            anim       = new Animation(actor.World, info.Image);
            anim.PlayRepeating(info.String);

            visibility          = actor.Trait <IDefaultVisibility>();
            visibilityModifiers = actor.TraitsImplementing <IVisibilityModifier>().ToArray();

            dotStates = new PlayerDictionary <DotState>(actor.World,
                                                        p => new DotState(actor, p.PlayerActor.Trait <GpsWatcher>(), p.PlayerActor.TraitOrDefault <FrozenActorLayer>()));
        }
Ejemplo n.º 7
0
        public GpsDotEffectAS(Actor actor, GpsDotAS trait)
        {
            this.actor = actor;
            this.trait = trait;
            anim       = new Animation(actor.World, trait.Info.Image);
            anim.PlayRepeating(trait.Info.Sequence);

            visibility          = actor.Trait <IDefaultVisibility>();
            visibilityModifiers = actor.TraitsImplementing <IVisibilityModifier>().ToArray();

            dotStates = new PlayerDictionary <DotState>(actor.World,
                                                        p => new DotState(actor, p.PlayerActor.Trait <GpsASWatcher>(), p.FrozenActorLayer));
        }
        /// <summary>
        /// Creates a new room UDP socket class instance
        /// </summary>
        public RoomUdpSocket(long id, string name, IClock clock, TPlayerFactory playerFactory, IPlayerDatabase <TPlayer, TPlayerFactory> playerDatabase, ILogger logger, int maxPlayerCount = 256, int maxTaskCount = 256) : base(logger, maxTaskCount)
        {
            this.id = id;

            Name           = name;
            MaxPlayerCount = maxPlayerCount;

            this.clock          = clock ?? throw new ArgumentNullException();
            this.playerFactory  = playerFactory ?? throw new ArgumentNullException();
            this.playerDatabase = playerDatabase ?? throw new ArgumentNullException();

            players      = new PlayerDictionary <TPlayer>();
            updateThread = new Thread(UpdateThreadLogic);
        }
Ejemplo n.º 9
0
 void Awake()
 {
     if (_instance == null)
     {
         _instance = this;
         DontDestroyOnLoad(gameObject);
     }
     else
     {
         if (_instance != this)
         {
             Destroy(gameObject);
         }
     }
 }
Ejemplo n.º 10
0
 public void Created(Actor self)
 {
     frozenStates = new PlayerDictionary <FrozenState>(self.World, (player, playerIndex) =>
     {
         var frozenActor = new FrozenActor(self, footprint, player.Shroud, startsRevealed);
         if (startsRevealed)
         {
             UpdateFrozenActor(self, frozenActor, playerIndex);
         }
         player.PlayerActor.Trait <FrozenActorLayer>().Add(frozenActor);
         return(new FrozenState(frozenActor)
         {
             IsVisible = startsRevealed
         });
     });
 }
Ejemplo n.º 11
0
        public GpsDot(Actor self, GpsDotInfo info)
        {
            this.self = self;
            this.info = info;
            anim      = new Animation(self.World, info.Image);
            anim.PlayRepeating(info.String);

            self.World.AddFrameEndTask(w => w.Add(this));

            huf      = Exts.Lazy(() => self.TraitOrDefault <HiddenUnderFog>());
            fuf      = Exts.Lazy(() => self.TraitOrDefault <FrozenUnderFog>());
            disguise = Exts.Lazy(() => self.TraitOrDefault <Disguise>());
            cloak    = Exts.Lazy(() => self.TraitOrDefault <Cloak>());

            frozen    = new Cache <Player, FrozenActorLayer>(p => p.PlayerActor.Trait <FrozenActorLayer>());
            dotStates = new PlayerDictionary <DotState>(self.World, player => new DotState(player.PlayerActor.Trait <GpsWatcher>()));
        }
Ejemplo n.º 12
0
        public GpsDot(Actor self, GpsDotInfo info)
        {
            this.self = self;
            this.info = info;
            anim = new Animation(self.World, info.Image);
            anim.PlayRepeating(info.String);

            self.World.AddFrameEndTask(w => w.Add(this));

            huf = Exts.Lazy(() => self.TraitOrDefault<HiddenUnderFog>());
            fuf = Exts.Lazy(() => self.TraitOrDefault<FrozenUnderFog>());
            disguise = Exts.Lazy(() => self.TraitOrDefault<Disguise>());
            cloak = Exts.Lazy(() => self.TraitOrDefault<Cloak>());

            frozen = new Cache<Player, FrozenActorLayer>(p => p.PlayerActor.Trait<FrozenActorLayer>());
            dotStates = new PlayerDictionary<DotState>(self.World, player => new DotState(player.PlayerActor.Trait<GpsWatcher>()));
        }
Ejemplo n.º 13
0
        public void Created(Actor self)
        {
            tooltip = self.TraitsImplementing <ITooltip>().FirstOrDefault();
            health  = self.TraitOrDefault <Health>();

            frozenStates = new PlayerDictionary <FrozenState>(self.World, (player, playerIndex) =>
            {
                var frozenActor = new FrozenActor(self, footprint, player.Shroud, startsRevealed);
                if (startsRevealed)
                {
                    UpdateFrozenActor(self, frozenActor, playerIndex);
                }
                player.PlayerActor.Trait <FrozenActorLayer>().Add(frozenActor);
                return(new FrozenState(frozenActor)
                {
                    IsVisible = startsRevealed
                });
            });
        }
Ejemplo n.º 14
0
        protected void OnListPlayers(FrostbiteClient sender, List<CPlayerInfo> lstPlayers, CPlayerSubset cpsSubset) {
            if (cpsSubset.Subset == CPlayerSubset.PlayerSubsetType.All) {
                // Add or update players.
                foreach (CPlayerInfo cpiPlayer in lstPlayers) {
                    if (PlayerList.Contains(cpiPlayer.SoldierName) == true) {
                        CPlayerInfo storedPlayer = PlayerList[PlayerList.IndexOf(PlayerList[cpiPlayer.SoldierName])];
                        cpiPlayer.JoinTime = CurrentServerInfo.ServerUptime;
                        if (storedPlayer.JoinTime == 0) { storedPlayer.JoinTime = CurrentServerInfo.ServerUptime; }
                        if (storedPlayer.JoinTime <= CurrentServerInfo.ServerUptime) {
                            cpiPlayer.SessionTime = CurrentServerInfo.ServerUptime - storedPlayer.JoinTime;
                            cpiPlayer.JoinTime = storedPlayer.JoinTime;
                        }
                        
                        PlayerList[PlayerList.IndexOf(PlayerList[cpiPlayer.SoldierName])] = cpiPlayer;
                    }
                    else {
                        cpiPlayer.JoinTime = CurrentServerInfo.ServerUptime;
                        PlayerList.Add(cpiPlayer);
                    }
                }

                var recievedPlayerList = new PlayerDictionary(lstPlayers);
                foreach (CPlayerInfo storedPlayer in new List<CPlayerInfo>(PlayerList)) {
                    // If the stored player is not in the list we recieved
                    if (recievedPlayerList.Contains(storedPlayer.SoldierName) == false) {
                        // They have left the server, remove them from the master stored list.
                        PlayerList.Remove(storedPlayer.SoldierName);
                    }
                }

                if (this.IsPRoConConnection == true && this.PlayTimesSynced == false) {
                    SendRequest(new List<string>() {
                        "procon.player.syncPlayTimes"
                    });
                    this.PlayTimesSynced = true;
                }
            }
        }
Ejemplo n.º 15
0
        protected void OnListPlayers(FrostbiteClient sender, List<CPlayerInfo> lstPlayers, CPlayerSubset cpsSubset) {
            if (cpsSubset.Subset == CPlayerSubset.PlayerSubsetType.All) {

                // Add or update players.
                foreach (CPlayerInfo cpiPlayer in lstPlayers) {
                    if (this.PlayerList.Contains(cpiPlayer.SoldierName) == true) {
                        this.PlayerList[this.PlayerList.IndexOf(this.PlayerList[cpiPlayer.SoldierName])] = cpiPlayer;
                    }
                    else {
                        this.PlayerList.Add(cpiPlayer);
                    }
                }

                PlayerDictionary recievedPlayerList = new PlayerDictionary(lstPlayers);
                foreach (CPlayerInfo storedPlayer in new List<CPlayerInfo>(this.PlayerList)) {

                    // If the stored player is not in the list we recieved
                    if (recievedPlayerList.Contains(storedPlayer.SoldierName) == false) {
                        // They have left the server, remove them from the master stored list.
                        this.PlayerList.Remove(storedPlayer.SoldierName);
                    }
                }

            }
        }
 static WeaponEventChecker()
 {
     _itemData = new PlayerDictionary <ItemBulletPair>();
 }
Ejemplo n.º 17
0
        private void InitialSetup() {
            if (Game != null) {
                IsLoadingSavingConnectionConfig = true;

                AssignEventHandlers();

                // Assume full access until we're told otherwise.
                Layer.Initialize(Parent, this);

                // I may move these events to within Layer, depends on the end of the restructure.
                Layer.LayerOnline += new PRoConLayer.LayerEmptyParameterHandler(Layer_LayerOnline);
                Layer.LayerOffline += new PRoConLayer.LayerEmptyParameterHandler(Layer_LayerOffline);
                Layer.AccountPrivileges.AccountPrivilegeAdded += new AccountPrivilegeDictionary.AccountPrivilegeAlteredHandler(AccountPrivileges_AccountPrivilegeAdded);
                Layer.AccountPrivileges.AccountPrivilegeRemoved += new AccountPrivilegeDictionary.AccountPrivilegeAlteredHandler(AccountPrivileges_AccountPrivilegeRemoved);

                foreach (AccountPrivilege apPriv in Layer.AccountPrivileges) {
                    apPriv.AccountPrivilegesChanged += new AccountPrivilege.AccountPrivilegesChangedHandler(item_AccountPrivilegesChanged);
                }

                Privileges = new CPrivileges(CPrivileges.FullPrivilegesFlags);
                EventsLogging = new EventCaptures(this);
                Console = new ConnectionConsole(this);
                PunkbusterConsole = new PunkbusterConsole(this);
                ChatConsole = new ChatConsole(this);
                PluginConsole = new PluginConsole(this);
                MapGeometry = new MapGeometry(this);
                MapGeometry.MapZones.MapZoneAdded += new MapZoneDictionary.MapZoneAlteredHandler(MapZones_MapZoneAdded);
                MapGeometry.MapZones.MapZoneChanged += new MapZoneDictionary.MapZoneAlteredHandler(MapZones_MapZoneChanged);
                MapGeometry.MapZones.MapZoneRemoved += new MapZoneDictionary.MapZoneAlteredHandler(MapZones_MapZoneRemoved);

                if (CurrentServerInfo == null) {
                    CurrentServerInfo = new CServerInfo();
                }

                ListSettings = new ListsSettings(this);
                ServerSettings = new ServerSettings(this);
                PlayerListSettings = new PlayerListSettings();
                PlayerList = new PlayerDictionary();
                TeamNameList = new List<CTeamName>();
                MapListPool = new NotificationList<CMap>();
                ReservedSlotList = new NotificationList<string>();
                Variables = new VariableDictionary();
                SV_Variables = new VariableDictionary();
                Reasons = new NotificationList<string>();
                FullVanillaBanList = new List<CBanInfo>();
                FullTextChatModerationList = new TextChatModerationDictionary();
                Weapons = new WeaponDictionary();
                Specializations = new SpecializationDictionary();

                if (Regex.Match(HostName, @"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$").Success == true) {
                    Variables.SetVariable("SERVER_COUNTRY", Parent.GetCountryName(HostName));
                    Variables.SetVariable("SERVER_COUNTRY_CODE", Parent.GetCountryCode(HostName));
                }
                else {
                    IPAddress ipServer = FrostbiteConnection.ResolveHostName(HostName);
                    Variables.SetVariable("SERVER_COUNTRY", Parent.GetCountryName(ipServer.ToString()));
                    Variables.SetVariable("SERVER_COUNTRY_CODE", Parent.GetCountryCode(ipServer.ToString()));
                }

                Console.Logging = Parent.OptionsSettings.ConsoleLogging;
                EventsLogging.Logging = Parent.OptionsSettings.EventsLogging;
                ChatConsole.Logging = Parent.OptionsSettings.ChatLogging;
                PluginConsole.Logging = Parent.OptionsSettings.PluginLogging;

                //this.m_blLoadingSavingConnectionConfig = true;

                if (CurrentServerInfo.GameMod == GameMods.None) {
                    ExecuteConnectionConfig(Game.GameType + ".def", 0, null, false);
                }
                else {
                    ExecuteConnectionConfig(Game.GameType + "." + CurrentServerInfo.GameMod + ".def", 0, null, false);
                }

                // load override global_vars.def
                ExecuteGlobalVarsConfig("global_vars.def", 0, null);

                ExecuteConnectionConfig("reasons.cfg", 0, null, false);

                lock (Parent) {
                    if (Username.Length == 0 || Parent.OptionsSettings.LayerHideLocalPlugins == false) {
                        CompilePlugins(Parent.OptionsSettings.PluginPermissions);
                    }
                }

                if (Parent.OptionsSettings.UsePluginOldStyleLoad == true) {
                    ExecuteConnectionConfig(FileHostNamePort + ".cfg", 0, null, false);
                }

                //this.m_blLoadingSavingConnectionConfig = false;

                // this.ManuallyDisconnected = true;

                // this.ConnectionError = false;

                BeginLoginSequence();

                if (Parent.OptionsSettings.UsePluginOldStyleLoad == false) {
                    ExecuteConnectionConfig(FileHostNamePort + ".cfg", 0, null, true);
                }

                IsLoadingSavingConnectionConfig = false;
            }
        }
 protected override void OnEnable()
 {
     PlayerDictionary.UpdateFriendsDictionary();
 }
 protected override void Awake()
 {
     PlayerDictionary.Init();
     base.Awake();
 }
Ejemplo n.º 20
0
 public FrozenUnderFogUpdatedByGps(ActorInitializer init)
 {
     self   = init.Self;
     traits = new PlayerDictionary <Traits>(init.World, player => new Traits(player, this));
 }
Ejemplo n.º 21
0
        private void InitialSetup() {
            if (Game != null) {
                IsLoadingSavingConnectionConfig = true;

                AssignEventHandlers();

                // Assume full access until we're told otherwise.
                Layer.Initialize(Parent, this);

                // I may move these events to within Layer, depends on the end of the restructure.
                Layer.LayerStarted += Layer_LayerOnline;
                Layer.LayerShutdown += Layer_LayerOffline;
                Layer.AccountPrivileges.AccountPrivilegeAdded += new AccountPrivilegeDictionary.AccountPrivilegeAlteredHandler(AccountPrivileges_AccountPrivilegeAdded);
                Layer.AccountPrivileges.AccountPrivilegeRemoved += new AccountPrivilegeDictionary.AccountPrivilegeAlteredHandler(AccountPrivileges_AccountPrivilegeRemoved);

                foreach (AccountPrivilege apPriv in Layer.AccountPrivileges) {
                    apPriv.AccountPrivilegesChanged += new AccountPrivilege.AccountPrivilegesChangedHandler(item_AccountPrivilegesChanged);
                }

                Privileges = new CPrivileges(CPrivileges.FullPrivilegesFlags);
                EventsLogging = new EventCaptures(this);
                Console = new ConnectionConsole(this);
                PunkbusterConsole = new PunkbusterConsole(this);
                ChatConsole = new ChatConsole(this);
                PluginConsole = new PluginConsole(this);
                MapGeometry = new MapGeometry(this);
                MapGeometry.MapZones.MapZoneAdded += new MapZoneDictionary.MapZoneAlteredHandler(MapZones_MapZoneAdded);
                MapGeometry.MapZones.MapZoneChanged += new MapZoneDictionary.MapZoneAlteredHandler(MapZones_MapZoneChanged);
                MapGeometry.MapZones.MapZoneRemoved += new MapZoneDictionary.MapZoneAlteredHandler(MapZones_MapZoneRemoved);

                if (CurrentServerInfo == null) {
                    CurrentServerInfo = new CServerInfo();
                }

                ListSettings = new ListsSettings(this);
                ServerSettings = new ServerSettings(this);
                PlayerListSettings = new PlayerListSettings();
                PlayerList = new PlayerDictionary();
                TeamNameList = new List<CTeamName>();
                MapListPool = new NotificationList<CMap>();
                ReservedSlotList = new NotificationList<string>();
                SpectatorList = new NotificationList<string>();
                Variables = new VariableDictionary();
                SV_Variables = new VariableDictionary();
                Reasons = new NotificationList<string>();
                FullVanillaBanList = new List<CBanInfo>();
                FullTextChatModerationList = new TextChatModerationDictionary();
                Weapons = new WeaponDictionary();
                Specializations = new SpecializationDictionary();

                if (Regex.Match(HostName, @"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$").Success == true) {
                    Variables.SetVariable("SERVER_COUNTRY", Parent.GetCountryName(HostName));
                    Variables.SetVariable("SERVER_COUNTRY_CODE", Parent.GetCountryCode(HostName));
                }
                else {
                    IPAddress ipServer = FrostbiteConnection.ResolveHostName(HostName);
                    Variables.SetVariable("SERVER_COUNTRY", Parent.GetCountryName(ipServer.ToString()));
                    Variables.SetVariable("SERVER_COUNTRY_CODE", Parent.GetCountryCode(ipServer.ToString()));
                }

                Console.Logging = Parent.OptionsSettings.ConsoleLogging;
                EventsLogging.Logging = Parent.OptionsSettings.EventsLogging;
                ChatConsole.Logging = Parent.OptionsSettings.ChatLogging;
                PluginConsole.Logging = Parent.OptionsSettings.PluginLogging;

                //this.m_blLoadingSavingConnectionConfig = true;

                if (CurrentServerInfo.GameMod == GameMods.None) {
                    ExecuteConnectionConfig(Game.GameType + ".def", 0, null, false);
                }
                else {
                    ExecuteConnectionConfig(Game.GameType + "." + CurrentServerInfo.GameMod + ".def", 0, null, false);
                }

                // load override global_vars.def
                ExecuteGlobalVarsConfig("global_vars.def", 0, null);

                ExecuteConnectionConfig("reasons.cfg", 0, null, false);

                lock (Parent) {
                    if (Username.Length == 0 || Parent.OptionsSettings.LayerHideLocalPlugins == false) {
                        CompilePlugins(Parent.OptionsSettings.PluginPermissions);
                    }
                }

                string configDirectoryPath = Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs"), FileHostNamePort);
                string oldConfigFilePath = Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs"), string.Format("{0}.cfg", FileHostNamePort));

                if (File.Exists(oldConfigFilePath) == false && Directory.Exists(configDirectoryPath) == true) {
                    string[] pluginConfigPaths = Directory.GetFiles(configDirectoryPath, "*.cfg");

                    if (Parent.OptionsSettings.UsePluginOldStyleLoad == true) {
                        foreach (string pluginConfigPath in pluginConfigPaths) {
                            ExecuteConnectionConfig(pluginConfigPath, 0, null, false);
                        }
                    }

                    BeginLoginSequence();

                    if (Parent.OptionsSettings.UsePluginOldStyleLoad == false) {
                        foreach (string pluginConfigPath in pluginConfigPaths) {
                            ExecuteConnectionConfig(pluginConfigPath, 0, null, true);
                        }
                    }

                    IsLoadingSavingConnectionConfig = false;
                }
                else {
                    if (Parent.OptionsSettings.UsePluginOldStyleLoad == true) {
                        ExecuteConnectionConfig(FileHostNamePort + ".cfg", 0, null, false);
                    }

                    BeginLoginSequence();

                    if (Parent.OptionsSettings.UsePluginOldStyleLoad == false) {
                        ExecuteConnectionConfig(FileHostNamePort + ".cfg", 0, null, true);
                    }

                    IsLoadingSavingConnectionConfig = false;
                    SaveConnectionConfig();

                    try
                    {
                        if (Directory.Exists(configDirectoryPath) == true && File.Exists(Path.Combine(configDirectoryPath, string.Format("{0}.cfg", FileHostNamePort))) == true)
                        {
                            try
                            {
                                if (File.Exists(oldConfigFilePath) == true) {
                                    File.Delete(oldConfigFilePath);
                                }
                            }
                            catch (Exception e) {
                                FrostbiteConnection.LogError("RemoveOldConfig", String.Empty, e);
                            }
                        }
                    }
                    catch (Exception e) {
                        FrostbiteConnection.LogError("MigrateConfig", "Error writing new config structure during migration", e);
                    }
                }

            }
        }