예제 #1
0
        private static bool usuarioAlreadyLogIn(Usuario user)
        {
            foreach (Usuario tmpUser in usuarios)
            {
                if (tmpUser.username == user.username)
                {
                    return true;
                }
            }

            return false;
        }
예제 #2
0
 private static void TellAllIamHere(Usuario tmpUser)
 {
     var users = OnlineUsers.Values.Where(o => o.username != tmpUser.username).ToArray();
     Broadcast(Errores.NewUserLogIn(tmpUser.username, "ha iniciado sesion."), users);
 }
예제 #3
0
        private static void LogIn(dynamic obj, UserContext context)
        {
            conexion.Open();
            string searchUser = "******" + (string)obj.username + "'";
            SQLiteCommand cmd = new SQLiteCommand(searchUser, conexion);
            SQLiteDataReader data = cmd.ExecuteReader();
            string password = "";
            string avatar = "";
            while (data.Read())
            {
                password = Convert.ToString(data[1]);
                avatar = Convert.ToString(data[2]);

            }
            conexion.Close();

            if (password == "" || password != (string)obj.password)
            {
                context.Send(Errores.LogInError("Nombre de usuario o contraseña incorrecta."));
            }
            else
            {
                Usuario tmpUsuario = new Usuario { Context = context };
                tmpUsuario.username = (string)obj.username;

               // if (!usuarioAlreadyLogIn(tmpUsuario))
               // {
                OnlineUsers.TryAdd(tmpUsuario.username, tmpUsuario);
               // }
                context.Send(Errores.LogInSuccess("", (string)obj.username, (string)obj.password));
            }
        }
예제 #4
0
        private static void ReConnectUser(dynamic obj, UserContext context)
        {
            var me = new Usuario { Context = context };

            me.username = obj.username;

               OnlineUsers.TryAdd(me.username, me);

               context.Send(getUserList());

               TellAllIamHere(me);
        }
예제 #5
0
        private static void CreateNewUser(dynamic obj, UserContext context)
        {
            conexion.Open();
            //
            string userCount = "SELECT COUNT(*) FROM usuarios WHERE username = '******'";
            SQLiteCommand cmdCount = new SQLiteCommand(userCount, conexion);
            long count = (long)cmdCount.ExecuteScalar();

            if (count > 0)
            {
                conexion.Close();
                context.Send(Errores.LogInErrorUserExists("El usuario ya existe."));
            }
            else
            {
                string insertUser = "******" + (string)obj.username + "','" + (string)obj.password + "')";
                SQLiteCommand cmd = new SQLiteCommand(insertUser, conexion);
                int result = cmd.ExecuteNonQuery();
                Usuario tmpUsuario = new Usuario { Context = context };

                tmpUsuario.username = (string)obj.username;

                //if (!usuarioAlreadyLogIn(tmpUsuario))
                //{
                    OnlineUsers.TryAdd(tmpUsuario.username, tmpUsuario);
                    //usuarios.Add(tmpUsuario);
                //}

                conexion.Close();
                context.Send(Errores.SuccessNewUser("Usuario Creado exitosamente.", (string)obj.username, (string)obj.password));
            }
        }