Beispiel #1
0
        public ConnectionManager JoinSession(string ip, string port)
        {
            Client = SteamNetworkingSockets.ConnectNormal <MaydayClient>(NetAddress.From(ip, ushort.Parse(port)));
            ((MaydayClient)Client).NetworkManager = this;

            return(Client);
        }
Beispiel #2
0
        private void SaveData(string output)
        {
            if (output.Length > 300)
            {
                _address.Clear();
                int start = output.LastIndexOf("----------", StringComparison.Ordinal);
                int length = output.Length - start;
                string selectedText = output.Substring(start, length);
                string[] array = selectedText.Split('\r');

                string[] addr;
                for (int i = 1; i < array.Length - 2; i++)
                {
                    NetAddress netAddress = new NetAddress();
                    if (array[i] != "\n")
                    {
                        Regex r = new Regex(@"\s+");
                        addr = r.Replace(array[i].Replace("\n", ""), @" ").Split(' ');
                        netAddress.PcAddress = addr[0];
                        netAddress.PcPort = addr[1];
                        netAddress.ServerAddress = addr[2];
                        netAddress.ServerPort = addr[3];
                        _address.Add(netAddress);
                    }
                }
            }
           
            CheckDataWithFile(_address);
        }
Beispiel #3
0
        void HandleLoginRes(SFMessage message)
        {
            var loginResult = message.GetValue <Result>("Result");

            if (loginResult.IsFailed)
            {
                PrintStatus(1, "Login failed {0}", loginResult);

                if (mLoginFailedAction != null)
                {
                    mLoginFailedAction(this, 2);
                }

                CloseAllConnections();
                return;
            }

            NextState = eTesterState.GAME_LOGINING;

            m_LoginTicket       = message.GetValue <UInt64>("Ticket");
            m_AccountID         = message.GetValue <UInt64>("AccID");
            m_GameServerAddress = message.GetValue <NetAddress>("GameServerAddrIPV4");
            m_LoginEntityID     = message.GetValue <UInt64>("LoginEntityUID");

            PrintStatus(1, "Login Success!! {0}", m_LoginID);////loginResult);

            if (!string.IsNullOrEmpty(m_GameServerAddress.Address))
            {
                m_ConnectionGame = new SFConnection(m_MessageRouter);
                m_ConnectionGame.Connect(m_LoginTicket, m_GameServerAddress.Address, m_GameServerAddress.Port);
            }
        }
        internal void SteamNetworkingIPAddr_ToString(ref NetAddress addr, out string buf, [MarshalAs(UnmanagedType.U1)] bool bWithPort)
        {
            IntPtr membuf = Helpers.TakeMemory();

            _SteamNetworkingIPAddr_ToString(Self, ref addr, membuf, (1024 * 32), bWithPort);
            buf = Helpers.MemoryToString(membuf);
        }
Beispiel #5
0
        public async Task SetupAsync()
        {
            ConfigureServices();

            Logger logger = ServiceProvider.GetService <ILoggerProvider>()
                            .GetLogger("Server");

            logger.LogInformation("Starting server");

            ServerConfig config = ServiceProvider.GetService <IConfigProvider>().Config;

            SteamServerInit init = new SteamServerInit
            {
                GamePort        = config.Port,
                Secure          = true,
                QueryPort       = (ushort)(config.Port + 1),
                SteamPort       = (ushort)(config.Port + 2),
                VersionString   = "0.1",
                DedicatedServer = true,
                IpAddress       = IPAddress.Parse(config.IpAddress),
                ModDir          = "pf",
                GameDescription = "Pony Forest"
            };

            try
            {
                SteamServer.Init(1026040, init);

                SteamServer.ServerName          = config.Name;
                SteamServer.AutomaticHeartbeats = true;
                SteamServer.DedicatedServer     = true;
                SteamServer.Passworded          = false;
                SteamServer.MaxPlayers          = config.MaxPlayers;

                SteamServer.LogOnAnonymous();

                NetAddress address = NetAddress.From(config.IpAddress, config.Port);
                _serverCore = SteamNetworkingSockets.CreateNormalSocket <ServerCore>(address);
            }
            catch (Exception e)
            {
                logger.LogFailure($"Can't start server: {Environment.NewLine + e}");
            }

            try
            {
                IMessageRouter messageRouter = ServiceProvider.GetService <IMessageRouter>();

                logger.LogInformation("Server started");

                _serverCore.OnMessageReceived = messageRouter.Route;

                IMessageListener messageListener = ServiceProvider.GetService <IMessageListener>();
                await messageListener.StartListening(_serverCore);
            }
            catch (Exception e)
            {
                logger.LogFailure($"Error while running server: {Environment.NewLine + e}");
            }
        }
