Advertisement
ShadyPL

Model member silnika shadyego

May 4th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.03 KB | None | 0 0
  1. <?php
  2. require './libs/Model.php';
  3.  
  4. class MemberModel extends Model
  5. {
  6.     public function antyFlood( $session )
  7.     {
  8.         if ( Session::Exists( $session ) )
  9.         {
  10.             if ( Session::Get( $session ) < time( ) )
  11.             {
  12.                 Session::Delete( $session );
  13.                 return false;
  14.             }
  15.             else
  16.             {
  17.                 return true;
  18.             }
  19.         }
  20.         else
  21.         {
  22.             return false;
  23.         }
  24.     }
  25.  
  26.     public function addFlood( $session, $count )
  27.     {
  28.         if ( Session::Exists( $session ) )
  29.         {
  30.             Session::plusOne( $session );
  31.  
  32.             if ( Session::Get( $session ) > $count )
  33.             {
  34.                 Session::Delete( $session );
  35.                 Session::Set( $session . 'Block', time() + 900 );
  36.             }  
  37.         }
  38.         else
  39.         {
  40.             Session::Set( $session, 1 );
  41.         }
  42.     }
  43.  
  44.     public function loged( $post )
  45.     {
  46.         if ( $this->is_loged( ) )
  47.         {
  48.             return (array) 'Jesteś już zalogowany do gry, wyloguj się, aby przejść na inne konto';
  49.         }
  50.  
  51.         if ( $this->antyFlood( 'loginBadBlock' ) )
  52.         {
  53.             return 'Przekroczono limit błędnych prób logowania, odczekaj 15 minut';
  54.         }
  55.  
  56.         $post['username'] = Filter::string( $post['username'] );
  57.         $post['password'] = Filter::string( $post['password'] );
  58.  
  59.         if ( empty( $post['username'] ) )
  60.         {
  61.             return 'Nie wypełniono loginu';
  62.         }
  63.         elseif ( empty( $post['password'] ) )
  64.         {
  65.             return 'Nie wypełniono hasła';
  66.         }
  67.  
  68.         $acc = DB::fetch( "SELECT uid, password, salt, role, ban FROM brutal_users WHERE username = '{$post['username']}' LIMIT 1" );
  69.  
  70.         if ( $acc['uid'] )
  71.         {
  72.             $post['password'] = $this->crypto( $post['password'], $acc['salt'] );
  73.  
  74.             if ( $acc['role'] == 666 )
  75.             {
  76.                 if ( $acc['ban'] < time( ) )
  77.                 {
  78.                     DB::query( "UPDATE brutal_users SET role = 0, ban = 0 WHERE uid = {$acc['uid']} LIMIT 1" );
  79.                 }
  80.                 else
  81.                 {
  82.                     return 'Te konto zostało zbanowane do dnia: ' . date( 'd/m/Y H:i', $acc['ban'] );
  83.                 }
  84.             }
  85.             elseif ( $post['password'] == $acc['password'] )
  86.             {
  87.                 $session = sha1( $this->uniq_key( ) . $acc['uid'] . $this->true_ip( ) );
  88.                 $ip_long = ip2long( $this->true_ip( ) );
  89.                 $time = time( );
  90.  
  91.                 DB::query( "UPDATE brutal_users SET session = '{$session}', loged = {$time}, lastip = {$ip_long} WHERE uid = {$acc['uid']} LIMIT 1" );
  92.  
  93.                 Session::Set( 'player_sess', $session );
  94.                 Session::Set( 'time', time( ) + 1200 );
  95.                 Session::Set( 'prev', 1 );
  96.  
  97.                 Router::setTrace( 'action=account/task=start' );
  98.             }
  99.             else
  100.             {
  101.                 $this->addFlood( 'loginBad', 4 );
  102.                 return 'Podano błędne hasło';
  103.             }
  104.         }
  105.         else
  106.         {
  107.             $this->addFlood( 'loginBad', 4 );
  108.             return 'Podane konto nie istnieje';
  109.         }
  110.  
  111.         $this->addFlood( 'loginBad', 4 );
  112.         return 'Nieoczekiwany błąd';
  113.     }
  114.  
  115.     public function reged( $post )
  116.     {
  117.         if ( $this->is_loged( ) )
  118.         {
  119.             return (array) 'Jesteś już zalogowany do gry, wyloguj się, aby przejść na inne konto';
  120.         }
  121.  
  122.         if ( $this->antyFlood( 'registerBadBlock' ) )
  123.         {
  124.             return (array) 'Przekroczono limit błędnych prób rejestracji, odczekaj 15 minut';
  125.         }
  126.  
  127.         $post['username'] = Filter::string( $post['username'] );
  128.         $post['password'] = Filter::string( $post['password'] );
  129.         $post['email']    = Filter::string( $post['email'] );
  130.         $post['email2']   = Filter::string( $post['email2'] );
  131.         $post['class']    = Filter::int( $post['class'] );
  132.  
  133.         $errors = array( );
  134.  
  135.         if ( empty( $post['username'] ) )
  136.         {
  137.             $errors[] = 'Nie podano nazwy postaci';
  138.         }
  139.         elseif ( strlen( $post['username'] ) < 3 )
  140.         {
  141.             $errors[] = 'Minimalna długość nazwy postaci to 3 znaki';
  142.         }
  143.         elseif ( strlen( $post['username'] ) > 20 )
  144.         {
  145.             $errors[] = 'Maksymalna długość nazwy postaci to 20 znaków';
  146.         }
  147.  
  148.         if ( empty( $post['password'] ))
  149.         {
  150.             $errors[] = 'Nie podano hasła';
  151.         }
  152.         elseif ( strlen( $post['password'] ) < 5 )
  153.         {
  154.             $errors[] = 'Minimalna długość hasła to 5 znaków';
  155.         }
  156.         elseif ( strlen( $post['password'] ) > 40 )
  157.         {
  158.             $errors[] = 'Maksymalna długość hasła to 40 znaków';
  159.         }
  160.         elseif ( $post['password'] == $post['username'])
  161.         {
  162.             $errors[] = 'Hasło nie może być identyczne jak login';
  163.         }
  164.  
  165.         if ( empty( $post['email'] ) )
  166.         {
  167.             $errors[] = 'Nie podano adresu e-mail';
  168.         }
  169.         elseif ( $post['email'] != $post['email2'] )
  170.         {
  171.             $errors[] = 'Adresy e-mail są niezgodne';
  172.         }
  173.         elseif ( strlen( $post['email'] ) > 120 )
  174.         {
  175.             $errors[] = 'Maksymalna długość adresu to 120 znaków';
  176.         }
  177.         elseif ( Filter::email_check( $post['email'] ) )
  178.         {
  179.             $errors[] = 'Nie poprawny adres e-mail';
  180.         }
  181.  
  182.         if ( empty( $post['class'] ))
  183.         {
  184.             $errors[] = 'Nie wybrano klasy postaci';
  185.         }
  186.         elseif ( $post['class'] < 1 || $post['class'] > 3 )
  187.         {
  188.             $errors[] = 'Nie zdefiniowana klasa postaci';
  189.         }
  190.  
  191.         if ( empty( $errors ) )
  192.         {
  193.             if ( DB::num_rows( "SELECT uid FROM brutal_users WHERE username = '{$post['username']}' LIMIT 1 UNION SELECT uid FROM brutal_users WHERE email = '{$post['email']}' LIMIT 1" ) )
  194.             {
  195.                 return (array) 'Konto o podanej nazwie lub adresie e-mail, istnieje już w naszej bazie';
  196.             }
  197.             else
  198.             {
  199.                 $salt = $this->uniq_key( );
  200.                 $post['password'] = $this->crypto( $post['password'], $salt );
  201.  
  202.                 $ip_long = ip2long( $this->true_ip( ) );
  203.                 $time = time( );
  204.  
  205.                 DB::query( "INSERT INTO brutal_users (username, password, salt, email, class, loged, reged, lastip, regip) VALUES ('{$post['username']}', '{$post['password']}', '{$salt}', '{$post['email']}', {$class}, {$time}, {$time}, {$ip_long}, {$ip_long})" );
  206.  
  207.                 $acc_id = DB::last_insert_id( );
  208.                 $session = sha1( $this->uniq_key( ) . $acc_id . $this->true_ip( ) );
  209.  
  210.                 DB::query( "UPDATE brutal_users SET session = '{$session}' WHERE uid = {$acc_id} LIMIT 1" );
  211.  
  212.                 Session::Set( 'player_sess', $session );
  213.                 Session::Set( 'time', time( ) + 1200 );
  214.                 Session::Set( 'prev', 1 );
  215.  
  216.                 Router::setTrace( 'action=account/task=start' );
  217.             }
  218.         }
  219.         else
  220.         {
  221.             $this->addFlood( 'registerBad', 5 );
  222.             return $errors;
  223.         }
  224.     }
  225.  
  226.     public function logout( )
  227.     {
  228.         if ( !$this->is_loged( ) )
  229.         {
  230.             Router::setTrace( 'action=member/task=login/alert=deny' );
  231.         }
  232.  
  233.         Session::Destroy( );
  234.         Router::setTrace( 'action=start/task=index' );
  235.     }
  236. }
  237. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement