public IActionResult PostCreateGame([FromBody] Validators.GameCreate gameCreate)
        {
            Result result = this.CreateGame(gameCreate);

            if (result.ResultFunc == this.Ok)
            {
                PusherServer.Pusher pusher = Pusher.Pusher.Create();

                GameData game = (GameData)result.Data;
                //check if there is a player 2
                if (game.user2.id != null)
                {
                    pusher.TriggerAsync(channelName: this.PRIVATE_USER_CHANNELNAME + ((GameData)result.Data).user2.id, eventName: "game_invite", data: result.Data);
                }
                else
                {
                    pusher.TriggerAsync(channelName: this.PUBLIC_GAME_CHANNEL, eventName: "game_created", data: result.Data, options: new TriggerOptions()
                    {
                        SocketId = gameCreate.socket_id
                    });
                }
            }

            return(result.ResultFunc(result.Data));
        }
Esempio n. 2
0
        public PusherLiteMessageBusService(string appKey, string appId,
                                           string appSecret,
                                           string cluster, IAuthorizer authorizer = null)
        {
            _channelManager = new ConcurrentDictionary <MessageChannel, PusherMessageChannelOption>();
            _channelInitializationManager =
                new ConcurrentDictionary <MessageChannel, ReplaySubject <AddedChannelEvent> >();

            _broadcaster = new PusherServer.Pusher(appId, appKey,
                                                   appSecret,
                                                   new PusherOptions
            {
                Cluster   = cluster,
                Encrypted = true
            });

            _recipient = new PusherClient.Pusher(appKey,
                                                 new PusherClient.PusherOptions
            {
                Cluster    = cluster,
                Authorizer = authorizer
            });

            _recipient.Connected    += OnRecipientConnected;
            _recipient.Disconnected += OnRecipientDisconnected;
        }
Esempio n. 3
0
        public PusherMessengerImpl(string cluster, string appId, string appKey, string appSecret)
        {
            var options = new PusherOptions
            {
                Cluster   = cluster,
                Encrypted = true
            };

            _pusher = new PusherServer.Pusher(appId, appKey, appSecret, options);
        }
Esempio n. 4
0
        public void InitializePusherServer(string appId, string appKey, string appSecret, string customHost, bool useSSL = false)
        {
            var options = new PusherOptions();

            options.Encrypted = useSSL;
            if ((customHost != null) && (customHost != ""))
            {
                options.HostName = customHost;
            }

            pusherServer = new PusherServer.Pusher(appId, appKey, appSecret, options);
        }
Esempio n. 5
0
        public Publisher()
        {
            var options = new PusherOptions
            {
                Cluster   = Resources.PusherCluster,
                Encrypted = bool.Parse(Resources.PusherEncryped)
            };

            this.pusher = new PusherServer.Pusher(
                Resources.PusherAppId,
                Resources.PusherAppKey,
                Resources.PusherAppSecret,
                options);
        }
        public PusherMessageChannelOption(string eventName, PusherClient.Channel recipientChannel, PusherServer.Pusher externalBroadcaster)
        {
            if (string.IsNullOrEmpty(eventName))
            {
                throw new ArgumentException($"{nameof(eventName)} is required.");
            }

            _eventName = eventName;

            InternalBroadcaster  = new ReplaySubject <MessageContainer <object> >();
            _externalBroadcaster = externalBroadcaster;
            _recipient           = recipientChannel;

            recipientChannel.Bind(eventName, OnEventMessageReceived);
        }
        public IActionResult PostCreateMove([FromBody] Validators.Move move)
        {
            Result result = this.CreateMove(move);

            if (result.ResultFunc == this.Ok)
            {
                PusherServer.Pusher pusher = Pusher.Pusher.Create();
                pusher.TriggerAsync(channelName: this.PRIVATE_GAME_CHANNELNAME + ((GameData)result.Data).id, eventName: "create_move", data: result.Data, options: new TriggerOptions()
                {
                    SocketId = move.socket_id
                });
            }

            return(result.ResultFunc(result.Data));
        }
        public IActionResult UpdateJoinGame([FromBody] Validators.Game gameJoin)
        {
            Result result = this.JoinGame(gameJoin);

            if (result.ResultFunc == this.Ok)
            {
                PusherServer.Pusher pusher = Pusher.Pusher.Create();
                pusher.TriggerAsync(channelName: this.PRIVATE_GAME_CHANNELNAME + ((GameData)result.Data).id, eventName: "game_join", data: result.Data, options: new TriggerOptions()
                {
                    SocketId = gameJoin.socket_id
                });
            }

            return(result.ResultFunc(result.Data));
        }
Esempio n. 9
0
        private PusherServer.Pusher GetPusher()
        {
            var options = new PusherOptions
            {
                Cluster        = _options.Cluster,
                Encrypted      = true,
                JsonSerializer = new JsonSerializer()
            };

            var pusher = new PusherServer.Pusher(
                _options.AppId,
                _options.ApiKey,
                _options.AppSecret,
                options);

            return(pusher);
        }