Beispiel #6
0
        public void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            string loginID = MainWindow.Instance.comboBoxLoginID.Text;

            loginID = loginID.Trim();
            if (string.IsNullOrEmpty(loginID))
            {
                MessageBox.Show("Enter valid Login ID");
                return;
            }

            if (ServerAddressRegistry.AddLoginID(loginID))
            {
                UpdateLoginIDUI();
            }

            OnClearLog(sender, e);
            m_NetTestUser.CloseAllConnections();

            m_NetTestUser.m_LoginID = loginID;

            SimpleTestGameID     = MainWindow.GetGameIDFromUI(MainWindow.Instance.comboBoxGameID);
            m_NetTestUser.gameID = SimpleTestGameID;

            ServerAddressRegistry.SaveGameID(100, SimpleTestGameID);

            NetAddress serverAddress = MainWindow.Instance.GetServerAddressFromUI(0, MainWindow.Instance.comboBoxIPAddress, UpdateServerAddressUI);

            m_NetTestUser.RunConnect(serverAddress);
        }
Beispiel #7
0
        public void RunConnect(NetAddress serverAddress,

                               System.Action <StressTest_LoginUser> OnLoginConnected,
                               System.Action <StressTest_LoginUser, SF.Net.SendMessageLogin> OnLoginDisConnected,
                               System.Action <StressTest_LoginUser, int> OnLoginFailed,

                               System.Action <StressTest_LoginUser> OnGameSvrConnected,
                               System.Action <StressTest_LoginUser, SF.Net.SendMessageGame> OnGameSvrDisConnected,
                               System.Action <StressTest_LoginUser> OnGameSvrFailedConnect,

                               System.Action <StressTest_LoginUser, bool> OnGameJoinAction)
        {
            mLoginConnectedAction    = OnLoginConnected;
            mLoginDisConnectedAction = OnLoginDisConnected;
            mLoginFailedAction       = OnLoginFailed;

            // Game Sever
            mGameSvrConnectedAction     = OnGameSvrConnected;
            mGameSvrDisConnectedAction  = OnGameSvrDisConnected;
            mGameSvrFailedConnectAction = OnGameSvrFailedConnect;

            mGameJoinResAction = OnGameJoinAction;

            NextState     = eTesterState.LOGINING;
            mCurDeltaTime = 0;

            m_ConnectionLogin = new SFConnection(m_MessageRouter);
            m_ConnectionLogin.Connect(0, serverAddress.Address, (int)serverAddress.Port);
        }
        void HandleLoginRes(SFMessage message)
        {
            var loginResult = message.GetValue <Result>("Result");

            if (loginResult.IsFailed)
            {
                if (mLoginResAction != null)
                {
                    mLoginResAction(this, false);
                }

                PrintStatus(1, "Login failed {0}", loginResult);
                CloseAllConnections();
                return;
            }
            else
            {
                m_LoginTicket       = message.GetValue <UInt64>("Ticket");
                m_AccountID         = message.GetValue <UInt64>("AccID");
                m_GameServerAddress = message.GetValue <NetAddress>("GameServerAddrIPV4");
                m_LoginEntityID     = message.GetValue <UInt64>("LoginEntityUID");

                if (mLoginResAction != null)
                {
                    mLoginResAction(this, true);
                }
            }
        }
 public HostsItem(NetAddress ip, HostAliases hosts, string comment = "")
 {
     Enabled = true;
     IP = ip;
     Aliases = hosts;
     Comment = comment ?? "";
     Valid = true;
 }
 public HostsItem(NetAddress ip, HostName host, string comment = "")
 {
     Enabled = true;
     IP = ip;
     Aliases = new HostAliases(host);
     Comment = comment ?? "";
     Valid = true;
 }
        /// <summary>
        /// Connect to a socket created via <method>CreateListenSocketIP</method>
        /// </summary>
        public static T ConnectNormal <T>(NetAddress address) where T : ConnectionInterface, new()
        {
            var t = new T();

            t.Connection = Internal.ConnectByIPAddress(ref address);
            SetConnectionInterface(t.Connection.Id, t);
            return(t);
        }
        /// <summary>
        /// Creates a "server" socket that listens for clients to connect to by calling
        /// Connect, over ordinary UDP (IPv4 or IPv6)
        /// </summary>
        public static T CreateNormalSocket <T>(NetAddress address) where T : SocketInterface, new()
        {
            var t = new T();

            t.Socket = Internal.CreateListenSocketIP(ref address);
            SetSocketInterface(t.Socket.Id, t);
            return(t);
        }
Beispiel #13
0
        void Connect(NetAddress serverAddress)
        {
            CloseAllConnections();

            m_ConnectionLogin = new SFConnection(m_MessageRouter);
            m_ConnectionLogin.Connect(0, serverAddress.Address, (int)serverAddress.Port);
            m_Login = new SF.Net.SendMessageLogin(m_ConnectionLogin);
        }
 public void OnConnectFailed(NetworkRunner runner, NetAddress remoteAddress, NetConnectFailedReason reason)
 {
     Util.Log($"Connect Failed {reason}");
     LeaveSession();
     SetConnectionStatus(Enum.ConnectionStatus.Failed);
     (string status, string msg) = ConnectFailedReasonToHuman(reason);
     //TODO : UI에 뿌려주자 status msg
 }
        public static T ConnectNormal <T>(NetAddress address)
            where T : ConnectionInterface, new()
        {
            T t = Activator.CreateInstance <T>();

            t.Connection = SteamNetworkingSockets.Internal.ConnectByIPAddress(ref address);
            SteamNetworkingSockets.SetConnectionInterface(t.Connection.Id, t);
            return(t);
        }
Beispiel #16
0
 public void Bind(int port, string host)
 {
     Address           = NetAddress.Resolve(port, host, Options.IPv4Only);
     Socket            = new NetSocket(Address, BufferPool, SocketArgPool);
     Socket.OnAccepted = HandleAccept;
     Socket.Listen(Options.MaxAccept);
     OnListen(this);
     StartAccept();
 }
        /// <summary>
        /// Return info about the FakeIP and port that we have been assigned, if any.
        ///
        /// </summary>
        public static Result GetFakeIP(int fakePortIndex, out NetAddress address)
        {
            var pInfo = default(SteamNetworkingFakeIPResult_t);

            Internal.GetFakeIP(0, ref pInfo);

            address = NetAddress.From(Utility.Int32ToIp(pInfo.IP), pInfo.Ports[fakePortIndex]);
            return(pInfo.Result);
        }
        /// <summary>
        /// Connect to a socket created via <method>CreateListenSocketIP</method>
        /// </summary>
        public static T ConnectNormal <T>(NetAddress address) where T : ConnectionInterface, new()
        {
            var t       = new T();
            var options = new NetKeyValue[0];

            t.Connection = Internal.ConnectByIPAddress(ref address, options.Length, options);
            SetConnectionInterface(t.Connection.Id, t);
            return(t);
        }
        public static T CreateNormalSocket <T>(NetAddress address)
            where T : SocketInterface, new()
        {
            T t = Activator.CreateInstance <T>();

            t.Socket = SteamNetworkingSockets.Internal.CreateListenSocketIP(ref address);
            SteamNetworkingSockets.SetSocketInterface(t.Socket.Id, t);
            return(t);
        }
Beispiel #20
0
        /// <summary>
        /// Connect to a socket created via <method>CreateListenSocketIP</method>
        /// </summary>
        public static T ConnectNormal <T>(NetAddress address) where T : ConnectionManager, new()
        {
            var t       = new T();
            var options = Array.Empty <NetKeyValue>();

            t.Connection = Internal.ConnectByIPAddress(ref address, options.Length, options);
            SetConnectionManager(t.Connection.Id, t);
            return(t);
        }
