Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require './libs/Model.php';
- class MemberModel extends Model
- {
- public function antyFlood( $session )
- {
- if ( Session::Exists( $session ) )
- {
- if ( Session::Get( $session ) < time( ) )
- {
- Session::Delete( $session );
- return false;
- }
- else
- {
- return true;
- }
- }
- else
- {
- return false;
- }
- }
- public function addFlood( $session, $count )
- {
- if ( Session::Exists( $session ) )
- {
- Session::plusOne( $session );
- if ( Session::Get( $session ) > $count )
- {
- Session::Delete( $session );
- Session::Set( $session . 'Block', time() + 900 );
- }
- }
- else
- {
- Session::Set( $session, 1 );
- }
- }
- public function loged( $post )
- {
- if ( $this->is_loged( ) )
- {
- return (array) 'Jesteś już zalogowany do gry, wyloguj się, aby przejść na inne konto';
- }
- if ( $this->antyFlood( 'loginBadBlock' ) )
- {
- return 'Przekroczono limit błędnych prób logowania, odczekaj 15 minut';
- }
- $post['username'] = Filter::string( $post['username'] );
- $post['password'] = Filter::string( $post['password'] );
- if ( empty( $post['username'] ) )
- {
- return 'Nie wypełniono loginu';
- }
- elseif ( empty( $post['password'] ) )
- {
- return 'Nie wypełniono hasła';
- }
- $acc = DB::fetch( "SELECT uid, password, salt, role, ban FROM brutal_users WHERE username = '{$post['username']}' LIMIT 1" );
- if ( $acc['uid'] )
- {
- $post['password'] = $this->crypto( $post['password'], $acc['salt'] );
- if ( $acc['role'] == 666 )
- {
- if ( $acc['ban'] < time( ) )
- {
- DB::query( "UPDATE brutal_users SET role = 0, ban = 0 WHERE uid = {$acc['uid']} LIMIT 1" );
- }
- else
- {
- return 'Te konto zostało zbanowane do dnia: ' . date( 'd/m/Y H:i', $acc['ban'] );
- }
- }
- elseif ( $post['password'] == $acc['password'] )
- {
- $session = sha1( $this->uniq_key( ) . $acc['uid'] . $this->true_ip( ) );
- $ip_long = ip2long( $this->true_ip( ) );
- $time = time( );
- DB::query( "UPDATE brutal_users SET session = '{$session}', loged = {$time}, lastip = {$ip_long} WHERE uid = {$acc['uid']} LIMIT 1" );
- Session::Set( 'player_sess', $session );
- Session::Set( 'time', time( ) + 1200 );
- Session::Set( 'prev', 1 );
- Router::setTrace( 'action=account/task=start' );
- }
- else
- {
- $this->addFlood( 'loginBad', 4 );
- return 'Podano błędne hasło';
- }
- }
- else
- {
- $this->addFlood( 'loginBad', 4 );
- return 'Podane konto nie istnieje';
- }
- $this->addFlood( 'loginBad', 4 );
- return 'Nieoczekiwany błąd';
- }
- public function reged( $post )
- {
- if ( $this->is_loged( ) )
- {
- return (array) 'Jesteś już zalogowany do gry, wyloguj się, aby przejść na inne konto';
- }
- if ( $this->antyFlood( 'registerBadBlock' ) )
- {
- return (array) 'Przekroczono limit błędnych prób rejestracji, odczekaj 15 minut';
- }
- $post['username'] = Filter::string( $post['username'] );
- $post['password'] = Filter::string( $post['password'] );
- $post['email'] = Filter::string( $post['email'] );
- $post['email2'] = Filter::string( $post['email2'] );
- $post['class'] = Filter::int( $post['class'] );
- $errors = array( );
- if ( empty( $post['username'] ) )
- {
- $errors[] = 'Nie podano nazwy postaci';
- }
- elseif ( strlen( $post['username'] ) < 3 )
- {
- $errors[] = 'Minimalna długość nazwy postaci to 3 znaki';
- }
- elseif ( strlen( $post['username'] ) > 20 )
- {
- $errors[] = 'Maksymalna długość nazwy postaci to 20 znaków';
- }
- if ( empty( $post['password'] ))
- {
- $errors[] = 'Nie podano hasła';
- }
- elseif ( strlen( $post['password'] ) < 5 )
- {
- $errors[] = 'Minimalna długość hasła to 5 znaków';
- }
- elseif ( strlen( $post['password'] ) > 40 )
- {
- $errors[] = 'Maksymalna długość hasła to 40 znaków';
- }
- elseif ( $post['password'] == $post['username'])
- {
- $errors[] = 'Hasło nie może być identyczne jak login';
- }
- if ( empty( $post['email'] ) )
- {
- $errors[] = 'Nie podano adresu e-mail';
- }
- elseif ( $post['email'] != $post['email2'] )
- {
- $errors[] = 'Adresy e-mail są niezgodne';
- }
- elseif ( strlen( $post['email'] ) > 120 )
- {
- $errors[] = 'Maksymalna długość adresu to 120 znaków';
- }
- elseif ( Filter::email_check( $post['email'] ) )
- {
- $errors[] = 'Nie poprawny adres e-mail';
- }
- if ( empty( $post['class'] ))
- {
- $errors[] = 'Nie wybrano klasy postaci';
- }
- elseif ( $post['class'] < 1 || $post['class'] > 3 )
- {
- $errors[] = 'Nie zdefiniowana klasa postaci';
- }
- if ( empty( $errors ) )
- {
- 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" ) )
- {
- return (array) 'Konto o podanej nazwie lub adresie e-mail, istnieje już w naszej bazie';
- }
- else
- {
- $salt = $this->uniq_key( );
- $post['password'] = $this->crypto( $post['password'], $salt );
- $ip_long = ip2long( $this->true_ip( ) );
- $time = time( );
- 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})" );
- $acc_id = DB::last_insert_id( );
- $session = sha1( $this->uniq_key( ) . $acc_id . $this->true_ip( ) );
- DB::query( "UPDATE brutal_users SET session = '{$session}' WHERE uid = {$acc_id} LIMIT 1" );
- Session::Set( 'player_sess', $session );
- Session::Set( 'time', time( ) + 1200 );
- Session::Set( 'prev', 1 );
- Router::setTrace( 'action=account/task=start' );
- }
- }
- else
- {
- $this->addFlood( 'registerBad', 5 );
- return $errors;
- }
- }
- public function logout( )
- {
- if ( !$this->is_loged( ) )
- {
- Router::setTrace( 'action=member/task=login/alert=deny' );
- }
- Session::Destroy( );
- Router::setTrace( 'action=start/task=index' );
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement