/// <summary>
        ///     Constructor taking the path to the configuration file. 
        ///     Starts the lidgren server to start listening for connections, and 
        ///     initializes all data structres and such.
        /// </summary>
        /// <param name="configpath"></param>
        public RegionServer(string configpath)
        {
            //Load this region server's junk from xml
            XmlSerializer deserializer = new XmlSerializer(typeof(RegionConfig));
            RegionConfig regionconfig = (RegionConfig)deserializer.Deserialize(XmlReader.Create(configpath));

            //Create the server
            var config = new NetPeerConfiguration(regionconfig.ServerName);
            config.Port = regionconfig.ServerPort;
            LidgrenServer = new NetServer(config);
            LidgrenServer.Start();

            //Initizlie our data structures
            Characters = new Dictionary<Guid, Character>();
            UserIdToMasterServer = new Dictionary<Guid, NetConnection>();
            TeleportEnters = new List<TeleportEnter>(regionconfig.TeleportEnters);
            TeleportExits = new List<TeleportExit>(regionconfig.TeleportExits);
            ItemSpawns = new List<ItemSpawn>(regionconfig.ItemSpawns);
            ItemSpawnIdGenerator = new UniqueId();
            ItemSpawnsWaitingForSpawn = new Dictionary<ItemSpawn, DateTime>();

            foreach(ItemSpawn spawn in ItemSpawns)
                ItemSpawnIdGenerator.RegisterId(spawn.Id);

            RegionId = regionconfig.RegionId;
        }
Esempio n. 2
0
        /// <summary>
        /// Default constructor for the WizardryGameServer class.
        /// </summary>
        public WizardryGameServer()
        {
            graphics = new GraphicsDeviceManager( this );
            Content.RootDirectory = "Content";
            textureProvider = new TextureProvider( Content );

            // Windows Settings for the XNA window
            Window.Title = "Wizardry Server";
            graphics.PreferredBackBufferWidth = 200;
            graphics.PreferredBackBufferHeight = 1;

            // Set up the lobbies list
            lobbies = new GameLobby[GameSettings.MAX_LOBBIES];
            for ( int i = 0; i < GameSettings.MAX_LOBBIES; ++i )
            {
                lobbies[i] = null;
            }

            playerLobbies = new ConcurrentDictionary<long, int>();

            // Setup the server configuration
            NetPeerConfiguration config = new NetPeerConfiguration( GameSettings.APP_NAME );
            config.Port = GameSettings.SERVER_PORT_NUM;
            config.EnableMessageType( NetIncomingMessageType.DiscoveryRequest );

            // Start the server
            server = new NetServer( config );
            server.Start();
            WriteConsoleMessage( "Server starting!" );

            // Start the Packet Receiver thread
            Thread packets = new Thread( new ThreadStart( this.PacketProcessor ) );
            packets.Start();
        }
Esempio n. 3
0
        /// <summary>
        ///     Метод для работып отока обработчика входящих новых соединений с сервером
        /// </summary>
        private static void ServerHandleConnections(object obj) {
            Log.Print("Starting Listen connections", LogType.Network);

            var config = new NetPeerConfiguration(Settings.GameIdentifier) {
                Port = Settings.Port,
                MaximumConnections = Settings.MaxConnections,
                SendBufferSize = 400000,
                UseMessageRecycling = true,
            };

            /* Получаем возможные адреса сервера */
            Log.Print("Server IP's:", LogType.Network);
            Log.Print("-------", LogType.Network);
            IPAddress[] ipList = Dns.GetHostAddresses(Dns.GetHostName());
            foreach (IPAddress ip in ipList) {
                if (ip.AddressFamily == AddressFamily.InterNetwork) {
                    Log.Print(ip.ToString(), LogType.Network);
                }
            }
            Log.Print("-------", LogType.Network);

            _server = new NetServer(config);
            _server.Start();

            // Запускаем обработчик пакетов
            StartProcessIncomingMessages();
        }
Esempio n. 4
0
        public GameServer()
        {
            /* Load Resources */
            Console.WriteLine("Loading Resources...");
            Resources = new ResourceManager();
            Resources.Load();

            /* Setting Up Server */
            Console.WriteLine("Starting Up Server...");
            //Package.RecompilePackages();
            //CodeManager StartUp = Package.GetPackage(Game.ServerInfo.StartupPackage).CodeManager;
            //StartUp.RunMain();
            //Game.World.Chunks.ClearWorldGen();
            //Game.World.Chunks.AddWorldGens(StartUp.GetWorldGens());
            Game.World.ClearWorldGen();
            List<WorldGenerator> temp = new List<WorldGenerator>();
            temp.Add(new WorldGenerator());
            Game.World.AddWorldGen(temp);

            /* Listen for Clients */
            NetPeerConfiguration Configuration = new NetPeerConfiguration("FantasyScape");
            Configuration.Port = 54987;
            Configuration.MaximumConnections = 20;
            Server = new NetServer(Configuration);
            Server.Start();
            Message.RegisterServer(Server);

            UpdateTimer = new Stopwatch();
            UpdateTimer.Start();

            Console.WriteLine("Ready!");
        }
Esempio n. 5
0
 public NetworkManager(int Port, string AppID)
 {
     Config = new NetPeerConfiguration(AppID);
     Config.Port = Port;
     Server = new NetServer(Config);
     Server.Start();
 }
Esempio n. 6
0
		static void Main()
		{
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			MainForm = new Form1();

			NetPeerConfiguration config = new NetPeerConfiguration("durable");
			config.Port = 14242;
			config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
			config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
			config.EnableUPnP = true;
			Server = new NetServer(config);
			Server.Start();

			// attempt upnp port forwarding
			Server.UPnP.ForwardPort(14242, "Durable sample test");

			m_expectedReliableOrdered = new uint[3];
			m_reliableOrderedCorrect = new int[3];
			m_reliableOrderedErrors = new int[3];

			m_expectedSequenced = new uint[3];
			m_sequencedCorrect = new int[3];
			m_sequencedErrors = new int[3];

			Application.Idle += new EventHandler(AppLoop);
			Application.Run(MainForm);

			Server.Shutdown("App exiting");
		}
Esempio n. 7
0
        public Boolean Open()
        {
            var result = true;

            if (nethandler == null || netaddress == null || netport == 0 || netmax == 0)
            {
                result = false;
            }
            else
            {
                if (netconn == null)
                {
                    netconfig      = new NetPeerConfiguration("AuthServer");
                    netconfig.Port = netport;
                    netconfig.MaximumConnections = netmax;
                    netconn = new Lidgren.Network.NetServer(netconfig);
                    netconn.RegisterReceivedCallback(new SendOrPostCallback(nethandler), new SynchronizationContext());
                }
                try {
                    netconn.Start();
                    result = true;
                } catch {
                    result = false;
                }
            }
            return(result);
        }
Esempio n. 8
0
        public void SetupServer(string gameName, int port = 14242, int maxConnections = 20)
        {
            // Create new instance of configs. Parameter is "application Id". It has to be same on client and server.
            var config = new NetPeerConfiguration(gameName) { Port = port, MaximumConnections = maxConnections };
            _heroList = new List<LoginInfo>();
            // Set server port

            // Max client amount
            // Enable New messagetype. Explained later
            config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);

            // Create new server based on the configs just defined
            _gameServer = new NetServer(config);

            // Start it
            _gameServer.Start();

            // Eh..
            Console.WriteLine("Server Started");

            // Object that can be used to store and read messages
            NetIncomingMessage inc;
            _serverThread = new Thread(() =>
            {
                while (true)
                {
                    ServerLoop();
                }
            });
            _serverThread.IsBackground = true;
            _serverThread.Start();
        }
