POT
POT
POT
Main menu

Download

Forum

SVN

Class: OTS_Account

Source Location: /classes/OTS_Account.php

Class OTS_Account

Class Overview

Implements interfaces:

  • IteratorAggregate (internal interface)
  • Countable (internal interface)

OTServ account abstraction.

OTServ account abstraction.

Located in /classes/OTS_Account.php [line 34]

OTS_Base_DAO
   |
   --OTS_Row_DAO
      |
      --OTS_Account
Author(s):
API Tags:
Property:  string $name: Account name.
Property:  string $password: Password.
Property:  string $eMail: Email address.
Property:  int $premiumEnd: Timestamp of PACC end.
Property:  bool $blocked: Blocked flag state.
Property:  bool $deleted: Deleted flag state.
Property:  bool $warned: Warned flag state.
Property:  bool $banned: Ban state.
Property-read:  int $id: Account number.
Property-read:  bool $loaded: Loaded state.
Property-read:  OTS_Players_List $playersList: Characters of this account.
Property-read:  int $access: Access level.

Information Tags:
Tutorial:  Accounts
Version:  0.0.1
Version:  0.1.5

Methods

[ Top ]
Inherited Properties, Constants, and Methods
Inherited Properties Inherited Methods Inherited Constants

Inherited From OTS_Base_DAO

OTS_Base_DAO::$db

Inherited From OTS_Row_DAO

OTS_Row_DAO::__construct()
Handles automatic loading for record.
OTS_Row_DAO::find()
Loads row by it's name.
OTS_Row_DAO::load()
Loads row by it's ID.

Inherited From OTS_Base_DAO

OTS_Base_DAO::__construct()
Sets database connection handler.
OTS_Base_DAO::__clone()
Creates clone of object.
OTS_Base_DAO::__set_state()
Magic PHP5 method.
OTS_Base_DAO::__sleep()
Magic PHP5 method.
OTS_Base_DAO::__wakeup()
Magic PHP5 method.

[ Top ]
Method Summary
void   ban()  
void   block()   Blocks account.
int   count()   Returns number of player within.
int   create()   Creates new account.
int   createEx()  
string   createNamed()   Creates new account.
void   delete()   Deletes account.
void   find()   Loads account by it's name.
void   findByEMail()   Loads account by it's e-mail address.
int   getAccess()   Checks highest access level of account.
string   getCustomField()   Reads custom field.
string   getEMail()   E-mail address.
OTS_Group   getGroup()  
int   getGuildAccess()   Checks highest access level of account in given guild.
int   getId()   Account number.
Iterator   getIterator()   Returns players iterator.
string   getName()   Name.
int   getPACCDays()  
string   getPassword()   Account's password.
array   getPlayers()  
OTS_Players_List   getPlayersList()   List of characters on account.
int   getPremiumEnd()   Account's Premium Account expiration timestamp.
bool   isBanned()  
bool   isBlocked()   Checks if account is blocked.
bool   isDeleted()   Checks if account is deleted (by flag setting).
bool   isLoaded()   Checks if object is loaded.
bool   isWarned()   Checks if account is warned.
void   load()   Loads account with given number.
void   save()   Updates account in database.
void   setCustomField()   Writes custom field.
void   setDeleted()   Deletes account (only by setting flag state, not physicly).
void   setEMail()   Sets account's email.
void   setGroup()  
void   setName()   Sets account's name.
void   setPACCDays()  
void   setPassword()   Sets account's password.
void   setPremiumEnd()   Sets account's Premium Account expiration timestamp.
void   unban()  
void   unblock()   Unblocks account.
void   unsetDeleted()   Unsets account's deleted flag.
void   unwarn()   Unwarns account.
void   warn()   Warns account.
mixed   __get()   Magic PHP5 method.
void   __set()   Magic PHP5 method.
string   __toString()   Returns string representation of object.

[ Top ]
Methods
ban  [line 807]

  void ban( [int $time = 0]  )

Parameters:
int   $time:  Time for time until expires (0 - forever).

API Tags:
Deprecated:  0.1.5 Use OTS_AccountBan class.
Access:  public

Information Tags:
Version:  0.1.5
Version:  0.0.1
Since:  0.0.5
Throws:  PDOException On PDO operation error.

[ Top ]
block  [line 547]

  void block( )

Blocks account.

Blocks account. This method only updates object state. To save changes in database you need to use save() method to flush changed to database.


API Tags:
Access:  public

Information Tags:
Version:  0.0.1

[ Top ]
count  [line 971]

  int count( )

Returns number of player within.

Returns number of player within.


API Tags:
Return:  Count of players.
Access:  public

