internal bool Init(LobbyRobot.Robot robot) { m_Robot = robot; Serialize.Init(); InitMessageHandler(); m_NetClientStarted = false; m_IsWaitStart = true; m_IsQuited = false; m_IsConnected = false; m_CanSendMessage = false; m_Config = new NetPeerConfiguration("RoomServer"); m_Config.AutoFlushSendQueue = false; m_Config.ConnectionTimeout = 5.0f; m_Config.PingInterval = 1.0f; m_Config.DisableMessageType(NetIncomingMessageType.DebugMessage); m_Config.DisableMessageType(NetIncomingMessageType.VerboseDebugMessage); m_Config.EnableMessageType(NetIncomingMessageType.ErrorMessage); m_Config.EnableMessageType(NetIncomingMessageType.WarningMessage); m_NetClient = new NetClient(m_Config); m_NetThread = new Thread(new ThreadStart(NetworkThread)); m_NetThread.IsBackground = true; m_NetThread.Start(); return(true); }
public GameClient(string appId, byte[] clientIdentifier, string userName) { if (clientIdentifier == null || clientIdentifier.Length != 16) { throw new ArgumentException("Client identifier must be 16 bytes long"); } this.clientIdentifier = clientIdentifier; this.userName = userName; callbacks = new Action <NetIncomingMessage> [byte.MaxValue + 1]; NetPeerConfiguration config = new NetPeerConfiguration(appId); #if NETWORK_DEBUG config.EnableMessageType(NetIncomingMessageType.DebugMessage); config.EnableMessageType(NetIncomingMessageType.ErrorMessage); config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage); config.EnableMessageType(NetIncomingMessageType.WarningMessage); #else config.DisableMessageType(NetIncomingMessageType.DebugMessage); config.DisableMessageType(NetIncomingMessageType.ErrorMessage); config.DisableMessageType(NetIncomingMessageType.VerboseDebugMessage); config.DisableMessageType(NetIncomingMessageType.WarningMessage); #endif client = new NetClient(config); client.Start(); threadUpdate = new Thread(OnHandleMessagesThread); threadUpdate.IsBackground = true; threadUpdate.Start(); }
internal bool Init() { Serialize.Init(); InitMessageHandler(); m_NetClientStarted = false; m_IsWaitStart = true; m_IsQuited = false; m_IsConnected = false; m_WaitDisconnect = false; m_CanSendMessage = false; m_Config = new NetPeerConfiguration("RoomServer"); m_Config.ConnectionTimeout = 5.0f; m_Config.PingInterval = 1.0f; m_Config.AutoFlushSendQueue = false; m_Config.DisableMessageType(NetIncomingMessageType.DebugMessage); m_Config.DisableMessageType(NetIncomingMessageType.VerboseDebugMessage); m_Config.EnableMessageType(NetIncomingMessageType.ErrorMessage); m_Config.EnableMessageType(NetIncomingMessageType.WarningMessage); m_NetClient = new NetClient(m_Config); #if !PLATFORM_WEBGL m_NetThread = new Thread(new ThreadStart(NetworkThread)); #else m_NetThread = new Thread(CustomNetWorkThread); #endif m_NetThread.IsBackground = true; m_NetThread.Start(); return(true); }
internal bool Init() { InitMessageHandler(); m_NetClientStarted = false; m_IsWaitStart = true; m_IsQuited = false; m_IsConnected = false; m_CanSendMessage = false; m_ReconnectCount = 0; m_Config = new NetPeerConfiguration("RoomServer"); m_Config.AutoFlushSendQueue = false; m_Config.DisableMessageType(NetIncomingMessageType.DebugMessage); m_Config.DisableMessageType(NetIncomingMessageType.VerboseDebugMessage); //m_Config.EnableMessageType(NetIncomingMessageType.DebugMessage); //m_Config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage); m_Config.EnableMessageType(NetIncomingMessageType.ErrorMessage); m_Config.EnableMessageType(NetIncomingMessageType.WarningMessage); m_Config.EnableMessageType(NetIncomingMessageType.UnconnectedData); m_NetClient = new NetClient(m_Config); m_NetThread = new Thread(new ThreadStart(NetworkThread)); m_NetThread.IsBackground = true; m_NetThread.Start(); return(true); }
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); }
public ServerDiscovery(string appId, int port, Action <string, IPEndPoint, int, int, int> serverFoundAction) { if (serverFoundAction == null) { throw new ArgumentNullException(nameof(serverFoundAction)); } this.port = port; this.serverFoundAction = serverFoundAction; NetPeerConfiguration config = new NetPeerConfiguration(appId); config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); #if DEBUG config.EnableMessageType(NetIncomingMessageType.DebugMessage); config.EnableMessageType(NetIncomingMessageType.ErrorMessage); config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage); config.EnableMessageType(NetIncomingMessageType.WarningMessage); #else config.DisableMessageType(NetIncomingMessageType.DebugMessage); config.DisableMessageType(NetIncomingMessageType.ErrorMessage); config.DisableMessageType(NetIncomingMessageType.VerboseDebugMessage); config.DisableMessageType(NetIncomingMessageType.WarningMessage); #endif client = new NetClient(config); client.RegisterReceivedCallback(OnMessage); client.Start(); waitEvent = new AutoResetEvent(false); thread = new Thread(OnPeriodicDiscoveryThread); thread.IsBackground = true; thread.Priority = ThreadPriority.Lowest; thread.Start(); }
internal void Init(int port) { InitMessageHandler(); int receiveBufferSize = 64; int sendBufferSize = 64; StringBuilder sb = new StringBuilder(256); if (CenterClientApi.GetConfig("ReceiveBufferSize", sb, 256)) { receiveBufferSize = int.Parse(sb.ToString()); } if (CenterClientApi.GetConfig("SendBufferSize", sb, 256)) { sendBufferSize = int.Parse(sb.ToString()); } m_Config = new NetPeerConfiguration("RoomServer"); m_Config.MaximumConnections = 1024; m_Config.ConnectionTimeout = 5.0f; m_Config.PingInterval = 1.0f; m_Config.ReceiveBufferSize = receiveBufferSize * 1024 * 1024; m_Config.SendBufferSize = sendBufferSize * 1024 * 1024; m_Config.Port = port; m_Config.DisableMessageType(NetIncomingMessageType.DebugMessage); m_Config.DisableMessageType(NetIncomingMessageType.VerboseDebugMessage); //m_Config.EnableMessageType(NetIncomingMessageType.DebugMessage); //m_Config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage); m_Config.EnableMessageType(NetIncomingMessageType.ErrorMessage); m_Config.EnableMessageType(NetIncomingMessageType.WarningMessage); if (m_Config.IsMessageTypeEnabled(NetIncomingMessageType.DebugMessage)) { LogSys.Log(LOG_TYPE.DEBUG, "Enable NetIncomingMessageType.DebugMessage"); } if (m_Config.IsMessageTypeEnabled(NetIncomingMessageType.VerboseDebugMessage)) { LogSys.Log(LOG_TYPE.DEBUG, "Enable NetIncomingMessageType.VerboseDebugMessage"); } if (m_Config.IsMessageTypeEnabled(NetIncomingMessageType.ErrorMessage)) { LogSys.Log(LOG_TYPE.DEBUG, "Enable NetIncomingMessageType.ErrorMessage"); } if (m_Config.IsMessageTypeEnabled(NetIncomingMessageType.WarningMessage)) { LogSys.Log(LOG_TYPE.DEBUG, "Enable NetIncomingMessageType.WarningMessage"); } m_NetServer = new NetServer(m_Config); m_NetServer.Start(); m_IOThread = new Thread(new ThreadStart(IOHandler)); m_IOThread.Name = "IOHandler"; m_IOThread.IsBackground = true; m_Status = RoomSrvStatus.STATUS_RUNNING; m_IOThread.Start(); RoomPeerMgr.Instance.Init(); Console.WriteLine("Init IOManager OK!"); }
public ServerConnection(string appId, int port, int maxPlayers, bool enableUPnP) { if (maxPlayers < 0 || maxPlayers >= byte.MaxValue) { throw new ArgumentOutOfRangeException("Max. number of players must be smaller than " + byte.MaxValue); } this.port = port; NetPeerConfiguration config = new NetPeerConfiguration(appId); config.Port = port; config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); config.EnableMessageType(NetIncomingMessageType.NatIntroductionSuccess); config.EnableMessageType(NetIncomingMessageType.UnconnectedData); config.EnableUPnP = enableUPnP; #if NETWORK_DEBUG //config.SimulatedMinimumLatency = 50 / 1000f; //config.SimulatedRandomLatency = 50 / 1000f; //config.SimulatedDuplicatesChance = 0.2f; config.EnableMessageType(NetIncomingMessageType.DebugMessage); config.EnableMessageType(NetIncomingMessageType.ErrorMessage); config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage); config.EnableMessageType(NetIncomingMessageType.WarningMessage); #else config.DisableMessageType(NetIncomingMessageType.DebugMessage); config.DisableMessageType(NetIncomingMessageType.ErrorMessage); config.DisableMessageType(NetIncomingMessageType.VerboseDebugMessage); config.DisableMessageType(NetIncomingMessageType.WarningMessage); #endif config.MaxConnections = maxPlayers; server = new NetServer(config); server.Start(); uniqueIdentifier = NetUtility.ToHexString(server.UniqueIdentifier); threadUpdate = new Thread(OnHandleMessagesThread); threadUpdate.IsBackground = true; threadUpdate.Start(); if (config.EnableUPnP) { publicIpAddresses = server.UPnP.GetExternalIP(); server.UPnP.ForwardPort(port, "Jazz2"); } }
/// <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; }
public Network(string ip) { NetPeerConfiguration config = new NetPeerConfiguration("SF"); config.Port = 14044; config.DisableMessageType(NetIncomingMessageType.ConnectionApproval | NetIncomingMessageType.ConnectionLatencyUpdated | NetIncomingMessageType.DebugMessage | NetIncomingMessageType.DiscoveryRequest | NetIncomingMessageType.DiscoveryResponse | NetIncomingMessageType.NatIntroductionSuccess | NetIncomingMessageType.Receipt | NetIncomingMessageType.StatusChanged | NetIncomingMessageType.UnconnectedData | NetIncomingMessageType.VerboseDebugMessage); config.EnableUPnP = true; netClient = new NetClient(config); netClient.Start(); netClient.UPnP.ForwardPort(14044, "MUD Port"); netClient.Connect(ip, 14040); Task waitForConnection = new Task(() => { while (netClient.ConnectionsCount < 1) { //WAIT FOR CONNECTION. } }); waitForConnection.Start(); waitForConnection.Wait(); SendConnectionMessage(Program.PlayerName); Program.OnUpdate += CheckIncomingMessages; }
public override void Start(object endPoint, int ownerKey) { if (isActive) { return; } netPeerConfiguration = new NetPeerConfiguration("barotrauma"); netPeerConfiguration.DisableMessageType(NetIncomingMessageType.DebugMessage | NetIncomingMessageType.WarningMessage | NetIncomingMessageType.Receipt | NetIncomingMessageType.ErrorMessage | NetIncomingMessageType.Error); netClient = new NetClient(netPeerConfiguration); incomingLidgrenMessages = new List <NetIncomingMessage>(); initializationStep = ConnectionInitialization.SteamTicketAndVersion; IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Loopback, Steam.SteamManager.STEAMP2P_OWNER_PORT); netClient.Start(); ServerConnection = new LidgrenConnection("Server", netClient.Connect(ipEndPoint), 0); ServerConnection.Status = NetworkConnectionStatus.Connected; remotePeers = new List <RemotePeer>(); Steam.SteamManager.Instance.Networking.OnIncomingConnection = OnIncomingConnection; Steam.SteamManager.Instance.Networking.OnP2PData = OnP2PData; Steam.SteamManager.Instance.Networking.SetListenChannel(0, true); Steam.SteamManager.Instance.Auth.OnAuthChange = OnAuthChange; isActive = true; }
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(); }
/// <summary> /// Inicializa as configurações do servidor. /// </summary> public static void InitializeServer() { var config = new NetPeerConfiguration(Settings.Discovery); config.Port = Settings.Port; config.AutoFlushSendQueue = true; config.AcceptIncomingConnections = true; config.MaximumConnections = Settings.MaxConnection; config.ConnectionTimeout = 25.0f; config.PingInterval = 2.0f; config.UseMessageRecycling = true; config.DisableMessageType(NetIncomingMessageType.ConnectionApproval | NetIncomingMessageType.ConnectionLatencyUpdated | NetIncomingMessageType.DebugMessage | NetIncomingMessageType.DiscoveryResponse | NetIncomingMessageType.Error | NetIncomingMessageType.NatIntroductionSuccess | NetIncomingMessageType.Receipt | NetIncomingMessageType.UnconnectedData | NetIncomingMessageType.VerboseDebugMessage | NetIncomingMessageType.WarningMessage); socket = new NetServer(config); socket.Start(); socket.Socket.Blocking = false; }
public ServerConnection(string appId, int port, int maxPlayers = 500) { if (maxPlayers < 0 || maxPlayers >= int.MaxValue) { throw new ArgumentOutOfRangeException("Max. number of players must be smaller than " + int.MaxValue); } this.port = port; this.maxPlayers = maxPlayers; //this.sessions = new Dictionary<int, Session>(max_sessions + 10); NetPeerConfiguration config = new NetPeerConfiguration(appId); config.Port = port; config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); config.EnableMessageType(NetIncomingMessageType.NatIntroductionSuccess); config.EnableUPnP = true; //config.SimulatedMinimumLatency = 0.02f; //config.SimulatedMinimumLatency = 0.8f; //config.SimulatedRandomLatency = 0.06f; //config.SimulatedDuplicatesChance = 0.2f; #if DEBUG config.EnableMessageType(NetIncomingMessageType.DebugMessage); config.EnableMessageType(NetIncomingMessageType.ErrorMessage); config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage); config.EnableMessageType(NetIncomingMessageType.WarningMessage); #else config.DisableMessageType(NetIncomingMessageType.DebugMessage); config.DisableMessageType(NetIncomingMessageType.ErrorMessage); config.DisableMessageType(NetIncomingMessageType.VerboseDebugMessage); config.DisableMessageType(NetIncomingMessageType.WarningMessage); #endif config.MaxConnections = maxPlayers; server = new NetServer(config); server.Start(); threadUpdate = new Thread(OnMessage); threadUpdate.IsBackground = true; threadUpdate.Start(); server.UPnP.ForwardPort(port, "Jazz2"); }
public static void Host(int port, int maxPlayers) { if (Peer != null) { return; } NetPeerConfiguration config = new NetPeerConfiguration(string.Format("game")) { Port = port, MaximumConnections = (maxPlayers - 1), }; config.DisableMessageType(NetIncomingMessageType.DebugMessage); config.DisableMessageType(NetIncomingMessageType.DiscoveryRequest); config.DisableMessageType(NetIncomingMessageType.DiscoveryResponse); config.DisableMessageType(NetIncomingMessageType.Error); config.DisableMessageType(NetIncomingMessageType.ErrorMessage); config.DisableMessageType(NetIncomingMessageType.Receipt); config.DisableMessageType(NetIncomingMessageType.WarningMessage); config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); Peer = Server = new NetServer(config); _onUpdate += UpdateServer; _onDisconnect += DisconnectServer; Server.Start(); PlayerState = new Player.NetState[maxPlayers - 1]; }
public Peer(Handler handler, Config config) { IsAlive = false; _handler = handler; #region Config NetPeerConfiguration netConfig = new NetPeerConfiguration(config.AppId) { AutoExpandMTU = false, AutoFlushSendQueue = true, AcceptIncomingConnections = true, EnableUPnP = false, NetworkThreadName = "MonoLightTech.UnityNetwork.P2P", UseMessageRecycling = true, DefaultOutgoingMessageCapacity = Environment.ProcessorCount * 2, Port = config.Port, MaximumHandshakeAttempts = config.MaximumHandshakeAttempts, ResendHandshakeInterval = config.ResendHandshakeInterval, MaximumConnections = config.MaximumConnections, ConnectionTimeout = config.ConnectionTimeout, PingInterval = config.PingInterval, MaximumTransmissionUnit = config.MaximumTransmissionUnit, RecycledCacheMaxCount = config.MessageCacheSize }; #region Messages foreach (NetIncomingMessageType type in Enum.GetValues(typeof(NetIncomingMessageType))) { netConfig.DisableMessageType(type); } netConfig.EnableMessageType(NetIncomingMessageType.ConnectionApproval); netConfig.EnableMessageType(NetIncomingMessageType.StatusChanged); netConfig.EnableMessageType(NetIncomingMessageType.Data); netConfig.EnableMessageType(NetIncomingMessageType.ConnectionLatencyUpdated); netConfig.EnableMessageType(NetIncomingMessageType.UnconnectedData); netConfig.EnableMessageType(NetIncomingMessageType.DebugMessage); netConfig.EnableMessageType(NetIncomingMessageType.WarningMessage); netConfig.EnableMessageType(NetIncomingMessageType.ErrorMessage); #endregion #endregion _peer = new NetPeer(netConfig); SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); _peer.RegisterReceivedCallback(_Callback); _clients = new List <Connection>(); _clientsCache = new Connection[0]; _auths = new List <Pair <IPEndPoint, string> >(); _authsCache = new Pair <IPEndPoint, string> [0]; }
public ServerDiscovery(string appId, int port, ServerUpdatedCallbackDelegate serverUpdatedAction) { if (serverUpdatedAction == null) { throw new ArgumentNullException(nameof(serverUpdatedAction)); } this.port = port; this.serverUpdatedAction = serverUpdatedAction; foundServers = new Dictionary <IPEndPoint, Server>(); publicEndPoints = new Dictionary <string, IPEndPoint>(); jsonParser = new JsonParser(); NetPeerConfiguration config = new NetPeerConfiguration(appId); config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse); config.EnableMessageType(NetIncomingMessageType.UnconnectedData); #if NETWORK_DEBUG config.EnableMessageType(NetIncomingMessageType.DebugMessage); config.EnableMessageType(NetIncomingMessageType.ErrorMessage); config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage); config.EnableMessageType(NetIncomingMessageType.WarningMessage); #else config.DisableMessageType(NetIncomingMessageType.DebugMessage); config.DisableMessageType(NetIncomingMessageType.ErrorMessage); config.DisableMessageType(NetIncomingMessageType.VerboseDebugMessage); config.DisableMessageType(NetIncomingMessageType.WarningMessage); #endif client = new NetClient(config); client.Start(); waitEvent = new AutoResetEvent(false); threadUpdate = new Thread(OnHandleMessagesThread); threadUpdate.IsBackground = true; threadUpdate.Start(); threadDiscovery = new Thread(OnPeriodicDiscoveryThread); threadDiscovery.IsBackground = true; threadDiscovery.Priority = ThreadPriority.Lowest; threadDiscovery.Start(); }
public override void Start(object endPoint, int ownerKey) { if (isActive) { return; } this.ownerKey = ownerKey; contentPackageOrderReceived = false; netPeerConfiguration = new NetPeerConfiguration("barotrauma") { UseDualModeSockets = GameMain.Config.UseDualModeSockets }; netPeerConfiguration.DisableMessageType(NetIncomingMessageType.DebugMessage | NetIncomingMessageType.WarningMessage | NetIncomingMessageType.Receipt | NetIncomingMessageType.ErrorMessage | NetIncomingMessageType.Error); netClient = new NetClient(netPeerConfiguration); if (SteamManager.IsInitialized) { steamAuthTicket = SteamManager.GetAuthSessionTicket(); //TODO: wait for GetAuthSessionTicketResponse_t if (steamAuthTicket == null) { throw new Exception("GetAuthSessionTicket returned null"); } } incomingLidgrenMessages = new List <NetIncomingMessage>(); initializationStep = ConnectionInitialization.SteamTicketAndVersion; if (!(endPoint is IPEndPoint ipEndPoint)) { throw new InvalidCastException("endPoint is not IPEndPoint"); } if (ServerConnection != null) { throw new InvalidOperationException("ServerConnection is not null"); } netClient.Start(); ServerConnection = new LidgrenConnection("Server", netClient.Connect(ipEndPoint), 0) { Status = NetworkConnectionStatus.Connected }; isActive = true; }
/// <summary> /// Initializes a new instance of the <see cref="ClientSocketManager"/> class. /// </summary> /// <param name="appIdentifier">The application identifier string.</param> public ClientSocketManager(string appIdentifier) { var config = new NetPeerConfiguration(appIdentifier) { AcceptIncomingConnections = false }; // Disable some message types that will not be used by the client config.DisableMessageType(NetIncomingMessageType.NatIntroductionSuccess); config.DisableMessageType(NetIncomingMessageType.Receipt); config.DisableMessageType(NetIncomingMessageType.UnconnectedData); config.DisableMessageType(NetIncomingMessageType.DiscoveryRequest); config.DisableMessageType(NetIncomingMessageType.DiscoveryResponse); // Custom configuration InitNetPeerConfig(config); // Start _local = new NetClient(config); _local.Start(); }
public bool Init() { Serialize.Init(); InitMessageHandler(); m_IsWaitStart = true; m_IsQuited = false; m_IsConnected = false; m_Config = new NetPeerConfiguration("RoomServer"); m_Config.AutoFlushSendQueue = false; m_Config.DisableMessageType(NetIncomingMessageType.DebugMessage); m_Config.DisableMessageType(NetIncomingMessageType.VerboseDebugMessage); m_Config.EnableMessageType(NetIncomingMessageType.ErrorMessage); m_Config.EnableMessageType(NetIncomingMessageType.WarningMessage); m_NetClient = new NetClient(m_Config); m_NetClient.Start(); m_NetThread = new Thread(new ThreadStart(NetworkThread)); m_NetThread.Start(); return(true); }
public void Run() { InitialStats(); ClientPeerList = new List <NetPeer>(); NetPeerConfiguration config = new NetPeerConfiguration("FinalProjet") { Port = 14242 }; config.DisableMessageType(NetIncomingMessageType.ConnectionApproval); _server = new NetServer(config); _server.Start(); }
public NetworkHandler(string appId) { callbacks = new Dictionary <byte, Action <NetIncomingMessage> >(); NetPeerConfiguration config = new NetPeerConfiguration(appId); #if DEBUG config.EnableMessageType(NetIncomingMessageType.DebugMessage); config.EnableMessageType(NetIncomingMessageType.ErrorMessage); config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage); config.EnableMessageType(NetIncomingMessageType.WarningMessage); #else config.DisableMessageType(NetIncomingMessageType.DebugMessage); config.DisableMessageType(NetIncomingMessageType.ErrorMessage); config.DisableMessageType(NetIncomingMessageType.VerboseDebugMessage); config.DisableMessageType(NetIncomingMessageType.WarningMessage); #endif client = new NetClient(config); client.Start(); threadUpdate = new Thread(OnMessage); threadUpdate.IsBackground = true; threadUpdate.Start(); }
/// <summary> /// Initializes a new instance of the <see cref="ServerSocketManager"/> class. /// </summary> /// <param name="appIdentifier">The application identifier string.</param> /// <param name="port">The port to listen on.</param> public ServerSocketManager(string appIdentifier, int port) { var config = new NetPeerConfiguration(appIdentifier) { AcceptIncomingConnections = true, Port = port, MaximumConnections = 50 }; // Disable some message types that will not be used by the server config.DisableMessageType(NetIncomingMessageType.NatIntroductionSuccess); config.DisableMessageType(NetIncomingMessageType.Receipt); config.DisableMessageType(NetIncomingMessageType.UnconnectedData); config.DisableMessageType(NetIncomingMessageType.DiscoveryRequest); config.DisableMessageType(NetIncomingMessageType.DiscoveryResponse); // Manually handle connection approval instead of just accepting everything config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); // Custom configuration InitNetPeerConfig(config); // Start _local = new NetServer(config); _local.Start(); }
public void Init() { NetPeerConfiguration config = new NetPeerConfiguration("FinalProjet"); config.DisableMessageType(NetIncomingMessageType.ConnectionApproval); Client = new NetClient(config); Client.Start(); var mOut = Client.CreateMessage(); mOut.Write(JeuProjet.Player.MpMax); mOut.Write(JeuProjet.Player.MpActuel); mOut.Write(JeuProjet.Player.PvMax); mOut.Write(JeuProjet.Player.PvActuels); Client.Connect("localhost", 14242, mOut); Client.FlushSendQueue(); }
/// <summary> /// Inicia as configurações. /// </summary> public static void InitializeTCP() { var config = new NetPeerConfiguration(Settings.Discovery); config.Port = Settings.Port; config.AutoFlushSendQueue = true; config.AcceptIncomingConnections = true; config.MaximumConnections = Settings.MaxConnection; config.ConnectionTimeout = (float)Settings.ConnectionTimeOut; config.PingInterval = 2.0f; config.UseMessageRecycling = true; config.DisableMessageType(NetIncomingMessageType.ConnectionApproval | NetIncomingMessageType.UnconnectedData | NetIncomingMessageType.VerboseDebugMessage | NetIncomingMessageType.ConnectionLatencyUpdated); Socket = new NetServer(config); Socket.Start(); Socket.Socket.Blocking = false; }
/// <summary> /// Initializes the server, starts the reiceve loop, creates a NetClient and connects it to the server /// </summary> public static void ServerStart() { //Server Setup var config = new NetPeerConfiguration("King of Ames") { Port = 6969 }; config.DisableMessageType(NetIncomingMessageType.DebugMessage); config.DisableMessageType(NetIncomingMessageType.DiscoveryRequest); config.DisableMessageType(NetIncomingMessageType.DiscoveryResponse); config.DisableMessageType(NetIncomingMessageType.ConnectionLatencyUpdated); config.DisableMessageType(NetIncomingMessageType.Receipt); config.DisableMessageType(NetIncomingMessageType.ErrorMessage); config.DisableMessageType(NetIncomingMessageType.WarningMessage); config.DisableMessageType(NetIncomingMessageType.UnconnectedData); config.DisableMessageType(NetIncomingMessageType.NatIntroductionSuccess); config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); _server = new NetServer(config); _server.Start(); Console.WriteLine("Server started..."); //add server to the SQL database with the current details NetworkClasses.CreateServer(User.PlayerId, User.LocalIp); // Starts thread to handle input from clients _shouldStop = false; var recieve = new Thread(RecieveLoop); recieve.Start(); //Setting up Client Client.Conn = User.LocalIp; Client.NetClient.Start(); Client.Connect(); }
public MineWorldServer() { NetPeerConfiguration netConfig = new NetPeerConfiguration("MineWorld"); netConfig.Port = Constants.MineworldPort; netConfig.MaximumConnections = 2; netConfig.EnableMessageType(NetIncomingMessageType.ConnectionApproval); netConfig.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); netConfig.DisableMessageType(NetIncomingMessageType.UnconnectedData); Server = new NetServer(netConfig); GameWorld = new GameWorld(this); Console = new MineWorldConsole(this); ServerListener = new ServerListener(Server, this); ServerSender = new ServerSender(Server, this); Listener = new Thread(ServerListener.Start); MapManager = new MapManager(); PlayerManager = new PlayerManager(); Configloader = new ConfigFile("Data/Settings.ini"); }
private void SetupSocket(BadNetworkSimulation badNetworkSimulation) { // Try each known port to see if we can open a socket... for (int i = 0; i < appConfig.KnownPorts.Length; i++) { try { NetPeerConfiguration config = CreateNetPeerConfiguration(badNetworkSimulation); config.Port = appConfig.KnownPorts[i]; netPeer = new NetPeer(config); netPeer.Start(); Log("Socket opened on port " + PortNumber); return; } catch (SocketException socketException) // Probably port unavailable { if (socketException.SocketErrorCode != SocketError.AddressAlreadyInUse) { throw; // Actually, it was something else } else { continue; // Try the next port } } } Log("Known port unavailable, auto-assigning port..."); { // Try again with auto-assigned port NetPeerConfiguration config = CreateNetPeerConfiguration(badNetworkSimulation); config.DisableMessageType(NetIncomingMessageType.DiscoveryRequest); // <- will enable when we need it config.Port = 0; netPeer = new NetPeer(config); netPeer.Start(); Log("Socket opened on port " + PortNumber); } }
public static void InitializeServer() { // SERVER TCP CONFIG // var config = new NetPeerConfiguration(Settings.Discovery); config.Port = Settings.Port; config.AutoFlushSendQueue = true; config.AcceptIncomingConnections = true; config.MaximumConnections = Settings.MaxConnection; config.ConnectionTimeout = 25.0f; config.PingInterval = 2.0f; config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); config.UseMessageRecycling = true; config.DisableMessageType(NetIncomingMessageType.ConnectionApproval | NetIncomingMessageType.UnconnectedData | NetIncomingMessageType.VerboseDebugMessage | NetIncomingMessageType.ConnectionLatencyUpdated); //SimulatedMinimumLatency, SimulatedRandomLatency Socket = new NetServer(config); Socket.Start(); Socket.Socket.Blocking = false; }
public override void Start() { if (netServer != null) { return; } netPeerConfiguration = new NetPeerConfiguration("barotrauma") { AcceptIncomingConnections = true, AutoExpandMTU = false, MaximumConnections = NetConfig.MaxPlayers * 2, EnableUPnP = serverSettings.EnableUPnP, Port = serverSettings.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(); if (serverSettings.EnableUPnP) { InitUPnP(); while (DiscoveringUPnP()) { } FinishUPnP(); } }