Beispiel #21
0
        public override void Deserialize(BinaryReader reader)
        {
            //
            base.Deserialize(reader);

            //
            reader.ReadBytes(3);
            Attributes          = reader.ReadInt32();
            ListenServerAddress = reader.Read <NetAddress>();
        }
        /// <summary>
        /// Creates a "server" socket that listens for clients to connect to by calling
        /// Connect, over ordinary UDP (IPv4 or IPv6)
        /// </summary>
        public static T CreateNormalSocket <T>(NetAddress address) where T : SocketInterface, new()
        {
            var t       = new T();
            var options = new NetKeyValue[0];

            t.Socket = Internal.CreateListenSocketIP(ref address, options.Length, options);
            t.Initialize();

            SetSocketInterface(t.Socket.Id, t);
            return(t);
        }
 public override void ClientConnect(string address)
 {
     if (useRelay)
     {
         Client = SteamNetworkingSockets.ConnectRelay <ClientManager>(targetSteamId);
     }
     else
     {
         Client = SteamNetworkingSockets.ConnectNormal <ClientManager>(NetAddress.From(address, port));
     }
 }
        public void TestNetAddress()
        {
            var sut = new NetAddress();

            Assert.NotNull(sut);
            Assert.Equal(0, sut.Port);
            Assert.Equal(IPAddress.Any, sut.Address);

            sut = new NetAddress("10.10.10.10");
            Assert.NotNull(sut);
            Assert.Equal(0, sut.Port);
            Assert.Equal("10.10.10.10", sut.ToString());

            sut = new NetAddress("10.10.10.10:5555");
            Assert.NotNull(sut);
            Assert.Equal(5555, sut.Port);
            Assert.Equal("10.10.10.10:5555", sut.ToString());

            sut = new NetAddress(":1234");
            Assert.NotNull(sut);
            Assert.Equal(1234, sut.Port);
            Assert.Equal(IPAddress.Any, sut.Address);

            Assert.Throws <ArgumentException>(() => new NetAddress(":"));
            Assert.Throws <ArgumentException>(() => new NetAddress(""));

            sut = new NetAddress("10.10.10.10", 54321);
            Assert.NotNull(sut);
            Assert.Equal(54321, sut.Port);
            Assert.Equal("10.10.10.10:54321", sut.ToString());

            sut = new NetAddress(IPAddress.Parse("10.10.10.10"), 1234);
            Assert.NotNull(sut);
            Assert.Equal(1234, sut.Port);
            Assert.Equal("10.10.10.10:1234", sut.ToString());

            sut = new NetAddress(7777);
            Assert.NotNull(sut);
            Assert.Equal(7777, sut.Port);
            Assert.Equal(IPAddress.Any, sut.Address);

            sut = new NetAddress(new IPEndPoint(IPAddress.Parse("1.2.3.4"), 4321));
            Assert.NotNull(sut);
            Assert.Equal(4321, sut.Port);
            Assert.Equal("1.2.3.4:4321", sut.ToString());

            sut = new NetAddress("255.255.255.255");
            Assert.NotNull(sut);
            Assert.True(sut.IsPossibleBroadcast);

            sut = new NetAddress("239.0.0.1");
            Assert.NotNull(sut);
            Assert.True(sut.IsMulticast);
        }
Beispiel #25
0
        /// <summary>
        /// Creates a "server" socket that listens for clients to connect to by calling
        /// Connect, over ordinary UDP (IPv4 or IPv6)
        ///
        /// To use this derive a class from SocketManager and override as much as you want.
        ///
        /// </summary>
        public static T CreateNormalSocket <T>(NetAddress address) where T : SocketManager, new()
        {
            var t       = new T();
            var options = Array.Empty <NetKeyValue>();

            t.Socket = Internal.CreateListenSocketIP(ref address, options.Length, options);
            t.Initialize();

            SetSocketManager(t.Socket.Id, t);
            return(t);
        }
 public override void ServerStart()
 {
     if (useRelay)
     {
         Server = SteamNetworkingSockets.CreateRelaySocket <ServerManager>();
     }
     else
     {
         Server = SteamNetworkingSockets.CreateNormalSocket <ServerManager>(NetAddress.AnyIp(port));
     }
     serverActive = true;
 }
        public void NetAddressTest()
        {
            {
                var n = NetAddress.From("127.0.0.1", 12445);
                Assert.AreEqual(n.ToString(), "127.0.0.1:12445");
            }

            {
                var n = NetAddress.AnyIp(5543);
                Assert.AreEqual(n.ToString(), "[::]:5543");
            }
        }
 public static INetLgInterface GetTargetInterface(NetAddress? destinationAddress, IEnumerable<INetLgInterface> ipInterfaces)
 {
     if (destinationAddress != null) {
         foreach (var ipInterface in ipInterfaces) {
             if (ipInterface.Address != null && ipInterface.Address.Value.GetNetwork( ).Contains(destinationAddress.Value) == true) {
                 EmulatorLogger.Log(LogLevel.Info, EventType.RouteFoundConnected, string.Empty);
                 return ipInterface;
             }
         }
     }
     return null;
 }
        public void IsMatch_InsideBeforeOutside( )
        {
            var netRoute = new SUTest(
                new NetIpAddress(124, 102, 0, 0),
                new NetIpAddress(255, 255, 0, 0),
                new NetIpAddress(172, 144, 11, 201));

            var netIpAddressInsideBeforeOutside = new NetAddress(
                new NetIpAddress(124, 102, 255, 255),
                new NetIpAddress(255, 255, 0, 0));

            Assert.AreEqual(true, netRoute.IsMatch(netIpAddressInsideBeforeOutside));
        }
        public void IsMatch_OutsideAfter( )
        {
            var netRoute = new SUTest(
                new NetIpAddress(124, 102, 0, 0),
                new NetIpAddress(255, 255, 0, 0),
                new NetIpAddress(172, 144, 11, 201));

            var netIpAddressOutsideAfter = new NetAddress(
                new NetIpAddress(124, 103, 0, 1),
                new NetIpAddress(255, 255, 0, 0));

            Assert.AreEqual(false, netRoute.IsMatch(netIpAddressOutsideAfter));
        }