Information Tags:
Version:  0.0.5
Version:  0.0.1
Throws:  E_OTS_NotLoaded If account is not loaded.
Since:  0.0.5
Throws:  PDOException On PDO operation error.

Implementation of:
Countable::count

[ Top ]
create  [line 136]

  int create( [int $min = 1], [int $max = 9999999], [string $name = null]  )

Creates new account.

Creates new account. Create new account in given range (1 - 9999999 by default).

Note: If account name won't be speciffied random will be created.

Note: Since 0.0.3 version this method doesn't require buffered queries.

Note: Since 0.1.5 version you should use createNamed() method since OTServ now uses account names.

Note: Since 0.1.1 version this method throws E_OTS_Generic exceptions instead of general Exception class objects. Since all exception classes are child classes of Exception class so your old code will still handle all exceptions.

Note: Since 0.1.5 version this method no longer creates account as blocked.

Parameters:
int   $min:  Minimum number.
int   $max:  Maximum number.
string   $name:  Account name.

API Tags:
Return:  Created account number.
Deprecated:  0.1.5 Use createNamed().
Access:  public

Information Tags:
Version:  0.1.5
Version:  0.0.1
Throws:  PDOException On PDO operation error.
Throws:  E_OTS_Generic When there are no free account numbers.

[ Top ]
createEx  [line 213]

  int createEx( OTS_Group $group, [int $min = 1], [int $max = 9999999]  )

Parameters:
OTS_Group   $group:  Group to be assigned to account.
int   $min:  Minimum number.
int   $max:  Maximum number.

API Tags:
Return:  Created account number.
Deprecated:  0.0.6 There is no more group_id field in database, use create().
Access:  public

Information Tags:
Version:  0.0.6
Version:  0.0.1
Since:  0.0.4

[ Top ]
createNamed  [line 67]

  string createNamed( [string $name = null]  )

Creates new account.

Creates new account. This method creates new account with given name. Account number is generated automaticly and saved into ID field.

If you won't specify account name then random one will be generated.

If you use own account name then it will be returned after success, and exception will be generated if it will be alredy used as name will be simply used in query with account create attempt.

Parameters:
string   $name:  Account name.

API Tags:
Return:  Account name.
Access:  public
Example:  create.php

Information Tags:
Tutorial:  Accounts
Version:  0.0.1
Version:  0.1.5
Throws:  PDOException On PDO operation error.
Since:  0.1.5

[ Top ]
delete  [line 877]

  void delete( )

Deletes account.

Deletes account. This method physicly deletes account from database! To set deleted flag use setDeleted() method.


API Tags:
Access:  public

Information Tags:
Version:  0.0.5
Version:  0.0.1
Throws:  E_OTS_NotLoaded If account is not loaded.
Since:  0.0.5
Throws:  PDOException On PDO operation error.

[ Top ]
find  [line 243]

  void find( string $name  )

Loads account by it's name.

Loads account by it's name. Note: Since 0.1.5 version this method loads account by it's name not by e-mail address. To find account by it's e-mail address use findByEMail() method.

Parameters:
string   $name:  Account's name.

API Tags:
Access:  public

Information Tags:
Version:  0.1.5
Version:  0.0.1
Throws:  PDOException On PDO operation error.
Since:  0.0.2

Redefinition of:
OTS_Row_DAO::find()
Loads row by it's name.

[ Top ]
findByEMail  [line 263]

  void findByEMail( string $email  )

Loads account by it's e-mail address.

Loads account by it's e-mail address.

Parameters:
string   $email:  Account's e-mail address.

API Tags:
Access:  public

Information Tags:
Version:  0.1.5
Version:  0.0.1
Throws:  PDOException On PDO operation error.
Since:  0.1.5

[ Top ]
getAccess  [line 897]

  int getAccess( )

Checks highest access level of account.

Checks highest access level of account.


API Tags:
Return:  Access level (highest access level of all characters).
Access:  public

Information Tags:
Version:  0.0.1
Throws:  PDOException On PDO operation error.

[ Top ]
getCustomField  [line 691]

  string getCustomField( string $field  )

Reads custom field.

Reads custom field. Reads field by it's name. Can read any field of given record that exists in database.

Note: You should use this method only for fields that are not provided in standard setters/getters (SVN fields). This method runs SQL query each time you call it so it highly overloads used resources.

Parameters:
string   $field:  Field name.

API Tags:
Return:  Field value.
Access:  public

Information Tags:
Version:  0.0.5
Version:  0.0.1
Throws:  E_OTS_NotLoaded If account is not loaded.
Since:  0.0.3
Throws:  PDOException On PDO operation error.

