Atrinik Server  4.0
Macros | Functions | Variables
atrinik_player.c File Reference
#include <plugin_python.h>
#include <toolkit/packet.h>
#include <faction.h>
#include <player.h>
#include <object.h>

Go to the source code of this file.

Macros

#define CHECK_INT_RANGE(min, max)
 
#define CHECK_UINT_RANGE(max)
 

Functions

static PyObject * Atrinik_Player_GetEquipment (Atrinik_Player *self, PyObject *args)
 
static PyObject * Atrinik_Player_CanCarry (Atrinik_Player *self, PyObject *what)
 
static PyObject * Atrinik_Player_AddExp (Atrinik_Player *self, PyObject *args)
 
static PyObject * Atrinik_Player_BankDeposit (Atrinik_Player *self, PyObject *args)
 
static PyObject * Atrinik_Player_BankWithdraw (Atrinik_Player *self, PyObject *args)
 
static PyObject * Atrinik_Player_BankBalance (Atrinik_Player *self)
 
static PyObject * Atrinik_Player_SwapApartments (Atrinik_Player *self, PyObject *args)
 
static PyObject * Atrinik_Player_ExecuteCommand (Atrinik_Player *self, PyObject *args)
 
static PyObject * Atrinik_Player_FindMarkedObject (Atrinik_Player *self)
 
static PyObject * Atrinik_Player_Sound (Atrinik_Player *self, PyObject *args, PyObject *keywds)
 
static PyObject * Atrinik_Player_Examine (Atrinik_Player *self, PyObject *args)
 
static PyObject * Atrinik_Player_SendPacket (Atrinik_Player *self, PyObject *args)
 
static PyObject * Atrinik_Player_DrawInfo (Atrinik_Player *self, PyObject *args, PyObject *keywds)
 
static PyObject * Atrinik_Player_FactionGetBounty (Atrinik_Player *self, PyObject *args)
 
static PyObject * Atrinik_Player_FactionClearBounty (Atrinik_Player *self, PyObject *args)
 
static PyObject * Atrinik_Player_InsertCoins (Atrinik_Player *self, PyObject *args)
 
static PyObject * Atrinik_Player_Save (Atrinik_Player *self)
 
static PyObject * Atrinik_Player_Address (Atrinik_Player *self, PyObject *args)
 
static void resolve_client_socket_field (fields_struct *field, const fields_struct *field_orig)
 
static PyObject * get_attribute (Atrinik_Player *pl, void *context)
 
static int set_attribute (Atrinik_Player *pl, PyObject *value, void *context)
 
static PyObject * Atrinik_Player_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
 
static void Atrinik_Player_dealloc (Atrinik_Player *pl)
 
static PyObject * Atrinik_Player_str (Atrinik_Player *pl)
 
static int Atrinik_Player_InternalCompare (Atrinik_Player *left, Atrinik_Player *right)
 
static PyObject * Atrinik_Player_RichCompare (Atrinik_Player *left, Atrinik_Player *right, int op)
 
int Atrinik_Player_init (PyObject *module)
 
PyObject * wrap_player (player *pl)
 

Variables

static fields_struct fields []
 
static const char doc_Atrinik_Player_GetEquipment []
 
static const char doc_Atrinik_Player_CanCarry []
 
static const char doc_Atrinik_Player_AddExp []
 
static const char doc_Atrinik_Player_BankDeposit []
 
static const char doc_Atrinik_Player_BankWithdraw []
 
static const char doc_Atrinik_Player_BankBalance []
 
static const char doc_Atrinik_Player_SwapApartments []
 
static const char doc_Atrinik_Player_ExecuteCommand []
 
static const char doc_Atrinik_Player_FindMarkedObject []
 
static const char doc_Atrinik_Player_Sound []
 
static const char doc_Atrinik_Player_Examine []
 
static const char doc_Atrinik_Player_SendPacket []
 
static const char doc_Atrinik_Player_DrawInfo []
 
static const char doc_Atrinik_Player_FactionGetBounty []
 
static const char doc_Atrinik_Player_FactionClearBounty []
 
static const char doc_Atrinik_Player_InsertCoins []
 
static const char doc_Atrinik_Player_Save []
 
static const char doc_Atrinik_Player_Address []
 
static PyMethodDef methods []
 
static PyGetSetDef getseters [NUM_FIELDS+1]
 
PyTypeObject Atrinik_PlayerType
 

Detailed Description

Atrinik Python plugin player related code.

Author
Alex Tokar

Definition in file atrinik_player.c.

Macro Definition Documentation

#define CHECK_INT_RANGE (   min,
  max 
)
Value:
if (PyErr_Occurred()) { \
PyErr_Format(PyExc_OverflowError, \
"Invalid integer value for '%c' format specifier.", \
format[i]); \
goto error; \
} else if (val < min || val > max) { \
PyErr_Format(PyExc_OverflowError, \
"Invalid integer value for '%c' format specifier.", \
format[i]); \
goto error; \
}
#define CHECK_UINT_RANGE (   max)
Value:
if (PyErr_Occurred()) { \
PyErr_Format(PyExc_OverflowError, \
"Invalid integer value for '%c' format specifier.", \
format[i]); \
goto error; \
} else if (val > max) { \
PyErr_Format(PyExc_OverflowError, \
"Invalid integer value for '%c' format specifier.", \
format[i]); \
goto error; \
}

Function Documentation

static PyObject* Atrinik_Player_AddExp ( Atrinik_Player self,
PyObject *  args 
)
static

Implements Atrinik.Player.Player.AddExp() Python method.

Parameters
selfSelf object for methods; module object for module functions.
argsArguments.

Definition at line 205 of file atrinik_player.c.

static PyObject* Atrinik_Player_Address ( Atrinik_Player self,
PyObject *  args 
)
static

Implements Atrinik.Player.Player.Address() Python method.

Parameters
selfSelf object for methods; module object for module functions.
argsArguments.

Definition at line 917 of file atrinik_player.c.

static PyObject* Atrinik_Player_BankBalance ( Atrinik_Player self)
static

Implements Atrinik.Player.Player.BankBalance() Python method.

Parameters
selfSelf object for methods; module object for module functions.

Definition at line 335 of file atrinik_player.c.

static PyObject* Atrinik_Player_BankDeposit ( Atrinik_Player self,
PyObject *  args 
)
static

Implements Atrinik.Player.Player.BankDeposit() Python method.

Parameters
selfSelf object for methods; module object for module functions.
argsArguments.

Definition at line 279 of file atrinik_player.c.

static PyObject* Atrinik_Player_BankWithdraw ( Atrinik_Player self,
PyObject *  args 
)
static

Implements Atrinik.Player.Player.BankWithdraw() Python method.

Parameters
selfSelf object for methods; module object for module functions.
argsArguments.

Definition at line 309 of file atrinik_player.c.

static PyObject* Atrinik_Player_CanCarry ( Atrinik_Player self,
PyObject *  what 
)
static

Implements Atrinik.Player.Player.CanCarry() Python method.

Parameters
selfSelf object for methods; module object for module functions.
whatThe object.

Definition at line 165 of file atrinik_player.c.

static void Atrinik_Player_dealloc ( Atrinik_Player pl)
static

Free a player wrapper.

Parameters
plThe wrapper to free.

Definition at line 1079 of file atrinik_player.c.

static PyObject* Atrinik_Player_DrawInfo ( Atrinik_Player self,
PyObject *  args,
PyObject *  keywds 
)
static

Implements Atrinik.Player.Player.DrawInfo() Python method.

Parameters
selfSelf object for methods; module object for module functions.
argsArguments.
keywdsKeyword arguments.

Definition at line 754 of file atrinik_player.c.

static PyObject* Atrinik_Player_Examine ( Atrinik_Player self,
PyObject *  args 
)
static

Implements Atrinik.Player.Player.Examine() Python method.

Parameters
selfSelf object for methods; module object for module functions.
argsArguments.

Definition at line 489 of file atrinik_player.c.

static PyObject* Atrinik_Player_ExecuteCommand ( Atrinik_Player self,
PyObject *  args 
)
static

Implements Atrinik.Player.Player.ExecuteCommand() Python method.

Parameters
selfSelf object for methods; module object for module functions.
argsArguments.

Definition at line 389 of file atrinik_player.c.

static PyObject* Atrinik_Player_FactionClearBounty ( Atrinik_Player self,
PyObject *  args 
)
static

Implements Atrinik.Player.Player.FactionClearBounty() Python method.

Parameters
selfSelf object for methods; module object for module functions.
argsArguments.

Definition at line 834 of file atrinik_player.c.

static PyObject* Atrinik_Player_FactionGetBounty ( Atrinik_Player self,
PyObject *  args 
)
static

Implements Atrinik.Player.Player.FactionGetBounty() Python method.

Parameters
selfSelf object for methods; module object for module functions.
argsArguments.

Definition at line 798 of file atrinik_player.c.

static PyObject* Atrinik_Player_FindMarkedObject ( Atrinik_Player self)
static

Implements Atrinik.Player.Player.FindMarkedObject() Python method.

Parameters
selfSelf object for methods; module object for module functions.

Definition at line 425 of file atrinik_player.c.

static PyObject* Atrinik_Player_GetEquipment ( Atrinik_Player self,
PyObject *  args 
)
static

Implements Atrinik.Player.GetEquipment() Python method.

Parameters
selfSelf object for methods; module object for module functions.
argsArguments.

Definition at line 133 of file atrinik_player.c.

int Atrinik_Player_init ( PyObject *  module)

Initialize the Atrinik.Player module.

Parameters
moduleThe Atrinik Python module.
Returns
1 on success, 0 on failure.

Definition at line 1183 of file atrinik_player.c.

static PyObject* Atrinik_Player_InsertCoins ( Atrinik_Player self,
PyObject *  args 
)
static

Implements Atrinik.Player.Player.InsertCoins() Python method.

Parameters
selfSelf object for methods; module object for module functions.
argsArguments.

Definition at line 872 of file atrinik_player.c.

static PyObject* Atrinik_Player_new ( PyTypeObject *  type,
PyObject *  args,
PyObject *  kwds 
)
static

Create a new player wrapper.

Parameters
typeType object.
argsUnused.
kwdsUnused.
Returns
The new wrapper.

Definition at line 1063 of file atrinik_player.c.

static PyObject* Atrinik_Player_Save ( Atrinik_Player self)
static

Implements Atrinik.Player.Player.Save() Python method.

Parameters
selfSelf object for methods; module object for module functions.

Definition at line 896 of file atrinik_player.c.

static PyObject* Atrinik_Player_SendPacket ( Atrinik_Player self,
PyObject *  args 
)
static

Implements Atrinik.Player.Player.Examine() Python method.

Parameters
selfSelf object for methods; module object for module functions.
argsArguments.

Definition at line 552 of file atrinik_player.c.

static PyObject* Atrinik_Player_Sound ( Atrinik_Player self,
PyObject *  args,
PyObject *  keywds 
)
static

Implements Atrinik.Player.Player.Sound() Python method.

Parameters
selfSelf object for methods; module object for module functions.
argsArguments.
keywdsKeyword arguments.

Definition at line 453 of file atrinik_player.c.

static PyObject* Atrinik_Player_str ( Atrinik_Player pl)
static

Return a string representation of a player.

Parameters
plThe player.
Returns
Python object containing the name of the player.

Definition at line 1096 of file atrinik_player.c.

static PyObject* Atrinik_Player_SwapApartments ( Atrinik_Player self,
PyObject *  args 
)
static

Implements Atrinik.Player.Player.SwapApartments() Python method.

Parameters
selfSelf object for methods; module object for module functions.
argsArguments.

Definition at line 360 of file atrinik_player.c.

static PyObject* get_attribute ( Atrinik_Player pl,
void *  context 
)
static

Get player's attribute.

Parameters
plPython player wrapper.
contextVoid pointer to the field ID.
Returns
Python object with the attribute value, NULL on failure.

Definition at line 1007 of file atrinik_player.c.

static void resolve_client_socket_field ( fields_struct field,
const fields_struct field_orig 
)
static

Resolve offsets from data in the player fields to a temporary one that maps to the player's client socket structure.

Parameters
fieldField to map to.
field_origField to map from.
Todo:
This should really be removed; instead we should wrap the player's client socket as a Python object.

Definition at line 986 of file atrinik_player.c.

static int set_attribute ( Atrinik_Player pl,
PyObject *  value,
void *  context 
)
static

Set attribute of a player.

Parameters
whoptrPython player wrapper.
valueValue to set.
contextVoid pointer to the field.
Returns
0 on success, -1 on failure.

Definition at line 1031 of file atrinik_player.c.

PyObject* wrap_player ( player pl)

Utility method to wrap a player.

Parameters
whatPlayer to wrap.
Returns
Python object wrapping the real player.

Definition at line 1219 of file atrinik_player.c.

Variable Documentation

PyTypeObject Atrinik_PlayerType

Our actual Python PlayerType.

Definition at line 1129 of file atrinik_player.c.

const char doc_Atrinik_Player_AddExp[]
static
Initial value:
=
".. method:: AddExp(skill, exp, exact=False, level=False).\n\n"
"Add (or subtract) experience.\n\n"
":param skill: ID or name of the skill to receive/lose exp in.\n"
":type skill: int or str\n"
":param exp: How much exp to gain/lose. If *level* is true, this is the number "
"of levels to gain/lose in the specified skill.\n"
":type exp: int\n"
":param exact: If True, the given exp will not be capped.\n"
":type exact: bool\n"
":param level: If True, will calculate exact experience needed for next (or "
"previous) level.\n"
":type level: bool\n"
":raises ValueError: If the skill ID/name is invalid.\n"
":raises Atrinik.AtrinikError: If the player doesn't have the specified skill."

Documentation for Atrinik_Player_AddExp().

Definition at line 185 of file atrinik_player.c.

const char doc_Atrinik_Player_Address[]
static
Initial value:
=
".. method:: Address(verbose=False).\n\n"
"Acquires the player's IP address.\n\n"
":param verbose: If True, will contain the port as well.\n"
":type verbose: bool\n"
":returns: The player's IP address.\n"
":rtype: str"

Documentation for Atrinik_Player_Address().

Definition at line 905 of file atrinik_player.c.

const char doc_Atrinik_Player_BankBalance[]
static
Initial value:
=
".. method:: BankBalance().\n\n"
"Figure out how much money player has in bank.\n\n"
":returns: Integer value of the money in bank.\n"
":rtype: int"

Documentation for Atrinik_Player_BankBalance().

Definition at line 325 of file atrinik_player.c.

const char doc_Atrinik_Player_BankDeposit[]
static
Initial value:
=
".. method:: BankDeposit(text).\n\n"
"Deposit money to bank.\n\n"
":param text: How much money to deposit, in string representation.\n"
":type text: str\n"
":returns: Tuple containing the status code (one of the BANK_xxx constants, "
"eg, :attr:`~Atrinik.BANK_SUCCESS`) and amount of money deposited as "
"integer.\n"
":rtype: tuple"

Documentation for Atrinik_Player_BankDeposit().

Definition at line 265 of file atrinik_player.c.

const char doc_Atrinik_Player_BankWithdraw[]
static
Initial value:
=
".. method:: BankWithdraw(text).\n\n"
"Withdraw money from bank.\n\n"
":param text: How much money to withdraw, in string representation.\n"
":type text: str\n"
":returns: Tuple containing the status code (one of the BANK_xxx constants, "
"eg, :attr:`~Atrinik.BANK_SUCCESS`) and amount of money withdrawn as "
"integer.\n"
":rtype: tuple"

Documentation for Atrinik_Player_BankWithdraw().

Definition at line 295 of file atrinik_player.c.

const char doc_Atrinik_Player_CanCarry[]
static
Initial value:
=
".. method:: CanCarry(what).\n\n"
"Check whether the player can carry *what*, taking weight limit into "
"consideration.\n\n"
":param what: Object that player wants to get. This can be the exact weight to "
"check instead of calculating the object's weight.\n"
":type what: :class:`Atrinik.Object.Object` or int\n"
":returns: Whether the player can carry the *what*.\n"
":rtype: bool"

Documentation for Atrinik_Player_CanCarry().

Definition at line 151 of file atrinik_player.c.

