//
// This file contains function that are used as serv triggers.
//

[PLEVEL 7]
f_onaccount_login
f_onchar_create
f_onchar_delete
f_onserver_start
f_onserver_save
f_onserver_save_ok
f_onserver_save_fail
f_onserver_save_finished
f_onserver_exit

// This function is called after client entered the password.
// ARGS --> username of the client loggin in
// RETURN
//	  0 --> normal action (login)
//	  1 --> disconnect the client
[FUNCTION f_onaccount_login]
IF (STRMATCH(*.*,<ARGS>))
SERV.LOG Illegal account name (contains .)!
RETURN 1
ENDIF
IF (<SERV.ACCOUNT.<ARGS>.TAG0.MAXCONNECTIONS>)
LOCAL.TOTALALLOWED=<SERV.ACCOUNT.<ARGS>.TAG0.MAXCONNECTIONS>
ELSE
LOCAL.TOTALALLOWED=1
ENDIF
FOR 0 <EVAL <SERV.CLIENTS>-1>
	IF (<SERV.CLIENT.<dLOCAL._FOR>.ISONLINE>)
		IF (!(STRCMPI(<SERV.CLIENT.<dLOCAL._FOR>.ACCOUNT.LASTIP>,<SERV.ACCOUNT.<ARGS>.LASTIP>)))
		LOCAL.TOTALCONNECTED ++
		ENDIF
		IF (<LOCAL.TOTALCONNECTED> >= <LOCAL.TOTALALLOWED>)
		SERV.LOG <ARGS> -> already logged with max number of accounts (<dLOCAL.TOTALALLOWED>)
		RETURN 1
		ENDIF
	ENDIF
ENDFOR

// This function is called after client have created a new char.
// SRC --> char being created
// ARGN1 --> flags
// ARGN2 --> profession chosen
// ARGN3 --> elf
// ARGS  --> Account name
[FUNCTION f_onchar_create]
SRC.MAXHITS ++
SRC.MAXMANA ++
SRC.MAXSTAM ++
SRC.HITS=<SRC.MAXHITS>
SRC.STAM=<SRC.MAXSTAM>
LOCAL.OLDNEW=<NEW>
SRC.NEWGOLD 900
SERV.NEWITEM i_focus_mem,1,<SRC>
SERV.NEWITEM i_elven_boots,1,<src>,1
NEW.COLOR=colors_all
NEW.ATTR |= attr_newbie
SERV.NEWITEM i_robe,1,<src>,1
IF (<SRC.MAGERY> >= 20.0)
SERV.NEWITEM i_spellbook
NEW.ADDCIRCLE=3,1
NEW.ATTR |= attr_newbie
NEW.BOUNCE
ENDIF
IF (<ARGN3>)
	IF ((<ARGN2> == prof_warrior) || (<ARGN2> >= prof_paladin))
	SERV.NEWITEM=i_elven_leafarmor_gloves
	NEW.ATTR |= attr_newbie
	NEW.EQUIP
	NEW.MODAR=-65
	SERV.NEWITEM=i_elven_leafarmor_gorget
	NEW.ATTR |= attr_newbie
	NEW.MODAR=-65
	NEW.EQUIP
	SERV.NEWITEM=i_elven_leafarmor_paldrons
	NEW.ATTR |= attr_newbie
	NEW.MODAR=-65
	NEW.EQUIP
	SERV.NEWITEM=i_winged_helm
	NEW.ATTR |= attr_newbie
	NEW.MODAR=-65
	NEW.EQUIP
	SERV.NEWITEM=i_elven_machete
	NEW.ATTR |= attr_newbie
	NEW.EQUIP
		IF (<SRC.BODY> == c_elf_female)
		SERV.NEWITEM=i_elven_leafarmor_tonlet
		NEW.ATTR |= attr_newbie
		NEW.MODAR=-65
		NEW.EQUIP
		SERV.NEWITEM=i_elven_leafarmor_femalechest
		NEW.ATTR |= attr_newbie
		NEW.MODAR=-65
		NEW.EQUIP
		ELSE
		SERV.NEWITEM=i_elven_leafarmor_pants
		NEW.ATTR |= attr_newbie
		NEW.MODAR=-65
		NEW.EQUIP
		SERV.NEWITEM=i_elven_leafarmor_chest
		NEW.ATTR |= attr_newbie
		NEW.MODAR=-65
		NEW.EQUIP
		ENDIF
	ELIF (<ARGN2> == prof_magician) || (<ARGN2> == prof_necromancer)
	SERV.NEWITEM=i_elven_specs
	NEW.ATTR |= attr_newbie
	NEW.EQUIP
	SERV.NEWITEM=tm_BAG_OF_MAGIC
	NEW.BOUNCE
		IF (<ARGN2> == prof_necromancer)
		SERV.NEWITEM=i_elven_male_robe2
		NEW.ATTR |= attr_newbie
		NEW.COLOR=colors_all
		NEW.EQUIP
		ELSE
		SERV.NEWITEM=i_elven_male_robe1
		NEW.ATTR |= attr_newbie
		NEW.COLOR=colors_all
		NEW.EQUIP
		ENDIF
	ELIF (<ARGN2> == prof_blacksmith)
	SERV.NEWITEM=i_elven_leafarmor_tonlet
	NEW.ATTR |= attr_newbie
	NEW.EQUIP
	SERV.NEWITEM=i_elven_male_shirt2
	NEW.ATTR |= attr_newbie
	NEW.EQUIP
	ENDIF
