Ejemplo n.º 1
0
    public static string GetSessionToken(string Email)
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();
            Guid token             = Guid.NewGuid();

            List <UserSession> usList = (from t in dc.UserSessions
                                         where t.UserID == GetUser(Email).UserID
                                         select t).ToList <UserSession>();

            dc.UserSessions.DeleteAllOnSubmit <UserSession>(usList);

            UserSession us = new UserSession();
            us.UserID       = GetUser(Email).UserID;
            us.ExpiresOn    = DateTime.Now.AddHours(1);
            us.SessionToken = token.ToString();

            dc.UserSessions.InsertOnSubmit(us);
            dc.SubmitChanges();

            return(token.ToString());
        }
        catch
        {
            return(string.Empty);
        }
    }
Ejemplo n.º 2
0
    public static List <ChatMessage> ChatInit()
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            List <LinqGameChat> lList = (from c in dc.LinqGameChats
                                         where c.PostedAt > DateTime.Now.Subtract(new TimeSpan(0, 5, 0))
                                         select c).ToList <LinqGameChat>();

            List <ChatMessage> cmList = new List <ChatMessage>();

            if (lList.Count > 0)
            {
                foreach (LinqGameChat lgc in lList)
                {
                    cmList.Add(new ChatMessage(lgc));
                }
            }
            else
            {
                LinqGameChat lgc = (from c in dc.LinqGameChats
                                    orderby c.ChatLineID descending
                                    select c).First <LinqGameChat>();

                cmList.Add(new ChatMessage(lgc));
            }

            return(cmList);
        }
        catch
        {
            return(new List <ChatMessage>());
        }
    }
Ejemplo n.º 3
0
    public static List<ChatMessage> ChatInit()
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            List<LinqGameChat> lList = (from c in dc.LinqGameChats
                                        where c.PostedAt > DateTime.Now.Subtract(new TimeSpan(0, 5, 0))
                                        select c).ToList<LinqGameChat>();

            List<ChatMessage> cmList = new List<ChatMessage>();

            if (lList.Count > 0)
            {
                foreach (LinqGameChat lgc in lList)
                {
                    cmList.Add(new ChatMessage(lgc));
                }
            }
            else
            {
                LinqGameChat lgc = (from c in dc.LinqGameChats
                                    orderby c.ChatLineID descending
                                    select c).First<LinqGameChat>();

                cmList.Add(new ChatMessage(lgc));
            }

            return cmList;
        }
        catch
        {
            return new List<ChatMessage>();
        }
    }
Ejemplo n.º 4
0
    public static int GetWordCount()
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            return((from w in dc.LinqWords
                    where w.IsRemoved == false
                    select w.WordID).Count <int>());
        }
        catch
        {
            return(0);
        }
    }
Ejemplo n.º 5
0
    public static User GetUser(string Email)
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            User u = (from user in dc.Users
                      where user.Email == Email
                      select user).First <User>();

            return(u);
        }
        catch
        {
            return(new User());
        }
    }
Ejemplo n.º 6
0
    public static bool CheckUserCredentials(string Email, string Password)
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            User u = (from user in dc.Users
                      where user.Email == Email
                      select user).First <User>();

            return(u.VerificationToken == GetVerificationHash(Email, Password));
        }
        catch
        {
            return(false);
        }
    }
Ejemplo n.º 7
0
    public static bool CheckUserCredentials(string Email, string Password)
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            User u = (from user in dc.Users
                      where user.Email == Email
                      select user).First<User>();

            return (u.VerificationToken == GetVerificationHash(Email, Password));
        }
        catch
        {
            return false;
        }
    }
Ejemplo n.º 8
0
    public static string GetRandomWord()
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            Random r     = new Random();
            int    place = r.Next(0, GetWordCount());

            return((from w in dc.LinqWords
                    where w.IsRemoved == false
                    orderby w.WordID
                    select w.Word).ToArray <string>()[place]);
        }
        catch
        {
            return(string.Empty);
        }
    }
Ejemplo n.º 9
0
    public static bool InsertWord(string Word)
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            LinqWord word = new LinqWord();
            word.Word      = Word;
            word.IsRemoved = false;

            dc.LinqWords.InsertOnSubmit(word);
            dc.SubmitChanges();

            return(true);
        }
        catch
        {
            return(false);
        }
    }
Ejemplo n.º 10
0
    public static bool CheckSessionToken(string token)
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            UserSession us = (from t in dc.UserSessions
                              where t.SessionToken == token &&
                              t.ExpiresOn > DateTime.Now
                              select t).First <UserSession>();

            us.ExpiresOn = DateTime.Now.AddHours(1);

            dc.SubmitChanges();

            return(true);
        }
        catch
        {
            return(false);
        }
    }
Ejemplo n.º 11
0
    public static bool CheckSessionToken(string token)
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            UserSession us = (from t in dc.UserSessions
                              where t.SessionToken == token &&
                                t.ExpiresOn > DateTime.Now
                              select t).First<UserSession>();

            us.ExpiresOn = DateTime.Now.AddHours(1);

            dc.SubmitChanges();

            return true;
        }
        catch
        {
            return false;
        }
    }
