public void StartNewGame(Guid key) { try { //Make sure the client has been authenticated if (!Utility.Global.IsClientAuthenticated(key)) { return; } //Host a new instance of the SurvivalInstanceService service. Zombies.ZombiesService zombiesService = new Zombies.ZombiesService(); //Start the game by loading the test map zombiesService.StartGame(@"Maps\Test.map"); LegendsOfKesmaiSurvival.Core.GameStateInformation.ServerInstanceInformation serverInstanceInformation = _serviceHostingManager.HostZombiesInstance(zombiesService); Console.WriteLine("New instance started:" + serverInstanceInformation.ToString()); //Tell the client to join the new instance GetCallback().JoinedGameCallback(serverInstanceInformation); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public LegendsOfKesmaiSurvival.Core.GameStateInformation.ServerInstanceInformation HostZombiesInstance(Zombies.ZombiesService zombiesService) { LegendsOfKesmaiSurvival.Core.GameStateInformation.ServerInstanceInformation serverInstanceInformation = new Core.GameStateInformation.ServerInstanceInformation(); serverInstanceInformation.ServerId = Guid.NewGuid(); //TODO:Currently this will get any free tcp port on the server. This works but it needs to be a known range so that port forwarding can //be setup for that known range. string baseAddress = "net.tcp://" + System.Environment.MachineName + ":" + GetFreeTcpPort().ToString() + "/LegendsOfKesmaiSurvival/Zombies"; NamedServiceHost host = new NamedServiceHost(zombiesService, new Uri(baseAddress)); host.Name = serverInstanceInformation.ServerId.ToString(); NetTcpBinding binding = new NetTcpBinding(SecurityMode.None, true); binding.MaxBufferSize = int.MaxValue; binding.MaxReceivedMessageSize = int.MaxValue; binding.ReaderQuotas.MaxArrayLength = int.MaxValue; binding.SendTimeout = TimeSpan.FromSeconds(10); ServiceEndpoint gamePlayEndpoint = host.AddServiceEndpoint(typeof(Zombies.IGameplay), binding, "/Gameplay"); serverInstanceInformation.GameplayUri = new Uri(baseAddress + "/Gameplay"); host.ServerInstanceInformation = serverInstanceInformation; host.Open(); this.ServiceHosts.Add(host); return(serverInstanceInformation); }