package Ġcom . example . domain . core Ċ Ċ import Ġakka . actor . Abstract Actor With Timers Ċ import Ġakka . actor . Actor Ref . no Sender Ċ import Ġakka . actor . One For One Strategy Ċ import Ġakka . actor . Props Ċ import Ġakka . actor . Supervisor Strategy Ċ import Ġakka . actor . Supervisor Strategy . restart Ċ import Ġakka . actor . Supervisor Strategy . resume Ċ import Ġakka . actor . Supervisor Strategy . stop Ċ import Ġakka . j api . pf . Dec ider Builder Ċ import Ġcom . example . domain . core . player . Add Player Ċ import Ġcom . example . domain . core . player . Remove Player Ċ import Ġcom . example . domain . core . room . Create Rooms Ċ import Ġcom . example . domain . core . room . Rooms Created Ċ import Ġcom . example . domain . core . zone . User Disconnected Ċ import Ġcom . example . domain . core . zone . User Joined Room Ċ import Ġcom . example . domain . core . zone . User Left Room Ċ import Ġcom . example . domain . core . zone . User Logged Out Ċ import Ġcom . example . infrastructure . config . AppConfig Ċ import Ġcom . example . ports . s fs 2 x . Room Extension Ċ import Ġcom . example . ports . s fs 2 x . Zone Extension Ċ import Ġcom . smart fox server . v 2 . entities . Room Ċ import Ġcom . smart fox server . v 2 . entities . User Ċ import Ġorg . pm w . tiny log . Logger Ċ import Ġscala . concurrent . duration . Duration Ċ import Ġjava . util . concurrent . TimeUnit . MIN UTES Ċ Ċ class ĠZone Actor ( private Ġval Ġapp Config : ĠApp Config , Ġprivate Ġval Ġzone : ĠZone Extension ) Ġ: ĠAbstract Actor With Timers () Ġ{ ĊĠ Ġprivate Ġobject ĠTick Key ĊĠ Ġprivate Ġval Ġusers Ġ= Ġmutable Map Of < User , ĠMutable Set < Room >>() ĊĊĠ Ġoverride Ġfun Ġsupervisor Strategy (): ĠSuper visor Strategy Ġ= ĠOne For One Strategy ( ĊĠĠĠĠ 1 0 , ĊĠĠĠ ĠDuration . create ( 1 , ĠMIN UTES ), ĊĠĠĠ ĠDec ider Builder ĊĠĠĠĠĠ Ġ. match ( TimeoutException :: class . java ) Ġ{ Ġrestart () Ġ} ĊĠĠĠĠĠ Ġ. match ( Un stable ClientException :: class . java ) Ġ{ Ġstop () Ġ} ĊĠĠĠĠĠ Ġ. match ( NullPointerException :: class . java ) Ġ{ Ġresume () Ġ} ĊĠĠĠĠĠ Ġ. build () ĊĠ Ġ) ĊĊĠ Ġinit Ġ{ ĊĠĠĠ ĠLogger . info (" Creating Ġ${ context . parent . path () }/${ self . path (). name () }") ĊĠĠĠ Ġtimers . start Periodic Timer ( Tick Key , ĠTick , Ġjava . time . Duration . of Minutes ( 1 )) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġcreate Receive (): ĠReceive Ġ= Ġreceive Builder () ĊĠĠĠ Ġ. match Any Ġ{ ĊĠĠĠĠĠ Ġwhen Ġ( it ) Ġ{ ĊĠĠĠĠĠĠĠ Ġis ĠTick Ġ-> Ġhandle ( it ) ĊĠĠĠĠĠĠĠ Ġis ĠCreate Rooms Ġ-> Ġhandle ( it ) ĊĠĠĠĠĠĠĠ Ġis ĠUser Joined Room Ġ-> Ġhandle ( it ) ĊĠĠĠĠĠĠĠ Ġis ĠUser Left Room Ġ-> Ġhandle ( it ) ĊĠĠĠĠĠĠĠ Ġis ĠUser Logged Out Ġ-> Ġhandle ( it ) ĊĠĠĠĠĠĠĠ Ġis ĠUser Disconnected Ġ-> Ġhandle ( it ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġ. build () ĊĊĠ Ġ/** ĊĠĠ Ġ* ĠMain Ġgame Ġtick Ġentry Ġpoint ĊĠĠ Ġ* ĊĠĠ Ġ* ĠCall Ġwhatever Ġneeds Ġto Ġbe Ġiter ated Ġin Ġa Ġserver Ġtick Ġhere ĊĠĠ Ġ*/ ĊĠ Ġprivate Ġfun Ġhandle ( cmd : ĠTick ) Ġ{ ĊĠĠĠ ĠLogger . debug (" tick =${ context . parent . path () }/${ self . path (). name () }") ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġhandle ( cmd : ĠCreate Rooms ) Ġ{ ĊĠĠĠ ĠLogger . info (" Create Rooms ") ĊĊĠĠĠ Ġval Ġactor Ref Ġ= Ġcontext . actor Of ( ĊĠĠĠĠĠ ĠRoom s Actor . props ( app Config , Ġcmd . zone ). with Dispatcher ( app Config . dispatch ers . affinity ), ĊĠĠĠĠĠ Ġ" rooms " ĊĠĠĠ Ġ) ĊĠĠĠ Ġsender . tell ( Rooms Created ( actor Ref ), Ġself ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġhandle ( event : ĠUser Joined Room ) Ġ{ ĊĠĠĠ ĠLogger . info (" User Joined Room ") ĊĊĠĠĠ Ġusers [ event . user ]?. add ( event . room ) Ġ?: Ġusers . put ( event . user , Ġmutable Set Of ( event . room )) ĊĊĠĠĠ Ġ( event . room . extension Ġas ĠRoom Extension ). room Actor (). tell ( Add Player ( event . user ), Ġno Sender ()) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġhandle ( event : ĠUser Left Room ) Ġ{ ĊĠĠĠ ĠLogger . info (" User Left Room ") ĊĊĠĠĠ Ġusers [ event . user ]?. remove ( event . room ) ĊĊĠĠĠ Ġ( event . room . extension Ġas ĠRoom Extension ). room Actor (). tell ( Remove Player ( event . user ), Ġno Sender ()) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġhandle ( event : ĠUser Logged Out ) Ġ{ ĊĠĠĠ ĠLogger . info (" User Logged Out ") ĊĊĠĠĠ Ġusers [ event . user ]?. forEach Ġ{ Ġroom Ġ-> ĊĠĠĠĠĠ Ġ( room . extension Ġas ĠRoom Extension ). room Actor (). tell ( Remove Player ( event . user ), Ġno Sender ()) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġhandle ( event : ĠUser Disconnected ) Ġ{ ĊĠĠĠ ĠLogger . info (" User Disconnected ") ĊĠĠĠ Ġself . tell ( User Logged Out ( event . user ), Ġno Sender ()) ĊĠ Ġ} ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġfun Ġprops ( config : ĠApp Config , Ġzone : ĠZone Extension ): ĠProps Ġ= ĠProps . create ( Zone Actor :: class . java , Ġconfig , Ġzone ) ĊĠ Ġ} Ċ } Ċ