/// <summary> /// Execute the program. /// </summary> /// <param name="args">Supplies arguments. The only valid argument is /// the -service argument, which directs the program to attempt to /// connect to the SCM for service-mode startup; otherwise, the program /// executes as a console application.</param> static void Main(string[] args) { // // Scan and process arguments. // for (int i = 0; i < args.Length; i += 1) { string Arg = args[i]; if (Arg == "-service") { // // Execute the server in service mode. This method returns // once service stop has been requested and the server has // shut down. // string ServiceName = "NWMasterServerSvc"; if ((i + 1) < args.Length) { i += 1; ServiceName = args[i]; } ServiceController.ExecuteService(ServiceName); return; } } // // Execute the server as an interactive, console application. // NWMasterServer ServerObject = new NWMasterServer(null); ServerObject.Run(); }
/// <summary> /// Called when a server info update is available. /// </summary> /// <param name="Info">Supplies the new server information /// structure.</param> public void OnServerInfoUpdate(NWMasterServer.ServerInfo Info) { DateTime Now = DateTime.UtcNow; lock (this) { LastHeartbeat = Now; if ((ExpansionsMask != Info.ExpansionsMask) || (MaximumPlayerCount != Info.MaximumPlayers) || (ActivePlayerCount != Info.ActivePlayers) || (LocalVault != Info.IsLocalVault) || (BuildNumber != Info.BuildNumber) || (PrivateServer != Info.HasPlayerPassword) || (ModuleName != Info.ModuleName) || (MinimumLevel != Info.MinLevel) || (MaximumLevel != Info.MaximumPlayers) || (PVPLevel != Info.PVPLevel) || (PlayerPause != Info.IsPlayerPauseAllowed) || (OnePartyOnly != Info.IsOnePartyOnly) || (ELCEnforced != Info.IsELC) || (ILREnforced != Info.HasILR)) { ExpansionsMask = Info.ExpansionsMask; MaximumPlayerCount = Info.MaximumPlayers; ActivePlayerCount = Info.ActivePlayers; LocalVault = Info.IsLocalVault; PrivateServer = Info.HasPlayerPassword; BuildNumber = Info.BuildNumber; ModuleName = Info.ModuleName; MinimumLevel = Info.MinLevel; MaximumLevel = Info.MaxLevel; PVPLevel = Info.PVPLevel; PlayerPause = Info.IsPlayerPauseAllowed; OnePartyOnly = Info.IsOnePartyOnly; ELCEnforced = Info.IsELC; ILREnforced = Info.HasILR; if (!Online) MarkServerOnline(); Save(); } else { Timesave(); } } }
/// <summary> /// Set up a SocketInfo descriptor for a socket and bind it to a /// local endpoint. /// </summary> /// <param name="MasterServer">Supplies the associated master /// server object.</param> /// <param name="BindAddress">Supplies the bind address.</param> /// <param name="BindPort">Supplies the bind port, else 0 if there /// is to be no specific local bind port.</param> /// <param name="SocketUse">Supplies the usage type of the /// socket.</param> /// <param name="OnRecvSocketDatagram">Supplies the high level /// socket receive message callback for the socket.</param> public SocketInfo(NWMasterServer MasterServer, IPAddress BindAddress, int BindPort, SocketUse SocketUse, OnRecvSocketDatagramDelegate OnRecvSocketDatagram) { this.MasterServer = MasterServer; this.SocketUse = SocketUse; this.OnRecvSocketDatagram = OnRecvSocketDatagram; for (int i = 0; i < BUFFER_COUNT; i += 1) { SocketRecvBuffer Buffer = new SocketRecvBuffer(); Buffers[i] = Buffer; Buffer.Buffer = new byte[MAX_FRAME_SIZE]; Buffer.Sender = new IPEndPoint(0, 0); Buffer.SocketDescriptor = this; } Socket.Blocking = false; Socket.Bind(new IPEndPoint(BindAddress, BindPort)); Socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.PacketInformation, true); }
public NWGameServer(NWMasterServer MasterServer, IPEndPoint ServerAddress) { Timer HbTimer; this.MasterServer = MasterServer; this.Address = ServerAddress; this.InitialHeartbeat = false; HbTimer = new Timer(HEARTBEAT_INTERVAL + (Rng.Next() % HEARTBEAT_JITTER)); HbTimer.AutoReset = false; HbTimer.Elapsed += new ElapsedEventHandler(HeartbeatTimer_Elapsed); this.HeartbeatTimer = HbTimer; }
/// <summary> /// Instantiate a server tracker instance. The list of currently /// known servers is retrieved from the database, but heartbeats are /// not yet enabled as the I/O subsystem is not yet online. /// </summary> /// <param name="MasterServer">Supplies the underlying associated /// master server instance.</param> public NWServerTracker(NWMasterServer MasterServer) { this.MasterServer = MasterServer; PendingGameServersSweepTimer = new System.Timers.Timer(PENDING_GAME_SERVER_SWEEP_INTERVAL); PendingGameServersSweepTimer.AutoReset = false; PendingGameServersSweepTimer.Elapsed += new System.Timers.ElapsedEventHandler(PendingGameServersSweepTimer_Elapsed); ScavengerSweepTimer = new System.Timers.Timer(SCAVENGE_SWEEP_INTERVAL); ScavengerSweepTimer.AutoReset = false; ScavengerSweepTimer.Elapsed += new System.Timers.ElapsedEventHandler(ScavengerSweepTimer_Elapsed); BlacklistSweepTimer = new System.Timers.Timer(BLACKLIST_SWEEP_INTERVAL); BlacklistSweepTimer.AutoReset = false; BlacklistSweepTimer.Elapsed += new System.Timers.ElapsedEventHandler(BlacklistSweepTimer_Elapsed); InitializeDatabase(); }