[ Top ]
getEMail  [line 449]

  string getEMail( )

E-mail address.

E-mail address. Note: Since 0.0.3 version this method throws E_OTS_NotLoaded exception instead of triggering E_USER_WARNING.


API Tags:
Return:  E-mail.
Access:  public

Information Tags:
Version:  0.0.3
Version:  0.0.1
Throws:  E_OTS_NotLoaded If account is not loaded.

[ Top ]
getGroup  [line 339]

  OTS_Group getGroup( )


API Tags:
Return:  Group of which current account is member (currently random group).
Deprecated:  0.0.6 There is no more group_id field in database.
Access:  public

Information Tags:
Version:  0.1.0
Version:  0.0.1
Since:  0.0.4
Throws:  E_OTS_NotLoaded If account is not loaded.

[ Top ]
getGuildAccess  [line 924]

  int getGuildAccess( OTS_Guild $guild  )

Checks highest access level of account in given guild.

Checks highest access level of account in given guild.

Parameters:
OTS_Guild   $guild:  Guild in which access should be checked.

API Tags:
Return:  Access level (highest access level of all characters).
Access:  public

Information Tags:
Version:  0.0.1
Throws:  PDOException On PDO operation error.

[ Top ]
getId  [line 322]

  int getId( )

Account number.

Account number. Note: Since 0.0.3 version this method throws E_OTS_NotLoaded exception instead of triggering E_USER_WARNING.


API Tags:
Return:  Account number.
Access:  public

Information Tags:
Version:  0.0.3
Version:  0.0.1
Throws:  E_OTS_NotLoaded If account is not loaded.

[ Top ]
getIterator  [line 957]

  Iterator getIterator( )

Returns players iterator.

Returns players iterator. There is no need to implement entire Iterator interface since we have players list class for it.


API Tags:
Return:  List of players.
Access:  public

Information Tags:
Version:  0.0.5
Version:  0.0.1
Throws:  E_OTS_NotLoaded If account is not loaded.
Since:  0.0.5
Throws:  PDOException On PDO operation error.

Implementation of:
IteratorAggregate::getIterator

[ Top ]
getName  [line 369]

  string getName( )

Name.

Name.


API Tags:
Return:  Name.
Access:  public

Information Tags:
Version:  0.1.5
Version:  0.0.1
Throws:  E_OTS_NotLoaded If account is not loaded.
Since:  0.1.5

[ Top ]
getPACCDays  [line 654]

  int getPACCDays( )


API Tags:
Return:  PACC days.
Deprecated:  0.0.3 There is no more premdays field in accounts table.
Access:  public

Information Tags:
Version:  0.0.4
Version:  0.0.1
Throws:  E_OTS_NotLoaded If account is not loaded.

[ Top ]
getPassword  [line 410]

  string getPassword( )

Account's password.

Account's password. Doesn't matter what password hashing mechanism is used by OTServ - this method will just return RAW database content. It is not possible to "decrypt" hashed strings, so it even wouldn't be possible to return real password string.

Note: Since 0.0.3 version this method throws E_OTS_NotLoaded exception instead of triggering E_USER_WARNING.


API Tags:
Return:  Password.
Access:  public

Information Tags:
Version:  0.0.3
Version:  0.0.1
Throws:  E_OTS_NotLoaded If account is not loaded.

[ Top ]
getPlayers  [line 746]

  array getPlayers( )


API Tags:
Return:  Array of OTS_Player objects from given account.
Deprecated:  0.0.5 Use getPlayersList().
Access:  public

Information Tags:
Version:  0.1.0
Version:  0.0.1
Throws:  E_OTS_NotLoaded If account is not loaded.

[ Top ]
getPlayersList  [line 782]

  OTS_Players_List getPlayersList( )

List of characters on account.

List of characters on account. In difference to getPlayers() method this method returns filtered OTS_Players_List object instead of array of OTS_Player objects. It is more effective since OTS_Player_List doesn't perform all rows loading at once.

Note: Returned object is only prepared, but not initialised. When using as parameter in foreach loop it doesn't matter since it will return it's iterator, but if you will wan't to execute direct operation on that object you will need to call rewind() method first.


API Tags:
Return:  List of players from current account.
Access:  public

Information Tags:
Version:  0.1.4
Version:  0.0.1
Throws:  E_OTS_NotLoaded If account is not loaded.
Since:  0.0.5

[ Top ]
getPremiumEnd  [line 481]

  int getPremiumEnd( )

Account's Premium Account expiration timestamp.

Account's Premium Account expiration timestamp.


API Tags:
Return:  Account PACC expiration timestamp.
Access:  public