SRC.MAXMANA += 20
SRC.NIGHTSIGHT=1
ELSE
	IF (<ARGN2> == prof_magician) || (<ARGN2> == prof_necromancer)
	SERV.NEWITEM i_robe,1,<src>,1
	NEW.COLOR=colors_all
	NEW.ATTR |= attr_newbie
	SERV.NEWITEM=tm_BAG_OF_MAGIC
	NEW.BOUNCE
	ELIF ((<ARGN2> == prof_warrior) || (<ARGN2> >= prof_paladin))
	SERV.NEWITEM i_chainmail_coif,1,<src>,1
	NEW.ATTR |= attr_newbie
	SERV.NEWITEM i_ringmail_tunic,1,<src>,1
	NEW.ATTR |= attr_newbie
	SERV.NEWITEM i_ringmail_leggings,1,<src>,1
	NEW.ATTR |= attr_newbie
	SERV.NEWITEM i_ringmail_gloves,1,<src>,1
	NEW.ATTR |= attr_newbie
	SERV.NEWITEM i_ringmail_sleeves,1,<src>,1
	NEW.ATTR |= attr_newbie
	ELIF (<ARGN2> == prof_blacksmith)
	SERV.NEWITEM=i_elven_leafarmor_tonlet
	NEW.ATTR |= attr_newbie
	NEW.EQUIP
	SERV.NEWITEM=i_elven_male_shirt2
	NEW.ATTR |= attr_newbie
	NEW.EQUIP
	ENDIF
SRC.MODMAXWEIGHT += 80
SRC.MAXHITS += 10
ENDIF
IF (<SRC.CHIVALRY>)
SERV.NEWITEM=i_book_chivalry
NEW.BOUNCE
ENDIF
IF (<SRC.NECROMANCY>)
SERV.NEWITEM=i_book_necromancy
NEW.BOUNCE
ENDIF
NEW=<LOCAL.OLDNEW>
SRC.MANA=<SRC.MAXMANA>
IF (<SRC.NINJITSU>) && !(<SRC.BUSHIDO>)
SRC.BUSHIDO=<SRC.NINJITSU>
SRC.NINJITSU
ELIF (<SRC.NINJITSU>) && (<SRC.BUSHIDO>)
SRC.STEALTH=<SRC.NINJITSU>
SRC.NINJITSU
ENDIF
SRC.TAG.BEFOREYOUNGNAME=<SRC.NAME>
SRC.NAME=<SRC.NAME> (Young)
SRC.EVENTS +E_YOUNG
SRC.TAG.TUTORIALSTARTP=<SRC.P>
SRC.FLAGS |= statf_freeze|statf_invul|statf_invisible|statf_insubstantial
SRC.REMOVEFROMVIEW
SRC.MOVETO 2507,598,0,1
SRC.UPDATE
SRC.TAG.TUTORIALPAGE=1
SRC.EVENTS +e_tutorial
SRC.TAG.virtudes.compassion=01
SRC.TAG.virtudes.justice=01
SRC.TAG.virtudes.sacrifice=01
SRC.TAG.virtudes.spirituality=01
SRC.TAG.VIRTUDES.valor=01
SRC.EVENTS +e_virt_justice

// This function is called before client is going to delete a character.
// SRC --> char being deleted
// RETURN
//	  0 --> normal action (delete char)
//	  1 --> denyes deletion
[FUNCTION f_onchar_delete]
if (<src.tag0.event.id>) || (<src.findid.i_pvp_time>) || !(STRCMPI(<SRC.REGION.NAME>,Arena da Lana))
serv.log <src.account.name> tentando deletar um char que nao pode (<src.name> <src>)
RETURN 1
endif
serv.log <src.name> foi deletado (<src>) (C: <src.account.name>)
SRC.remove_invalid_houses
try uid.01f379.TAG.<SRC>
try uid.01ae82.TAG.<SRC>

// This function is called on server startup
[FUNCTION f_onserver_start]

//Called after server exit
[FUNCTION f_onserver_exit]

//This function is called before server is going to save.
//ARGN1 --> save is forced (writable)
//ARGN2 --> save stage (for backgroud save goes 1 to 6144)
//RETURN
//	  0 --> normal action (save)
//	  1 --> denyes save
[FUNCTION f_onserver_save]
SERv.ALLCLIENTS DIALOG_UP D_SAVING_DLG

// This function is called after server hasn't saved correctly (once per stage with background save).
[FUNCTION f_onserver_save_fail]
SERV.LOG SAVE FAILED!!!!
SERV.B @33 WORLD SAVE FAILED, CONTACT AN ADMIN! SPHERE IS CLOSING.
SERV.EXIT 1

// This function is called after server has saved thing correctly.
[FUNCTION f_onserver_save_ok]

// This function is called after server completely finished saving (also at end of background save).
// ARGS --> Time it took to save (in seconds, 4 digit precision)
[FUNCTION f_onserver_save_finished]
SERV.B @55,3 The process took <ARGS> ms. <SERV.ITEMS> items and <SERV.CHARS> chars were saved.
IF (<EVAL <SERV.RTIME.FORMAT %H>> == 10)
SERV.SHRINKMEM
ENDIF
SERV.ALLCLIENTS CLOSESAVINGDLG

[FUNCTION f_onserver_timer]
F_CHECKALLGUILDS_ALLYPOINTS

// Called when an account is going to be deleted.
// ARGS --> Account name
// RETURN 1 --> Cancels deletion
[FUNCTION f_onaccount_delete]

// This function is called when an IP is blocked from the server
// ARGS  --> IP being blocked
// ARGN1 --> Time to block the IP for in tenths of a second (writable)
[FUNCTION f_onserver_blockip]

[EOF]