public void Run() { LoggerManager.ServerMsg("Server started at local IP: '" + GetLocalIPAddress() + "', external IP: '" + GetExternalIPAddress() + "' and port: '" + NetServer.Configuration.Port + "'"); LoggerManager.ServerMsg("Waiting for new connections and updating world state to current ones"); UpdateTimer = new Timer(_ => Update(), null, 0, 16 + 2 / 3); NetServer.Start(); LoggerManager.ServerMsg("Server started..."); while (true) { NetIncomingMessage inc; if ((inc = NetServer.ReadMessage()) == null) { continue; } switch (inc.MessageType) { case NetIncomingMessageType.ConnectionApproval: var connectionType = (PacketTypes)inc.ReadByte(); switch (connectionType) { case PacketTypes.Login: { var login = new LoginCommand(); login.Run(LoggerManager, MongoClient, NetServer, inc, null, AllPlayers, GameRooms); continue; } case PacketTypes.Register: { var login = new RegisterCommand(); login.Run(LoggerManager, MongoClient, NetServer, inc, null, AllPlayers, GameRooms); continue; } } const string deniedReason = "Faulty connection type"; inc.SenderConnection.Deny(deniedReason); LoggerManager.ServerMsg(deniedReason); break; case NetIncomingMessageType.Data: Data(inc); break; case NetIncomingMessageType.StatusChanged: StatusChanged(inc); break; } } }