예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LilaTournament"/> class.
        /// </summary>
        /// <param name="c">The client.</param>
        /// <param name="socket">The socket.</param>
        /// <param name="tournamentData">The tournament data.</param>
        internal LilaTournament(LilaClient c, LilaSocket socket, TournamentData tournamentData)
        {
            tournamentPing = new PPingVersion(0);
            Version        = tournamentData.SocketVersion;

            Client = c;

            this.socket         = socket;
            this.tournamentData = tournamentData;

            socket.OnDisconnect += OnDisconnect;

            socket.AddHandler <MPong>(OnPong);
            socket.AddHandler <MCrowd>(OnCrowd);
            socket.AddHandler <MReload>(OnReload);
            socket.AddHandler <MMessage>(OnMessage);
            socket.AddHandler <MTournamentRedirect>(OnRedirect);
            socket.AddHandler <MTournamentReminder>(OnReminder);
            socket.AddHandler <MResync>(OnResync);
            socket.AddHandler <MChallenges>(OnChallenges);
            socket.AddHandler <MDeployPre>(OnDeployPre);
            socket.AddHandler <MFollowingPlaying>(OnFollowingPlaying);
            socket.AddHandler <MFollowingStoppedPlaying>(OnFollowingStoppedPlaying);
            socket.AddHandler <MFollowingOnlines>(OnFollowingOnline);

            SendPing();
            socket.SchedulePacket(tournamentPing, 1000);
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LilaGame"/> class.
        /// </summary>
        /// <param name="c">The c.</param>
        /// <param name="socket">The socket.</param>
        /// <param name="gameData">The game data.</param>
        internal LilaGame(LilaClient c, LilaSocket socket, GameData gameData)
        {
            gamePing = new PPingVersion(0);
            Version  = gameData.Player.Version;
            curClock = new ClockData
            {
                White = gameData.Clock.White,
                Black = gameData.Clock.Black
            };

            Client = c;

            this.socket   = socket;
            this.gameData = gameData;

            socket.OnDisconnect += OnDisconnect;

            socket.AddHandler <MPong>(OnPong);
            socket.AddHandler <MMove>(OnMove);
            socket.AddHandler <MGameMessages>(OnGameEvent);
            socket.AddHandler <MReload>(OnReload);
            socket.AddHandler <MMessage>(OnMessage);
            socket.AddHandler <MEnd>(OnEnd);
            socket.AddHandler <MEndData>(OnEndData);
            socket.AddHandler <MTakebackOffer>(OnTakebackOffer);
            socket.AddHandler <MAck>(OnAck);
            socket.AddHandler <MGone>(OnGone);
            socket.AddHandler <MCrowd>(OnCrowd);
            socket.AddHandler <MClock>(OnClock);
            socket.AddHandler <MChallenges>(OnChallenges);
            socket.AddHandler <MResync>(OnResync);
            socket.AddHandler <MRoundRedirect>(OnRedirect);
            socket.AddHandler <MCheckCount>(OnCheckCount);
            socket.AddHandler <MTournamentReminder>(OnReminder);
            socket.AddHandler <MBerserk>(OnBerserk);
            socket.AddHandler <MClockIncrement>(OnClockInc);
            socket.AddHandler <MTournamentStandings>(OnStandings);
            socket.AddHandler <MDeployPre>(OnDeployPre);

            socket.AddVersionHandler <MVersion>(OnVersion);

            SendPing();
            socket.SchedulePacket(gamePing, 1000);

            random = new Random();
        }
예제 #3
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;
            }
        }