Esempio n. 9
0
        public void SetUpConnection()
        {
            configuration = new NetPeerConfiguration("PingPong");

            configuration.EnableMessageType(NetIncomingMessageType.WarningMessage);
            configuration.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage);
            configuration.EnableMessageType(NetIncomingMessageType.ErrorMessage);
            configuration.EnableMessageType(NetIncomingMessageType.Error);
            configuration.EnableMessageType(NetIncomingMessageType.DebugMessage);
            configuration.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            configuration.EnableMessageType(NetIncomingMessageType.Data);

            switch (networkRole)
            {
                case GamerNetworkType.Client:
                    Client = new NetClient(configuration);
                    Client.Start();
                    Client.Connect(new IPEndPoint(NetUtility.Resolve(IP), Convert.ToInt32(Port)));
                    break;
                case GamerNetworkType.Server:
                    configuration.Port = Convert.ToInt32(Port);
                    Server = new NetServer(configuration);
                    Server.Start();
                    break;
                default:
                    throw new ArgumentException("Network type was not set");
            }
        }
        /// <summary>
        ///     Server constructor, starts the server and connects to all region servers.
        /// </summary>
        /// <remarks>
        ///     TODO: Make the config file be able to be in a different location. Load from command line.
        /// </remarks>
        public MasterServer()
        {
            //Load this region server's junk from xml
            XmlSerializer deserializer = new XmlSerializer(typeof(MasterConfig));
            MasterConfig masterconfig = (MasterConfig)deserializer.Deserialize(XmlReader.Create(@"C:\Users\Addie\Programming\Mobius\Mobius.Server.MasterServer\bin\Release\MasterData.xml"));
            //Start it with the name MobiusMasterServer, and let connection approvals be enabled
            var config = new NetPeerConfiguration(masterconfig.ServerName);
            config.Port = masterconfig.ServerPort;
            config.MaximumConnections = masterconfig.MaxConnections;
            config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            LidgrenServer = new NetServer(config);

            RegionServers = new Dictionary<ushort, NetClient>();
            foreach(RegionInfo info in masterconfig.RegionServers)
            {
                NetClient region = new NetClient(new NetPeerConfiguration(info.ServerName));
                region.Start();
                region.Connect(info.ServerIp, info.ServerPort);
                RegionServers.Add(info.RegionId, region);
            }

            //Initialize our data structures
            Users = new Dictionary<Guid, User>();
            UserIdToCharacters = new Dictionary<Guid, List<Character>>();
            //Start the server
            LidgrenServer.Start();
        }
Esempio n. 11
0
 protected override void OnInitialise()
 {
     Log.Info(String.Format("Initialising NetServer on Port {0}..", _config.Port));
     OnIncomingMessage += LidgrenServer_OnIncomingMessage;
     _config.AcceptIncomingConnections = true;
     _server = new NetServer(_config);
     _server.Start();
 }
Esempio n. 12
0
		public Server()
		{
			NetPeerConfiguration config = new NetPeerConfiguration( "Server" );
			config.Port = 14242;

			instance = new NetServer( config );

			instance.Start();
		}
Esempio n. 13
0
 private void Initialize()
 {
     mConfig.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
     mConfig.Port = port;
     mPeer = new NetServer(mConfig);
     mPeer.Start();
     mOutgoingMessage = mPeer.CreateMessage();
     while(true) CheckForMessages();
 }
Esempio n. 14
0
        private static void Main(string[] args)
        {
            var config = new NetPeerConfiguration("airgap")
            {
                Port = port,
                MaximumConnections = 50,
                ConnectionTimeout = 5f
            };

            config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);

            var server = new NetServer(config);
            server.Start();
            Console.WriteLine("AudioGap Server Started");
            waveOut.DeviceNumber = 0; // TODO: need an option for this

            while (true)
            {
                NetIncomingMessage msg;

                if ((msg = server.ReadMessage()) == null)
                {
                    Thread.Sleep(1);
                    continue;
                }

                switch (msg.MessageType)
                {
                    case NetIncomingMessageType.VerboseDebugMessage:
                    case NetIncomingMessageType.DebugMessage:
                    case NetIncomingMessageType.WarningMessage:
                    case NetIncomingMessageType.ErrorMessage:
                        Console.WriteLine(msg.ReadString());
                        break;

                    case NetIncomingMessageType.StatusChanged:
                        var status = (NetConnectionStatus)msg.ReadByte();
                        string reason = msg.ReadString();
                        Console.WriteLine("New status: " + status + " (" + reason + ")");
                        break;

                    case NetIncomingMessageType.ConnectionApproval:
                        SetupAudio(msg);
                        msg.SenderConnection.Approve();
                        break;

                    case NetIncomingMessageType.Data:
                        if (msg.SenderConnection.Status == NetConnectionStatus.Connected)
                            HandleAudioPacket(msg);
                        break;

                    default:
                        Console.WriteLine("Unhandled type: " + msg.MessageType);
                        break;
                }
            }
        }
