protected override void connectImpl() { NetPeerConfiguration config = new NetPeerConfiguration("StardewValley"); config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); config.EnableMessageType(NetIncomingMessageType.ConnectionLatencyUpdated); config.ConnectionTimeout = 30f; config.PingInterval = 5f; config.MaximumTransmissionUnit = 1200; client = new NetClient(config); client.Start(); attemptConnection(); }
/// /// <summary> /// Initializes a new instance of the <see cref="ServerForm"/> class. /// </summary> /// /// <param name="autoStart">Whether or not to automatically start the server.</param> /// public ServerForm(Boolean autoStart) { InitializeComponent(); // Set up the file system. serverDataDirectory = Path.Combine(Environment.CurrentDirectory, "server_data"); // Set up the RNG. random = new Random(); #region Networking Setup // Set up the config. netConfig = new NetPeerConfiguration("Everblaze"); netConfig.Port = 1945; netConfig.EnableMessageType(NetIncomingMessageType.ConnectionApproval); netConfig.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); netConfig.PingInterval = 1.5F; netConfig.ConnectionTimeout = 8.0F; // Set up the server object. server = new NetServer(netConfig); ServerTimer.Interval = 17; #endregion #region Game Setup // Set up the server configuration. // This will automatically load existing server data or create new data. serverConfiguration = new ServerConfiguration( Path.Combine(serverDataDirectory, "main.cfg"), ref world); #endregion if (autoStart) { log("INFO", "Automatic startup command received. Starting automatically."); Thread.Sleep(750); StartMenuItem_Click(null, null); } }
public override void OnEnabled() { NetPeerConfiguration Configuration = new NetPeerConfiguration(ConstantValues.ServerString) { Port = (int)ConstantValues.Port }; Configuration.EnableMessageType(NetIncomingMessageType.ConnectionApproval); Configuration.EnableMessageType(NetIncomingMessageType.StatusChanged); server = new NetServer(Configuration); server.Start(); base.OnEnabled(); }
public void Start(bool isServer, int port, string url = null) { _isServer = isServer; _url = url; _port = port; _cancellationTokenSource = new CancellationTokenSource(); OnClose += Close; if (_isServer) { var config = new NetPeerConfiguration("networkGame") { Port = _port, PingInterval = 1f, ConnectionTimeout = 5f }; config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); config.EnableMessageType(NetIncomingMessageType.ConnectionLatencyUpdated); config.EnableMessageType(NetIncomingMessageType.WarningMessage); config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage); config.EnableMessageType(NetIncomingMessageType.ErrorMessage); config.EnableMessageType(NetIncomingMessageType.Error); config.EnableMessageType(NetIncomingMessageType.DebugMessage); _server = new NetServer(config); _server.Start(); } else { var config = new NetPeerConfiguration("networkGame") { PingInterval = 1f, ConnectionTimeout = 5f }; config.EnableMessageType(NetIncomingMessageType.WarningMessage); config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage); config.EnableMessageType(NetIncomingMessageType.ErrorMessage); config.EnableMessageType(NetIncomingMessageType.Error); config.EnableMessageType(NetIncomingMessageType.DebugMessage); _client = new NetClient(config); _client.Start(); _client.Connect(_url, _port); } _task = new Task(() => { Run(_cancellationTokenSource.Token); }); _task.Start(); }
public MasterServerMgr(int port = SharedDef.MASTER_SERVER_PORT) { connections = new Dictionary <NetConnection, ServerMgr>(); NetPeerConfiguration conf = new NetPeerConfiguration("Orbit"); conf.EnableMessageType(NetIncomingMessageType.UnconnectedData); conf.EnableMessageType(NetIncomingMessageType.ConnectionApproval); conf.Port = port; #if DEBUG /*conf.SimulatedMinimumLatency = 0.2f; // 100ms * conf.SimulatedRandomLatency = 0.05f; // +- 50ms*/ //conf.EnableMessageType(NetIncomingMessageType.DebugMessage); conf.EnableMessageType(NetIncomingMessageType.Error); conf.EnableMessageType(NetIncomingMessageType.ErrorMessage); conf.EnableMessageType(NetIncomingMessageType.Receipt); conf.EnableMessageType(NetIncomingMessageType.UnconnectedData); conf.EnableMessageType(NetIncomingMessageType.WarningMessage); #endif #if VERBOSE conf.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage); #endif server = new NetServer(conf); server.RegisterReceivedCallback(new SendOrPostCallback(GotMessage)); server.Start(); }
public Server() { players = new List <Player>(); var config = new NetPeerConfiguration("networkGame") { Port = 4207 }; config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); config.EnableMessageType(NetIncomingMessageType.Data); server = new NetServer(config); server.Start(); }
public override void initialize() { Console.WriteLine("Starting LAN server"); NetPeerConfiguration config = new NetPeerConfiguration("StardewValley"); config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); config.Port = 24642; config.ConnectionTimeout = 30f; config.PingInterval = 5f; config.MaximumConnections = Game1.multiplayer.playerLimit * 2; config.MaximumTransmissionUnit = 1200; server = new NetServer(config); server.Start(); }
public ConnectionHandler(Random rand, Game1 g) { // Creates a unique identifier, thats what the string is for (used for people on the same ports) NetPeerConfiguration config = new NetPeerConfiguration("GalaticImperialism"); config.PingInterval = 6; // Not entirely sure oops. config.MaximumConnections = 4; // Maximum amount of connections you're allowed to have, set this to 4 since max is 4 players. config.AcceptIncomingConnections = true; // Allows people to connect to you essentially config.AutoFlushSendQueue = true; // Not entirely sure. config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); // Essentially these two lines say what type of messages are allowed config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); // and what we will handle and receive essentially. peer = new NetPeer(config); // Creates the NetPeer object with the config above. game = g; }
private static NetServer CreatePeer(int port) { var config = new NetPeerConfiguration(AppConstants.NetAppIdentifier) { Port = port, AcceptIncomingConnections = true, UseMessageRecycling = true, PingInterval = 2f }; config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); config.EnableMessageType(NetIncomingMessageType.UnconnectedData); return(new NetServer(config)); }
protected NetServer StartServer(int aPort) { NetPeerConfiguration npConfig = new NetPeerConfiguration("DMP"); npConfig.EnableMessageType(NetIncomingMessageType.ConnectionApproval); npConfig.EnableMessageType(NetIncomingMessageType.StatusChanged); npConfig.EnableMessageType(NetIncomingMessageType.Data); npConfig.Port = aPort; NetServer server = new NetServer(npConfig); server.Start(); return(server); }
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); }
public Arena(World world, Tile[,] walls, Tile[,] floors, Item[] items, int size) { Walls = walls; Floors = floors; Size = size; Items = items; _world = world; ListOfMyBullets = new List <Bullet>(); ListOfOtherBullets = new List <Bullet>(); Random rnd = new Random(); int id = rnd.Next(0, 1000); Player me = new Player(_world, new Vector2(100, 100), 0, true); me.id = id; Team1 = new List <Player>(); Team2 = new List <Player>(); Team1.Add(me); Me.BulletEvent += AddBullet; _timers = new float[items.Length]; light = new Light(Me.Position); #region networking NetPeerConfiguration config = new NetPeerConfiguration("xnaapp"); config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); client = new NetClient(config); client.Start(); client.Connect("127.0.0.1", 14242); #endregion }
public static void Run(NetPeer peer) { NetPeerConfiguration config = new NetPeerConfiguration("Test"); config.EnableMessageType(NetIncomingMessageType.UnconnectedData); if (config.IsMessageTypeEnabled(NetIncomingMessageType.UnconnectedData) == false) { throw new NetException("setting enabled message types failed"); } config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, false); if (config.IsMessageTypeEnabled(NetIncomingMessageType.UnconnectedData) == true) { throw new NetException("setting enabled message types failed"); } TestContext.Out.WriteLine("Misc tests OK"); TestContext.Out.WriteLine("Hex test: " + NetUtility.ToHexString(new byte[] { 0xDE, 0xAD, 0xBE, 0xEF })); if (NetUtility.BitsToHoldUInt64((ulong)UInt32.MaxValue + 1ul) != 33) { throw new NetException("BitsToHoldUInt64 failed"); } }
private void InitNetwork() { LogText("Current Directory: " + Directory.GetCurrentDirectory()); if (connectToIp == "-server") { StartServer(); return; } var config = new NetPeerConfiguration("file transfer"); if (connectToIp == null) { LogText("Searching for server..."); config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); stopWatch.Start(); } var client = new NetClient(config); client.Start(); if (connectToIp == null) { client.DiscoverLocalPeers(mPort); } else { LogText("Connecting to server:" + connectToIp); client.Connect(connectToIp, mPort); foundServer = true; } peer = client; }
static void UdpMain(GameList gameList) { var config = new NetPeerConfiguration("SpagAachen.Ballz"); config.Port = 43117; config.EnableMessageType(NetIncomingMessageType.UnconnectedData); var peer = new NetPeer(config); peer.Start(); while (true) { Thread.Sleep(10); NetIncomingMessage msg; while ((msg = peer.ReadMessage()) != null) { switch (msg.MessageType) { case NetIncomingMessageType.UnconnectedData: gameList.RequestAddGame(msg); break; } peer.Recycle(msg); } } }
public void Initiate() { //Load all assets Assets.Load(); Console.WriteLine("Assets Loaded Successfully"); //Load our zone Zone.Initiate(); Configuration = new NetPeerConfiguration(ServerHandle); Configuration.Port = Port; Configuration.MaximumConnections = MaximumConnections; Configuration.EnableMessageType(NetIncomingMessageType.ConnectionApproval); Server = new NetServer(Configuration); Server.Start(); LinkConfig = new NetPeerConfiguration("LinkServer"); LinkServer = new NetClient(LinkConfig); LinkServer.Start(); Receive = new Receiver(); Console.WriteLine("Server started -- Now Listening.."); //Poll Communcation while (!Console.KeyAvailable || Console.ReadKey().Key != ConsoleKey.Escape) { Discovery(); ReadMessage(); Zone.Poll(); } //Sends a disconnection message and shuts down server WriteMessage(); }
public HostLobby(EventHandler callback) : base(callback) { if (!contentLoaded) { contentLoaded = true; bigFont = Content.Load <SpriteFont>("spritefonts/BigMessage"); } viewport = GraphicsDevice.Viewport; NetPeerConfiguration config = new NetPeerConfiguration("rts"); config.Port = 14242; config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); server = new NetServer(config); server.Start(); if (Game1.DEBUG) { server.Configuration.SimulatedMinimumLatency = .08f; server.Configuration.SimulatedRandomLatency = .01f; } }
// Init Network Controller public void initTCP() { if (TCPClient == null) { // Networking // NetPeerConfiguration config = new NetPeerConfiguration("Elysium Diamond #1.0.0"); config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); config.ConnectionTimeout = 25; config.UseMessageRecycling = true; TCPClient = new NetClient(config); TCPClient.Start(); TCPClient.Socket.Blocking = false; } if (Connected() == false) { if (string.IsNullOrEmpty(Settings.WorldServerIP)) { return; } // Check if server is online // if (Environment.TickCount >= tick + 1000) { TCPClient.DiscoverKnownPeer(Settings.WorldServerIP, Settings.WorldServerPort); tick = Environment.TickCount; } } }
public IConnection InitializeUdpLanConnection(out Guid connectionGuid) { var config = new NetPeerConfiguration("RemoteDesktop") { LocalAddress = _localIpAddress.Value, MaximumConnections = 1 }; config.EnableMessageType(NetIncomingMessageType.UnconnectedData); var server = new NetServer(config); server.Start(); server.RegisterReceivedCallback(state => { var message2 = server.ReadMessage(); Debug.Print("Receive message"); }); connectionGuid = _dtpFactory.ExecuteFunction <Guid>("InitializeUdpLanConnection", (IPEndPoint)server.Socket.LocalEndPoint); var message = server.WaitMessage(5 * 1000); if (message?.ReadString() == "GARYFUCKINGWASHINGTON") { //if (server.WaitMessage(5*1000)?.SenderConnection?.Status == NetConnectionStatus.Connected) return(new NetServerConnection(server)); } throw new ConnectionException("Unable to receive data from remote client", ConnectionType.UdpLan); }
public ServerHandler(EntityList eList) { this.eList = eList; config = new NetPeerConfiguration("NetworkTestGame") { Port = 14242 }; config.EnableUPnP = true; //config.LocalAddress = IPAddress.Parse("172.30.1.32"); config.MaximumConnections = 8; config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); server = new NetServer(config); server.Start(); server.UPnP.ForwardPort(14242, "NetworkGameTest"); if (server.Status == NetPeerStatus.Running) { Console.WriteLine("Server is running on port " + config.Port); } else { Console.WriteLine("Server not started..."); } }
/// <summary> /// Inicia o servidor. /// </summary> /// <param name="localAddress"></param> /// <param name="address"></param> /// <param name="port"></param> public void InitializeClient(string localAddress, string address, int port) { localIP = localAddress; ip = address; this.port = port; NetPeerConfiguration config = new NetPeerConfiguration(Settings.Discovery); config.ConnectionTimeout = 25; config.UseMessageRecycling = true; config.AutoFlushSendQueue = true; config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse | NetIncomingMessageType.StatusChanged | NetIncomingMessageType.Data); config.DisableMessageType(NetIncomingMessageType.ConnectionApproval | NetIncomingMessageType.ConnectionLatencyUpdated | NetIncomingMessageType.DebugMessage | NetIncomingMessageType.Error | NetIncomingMessageType.NatIntroductionSuccess | NetIncomingMessageType.Receipt | NetIncomingMessageType.UnconnectedData | NetIncomingMessageType.VerboseDebugMessage | NetIncomingMessageType.WarningMessage); socket = new NetClient(config); socket.Start(); socket.Socket.Blocking = false; }
private void startServer(object sender, EventArgs e) { //Create a new config instance, used to configure the server settings. Ky is the identifier for our network relationship in this case Config = new NetPeerConfiguration("Ky"); //Listening on port 3000, clients must connect to port 3000 if they want to connect to us. Config.Port = 3000; //Enables it so users have to 'login'/'be approved' to join our network Config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); //Create new server instance with the Config we've created Server = new NetServer(Config); //[sass]I don't know what this does..[/sass] Server.Start(); //Let it be known that the server has started, hallelujah Write("Server started on port: " + Config.Port); //Create our data instances to keep track of our game world ConnectedPlayers = new List <Character>(); //We listen for clients on a separate Thread. This is a bit of an 'advanced' topic. You can ask me more about it if you're curious //But the main reason for this one is so, it does not perform these actions on our 'Main' thread. This thread is used for our UI //If we perform too many functions on our UI thread. Our UI may lag, so.. there's that! Thread t = new Thread(new ThreadStart(listenForMessages)); t.Start(); serverIsRunning = true; }
public void Startup() { var netConfig = new NetPeerConfiguration("SS14_NetTag"); if (IsServer) { netConfig.Port = Port; netConfig.EnableMessageType(NetIncomingMessageType.ConnectionApproval); } #if DEBUG //Simulate Latency if (_config.GetCVar <bool>("net.fakelag")) { netConfig.SimulatedLoss = _config.GetCVar <float>("net.fakeloss"); netConfig.SimulatedMinimumLatency = _config.GetCVar <float>("net.fakelagmin"); netConfig.SimulatedRandomLatency = _config.GetCVar <float>("net.fakelagrand"); } netConfig.ConnectionTimeout = 30000f; #endif _netPeer = new NetPeer(netConfig); _netPeer.Start(); }
public NetHandler(string gameName, int port) { _packetHandlers = new Dictionary <PacketType, List <Action <PacketReceivedEventArgs> > >(); _connections = new Dictionary <long, PlayerConnection>(); var config = new NetPeerConfiguration(gameName) { Port = port }; config.DisableMessageType(NetIncomingMessageType.NatIntroductionSuccess); config.DisableMessageType(NetIncomingMessageType.Receipt); config.DisableMessageType(NetIncomingMessageType.UnconnectedData); config.DisableMessageType(NetIncomingMessageType.DiscoveryRequest); config.DisableMessageType(NetIncomingMessageType.DiscoveryResponse); config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); config.AcceptIncomingConnections = true; #if DEBUG config.ConnectionTimeout = 60; #else config.ConnectionTimeout = 5; #endif config.EnableUPnP = false; _netServer = new NetServer(config); }
/// /// <summary> /// Initializes a new instance of the <see cref="Game"/> class. /// </summary> /// /// <param name="IP">The IP address of the server to attempt connection with.</param> /// public Game(String IP) { // Set up the graphics device manager. graphics = new GraphicsDeviceManager(this); // Set the initial window size... graphics.PreferredBackBufferWidth = 1920; graphics.PreferredBackBufferHeight = 1080; graphics.IsFullScreen = true; // Set the content root directory. Content.RootDirectory = "data"; // Make sure the cursor is visible... this.IsMouseVisible = true; #region Networking Setup // Set up the networking configuration. netConfig = new NetPeerConfiguration("Everblaze"); netConfig.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); // Set up the actual client object. client = new NetClient(netConfig); client.Start(); this.serverIP = IP; #endregion }
/// <summary> /// Initializes a new instance of the <see cref="NetworkClient"/> class. /// </summary> /// <param name="applicationIdentifier">The application identifier.</param> public NetworkClient(string applicationIdentifier) { var config = new NetPeerConfiguration(applicationIdentifier); config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); this.client = new NetClient(config); }
public override void Start() { if (netServer != null) { return; } netPeerConfiguration = new NetPeerConfiguration("barotrauma") { AcceptIncomingConnections = true, AutoExpandMTU = false, MaximumConnections = 1, //only allow owner to connect EnableUPnP = false, Port = Steam.SteamManager.STEAMP2P_OWNER_PORT }; netPeerConfiguration.DisableMessageType(NetIncomingMessageType.DebugMessage | NetIncomingMessageType.WarningMessage | NetIncomingMessageType.Receipt | NetIncomingMessageType.ErrorMessage | NetIncomingMessageType.Error | NetIncomingMessageType.UnconnectedData); netPeerConfiguration.EnableMessageType(NetIncomingMessageType.ConnectionApproval); netServer = new NetServer(netPeerConfiguration); netServer.Start(); }
private static void StartServer() { NetPeerConfiguration config = new NetPeerConfiguration("MMO"); config.Port = 8002; config.MaximumConnections = 100; config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); server = new NetServer(config); server.Start(); Console.ForegroundColor = logColour; Console.Write("NA REGION: "); Console.ForegroundColor = ConsoleColor.Red; Console.Write("Offline"); Console.WriteLine(""); Console.ForegroundColor = logColour; Console.Write("EU REGION: "); Console.ForegroundColor = ConsoleColor.Red; Console.Write("Offline"); Console.WriteLine(""); Console.ForegroundColor = logColour; Console.Write("OCE REGION: "); Console.ForegroundColor = ConsoleColor.Red; Console.Write("Offline"); Console.WriteLine(""); Console.ForegroundColor = logColour; Console.Write("CLIENTS CONNECTED: " + clientList.Count); Console.WriteLine(""); Console.ForegroundColor = ConsoleColor.White; while (true) { Listen(); } }
public GameServer(int port) { hub = Hub.Default; hub.Subscribe <GameFinished>(this, HandleGameFinished); currentState = ServerState.ReadyForNewGame; //checkForServerUseTimer = new Timer(Constants.SERVER_IN_USE_TIMER) { // AutoReset = true, // Enabled = true, //}; //checkForServerUseTimer.Elapsed += CheckForServerUse; var config = new NetPeerConfiguration(Constants.LIDGREN_SERVER_NAME) { Port = port, MaximumConnections = Constants.MAXIMUM_CONNECTIONS }; config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); server = new NetServer(config); server.Start(); gameLoop = new GameLoop(server); Logger.Debug("Host: " + server.Configuration.LocalAddress + " Port: " + server.Configuration.Port); }
public static async void Start() { var config = new NetPeerConfiguration("masterserver") { AutoFlushSendQueue = false, //Set it to false so lidgren doesn't wait until msg.size = MTU for sending Port = Port, SuppressUnreliableUnorderedAcks = true, PingInterval = 500, ConnectionTimeout = ServerMsTimeout }; config.EnableMessageType(NetIncomingMessageType.UnconnectedData); var peer = new NetPeer(config); peer.Start(); CheckMasterServerListed(); ConsoleLogger.Log(LogLevels.Normal, $"Master server {LmpVersioning.CurrentVersion} started! Поехали!"); RemoveExpiredServers(); while (RunServer) { NetIncomingMessage msg; while ((msg = peer.ReadMessage()) != null) { switch (msg.MessageType) { case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.VerboseDebugMessage: ConsoleLogger.Log(LogLevels.Debug, msg.ReadString()); break; case NetIncomingMessageType.WarningMessage: ConsoleLogger.Log(LogLevels.Warning, msg.ReadString()); break; case NetIncomingMessageType.ErrorMessage: ConsoleLogger.Log(LogLevels.Error, msg.ReadString()); break; case NetIncomingMessageType.UnconnectedData: if (FloodControl.AllowRequest(msg.SenderEndPoint.Address)) { var message = GetMessage(msg); if (message != null && !message.VersionMismatch) { HandleMessage(message, msg, peer); message.Recycle(); } peer.Recycle(msg); } break; } } await Task.Delay(ServerMsTick); } peer.Shutdown("Goodbye and thanks for all the fish!"); }