// Only for Introducer's NetworkServer public static NetPeerConfiguration GetStandardConfiguration(this NetPeerConfiguration self, int listeningPort) { var config = new NetPeerConfiguration("NovaRat"); // Disable all message types config.DisableMessageType(NetIncomingMessageType.ConnectionApproval); config.DisableMessageType(NetIncomingMessageType.ConnectionLatencyUpdated); config.DisableMessageType(NetIncomingMessageType.Data); config.DisableMessageType(NetIncomingMessageType.DebugMessage); config.DisableMessageType(NetIncomingMessageType.DiscoveryRequest); config.DisableMessageType(NetIncomingMessageType.DiscoveryResponse); config.DisableMessageType(NetIncomingMessageType.Error); config.DisableMessageType(NetIncomingMessageType.ErrorMessage); config.DisableMessageType(NetIncomingMessageType.NatIntroductionSuccess); config.DisableMessageType(NetIncomingMessageType.Receipt); config.DisableMessageType(NetIncomingMessageType.UnconnectedData); config.DisableMessageType(NetIncomingMessageType.VerboseDebugMessage); config.DisableMessageType(NetIncomingMessageType.WarningMessage); // Enable only what we need config.EnableMessageType(NetIncomingMessageType.UnconnectedData); config.EnableMessageType(NetIncomingMessageType.NatIntroductionSuccess); config.EnableMessageType(NetIncomingMessageType.StatusChanged); //config.EnableMessageType(NetIncomingMessageType.DebugMessage); //config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage); //config.EnableMessageType(NetIncomingMessageType.WarningMessage); //config.EnableMessageType(NetIncomingMessageType.ErrorMessage); config.Port = listeningPort; config.AcceptIncomingConnections = true; return config; }
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"); }
/// <summary> /// /// </summary> /// <param name="numPorts"></param> /// <param name="timeout"></param> void StartDiscoveryInternal ( int numPorts, TimeSpan timeout ) { lock (lockObj) { if (client!=null) { Log.Warning("Discovery is already started."); return; } this.timeout = timeout; var netConfig = new NetPeerConfiguration( Game.GameID ); netConfig.EnableMessageType( NetIncomingMessageType.DiscoveryRequest ); netConfig.EnableMessageType( NetIncomingMessageType.DiscoveryResponse ); client = new NetClient( netConfig ); client.Start(); var svPort = Game.Network.Port; var ports = Enumerable.Range(svPort, numPorts) .Where( p => p <= ushort.MaxValue ) .ToArray(); Log.Message("Start discovery on ports: {0}", string.Join(", ", ports) ); foreach (var port in ports) { client.DiscoverLocalPeers( port ); } } }
public static NetPeerConfiguration GetStandardConfiguration(this NetPeerConfiguration self) { var config = new NetPeerConfiguration("NovaRat"); // Disable all message types config.DisableMessageType(NetIncomingMessageType.ConnectionApproval); config.DisableMessageType(NetIncomingMessageType.ConnectionLatencyUpdated); config.DisableMessageType(NetIncomingMessageType.Data); config.DisableMessageType(NetIncomingMessageType.DebugMessage); config.DisableMessageType(NetIncomingMessageType.DiscoveryRequest); config.DisableMessageType(NetIncomingMessageType.DiscoveryResponse); config.DisableMessageType(NetIncomingMessageType.Error); config.DisableMessageType(NetIncomingMessageType.ErrorMessage); config.DisableMessageType(NetIncomingMessageType.NatIntroductionSuccess); config.DisableMessageType(NetIncomingMessageType.Receipt); config.DisableMessageType(NetIncomingMessageType.UnconnectedData); config.DisableMessageType(NetIncomingMessageType.VerboseDebugMessage); config.DisableMessageType(NetIncomingMessageType.WarningMessage); // Enable only what we need config.EnableMessageType(NetIncomingMessageType.UnconnectedData); config.EnableMessageType(NetIncomingMessageType.NatIntroductionSuccess); config.EnableMessageType(NetIncomingMessageType.StatusChanged); //config.EnableMessageType(NetIncomingMessageType.DebugMessage); //config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage); //config.EnableMessageType(NetIncomingMessageType.WarningMessage); //config.EnableMessageType(NetIncomingMessageType.ErrorMessage); config.AcceptIncomingConnections = true; // No need to assign a port, as the OS will automatically assign an available port return config; }
public GameClient() { var npcc = new NetPeerConfiguration("SpajsFajt"); npcc.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); npcc.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); netClient = new NetClient(npcc); netClient.Start(); }
public WorldPortalConnection() { CameraPos = new Vector2f(0, 0); NetPeerConfiguration config = new NetPeerConfiguration("Dystopia2"); config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); client = new NetClient(config); client.Start(); }
public static NetPeerConfiguration GetConfig() { NetPeerConfiguration config = new NetPeerConfiguration(AppID); config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); return config; }
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(); }
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(); }
public MasterClient() { m_registeredHosts = new Dictionary<long, Object[]>(); NetPeerConfiguration config = new NetPeerConfiguration("game"); config.EnableMessageType(NetIncomingMessageType.UnconnectedData); config.EnableMessageType(NetIncomingMessageType.NatIntroductionSuccess); m_client = new NetClient(config); m_client.Start(); }
public NetManager() { _packetHandlers = new Dictionary<PacketType, List<Action<PacketReceivedEventArgs>>>(); NetPeerConfiguration config = new NetPeerConfiguration("CEngineSharp"); config.Port = Constants.SERVER_PORT; config.EnableMessageType(NetIncomingMessageType.Data); config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); _netServer = new NetServer(config); }
private void button1_Click(object sender, EventArgs e) { NetPeerConfiguration config = new NetPeerConfiguration("MMC"); config.MaximumConnections = 100; config.Port = 3939; // Enable DiscoveryResponse messages config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); s_server = new NetPeer(config); Output("listening on " + config.Port.ToString()); s_server.Start(); }
public NetManager() { _packetHandlers = new Dictionary<PacketType, List<Action<PacketReceivedEventArgs>>>(); _packetCache = new List<Tuple<NetOutgoingMessage, NetDeliveryMethod, ChannelTypes>>(); NetPeerConfiguration config = new NetPeerConfiguration("CEngineSharp"); config.EnableMessageType(NetIncomingMessageType.Data); config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); _netClient = new NetClient(config); _netClient.Start(); }
public static void Initialize() { TickRate = Shared.Settings.TickRate; if (!System.IO.File.Exists("serverconfig.xml")) { Console.WriteLine("Config file not found..."); System.Threading.Thread.Sleep(5000); System.Diagnostics.Process.GetCurrentProcess().Kill(); } XmlDocument Config = new XmlDocument(); Config.Load("serverconfig.xml"); Port = int.Parse(Config.DocumentElement.SelectSingleNode("/config/serverport").InnerText); MaxPlayers = int.Parse(Config.DocumentElement.SelectSingleNode("/config/maxplayers").InnerText); XmlNodeList Resources = Config.DocumentElement.SelectNodes("/config/resource"); NetPeerConfiguration NetConfig = new NetPeerConfiguration("ivmp"); NetConfig.MaximumConnections = MaxPlayers; NetConfig.Port = Port; NetConfig.ConnectionTimeout = 50; NetConfig.EnableMessageType(NetIncomingMessageType.ConnectionApproval); NetConfig.EnableMessageType(NetIncomingMessageType.StatusChanged); NetServer = new NetServer(NetConfig); NetServer.Start(); PlayersController = new PlayersController(); VehiclesController = new VehiclesController(); ResourcesManager = new Shared.Scripting.ResourcesManager(); EventsManager = new Shared.Scripting.EventsManager(); Engine = new Jint.Engine(); // load resources foreach (XmlNode Resource in Resources) { try { ResourcesManager.Load(Resource.Attributes["name"].InnerText); ResourcesManager.Start(Resource.Attributes["name"].InnerText); } catch(Exception) { } } Timer tick = new Timer(); tick.Elapsed += OnTick; tick.Interval = TickRate; tick.Enabled = true; tick.Start(); Console.WriteLine("Started game server on Port " + Port); Console.WriteLine("Max Players: " + MaxPlayers); }
public ClientNetworkInterface(string appIdentifier, string host, int port, IClientNetworkManager manager) { NetPeerConfiguration config = new NetPeerConfiguration(appIdentifier); config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); lidgrenClient = new NetClient(config); Host = host; ContactPort = port; AppId = appIdentifier; Manager = manager; }
public ServerNetworkInterface(string appId, int port, IServerNetworkManager manager) { Manager = manager; AppId = appId; Port = port; NetPeerConfiguration config = new NetPeerConfiguration(appId); config.Port = port; config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); config.EnableMessageType(NetIncomingMessageType.UnconnectedData); lidgrenServer = new NetServer(config); }
public static void Initialize() { NetPeerConfiguration config = new NetPeerConfiguration("Mobile Fortress"); config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); config.EnableMessageType(NetIncomingMessageType.UnconnectedData); config.Port = Port; config.SimulatedMinimumLatency = 0.0025f; config.SimulatedRandomLatency = 0.002f; config.SimulatedDuplicatesChance = 0.00005f; config.SimulatedLoss = 0.0001f; //config.EnableUPnP = true; Server = new NetServer(config); Server.Start(); }
public NetPlayer(Backend.IHandleEvent parent) { _config = new NetPeerConfiguration("DungeonCrawler"); _config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); _config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); _config.UseMessageRecycling = true; _config.PingInterval = 0.25f; _config.ConnectionTimeout = 20f; _config.MaximumHandshakeAttempts = 3; _config.ResendHandshakeInterval = 5; _parent = parent; _servers = new Dictionary<string, string>(); Start(); }
public static NetPeerConfiguration GetConfiguration(bool server) { NetPeerConfiguration config = new NetPeerConfiguration("Forge.Networking"); if (server) { config.Port = Port; config.EnableUPnP = true; config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); } else { config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); } return config; }
public static void Main(string[] args) { Console.WriteLine("[CLIENT] Testing Lidgren-Network-v3..."); NetPeerConfiguration clientConfig = new NetPeerConfiguration("test"); clientConfig.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); NetClient client = new NetClient(clientConfig); client.Start(); SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); client.RegisterReceivedCallback(new SendOrPostCallback(GotMessage)); Console.WriteLine("IP to connect to: "); String ip = Console.ReadLine(); client.Connect(new System.Net.IPEndPoint(System.Net.IPAddress.Parse(ip), 12345)); while(true) { string msg = Console.ReadLine(); NetOutgoingMessage sendMsg = client.CreateMessage(); sendMsg.Write("[CLIENT] " + msg); client.SendMessage(sendMsg, NetDeliveryMethod.ReliableOrdered); } }
public NetworkMultiplayer(bool createServer = false) : base(GameModes.Network) { if(createServer) GameServer = new GameServer(); //read network on each update Game.Instance.OnUpdate += ReadNetwork; //server config NetPeerConfiguration config = new NetPeerConfiguration("tank"); config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); //server creation Client = new NetClient(config); Client.Start(); if (!createServer) { //check whether the user has a known server ListMenu serverMenu = new ListMenu("Do you want to connect to a given IP (if yes, enter in console)?", "tank.Code.YESORNOCHOOSENOW", ConnectionMethodSelectionCallback); Scene.Add(serverMenu); } else//we know that a local server must exist Client.DiscoverLocalPeers(14242); //register handler for receiving data OnClientData += IncomingHandler; //are we client, or are we dancer? if(!createServer) Console.WriteLine("client"); }
public Client() { NetPeerConfiguration config = new NetPeerConfiguration("CozyAnywhere"); config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); client = new NetClient(config); client.RegisterReceivedCallback(RecivePacket); }
public CozyClient(string ClientName) { NetPeerConfiguration config = new NetPeerConfiguration(ClientName); config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); InnerClient = new NetClient(config); InnerClient.RegisterReceivedCallback(RecivePacket); }
public static void Main(string[] args) { Console.WriteLine("[CLIENT] Testing Lidgren-Network-v3..."); NetPeerConfiguration clientConfig = new NetPeerConfiguration("test"); clientConfig.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); NetClient client = new NetClient(clientConfig); client.Start(); Console.WriteLine("IP to connect to: "); String ip = Console.ReadLine(); client.Connect("192.168.1.2", 80); while (true) { if (client.ServerConnection != null) { string msg = Console.ReadLine(); NetOutgoingMessage sendMsg = client.CreateMessage(); sendMsg.Write(msg); client.SendMessage(sendMsg, NetDeliveryMethod.ReliableOrdered); } } }
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(); }
/// <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(); }
public void StartClientConnection(string ip, string port) { _config = new NetPeerConfiguration(GameConfiguration.NetworkAppIdentifier) { #if DEBUG //PingInterval = 1f, // send ping every 1 second //SimulatedLoss = 0.5f, // from 0 to 1 SimulatedMinimumLatency = GameConfiguration.SimulatedMinimumLatency, #endif }; _config.EnableMessageType(NetIncomingMessageType.ConnectionLatencyUpdated); _hasStarted = true; _connected = false; _disconnected = false; // Client initialize _client = new NetClient(_config); _client.Start(); _messagePool = new Queue<NetIncomingMessage>(); var threadStart = new ThreadStart(MessagePooling); _messagePooling = new Thread(threadStart); _messagePooling.Start(); TryToConnect(ip, port); }
/// <summary> /// Initializes a new instance of the <see cref="NetworkServer" /> class. /// </summary> /// <param name="applicationIdentifier">The application identifier.</param> /// <param name="port">The port.</param> public NetworkServer(string applicationIdentifier, int port) { var config = new NetPeerConfiguration(applicationIdentifier); config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); config.Port = port; this.server = new NetServer(config); }
/// <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(); }
public WorldClientBase(string protocolVersion) { this.protocolVersion = protocolVersion; // Net configuration NetPeerConfiguration cfg = new NetPeerConfiguration("Asteria"); cfg.MaximumConnections = 1; cfg.ReceiveBufferSize = 4095; cfg.MaximumTransmissionUnit = 4095; #if DEBUG try { cfg.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage); } catch { Logger.Output(this, "Running in debug mode but using release Lidgren library version, Lidgren debug messages disabled!"); } #endif client = new NetClient(cfg); client.Start(); // Create objects needed. sendingQ = new Queue<ClientToServerMessage>(64); receivingQ = new Queue<NetIncomingMessage>(128); newDataArrivedEvent = new AutoResetEvent(false); messages = new Dictionary<MessageType, List<ServerToClientMessage>>(); serializer = new ClientToServerMessageSerializer(); deserializer = new ServerToClientMessageSerializer(); isRunning = true; }
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); } } }