Esempio n. 15
0
        public static void Initialize()
        {
            var config = new NetPeerConfiguration("LidgrenChat") {Port = 5555};
            NetServer = new NetServer(config);

            NetServer.Start();

            StartThread();
            Started = true;
        }
Esempio n. 16
0
 public GameServer(int port)
 {
     //Configuration
     var npc = new NetPeerConfiguration("SpajsFajt");
     npc.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
     npc.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
     npc.Port = port;
     netServer = new NetServer(npc);
     netServer.Start();
 }
Esempio n. 17
0
        public void Start()
        {
            NetPeerConfiguration config = new NetPeerConfiguration("ths");
            config.Port = _port;
            config.MaximumConnections = s_maxConnNum;

            _server = new NetServer(config);
            _server.Start();
            InitializeMessageActionsTable();
        }
        private void Server_Load(object sender, EventArgs e)
        {
            NetPeerConfiguration config = new NetPeerConfiguration("Testing");
            config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
            config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            config.Port = 50001;

            server =  new NetServer(config);
            server.Start();
        }
Esempio n. 19
0
        public NetworkServer()
        {
            var cfg = new NetConfiguration("aav.defense");
            cfg.Address = IPAddress.Any;
            cfg.Port = 52244;
            cfg.AnswerDiscoveryRequests = true;
            _srv = new NetServer(cfg);

            _srv.Start();
        }
Esempio n. 20
0
        static S_NetworkManager()
        {
            NetPeerConfiguration lidServerConfig = new NetPeerConfiguration("chat");
            lidServerConfig.Port = 2323;
            lidServerConfig.PingInterval = HEARTBEAT_S;
            lidServerConfig.ConnectionTimeout = TIMEOUT_S;
            lidServerConfig.SetMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval, true);

            myLidServer = new NetServer(lidServerConfig);
            myLidServer.Start();
        }
Esempio n. 21
0
        public void Host()
        {
            // Create server and tell it to start listening for connections.
            Config.Port = 25000;
            NetServer server = new NetServer(Config);
            server.Start();
            // Assign it to NetPeer so it can be used interchangibly with client.
            Peer = server;

            Console.WriteLine("Server has started.");
        }
Esempio n. 22
0
        private static void OnHappyServerProgerss()
        {
            NetPeerConfiguration config = new NetPeerConfiguration("CozyKxlol");
            config.MaximumConnections   = 10000;
            config.Port                 = 36048;

            HappyServer                 = new NetServer(config);
            HappyServer.Start();

            RegisterHappyMessage();
        }
Esempio n. 23
0
        public void AddListener(ushort port, int maxClient)
        {
            var config = new NetPeerConfiguration(SharedUtil.GetAppIdentifierForNet());

            config.Port = port;
            config.MaximumConnections = maxClient;
            //config.DualStack = true;

            _netServer = new Lidgren.Network.NetServer(config);
            _netServer.Start();
        }
Esempio n. 24
0
        static void Main(string[] args)
        {
            server = new NetServer(new NetPeerConfiguration("Fireworks")
                                       {
                                           AcceptIncomingConnections = true,
                                           Port = 7007,
                                           ConnectionTimeout =  5
                                       });

            server.Start();

            Console.WriteLine("Started server");

            while (true)
            {
                NetIncomingMessage message;
                while ((message = server.ReadMessage()) != null)
                {
                    switch (message.MessageType)
                    {
                        case NetIncomingMessageType.Data:
                            {
                                var type = (Protocol)message.ReadByte();

                                HandleIncomingData(type, message.SenderConnection, message);

                                break;
                            }
                        case NetIncomingMessageType.StatusChanged:
                            {
                                var status = (NetConnectionStatus) message.ReadByte();
                                var msg = message.ReadString();

                                Console.WriteLine(status);
                                Console.WriteLine(msg);

                                if (status == NetConnectionStatus.Connected)
                                {
                                    Console.WriteLine("Client connected from " + message.SenderConnection.ToString());
                                }
                                else if (status == NetConnectionStatus.Disconnected)
                                {
                                    Console.WriteLine("Client disconnected from " + message.SenderConnection.ToString());
                                }

                                break;
                            }
                    }
                }

                Thread.Sleep(1);
            }
        }
Esempio n. 25
0
		static void Main(string[] args)
		{
			IPEndPoint masterServerEndpoint = NetUtility.Resolve("localhost", CommonConstants.MasterServerPort);

			NetPeerConfiguration config = new NetPeerConfiguration("game");
			config.SetMessageTypeEnabled(NetIncomingMessageType.NatIntroductionSuccess, true);
			config.Port = 14242;

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

			Console.WriteLine("Server started; waiting 5 seconds...");
			System.Threading.Thread.Sleep(5000);

			var lastRegistered = -60.0f;

			while(Console.KeyAvailable == false || Console.ReadKey().Key != ConsoleKey.Escape)
			{
				// (re-)register periodically with master server
				if (NetTime.Now > lastRegistered + 60)
				{
					// register with master server
					NetOutgoingMessage regMsg = server.CreateMessage();
					regMsg.Write((byte)MasterServerMessageType.RegisterHost);
					IPAddress mask;
					IPAddress adr = NetUtility.GetMyAddress(out mask);
					regMsg.Write(server.UniqueIdentifier);
					regMsg.Write(new IPEndPoint(adr, 14242));
					Console.WriteLine("Sending registration to master server");
					server.SendUnconnectedMessage(regMsg, masterServerEndpoint);
					lastRegistered = (float)NetTime.Now;
				}

				NetIncomingMessage inc;
				while ((inc = server.ReadMessage()) != null)
				{
					switch (inc.MessageType)
					{
						case NetIncomingMessageType.VerboseDebugMessage:
						case NetIncomingMessageType.DebugMessage:
						case NetIncomingMessageType.WarningMessage:
						case NetIncomingMessageType.ErrorMessage:
							Console.WriteLine(inc.ReadString());
							break;
					}
				}

				System.Threading.Thread.Sleep(1);
			}

			Console.ReadKey();
		}
Esempio n. 26
0
        private static void OnAgarServerProgerss()
        {
            NetPeerConfiguration config = new NetPeerConfiguration("CozyKxlol");
            config.MaximumConnections   = 10000;
            config.Port                 = 48360;

            AgarServer                  = new NetServer(config);
            AgarServer.Start();

            RegisterAgarMessage();

            FixedBallMgr.Update();
        }
Esempio n. 27
0
        public static void Initialize()
        {
            NetServer = new NetServer(new NetPeerConfiguration("XnaMultiplayerGame")
                                      	{
                                      		Port = 5555
                                      	});

            NetServer.RegisterReceivedCallback(MessageReceived);

            NetServer.Start();

            Clients = new List<Client>();
        }
Esempio n. 28
0
 public Server(bool isLocalServer)
 {
     IsLocalServer = isLocalServer;
     if (!IsLocalServer) {
         config = new NetPeerConfiguration(Arena.Config.ApplicationID);
         config.Port = Arena.Config.Port;
         config.ConnectionTimeout = 10;
         config.MaximumConnections = 16;
         config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
         server = new NetServer(config);
         server.Start();
     }
     Local = this;
 }
