public bool getUserData(int userId, int scienceNodeCount, out Models.UserDataModel userData)
        {
            userData = new Models.UserDataModel();
            MySqlCommand com = client.CreateCommand();

            com.CommandText = "SELECT * FROM userdata WHERE userid=" + userId;
            com.Connection  = client;

            MySqlDataReader reader = null;

            try
            {
                reader = com.ExecuteReader(new System.Data.CommandBehavior());

                if (reader.Read())  // tek column okusak yeter, o yuzden while yapmadim.
                {
                    userData.userId     = userId;
                    userData.physPoints = (int)reader["physpoints"];
                    userData.chemPoints = (int)reader["chempoints"];
                    userData.bioPoints  = (int)reader["biopoints"];

                    byte[] scienceNodesByte = (byte[])reader["unlockedsciencenodes"];

                    bool[] unlockedScienceNodeDbIds = new bool[scienceNodeCount];

                    for (int i = 0; i < scienceNodeCount && i < scienceNodesByte.Length * 8; i++)
                    {
                        unlockedScienceNodeDbIds[i] = (scienceNodesByte[i / 8] & (1 << (i % 8))) != 0;
                    }

                    userData.unlockedScienceNodes = new bool[scienceNodeCount];

                    foreach (var nodeDbIdPair in ScienceNode.scienceNodeDbIds)  // dbId'leri, typeId ye donusturuyoruz. Cunku db disinda bize lazim degil dbId. indexlerde hep typeId lazim.
                    {
                        userData.unlockedScienceNodes[TypeIdGenerator.getScienceNodeIds(nodeDbIdPair.Key.GetType())] = unlockedScienceNodeDbIds[nodeDbIdPair.Value];
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
            finally
            {
                try
                {
                    reader.Close();
                }
                catch { }
            }
        }
        public bool getUserData(int userId, int scienceNodeCount, out Models.UserDataModel userData)
        {
            userData = new Models.UserDataModel();
            MySqlCommand com = client.CreateCommand();
            com.CommandText = "SELECT * FROM userdata WHERE userid=" + userId;
            com.Connection = client;

            MySqlDataReader reader=null;
            try
            {
                reader = com.ExecuteReader(new System.Data.CommandBehavior());

                if (reader.Read())  // tek column okusak yeter, o yuzden while yapmadim.
                {
                    userData.userId = userId;
                    userData.physPoints = (int)reader["physpoints"];
                    userData.chemPoints = (int)reader["chempoints"];
                    userData.bioPoints  = (int)reader["biopoints"];

                    byte[] scienceNodesByte = (byte[])reader["unlockedsciencenodes"];

                    bool[] unlockedScienceNodeDbIds = new bool[scienceNodeCount];
                    
                    for (int i = 0; i < scienceNodeCount && i < scienceNodesByte.Length * 8; i++)
                    {
                        unlockedScienceNodeDbIds[i] = ( scienceNodesByte[i/8] & (1 << (i%8 ) )) != 0;

                    }

                    userData.unlockedScienceNodes = new bool[scienceNodeCount];

                    foreach (var nodeDbIdPair in ScienceNode.scienceNodeDbIds)  // dbId'leri, typeId ye donusturuyoruz. Cunku db disinda bize lazim degil dbId. indexlerde hep typeId lazim.
                    {
                        userData.unlockedScienceNodes[TypeIdGenerator.getScienceNodeIds(nodeDbIdPair.Key.GetType())] = unlockedScienceNodeDbIds[nodeDbIdPair.Value];
                    }

                    return true;
                }
                else
                    return false;
            }
            catch
            {
                return false;
            }
            finally
            {
                try
                {
                    reader.Close();
                }
                catch { }
            }
        }
Пример #3
0
        private void loginProcess()
        {
            string username;
            string password;

            string certPassword = "******";
            X509Certificate certificate = new X509Certificate2("ScienceWars_SSL_certificate.pfx", certPassword);

            SslStreamObject sslStream = session.client.createSslStreamObject(true);
            try
            {
                sslStream.AuthenticateAsServer(certificate);
            }
            catch (Exception e)
            {
                return;
            }

            while (true)
            {
                RawMessage message = sslStream.ReadSingleMessage();

                if (message == null)
                    return;

                username = message.getUTF8String("username"); // TODO exception check
                password = message.getUTF8String("password");

                int userId = 0;
                if (dal.credentialCheck(username,password,out userId)) //username, password, out userId))
                {
                    Database.Models.UserDataModel userData = new Database.Models.UserDataModel();

                    if (dal.getUserData(userId, TypeIdGenerator.getScienceNodeCount(), out userData))
                    {
                        //TODO unlocked Science Nodes bize dbId olarak geliyor ancak biz o id yi sanki isimden uretilen typeId si gibi kullaniyoruz. burada bir convert yapmak lazim
                        // aldigin unlockedScienceNodes arrayindeki her bir indexi dbId olarak tutan scienceNode u bul, o nodun typeId sini al, o typeId yi index olarak kullanarak yeni bir bool[] doldur.
                        // yeni olusturdugun bool array i User konstraktirina gonder.

                        sendLoginResponse(sslStream, true, "successful");
                        //sslStream.Close();        // DUE TO A BUG -kardeslerim- WE CANNOT CLOSE THE STREAM.
                                                    // Cunku close yaparsak, nereden geldigi belirsiz 37 byte, client'a ait messageListenera dusuyor.
                                                    // sadece unity'de oluyor, .net'te duzgun calisiyor. Muhtemelen Mono kaynakli bir sorun.

                        session.client.ListenForMessages();
                        User user = new User(session, username , userData.physPoints, userData.chemPoints, userData.chemPoints, userData.unlockedScienceNodes);
                        runner.userLoggedIn(user);
                        return;
                    }
                    else
                        sendLoginResponse(sslStream, false, "cannot retrieve user data");
                }
                else
                    sendLoginResponse(sslStream, false, "wrong username or password");
            }
        }
Пример #4
0
        private void loginProcess()
        {
            string username;
            string password;

            string          certPassword = "******";
            X509Certificate certificate  = new X509Certificate2("ScienceWars_SSL_certificate.pfx", certPassword);

            SslStreamObject sslStream = session.client.createSslStreamObject(true);

            try
            {
                sslStream.AuthenticateAsServer(certificate);
            }
            catch (Exception e)
            {
                return;
            }

            while (true)
            {
                RawMessage message = sslStream.ReadSingleMessage();

                if (message == null)
                {
                    return;
                }

                username = message.getUTF8String("username"); // TODO exception check
                password = message.getUTF8String("password");

                int userId = 0;
                if (dal.credentialCheck(username, password, out userId)) //username, password, out userId))
                {
                    Database.Models.UserDataModel userData = new Database.Models.UserDataModel();

                    if (dal.getUserData(userId, TypeIdGenerator.getScienceNodeCount(), out userData))
                    {
                        //TODO unlocked Science Nodes bize dbId olarak geliyor ancak biz o id yi sanki isimden uretilen typeId si gibi kullaniyoruz. burada bir convert yapmak lazim
                        // aldigin unlockedScienceNodes arrayindeki her bir indexi dbId olarak tutan scienceNode u bul, o nodun typeId sini al, o typeId yi index olarak kullanarak yeni bir bool[] doldur.
                        // yeni olusturdugun bool array i User konstraktirina gonder.

                        sendLoginResponse(sslStream, true, "successful");
                        //sslStream.Close();        // DUE TO A BUG -kardeslerim- WE CANNOT CLOSE THE STREAM.
                        // Cunku close yaparsak, nereden geldigi belirsiz 37 byte, client'a ait messageListenera dusuyor.
                        // sadece unity'de oluyor, .net'te duzgun calisiyor. Muhtemelen Mono kaynakli bir sorun.

                        session.client.ListenForMessages();
                        User user = new User(session, username, userData.physPoints, userData.chemPoints, userData.chemPoints, userData.unlockedScienceNodes);
                        runner.userLoggedIn(user);
                        return;
                    }
                    else
                    {
                        sendLoginResponse(sslStream, false, "cannot retrieve user data");
                    }
                }
                else
                {
                    sendLoginResponse(sslStream, false, "wrong username or password");
                }
            }
        }