Beispiel #31
0
        public SocketManager CreateSession(string port)
        {
            var netAddress = NetAddress.AnyIp(ushort.Parse(port));

            Server = SteamNetworkingSockets.CreateNormalSocket <MaydayServer>(netAddress);

            ((MaydayServer)Server).NetworkManager = this;

            SteamMatchmaking.OnLobbyCreated += (result, lobby) => OnLobbyCreated(result, lobby, port);
            SteamMatchmaking.CreateLobbyAsync();

            return(Server);
        }
Beispiel #32
0
        public void MapShareFileToLocal(NetAddress gatewayAddress, string shareFilePath, string localFilePath, Action <string, string> callback)
        {
            if (_gatewayAddress != null && _gatewayAddress.Equals(gatewayAddress.Address, gatewayAddress.Port) == false)
            {
                throw new Exception("不能监测不同网关的文件");
            }
            _dict[shareFilePath] = new MapItem {
                LocalPath = localFilePath,
                Callback  = callback
            };

            _gatewayAddress = gatewayAddress;
        }
Beispiel #33
0
        /// <summary>
        /// Connect to a socket created via <method>CreateListenSocketIP</method>
        /// </summary>
        public static ConnectionManager ConnectNormal(NetAddress address, IConnectionManager iface)
        {
            var options    = Array.Empty <NetKeyValue>();
            var connection = Internal.ConnectByIPAddress(ref address, options.Length, options);

            var t = new ConnectionManager
            {
                Connection = connection,
                Interface  = iface
            };

            SetConnectionManager(t.Connection.Id, t);
            return(t);
        }
 public static NetAddress? GetRoute(NetAddress? destinationAddress, IEnumerable<INetLgInterface> ipInterfaces, IEnumerable<INetRoute> routes, INetRoute defaultRoute)
 {
     if (destinationAddress != null) {
         foreach (var route in routes) {
             if (route.IsMatch(destinationAddress.Value)) {
                 EmulatorLogger.Log(LogLevel.Info, EventType.RouteFound, string.Empty);
                 return route.Target;
             }
         }
         if (defaultRoute != null) {
             EmulatorLogger.Log(LogLevel.Info, EventType.RouteDefaultUsed, string.Empty);
             return defaultRoute.Target;
         }
         EmulatorLogger.Log(LogLevel.Info, EventType.RouteNotFound, string.Empty);
     }else {
         EmulatorLogger.Log(LogLevel.Warning, EventType.RouteInvalidDestinationAddress, string.Empty);
     }
     return null;
 }
 public bool Parse(string value)
 {
     SourceString = value;
     try
     {
         var match = HostRowPattern.Match(value);
         if (!match.Success) throw new FormatException();
         Enabled = value[0] != '#';
         IP = new NetAddress(match.Groups["ip"].Value);
         Aliases = new HostAliases(match.Groups["hosts"].Value);
         Comment = match.Groups["comment"].Value;
         Hidden = false;
         if (!String.IsNullOrEmpty(Comment))
         {
             Hidden = Comment[0] == '!';
             if (Hidden) Comment = Comment.Substring(1).Trim();
         }
         Valid = true;
     }
     catch
     {
         Enabled = false;
         Hidden = false;
         IP = null;
         Aliases = null;
         Comment = null;
         Valid = false;
     }
     SourceHash = HalfMD5.ComputeHash(ToString());
     return Valid;
 }