Esempio n. 10
0
        public PusherUtil()
        {
            string pusherAppId     = ConfigurationManager.AppSettings["pusherAppId"];
            string pusherAppKey    = ConfigurationManager.AppSettings["pusherAppKey"];
            string pusherAppSecret = ConfigurationManager.AppSettings["pusherAppSecret"];

            _pusherOddsChannelName  = ConfigurationManager.AppSettings["pusherOddsChannelName"];
            _pusherScoreChannelName = ConfigurationManager.AppSettings["pusherScoreChannelName"];
            _pusherEventName        = ConfigurationManager.AppSettings["pusherEventName"];

            PusherOptions pusherOptions = new PusherOptions
            {
                Cluster   = "us2",
                Encrypted = true
            };

            _pusherServer      = new PusherServer.Pusher(pusherAppId, pusherAppKey, pusherAppSecret, pusherOptions);
            _messageDictionary = new Dictionary <string, string>();
        }
Esempio n. 11
0
        public AuthModule()
        {
            PusherServer.PusherOptions options = new PusherServer.PusherOptions
            {
                EncryptionMasterKey = Convert.FromBase64String(EncryptionMasterKeyText),
                Cluster             = Config.Cluster,
            };
            var provider = new PusherServer.Pusher(PusherApplicationId, PusherApplicationKey, PusherApplicationSecret, options);

            Post["/auth/{username}", ctx => ctx.Request.Form.channel_name && ctx.Request.Form.socket_id] = _ =>
            {
                Console.WriteLine($"Processing auth request for '{Request.Form.channel_name}' channel, for socket ID '{Request.Form.socket_id}'");

                string channelName = Request.Form.channel_name;
                string socketId    = Request.Form.socket_id;

                string authData = null;

                if (Channel.GetChannelType(channelName) == ChannelTypes.Presence)
                {
                    var channelData = new PresenceChannelData
                    {
                        user_id   = socketId,
                        user_info = new { Name = _.username.ToString() }
                    };

                    authData = provider.Authenticate(channelName, socketId, channelData).ToJson();
                }
                else
                {
                    authData = provider.Authenticate(channelName, socketId).ToJson();
                }

                if (Channel.GetChannelType(channelName) == ChannelTypes.PrivateEncrypted)
                {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                    SendSecretMessageAsync();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                }

                return(authData);
            };
        }
Esempio n. 12
0
        public string Authorize(string channelName, string socketId)
        {
            var provider = new PusherServer.Pusher(Config.AppId, Config.AppKey, Config.AppSecret);

            string authData;

            if (channelName.StartsWith("presence-"))
            {
                var channelData = new PresenceChannelData();
                channelData.user_id   = socketId;
                channelData.user_info = new { name = _userName };

                authData = provider.Authenticate(channelName, socketId, channelData).ToJson();
            }
            else
            {
                authData = provider.Authenticate(channelName, socketId).ToJson();
            }

            return(authData);
        }
Esempio n. 13
0
        private async Task SendSecretMessageAsync()
        {
            await Task.Delay(5000).ConfigureAwait(false);

            PusherServer.PusherOptions options = new PusherServer.PusherOptions
            {
                EncryptionMasterKey = Convert.FromBase64String(EncryptionMasterKeyText),
                Cluster             = Config.Cluster,
            };
            string channelName   = "private-encrypted-channel";
            string eventName     = "secret-event";
            var    provider      = new PusherServer.Pusher(PusherApplicationId, PusherApplicationKey, PusherApplicationSecret, options);
            string secretMessage = $"sent secret at {DateTime.Now} on '{channelName}' using event '{eventName}'.";
            await provider.TriggerAsync(channelName, eventName, new
            {
                Name    = nameof(AuthModule),
                Message = secretMessage,
            }).ConfigureAwait(false);

            Console.WriteLine(secretMessage);
        }
        public async Task <string> AuthorizeAsync(string channelName, string socketId)
        {
            string authData = null;
            double delay    = (await LatencyInducer.InduceLatencyAsync(MinLatency, MaxLatency)) / 1000.0;

            Trace.TraceInformation($"{this.GetType().Name} paused for {Math.Round(delay, 3)} second(s)");
            await Task.Run(() =>
            {
                PusherServer.PusherOptions options = new PusherServer.PusherOptions
                {
                    EncryptionMasterKey = _encryptionKey,
                    Cluster             = Config.Cluster,
                };
                var provider = new PusherServer.Pusher(Config.AppId, Config.AppKey, Config.AppSecret, options);
                if (channelName.StartsWith("presence-"))
                {
                    var channelData = new PresenceChannelData
                    {
                        user_id   = socketId,
                        user_info = new FakeUserInfo {
                            name = _userName
                        }
                    };

                    authData = provider.Authenticate(channelName, socketId, channelData).ToJson();
                }
                else
                {
                    authData = provider.Authenticate(channelName, socketId).ToJson();
                }

                if (channelName.Contains(TamperToken))
                {
                    authData = authData.Replace("1", "2");
                }
            }).ConfigureAwait(false);

            return(authData);
        }