public async void CreateServer(int playerCount) { IsServerBeingCreated = true; if (GlobalDebugFlag.LogTypes != MessageCategoryTypes.None) { _msgHubLogger = new LoggingMessageHubClient(_msgHub, GlobalDebugFlag.LogTypes); _msgHubLogger.ExceptionPushed += (s, e) => Debug.LogError(e.ToString()); _msgHubLogger.MessagePushed += (s, e) => Debug.Log(e.ToString()); _msgHubLogger.InformationPushed += (s, e) => Debug.Log(e.ToString()); _msgHubLogger.LogPushed += (s, e) => Debug.Log(e.ToString()); _msgHubLogger.Start(); } //create ardnet server _ardServ = ArdNetFactory.GetArdServer(_msgHub); //create game communincation manager //watches for clients //tracks command inputs _commState = await TankSimCommService.Create(_ardServ, playerCount); //cmdFacade.AimChanged += CmdFacade_AimChanged; //release task in new thread to guard against deadlocks IsServerRunning = true; _serverstartupTask.SetResult(_commState.CmdFacade); await _commState.GetConnectionTask(); AreAllPlayersReady = true; }
public RobustServerCLI(bool DEBUG = false) { var configBuilder = new ConfigurationBuilder(); _ = configBuilder.AddJsonFile("config.json", optional: false, reloadOnChange: true); var config = configBuilder.Build(); int serverPort = config.GetValue <int>("ServerPort"); string AppID = config.GetValue <string>("AppID"); MsgHub = new MessageHub(); _ = IPTools.TryGetLocalIP(out var localAddress); var netConfig = new ArdNetServerConfig(AppID, localAddress, serverPort); //var providerFlags = TcpDataStreamOptions.Server | TcpDataStreamOptions.Encrypted; //netConfig.TCP.DataStreamProvider = TcpDataStreamProvider.GetProvider(providerFlags, myCertFactory); ArdServer = new ArdNetServer(netConfig, MsgHub); ArdServer.NetConfig.TCP.HeartbeatConfig.HeartbeatInterval = TimeSpan.FromMilliseconds(1000); ArdServer.NetConfig.TCP.HeartbeatConfig.ForceStrictHeartbeat = true; ArdServer.NetConfig.TCP.HeartbeatConfig.RespondToHeartbeats = false; ArdServer.NetConfig.TCP.HeartbeatConfig.HeartbeatToleranceMultiplier = 0; ArdLogger = new LoggingMessageHubClient( ArdServer.MessageHub, MessageCategoryTypes.ExceptionMessages | MessageCategoryTypes.LoggingMessages); ArdLogger.LogPushed += (sender, msg) => { Console.WriteLine($"LOG: {msg.Message}"); }; ArdLogger.ExceptionPushed += (sender, msg) => { if (msg.Severity == ExceptionSeverity.Expected) { return; } Console.WriteLine($"EXCEPTION: {msg.Exception}"); }; MouseMover = new MouseMover(ArdServer); }