private static void CheckMasterServerListed() { var servers = MasterServerRetriever.RetrieveWorkingMasterServersEndpoints(); var ownEndpoint = $"{Helper.GetOwnIpAddress()}:{Port}"; if (!servers.Contains(ownEndpoint)) { ConsoleLogger.Log(LogLevels.Error, $"You're not in the master-servers URL ({RepoConstants.MasterServersListShortUrl}) " + "Clients/Servers won't see you"); } else { ConsoleLogger.Log(LogLevels.Normal, "Own ip correctly listed in master - servers URL"); } }
private static void RegisterServer(IMessageBase message, NetIncomingMessage netMsg) { var msgData = (MsRegisterServerMsgData)message.Data; if (!ServerDictionary.ContainsKey(msgData.Id)) { ServerDictionary.TryAdd(msgData.Id, new Server(msgData, netMsg.SenderEndPoint)); ConsoleLogger.Log(LogLevels.Normal, $"NEW SERVER: {netMsg.SenderEndPoint}"); } else { //Just update ServerDictionary[msgData.Id] = new Server(msgData, netMsg.SenderEndPoint); } }
public static void MainEntryPoint(string[] args) { IsNightly = args.Any(a => a.Contains("nightly")); if (Common.PlatformIsWindows()) { ConsoleUtil.DisableConsoleQuickEdit(); } Console.Title = $"LMP MasterServer {LmpVersioning.CurrentVersion}"; if (IsNightly) { Console.Title += " NIGHTLY"; } Console.OutputEncoding = Encoding.Unicode; var commandLineArguments = new Arguments(args); if (commandLineArguments["h"] != null) { ShowCommandLineHelp(); return; } if (!ParseMasterServerPortNumber(commandLineArguments)) { return; } if (!ParseHttpServerPort(commandLineArguments)) { return; } ConsoleLogger.Log(LogLevels.Normal, $"Starting MasterServer at port: {Lidgren.MasterServer.Port}"); if (IsNightly) { ConsoleLogger.Log(LogLevels.Normal, "Will download NIGHTLY versions!"); } ConsoleLogger.Log(LogLevels.Normal, $"Listening for GET requests at port: {LunaHttpServer.Port}"); if (CheckPort()) { Lidgren.MasterServer.RunServer = true; LunaHttpServer.Start(); Task.Run(() => Lidgren.MasterServer.Start()); } }
private static bool ParseMaxRequestsPerSecond(Arguments commandLineArguments) { if (commandLineArguments["f"] != null) { if (int.TryParse(commandLineArguments["f"].Trim(), out var floodSeconds) && floodSeconds >= 0) { FloodControl.MaxRequestsPerMs = floodSeconds; } else { ConsoleLogger.Log(LogLevels.Error, $"Invalid max request per second specified: {commandLineArguments["f"].Trim()}"); return(false); } } return(true); }
public static void MainEntryPoint(string[] args) { if (Common.PlatformIsWindows()) { ConsoleUtil.DisableConsoleQuickEdit(); } Console.Title = $"LMP MasterServer {LmpVersioning.CurrentVersion}"; Console.OutputEncoding = Encoding.Unicode; var commandLineArguments = new Arguments(args); if (commandLineArguments["h"] != null) { ShowCommandLineHelp(); return; } if (!ParseMasterServerPortNumber(commandLineArguments)) { return; } if (!ParseHttpServerPort(commandLineArguments)) { return; } if (!ParseMaxRequestsPerSecond(commandLineArguments)) { return; } ConsoleLogger.Log(LogLevels.Normal, $"Starting MasterServer at port: {MasterServer.Port}"); ConsoleLogger.Log(LogLevels.Normal, $"Listening for GET requests at port: {LunaHttpServer.Port}"); if (CheckPort()) { MasterServer.RunServer = true; Task.Run(() => new LunaHttpServer().Listen()); Task.Run(() => MasterServer.Start()); } }
private static void RemoveExpiredServers() { Task.Run(async() => { while (RunServer) { var serversIdsToRemove = ServerDictionary .Where(s => LunaTime.UtcNow.Ticks - s.Value.LastRegisterTime > TimeSpan.FromMilliseconds(ServerMsTimeout).Ticks) .ToArray(); foreach (var serverId in serversIdsToRemove) { ConsoleLogger.Log(LogLevels.Normal, $"REMOVING SERVER: {serverId.Value.ExternalEndpoint}"); ServerDictionary.TryRemove(serverId.Key, out var _); } await Task.Delay(ServerRemoveMsCheckInterval); } }); }
private static void HandleMessage(IMasterServerMessageBase message, NetIncomingMessage netMsg, NetPeer peer) { try { switch ((message?.Data as MsBaseMsgData)?.MasterServerMessageSubType) { case MasterServerMessageSubType.RegisterServer: RegisterServer(message, netMsg); break; case MasterServerMessageSubType.RequestServers: ConsoleLogger.Log(LogLevels.Normal, $"LIST REQUEST from: {netMsg.SenderEndPoint}"); SendServerLists(netMsg, peer); break; case MasterServerMessageSubType.Introduction: var msgData = (MsIntroductionMsgData)message.Data; if (ServerDictionary.TryGetValue(msgData.Id, out var server)) { ConsoleLogger.Log(LogLevels.Normal, $"INTRODUCTION request from: {netMsg.SenderEndPoint} to server: {server.ExternalEndpoint}"); peer.Introduce(server.InternalEndpoint, server.ExternalEndpoint, Common.CreateEndpointFromString(msgData.InternalEndpoint), // client internal netMsg.SenderEndPoint, // client external msgData.Token); // request token } else { ConsoleLogger.Log(LogLevels.Warning, $"Client {netMsg.SenderEndPoint} requested introduction to nonlisted host!"); } break; } } catch (Exception e) { ConsoleLogger.Log(LogLevels.Error, $"Error handling message. Details: {e}"); } }