Esempio n. 1
0
        public BeepLiveGame(BeepConfig beepConfig, Guid playerGuid)
        {
            BeepConfig = beepConfig;
            PlayerGuid = playerGuid;

            Map = new Map(beepConfig.MapConfig);

            Teams = beepConfig.TeamConfigs.Select(x => new Team(this, x)).ToList();
        }
Esempio n. 2
0
        public BeepServer()
        {
            IConfiguration config = new ConfigurationBuilder()
                                    .AddJsonFile("appSettings.json", false, true)
                                    .Build();

            using var loggerFactory = LoggerFactory.Create(x => x
                                                           .AddConfiguration(config.GetSection("Logging"))
                                                           .AddConsole());

            Logger = loggerFactory.CreateLogger <BeepServer>();

            IConfigurationSection networkConfig = config.GetSection("Network");

            Players = new List <ServerPlayer>();

            IPAddress hostAddress = IPAddress.Parse("127.0.0.1");

            TcpListener tcpListener = new TcpListener(hostAddress, networkConfig.GetValue <int>("TcpPort"));

            GameServer = new NetTcpServer(tcpListener, new StreamProtobuf(PrefixStyle.Base128, Packet.PacketTypes));

            GameServer.PacketReceivedEvent += HandlePacket;

            const string beepConfigXml = "BeepConfig.xml";

            if (!File.Exists(beepConfigXml))
            {
                BeepConfig = new BeepConfig();
                File.WriteAllText(beepConfigXml, XmlHelper.ToXml(BeepConfig));
            }
            else
            {
                BeepConfig = XmlHelper.LoadFromXmlString <BeepConfig>(File.ReadAllText(beepConfigXml));
            }

            tcpListener.Start();

            _ = GameServer.AcceptClients(
                (server, _) => server.Clients.Count < 20,
                server => server.Clients.Count < 20);

            _ = GameServer.AcceptPackets();
        }
Esempio n. 3
0
 public SyncPacket(BeepConfig beepConfig)
 {
     BeepConfig = beepConfig;
 }