Esempio n. 1
0
        public static void testSession()
        {
            Server.Session session = new Server.Session("test");
            session.dump();

            Console.WriteLine("Getting name: " + session.get("name"));

            session.set("name", "Test");
            session.dump();

            session.unset();
            session.dump();
        }
Esempio n. 2
0
        public UserControler(HttpListenerContext Context, Models.UserModel Model, Map.Map World)
        {
            context = Context;
            model = Model;
            world = World;

            Cookie sessid = context.Request.Cookies["sessid"];
            string sid = (sessid != null && !sessid.Expired) ? sessid.Value.ToString() : "";
            //Console.WriteLine("Try to connect with {0} session.", sid);

            if (sid.Length == 0 || sid.Equals("0"))
            {
                sid = Guid.NewGuid().ToString();
            }

            session = new Session(sid);

            if (!session.isEmpty() && !session.isValid())
            {
                bool found = false;

                session.unset();
                while (!found)
                {
                    sid = Guid.NewGuid().ToString();
                    if (!File.Exists(Session.SAVE_PATH + sid + ".session"))
                    {
                        found = true;
                    }
                }

                session = new Session(sid);
            }

            if (session.isEmpty())
            {
                session.set("user", "Anonymous");
            }
            //Console.WriteLine("Creating session {0}", sid);
            Cookie cookie = new Cookie("sessid", sid);
            cookie.Expires = session.getExpiration();
            context.Response.Cookies.Add(cookie);
        }