Information Tags:
Version:  0.1.5
Version:  0.0.1
Throws:  E_OTS_NotLoaded If account is not loaded.
Since:  0.1.5

[ Top ]
isBanned  [line 851]

  bool isBanned( )


API Tags:
Return:  True if account is banned, false otherwise.
Deprecated:  0.1.5 Use OTS_AccountBan class.
Access:  public

Information Tags:
Version:  0.1.5
Version:  0.0.1
Since:  0.0.5
Throws:  PDOException On PDO operation error.

[ Top ]
isBlocked  [line 518]

  bool isBlocked( )

Checks if account is blocked.

Checks if account is blocked. Note: Since 0.0.3 version this method throws E_OTS_NotLoaded exception instead of triggering E_USER_WARNING.


API Tags:
Return:  Blocked state.
Access:  public

Information Tags:
Version:  0.0.3
Version:  0.0.1
Throws:  E_OTS_NotLoaded If account is not loaded.

[ Top ]
isDeleted  [line 560]

  bool isDeleted( )

Checks if account is deleted (by flag setting).

Checks if account is deleted (by flag setting).


API Tags:
Return:  Flag state.
Access:  public

Information Tags:
Version:  0.1.5
Version:  0.0.1
Throws:  E_OTS_NotLoaded If account is not loaded.
Since:  0.1.5

[ Top ]
isLoaded  [line 280]

  bool isLoaded( )

Checks if object is loaded.

Checks if object is loaded.


API Tags:
Return:  Load state.
Access:  public

Information Tags:
Version:  0.0.1

[ Top ]
isWarned  [line 608]

  bool isWarned( )

Checks if account is warned.

Checks if account is warned.


API Tags:
Return:  Flag state.
Access:  public

Information Tags:
Version:  0.1.5
Version:  0.0.1
Throws:  E_OTS_NotLoaded If account is not loaded.
Since:  0.1.5

[ Top ]
load  [line 225]

  void load( int $id  )

Loads account with given number.

Loads account with given number.

Parameters:
int   $id:  Account number.

API Tags:
Access:  public

Information Tags:
Version:  0.0.6
Version:  0.0.1
Throws:  PDOException On PDO operation error.

Redefinition of:
OTS_Row_DAO::load()
Loads row by it's ID.

[ Top ]
save  [line 300]

  void save( )

Updates account in database.

Updates account in database. Unlike other DAO objects account can't be saved without ID being set. It means that you can't just save unexisting account to automaticly create it. First you have to create record by using OTS_Account::createName()

Note: Since 0.0.3 version this method throws E_OTS_NotLoaded exception instead of triggering E_USER_WARNING.


API Tags:
Access:  public

Information Tags:
Version:  0.1.5
Version:  0.0.1
Throws:  E_OTS_NotLoaded If account doesn't have ID assigned.
Throws:  PDOException On PDO operation error.

[ Top ]
setCustomField  [line 724]

  void setCustomField( string $field, mixed $value  )

Writes custom field.

Writes custom field. Write field by it's name. Can write any field of given record that exists in database.

Note: You should use this method only for fields that are not provided in standard setters/getters (SVN fields). This method runs SQL query each time you call it so it highly overloads used resources.

Note: Make sure that you pass $value argument of correct type. This method determinates whether to quote field name. It is safe - it makes you sure that no unproper queries that could lead to SQL injection will be executed, but it can make your code working wrong way. For example: $object->setCustomField('foo', '1'); will quote 1 as as string ('1') instead of passing it as a integer.

Parameters:
string   $field:  Field name.
mixed   $value:  Field value.

API Tags:
Access:  public

Information Tags:
Version:  0.0.5
Version:  0.0.1
Throws:  E_OTS_NotLoaded If account is not loaded.
Since:  0.0.3
Throws:  PDOException On PDO operation error.

[ Top ]
setDeleted  [line 595]

  void setDeleted( )

Deletes account (only by setting flag state, not physicly).

Deletes account (only by setting flag state, not physicly). This method only updates object state. To save changes in database you need to use save() method to flush changed to database.


API Tags:
Access:  public

Information Tags:
Version:  0.1.5
Version:  0.0.1
Since:  0.1.5

[ Top ]
setEMail  [line 468]

  void setEMail( string $email  )

Sets account's email.

Sets account's email. This method only updates object state. To save changes in database you need to use save() method to flush changed to database.

Parameters:
string   $email:  E-mail address.

API Tags:
Access:  public

Information Tags:
Version:  0.0.1

[ Top ]
setGroup  [line 357]

  void setGroup( OTS_Group $group  )

Parameters:
OTS_Group   $group:  Group to be a member.

