@@ -46,11 +46,6 @@ public static ServerContainer Create(IPEndPoint ip, bool enableLogging = false,
4646 /// </summary>
4747 public TcpListener tcpListener ;
4848
49- /// <summary>
50- /// The formatter used to encode / decode all packets.
51- /// </summary>
52- public IFormatter ? GlobalFormatter = null ; // TODO: ?? Move to connections (per-client) ??
53-
5449 /// <summary>
5550 /// An event that is called when a packet is received.
5651 /// </summary>
@@ -159,7 +154,7 @@ public void SetLogger(Logger? logger = null) {
159154 public bool SendPacket ( Packet packet , Connection connection ) {
160155 if ( Closed ) { return false ; }
161156 try {
162- connection . Serializer . WritePacket ( packet , GlobalFormatter ) ;
157+ connection . Serializer . WritePacket ( packet , connection . Formatter ) ;
163158 } catch ( IOException e ) {
164159 Logger ? . LogError ( $ "Could not send packet (connection ID: { connection . ToConnectionID ( ) } ):") ;
165160 Logger ? . LogException ( e , Severity . Error ) ;
@@ -214,7 +209,7 @@ public bool BroadcastPacket(Packet packet) {
214209 public async ValueTask < bool > SendPacketAsync ( Packet packet , Connection connection ) {
215210 if ( Closed ) { return false ; }
216211 try {
217- connection . Serializer . WritePacket ( packet , GlobalFormatter ) ; // TODO?: this isnt really async.
212+ connection . Serializer . WritePacket ( packet , connection . Formatter ) ; // TODO?: this isnt really async.
218213 } catch ( IOException e ) {
219214 Logger ? . LogError ( $ "Could not send packet (connection ID: { connection . ToConnectionID ( ) } ):") ;
220215 Logger ? . LogException ( e , Severity . Error ) ;
@@ -371,7 +366,7 @@ private void ListenConnection(IAsyncResult result) {
371366 connections . Add ( connection . ID , connection ) ;
372367 OnConnect ? . Invoke ( this , connection ) ;
373368 try {
374- if ( ! connection . Parser . Parse ( GlobalFormatter , ( ) => Closed || connection . Closed , p => {
369+ if ( ! connection . Parser . Parse ( connection . Formatter , ( ) => Closed || connection . Closed , p => {
375370 OnPacket ? . Invoke ( this , connection , p ) ;
376371 if ( p is DisconnectPacket ) {
377372 connections . Remove ( connection . ID ) ;
0 commit comments