Exemple #1
0
        internal byte[] ReceiveData()
        {
            try
            {
                //Orignally I thought about clearing the buffer here, but I changed
                //my mind since you should never get more bytes in the returned
                //buffer than what you receive.

                SessionSocket.ReceiveTimeout = MillisecondTimeout;
                int bytesRecvd = SessionSocket.Receive(_receiveBuffer);


                byte[] retVal = new byte[bytesRecvd];
                Buffer.BlockCopy(_receiveBuffer, 0, retVal, 0, bytesRecvd);

                return(retVal);
            }
            catch (SocketException se)
            {
                //The connection has timed out probably
                if (OnSocketError != null)
                {
                    OnSocketError(se);
                }
            }

            return(null);
        }
Exemple #2
0
 public static ActionLiveModel Convert(SessionSocket socket)
 => new ActionLiveModel()
 {
     ID   = socket.Action.Key,
     sid  = socket.Session.Key,
     srid = socket.Session.Request.GetStringID(),
     li   = socket.LastInteraction,
     crt  = socket.Created
 };
Exemple #3
0
 void StartSessionSocket()
 {
     sessionSocket = new SessionSocket(liveGameData)
     {
         OnSessionStarted = OnNewSession,
         OnGameEnded      = SetGameEnded
     };
     sessionSocket.ConnectAsync();
 }
        internal int SendData(byte[] data)
        {
            if (!Connected)
            {
                return(-1);
            }

            try
            {
                return(SessionSocket.Send(data));
            }
            catch (SocketException se)
            {
                OnSocketError?.Invoke(se);
            }

            return(-1);
        }
Exemple #5
0
        internal int SendData(byte[] Data)
        {
            if (!Connected)
            {
                return(-1);
            }

            try
            {
                return(SessionSocket.Send(Data));
            }
            catch (SocketException se)
            {
                if (OnSocketError != null)
                {
                    OnSocketError(se);
                }
            }

            return(-1);
        }
 public CommunicationBase(SessionSocket socket)
 {
     this.Socket = socket;
 }
 public PrelanderCommunication(SessionSocket socket) : base(socket)
 {
 }
Exemple #8
0
        public IActionResult Index(string type, string dbg, string recompile = "0")
        {
            return(this.Ok("notActive"));

            Response.ContentType = "text/javascript";
            if (string.IsNullOrEmpty(type))
            {
                return(this.Content("console.error('ccsocket:: type missing');"));
            }

            SessionType sessionType = SessionType.Default;

            if (type.ToLower().Equals("pl"))
            {
                sessionType = SessionType.Prelander;
            }
            else if (type.ToLower().Equals("lp"))
            {
                sessionType = SessionType.Lander;
            }
            else
            {
                return(this.Content("console.error('ccsocket:: uknown type');"));
            }

            #region #compile.js#

            string js_extension = string.Empty;
            if (string.IsNullOrEmpty(ClientJS) || recompile.Equals("1"))
            {
                string path = this.HostingEnvironment.WebRootPath + @"/js/compiled/client.js";
                ClientJS = (new JSMinify.Minify(path)).getModifiedData();
            }

            if (sessionType == SessionType.Prelander)
            {
                if (string.IsNullOrEmpty(PrelanderJS) || recompile.Equals("1"))
                {
                    string path = this.HostingEnvironment.WebRootPath + @"/js/shared/prelander.js";
                    PrelanderJS = (new Microsoft.Ajax.Utilities.Minifier().MinifyJavaScript(System.IO.File.ReadAllText(path)));
                }
                js_extension = PrelanderJS;
            }
            else if (sessionType == SessionType.Lander)
            {
                if (string.IsNullOrEmpty(LanderJS) || recompile.Equals("1"))
                {
                    string path = this.HostingEnvironment.WebRootPath + @"/js/shared/lander.js";
                    LanderJS = (new Microsoft.Ajax.Utilities.Minifier().MinifyJavaScript(System.IO.File.ReadAllText(path)));
                }
                js_extension = LanderJS;
            }

            #endregion

            SessionSocket socket = null;
            try
            {
                //socket = new SessionSocket(this.Context, sessionType);
            }
            catch (Exception e)
            {
                Logger.Instance.LogException(e);
                return(this.Content("console.error('ccsocket:: error 500');"));
            }

            var    baseUrl   = $"{(this.Request.Scheme.Equals("https") ? "wss" : "ws")}://{this.Request.Host.Value.ToString()}{this.Request.PathBase.Value.ToString()}";
            string variables = "var CC=Object;";
            variables += string.Format("CC.dbg={0};", string.IsNullOrEmpty(dbg) || dbg.Equals("0") ? "false" : "true");
            variables += string.Format("CC.host='{0}';", baseUrl);
            variables += string.Format("CC.type='{0}';", type.ToLower());
            variables += string.Format("CC.sguid='{0}';", socket.Key);
            variables += string.Format("CC.uid='{0}';", socket.User.Key);

            ApiSocketServer.AddSession(socket);

            return(this.ReturnContent(variables + ClientJS + js_extension));
        }