API Tags:
Deprecated:  0.0.6 There is no more group_id field in database.
Access:  public

Information Tags:
Version:  0.0.6
Version:  0.0.1

[ Top ]
setName  [line 390]

  void setName( string $name  )

Sets account's name.

Sets account's name. This method only updates object state. To save changes in database you need to use save() method to flush changed to database.

Parameters:
string   $name:  Account name.

API Tags:
Access:  public

Information Tags:
Version:  0.1.5
Version:  0.0.1
Since:  0.1.5

[ Top ]
setPACCDays  [line 669]

  void setPACCDays( $premdays, int $pacc  )

Parameters:
int   $pacc:  PACC days.
   $premdays: 

API Tags:
Deprecated:  0.0.3 There is no more premdays field in accounts table.
Access:  public

Information Tags:
Version:  0.0.4
Version:  0.0.1

[ Top ]
setPassword  [line 433]

  void setPassword( string $password  )

Sets account's password.

Sets account's password. This method only updates object state. To save changes in database you need to use save() method to flush changed to database.

Remember that this method just sets database field's content. It doesn't apply any hashing/encryption so if OTServ uses hashing for passwords you have to apply it by yourself before passing string to this method.

Parameters:
string   $password:  Password.

API Tags:
Access:  public

Information Tags:
Version:  0.0.1

[ Top ]
setPremiumEnd  [line 502]

  void setPremiumEnd( int $premend  )

Sets account's Premium Account expiration timestamp.

Sets account's Premium Account expiration timestamp. This method only updates object state. To save changes in database you need to use save() method to flush changed to database.

Parameters:
int   $premend:  PACC expiration timestamp.

API Tags:
Access:  public

Information Tags:
Version:  0.1.5
Version:  0.0.1
Since:  0.1.5

[ Top ]
unban  [line 830]

  void unban( )


API Tags:
Deprecated:  0.1.5 Use OTS_AccountBan class.
Access:  public

Information Tags:
Version:  0.1.5
Version:  0.0.1
Since:  0.0.5
Throws:  PDOException On PDO operation error.

[ Top ]
unblock  [line 535]

  void unblock( )

Unblocks account.

Unblocks account. This method only updates object state. To save changes in database you need to use save() method to flush changed to database.


API Tags:
Access:  public

Information Tags:
Version:  0.0.1

[ Top ]
unsetDeleted  [line 580]

  void unsetDeleted( )

Unsets account's deleted flag.

Unsets account's deleted flag. This method only updates object state. To save changes in database you need to use save() method to flush changed to database.


API Tags:
Access:  public

Information Tags:
Version:  0.1.5
Version:  0.0.1
Since:  0.1.5

[ Top ]
unwarn  [line 628]

  void unwarn( )

Unwarns account.

Unwarns account. This method only updates object state. To save changes in database you need to use save() method to flush changed to database.


API Tags:
Access:  public

Information Tags:
Version:  0.1.5
Version:  0.0.1
Since:  0.1.5

[ Top ]
warn  [line 643]

  void warn( )

Warns account.

Warns account. This method only updates object state. To save changes in database you need to use save() method to flush changed to database.


API Tags:
Access:  public

Information Tags:
Version:  0.1.5
Version:  0.0.1
Since:  0.1.5

[ Top ]
__get  [line 987]

  mixed __get( string $name  )

Magic PHP5 method.

Magic PHP5 method.

Parameters:
string   $name:  Property name.

API Tags:
Return:  Property value.
Access:  public

Information Tags:
Version:  0.1.5
Version:  0.0.1
Throws:  OutOfBoundsException For non-supported properties.
Throws:  E_OTS_NotLoaded If account is not loaded.
Throws:  PDOException On PDO operation error.
Since:  0.1.0

[ Top ]
__set  [line 1043]

  void __set( string $name, mixed $value  )

Magic PHP5 method.

Magic PHP5 method.

Parameters:
string   $name:  Property name.
mixed   $value:  Property value.

API Tags:
Access:  public

Information Tags:
Version:  0.1.5
Version:  0.0.1
Throws:  OutOfBoundsException For non-supported properties.
Throws:  E_OTS_NotLoaded If account is not loaded.
Throws:  PDOException On PDO operation error.
Since:  0.1.0

[ Top ]
__toString  [line 1123]

  string __toString( )

Returns string representation of object.

Returns string representation of object. If any display driver is currently loaded then it uses it's method. Otherwise just returns account number.


API Tags:
Return:  String representation of object.
Access:  public

Information Tags:
Version:  0.1.3
Version:  0.0.1
Since:  0.1.0

[ Top ]