Ejemplo n.º 1
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="finalize"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        public void Dispose(bool finalize)
        {
            _disposing = true;
            if (random != null)
            {
                random.Dispose();
                random = null;
            }

            if (lobbyCon != null)
            {
                lobbyCon.Dispose();
                lobbyCon = null;
            }

            if (challengeCon != null)
            {
                challengeCon.Dispose();
                challengeCon = null;
            }

            if (gameCons != null)
            {
                foreach (KeyValuePair <string, LilaGame> game in gameCons)
                {
                    log.ConditionalDebug("Disconnecting {0}", game.Key);
                    game.Value.Dispose();
                }

                gameCons = null;
            }

            if (tournamentCons != null)
            {
                foreach (KeyValuePair <string, LilaTournament> tournament in tournamentCons)
                {
                    log.ConditionalDebug("Disconnecting {0}", tournament.Key);
                    tournament.Value.Dispose();
                }

                tournamentCons = null;
            }

            if (finalize)
            {
                GC.SuppressFinalize(this);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LilaClient"/> class.
        /// </summary>
        /// <param name="culture">The culture of the client.</param>
        /// <param name="settings">The settings for the client to use.</param>
        public LilaClient(CultureInfo culture, LilaSettings settings)
        {
            random         = new LilaRandom();
            tournamentCons = new ConcurrentDictionary <string, LilaTournament>();
            gameCons       = new ConcurrentDictionary <string, LilaGame>();

            //#Lobby Connection
            lobbyCon = new LilaSocket("Lobby-Socket", ResourceType.Thread);
            lobbyCon.OnDisconnect += OnLobbyDisconnect;

            //#Challenge Connection
            challengeCon = new LilaSocket("Challenge-Socket", ResourceType.Task);
            challengeCon.OnDisconnect += OnChallengeDisconnect;

            //#Hooks
            joinLock = new object();
            hookLock = new object();
            hooks    = new List <IHook>();

            //#Json
            jsonSettings = new JsonSerializerSettings
            {
                Formatting       = Formatting.None,
                Error            = OnJsonParseError,
                ContractResolver = new PacketResolver()
            };

            //#Packets
            _lobbyPing      = new PP();
            _challengePing  = new PP();
            _challengePing2 = new PPing();
            _gamePing       = new PP();

            //#Lobby Events
            Events = new LilaEvents();
            lobbyCon.AddHandler <MPong>(OnLobbyPong);
            lobbyCon.AddHandler <MServerLatency>(OnLag);
            lobbyCon.AddHandler <MRemovedHooks>(OnHooksRemoved);
            lobbyCon.AddHandler <MNewHook>(OnNewHook);
            lobbyCon.AddHandler <MHookSync>(OnHookSync);
            lobbyCon.AddHandler <MHooks>(OnHooks);
            lobbyCon.AddHandler <MReloadSeeks>(OnReloadSeeks);
            lobbyCon.AddHandler <MRoundRedirect>(OnRedirect);
            lobbyCon.AddHandler <MChallenges>(OnChallenges);
            lobbyCon.AddHandler <MTournaments>(OnTournaments);
            lobbyCon.AddHandler <MSimuls>(OnSimuls);
            lobbyCon.AddHandler <MStreams>(OnStreams);
            lobbyCon.AddHandler <MFeatured>(OnFeatured);
            lobbyCon.AddHandler <MTournamentReminder>(OnReminder);
            lobbyCon.AddHandler <MReloadForum>(OnReloadForum);
            lobbyCon.AddHandler <MReloadTimeline>(OnReloadTimeline);
            lobbyCon.AddHandler <MDeployPre>(OnDeployPre);
            lobbyCon.AddHandler <MFollowingPlaying>(OnFollowingPlaying);
            lobbyCon.AddHandler <MFollowingStoppedPlaying>(OnFollowingStoppedPlaying);
            lobbyCon.AddHandler <MFollowingOnlines>(OnFollowingOnline);

            challengeCon.AddHandler <MPong>(OnChallengePong);
            challengeCon.AddHandler <MChallenges>(OnChallenges);
            challengeCon.AddHandler <MReload>(OnChallengeReload);

            //#Scheduled packets
            lobbyCon.SchedulePacket(_lobbyPing, 1000);
            challengeCon.SchedulePacket(_challengePing, 1000);
            challengeCon.SchedulePacket(_challengePing2, 2000);

            if (culture == null)
            {
                Culture = CultureInfo.CurrentCulture;
            }
            else
            {
                Culture = culture;
            }

            if (settings == null)
            {
                lilaSettings = new LilaSettings();
            }
            else
            {
                lilaSettings = settings;
            }
        }