@@ -24,7 +24,8 @@ public static class Server {
2424 public static Dictionary < ushort , EntityUpdate > dynamicEntities = new Dictionary < ushort , EntityUpdate > ( ) ;
2525 public static UserDatabase Database ;
2626
27- public static void Setup ( int port ) {
27+ public static void Start ( int port ) {
28+ Log . PrintLn ( "server starting..." ) ;
2829 Database = new UserDatabase ( ) ;
2930 Database . Database . Migrate ( ) ; //Ensure database exists
3031
@@ -103,13 +104,13 @@ public static void Setup(int port) {
103104 tcpListener = new TcpListener ( IPAddress . Any , port ) ;
104105 tcpListener . Start ( ) ;
105106 new Thread ( new ThreadStart ( ListenTCP ) ) . Start ( ) ;
107+ Log . PrintLn ( "loading completed" ) ;
106108 }
107109
108110 private static void ListenTCP ( ) {
109111 var player = new Player ( tcpListener . AcceptTcpClient ( ) ) ;
110112 new Thread ( new ThreadStart ( ListenTCP ) ) . Start ( ) ;
111- Console . ForegroundColor = ConsoleColor . Blue ;
112- Console . WriteLine ( player . IP + " connected" ) ;
113+ Log . PrintLn ( player . IP + " connected" , ConsoleColor . Blue ) ;
113114 try {
114115 while ( true ) ProcessPacket ( player . reader . ReadByte ( ) , player ) ;
115116 }
@@ -118,8 +119,7 @@ private static void ListenTCP() {
118119 RemovePlayerEntity ( player , false ) ;
119120 }
120121 players . Remove ( player ) ;
121- Console . ForegroundColor = ConsoleColor . Red ;
122- Console . WriteLine ( player . IP + " disconnected" ) ;
122+ Log . PrintLn ( player . IP + " disconnected" , ConsoleColor . Red ) ;
123123 }
124124 }
125125 private static void ListenUDP ( ) {
@@ -201,16 +201,14 @@ private static void ProcessPacket(byte packetID, Player source) {
201201
202202 dynamicEntities . Add ( ( ushort ) source . entity . guid , source . entity ) ;
203203
204- Console . ForegroundColor = ConsoleColor . Green ;
205- Console . WriteLine ( source . IP + " logged in as " + username ) ;
204+ Log . PrintLn ( source . IP + " logged in as " + username , ConsoleColor . Green ) ;
206205 break ;
207206 #endregion
208207 case ServerPacketID . Logout :
209208 #region logout
210209 if ( source . entity == null ) break ; //not logged in
211210 RemovePlayerEntity ( source , false ) ;
212- Console . ForegroundColor = ConsoleColor . Yellow ;
213- Console . WriteLine ( source . IP + " logged out" ) ;
211+ Log . PrintLn ( source . IP + " logged out" , ConsoleColor . Yellow ) ;
214212 break ;
215213 #endregion
216214 case ServerPacketID . Register :
@@ -229,13 +227,12 @@ private static void ProcessPacket(byte packetID, Player source) {
229227 source . writer . Write ( ( byte ) ServerPacketID . Register ) ;
230228 source . writer . Write ( ( byte ) registerResponse ) ;
231229 if ( registerResponse == RegisterResponse . Success ) {
232- Console . ForegroundColor = ConsoleColor . Cyan ;
233- Console . WriteLine ( source . IP + " registered: " + username ) ;
230+ Log . PrintLn ( source . IP + " registered as " + username , ConsoleColor . Cyan ) ;
234231 }
235232 break ;
236233 #endregion
237234 default :
238- Console . WriteLine ( $ "unknown packetID { packetID } received from { source . IP } ") ;
235+ Log . PrintLn ( $ "unknown packetID { packetID } received from { source . IP } ", ConsoleColor . Magenta ) ;
239236 source . tcpClient . Close ( ) ;
240237 break ;
241238 }
@@ -376,10 +373,8 @@ private static void ProcessDatagram(byte[] datagram, Player source) {
376373 }
377374 break ;
378375 }
379- Console . ForegroundColor = ConsoleColor . Cyan ;
380- Console . Write ( dynamicEntities [ chat . Sender ] . name + ": " ) ;
381- Console . ForegroundColor = ConsoleColor . White ;
382- Console . WriteLine ( chat . Text ) ;
376+ Log . Print ( dynamicEntities [ chat . Sender ] . name + ": " , ConsoleColor . Cyan ) ;
377+ Log . PrintLn ( chat . Text , ConsoleColor . White , false ) ;
383378
384379 BroadcastUDP ( chat . data , null ) ; //pass to all players
385380 break ;
@@ -406,7 +401,7 @@ private static void ProcessDatagram(byte[] datagram, Player source) {
406401 specialMove . Guid = ( ushort ) source . entity . guid ;
407402 SendUDP ( specialMove . data , target ) ;
408403 }
409- break ;
404+ break ;
410405 case SpecialMoveID . CursedArrow :
411406 case SpecialMoveID . ArrowRain :
412407 case SpecialMoveID . Shrapnel :
@@ -424,7 +419,7 @@ private static void ProcessDatagram(byte[] datagram, Player source) {
424419 case DatagramID . HolePunch :
425420 break ;
426421 default :
427- Console . WriteLine ( $ "unknown DatagramID { datagram [ 0 ] } received from { source . IP } ") ;
422+ Log . PrintLn ( $ "unknown DatagramID { datagram [ 0 ] } received from { source . IP } ", ConsoleColor . Magenta ) ;
428423 Kick ( source , "invalid data received" ) ;
429424 break ;
430425 }
0 commit comments