예제 #1
0
파일: Player.cs 프로젝트: aotis/AngryTanks
        public Player(GameKeeper gameKeeper, Byte slot, NetConnection connection, PlayerInformation playerInfo)
        {
            this.Slot       = slot;
            this.Connection = connection;
            this.Team       = playerInfo.Team;
            this.Callsign   = playerInfo.Callsign;
            this.Tag        = playerInfo.Tag;

            this.gameKeeper = gameKeeper;

            this.playerState = PlayerState.Joining;

            Log.InfoFormat("Player #{0} \"{1}\" <{2}> created and joined to {3}", Slot, Callsign, Tag, Team);
        }
예제 #2
0
        static void Main(String[] args)
        {
            UInt16 port = 5150;
            int verbosity = 0;
            bool showHelp = false;
            String worldFilePath = null;
            Dictionary<String, String> variables = new Dictionary<String, String>();

            OptionSet p = new OptionSet()
            {
                {
                    "p|port=",
                    "sets the port to run the server on",
                    (UInt16 v) => port = v
                },
                {
                    "w|world=",
                    "sets the world file to serve",
                    (String v) => worldFilePath = v
                },
                {
                    "s|set=",
                    "sets a variable",
                    (String k, String v) => { variables[k] = v; }
                },
                {
                    "v",
                    "increases verbosity level",
                    v => { if (v != null) ++verbosity; }
                },
                {
                    "h|?|help",
                    "shows this message and exits",
                    v => showHelp = v != null
                },
            };

            List<String> extra;
            try
            {
                extra = p.Parse(args);

                if (worldFilePath == null)
                    throw new OptionException("Missing required world option", "-w|--world");
            }
            catch (OptionException e)
            {
                Log.Fatal(e.Message);
                ShowHelp(p, args);
                return;
            }

            // set logging level
            log4net.Core.Level loggingLevel;

            if (verbosity == 0)
                loggingLevel = log4net.Core.Level.Error;
            else if (verbosity == 1)
                loggingLevel = log4net.Core.Level.Warn;
            else if (verbosity == 2)
                loggingLevel = log4net.Core.Level.Info;
            else
                loggingLevel = log4net.Core.Level.Debug;

            ((log4net.Repository.Hierarchy.Logger)Log.Logger).Level = loggingLevel;

            // do we need to show help?
            if (showHelp)
            {
                ShowHelp(p, args);
                return;
            }

            // and does it exist?
            if (!File.Exists(worldFilePath))
            {
                Log.FatalFormat("A world file does not exist at '{0}'", worldFilePath);
                ShowHelp(p, args);
                return;
            }

            // let's read the world now and save it
            rawWorld = ReadWorld(worldFilePath);

            // TODO parse world, also checks if valid

            NetPeerConfiguration config = new NetPeerConfiguration("AngryTanks");

            // we need to enable these default disabled message types
            config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            config.EnableMessageType(NetIncomingMessageType.ConnectionLatencyUpdated);

            // use configured port
            config.Port = port;

            // start server
            server = new NetServer(config);
            server.Start();

            // let's start game keeper
            gameKeeper = new GameKeeper(server, rawWorld);

            // go to main loop
            AppLoop();
        }