Exemple #9
0
 public LanderCommunicationChannel(SessionSocket session) : base(session)
 {
 }
Exemple #10
0
        public async Task <IActionResult> Index(string type, string data)
        {
            SocketBackupControllerLogger logger = new SocketBackupControllerLogger(
                this.Context.CookiesGet(Constants.ActionID),
                this.Context.CookiesGet(Constants.UserGuidCookie),
                this.Context.CookiesGetInt(Constants.CountryID),
                this.Context.HttpContext.Request.Headers["User-Agent"]);

            SessionType   sessionType = (type.Equals("lp") ? Sockets.ApiSockets.Models.SessionType.Lander : Sockets.ApiSockets.Models.SessionType.Prelander);
            SessionSocket socket      = new SessionSocket(this.Context, sessionType);

            ActionDM action = socket.Action.Data;

            if (action == null)
            {
                logger.StartLoggin("")
                .Add("type", type)
                .Add("data", data)
                .OnException(new Exception("Could not load action"));
                return(this.ReturnObject(new DistributionModel()
                {
                    Status = false
                }));
            }

            string[] split = data.Split('|');
            if (split.Length != 2)
            {
                logger.StartLoggin("")
                .Add("type", type)
                .Add("data", data)
                .OnException(new Exception("Could not get data from object"));
                return(this.ReturnObject(new DistributionModel()
                {
                    Status = false
                }));
            }

            string userID  = socket.User.Key;
            int?   country = socket.CountryID;

            if (action.http_flow == false)
            {
                action.http_flow = true;
                action.UpdateLater();
            }

            try
            {
                if (type.Equals("pl"))
                {
                    PrelanderCommunicationChannel channel = new PrelanderCommunicationChannel(logger, action, userID, country, this.Database);
                    return(this.ReturnObject(await channel.Call(split[0], split[1])));
                }
                else if (type.Equals("lp"))
                {
                    LanderCommunicationChannel channel = new LanderCommunicationChannel(logger, action, userID, country, this.Database);
                    return(this.ReturnObject(await channel.Call(split[0], split[1])));
                }
                else
                {
                    logger.StartLoggin("")
                    .Add("type", type)
                    .Add("data", data)
                    .OnException(new Exception("Type was not present "));
                    return(this.ReturnObject(new DistributionModel()
                    {
                        Status = false
                    }));
                }
            }
            catch (Exception e)
            {
                logger.StartLoggin("")
                .Add("type", type)
                .Add("data", data)
                .OnException(e);
                return(this.ReturnObject(new DistributionModel()
                {
                    Status = false
                }));
            }
        }
 public SharedCommunication(SessionSocket socket) : base(socket)
 {
 }