package Ġsz ew ek . fl . network Ċ Ċ import Ġio . netty . buffer . Un p ooled Ċ import Ġio . netty . channel . Channel Future Listener Ċ import Ġio . netty . channel . Channel Handler Ċ import Ġio . netty . channel . Channel HandlerContext Ċ import Ġio . netty . channel . Simple Channel Inbound Handler Ċ import Ġnet . minecraft . entity . player . Entity Player MP Ċ import Ġnet . minecraft . network . Packet Buffer Ċ import Ġnet . minecraftforge . fml . common . network . F MLE mbed ded Channel Ċ import Ġnet . minecraftforge . fml . common . network . FM LO ut bound Handler Ċ import Ġnet . minecraftforge . fml . common . network . Network Registry Ċ import Ġnet . minecraftforge . fml . common . network . internal . F ML Proxy Packet Ċ import Ġnet . minecraftforge . fml . rel a unch er . Side Ċ import Ġsz ew ek . fl . FL Ċ import Ġsz ew ek . fl . FL X Ċ Ċ @ Channel Handler . Sh arable Ċ class ĠFL Net Channel ( private Ġval Ġch name : ĠString , Ġprivate Ġval Ġids : ĠList < Class < out ĠFL Net Msg >>) Ġ: ĠSimple Channel Inbound Handler < F ML Proxy Packet >() Ġ{ Ċ ĉ private Ġval Ġsrv Chan : ĠF MLE mbed ded Channel Ċ ĉ private Ġval Ġcli Chan : ĠF MLE mbed ded Channel ĊĊ ĉ init Ġ{ Ċĉ ĉ val Ġchannels Ġ= ĠNetwork Registry . INSTANCE . new Channel ( ch name , Ġthis ) Ċĉ ĉ srv Chan Ġ= Ġchannels [ Side . SERVER ] !! Ċĉ ĉ cli Chan Ġ= Ġchannels [ Side . CLIENT ] !! Ċ ĉ } ĊĊ ĉ @ Throws ( Exception :: class ) Ċ ĉ override Ġfun Ġchannel Read 0 ( ctx : ĠChannel HandlerContext , Ġmsg : ĠF ML Proxy Packet ) Ġ{ Ċĉ ĉ try Ġ{ Ċĉĉ ĉ val Ġs Ġ= ĠFL X . PROXY !!. net Util . check ( msg . handler ()) Ċĉĉ ĉ val Ġtup Ġ= ĠFL X . PROXY !!. net Util . preprocess ( msg , Ġs !! ) Ċĉĉ ĉ if Ġ( tup Ġ== Ġnull ) Ġ{ Ċĉĉĉ ĉ FL . L !!. warn (" No ĠTuple ") Ċĉĉĉ ĉ return Ċĉĉ ĉ } Ċĉĉ ĉ val Ġit l Ġ= Ġtup . first Ċĉĉ ĉ val Ġep Ġ= Ġtup . second Ċĉĉ ĉ var Ġpb : ĠPacket Buffer ? Ġ= Ġmsg . payload () Ġas ĠPacket Buffer Ċĉĉ ĉ if Ġ( pb Ġ== Ġnull ) Ċĉĉĉ ĉ pb Ġ= ĠPacket Buffer ( msg . payload ()) Ċĉĉ ĉ val Ġid Ġ= Ġpb . read Byte () Ċĉĉ ĉ val Ġfm Ġ= Ġids [ id . toInt ()]. newInstance () Ċĉĉ ĉ if Ġ(! it l . is Calling From Minecraft Thread ) Ġ{ Ċĉĉĉ ĉ try Ġ{ Ċĉĉĉĉ ĉ fm . decode ( pb ) Ċĉĉĉ ĉ } Ġcatch Ġ( fx : ĠException ) Ġ{ Ċĉĉĉĉ ĉ fm . exception ( fx ) Ċĉĉĉ ĉ } ĊĊĉĉĉ ĉ it l . add Scheduled Task ( FL Net Msg . Decode ( fm , Ġep , Ġs )) Ċĉĉ ĉ } Ċĉ ĉ } Ġcatch Ġ( x : ĠException ) Ġ{ Ċĉĉ ĉ FL . L !!. error ("[ FL Net Channel ] ĠException Ġthrown Ġwhile Ġdecoding !", Ġx ) Ċĉ ĉ } ĊĊ ĉ } ĊĊ ĉ @ Throws ( Exception :: class ) Ċ ĉ override Ġfun Ġuser Event Triggered ( ctx : ĠChannel HandlerContext , Ġevt : ĠAny ) Ġ{ Ċĉ ĉ // Ġfire User Event Ċ ĉ } ĊĊ ĉ @ Throws ( Exception :: class ) Ċ ĉ override Ġfun Ġexception Ca ught ( ctx : ĠChannel HandlerContext , Ġcause : ĠThrowable ) Ġ{ Ċĉ ĉ FL . L !!. error (" FL Net Channel Ġexception ", Ġcause ) Ċĉ ĉ super . exception Ca ught ( ctx , Ġcause ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġsend ( ch : ĠF MLE mbed ded Channel , Ġmsg : ĠFL Net Msg , Ġot : ĠFM LO ut bound Handler . Outbound Target , Ġarg : ĠAny ?) Ġ{ Ċĉ ĉ val Ġpb Ġ= ĠPacket Buffer ( Un p ooled . buffer ()) Ċĉ ĉ val Ġid Ġ= Ġids . indexOf ( msg . java Class ). to Byte () Ċĉ ĉ pb . write Byte ( id . toInt ()) Ċĉ ĉ try Ġ{ Ċĉĉ ĉ msg . encode ( pb ) Ċĉ ĉ } Ġcatch Ġ( x : ĠException ) Ġ{ Ċĉĉ ĉ msg . exception ( x ) Ċĉĉ ĉ return Ċĉ ĉ } ĊĊĉ ĉ ch . attr < FM LO ut bound Handler . Outbound Target >( FM LO ut bound Handler . F ML _ MESS AG ET ARGET ). set ( ot ) Ċĉ ĉ if Ġ( arg Ġ!= Ġnull ) Ċĉĉ ĉ ch . attr ( FM LO ut bound Handler . F ML _ MESS AG ET ARGET ARGS ). set ( arg ) Ċĉ ĉ ch . write And Flush ( F ML Proxy Packet ( pb , Ġch name )). addListener ( Channel Future Listener . FIRE _ EXCEPTION _ ON _ FAILURE ) Ċ ĉ } ĊĊ ĉ fun Ġto ( msg : ĠFL Net Msg , Ġmp : ĠEntity Player MP ) Ġ{ Ċĉ ĉ send ( srv Chan , Ġmsg , ĠFM LO ut bound Handler . Outbound Target . PLAYER , Ġmp ) Ċ ĉ } ĊĊ ĉ fun Ġto All ( msg : ĠFL Net Msg ) Ġ{ Ċĉ ĉ send ( srv Chan , Ġmsg , ĠFM LO ut bound Handler . Outbound Target . ALL , Ġnull ) Ċ ĉ } ĊĊ ĉ fun Ġto All Around ( msg : ĠFL Net Msg , Ġtp : ĠNetwork Registry . Target Point ) Ġ{ Ċĉ ĉ send ( srv Chan , Ġmsg , ĠFM LO ut bound Handler . Outbound Target . ALL AR O UND POINT , Ġtp ) Ċ ĉ } ĊĊ ĉ fun Ġto Dimension ( msg : ĠFL Net Msg , Ġdim Id : ĠInt ) Ġ{ Ċĉ ĉ send ( srv Chan , Ġmsg , ĠFM LO ut bound Handler . Outbound Target . DIMENSION , Ġdim Id ) Ċ ĉ } ĊĊ ĉ fun Ġto Server ( msg : ĠFL Net Msg ) Ġ{ Ċĉ ĉ send ( cli Chan , Ġmsg , ĠFM LO ut bound Handler . Outbound Target . TO SERVER , Ġnull ) Ċ ĉ } Ċ } Ċ