Ejemplo n.º 12
0
    public static bool PostChat(string email, string message)
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            LinqGameChat lgc = new LinqGameChat();
            lgc.IsExCathedra = false;
            lgc.PostedAt     = DateTime.Now;
            lgc.GameID       = 1; // Lobby - for testing
            lgc.UserID       = GetUser(email).UserID;
            lgc.ChatText     = message;

            dc.LinqGameChats.InsertOnSubmit(lgc);
            dc.SubmitChanges();

            return(true);
        }
        catch
        {
            return(false);
        }
    }
Ejemplo n.º 13
0
    public static bool CreateUser(string Email, string Nickname, string Password)
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            User u = new User();
            u.Email             = Email;
            u.Nickname          = Nickname;
            u.VerificationToken = GetVerificationHash(Email, Password);

            u.IsAdmin  = false;
            u.JoinDate = DateTime.Now;

            dc.Users.InsertOnSubmit(u);
            dc.SubmitChanges();

            return(true);
        }
        catch
        {
            return(false);
        }
    }
Ejemplo n.º 14
0
    public static List <ChatMessage> GetLatestChat(int AfterChatLineID)
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            List <LinqGameChat> lList = (from c in dc.LinqGameChats
                                         where c.ChatLineID > AfterChatLineID
                                         select c).ToList <LinqGameChat>();

            List <ChatMessage> cmList = new List <ChatMessage>();

            foreach (LinqGameChat lgc in lList)
            {
                cmList.Add(new ChatMessage(lgc));
            }

            return(cmList);
        }
        catch
        {
            return(new List <ChatMessage>());
        }
    }
Ejemplo n.º 15
0
    public static List<ChatMessage> GetLatestChat(int AfterChatLineID)
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            List<LinqGameChat> lList = (from c in dc.LinqGameChats
                                        where c.ChatLineID > AfterChatLineID
                                        select c).ToList<LinqGameChat>();

            List<ChatMessage> cmList = new List<ChatMessage>();

            foreach (LinqGameChat lgc in lList)
            {
                cmList.Add(new ChatMessage(lgc));
            }

            return cmList;
        }
        catch
        {
            return new List<ChatMessage>();
        }
    }
Ejemplo n.º 16
0
    public static string GetRandomWord()
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            Random r = new Random();
            int place = r.Next(0, GetWordCount());

            return (from w in dc.LinqWords
                    where w.IsRemoved == false
                    orderby w.WordID
                    select w.Word).ToArray<string>()[place];
        }
        catch
        {
            return string.Empty;
        }
    }
Ejemplo n.º 17
0
    public static string GetSessionToken(string Email)
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();
            Guid token = Guid.NewGuid();

            List<UserSession> usList = (from t in dc.UserSessions
                                        where t.UserID == GetUser(Email).UserID
                                        select t).ToList<UserSession>();

            dc.UserSessions.DeleteAllOnSubmit<UserSession>(usList);

            UserSession us = new UserSession();
            us.UserID = GetUser(Email).UserID;
            us.ExpiresOn = DateTime.Now.AddHours(1);
            us.SessionToken = token.ToString();

            dc.UserSessions.InsertOnSubmit(us);
            dc.SubmitChanges();

            return token.ToString();
        }
        catch
        {
            return string.Empty;
        }
    }
Ejemplo n.º 18
0
    public static User GetUser(string Email)
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            User u = (from user in dc.Users
                      where user.Email == Email
                      select user).First<User>();

            return u;
        }
        catch
        {
            return new User();
        }
    }
Ejemplo n.º 19
0
    public static int GetWordCount()
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            return (from w in dc.LinqWords
                    where w.IsRemoved == false
                    select w.WordID).Count<int>();
        }
        catch
        {
            return 0;
        }
    }
Ejemplo n.º 20
0
    public static bool CreateUser(string Email, string Nickname, string Password)
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            User u = new User();
            u.Email = Email;
            u.Nickname = Nickname;
            u.VerificationToken = GetVerificationHash(Email, Password);

            u.IsAdmin = false;
            u.JoinDate = DateTime.Now;

            dc.Users.InsertOnSubmit(u);
            dc.SubmitChanges();

            return true;
        }
        catch
        {
            return false;
        }
    }
Ejemplo n.º 21
0
    public static bool PostChat(string email, string message)
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            LinqGameChat lgc = new LinqGameChat();
            lgc.IsExCathedra = false;
            lgc.PostedAt = DateTime.Now;
            lgc.GameID = 1; // Lobby - for testing
            lgc.UserID = GetUser(email).UserID;
            lgc.ChatText = message;

            dc.LinqGameChats.InsertOnSubmit(lgc);
            dc.SubmitChanges();

            return true;
        }
        catch
        {
            return false;
        }
    }
Ejemplo n.º 22
0
    public static bool InsertWord(string Word)
    {
        try
        {
            LinqGameDataContext dc = new LinqGameDataContext();

            LinqWord word = new LinqWord();
            word.Word = Word;
            word.IsRemoved = false;

            dc.LinqWords.InsertOnSubmit(word);
            dc.SubmitChanges();

            return true;
        }
        catch
        {
            return false;
        }
    }