package Ġio . rs box . server . serializer . player Ċ Ċ import Ġcom . uch uh imo . kon f . Config Ċ import Ġcom . uch uh imo . kon f . source . yaml . to Yaml Ċ import Ġio . rs box . server . Server Ċ import Ġio . rs box . server . Server Constants Ċ import Ġio . rs box . server . config . Settings Spec Ċ import Ġio . rs box . server . model . entity . Client Ċ import Ġio . rs box . api . world . Tile Ċ import Ġio . rs box . server . net . login . Login Request Ċ import Ġorg . mind rot . j bcrypt . BC rypt Ċ import Ġjava . io . File Ċ Ċ /** Ċ Ġ* Ġ@ author ĠK yle ĠEs co bar Ċ Ġ*/ Ċ Ċ object ĠPlayer Save Ġ{ ĊĠĠĠ Ġfun Ġcheck ( username : ĠString , Ġpassword : ĠString ): ĠPlayer Load Result Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġr username Ġ= Ġfilter Username ( username ) ĊĠĠĠĠĠĠĠ Ġval Ġfile Ġ= ĠFile ("${ Server Constants . SA V ES _ PATH }$ r username . yml ") ĊĊĠĠĠĠĠĠĠ Ġif (! file . exists ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠPlayer Load Result . NEW _ ACCOUNT ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġsave Ġ= ĠConfig Ġ{ Ġadd Spec ( Player Spec ) Ġ}. from . yaml . file ( file ) ĊĊĠĠĠĠĠĠĠ Ġif (! BC rypt . check pw ( password , Ġsave [ Player Spec . password ])) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠPlayer Load Result . INVALID ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn ĠPlayer Load Result . ACCEPT ABLE ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġfilter Username ( username : ĠString ): ĠString Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġregex Ġ= ĠRegex ("[ ^ A - Za - z 0 - 9 ]") ĊĠĠĠĠĠĠĠ Ġreturn Ġregex . replace ( username , Ġ"") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġcreate ( request : ĠLogin Request ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsave Ġ= ĠConfig Ġ{ Ġadd Spec ( Player Spec ) Ġ} ĊĠĠĠĠĠĠĠ Ġsave [ Player Spec . username ] Ġ= Ġrequest . username ĊĠĠĠĠĠĠĠ Ġsave [ Player Spec . password ] Ġ= ĠBC rypt . hash pw ( request . password , ĠBC rypt . gens alt ( 1 6 )) ĊĠĠĠĠĠĠĠ Ġsave [ Player Spec . displayName ] Ġ= Ġ"" ĊĠĠĠĠĠĠĠ Ġsave [ Player Spec . privilege ] Ġ= Ġ 0 ĊĠĠĠĠĠĠĠ Ġsave [ Player Spec . x ] Ġ= ĠServer . settings [ Settings Spec . home _ x ] ĊĠĠĠĠĠĠĠ Ġsave [ Player Spec . z ] Ġ= ĠServer . settings [ Settings Spec . home _ z ] ĊĠĠĠĠĠĠĠ Ġsave [ Player Spec . height ] Ġ= ĠServer . settings [ Settings Spec . home _ height ] ĊĠĠĠĠĠĠĠ Ġsave [ Player Spec . uuid ] Ġ= Ġ"" ĊĊĠĠĠĠĠĠĠ Ġval Ġfile Ġ= ĠFile ("${ Server Constants . SA V ES _ PATH }${ filter Username ( request . username )}. yml ") ĊĠĠĠĠĠĠĠ Ġsave . to Yaml . to File ( file ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġload ( client : ĠClient , Ġrequest : ĠLogin Request ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġfile Ġ= ĠFile ("${ Server Constants . SA V ES _ PATH }${ Player Save . filter Username ( request . username )}. yml ") ĊĠĠĠĠĠĠĠ Ġval Ġsave Ġ= ĠConfig Ġ{ Ġadd Spec ( Player Spec ) Ġ}. from . yaml . file ( file ) ĊĊĠĠĠĠĠĠĠ Ġclient . username Ġ= ĠPlayer Save . filter Username ( save [ Player Spec . username ]) ĊĠĠĠĠĠĠĠ Ġclient . password Ġ= Ġsave [ Player Spec . password ] ĊĠĠĠĠĠĠĠ Ġclient . displayName Ġ= Ġsave [ Player Spec . displayName ] ĊĠĠĠĠĠĠĠ Ġclient . privilege Ġ= Ġsave [ Player Spec . privilege ] ĊĠĠĠĠĠĠĠ Ġclient . uuid Ġ= Ġsave [ Player Spec . uuid ] ĊĠĠĠĠĠĠĠ Ġclient . client Resizable Ġ= Ġrequest . resizable Client ĊĠĠĠĠĠĠĠ Ġclient . client Width Ġ= Ġrequest . client Width ĊĠĠĠĠĠĠĠ Ġclient . client Height Ġ= Ġrequest . client Height ĊĠĠĠĠĠĠĠ Ġclient . tile Ġ= ĠTile ( save [ Player Spec . x ], Ġsave [ Player Spec . z ], Ġsave [ Player Spec . height ]) ĊĠĠĠ Ġ} Ċ }