Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // We store the game in the Session, but use a dictionary keyed by GUIDs which
            // are stored in the ViewState. This allows the same user in the same browser
            // to open multiple games in different browser tabs.

            if (Games == null)
            {
                Games = new Dictionary<string, PlayerHandler>();
            }

            if (OutputBuffers == null)
            {
                OutputBuffers = new Dictionary<string, OutputBuffer>();
            }

            if (Resources == null)
            {
                Resources = new SessionResources();
            }

            m_gameId = (string)ViewState["GameId"];
            if (m_gameId == null)
            {
                m_gameId = Guid.NewGuid().ToString();
                ViewState["GameId"] = m_gameId;
            }

            if (Page.IsPostBack)
            {
                if (Games.ContainsKey(m_gameId))
                {
                    m_player = Games[m_gameId];
                }

                if (!OutputBuffers.ContainsKey(m_gameId))
                {
                    // TO DO: Think this only ever happens while debugging?
                    return;
                }
                m_buffer = OutputBuffers[m_gameId];
            }
            else
            {
                m_buffer = new OutputBuffer();
                OutputBuffers.Add(m_gameId, m_buffer);

                bool saveVisible = IsLoggedIn && (!string.IsNullOrEmpty(Request["id"]) || !string.IsNullOrEmpty(Request["load"]));
                m_buffer.AddJavaScriptToBuffer("showSaveButton", new BooleanParameter(saveVisible));
            }
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // We store the game in the Session, but use a dictionary keyed by GUIDs which
            // are stored in the ViewState. This allows the same user in the same browser
            // to open multiple games in different browser tabs.

            if (Games == null)
            {
                Games = new Dictionary <string, PlayerHandler>();
            }

            if (OutputBuffers == null)
            {
                OutputBuffers = new Dictionary <string, OutputBuffer>();
            }

            if (Resources == null)
            {
                Resources = new SessionResources();
            }

            m_gameId = (string)ViewState["GameId"];
            if (m_gameId == null)
            {
                m_gameId            = Guid.NewGuid().ToString();
                ViewState["GameId"] = m_gameId;
            }

            if (Page.IsPostBack)
            {
                if (Games.ContainsKey(m_gameId))
                {
                    m_player = Games[m_gameId];
                }

                if (!OutputBuffers.ContainsKey(m_gameId))
                {
                    // TO DO: Think this only ever happens while debugging?
                    return;
                }
                m_buffer = OutputBuffers[m_gameId];
            }
            else
            {
                m_buffer = new OutputBuffer(m_gameId);
                OutputBuffers.Add(m_gameId, m_buffer);
                m_buffer.AddJavaScriptToBuffer("setOutputBufferId", new StringParameter(m_gameId));
            }
        }
Ejemplo n.º 3
0
        public void ProcessRequest(HttpContext context)
        {
            SessionResources resources = context.Session["Resources"] as SessionResources;
            string           id        = context.Request["id"];
            string           filename  = context.Request["filename"];

            if (resources == null || id == null || filename == null)
            {
                context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                return;
            }

            Stream stream = resources.Get(id, filename);

            if (stream == null)
            {
                context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                Logging.Log.InfoFormat("File not found: {0}", filename);
                return;
            }

            string contentType = PlayerHelper.GetContentType(filename);

            if (string.IsNullOrEmpty(contentType))
            {
                Logging.Log.InfoFormat("Unknown content type for resource {0}", filename);
                context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                return;
            }

            Logging.Log.DebugFormat("Sending resource {0}:'{1}', format is '{2}'", id, filename, contentType);
            context.Response.ContentType = contentType;

            int fileSize = (int)stream.Length;

            byte[] buffer = new byte[fileSize];
            stream.Read(buffer, 0, fileSize);
            stream.Close();
            context.Response.BinaryWrite(buffer);
        }
Ejemplo n.º 4
0
        string AddResource(string filename)
        {
            SessionResources resources = Session["Resources"] as SessionResources;
            if (resources == null)
            {
                resources = new SessionResources();
                Session["Resources"] = resources;
            }

            return resources.Add(filename);
        }