Exemple #1
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;
            }
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LilaClient"/> class.
 /// </summary>
 /// <param name="settings">The settings for the client to use.</param>
 public LilaClient(LilaSettings settings) : this(CultureInfo.CurrentCulture, settings)
 {
 }