const char doc_Atrinik_Player_DrawInfo[]
static
Initial value:
=
".. method:: DrawInfo(message, color=Atrinik.COLOR_ORANGE, "
"type=Atrinik.CHAT_TYPE_GAME, broadcast=False, name=None).\n\n"
"Sends a message to the player.\n\n"
":param message: The message to send.\n"
":type message: str\n"
":param color: Color to use for the message. Can be one of the COLOR_xxx "
"constants (eg, :attr:`~Atrinik.COLOR_RED`) or a regular HTML color notation "
"(eg, '00ff00')\n"
":type color: str\n"
":param type: One of the CHAT_TYPE_xxx constants, eg, :attr:"
"`~Atrinik.CHAT_TYPE_CHAT`.\n"
":type type: int\n"
":param broadcast: If True, the message will be broadcast to all players.\n"
":type broadcast: bool\n"
":param name: Player name that is the source of this message, if applicable. "
"If None and *type* is not :attr:`~Atrinik.CHAT_TYPE_GAME`, :attr:"
"`Atrinik.Player.Player.ob.name` will be used.\n"
":type name: str or None"

Documentation for Atrinik_Player_DrawInfo().

Definition at line 730 of file atrinik_player.c.

const char doc_Atrinik_Player_Examine[]
static
Initial value:
=
".. method:: Examine(obj, ret=False).\n\n"
"Makes player examine the specified object.\n\n"
":param obj: Object to examine.\n"
":type obj: :class:`Atrinik.Object.Object`\n"
":param ret: If True, instead of printing out the examine text to the player,"
"the examine text is returned as a string.\n"
":type ret: bool\n"
":returns: None, examine string in case *ret* was True.\n"
":rtype: None or str"

Documentation for Atrinik_Player_Examine().

Definition at line 474 of file atrinik_player.c.

const char doc_Atrinik_Player_ExecuteCommand[]
static
Initial value:
=
".. method:: ExecuteCommand(command).\n\n"
"Make player execute a command.\n\n"
":param command: Command to execute.\n"
":type command: str\n"
":returns: Return value of the command.\n"
":rtype: int\n"
":raises Atrinik.AtrinikError: If player is not in a state to execute "
"commands."

Documentation for Atrinik_Player_ExecuteCommand().

Definition at line 375 of file atrinik_player.c.

const char doc_Atrinik_Player_FactionClearBounty[]
static
Initial value:
=
".. method:: FactionClearBounty(faction).\n\n"
"Clear player's bounty for the specified faction.\n\n"
":param faction: The faction name.\n"
":type faction: str\n"
":raises Atrinik.AtrinikError: If the specified faction doesn't exist"

Documentation for Atrinik_Player_FactionClearBounty().

Definition at line 823 of file atrinik_player.c.

const char doc_Atrinik_Player_FactionGetBounty[]
static
Initial value:
=
".. method:: FactionGetBounty(faction).\n\n"
"Acquires player's bounty for the specified faction.\n\n"
":param faction: The faction name.\n"
":type faction: str\n"
":returns: Player's bounty in the specified faction.\n"
":rtype: float\n"
":raises Atrinik.AtrinikError: If the specified faction doesn't exist."

Documentation for Atrinik_Player_FactionGetBounty().

Definition at line 785 of file atrinik_player.c.

const char doc_Atrinik_Player_FindMarkedObject[]
static
Initial value:
=
".. method:: FindMarkedObject().\n\n"
"Find marked object in player's inventory.\n\n"
":returns: The marked object, or None if no object is marked\n"
":rtype: :class:`Atrinik.Object.Object` or None"

Documentation for Atrinik_Player_FindMarkedObject().

Definition at line 415 of file atrinik_player.c.

const char doc_Atrinik_Player_GetEquipment[]
static
Initial value:
=
".. method:: GetEquipment(slot).\n\n"
"Get player's current equipment object for a given slot.\n\n"
":param slot: The slot number; one of PLAYER_EQUIP_xxx, eg, :attr:"
"`~Atrinik.PLAYER_EQUIP_LEGGINGS`.\n"
":type slot: int\n"
":returns: The equipment object for the given slot, None if there's no object "
"in the slot.\n"
":rtype: :class:`Atrinik.Object.Object` or None\n"
":throws ValueError: If the *slot* number is invalid."

Documentation for Atrinik_Player_GetEquipment().

Definition at line 118 of file atrinik_player.c.

const char doc_Atrinik_Player_InsertCoins[]
static
Initial value:
=
".. method:: InsertCoins(value).\n\n"
"Gives coins of the specified value to the player.\n\n"
":param value: The value.\n"
":type value: int"