Esempio n. 29
0
        public static void start()
        {
            net = new NetServer(config);

            net.RegisterReceivedCallback(new SendOrPostCallback((e) =>
            {
                message = ((NetServer)e).ReadMessage();
                messageRecieved(message);
            }), new SynchronizationContext());

            print("info", "Starting...");
            net.Start();
            print("info", "Server running");
        }
Esempio n. 30
0
        /// <summary>
        /// Client Listener
        /// </summary>
        public Listener()
        {
            // Configuration
            NetPeerConfiguration config = new NetPeerConfiguration("Lidgren.Authentication.Sample");
            config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            config.Port = 15812;
            config.ConnectionTimeout = 60 * 15;
            config.UseMessageRecycling = true;

            _server = new NetServer(config);
            _server.Start();

            Listener.Port = config.Port;
        }
        public override void Start()
        {
            if (m_peer != null)
            {
                throw new InvalidOperationException("Server already started");
            }

            NetPeerConfiguration config = new NetPeerConfiguration(m_name);
            config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
            config.Port = m_port;

            m_peer = new NetServer(config);
            m_peer.Start();
        }
Esempio n. 32
0
 /// <summary>
 /// Allows the game to perform any initialization it needs to before starting to run.
 /// This is where it can query for any required services and load any non-graphic
 /// related content.  Calling base.Initialize will enumerate through any components
 /// and initialize them as well.
 /// </summary>
 protected override void Initialize()
 {
     //LINGREN CODE STARTS//
     //When initialising, create a configuration object.
     NetPeerConfiguration config = new NetPeerConfiguration("Server");
     //Setting the port, where the NetPeer shall listen.
     config.Port = 50001;
     //Create the NetPeer object with the configurations.
     server = new NetServer(config);
     //Start
     server.Start();
     //LINGREN CODE ENDS//
     base.Initialize();
 }
Esempio n. 33
0
        static void Main(string[] args)
        {
            var config = new NetPeerConfiguration("ConquerLeague")
            {
                Port = 47410
            };

            config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
            server = new NetServer(config);
            server.Start();

            SessionManager sessionManager = new SessionManager();

            while (true)
            {
                NetIncomingMessage message;
                while ((message = server.ReadMessage()) != null)
                {
                    switch (message.MessageType)
                    {
                    case NetIncomingMessageType.DiscoveryRequest:
                        NetOutgoingMessage response = server.CreateMessage();           // Create a response and write some example data to it
                        response.Write("ConquerLeagueServer");
                        server.SendDiscoveryResponse(response, message.SenderEndPoint); // Send the response to the sender of the request
                        break;

                    case NetIncomingMessageType.Data:
                        var dataLength = message.ReadInt32();
                        var data       = message.ReadBytes(dataLength);
                        sessionManager.ForwardMessageToSession(message.SenderConnection, dataLength, data);
                        break;

                    case NetIncomingMessageType.StatusChanged:
                        Console.WriteLine(message.SenderConnection.Status);
                        switch (message.SenderConnection.Status)
                        {
                        case NetConnectionStatus.Connected:
                            Console.WriteLine("Client " + message.SenderConnection.RemoteEndPoint.ToString() + " connected!");
                            sessionManager.AddPlayerToMatchmaking(message.SenderConnection);
                            break;

                        case NetConnectionStatus.RespondedConnect:
                            Console.WriteLine(message.SenderConnection.Status.ToString());
                            break;

                        default:
                            Console.WriteLine("Unhandled status change with type: " + message.SenderConnection.Status.ToString());
                            break;
                        }

                        break;

                    case NetIncomingMessageType.ConnectionApproval:
                        message.SenderConnection.Approve();
                        break;

                    case NetIncomingMessageType.DebugMessage:
                        Console.WriteLine(message.ReadString());
                        break;

                    case NetIncomingMessageType.WarningMessage:
                        Console.WriteLine("Warning: " + message.ReadString());
                        break;

                    default:
                        Console.WriteLine("unhandled message with type: " + message.MessageType);
                        break;
                    }

                    server.Recycle(message);
                }
            }
        }