예제 #1
0
        static int Main(string[] args)
        {
            ServerHandlerV2.Initialize();
            EntityStore.LoadMelee();
            EntityStore.LoadRanged();
            gameTime = new ServerTime();

            if (args.Length < 1)
            {
                return(-1);
            }
            server = new ServerV2(args[0]);
            server.start(27015, 5);
            while (true)
            {
                ;
            }
        }
예제 #2
0
        public void start(int port, int slots)
        {
            _server.Start(port);
            _server.DisconnectTimeout = 60000;

            //Connection Request handler
            _listener.ConnectionRequestEvent += request =>
            {
                if (_server.PeersCount < slots)
                {
                    request.AcceptIfKey("FrozenPizza");
                }
                else
                {
                    NetDataWriter writer = new NetDataWriter();
                    writer.Put("Server is full");
                    request.Reject(writer);
                }
            };
            //Connect handler
            _listener.PeerConnectedEvent += peer =>
            {
                _clients.Add(peer);
                Console.WriteLine("New client connected: {0}", peer.EndPoint);
                players.Add(peer, new Player(peer.Id, "Player" + peer.Id, new Vector2(10, 10), 100));
                NetDataWriter writer  = new NetDataWriter();
                var           payload = new { version = Assembly.GetExecutingAssembly().GetName().Version.ToString() };
                writer.Put(".WELCOME " + JsonConvert.SerializeObject(payload));
                peer.Send(writer, DeliveryMethod.ReliableOrdered);
            };
            //Disconnect handler
            _listener.PeerDisconnectedEvent += (peer, disconnectInfo) =>
            {
                Console.WriteLine("Client disconnected: {0}", peer.EndPoint);
                players.Remove(peer);
                _clients.Remove(peer);
                NetDataWriter writer = new NetDataWriter();
                writer.Put(".RMPLAYER " + peer.Id);
                broadcast(peer, writer, DeliveryMethod.ReliableOrdered);
            };
            _listener.NetworkReceiveEvent += (fromPeer, dataReader, deliveryMethod) => { ServerHandlerV2.Parse(fromPeer, dataReader, deliveryMethod); };
            run();
        }