Documentation for Atrinik_Player_InsertCoins().

Definition at line 862 of file atrinik_player.c.

const char doc_Atrinik_Player_Save[]
static
Initial value:
=
".. method:: Save().\n\n"
"Saves the player.\n\n"

Documentation for Atrinik_Player_Save().

Definition at line 888 of file atrinik_player.c.

const char doc_Atrinik_Player_SendPacket[]
static
Initial value:
=
".. method:: SendPacket(command, format, *args).\n\n"
"Constructs and sends a packet to the player's client.\n\n"
":param command: The command ID.\n"
":type command: int\n"
":param format: Format specifier. For example, 'Bs' would imply uint8_t + "
"string data, and the format specifier would need to be followed by an integer "
"that is within uint8_t data range and a string. Allowed format specifiers "
"are:\n\n"
" * **b**: 8-bit signed int (int8_t)\n"
" * **B**: 8-bit unsigned int (uint8_t)\n"
" * **h**: 16-bit signed int (int16_t)\n"
" * **H**: 16-bit unsigned int (uint16_t)\n"
" * **i**: 32-bit signed int (int32_t)\n"
" * **I**: 32-bit unsigned int (uint32_t)\n"
" * **l**: 64-bit signed int (int64_t)\n"
" * **L**: 64-bit unsigned int (uint64_t)\n"
" * **s**: String (automatically NUL-terminated)\n"
" * **x**: Bytes (NOT NUL-terminated)\n"
":type format: str\n"
":param \\*args: Rest of the arguments is converted into the packet data as "
"specified by the format string.\n"
":raises OverflowError: If *command* is not within a valid range.\n"
":raises ValueError: If an unrecognized character is encountered in "
"*format*.\n"
":raises TypeError: If an object's type in *args* does not match what was "
"specified in *format*.\n"
":raises OverflowError: If an integer specified in *args* is not within a "
"valid range."

Documentation for Atrinik_Player_SendPacket().

Definition at line 518 of file atrinik_player.c.

const char doc_Atrinik_Player_Sound[]
static
Initial value:
=
".. method:: Sound(filename, type=Atrinik.CMD_SOUND_EFFECT, x=0, y=0, loop=0, "
"volume=0).\n\n"
"Play a sound to the specified player.\n\n"
":param filename: Sound file to play.\n"
":type filename: str\n"
":param type: Sound type to play, one of the CMD_SOUND_xxx constants, eg, "
":attr:`~Atrinik.CMD_SOUND_BACKGROUND`.\n"
":type type: int\n"
":param x: X position where the sound is playing from.\n"
":type x: int\n"
":param y: Y position where the sound is playing from.\n"
":type y: int\n"
":param loop: How many times to loop the sound, -1 to loop infinitely.\n"
":type loop: int\n"
":param volume: Volume adjustment.\n"
":type volume: int"

Documentation for Atrinik_Player_Sound().

Definition at line 431 of file atrinik_player.c.

const char doc_Atrinik_Player_SwapApartments[]
static
Initial value:
=
".. method:: SwapApartments(oldmap, newmap, x, y).\n\n"
"Swaps *oldmap* apartment with *newmap* one.\n\nCopies old items from *oldmap* "
"to *newmap* at *x*, *y* and saves the map.\n\n"
":param oldmap: The old apartment map.\n"
":type oldmap: str\n"
":param newmap: The new apartment map.\n"
":type newmap: str\n"
":param x: X coordinate to copy the items to.\n"
":type x: int\n"
":param y: Y coordinate to copy the items to.\n"
":type y: int\n"
":returns: Whether the operation was successful or not.\n"
":rtype: bool"

Documentation for Atrinik_Player_SwapApartments().

Definition at line 341 of file atrinik_player.c.

fields_struct fields[]
static

Player fields.

Definition at line 41 of file atrinik_player.c.

PyGetSetDef getseters[NUM_FIELDS+1]
static

This is filled in when we initialize our player type.

Definition at line 1124 of file atrinik_player.c.

PyMethodDef methods[]
static

Available Python methods for the AtrinikPlayer type.

Definition at line 932 of file atrinik_player.c.